ProductController.php 72 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742
  1. <?php
  2. /**
  3. * User: admin
  4. * Date Time: 2021/1/15 20:36
  5. */
  6. namespace ghs\controllers;
  7. use biz\admin\classes\AdminRoleClass;
  8. use biz\item\classes\PtItemClass;
  9. use biz\wx\classes\WxMessageClass;
  10. use bizGhs\book\classes\BookItemClass;
  11. use bizGhs\cp\classes\CpClass;
  12. use bizGhs\cp\classes\CpItemClass;
  13. use bizGhs\custom\classes\CustomClass;
  14. use bizGhs\item\classes\ItemClass;
  15. use bizGhs\item\classes\ItemClassClass;
  16. use bizGhs\item\classes\UnitChangeClass;
  17. use bizGhs\merchant\classes\ShopClass;
  18. use bizGhs\notify\classes\NotifyClass;
  19. use bizGhs\order\classes\PurchaseOrderClass;
  20. use bizGhs\product\classes\ProductClass;
  21. use bizGhs\product\models\Product;
  22. use bizGhs\product\services\ProductService;
  23. use bizGhs\shop\classes\ShopAdminClass;
  24. use bizGhs\stock\classes\StockInDayClass;
  25. use common\components\imgUtil;
  26. use common\components\noticeUtil;
  27. use common\components\printUtil;
  28. use common\components\stringUtil;
  29. use common\components\util;
  30. use bizGhs\stock\classes\OnStockRecordClass;
  31. use Yii;
  32. class ProductController extends BaseController
  33. {
  34. public $guestAccess = ['index'];
  35. //修改平均成本 ssh 2025114
  36. public function actionModifyAvCost()
  37. {
  38. $get = Yii::$app->request->get();
  39. $id = $get['id'] ?? 0;
  40. $amount = $get['avCost'] ?? 0;
  41. $product = ProductClass::getById($id, true);
  42. if (empty($product)) {
  43. util::fail('没有找到花材');
  44. }
  45. if ($product->mainId != $this->mainId) {
  46. util::fail('不是你的花材');
  47. }
  48. $product->avCost = $amount;
  49. $product->save();
  50. util::complete('修改成功');
  51. }
  52. //修改路上库存 ssh 20231219
  53. public function actionModifyOnStock()
  54. {
  55. $get = Yii::$app->request->get();
  56. $id = $get['id'] ?? 0;
  57. $onStock = $get['onStock'] ?? 0;
  58. $info = ProductClass::getLockById($id);
  59. ProductClass::check($info, $this->mainId);
  60. $oldOnStock = $info->onStock ?? 0;
  61. $newOnStock = $onStock;
  62. $num = bcsub($newOnStock, $oldOnStock);
  63. $num = abs($num);
  64. $staff = $this->shopAdmin;
  65. $staffName = $staff->name ?? '';
  66. $onRecord = [];
  67. $onRecord['sjId'] = $this->sjId;
  68. $onRecord['shopId'] = $this->shopId;
  69. $onRecord['mainId'] = $this->mainId;
  70. $onRecord['orderSn'] = '';
  71. $onRecord['productId'] = $id;
  72. $onRecord['itemId'] = $info->itemId ?? 0;
  73. $onRecord['relateName'] = $staffName;
  74. $onRecord['itemNum'] = $num;
  75. $onRecord['oldStock'] = $oldOnStock;
  76. $onRecord['newStock'] = $newOnStock;
  77. $onRecord['ptStyle'] = 2;
  78. OnStockRecordClass::modify($onRecord);
  79. $info->onStock = $newOnStock;
  80. $info->save();
  81. util::complete('修改成功');
  82. }
  83. //停止预售 ssh 20230224
  84. public function actionCancelPreSell()
  85. {
  86. $get = Yii::$app->request->get();
  87. $id = $get['id'] ?? 0;
  88. $info = ProductClass::getById($id, true);
  89. ProductClass::check($info, $this->mainId);
  90. if ($info->stock > 0) {
  91. util::fail('没有库存才能停止预售');
  92. }
  93. $info->presell = 0;
  94. $info->presellDate = '';
  95. $info->save();
  96. util::complete();
  97. }
  98. //修改预售 ssh 20221214
  99. public function actionChangePresell()
  100. {
  101. $post = Yii::$app->request->post();
  102. $id = $post['id'] ?? 0;
  103. $info = ProductClass::getById($id, true);
  104. ProductClass::check($info, $this->mainId);
  105. $str = $post['date'] ?? '';
  106. $presell = $post['presell'] ?? 0;
  107. $newStr = '';
  108. if ($presell == 1) {
  109. if (empty($str)) {
  110. util::fail('请填写预售日期');
  111. }
  112. $arr = json_decode($str, true);
  113. if (empty($arr)) {
  114. util::fail('请填写预售日期');
  115. }
  116. $new = [];
  117. foreach ($arr as $date) {
  118. $new[] = strtotime($date);
  119. }
  120. $new = array_unique(array_filter($new));
  121. asort($new);
  122. $newStr = implode(',', $new);
  123. }
  124. $info->presell = $presell;
  125. $info->presellDate = $newStr;
  126. $info->discountPrice = 0;
  127. $info->save();
  128. util::complete();
  129. }
  130. //取消满减 ssh 20231216
  131. public function actionCancelFullOff()
  132. {
  133. $get = Yii::$app->request->get();
  134. $id = $get['id'] ?? 0;
  135. $info = ProductClass::getById($id, true);
  136. ProductClass::check($info, $this->mainId);
  137. $info->reachNum = 0;
  138. $info->reachNumDiscount = 0;
  139. $info->save();
  140. util::complete('取消成功');
  141. }
  142. //取消特价 ssh 20220901
  143. public function actionCancelDiscount()
  144. {
  145. $get = Yii::$app->request->get();
  146. $id = $get['id'] ?? 0;
  147. $info = ProductClass::getById($id, true);
  148. ProductClass::check($info, $this->mainId);
  149. $info->discountPrice = 0;
  150. $info->skDiscountPrice = 0;
  151. $info->hjDiscountPrice = 0;
  152. $info->save();
  153. util::complete('取消成功');
  154. }
  155. //打印花材的标签 ssh 20220602
  156. public function actionPrint()
  157. {
  158. $get = Yii::$app->request->get();
  159. $id = $get['id'] ?? 0;
  160. $num = $get['num'] ?? 1;
  161. $num = floatval($num);
  162. $num = (int)$num;
  163. $type = $get['type'] ?? 0;
  164. $priceOption = $get['priceOption'] ?? 0;
  165. $info = ProductClass::getById($id, true);
  166. if (empty($info)) {
  167. util::fail('没有找到花材');
  168. }
  169. $price = $info->skPrice ?? 0;
  170. $price = floatval($price);
  171. $name = $info->name ?? '';
  172. $ptItemId = $info->itemId ?? 0;
  173. $mainId = $info->mainId ?? 0;
  174. $ext = $this->shopExt;
  175. $printLabelSn = $ext->printLabelSn ?? '';
  176. if (empty($printLabelSn)) {
  177. util::fail('请设置标签打印机');
  178. }
  179. $p = new printUtil($printLabelSn);
  180. $unit = $info->ratio . $info->smallUnit . '装';
  181. if (isset($info->ratioType) && $info->ratioType == 1) {
  182. $unit = '若干' . $info->smallUnit . '装';
  183. }
  184. $p->times = $num;
  185. if (stringUtil::getWordNum($name) > 8) {
  186. $content = '<TEXT x="30" y="30" font="12" w="1" h="1" r="0">' . $name . '</TEXT>';
  187. } else {
  188. $content = '<TEXT x="30" y="30" font="12" w="2" h="2" r="0">' . $name . '</TEXT>';
  189. }
  190. if ($type == 0) {
  191. //打标签
  192. $content .= '<BC128 x="30" y="115" h="75" s="1" r="0" n="3" w="10">' . $ptItemId . '</BC128>';
  193. if (in_array($mainId, [52, 1459])) {
  194. $content .= '<TEXT x="30" y="250" font="12" w="2" h="2" r="0">惠雅鲜花</TEXT>';
  195. } elseif ($mainId == 16948) {
  196. $content .= '<TEXT x="30" y="250" font="12" w="2" h="2" r="0">淘花里鲜花</TEXT>';
  197. } elseif ($mainId == 72057) {
  198. $content .= '<TEXT x="30" y="250" font="12" w="2" h="2" r="0">淘花里小榄店</TEXT>';
  199. } else {
  200. if ($priceOption == 0) {
  201. $content .= '<TEXT x="30" y="250" font="12" w="2" h="2" r="0">' . $unit . '</TEXT>';
  202. } else {
  203. $content .= '<TEXT x="30" y="250" font="12" w="2" h="2" r="0">' . $unit . ' ' . $price . '元</TEXT>';
  204. }
  205. }
  206. } else {
  207. if (getenv('YII_ENV') == 'production') {
  208. $doublePrice = [52, 1459];
  209. } else {
  210. $doublePrice = [];
  211. }
  212. if (in_array($this->mainId, $doublePrice)) {
  213. //惠雅鲜花,打价格,显示正价和会员价,多处同步修改,关键词 hy_print_label_price ssh 20260101
  214. $hyPrice = $info->price ?? 0;
  215. $hyPrice = floatval($hyPrice);
  216. $content .= '<TEXT x="35" y="90" font="12" w="2" h="2" r="0">----------</TEXT>';
  217. $content .= '<TEXT x="35" y="150" font="12" w="2" h="2" r="0">正价 ' . $price . '元</TEXT>';
  218. $content .= '<TEXT x="35" y="230" font="12" w="2" h="2" r="0">会员价 ' . $hyPrice . '元</TEXT>';
  219. } elseif ($this->mainId == 4556) {
  220. //打价格,显示零售价,并且不带元,杭州斗南鲜花不要带元
  221. $content .= '<TEXT x="35" y="150" font="12" w="4" h="4" r="0">' . $price . '</TEXT>';
  222. } else {
  223. $content .= '<TEXT x="35" y="150" font="12" w="4" h="4" r="0">' . $price . '元</TEXT>';
  224. }
  225. }
  226. $p->printLabelMsg($content);
  227. util::complete();
  228. }
  229. //取出今天有入库的花材 ssh 20221024
  230. public function actionStockIn()
  231. {
  232. $py = Yii::$app->request->get('py', '');
  233. $version = Yii::$app->request->get('version', 0);
  234. if ($version == 0) {
  235. util::fail('请先升级版本到1.0.70以上');
  236. }
  237. $classInfo = ItemClassClass::getGhsItemClassAll($this->mainId);
  238. $mainId = $this->mainId ?? 0;
  239. $where['mainId'] = $mainId;
  240. if ($py) {
  241. $pyName = strtolower($py);
  242. $where['py'] = $pyName;
  243. }
  244. $arr = StockInDayClass::getAllByCondition(['mainId' => $mainId], null, '*');
  245. if (empty($arr)) {
  246. util::fail('没有花材需要盘点');
  247. }
  248. $ids = array_column($arr, 'itemId');
  249. $ids = array_unique($ids);
  250. $where['id'] = ['in', $ids];
  251. $level = 1;
  252. $field = 'id,py,cover,name,ratio,cost,addPrice,classId,skMore,skPrice,itemId,smallUnit,smallRatio,presellDate,bigUnit,smallUnit,ratioType,variety,price,stock,stockWarning,discountPrice,presell,presellDate';
  253. $itemInfoData = ProductClass::getAllByCondition($where, ['inTurn' => SORT_DESC, 'actualSold' => SORT_DESC], $field);
  254. $itemInfoData = ProductClass::groupProductInfo($itemInfoData, $level);
  255. $data = ProductService::assembleData($classInfo, $itemInfoData, true);
  256. util::success($data);
  257. }
  258. //按分类列出所有花材
  259. public function actionShow()
  260. {
  261. $py = Yii::$app->request->get('py', '');
  262. $name = Yii::$app->request->get('name', '');
  263. $requestType = Yii::$app->request->get('requestType', 'common');
  264. //默认显示上架商品
  265. $status = Yii::$app->request->get('status', 1);
  266. //默认显示未删除商品
  267. $delStatus = Yii::$app->request->get('delStatus', 0);
  268. $classId = Yii::$app->request->get('classId', 0);
  269. //获取所有当前供货商的分类 (全部、常用)
  270. //根据分类组装分类下的花材信息
  271. //中央ID
  272. $classInfo = ItemClassClass::getGhsItemClassAll($this->mainId);
  273. $where['mainId'] = $this->mainId;
  274. if ($py) {
  275. $pyName = strtolower($py);
  276. $where['py'] = $pyName;
  277. }
  278. //改价和全部有库存花材列表
  279. if ($requestType == 'changePrice' || $requestType == 'hasStockList') {
  280. $where['stock>'] = 0;
  281. }
  282. if (!empty($status)) {
  283. $where['status'] = $status;
  284. if ($requestType == 'itemList') {
  285. unset($where['status']);
  286. }
  287. }
  288. if ($requestType == 'book') {
  289. unset($where['status']);
  290. }
  291. $where['delStatus'] = $delStatus;
  292. if (!empty($classId)) {
  293. $where['classId'] = $classId;
  294. }
  295. if (!empty($name)) {
  296. if (stringUtil::isLetter($name)) {
  297. $name = strtolower($name);
  298. $where['py'] = ['like', $name];
  299. } else {
  300. $where['name'] = ['like', $name];
  301. }
  302. }
  303. //客户等级
  304. $customId = Yii::$app->request->get('customId', 0);
  305. $level = 1;
  306. $custom = [];
  307. if (!empty($customId)) {
  308. $custom = CustomClass::getById($customId, true);
  309. $level = $custom->level ?? 1;
  310. }
  311. $itemInfoData = [];
  312. if ($requestType == 'hasStockList') {
  313. //有库存的花材列表
  314. $field = 'id,py,cover,name,classId,itemId,price,skPrice,hjPrice,stock,onStock,cost,avCost,addPrice,hjAddPrice,skMore';
  315. $itemInfoData = ProductClass::getAllByCondition($where, ['inTurn' => SORT_DESC, 'actualSold' => SORT_DESC], $field);
  316. if (!empty($itemInfoData)) {
  317. foreach ($itemInfoData as $key => $val) {
  318. //以下参数主要是网页批量改价要用到
  319. $shortCover = $val['cover'] ?? '';
  320. $itemInfoData[$key]['cover'] = imgUtil::groupImg($shortCover) . "?x-oss-process=image/resize,m_fill,h_100,w_100";
  321. $itemInfoData[$key]['shortCover'] = $shortCover;
  322. }
  323. }
  324. } elseif ($requestType == 'changePrice') {
  325. $field = 'id,py,cover,name,cost,itemId,classId,addPrice,skPrice,hjPrice,discountPrice,hjDiscountPrice,skDiscountPrice,skMore,hjAddPrice,addPrice,variety,price,hjPrice,stock,onStock,presell,frontHide,reachNum,reachNumDiscount';
  326. $itemInfoData = ProductClass::getAllByCondition($where, ['inTurn' => SORT_DESC, 'actualSold' => SORT_DESC], $field);
  327. $itemInfoData = ProductClass::changePriceGroup($itemInfoData, $level);
  328. } elseif ($requestType == 'changeStock') {
  329. //修改库存列表
  330. $field = 'id,py,cover,name,cost,itemId,status,classId,addPrice,skPrice,discountPrice,skMore,variety,price,stock,frontHide';
  331. $itemInfoData = ProductClass::getAllByCondition($where, ['inTurn' => SORT_DESC, 'actualSold' => SORT_DESC], $field);
  332. $itemInfoData = ProductClass::changeStockGroup($itemInfoData, $level);
  333. } elseif ($requestType == 'kd') {
  334. //开单的花材列表
  335. $field = 'id,py,cover,name,cost,itemId,classId,skPrice,variety,price,hjPrice,hjDiscountPrice,skDiscountPrice,discountPrice,stock,weight,stockWarning,presell,ratioType,smallUnit,smallRatio,bigUnit,ratio,frontHide,reachNum,reachNumDiscount';
  336. $itemInfoData = ProductClass::getAllByCondition($where, ['inTurn' => SORT_DESC, 'actualSold' => SORT_DESC], $field);
  337. $itemInfoData = ProductClass::kdItemGroup($itemInfoData, $level, $custom);
  338. } elseif ($requestType == 'book') {
  339. //预订花材列表
  340. $field = 'id,py,cover,name,cost,itemId,classId,skPrice,variety,price,hjPrice,hjDiscountPrice,skDiscountPrice,discountPrice,stock,weight,stockWarning,presell,ratioType,smallUnit,smallRatio,bigUnit,ratio,frontHide';
  341. $itemInfoData = ProductClass::getAllByCondition($where, ['inTurn' => SORT_DESC, 'actualSold' => SORT_DESC], $field);
  342. $itemInfoData = ProductClass::bookItemGroup($itemInfoData, $level);
  343. } elseif ($requestType == 'itemList') {
  344. //花材列表
  345. $field = 'id,py,cover,name,cost,avCost,itemId,classId,skPrice,variety,price,hjPrice,discountPrice,hjDiscountPrice,skDiscountPrice,stock,onStock,actualSold,status,ratio,ratioType,presell,frontHide,auth,reachNum,reachNumDiscount,addPrice,hjAddPrice,skMore';
  346. $itemInfoData = ProductClass::getAllByCondition($where, ['inTurn' => SORT_DESC, 'actualSold' => SORT_DESC], $field);
  347. $itemInfoData = ProductClass::itemListGroup($itemInfoData, $level);
  348. } elseif ($requestType == 'cgStaffList') {
  349. unset($where['status']);
  350. $where['delStatus'] = 0;
  351. $field = 'id,py,cover,name,cost,itemId,classId,skPrice,variety,price,hjPrice,discountPrice,hjDiscountPrice,skDiscountPrice,stock,onStock,actualSold,status,ratio,ratioType,presell,frontHide,auth,reachNum,reachNumDiscount,cgStaffId,cgStaffName';
  352. $itemInfoData = ProductClass::getAllByCondition($where, ['inTurn' => SORT_DESC, 'actualSold' => SORT_DESC], $field);
  353. $itemInfoData = ProductClass::cgStaffListGroup($itemInfoData, $level);
  354. } elseif ($requestType == 'outList') {
  355. //下架花材列表
  356. $where['status'] = 2;
  357. $where['delStatus'] = 0;
  358. $where['removeStatus'] = 0;
  359. $field = 'id,py,cover,name,cost,itemId,classId,addPrice,skPrice,bigUnit,smallUnit,ratio,ratioType,discountPrice,skMore,variety,price,stock,presell,status';
  360. $itemInfoData = ProductClass::getAllByCondition($where, ['inTurn' => SORT_DESC, 'actualSold' => SORT_DESC], $field);
  361. $itemInfoData = ProductClass::simpleGroup($itemInfoData, $level);
  362. } elseif ($requestType == 'stopList') {
  363. //停用花材列表
  364. unset($where['status']);
  365. $where['delStatus'] = 1;
  366. $where['removeStatus'] = 0;
  367. $field = 'id,py,cover,name,cost,itemId,classId,addPrice,skPrice,bigUnit,smallUnit,ratio,ratioType,discountPrice,skMore,variety,price,stock,presell,status,delStatus';
  368. $itemInfoData = ProductClass::getAllByCondition($where, ['inTurn' => SORT_DESC, 'actualSold' => SORT_DESC], $field);
  369. $itemInfoData = ProductClass::simpleGroup($itemInfoData, $level);
  370. } elseif ($requestType == 'removeList') {
  371. //删除花材列表
  372. unset($where['status']);
  373. $where['delStatus'] = 1;
  374. $where['removeStatus'] = 1;
  375. $field = 'id,py,cover,name,cost,itemId,classId,addPrice,skPrice,bigUnit,smallUnit,ratio,ratioType,discountPrice,skMore,variety,price,stock,presell,status';
  376. $itemInfoData = ProductClass::getAllByCondition($where, ['inTurn' => SORT_DESC, 'actualSold' => SORT_DESC], $field);
  377. $itemInfoData = ProductClass::simpleGroup($itemInfoData, $level);
  378. } elseif ($requestType == 'check') {
  379. $field = 'id,py,cover,name,itemId,classId,variety,price,discountPrice,stock,stockWarning,presell,ratioType,smallUnit,bigUnit,ratio,frontHide';
  380. $itemInfoData = ProductClass::getAllByCondition($where, ['inTurn' => SORT_DESC, 'actualSold' => SORT_DESC], $field);
  381. $itemInfoData = ProductClass::checkItemGroup($itemInfoData, $level);
  382. } elseif ($requestType == 'break') {
  383. $field = 'id,py,cover,name,itemId,classId,variety,price,discountPrice,stock,stockWarning,presell,ratioType,smallUnit,bigUnit,ratio,frontHide';
  384. $itemInfoData = ProductClass::getAllByCondition($where, ['inTurn' => SORT_DESC, 'actualSold' => SORT_DESC], $field);
  385. $itemInfoData = ProductClass::breakItemGroup($itemInfoData, $level);
  386. } elseif ($requestType == 'part') {
  387. //拆散花材
  388. $field = 'id,py,cover,name,itemId,classId,variety,price,discountPrice,stock,stockWarning,presell,ratioType,smallUnit,bigUnit,ratio';
  389. $itemInfoData = ProductClass::getAllByCondition($where, ['inTurn' => SORT_DESC, 'actualSold' => SORT_DESC], $field);
  390. $itemInfoData = ProductClass::partItemGroup($itemInfoData, $level);
  391. } elseif ($requestType == 'stockOut') {
  392. $field = 'id,py,cover,name,itemId,classId,variety,price,discountPrice,stock,stockWarning,presell,ratioType,smallUnit,bigUnit,ratio,smallRatio,frontHide';
  393. $itemInfoData = ProductClass::getAllByCondition($where, ['inTurn' => SORT_DESC, 'actualSold' => SORT_DESC], $field);
  394. $itemInfoData = ProductClass::stockOutGroup($itemInfoData, $level);
  395. } elseif ($requestType == 'cg') {
  396. $field = 'id,py,cover,name,itemId,classId,variety,price,discountPrice,stock,presell,ratioType,smallUnit,bigUnit,ratio,weight,frontHide';
  397. $itemInfoData = ProductClass::getAllByCondition($where, ['inTurn' => SORT_DESC, 'actualSold' => SORT_DESC], $field);
  398. $itemInfoData = ProductClass::cgItemGroup($itemInfoData, $level);
  399. } elseif ($requestType == 'warning') {
  400. $field = 'id,py,cover,name,cost,itemId,classId,skPrice,variety,price,discountPrice,stock,onStock,actualSold,presell,bigUnit,stockWarning,status,frontHide';
  401. $itemInfoData = Product::find()->where("mainId={$this->mainId}")
  402. ->andWhere('`stock`+`onStock`<`stockWarning`')
  403. ->andWhere("delStatus=0")
  404. ->select($field)->asArray()->all();
  405. $itemInfoData = ProductClass::warningGroup($itemInfoData, $level);
  406. } else {
  407. util::fail('没有数据');
  408. }
  409. $data = ProductService::assembleItemData($classInfo, $itemInfoData);
  410. util::success($data);
  411. }
  412. //取出今天有入库的花材 ssh 20221224
  413. public function actionGetStockIn()
  414. {
  415. $py = Yii::$app->request->get('py', '');
  416. $version = Yii::$app->request->get('version', 0);
  417. if ($version == 0) {
  418. util::fail('请先升级版本到1.0.70以上');
  419. }
  420. $classInfo = ItemClassClass::getGhsItemClassAll($this->mainId);
  421. $mainId = $this->mainId ?? 0;
  422. $where['mainId'] = $mainId;
  423. if ($py) {
  424. $pyName = strtolower($py);
  425. $where['py'] = $pyName;
  426. }
  427. $arr = StockInDayClass::getAllByCondition(['mainId' => $mainId], null, '*');
  428. if (empty($arr)) {
  429. util::fail('没有花材需要盘点');
  430. }
  431. $ids = array_column($arr, 'itemId');
  432. $ids = array_unique($ids);
  433. $where['id'] = ['in', $ids];
  434. $level = 1;
  435. $field = 'id,py,cover,name,itemId,classId,variety,price,discountPrice,stock,stockWarning,presell,ratioType,smallUnit,bigUnit,ratio';
  436. $itemInfoData = ProductClass::getAllByCondition($where, ['inTurn' => SORT_DESC, 'actualSold' => SORT_DESC], $field);
  437. $itemInfoData = ProductClass::checkItemGroup($itemInfoData, $level);
  438. $data = ProductService::assembleItemData($classInfo, $itemInfoData);
  439. util::success($data);
  440. }
  441. //按分类列出所有花材
  442. public function actionIndex()
  443. {
  444. $py = Yii::$app->request->get('py', '');
  445. $requestType = Yii::$app->request->get('requestType', 'common');
  446. //默认显示上架商品
  447. $status = Yii::$app->request->get('status', 1);
  448. //默认显示未删除商品
  449. $delStatus = Yii::$app->request->get('delStatus', 0);
  450. $warning = Yii::$app->request->get('warning', 0);
  451. //获取所有当前供货商的分类 (全部、常用)
  452. //根据分类组装分类下的花材信息
  453. //中央ID
  454. $classInfo = ItemClassClass::getGhsItemClassAll($this->mainId);
  455. $where['mainId'] = $this->mainId;
  456. if ($py) {
  457. $pyName = strtolower($py);
  458. $where['py'] = $pyName;
  459. }
  460. if ($requestType == 'hasStock') {
  461. //改价只显示库存大于0的
  462. $where['stock>'] = 0;
  463. }
  464. if (!empty($status)) {
  465. $where['status'] = $status;
  466. }
  467. $where['delStatus'] = $delStatus;
  468. //客户等级
  469. $customId = Yii::$app->request->get('customId', 0);
  470. $level = 1;
  471. if (!empty($customId)) {
  472. $custom = CustomClass::getById($customId, true);
  473. $level = $custom->level ?? 1;
  474. }
  475. if ($warning == 1) {
  476. //库存预警
  477. $field = 'id,py,cover,name,ratio,cost,addPrice,classId,skMore,skPrice,itemId,smallUnit,smallRatio,presellDate,bigUnit,smallUnit,ratioType,variety,price,stock,stockWarning,discountPrice,presell';
  478. $itemInfoData = Product::find()->where("mainId={$this->mainId}")
  479. ->andWhere('`stock`<`stockWarning`')
  480. ->andWhere("delStatus=0")
  481. ->select($field)->asArray()->all();
  482. } else {
  483. $field = 'id,py,cover,name,ratio,cost,addPrice,classId,skMore,skPrice,itemId,smallUnit,smallRatio,presellDate,bigUnit,smallUnit,ratioType,variety,price,stock,stockWarning,discountPrice,presell';
  484. $itemInfoData = ProductClass::getAllByCondition($where, ['inTurn' => SORT_DESC, 'actualSold' => SORT_DESC], $field);
  485. }
  486. $itemInfoData = ProductClass::groupProductInfo($itemInfoData, $level);
  487. $data = ProductService::assembleData($classInfo, $itemInfoData, true);
  488. util::success($data);
  489. }
  490. //所有花材分页和不分页
  491. public function actionList()
  492. {
  493. $get = Yii::$app->request->get();
  494. $where = [];
  495. $classId = Yii::$app->request->get('classId', 0);
  496. if (!empty($classId)) {
  497. $where['classId'] = $classId;
  498. }
  499. $name = Yii::$app->request->get('name', '');
  500. if (empty($name)) {
  501. $py = Yii::$app->request->get('py', '');
  502. $name = !empty($py) ? $py : '';
  503. }
  504. if (!empty($name)) {
  505. if (stringUtil::isLetter($name)) {
  506. $where['py'] = ['like', $name];
  507. } else {
  508. $where['name'] = ['like', $name];
  509. }
  510. }
  511. $status = Yii::$app->request->get('status', 0);
  512. if (!empty($status)) {
  513. $where['status'] = $status;
  514. }
  515. $delStatus = Yii::$app->request->get('delStatus', 0);
  516. if ($delStatus != 2) {
  517. $where['delStatus'] = $delStatus;
  518. }
  519. $where['mainId'] = $this->mainId;
  520. $productIds = Yii::$app->request->get('ids', '');
  521. if (!empty($productIds)) {
  522. $productIdArr = explode(',', $productIds);
  523. if (!empty($productIdArr)) {
  524. $where['id'] = ['in', $productIdArr];
  525. }
  526. }
  527. //输出标准会员价,即批发价,默认显示的是批发价
  528. $level = 1;
  529. $type = Yii::$app->request->get('type', '');
  530. $showPage = Yii::$app->request->get('showPage', 0);
  531. if ($showPage) {
  532. if ($type == 'waring') {
  533. $pro = Product::find()->where("mainId={$this->mainId}")->andWhere('`stock`<`stockWarning`')->select('id')->asArray()->all();
  534. $lackIds = array_column($pro, 'id');
  535. if (empty($lackIds)) {
  536. util::success([]);
  537. }
  538. $lackIds = array_filter(array_unique($lackIds));
  539. $where['id'] = ['in', $lackIds];
  540. $respond = ProductClass::getList("*", $where, "actualSold desc");
  541. } else {
  542. $hasStock = $get['hasStock'] ?? -1;
  543. if ($hasStock == 0) {
  544. $where['stock'] = 0;
  545. }
  546. if ($hasStock == 1) {
  547. $where['stock>'] = 0;
  548. }
  549. $cgStaffId = $get['cgStaffId'] ?? 0;
  550. if (!empty($cgStaffId)) {
  551. $where['cgStaffId'] = $cgStaffId;
  552. }
  553. $respond = ProductClass::getList("*", $where, "inTurn desc");
  554. }
  555. $respond['list'] = ProductClass::groupProductInfo($respond['list'], $level);
  556. $respond['list'] = ProductClass::groupClassName($this->mainId, $respond['list']);
  557. util::success($respond);
  558. } else {
  559. if ($type == 'waring') {
  560. //库存预警 按库存从小到大排序
  561. $data = ProductClass::getAllByCondition($where, ['stock' => SORT_ASC, 'inTurn' => SORT_DESC], "*");
  562. } else {
  563. if (!empty($productIds)) {
  564. //优先按 $productIds 排序 "FIELD(`id`,4,5,6)"=>true
  565. $data = ProductClass::getAllByCondition($where, ["FIELD(`id`,$productIds)" => true, 'inTurn' => SORT_DESC], "*");
  566. } else {
  567. $data = ProductClass::getAllByCondition($where, ['actualSold' => SORT_DESC, 'inTurn' => SORT_DESC], "*");
  568. }
  569. }
  570. $data = ProductClass::groupProductInfo($data, $level);
  571. $data = ProductClass::groupClassName($this->mainId, $data);
  572. if ($type == 'waring') {
  573. //库存预警
  574. $newData = [];
  575. foreach ($data as $v) {
  576. if ($v['stock'] <= $v['stockWarning']) {
  577. $newData[] = $v;
  578. }
  579. }
  580. util::success(['list' => $newData]);
  581. }
  582. util::success(['list' => $data]);
  583. }
  584. }
  585. //所有花材
  586. public function actionAll()
  587. {
  588. $where = [];
  589. $where['mainId'] = $this->mainId;
  590. $classId = Yii::$app->request->get('classId', 0);
  591. if (!empty($classId)) {
  592. $where['classId'] = $classId;
  593. }
  594. $status = Yii::$app->request->get('status', 0);
  595. if (!empty($status)) {
  596. $where['status'] = $status;
  597. }
  598. $delStatus = Yii::$app->request->get('delStatus', 0);
  599. if ($delStatus != 2) {
  600. $where['delStatus'] = $delStatus;
  601. }
  602. //输出标准会员价,即批发价,默认显示的是批发价
  603. $level = 1;
  604. $data = ProductClass::getAllByCondition($where, ['actualSold' => SORT_DESC, 'inTurn' => SORT_DESC], "*");
  605. $data = ProductClass::groupProductInfo($data, $level);
  606. util::success(['list' => $data]);
  607. }
  608. //批量改价
  609. public function actionBatchChangePrice()
  610. {
  611. $shop = $this->shop;
  612. $join = $shop->join ?? 0;
  613. $default = $shop->default ?? 0;
  614. if ($join == 0 && $default == 0) {
  615. //除了小蔡鲜花的蔡总、郑总、苏南3007,其他人直营分店不能改价格,多处要同步修改,关键词 direct_price_change
  616. if (!in_array($this->adminId, [35725, 23659, 29264])) {
  617. util::fail('直营店不能改价');
  618. }
  619. }
  620. $shopAdmin = $this->shopAdmin;
  621. if (!isset($shopAdmin->super) || $shopAdmin->super != 1) {
  622. util::fail('超管才能修改');
  623. }
  624. $shop = $this->shop;
  625. $default = $shop->default ?? 0;
  626. $adminId = $this->adminId ?? 0;
  627. //normal常规改价,cg采购改价
  628. $changeType = Yii::$app->request->post('changeType', 'normal');
  629. $targetId = Yii::$app->request->post('targetId', 0);
  630. $changeParams = ['staffId' => $shopAdmin->id, 'staffName' => $shopAdmin->name, 'changeType' => $changeType, 'targetId' => $targetId];
  631. $post = Yii::$app->request->post();
  632. $data = $post['data'] ?? '';
  633. if (empty($data)) {
  634. util::fail('没有修改');
  635. }
  636. $arr = json_decode($data, true);
  637. if (empty($arr)) {
  638. util::fail('没有修改哦');
  639. }
  640. $appVersion = $post['appVersion'] ?? 0;
  641. if ($appVersion != 1) {
  642. util::fail('请先升级应用');
  643. }
  644. //解决重复请求问题
  645. $cacheKey = 'batch_change_price_' . $targetId;
  646. $has = Yii::$app->redis->executeCommand('GET', [$cacheKey]);
  647. if (!empty($has)) {
  648. util::fail('请5秒后操作');
  649. }
  650. Yii::$app->redis->executeCommand('SETEX', [$cacheKey, 5, 'has']);
  651. $connection = Yii::$app->db;
  652. $transaction = $connection->beginTransaction();
  653. try {
  654. $needNotice = false;
  655. $cg = PurchaseOrderClass::getLockById($targetId);
  656. if (!empty($cg)) {
  657. if (isset($cg->mainId) == false || $cg->mainId != $this->mainId) {
  658. util::fail('不是您的采购单');
  659. }
  660. //批量改价同时入库
  661. if ($cg->status == PurchaseOrderClass::PURCHASE_ORDER_STATUS_SENDING) {
  662. $staff = $this->shopAdmin;
  663. $data = [];
  664. $data['staffId'] = $staff->id ?? 0;
  665. $data['staffName'] = $staff->name ?? '';
  666. $data['adminId'] = $this->adminId ?? 0;
  667. $data['shop'] = $this->shop;
  668. PurchaseOrderClass::putIn($cg, $data);
  669. $needNotice = true;
  670. }
  671. }
  672. $ids = array_column($arr, 'id');
  673. $ids = array_unique(array_filter($ids));
  674. if (empty($ids)) {
  675. util::fail('请选择花材');
  676. }
  677. $sjId = $shop->sjId ?? 0;
  678. $chainShopList = [];
  679. if ($default == 1) {
  680. $chainShopList = ShopClass::getAllByCondition(['sjId' => $sjId, 'join' => 0], null, '*', null, true);
  681. }
  682. $productList = ProductClass::getAllByCondition(['id' => ['in', $ids]], null, '*', 'id', true);
  683. foreach ($arr as $product) {
  684. $productId = $product['id'];
  685. $productInfo = $productList[$productId] ?? [];
  686. if (empty($productInfo)) {
  687. util::fail('没有找到花材');
  688. }
  689. $productName = $productInfo->name ?? '';
  690. if (!isset($product['id'])) {
  691. util::fail('没有花材');
  692. }
  693. if (!isset($product['price']) || !is_numeric($product['price']) || $product['price'] < 0) {
  694. util::fail('请填写' . $productName . '的批发价');
  695. }
  696. $price = $product['price'];
  697. if (!isset($product['skPrice']) || !is_numeric($product['skPrice']) || $product['skPrice'] < 0) {
  698. util::fail('请填写' . $productName . '的零售价');
  699. }
  700. $skPrice = $product['skPrice'];
  701. if (!isset($product['hjPrice']) || !is_numeric($product['hjPrice']) || $product['hjPrice'] < 0) {
  702. util::fail('请填写' . $productName . '的会员价');
  703. }
  704. $hjPrice = $product['hjPrice'] ?? 0;
  705. if (!isset($productInfo->mainId) || $productInfo->mainId != $this->mainId) {
  706. util::fail('无法访问');
  707. }
  708. if ($hjPrice > $price) {
  709. util::fail($productName . ' 批发价要大于会员价');
  710. }
  711. if ($price > $skPrice) {
  712. util::fail($productName . ' 零售价要大于批发价');
  713. }
  714. $ptItemId = $productInfo->itemId;
  715. ProductClass::changeSinglePrice($shop, $ptItemId, $price, $skPrice, $hjPrice, $changeParams);
  716. //在首店修改需要同步到所有直营店
  717. if ($default == 1 && isset($shop->dataSync) && $shop->dataSync == 1) {
  718. foreach ($chainShopList as $chain) {
  719. if ($chain->id == $shop->id) {
  720. continue;
  721. }
  722. $chainMainId = $chain->mainId ?? 0;
  723. $staff = ShopAdminClass::getByCondition(['mainId' => $chainMainId, 'adminId' => $adminId], true);
  724. $staffId = $staff->id ?? 0;
  725. $staffName = $staff->name ?? '';
  726. $changeParams2 = ['staffId' => $staffId, 'staffName' => $staffName, 'changeType' => $changeType, 'targetId' => $targetId];
  727. ProductClass::changeSinglePrice($chain, $ptItemId, $price, $skPrice, $hjPrice, $changeParams2);
  728. }
  729. }
  730. }
  731. $mainId = $shop->mainId ?? 0;
  732. if (!empty($mainId)) {
  733. //提醒零售收银台界面要刷新,多处要修改,关键词 modify_price_remind_cashier
  734. $staffList = ShopAdminClass::getAllByCondition(['mainId' => $mainId], null, '*', null, true);
  735. if (!empty($staffList)) {
  736. foreach ($staffList as $staff) {
  737. $staffId = $staff->id ?? 0;
  738. Yii::$app->redis->executeCommand('SET', ['cashier_' . $mainId . '_' . $staffId . '_may_refresh', 'yes']);
  739. Yii::$app->redis->executeCommand('SET', ['ghs_cashier_' . $mainId . '_' . $staffId . '_may_refresh', 'yes']);
  740. }
  741. }
  742. }
  743. $transaction->commit();
  744. //入库成功通知相关人员,关键词 put_in_notice
  745. if ($needNotice) {
  746. // $cg = PurchaseOrderClass::getLockById($targetId);
  747. // WxMessageClass::ghsCgEntryInform($shop, $cg);
  748. }
  749. util::complete('操作成功');
  750. } catch (\Exception $e) {
  751. $transaction->rollBack();
  752. $msg = $e->getMessage();
  753. Yii::info("修改失败原因:" . $msg);
  754. noticeUtil::push("修改价格出现失败情况,原因:" . $msg, '15280215347');
  755. util::fail('修改失败');
  756. }
  757. }
  758. //多个花材同时改成一个价 ssh 20231003
  759. public function actionManyItemChangeOnePrice()
  760. {
  761. $shop = $this->shop;
  762. $join = $shop->join ?? 0;
  763. $default = $shop->default ?? 0;
  764. if ($join == 0 && $default == 0) {
  765. util::fail('当前直营分店,只能回总店修改价格');
  766. }
  767. $shopAdmin = $this->shopAdmin;
  768. if (isset($shopAdmin->super) == false || $shopAdmin->super != 1) {
  769. util::fail('超管才能修改');
  770. }
  771. $post = Yii::$app->request->post();
  772. $idsList = $post['ids'] ?? '';
  773. $ids = json_decode($idsList, true);
  774. if (empty($ids)) {
  775. util::fail('请选择花材');
  776. }
  777. $list = ProductClass::getAllByCondition(['id' => ['in', $ids]], null, '*', null, true);
  778. if (empty($list)) {
  779. util::fail('请选择花材哦');
  780. }
  781. $mainId = $this->mainId;
  782. $adminId = $this->adminId ?? 0;
  783. $shop = $this->shop;
  784. $default = $shop->default ?? 0;
  785. $shopAdmin = $this->shopAdmin;
  786. $price = $post['price'] ?? 0;
  787. if (is_numeric($price) == false) {
  788. util::fail('批发价填写错误');
  789. }
  790. $skPrice = $post['skPrice'] ?? 0;
  791. if (is_numeric($skPrice) == false) {
  792. util::fail('散客价填写错误');
  793. }
  794. $hjPrice = $post['hjPrice'] ?? 0;
  795. if (is_numeric($hjPrice) == false) {
  796. util::fail('会员价填写错误');
  797. }
  798. if ($hjPrice > $price) {
  799. util::fail('会员价不能大于批发价');
  800. }
  801. if ($price > $skPrice) {
  802. util::fail('批发价不能大于零售价');
  803. }
  804. $sjId = $shop->sjId ?? 0;
  805. $chainShopList = [];
  806. if ($default == 1) {
  807. $chainShopList = ShopClass::getAllByCondition(['sjId' => $sjId, 'join' => 0], null, '*', null, true);
  808. }
  809. //normal常规改价,cg采购改价
  810. $changeType = Yii::$app->request->post('changeType', 'normal');
  811. $targetId = 0;
  812. $changeParams = ['staffId' => $shopAdmin->id, 'staffName' => $shopAdmin->name, 'changeType' => $changeType, 'targetId' => $targetId];
  813. $connection = Yii::$app->db;
  814. $transaction = $connection->beginTransaction();
  815. try {
  816. foreach ($list as $product) {
  817. if ($product->mainId != $mainId) {
  818. util::fail('修改失败,不是你的花材');
  819. }
  820. $ptItemId = $product->itemId;
  821. ProductClass::changeSinglePrice($shop, $ptItemId, $price, $skPrice, $hjPrice, $changeParams);
  822. //在首店修改需要同步到所有直营店
  823. if ($default == 1 && isset($shop->dataSync) && $shop->dataSync == 1) {
  824. if (!empty($chainShopList)) {
  825. foreach ($chainShopList as $chain) {
  826. if ($chain->id == $shop->id) {
  827. continue;
  828. }
  829. $chainMainId = $chain->mainId ?? 0;
  830. $staff = ShopAdminClass::getByCondition(['mainId' => $chainMainId, 'adminId' => $adminId], true);
  831. $changeParams2 = ['staffId' => $staff->id, 'staffName' => $staff->name, 'changeType' => $changeType, 'targetId' => $targetId];
  832. ProductClass::changeSinglePrice($chain, $ptItemId, $price, $skPrice, $hjPrice, $changeParams2);
  833. }
  834. }
  835. }
  836. }
  837. if (!empty($mainId)) {
  838. //提醒零售收银台界面要刷新,多处要修改,关键词 modify_price_remind_cashier
  839. $staffList = ShopAdminClass::getAllByCondition(['mainId' => $mainId], null, '*', null, true);
  840. if (!empty($staffList)) {
  841. foreach ($staffList as $staff) {
  842. $staffId = $staff->id ?? 0;
  843. Yii::$app->redis->executeCommand('SET', ['cashier_' . $mainId . '_' . $staffId . '_may_refresh', 'yes']);
  844. Yii::$app->redis->executeCommand('SET', ['ghs_cashier_' . $mainId . '_' . $staffId . '_may_refresh', 'yes']);
  845. }
  846. }
  847. }
  848. $transaction->commit();
  849. util::complete('修改成功');
  850. } catch (\Exception $e) {
  851. $transaction->rollBack();
  852. Yii::info("修改失败原因:" . $e->getMessage());
  853. util::fail('修改失败');
  854. }
  855. }
  856. //改价
  857. public function actionChangePrice()
  858. {
  859. $shopAdmin = $this->shopAdmin;
  860. if (isset($shopAdmin->super) == false || $shopAdmin->super != 1) {
  861. util::fail('超管才能修改');
  862. }
  863. $productId = Yii::$app->request->post('productId', 0);
  864. $productInfo = ProductClass::getById($productId, true);
  865. if (empty($productInfo)) {
  866. util::fail("花材不存在");
  867. }
  868. if ($productInfo->mainId != $this->mainId) {
  869. util::fail('没有权限');
  870. }
  871. $price = Yii::$app->request->post('price', '');
  872. if (is_numeric($price) && $price > 0) {
  873. ProductClass::changeSinglePrice($productInfo, $price, ProductClass::PRICE_LABEL_CHANGE);
  874. } else {
  875. $price = bcadd($productInfo->cost, $productInfo->addPrice, 2);
  876. ProductClass::changeSinglePrice($productInfo, $price, ProductClass::PRICE_LABEL_AUTO);
  877. }
  878. util::success(['price' => $price]);
  879. }
  880. //恢复自动调价
  881. public function actionAutoPrice()
  882. {
  883. $productId = Yii::$app->request->post('productId', 0);
  884. $productData = ProductClass::getById($productId);
  885. if (!$productData) {
  886. util::fail("花材不存在");
  887. }
  888. //2021.04.06改为用product中的成本价+加价
  889. $price = bcadd($productData['cost'], $productData['addPrice'], 2);
  890. ProductClass::changeSinglePrice($productId, $this->shopId, $price, ProductClass::PRICE_LABEL_AUTO);
  891. util::complete("操作成功");
  892. }
  893. //修改加价
  894. public function actionChangeAddPrice()
  895. {
  896. $productId = Yii::$app->request->post('productId', 0);
  897. $addPrice = Yii::$app->request->post('addPrice', '');
  898. if ($addPrice < 0) {
  899. util::fail("加价不能小于0");
  900. }
  901. $productData = ProductClass::getProductData($productId, $this->mainId);
  902. if (!$productData) {
  903. util::fail("花材不存在");
  904. }
  905. ProductClass::changeAddPrice($productId, $addPrice);
  906. util::complete();
  907. }
  908. //批量修改更多,包括排序、重量和保质期 ssh 20211211
  909. public function actionBatchChangeMore()
  910. {
  911. $shop = $this->shop;
  912. $default = $shop->default ?? 0;
  913. $join = $shop->join ?? 0;
  914. if ($default == 0 && $join == 0) {
  915. util::fail('当前是直营店,请返回总店修改');
  916. }
  917. $shopAdmin = $this->shopAdmin;
  918. if (isset($shopAdmin->super) == false || $shopAdmin->super != 1) {
  919. util::fail('超管才能操作');
  920. }
  921. $addData = Yii::$app->request->post('addData', '');
  922. if (empty($addData)) {
  923. util::fail('没有花材');
  924. }
  925. $itemData = json_decode($addData, true);
  926. if (is_array($itemData) == false) {
  927. util::fail('没有花材...');
  928. }
  929. $ids = array_column($itemData, 'id');
  930. $infoList = ProductClass::getByIds($ids, null, 'id');
  931. if (empty($infoList)) {
  932. util::fail('没有花材');
  933. }
  934. foreach ($infoList as $info) {
  935. if (isset($info['mainId']) == false || $info['mainId'] != $this->mainId) {
  936. util::fail('不是你的花材不能修改');
  937. }
  938. }
  939. //总店修改同步到所有门店
  940. $sjId = $shop->sjId ?? 0;
  941. $chainShopList = ShopClass::getAllByCondition(['sjId' => $sjId], null, '*', null, true);
  942. foreach ($itemData as $key => $data) {
  943. $id = $data['id'] ?? 0;
  944. unset($data['id']);
  945. ProductClass::updateById($id, $data);
  946. $ptItemId = $infoList[$id]['itemId'] ?? 0;
  947. if (empty($ptItemId)) {
  948. continue;
  949. }
  950. if (isset($shop->default) && $shop->default == 1 && isset($shop->dataSync) && $shop->dataSync == 1) {
  951. foreach ($chainShopList as $chainShop) {
  952. $currentMainId = $chainShop->mainId ?? 0;
  953. if ($currentMainId == $shop->mainId) {
  954. //前面已经修改过了,不需要重复修改
  955. continue;
  956. }
  957. ProductClass::updateByCondition(['mainId' => $currentMainId, 'itemId' => $ptItemId], $data);
  958. }
  959. }
  960. }
  961. util::complete('修改成功');
  962. }
  963. //批量修改加价 ssh 20211211
  964. public function actionBatchChangeAddPrice()
  965. {
  966. $shop = $this->shop;
  967. $join = $shop->join ?? 0;
  968. $default = $shop->default ?? 0;
  969. if ($join == 0 && $default == 0) {
  970. util::fail('当前直营分店,请切回总店操作');
  971. }
  972. $shopAdmin = $this->shopAdmin;
  973. if (isset($shopAdmin->super) == false || $shopAdmin->super != 1) {
  974. util::fail('超管才能操作');
  975. }
  976. $post = Yii::$app->request->post();
  977. $addData = $post['addData'] ?? '';
  978. if (empty($addData)) {
  979. util::fail('没有花材');
  980. }
  981. $itemData = json_decode($addData, true);
  982. if (is_array($itemData) == false) {
  983. util::fail('没有花材...');
  984. }
  985. $ids = array_column($itemData, 'id');
  986. $infoList = ProductClass::getByIds($ids, null, 'id');
  987. if (empty($infoList)) {
  988. util::fail('没有花材');
  989. }
  990. foreach ($infoList as $info) {
  991. if (isset($info['mainId']) == false || $info['mainId'] != $this->mainId) {
  992. util::fail('不能修改别人的花材');
  993. }
  994. }
  995. $appVersion = $post['appVersion'] ?? 0;
  996. if ($appVersion != 1) {
  997. util::fail('请先升级应用');
  998. }
  999. //总店修改同步到所有门店
  1000. $sjId = $shop->sjId ?? 0;
  1001. $chainShopList = ShopClass::getAllByCondition(['sjId' => $sjId], null, '*', null, true);
  1002. foreach ($itemData as $key => $data) {
  1003. $id = $data['id'] ?? 0;
  1004. unset($data['id']);
  1005. ProductClass::updateById($id, $data);
  1006. $ptItemId = $infoList[$id]['itemId'] ?? 0;
  1007. if (empty($ptItemId)) {
  1008. continue;
  1009. }
  1010. if (isset($shop->default) && $shop->default == 1 && isset($shop->dataSync) && $shop->dataSync == 1) {
  1011. foreach ($chainShopList as $chainShop) {
  1012. if (isset($chainShop->join) && $chainShop->join == 1) {
  1013. continue;
  1014. }
  1015. $currentMainId = $chainShop->mainId ?? 0;
  1016. if ($currentMainId == $shop->mainId) {
  1017. //前面已经修改过了,不需要重复修改
  1018. continue;
  1019. }
  1020. ProductClass::updateByCondition(['mainId' => $currentMainId, 'itemId' => $ptItemId], $data);
  1021. }
  1022. }
  1023. }
  1024. util::complete('修改成功');
  1025. }
  1026. public function actionUpdate()
  1027. {
  1028. $shopAdmin = $this->shopAdmin;
  1029. if (!isset($shopAdmin->super) || $shopAdmin->super != 1) {
  1030. util::fail('超管才能操作');
  1031. }
  1032. $shop = $this->shop;
  1033. $join = $shop->join ?? 0;
  1034. $default = $shop->default ?? 0;
  1035. if ($join == 0 && $default == 0) {
  1036. //因为盘点不能将花材盘成0,所以这边放出入口允许创始人在分店修改分店的花材库存
  1037. if ($shopAdmin->super != 1) {
  1038. util::fail('请先开通超管权限');
  1039. }
  1040. }
  1041. $deadline = $shop->deadline;
  1042. $deadTime = strtotime($deadline);
  1043. if (time() > $deadTime) {
  1044. util::fail('系统已到期,编号1689');
  1045. }
  1046. $post = Yii::$app->request->post();
  1047. $discountPrice = $post['discountPrice'] ?? 0;
  1048. if ($discountPrice > 0) {
  1049. if (empty($post['hjDiscountPrice'])) {
  1050. $addPrice = $post['addPrice'] ?? 0;
  1051. $hjAddPrice = $post['hjAddPrice'] ?? 0;
  1052. $skMore = $post['skMore'] ?? 0;
  1053. $diff = bcsub($addPrice, $hjAddPrice, 2);
  1054. if ($diff > 0 && $discountPrice > $diff) {
  1055. $hjDiscountPrice = bcsub($discountPrice, $diff, 2);
  1056. } else {
  1057. $hjDiscountPrice = $discountPrice;
  1058. }
  1059. $diff = bcsub($skMore, $addPrice, 2);
  1060. if ($diff > 0) {
  1061. $skDiscountPrice = bcadd($diff, $discountPrice, 2);
  1062. } else {
  1063. $skDiscountPrice = $discountPrice;
  1064. }
  1065. $post['skDiscountPrice'] = $skDiscountPrice;
  1066. $post['hjDiscountPrice'] = $hjDiscountPrice;
  1067. }
  1068. $reachNum = $post['reachNum'] ?? 0;
  1069. $reachNumDiscount = $post['reachNumDiscount'] ?? 0;
  1070. if ($reachNum > 0 && $reachNumDiscount > 0) {
  1071. util::fail('特价和满减不能同时进行');
  1072. }
  1073. }
  1074. $post['adminId'] = $this->adminId;
  1075. $post['staffId'] = $this->shopAdmin->id;
  1076. $post['staffName'] = $this->shopAdmin->name;
  1077. // 图片列表数组转换为字符串
  1078. if (is_array($post['images'])) {
  1079. $post['images'] = implode(',', $post['images']);
  1080. }
  1081. $connection = Yii::$app->db;
  1082. $transaction = $connection->beginTransaction();
  1083. try {
  1084. ProductClass::updateProduct($post, $this->shop);
  1085. $transaction->commit();
  1086. util::complete();
  1087. } catch (\Exception $e) {
  1088. Yii::info("操作失败:" . $e->getMessage());
  1089. $transaction->rollBack();
  1090. util::fail('操作失败');
  1091. }
  1092. }
  1093. //上下架状态控制 ssh 20210713
  1094. public function actionStatusUpdate()
  1095. {
  1096. $post = Yii::$app->request->post();
  1097. $shopAdmin = $this->shopAdmin;
  1098. $roleId = $shopAdmin['roleId'] ?? 0;
  1099. $role = AdminRoleClass::getById($roleId);
  1100. $roleName = $role['roleName'] ?? '';
  1101. if ($roleName == '员工') {
  1102. util::fail('无法操作哦');
  1103. }
  1104. $id = $post['id'] ?? 0;
  1105. $status = $post['status'] ?? 1;
  1106. $product = ProductClass::getById($id, true);
  1107. if ($product->mainId != $this->mainId) {
  1108. util::fail('无法操作');
  1109. }
  1110. $product->status = $status;
  1111. if ($status == 2) {
  1112. $product->discountPrice = 0;
  1113. }
  1114. $product->save();
  1115. util::complete();
  1116. }
  1117. //花材展示状态控制 ssh 20231113
  1118. public function actionDelStatusUpdate()
  1119. {
  1120. $post = Yii::$app->request->post();
  1121. $shop = $this->shop;
  1122. $join = $shop->join ?? 0;
  1123. $default = $shop->default ?? 0;
  1124. if ($join == 0 && $default == 0) {
  1125. util::fail('请在首店操作');
  1126. }
  1127. $id = $post['id'] ?? 0;
  1128. $delStatus = $post['delStatus'] ?? 0;
  1129. $product = ProductClass::getById($id, true);
  1130. if ($product->mainId != $this->mainId) {
  1131. util::fail('不是你的花材哦!!');
  1132. }
  1133. //扫码收款、直接收款和特价商品,不可删除,多处要同步修改 system_item
  1134. if (getenv('YII_ENV') == 'production') {
  1135. $systemItem = [78076, 80960, 81004];
  1136. } else {
  1137. $systemItem = [11157, 11156, 11158];
  1138. }
  1139. if (in_array($product->itemId, $systemItem)) {
  1140. util::fail('系统使用花材,不可删除');
  1141. }
  1142. $product->delStatus = $delStatus;
  1143. if ($delStatus == 1) {
  1144. $product->stock = 0;
  1145. $product->status = 2;
  1146. }
  1147. $product->save();
  1148. $ptItemId = $product->itemId ?? 0;
  1149. if (isset($shop->default) && $shop->default == 1 && isset($shop->dataSync) && $shop->dataSync == 1) {
  1150. //总店修改同步到所有门店
  1151. $sjId = $shop->sjId ?? 0;
  1152. $chainShopList = ShopClass::getAllByCondition(['sjId' => $sjId], null, '*', null, true);
  1153. foreach ($chainShopList as $chainShop) {
  1154. $chainShopId = $chainShop->id ?? 0;
  1155. if (isset($chainShop->join) && $chainShop->join == 1) {
  1156. continue;
  1157. }
  1158. if ($chainShopId == $shop->id) {
  1159. continue;
  1160. }
  1161. $chainMainId = $chainShop->mainId ?? 0;
  1162. $chainProduct = ProductClass::getByCondition(['mainId' => $chainMainId, 'itemId' => $ptItemId], true);
  1163. if (!empty($chainProduct)) {
  1164. $chainProduct->delStatus = $delStatus;
  1165. if ($delStatus == 1) {
  1166. $chainProduct->stock = 0;
  1167. $chainProduct->status = 2;
  1168. }
  1169. $chainProduct->save();
  1170. }
  1171. }
  1172. }
  1173. util::complete();
  1174. }
  1175. //详情 shish 20240115
  1176. public function actionDetail()
  1177. {
  1178. $id = Yii::$app->request->get('id', 0);
  1179. $source = Yii::$app->request->get('source', '');
  1180. $respond = ProductClass::getItemInfo($id);
  1181. $ptItemId = $respond['itemId'] ?? 0;
  1182. // 封面图与多花材图片的兼容处理
  1183. if ($respond['images'] == '' && $respond['shortCover'] != '') {
  1184. $respond['images'] = $respond['shortCover'];
  1185. }
  1186. $ptItemInfo = PtItemClass::getById($ptItemId);
  1187. $respond['ptItemInfo'] = $ptItemInfo;
  1188. //通知提醒抹除
  1189. if ($source == 'notify' && $respond['mainId'] == $this->mainId) {
  1190. $staff = $this->shopAdmin;
  1191. $staffId = $this->shopAdminId;
  1192. $notify = NotifyClass::getByCondition(['staffId' => $staffId, 'type' => 1, 'targetId' => $id], true);
  1193. if (!empty($notify)) {
  1194. if ($notify->read == 0) {
  1195. $notify->read = 1;
  1196. $notify->save();
  1197. $notifyNum = $staff->notifyNum;
  1198. if ($notifyNum > 0) {
  1199. $notifyNum--;
  1200. $staff->notifyNum = $notifyNum;
  1201. $staff->save();
  1202. }
  1203. }
  1204. }
  1205. }
  1206. //重复花材
  1207. $repeatList = ProductClass::getAllByCondition(['mainId' => $this->mainId, 'itemId' => $ptItemId, 'delStatus' => 0], null, '*', null, true);
  1208. $repeatId = 0;
  1209. if (!empty($repeatList)) {
  1210. foreach ($repeatList as $repeat) {
  1211. if ($repeat->id != $id) {
  1212. $repeatId = $repeat->id;
  1213. }
  1214. }
  1215. }
  1216. $respond['repeatId'] = $repeatId;
  1217. $cpItemList = CpItemClass::getAllByCondition(['productId' => $id], null, '*', 'cpId');
  1218. $cpInfo = [];
  1219. if (!empty($cpItemList)) {
  1220. $cpIds = array_column($cpItemList, 'cpId');
  1221. $cpList = CpClass::getByIds($cpIds);
  1222. if (!empty($cpList)) {
  1223. foreach ($cpList as $key => $val) {
  1224. $id = $val['id'] ?? 0;
  1225. $name = $val['name'] ?? '';
  1226. $cpInfo[] = ['cpId' => $id, 'cpName' => $name];
  1227. }
  1228. }
  1229. }
  1230. //判断这个花材能否被修改单位比和重量,同步参考ShopController actionMyShop方法,关键词has_right_shop_list
  1231. //判断当前登录的人,在自己有财务权限的main里面,是否包括了这个花材所属的平台id,在这个平台id下所有花材的main
  1232. $adminId = $this->adminId;
  1233. $hasRightRespond = ShopAdminClass::changeWeightRight($adminId, $ptItemId);
  1234. $respond['hasRightChange'] = $hasRightRespond['hasRightChange'];
  1235. $respond['hasRightChangeReason'] = $hasRightRespond['reason'];
  1236. //查出拆散的子花材
  1237. $part = UnitChangeClass::getByCondition(['big' => $id], true);
  1238. $partAcceptItem = 0;
  1239. $partAcceptItemName = '';
  1240. if (!empty($part)) {
  1241. $partAcceptItem = $part->small;
  1242. $small = ProductClass::getByCondition(['id' => $partAcceptItem], true, false, 'id,name');
  1243. $partAcceptItemName = $small->name ?? '';;
  1244. }
  1245. $respond['partAcceptItem'] = $partAcceptItem;
  1246. $respond['partAcceptItemName'] = $partAcceptItemName;
  1247. $respond['cpInfo'] = $cpInfo;
  1248. util::success($respond);
  1249. }
  1250. //新增花材 2021.6.21
  1251. public function actionAdd()
  1252. {
  1253. $post = Yii::$app->request->post();
  1254. $discountPrice = $post['discountPrice'] ?? 0;
  1255. if ($discountPrice > 0) {
  1256. if (isset($post['hjDiscountPrice']) == false || empty($post['hjDiscountPrice'])) {
  1257. $addPrice = $post['addPrice'] ?? 0;
  1258. $hjAddPrice = $post['hjAddPrice'] ?? 0;
  1259. $skMore = $post['skMore'] ?? 0;
  1260. $diff = bcsub($addPrice, $hjAddPrice, 2);
  1261. if ($diff > 0 && $discountPrice > $diff) {
  1262. $hjDiscountPrice = bcsub($discountPrice, $diff, 2);
  1263. } else {
  1264. $hjDiscountPrice = $discountPrice;
  1265. }
  1266. $diff = bcsub($skMore, $addPrice, 2);
  1267. if ($diff > 0) {
  1268. $skDiscountPrice = bcadd($diff, $discountPrice, 2);
  1269. } else {
  1270. $skDiscountPrice = $discountPrice;
  1271. }
  1272. $post['skDiscountPrice'] = $skDiscountPrice;
  1273. $post['hjDiscountPrice'] = $hjDiscountPrice;
  1274. }
  1275. }
  1276. $shop = $this->shop;
  1277. $join = $shop->join ?? 0;
  1278. $default = $shop->default ?? 0;
  1279. if ($join == 0 && $default == 0) {
  1280. util::fail('当前直营分店,请切回总店添加花材');
  1281. }
  1282. $shopAdmin = $this->shopAdmin;
  1283. if (!isset($shopAdmin->super) || $shopAdmin->super != 1) {
  1284. util::fail('管理员才能添加花材');
  1285. }
  1286. $post['sjId'] = $this->sjId;
  1287. $post['adminId'] = $this->adminId;
  1288. $post['mainId'] = $this->mainId;
  1289. $price = $post['price'] ?? 0;
  1290. $addPrice = $post['addPrice'] ?? 0;
  1291. if ($addPrice > $price) {
  1292. //客户添加花材时,经常会出现加价大于售价的怦,这个时候就直接把加价全部设置为0
  1293. $post['addPrice'] = 0;
  1294. $post['hjAddPrice'] = 0;
  1295. $post['skMore'] = 0;
  1296. //util::fail('加价不能大于售价');
  1297. }
  1298. $weight = isset($post['weight']) && is_numeric($post['weight']) ? $post['weight'] : 0;
  1299. if ($weight <= 0) {
  1300. util::fail('请填写重量,最小0.1');
  1301. }
  1302. $post['staffName'] = $shopAdmin->name ?? '';
  1303. // 图片列表数组转换为字符串
  1304. if (is_array($post['images'])) {
  1305. $post['images'] = implode(',', $post['images']);
  1306. }
  1307. ProductClass::addProduct($post, $this->shop);
  1308. util::complete('添加成功');
  1309. }
  1310. //获取拼音缩写 ssh 20210707
  1311. public function actionPy()
  1312. {
  1313. $name = Yii::$app->request->get('name');
  1314. $py = stringUtil::py($name);
  1315. util::success(['py' => $py]);
  1316. }
  1317. //(客户端-批发商)复制花材
  1318. public function actionClone()
  1319. {
  1320. $post = Yii::$app->request->post();
  1321. $discountPrice = $post['discountPrice'] ?? 0;
  1322. if ($discountPrice > 0) {
  1323. if (isset($post['hjDiscountPrice']) == false || empty($post['hjDiscountPrice'])) {
  1324. $addPrice = $post['addPrice'] ?? 0;
  1325. $hjAddPrice = $post['hjAddPrice'] ?? 0;
  1326. $skMore = $post['skMore'] ?? 0;
  1327. $diff = bcsub($addPrice, $hjAddPrice, 2);
  1328. if ($diff > 0 && $discountPrice > $diff) {
  1329. $hjDiscountPrice = bcsub($discountPrice, $diff, 2);
  1330. } else {
  1331. $hjDiscountPrice = $discountPrice;
  1332. }
  1333. $diff = bcsub($skMore, $addPrice, 2);
  1334. if ($diff > 0) {
  1335. $skDiscountPrice = bcadd($diff, $discountPrice, 2);
  1336. } else {
  1337. $skDiscountPrice = $discountPrice;
  1338. }
  1339. $post['skDiscountPrice'] = $skDiscountPrice;
  1340. $post['hjDiscountPrice'] = $hjDiscountPrice;
  1341. }
  1342. }
  1343. $shop = $this->shop;
  1344. $join = $shop->join ?? 0;
  1345. $default = $shop->default ?? 0;
  1346. if ($join == 0 && $default == 0) {
  1347. util::fail('请在首店操作');
  1348. }
  1349. $shopAdmin = $this->shopAdmin;
  1350. if (isset($shopAdmin->super) == false || $shopAdmin->super != 1) {
  1351. util::fail('管理员才能添加花材');
  1352. }
  1353. $post['sjId'] = $this->sjId;
  1354. $post['adminId'] = $this->adminId;
  1355. $post['mainId'] = $this->mainId;
  1356. $post['staffName'] = $shopAdmin->name ?? '';
  1357. $price = $post['price'] ?? 0;
  1358. if (empty($price) || $price <= 0) {
  1359. util::fail('请填写批发价');
  1360. }
  1361. $skPrice = $post['skPrice'] ?? 0;
  1362. if (empty($skPrice) || $skPrice <= 0) {
  1363. util::fail('请填写零售价');
  1364. }
  1365. $hjPrice = $post['hjPrice'] ?? 0;
  1366. if (empty($hjPrice) || $hjPrice <= 0) {
  1367. util::fail('请填写会员价');
  1368. }
  1369. $addPrice = $post['addPrice'] ?? 0;
  1370. if ($addPrice > $price) {
  1371. util::fail('批发价的加价不能大于售价');
  1372. }
  1373. // 图片列表数组转换为字符串
  1374. if (is_array($post['images'])) {
  1375. $post['images'] = implode(',', $post['images']);
  1376. }
  1377. //复制标识
  1378. $post['copy'] = 1;
  1379. //去除无用的字段
  1380. unset($post['viewNum']);
  1381. unset($post['actualSold']);
  1382. unset($post['itemId']);
  1383. unset($post['id']);
  1384. unset($post['delStatus']);
  1385. unset($post['variety']);
  1386. ProductClass::addProduct($post, $this->shop);
  1387. util::complete('复制成功');
  1388. }
  1389. //下载价格表 ssh 20210922
  1390. public function actionGeneratePriceTable()
  1391. {
  1392. $level = Yii::$app->request->get('level', 0);
  1393. $respond = ProductService::generatePriceTable($this->sjId, $level, $this->mainId);
  1394. $file = $respond['file'] ?? '';
  1395. $shortFile = $respond['shortFile'] ?? '';
  1396. $fileUrl = Yii::$app->params['ghsHost'] . $file;
  1397. util::success(['file' => $fileUrl, 'shortFile' => $shortFile]);
  1398. }
  1399. //下载有库存花材,不含虚拟库存 ssh 20241-28
  1400. public function actionGenerateStockTable()
  1401. {
  1402. $level = Yii::$app->request->get('level', 0);
  1403. $respond = ProductService::generateStockTable($this->sjId, $level, $this->mainId);
  1404. $file = $respond['file'] ?? '';
  1405. $shortFile = $respond['shortFile'] ?? '';
  1406. $fileUrl = Yii::$app->params['ghsHost'] . $file;
  1407. util::success(['file' => $fileUrl, 'shortFile' => $shortFile]);
  1408. }
  1409. public function actionGenerateItemTable()
  1410. {
  1411. $level = Yii::$app->request->get('level', 0);
  1412. $respond = ProductService::generateItemTable($this->sjId, $level, $this->mainId);
  1413. $file = $respond['file'] ?? '';
  1414. $shortFile = $respond['shortFile'] ?? '';
  1415. $fileUrl = Yii::$app->params['ghsHost'] . $file;
  1416. util::success(['file' => $fileUrl, 'shortFile' => $shortFile]);
  1417. }
  1418. //下载条形码 lqh 20211227
  1419. public function actionGenerateBarcodeTable()
  1420. {
  1421. $respond = ProductService::generateBarcodeTable($this->sjId, $this->shopId, $this->mainId);
  1422. $file = $respond['file'] ?? '';
  1423. $shortFile = $respond['shortFile'] ?? '';
  1424. $fileUrl = Yii::$app->params['ghsHost'] . $file;
  1425. util::success(['file' => $fileUrl, 'shortFile' => $shortFile]);
  1426. }
  1427. //批量修改花材的分类 ssh 20230405
  1428. public function actionBatchModifyClass()
  1429. {
  1430. $post = Yii::$app->request->post();
  1431. $shop = $this->shop;
  1432. $sjName = $shop->merchantName ?? '';
  1433. $shopName = $shop->shopName ?? '';
  1434. $sjShopName = $shop->shopName == '首店' ? $sjName : $sjName . ' ' . $shopName;
  1435. //noticeUtil::push($sjShopName . ' 批量移动花材分类', '15280215347');
  1436. $join = $shop->join ?? 0;
  1437. $default = $shop->default ?? 0;
  1438. if ($join == 0 && $default == 0) {
  1439. util::fail('当前直营分店,请切回总店操作');
  1440. }
  1441. $classId = $post['classId'] ?? 0;
  1442. $class = ItemClassClass::getById($classId, true);
  1443. if (empty($class) || $class->mainId != $this->mainId) {
  1444. util::fail('请选择您自己的分类');
  1445. }
  1446. $connection = Yii::$app->db;
  1447. $transaction = $connection->beginTransaction();
  1448. try {
  1449. $className = $class->name ?? '';
  1450. $idsList = $post['ids'] ?? '';
  1451. $ids = json_decode($idsList, true);
  1452. if (empty($ids)) {
  1453. util::fail('请选择花材');
  1454. }
  1455. $list = ProductClass::getAllByCondition(['id' => ['in', $ids]], null, '*', null, true);
  1456. if (empty($list)) {
  1457. util::fail('请选择花材');
  1458. }
  1459. $ptItemList = [];
  1460. foreach ($list as $item) {
  1461. $name = $item->name ?? '';
  1462. if ($item->mainId != $this->mainId) {
  1463. util::fail($name . '不是您的花材');
  1464. }
  1465. $item->classId = $classId;
  1466. $item->save();
  1467. $ptItemId = $item->itemId ?? 0;
  1468. $ptItemList[] = $ptItemId;
  1469. //如果有修改分类,则在多个订单表中同步修改,如需修改,多个地方要同步修改,请搜索关键词item_class_modify_sync
  1470. $itemClassKey = 'item_class_modify_sync';
  1471. Yii::$app->redis->executeCommand('LPUSH', [$itemClassKey, $item->id]);
  1472. }
  1473. $shop = $this->shop;
  1474. if (isset($shop->default) && $shop->default == 1 && isset($shop->dataSync) && $shop->dataSync == 1) {
  1475. //总店修改同步到所有门店
  1476. $sjId = $shop->sjId ?? 0;
  1477. $chainShopList = ShopClass::getAllByCondition(['sjId' => $sjId], null, '*', null, true);
  1478. foreach ($chainShopList as $chainShop) {
  1479. $chainShopId = $chainShop->id ?? 0;
  1480. if ($chainShopId == $shop->id) {
  1481. continue;
  1482. }
  1483. $chainManId = $chainShop->mainId ?? 0;
  1484. $chainAllClassList = ItemClassClass::getAllByCondition(['mainId' => $chainManId], null, '*', null, true);
  1485. if (!empty($chainAllClassList)) {
  1486. foreach ($chainAllClassList as $chainClass) {
  1487. $chainName = $chainClass->name ?? '';
  1488. $chainClassId = $chainClass->id ?? 0;
  1489. if ($chainName == $className) {
  1490. $chainProductList = Productclass::getAllByCondition(['mainId' => $chainManId, 'itemId' => ['in', $ptItemList]], null, '*', null, true);
  1491. if (!empty($chainProductList)) {
  1492. foreach ($chainProductList as $currentProduct) {
  1493. $currentProduct->classId = $chainClassId;
  1494. $currentProduct->save();
  1495. //如果有修改分类,则在多个订单表中同步修改,如需修改,多个地方要同步修改,请搜索关键词item_class_modify_sync
  1496. $itemClassKey = 'item_class_modify_sync';
  1497. Yii::$app->redis->executeCommand('LPUSH', [$itemClassKey, $currentProduct->id]);
  1498. }
  1499. }
  1500. }
  1501. }
  1502. }
  1503. }
  1504. }
  1505. $transaction->commit();
  1506. util::complete('修改成功');
  1507. } catch (\Exception $e) {
  1508. $transaction->rollBack();
  1509. Yii::info("修改失败原因:" . $e->getMessage());
  1510. util::fail('修改失败');
  1511. }
  1512. }
  1513. //批量修改采购人 ssh 20240609
  1514. public function actionBatchModifyCgStaff()
  1515. {
  1516. $post = Yii::$app->request->post();
  1517. $staffId = $post['staffId'] ?? 0;
  1518. $staff = ShopAdminClass::getById($staffId, true);
  1519. if (empty($staff)) {
  1520. util::fail('没有找到这个员工');
  1521. }
  1522. if ($staff->mainId != $this->mainId) {
  1523. util::fail('不是你的员工');
  1524. }
  1525. $staffName = $staff->name ?? '';
  1526. $connection = Yii::$app->db;
  1527. $transaction = $connection->beginTransaction();
  1528. try {
  1529. $idsList = $post['ids'] ?? '';
  1530. $ids = json_decode($idsList, true);
  1531. if (empty($ids)) {
  1532. util::fail('请选择花材');
  1533. }
  1534. $list = ProductClass::getAllByCondition(['id' => ['in', $ids]], null, '*', null, true);
  1535. if (empty($list)) {
  1536. util::fail('请选择花材');
  1537. }
  1538. $shop = $this->shop;
  1539. $bookSn = $shop->bookSn ?? 0;
  1540. foreach ($list as $item) {
  1541. $name = $item->name ?? '';
  1542. if ($item->mainId != $this->mainId) {
  1543. util::fail($name . '不是您的花材');
  1544. }
  1545. $item->cgStaffId = $staffId;
  1546. $item->cgStaffName = $staffName;
  1547. $item->save();
  1548. $itemId = $item->id ?? 0;
  1549. if (!empty($bookSn)) {
  1550. //预订管理的花材需要变化
  1551. BookItemClass::updateByCondition(['bookSn' => $bookSn, 'itemId' => $itemId], ['cgStaffId' => $staffId, 'cgStaffName' => $staffName]);
  1552. }
  1553. }
  1554. $transaction->commit();
  1555. util::complete('修改成功');
  1556. } catch (\Exception $e) {
  1557. $transaction->rollBack();
  1558. Yii::info("修改失败原因:" . $e->getMessage());
  1559. util::fail('修改失败');
  1560. }
  1561. }
  1562. //修改属于成本还是收入选项 ssh 20240514
  1563. public function actionChangeBelongCost()
  1564. {
  1565. $get = Yii::$app->request->get();
  1566. $id = $get['id'] ?? 0;
  1567. $belongCost = $get['belongCost'] ?? 0;
  1568. $info = ProductClass::getById($id, true);
  1569. if (empty($info)) {
  1570. util::fail('没有找到花材');
  1571. }
  1572. if ($info->mainId != $this->mainId) {
  1573. util::fail('不是你的花材哦');
  1574. }
  1575. $info->belongCost = $belongCost;
  1576. $info->save();
  1577. //队列方式去处理
  1578. $redisKey = 'change_belong_cost_item_list';
  1579. $value = $id . '_' . $belongCost;
  1580. Yii::$app->redis->executeCommand('LPUSH', [$redisKey, $value]);
  1581. util::complete('修改成功');
  1582. }
  1583. //修改拆散接收的花材 ssh 20251124
  1584. public function actionModifyPartAcceptItem()
  1585. {
  1586. $get = Yii::$app->request->get();
  1587. $smallId = $get['small'] ?? 0;
  1588. $bigId = $get['big'] ?? 0;
  1589. $small = ProductClass::getById($smallId, true);
  1590. if (empty($small)) {
  1591. util::fail('子花材没找到');
  1592. }
  1593. $smallName = $small->name ?? '';
  1594. if ($small->mainId != $this->mainId) {
  1595. util::fail($smallName . '不是你的花材');
  1596. }
  1597. if ($small->ratio != 1) {
  1598. util::fail($smallName . '不是1支装的');
  1599. }
  1600. $big = ProductClass::getById($bigId, true);
  1601. if (empty($big)) {
  1602. util::fail('没有找到花材');
  1603. }
  1604. if ($big->mainId != $this->mainId) {
  1605. util::fail('不是你的花材呢');
  1606. }
  1607. $change = UnitChangeClass::getByCondition(['big' => $bigId], true);
  1608. if (empty($change)) {
  1609. UnitChangeClass::add(['big' => $bigId, 'small' => $smallId], true);
  1610. } else {
  1611. $change->small = $smallId;
  1612. $change->save();
  1613. }
  1614. util::complete('修改成功');
  1615. }
  1616. }