ProductController.php 65 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587
  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,addPrice,hjAddPrice,skMore';
  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,addPrice,hjAddPrice,skMore';
  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. $get = Yii::$app->request->get();
  454. $where = [];
  455. $classId = Yii::$app->request->get('classId', 0);
  456. if (!empty($classId)) {
  457. $where['classId'] = $classId;
  458. }
  459. $name = Yii::$app->request->get('name', '');
  460. if (empty($name)) {
  461. $py = Yii::$app->request->get('py', '');
  462. $name = !empty($py) ? $py : '';
  463. }
  464. if (!empty($name)) {
  465. if (stringUtil::isLetter($name)) {
  466. $where['py'] = ['like', $name];
  467. } else {
  468. $where['name'] = ['like', $name];
  469. }
  470. }
  471. $status = Yii::$app->request->get('status', 0);
  472. if (!empty($status)) {
  473. $where['status'] = $status;
  474. }
  475. $delStatus = Yii::$app->request->get('delStatus', 0);
  476. if ($delStatus != 2) {
  477. $where['delStatus'] = $delStatus;
  478. }
  479. $where['mainId'] = $this->mainId;
  480. $productIds = Yii::$app->request->get('ids', '');
  481. if (!empty($productIds)) {
  482. $productIdArr = explode(',', $productIds);
  483. if (!empty($productIdArr)) {
  484. $where['id'] = ['in', $productIdArr];
  485. }
  486. }
  487. //输出标准会员价,即批发价,默认显示的是批发价
  488. $level = 1;
  489. $type = Yii::$app->request->get('type', '');
  490. $showPage = Yii::$app->request->get('showPage', 0);
  491. if ($showPage) {
  492. if ($type == 'waring') {
  493. $pro = Product::find()->where("mainId={$this->mainId}")->andWhere('`stock`<`stockWarning`')->select('id')->asArray()->all();
  494. $lackIds = array_column($pro, 'id');
  495. if (empty($lackIds)) {
  496. util::success([]);
  497. }
  498. $lackIds = array_filter(array_unique($lackIds));
  499. $where['id'] = ['in', $lackIds];
  500. $respond = ProductClass::getList("*", $where, "actualSold desc");
  501. } else {
  502. $hasStock = $get['hasStock']??-1;
  503. if($hasStock == 0){
  504. $where['stock']=0;
  505. }
  506. if($hasStock == 1){
  507. $where['stock>']=0;
  508. }
  509. $respond = ProductClass::getList("*", $where, "inTurn desc");
  510. }
  511. $respond['list'] = ProductClass::groupProductInfo($respond['list'], $level);
  512. $respond['list'] = ProductClass::groupClassName($this->mainId, $respond['list']);
  513. util::success($respond);
  514. } else {
  515. if ($type == 'waring') {
  516. //库存预警 按库存从小到大排序
  517. $data = ProductClass::getAllByCondition($where, ['stock' => SORT_ASC, 'inTurn' => SORT_DESC], "*");
  518. } else {
  519. if (!empty($productIds)) {
  520. //优先按 $productIds 排序 "FIELD(`id`,4,5,6)"=>true
  521. $data = ProductClass::getAllByCondition($where, ["FIELD(`id`,$productIds)" => true, 'inTurn' => SORT_DESC], "*");
  522. } else {
  523. $data = ProductClass::getAllByCondition($where, ['actualSold' => SORT_DESC, 'inTurn' => SORT_DESC], "*");
  524. }
  525. }
  526. $data = ProductClass::groupProductInfo($data, $level);
  527. $data = ProductClass::groupClassName($this->mainId, $data);
  528. if ($type == 'waring') {
  529. //库存预警
  530. $newData = [];
  531. foreach ($data as $v) {
  532. if ($v['stock'] <= $v['stockWarning']) {
  533. $newData[] = $v;
  534. }
  535. }
  536. util::success(['list' => $newData]);
  537. }
  538. util::success(['list' => $data]);
  539. }
  540. }
  541. //所有花材
  542. public function actionAll()
  543. {
  544. $where = [];
  545. $where['mainId'] = $this->mainId;
  546. $classId = Yii::$app->request->get('classId', 0);
  547. if (!empty($classId)) {
  548. $where['classId'] = $classId;
  549. }
  550. $status = Yii::$app->request->get('status', 0);
  551. if (!empty($status)) {
  552. $where['status'] = $status;
  553. }
  554. $delStatus = Yii::$app->request->get('delStatus', 0);
  555. if ($delStatus != 2) {
  556. $where['delStatus'] = $delStatus;
  557. }
  558. //输出标准会员价,即批发价,默认显示的是批发价
  559. $level = 1;
  560. $data = ProductClass::getAllByCondition($where, ['actualSold' => SORT_DESC, 'inTurn' => SORT_DESC], "*");
  561. $data = ProductClass::groupProductInfo($data, $level);
  562. util::success(['list' => $data]);
  563. }
  564. //批量改价
  565. public function actionBatchChangePrice()
  566. {
  567. $shop = $this->shop;
  568. $join = $shop->join ?? 0;
  569. $default = $shop->default ?? 0;
  570. if ($join == 0 && $default == 0) {
  571. util::fail('直营分店不能改价');
  572. }
  573. $shopAdmin = $this->shopAdmin;
  574. if (isset($shopAdmin->super) == false || $shopAdmin->super != 1) {
  575. util::fail('超管才能修改');
  576. }
  577. $shop = $this->shop;
  578. $default = $shop->default ?? 0;
  579. $adminId = $this->adminId ?? 0;
  580. //normal常规改价,cg采购改价
  581. $changeType = Yii::$app->request->post('changeType', 'normal');
  582. $targetId = Yii::$app->request->post('targetId', 0);
  583. $changeParams = ['staffId' => $shopAdmin->id, 'staffName' => $shopAdmin->name, 'changeType' => $changeType, 'targetId' => $targetId];
  584. $post = Yii::$app->request->post();
  585. $data = $post['data'] ?? '';
  586. if (empty($data)) {
  587. util::fail('没有修改');
  588. }
  589. $arr = json_decode($data, true);
  590. if (empty($arr)) {
  591. util::fail('没有修改哦');
  592. }
  593. $appVersion = $post['appVersion'] ?? 0;
  594. if ($appVersion != 1) {
  595. util::fail('请先升级应用');
  596. }
  597. //解决重复请求问题
  598. $cacheKey = 'batch_change_price_' . $targetId;
  599. $has = Yii::$app->redis->executeCommand('GET', [$cacheKey]);
  600. if (!empty($has)) {
  601. util::fail('请5秒后操作');
  602. }
  603. Yii::$app->redis->executeCommand('SETEX', [$cacheKey, 5, 'has']);
  604. $connection = Yii::$app->db;
  605. $transaction = $connection->beginTransaction();
  606. try {
  607. $needNotice = false;
  608. $cg = PurchaseOrderClass::getLockById($targetId);
  609. if (!empty($cg)) {
  610. if (isset($cg->mainId) == false || $cg->mainId != $this->mainId) {
  611. util::fail('不是您的采购单');
  612. }
  613. //批量改价同时入库
  614. if ($cg->status == PurchaseOrderClass::PURCHASE_ORDER_STATUS_SENDING) {
  615. $staff = $this->shopAdmin;
  616. $data = [];
  617. $data['staffId'] = $staff->id ?? 0;
  618. $data['staffName'] = $staff->name ?? '';
  619. $data['adminId'] = $this->adminId ?? 0;
  620. $data['shop'] = $this->shop;
  621. PurchaseOrderClass::putIn($cg, $data);
  622. $needNotice = true;
  623. }
  624. }
  625. $ids = array_column($arr, 'id');
  626. $ids = array_unique(array_filter($ids));
  627. if (empty($ids)) {
  628. util::fail('请选择花材');
  629. }
  630. $sjId = $shop->sjId ?? 0;
  631. $chainShopList = [];
  632. if ($default == 1) {
  633. $chainShopList = ShopClass::getAllByCondition(['sjId' => $sjId, 'join' => 0], null, '*', null, true);
  634. }
  635. $productList = ProductClass::getAllByCondition(['id' => ['in', $ids]], null, '*', 'id', true);
  636. foreach ($arr as $product) {
  637. $productId = $product['id'];
  638. $productInfo = $productList[$productId] ?? [];
  639. if (empty($productInfo)) {
  640. util::fail('没有找到花材');
  641. }
  642. $productName = $productInfo->name ?? '';
  643. if (isset($product['id']) == false) {
  644. util::fail('没有花材');
  645. }
  646. if (isset($product['price']) == false || is_numeric($product['price']) == false || $product['price'] < 0) {
  647. util::fail('请填写' . $productName . '的批发价');
  648. }
  649. $price = $product['price'];
  650. if (isset($product['skPrice']) == false || is_numeric($product['skPrice']) == false || $product['skPrice'] < 0) {
  651. util::fail('请填写' . $productName . '的零售价');
  652. }
  653. $skPrice = $product['skPrice'];
  654. if (isset($product['hjPrice']) == false || is_numeric($product['hjPrice']) == false || $product['hjPrice'] < 0) {
  655. util::fail('请填写' . $productName . '的会员价');
  656. }
  657. $hjPrice = $product['hjPrice'] ?? 0;
  658. if (isset($productInfo->mainId) == false || $productInfo->mainId != $this->mainId) {
  659. util::fail('无法访问');
  660. }
  661. if ($hjPrice > $price) {
  662. util::fail($productName . ' 批发价要大于会员价');
  663. }
  664. if ($price > $skPrice) {
  665. util::fail($productName . ' 零售价要大于批发价');
  666. }
  667. $ptItemId = $productInfo->itemId;
  668. ProductClass::changeSinglePrice($shop, $ptItemId, $price, $skPrice, $hjPrice, $changeParams);
  669. //在首店修改需要同步到所有直营店
  670. if ($default == 1 && isset($shop->dataSync) && $shop->dataSync == 1) {
  671. foreach ($chainShopList as $chain) {
  672. if ($chain->id == $shop->id) {
  673. continue;
  674. }
  675. $chainMainId = $chain->mainId ?? 0;
  676. $staff = ShopAdminClass::getByCondition(['mainId' => $chainMainId, 'adminId' => $adminId], true);
  677. $staffId = $staff->id ?? 0;
  678. $staffName = $staff->name ?? '';
  679. $changeParams2 = ['staffId' => $staffId, 'staffName' => $staffName, 'changeType' => $changeType, 'targetId' => $targetId];
  680. ProductClass::changeSinglePrice($chain, $ptItemId, $price, $skPrice, $hjPrice, $changeParams2);
  681. }
  682. }
  683. }
  684. $mainId = $shop->mainId ?? 0;
  685. if (!empty($mainId)) {
  686. //提醒零售收银台界面要刷新
  687. $staffList = ShopAdminClass::getAllByCondition(['mainId' => $mainId], null, '*', null, true);
  688. if (!empty($staffList)) {
  689. foreach ($staffList as $staff) {
  690. $staffId = $staff->id ?? 0;
  691. Yii::$app->redis->executeCommand('SET', ['cashier_' . $mainId . '_' . $staffId . '_may_refresh', 'yes']);
  692. Yii::$app->redis->executeCommand('SET', ['ghs_cashier_' . $mainId . '_' . $staffId . '_may_refresh', 'yes']);
  693. }
  694. }
  695. }
  696. $transaction->commit();
  697. //入库成功通知相关人员,关键词 put_in_notice
  698. if ($needNotice) {
  699. // $cg = PurchaseOrderClass::getLockById($targetId);
  700. // WxMessageClass::ghsCgEntryInform($shop, $cg);
  701. }
  702. util::complete('操作成功');
  703. } catch (\Exception $e) {
  704. $transaction->rollBack();
  705. $msg = $e->getMessage();
  706. Yii::info("修改失败原因:" . $msg);
  707. noticeUtil::push("修改价格出现失败情况,原因:" . $msg, '15280215347');
  708. util::fail('修改失败');
  709. }
  710. }
  711. //多个花材同时改成一个价 ssh 20231003
  712. public function actionManyItemChangeOnePrice()
  713. {
  714. $shop = $this->shop;
  715. $join = $shop->join ?? 0;
  716. $default = $shop->default ?? 0;
  717. if ($join == 0 && $default == 0) {
  718. util::fail('当前直营分店,只能回总店修改价格');
  719. }
  720. $shopAdmin = $this->shopAdmin;
  721. if (isset($shopAdmin->super) == false || $shopAdmin->super != 1) {
  722. util::fail('超管才能修改');
  723. }
  724. $post = Yii::$app->request->post();
  725. $idsList = $post['ids'] ?? '';
  726. $ids = json_decode($idsList, true);
  727. if (empty($ids)) {
  728. util::fail('请选择花材');
  729. }
  730. $list = ProductClass::getAllByCondition(['id' => ['in', $ids]], null, '*', null, true);
  731. if (empty($list)) {
  732. util::fail('请选择花材哦');
  733. }
  734. $mainId = $this->mainId;
  735. $adminId = $this->adminId ?? 0;
  736. $shop = $this->shop;
  737. $default = $shop->default ?? 0;
  738. $shopAdmin = $this->shopAdmin;
  739. $price = $post['price'] ?? 0;
  740. if (is_numeric($price) == false) {
  741. util::fail('批发价填写错误');
  742. }
  743. $skPrice = $post['skPrice'] ?? 0;
  744. if (is_numeric($skPrice) == false) {
  745. util::fail('散客价填写错误');
  746. }
  747. $hjPrice = $post['hjPrice'] ?? 0;
  748. if (is_numeric($hjPrice) == false) {
  749. util::fail('会员价填写错误');
  750. }
  751. if ($hjPrice > $price) {
  752. util::fail('会员价不能大于批发价');
  753. }
  754. if ($price > $skPrice) {
  755. util::fail('批发价不能大于零售价');
  756. }
  757. $sjId = $shop->sjId ?? 0;
  758. $chainShopList = [];
  759. if ($default == 1) {
  760. $chainShopList = ShopClass::getAllByCondition(['sjId' => $sjId, 'join' => 0], null, '*', null, true);
  761. }
  762. //normal常规改价,cg采购改价
  763. $changeType = Yii::$app->request->post('changeType', 'normal');
  764. $targetId = 0;
  765. $changeParams = ['staffId' => $shopAdmin->id, 'staffName' => $shopAdmin->name, 'changeType' => $changeType, 'targetId' => $targetId];
  766. $connection = Yii::$app->db;
  767. $transaction = $connection->beginTransaction();
  768. try {
  769. foreach ($list as $product) {
  770. if ($product->mainId != $mainId) {
  771. util::fail('修改失败,不是你的花材');
  772. }
  773. $ptItemId = $product->itemId;
  774. ProductClass::changeSinglePrice($shop, $ptItemId, $price, $skPrice, $hjPrice, $changeParams);
  775. //在首店修改需要同步到所有直营店
  776. if ($default == 1 && isset($shop->dataSync) && $shop->dataSync == 1) {
  777. if (!empty($chainShopList)) {
  778. foreach ($chainShopList as $chain) {
  779. if ($chain->id == $shop->id) {
  780. continue;
  781. }
  782. $chainMainId = $chain->mainId ?? 0;
  783. $staff = ShopAdminClass::getByCondition(['mainId' => $chainMainId, 'adminId' => $adminId], true);
  784. $changeParams2 = ['staffId' => $staff->id, 'staffName' => $staff->name, 'changeType' => $changeType, 'targetId' => $targetId];
  785. ProductClass::changeSinglePrice($chain, $ptItemId, $price, $skPrice, $hjPrice, $changeParams2);
  786. }
  787. }
  788. }
  789. }
  790. if (!empty($mainId)) {
  791. //提醒零售收银台界面要刷新
  792. $staffList = ShopAdminClass::getAllByCondition(['mainId' => $mainId], null, '*', null, true);
  793. if (!empty($staffList)) {
  794. foreach ($staffList as $staff) {
  795. $staffId = $staff->id ?? 0;
  796. Yii::$app->redis->executeCommand('SET', ['cashier_' . $mainId . '_' . $staffId . '_may_refresh', 'yes']);
  797. Yii::$app->redis->executeCommand('SET', ['ghs_cashier_' . $mainId . '_' . $staffId . '_may_refresh', 'yes']);
  798. }
  799. }
  800. }
  801. $transaction->commit();
  802. util::complete('修改成功');
  803. } catch (\Exception $e) {
  804. $transaction->rollBack();
  805. Yii::info("修改失败原因:" . $e->getMessage());
  806. util::fail('修改失败');
  807. }
  808. }
  809. //改价
  810. public function actionChangePrice()
  811. {
  812. $shopAdmin = $this->shopAdmin;
  813. if (isset($shopAdmin->super) == false || $shopAdmin->super != 1) {
  814. util::fail('超管才能修改');
  815. }
  816. $productId = Yii::$app->request->post('productId', 0);
  817. $productInfo = ProductClass::getById($productId, true);
  818. if (empty($productInfo)) {
  819. util::fail("花材不存在");
  820. }
  821. if ($productInfo->mainId != $this->mainId) {
  822. util::fail('没有权限');
  823. }
  824. $price = Yii::$app->request->post('price', '');
  825. if (is_numeric($price) && $price > 0) {
  826. ProductClass::changeSinglePrice($productInfo, $price, ProductClass::PRICE_LABEL_CHANGE);
  827. } else {
  828. $price = bcadd($productInfo->cost, $productInfo->addPrice, 2);
  829. ProductClass::changeSinglePrice($productInfo, $price, ProductClass::PRICE_LABEL_AUTO);
  830. }
  831. util::success(['price' => $price]);
  832. }
  833. //恢复自动调价
  834. public function actionAutoPrice()
  835. {
  836. $productId = Yii::$app->request->post('productId', 0);
  837. $productData = ProductClass::getById($productId);
  838. if (!$productData) {
  839. util::fail("花材不存在");
  840. }
  841. //2021.04.06改为用product中的成本价+加价
  842. $price = bcadd($productData['cost'], $productData['addPrice'], 2);
  843. ProductClass::changeSinglePrice($productId, $this->shopId, $price, ProductClass::PRICE_LABEL_AUTO);
  844. util::complete("操作成功");
  845. }
  846. //修改加价
  847. public function actionChangeAddPrice()
  848. {
  849. $productId = Yii::$app->request->post('productId', 0);
  850. $addPrice = Yii::$app->request->post('addPrice', '');
  851. if ($addPrice < 0) {
  852. util::fail("加价不能小于0");
  853. }
  854. $productData = ProductClass::getProductData($productId, $this->mainId);
  855. if (!$productData) {
  856. util::fail("花材不存在");
  857. }
  858. ProductClass::changeAddPrice($productId, $addPrice);
  859. util::complete();
  860. }
  861. //批量修改更多,包括排序、重量和保质期 ssh 20211211
  862. public function actionBatchChangeMore()
  863. {
  864. $shop = $this->shop;
  865. $default = $shop->default ?? 0;
  866. if ($default == 0) {
  867. util::fail('当前直营分店,请返回总店修改');
  868. }
  869. $shopAdmin = $this->shopAdmin;
  870. if (isset($shopAdmin->super) == false || $shopAdmin->super != 1) {
  871. util::fail('超管才能操作');
  872. }
  873. $addData = Yii::$app->request->post('addData', '');
  874. if (empty($addData)) {
  875. util::fail('没有花材');
  876. }
  877. $itemData = json_decode($addData, true);
  878. if (is_array($itemData) == false) {
  879. util::fail('没有花材...');
  880. }
  881. $ids = array_column($itemData, 'id');
  882. $infoList = ProductClass::getByIds($ids, null, 'id');
  883. if (empty($infoList)) {
  884. util::fail('没有花材');
  885. }
  886. foreach ($infoList as $info) {
  887. if (isset($info['mainId']) == false || $info['mainId'] != $this->mainId) {
  888. util::fail('不是你的花材不能修改');
  889. }
  890. }
  891. //总店修改同步到所有门店
  892. $sjId = $shop->sjId ?? 0;
  893. $chainShopList = ShopClass::getAllByCondition(['sjId' => $sjId], null, '*', null, true);
  894. foreach ($itemData as $key => $data) {
  895. $id = $data['id'] ?? 0;
  896. unset($data['id']);
  897. ProductClass::updateById($id, $data);
  898. $ptItemId = $infoList[$id]['itemId'] ?? 0;
  899. if (empty($ptItemId)) {
  900. continue;
  901. }
  902. if (isset($shop->default) && $shop->default == 1 && isset($shop->dataSync) && $shop->dataSync == 1) {
  903. foreach ($chainShopList as $chainShop) {
  904. $currentMainId = $chainShop->mainId ?? 0;
  905. if ($currentMainId == $shop->mainId) {
  906. //前面已经修改过了,不需要重复修改
  907. continue;
  908. }
  909. ProductClass::updateByCondition(['mainId' => $currentMainId, 'itemId' => $ptItemId], $data);
  910. }
  911. }
  912. }
  913. util::complete('修改成功');
  914. }
  915. //批量修改加价 ssh 20211211
  916. public function actionBatchChangeAddPrice()
  917. {
  918. $shop = $this->shop;
  919. $join = $shop->join ?? 0;
  920. $default = $shop->default ?? 0;
  921. if ($join == 0 && $default == 0) {
  922. util::fail('当前直营分店,请切回总店操作');
  923. }
  924. $shopAdmin = $this->shopAdmin;
  925. if (isset($shopAdmin->super) == false || $shopAdmin->super != 1) {
  926. util::fail('超管才能操作');
  927. }
  928. $post = Yii::$app->request->post();
  929. $addData = $post['addData'] ?? '';
  930. if (empty($addData)) {
  931. util::fail('没有花材');
  932. }
  933. $itemData = json_decode($addData, true);
  934. if (is_array($itemData) == false) {
  935. util::fail('没有花材...');
  936. }
  937. $ids = array_column($itemData, 'id');
  938. $infoList = ProductClass::getByIds($ids, null, 'id');
  939. if (empty($infoList)) {
  940. util::fail('没有花材');
  941. }
  942. foreach ($infoList as $info) {
  943. if (isset($info['mainId']) == false || $info['mainId'] != $this->mainId) {
  944. util::fail('不能修改别人的花材');
  945. }
  946. }
  947. $appVersion = $post['appVersion'] ?? 0;
  948. if ($appVersion != 1) {
  949. util::fail('请先升级应用');
  950. }
  951. //总店修改同步到所有门店
  952. $sjId = $shop->sjId ?? 0;
  953. $chainShopList = ShopClass::getAllByCondition(['sjId' => $sjId], null, '*', null, true);
  954. foreach ($itemData as $key => $data) {
  955. $id = $data['id'] ?? 0;
  956. unset($data['id']);
  957. ProductClass::updateById($id, $data);
  958. $ptItemId = $infoList[$id]['itemId'] ?? 0;
  959. if (empty($ptItemId)) {
  960. continue;
  961. }
  962. if (isset($shop->default) && $shop->default == 1 && isset($shop->dataSync) && $shop->dataSync == 1) {
  963. foreach ($chainShopList as $chainShop) {
  964. if (isset($chainShop->join) && $chainShop->join == 1) {
  965. continue;
  966. }
  967. $currentMainId = $chainShop->mainId ?? 0;
  968. if ($currentMainId == $shop->mainId) {
  969. //前面已经修改过了,不需要重复修改
  970. continue;
  971. }
  972. ProductClass::updateByCondition(['mainId' => $currentMainId, 'itemId' => $ptItemId], $data);
  973. }
  974. }
  975. }
  976. util::complete('修改成功');
  977. }
  978. public function actionUpdate()
  979. {
  980. $shopAdmin = $this->shopAdmin;
  981. if (isset($shopAdmin->super) == false || $shopAdmin->super != 1) {
  982. util::fail('超管才能操作');
  983. }
  984. $shop = $this->shop;
  985. $join = $shop->join ?? 0;
  986. $default = $shop->default ?? 0;
  987. if ($join == 0 && $default == 0) {
  988. //因为盘点不能将花材盘成0,所以这边放出入口允许创始人在分店修改分店的花材库存
  989. if ($shopAdmin->super != 1) {
  990. util::fail('请先开通超管权限');
  991. }
  992. }
  993. $post = Yii::$app->request->post();
  994. $discountPrice = $post['discountPrice'] ?? 0;
  995. if ($discountPrice > 0) {
  996. if (isset($post['hjDiscountPrice']) == false || empty($post['hjDiscountPrice'])) {
  997. $addPrice = $post['addPrice'] ?? 0;
  998. $hjAddPrice = $post['hjAddPrice'] ?? 0;
  999. $skMore = $post['skMore'] ?? 0;
  1000. $diff = bcsub($addPrice, $hjAddPrice, 2);
  1001. if ($diff > 0 && $discountPrice > $diff) {
  1002. $hjDiscountPrice = bcsub($discountPrice, $diff, 2);
  1003. } else {
  1004. $hjDiscountPrice = $discountPrice;
  1005. }
  1006. $diff = bcsub($skMore, $addPrice, 2);
  1007. if ($diff > 0) {
  1008. $skDiscountPrice = bcadd($diff, $discountPrice, 2);
  1009. } else {
  1010. $skDiscountPrice = $discountPrice;
  1011. }
  1012. $post['skDiscountPrice'] = $skDiscountPrice;
  1013. $post['hjDiscountPrice'] = $hjDiscountPrice;
  1014. }
  1015. $reachNum = $post['reachNum'] ?? 0;
  1016. $reachNumDiscount = $post['reachNumDiscount'] ?? 0;
  1017. if ($reachNum > 0 && $reachNumDiscount > 0) {
  1018. util::fail('特价和满减不能同时进行');
  1019. }
  1020. }
  1021. $post['adminId'] = $this->adminId;
  1022. $post['staffId'] = $this->shopAdmin->id;
  1023. $post['staffName'] = $this->shopAdmin->name;
  1024. $connection = Yii::$app->db;
  1025. $transaction = $connection->beginTransaction();
  1026. try {
  1027. ProductClass::updateProduct($post, $this->shop);
  1028. $transaction->commit();
  1029. util::complete();
  1030. } catch (\Exception $e) {
  1031. Yii::info("操作失败:" . $e->getMessage());
  1032. $transaction->rollBack();
  1033. util::fail('操作失败');
  1034. }
  1035. }
  1036. //上下架状态控制 ssh 20210713
  1037. public function actionStatusUpdate()
  1038. {
  1039. $post = Yii::$app->request->post();
  1040. $shopAdmin = $this->shopAdmin;
  1041. $roleId = $shopAdmin['roleId'] ?? 0;
  1042. $role = AdminRoleClass::getById($roleId);
  1043. $roleName = $role['roleName'] ?? '';
  1044. if ($roleName == '员工') {
  1045. util::fail('无法操作哦');
  1046. }
  1047. $id = $post['id'] ?? 0;
  1048. $status = $post['status'] ?? 1;
  1049. $product = ProductClass::getById($id, true);
  1050. if ($product->mainId != $this->mainId) {
  1051. util::fail('无法操作');
  1052. }
  1053. $product->status = $status;
  1054. if ($status == 2) {
  1055. $product->discountPrice = 0;
  1056. }
  1057. $product->save();
  1058. util::complete();
  1059. }
  1060. //花材展示状态控制 ssh 20231113
  1061. public function actionDelStatusUpdate()
  1062. {
  1063. $post = Yii::$app->request->post();
  1064. $shop = $this->shop;
  1065. $join = $shop->join ?? 0;
  1066. $default = $shop->default ?? 0;
  1067. if ($join == 0 && $default == 0) {
  1068. util::fail('请在首店操作');
  1069. }
  1070. $id = $post['id'] ?? 0;
  1071. $delStatus = $post['delStatus'] ?? 0;
  1072. $product = ProductClass::getById($id, true);
  1073. if ($product->mainId != $this->mainId) {
  1074. util::fail('不是你的花材哦!!');
  1075. }
  1076. $product->delStatus = $delStatus;
  1077. if ($delStatus == 1) {
  1078. $product->stock = 0;
  1079. $product->status = 2;
  1080. }
  1081. $product->save();
  1082. $ptItemId = $product->itemId ?? 0;
  1083. if (isset($shop->default) && $shop->default == 1 && isset($shop->dataSync) && $shop->dataSync == 1) {
  1084. //总店修改同步到所有门店
  1085. $sjId = $shop->sjId ?? 0;
  1086. $chainShopList = ShopClass::getAllByCondition(['sjId' => $sjId], null, '*', null, true);
  1087. foreach ($chainShopList as $chainShop) {
  1088. $chainShopId = $chainShop->id ?? 0;
  1089. if (isset($chainShop->join) && $chainShop->join == 1) {
  1090. continue;
  1091. }
  1092. if ($chainShopId == $shop->id) {
  1093. continue;
  1094. }
  1095. $chainMainId = $chainShop->mainId ?? 0;
  1096. $chainProduct = ProductClass::getByCondition(['mainId' => $chainMainId, 'itemId' => $ptItemId], true);
  1097. if (!empty($chainProduct)) {
  1098. $chainProduct->delStatus = $delStatus;
  1099. if ($delStatus == 1) {
  1100. $chainProduct->stock = 0;
  1101. $chainProduct->status = 2;
  1102. }
  1103. $chainProduct->save();
  1104. }
  1105. }
  1106. }
  1107. util::complete();
  1108. }
  1109. //详情 shish 20240115
  1110. public function actionDetail()
  1111. {
  1112. $id = Yii::$app->request->get('id', 0);
  1113. $source = Yii::$app->request->get('source', '');
  1114. $respond = ProductClass::getItemInfo($id);
  1115. $ptItemId = $respond['itemId'] ?? 0;
  1116. $ptItemInfo = PtItemClass::getById($ptItemId);
  1117. $respond['ptItemInfo'] = $ptItemInfo;
  1118. //通知提醒抹除
  1119. if ($source == 'notify' && $respond['mainId'] == $this->mainId) {
  1120. $staff = $this->shopAdmin;
  1121. $staffId = $this->shopAdminId;
  1122. $notify = NotifyClass::getByCondition(['staffId' => $staffId, 'type' => 1, 'targetId' => $id], true);
  1123. if (!empty($notify)) {
  1124. if ($notify->read == 0) {
  1125. $notify->read = 1;
  1126. $notify->save();
  1127. $notifyNum = $staff->notifyNum;
  1128. if ($notifyNum > 0) {
  1129. $notifyNum--;
  1130. $staff->notifyNum = $notifyNum;
  1131. $staff->save();
  1132. }
  1133. }
  1134. }
  1135. }
  1136. //重复花材
  1137. $repeatList = ProductClass::getAllByCondition(['mainId' => $this->mainId, 'itemId' => $ptItemId, 'delStatus' => 0], null, '*', null, true);
  1138. $repeatId = 0;
  1139. if (!empty($repeatList)) {
  1140. foreach ($repeatList as $repeat) {
  1141. if ($repeat->id != $id) {
  1142. $repeatId = $repeat->id;
  1143. }
  1144. }
  1145. }
  1146. $respond['repeatId'] = $repeatId;
  1147. $cpItemList = CpItemClass::getAllByCondition(['productId' => $id], null, '*', 'cpId');
  1148. $cpInfo = [];
  1149. if (!empty($cpItemList)) {
  1150. $cpIds = array_column($cpItemList, 'cpId');
  1151. $cpList = CpClass::getByIds($cpIds);
  1152. if (!empty($cpList)) {
  1153. foreach ($cpList as $key => $val) {
  1154. $id = $val['id'] ?? 0;
  1155. $name = $val['name'] ?? '';
  1156. $cpInfo[] = ['cpId' => $id, 'cpName' => $name];
  1157. }
  1158. }
  1159. }
  1160. $respond['cpInfo'] = $cpInfo;
  1161. util::success($respond);
  1162. }
  1163. //新增花材 2021.6.21
  1164. public function actionAdd()
  1165. {
  1166. $post = Yii::$app->request->post();
  1167. //临时兼容,2023.7.1后可以删除
  1168. $appVersion = $post['appVersion'] ?? 0;
  1169. if ($appVersion != 1) {
  1170. util::fail('请先升级应用');
  1171. }
  1172. $discountPrice = $post['discountPrice'] ?? 0;
  1173. if ($discountPrice > 0) {
  1174. if (isset($post['hjDiscountPrice']) == false || empty($post['hjDiscountPrice'])) {
  1175. $addPrice = $post['addPrice'] ?? 0;
  1176. $hjAddPrice = $post['hjAddPrice'] ?? 0;
  1177. $skMore = $post['skMore'] ?? 0;
  1178. $diff = bcsub($addPrice, $hjAddPrice, 2);
  1179. if ($diff > 0 && $discountPrice > $diff) {
  1180. $hjDiscountPrice = bcsub($discountPrice, $diff, 2);
  1181. } else {
  1182. $hjDiscountPrice = $discountPrice;
  1183. }
  1184. $diff = bcsub($skMore, $addPrice, 2);
  1185. if ($diff > 0) {
  1186. $skDiscountPrice = bcadd($diff, $discountPrice, 2);
  1187. } else {
  1188. $skDiscountPrice = $discountPrice;
  1189. }
  1190. $post['skDiscountPrice'] = $skDiscountPrice;
  1191. $post['hjDiscountPrice'] = $hjDiscountPrice;
  1192. }
  1193. }
  1194. $shop = $this->shop;
  1195. $join = $shop->join ?? 0;
  1196. $default = $shop->default ?? 0;
  1197. if ($join == 0 && $default == 0) {
  1198. util::fail('当前直营分店,请切回总店添加花材');
  1199. }
  1200. $shopAdmin = $this->shopAdmin;
  1201. if (isset($shopAdmin->super) == false || $shopAdmin->super != 1) {
  1202. util::fail('管理员才能添加花材');
  1203. }
  1204. $post['sjId'] = $this->sjId;
  1205. $post['adminId'] = $this->adminId;
  1206. $post['mainId'] = $this->mainId;
  1207. $price = $post['price'] ?? 0;
  1208. $addPrice = $post['addPrice'] ?? 0;
  1209. if ($addPrice > $price) {
  1210. util::fail('加价不能大于售价');
  1211. }
  1212. $weight = isset($post['weight']) && is_numeric($post['weight']) ? $post['weight'] : 0;
  1213. if ($weight <= 0) {
  1214. util::fail('请填写重量,最小0.1');
  1215. }
  1216. $post['staffName'] = $shopAdmin->name ?? '';
  1217. ProductClass::addProduct($post, $this->shop);
  1218. util::complete('添加成功');
  1219. }
  1220. //获取拼音缩写 ssh 20210707
  1221. public function actionPy()
  1222. {
  1223. $name = Yii::$app->request->get('name');
  1224. $py = stringUtil::py($name);
  1225. util::success(['py' => $py]);
  1226. }
  1227. //(客户端-批发商)复制花材
  1228. public function actionClone()
  1229. {
  1230. $post = Yii::$app->request->post();
  1231. $appVersion = $post['appVersion'] ?? 0;
  1232. if ($appVersion != 1) {
  1233. util::fail('请先升级应用');
  1234. }
  1235. $discountPrice = $post['discountPrice'] ?? 0;
  1236. if ($discountPrice > 0) {
  1237. if (isset($post['hjDiscountPrice']) == false || empty($post['hjDiscountPrice'])) {
  1238. $addPrice = $post['addPrice'] ?? 0;
  1239. $hjAddPrice = $post['hjAddPrice'] ?? 0;
  1240. $skMore = $post['skMore'] ?? 0;
  1241. $diff = bcsub($addPrice, $hjAddPrice, 2);
  1242. if ($diff > 0 && $discountPrice > $diff) {
  1243. $hjDiscountPrice = bcsub($discountPrice, $diff, 2);
  1244. } else {
  1245. $hjDiscountPrice = $discountPrice;
  1246. }
  1247. $diff = bcsub($skMore, $addPrice, 2);
  1248. if ($diff > 0) {
  1249. $skDiscountPrice = bcadd($diff, $discountPrice, 2);
  1250. } else {
  1251. $skDiscountPrice = $discountPrice;
  1252. }
  1253. $post['skDiscountPrice'] = $skDiscountPrice;
  1254. $post['hjDiscountPrice'] = $hjDiscountPrice;
  1255. }
  1256. }
  1257. $shop = $this->shop;
  1258. $join = $shop->join ?? 0;
  1259. $default = $shop->default ?? 0;
  1260. if ($join == 0 && $default == 0) {
  1261. util::fail('请在首店操作');
  1262. }
  1263. $shopAdmin = $this->shopAdmin;
  1264. if (isset($shopAdmin->super) == false || $shopAdmin->super != 1) {
  1265. util::fail('管理员才能添加花材');
  1266. }
  1267. $post['sjId'] = $this->sjId;
  1268. $post['adminId'] = $this->adminId;
  1269. $post['mainId'] = $this->mainId;
  1270. $post['staffName'] = $shopAdmin->name ?? '';
  1271. $price = $post['price'] ?? 0;
  1272. if (empty($price) || $price <= 0) {
  1273. util::fail('请填写批发价');
  1274. }
  1275. $skPrice = $post['skPrice'] ?? 0;
  1276. if (empty($skPrice) || $skPrice <= 0) {
  1277. util::fail('请填写零售价');
  1278. }
  1279. $hjPrice = $post['hjPrice'] ?? 0;
  1280. if (empty($hjPrice) || $hjPrice <= 0) {
  1281. util::fail('请填写会员价');
  1282. }
  1283. $addPrice = $post['addPrice'] ?? 0;
  1284. if ($addPrice > $price) {
  1285. util::fail('批发价的加价不能大于售价');
  1286. }
  1287. //复制标识
  1288. $post['copy'] = 1;
  1289. //去除无用的字段
  1290. unset($post['viewNum']);
  1291. unset($post['actualSold']);
  1292. unset($post['itemId']);
  1293. unset($post['id']);
  1294. unset($post['delStatus']);
  1295. ProductClass::addProduct($post, $this->shop);
  1296. util::complete('复制成功');
  1297. }
  1298. //下载价格表 ssh 20210922
  1299. public function actionGeneratePriceTable()
  1300. {
  1301. $level = Yii::$app->request->get('level', 0);
  1302. $respond = ProductService::generatePriceTable($this->sjId, $level, $this->mainId);
  1303. $file = $respond['file'] ?? '';
  1304. $shortFile = $respond['shortFile'] ?? '';
  1305. $fileUrl = Yii::$app->params['ghsHost'] . $file;
  1306. util::success(['file' => $fileUrl, 'shortFile' => $shortFile]);
  1307. }
  1308. public function actionGenerateItemTable()
  1309. {
  1310. $level = Yii::$app->request->get('level', 0);
  1311. $respond = ProductService::generateItemTable($this->sjId, $level, $this->mainId);
  1312. $file = $respond['file'] ?? '';
  1313. $shortFile = $respond['shortFile'] ?? '';
  1314. $fileUrl = Yii::$app->params['ghsHost'] . $file;
  1315. util::success(['file' => $fileUrl, 'shortFile' => $shortFile]);
  1316. }
  1317. //下载条形码 lqh 20211227
  1318. public function actionGenerateBarcodeTable()
  1319. {
  1320. $respond = ProductService::generateBarcodeTable($this->sjId, $this->shopId, $this->mainId);
  1321. $file = $respond['file'] ?? '';
  1322. $shortFile = $respond['shortFile'] ?? '';
  1323. $fileUrl = Yii::$app->params['ghsHost'] . $file;
  1324. util::success(['file' => $fileUrl, 'shortFile' => $shortFile]);
  1325. }
  1326. //批量修改花材的分类 ssh 20230405
  1327. public function actionBatchModifyClass()
  1328. {
  1329. $post = Yii::$app->request->post();
  1330. $shop = $this->shop;
  1331. $sjName = $shop->merchantName ?? '';
  1332. $shopName = $shop->shopName ?? '';
  1333. $sjShopName = $shop->shopName == '首店' ? $sjName : $sjName . ' ' . $shopName;
  1334. //noticeUtil::push($sjShopName . ' 批量移动花材分类', '15280215347');
  1335. $join = $shop->join ?? 0;
  1336. $default = $shop->default ?? 0;
  1337. if ($join == 0 && $default == 0) {
  1338. util::fail('当前直营分店,请切回总店操作');
  1339. }
  1340. $classId = $post['classId'] ?? 0;
  1341. $class = ItemClassClass::getById($classId, true);
  1342. if (empty($class) || $class->mainId != $this->mainId) {
  1343. util::fail('请选择您自己的分类');
  1344. }
  1345. $connection = Yii::$app->db;
  1346. $transaction = $connection->beginTransaction();
  1347. try {
  1348. $className = $class->name ?? '';
  1349. $idsList = $post['ids'] ?? '';
  1350. $ids = json_decode($idsList, true);
  1351. if (empty($ids)) {
  1352. util::fail('请选择花材');
  1353. }
  1354. $list = ProductClass::getAllByCondition(['id' => ['in', $ids]], null, '*', null, true);
  1355. if (empty($list)) {
  1356. util::fail('请选择花材');
  1357. }
  1358. $ptItemList = [];
  1359. foreach ($list as $item) {
  1360. $name = $item->name ?? '';
  1361. if ($item->mainId != $this->mainId) {
  1362. util::fail($name . '不是您的花材');
  1363. }
  1364. $item->classId = $classId;
  1365. $item->save();
  1366. $ptItemId = $item->itemId ?? 0;
  1367. $ptItemList[] = $ptItemId;
  1368. //如果有修改分类,则在多个订单表中同步修改,如需修改,多个地方要同步修改,请搜索关键词item_class_modify_sync
  1369. $itemClassKey = 'item_class_modify_sync';
  1370. Yii::$app->redis->executeCommand('LPUSH', [$itemClassKey, $item->id]);
  1371. }
  1372. $shop = $this->shop;
  1373. if (isset($shop->default) && $shop->default == 1 && isset($shop->dataSync) && $shop->dataSync == 1) {
  1374. //总店修改同步到所有门店
  1375. $sjId = $shop->sjId ?? 0;
  1376. $chainShopList = ShopClass::getAllByCondition(['sjId' => $sjId], null, '*', null, true);
  1377. foreach ($chainShopList as $chainShop) {
  1378. $chainShopId = $chainShop->id ?? 0;
  1379. if ($chainShopId == $shop->id) {
  1380. continue;
  1381. }
  1382. $chainManId = $chainShop->mainId ?? 0;
  1383. $chainAllClassList = ItemClassClass::getAllByCondition(['mainId' => $chainManId], null, '*', null, true);
  1384. if (!empty($chainAllClassList)) {
  1385. foreach ($chainAllClassList as $chainClass) {
  1386. $chainName = $chainClass->name ?? '';
  1387. $chainClassId = $chainClass->id ?? 0;
  1388. if ($chainName == $className) {
  1389. $chainProductList = Productclass::getAllByCondition(['mainId' => $chainManId, 'itemId' => ['in', $ptItemList]], null, '*', null, true);
  1390. if (!empty($chainProductList)) {
  1391. foreach ($chainProductList as $currentProduct) {
  1392. $currentProduct->classId = $chainClassId;
  1393. $currentProduct->save();
  1394. //如果有修改分类,则在多个订单表中同步修改,如需修改,多个地方要同步修改,请搜索关键词item_class_modify_sync
  1395. $itemClassKey = 'item_class_modify_sync';
  1396. Yii::$app->redis->executeCommand('LPUSH', [$itemClassKey, $currentProduct->id]);
  1397. }
  1398. }
  1399. }
  1400. }
  1401. }
  1402. }
  1403. }
  1404. $transaction->commit();
  1405. util::complete('修改成功');
  1406. } catch (\Exception $e) {
  1407. $transaction->rollBack();
  1408. Yii::info("修改失败原因:" . $e->getMessage());
  1409. util::fail('修改失败');
  1410. }
  1411. }
  1412. //批量修改采购人 ssh 20240609
  1413. public function actionBatchModifyCgStaff()
  1414. {
  1415. $post = Yii::$app->request->post();
  1416. $staffId = $post['staffId'] ?? 0;
  1417. $staff = ShopAdminClass::getById($staffId, true);
  1418. if (empty($staff)) {
  1419. util::fail('没有找到这个员工');
  1420. }
  1421. if ($staff->mainId != $this->mainId) {
  1422. util::fail('不是你的员工');
  1423. }
  1424. $staffName = $staff->name ?? '';
  1425. $connection = Yii::$app->db;
  1426. $transaction = $connection->beginTransaction();
  1427. try {
  1428. $idsList = $post['ids'] ?? '';
  1429. $ids = json_decode($idsList, true);
  1430. if (empty($ids)) {
  1431. util::fail('请选择花材');
  1432. }
  1433. $list = ProductClass::getAllByCondition(['id' => ['in', $ids]], null, '*', null, true);
  1434. if (empty($list)) {
  1435. util::fail('请选择花材');
  1436. }
  1437. foreach ($list as $item) {
  1438. $name = $item->name ?? '';
  1439. if ($item->mainId != $this->mainId) {
  1440. util::fail($name . '不是您的花材');
  1441. }
  1442. $item->cgStaffId = $staffId;
  1443. $item->cgStaffName = $staffName;
  1444. $item->save();
  1445. }
  1446. $transaction->commit();
  1447. util::complete('修改成功');
  1448. } catch (\Exception $e) {
  1449. $transaction->rollBack();
  1450. Yii::info("修改失败原因:" . $e->getMessage());
  1451. util::fail('修改失败');
  1452. }
  1453. }
  1454. //修改属于成本还是收入选项 ssh 20240514
  1455. public function actionChangeBelongCost()
  1456. {
  1457. $get = Yii::$app->request->get();
  1458. $id = $get['id'] ?? 0;
  1459. $belongCost = $get['belongCost'] ?? 0;
  1460. $info = ProductClass::getById($id, true);
  1461. if (empty($info)) {
  1462. util::fail('没有找到花材');
  1463. }
  1464. if ($info->mainId != $this->mainId) {
  1465. util::fail('不是你的花材哦');
  1466. }
  1467. $info->belongCost = $belongCost;
  1468. $info->save();
  1469. //队列方式去处理
  1470. $redisKey = 'change_belong_cost_item_list';
  1471. $value = $id . '_' . $belongCost;
  1472. Yii::$app->redis->executeCommand('LPUSH', [$redisKey, $value]);
  1473. util::complete('修改成功');
  1474. }
  1475. }