ProductController.php 65 KB

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