ProductController.php 68 KB

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