ProductController.php 68 KB

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