ProductController.php 69 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663
  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. //客户添加花材时,经常会出现加价大于售价的怦,这个时候就直接把加价全部设置为0
  1251. $post['addPrice'] = 0;
  1252. $post['hjAddPrice'] = 0;
  1253. $post['skMore'] = 0;
  1254. //util::fail('加价不能大于售价');
  1255. }
  1256. $weight = isset($post['weight']) && is_numeric($post['weight']) ? $post['weight'] : 0;
  1257. if ($weight <= 0) {
  1258. util::fail('请填写重量,最小0.1');
  1259. }
  1260. $post['staffName'] = $shopAdmin->name ?? '';
  1261. // 图片列表数组转换为字符串
  1262. if (is_array($post['images'])) {
  1263. $post['images'] = implode(',', $post['images']);
  1264. }
  1265. ProductClass::addProduct($post, $this->shop);
  1266. util::complete('添加成功');
  1267. }
  1268. //获取拼音缩写 ssh 20210707
  1269. public function actionPy()
  1270. {
  1271. $name = Yii::$app->request->get('name');
  1272. $py = stringUtil::py($name);
  1273. util::success(['py' => $py]);
  1274. }
  1275. //(客户端-批发商)复制花材
  1276. public function actionClone()
  1277. {
  1278. $post = Yii::$app->request->post();
  1279. $discountPrice = $post['discountPrice'] ?? 0;
  1280. if ($discountPrice > 0) {
  1281. if (isset($post['hjDiscountPrice']) == false || empty($post['hjDiscountPrice'])) {
  1282. $addPrice = $post['addPrice'] ?? 0;
  1283. $hjAddPrice = $post['hjAddPrice'] ?? 0;
  1284. $skMore = $post['skMore'] ?? 0;
  1285. $diff = bcsub($addPrice, $hjAddPrice, 2);
  1286. if ($diff > 0 && $discountPrice > $diff) {
  1287. $hjDiscountPrice = bcsub($discountPrice, $diff, 2);
  1288. } else {
  1289. $hjDiscountPrice = $discountPrice;
  1290. }
  1291. $diff = bcsub($skMore, $addPrice, 2);
  1292. if ($diff > 0) {
  1293. $skDiscountPrice = bcadd($diff, $discountPrice, 2);
  1294. } else {
  1295. $skDiscountPrice = $discountPrice;
  1296. }
  1297. $post['skDiscountPrice'] = $skDiscountPrice;
  1298. $post['hjDiscountPrice'] = $hjDiscountPrice;
  1299. }
  1300. }
  1301. $shop = $this->shop;
  1302. $join = $shop->join ?? 0;
  1303. $default = $shop->default ?? 0;
  1304. if ($join == 0 && $default == 0) {
  1305. util::fail('请在首店操作');
  1306. }
  1307. $shopAdmin = $this->shopAdmin;
  1308. if (isset($shopAdmin->super) == false || $shopAdmin->super != 1) {
  1309. util::fail('管理员才能添加花材');
  1310. }
  1311. $post['sjId'] = $this->sjId;
  1312. $post['adminId'] = $this->adminId;
  1313. $post['mainId'] = $this->mainId;
  1314. $post['staffName'] = $shopAdmin->name ?? '';
  1315. $price = $post['price'] ?? 0;
  1316. if (empty($price) || $price <= 0) {
  1317. util::fail('请填写批发价');
  1318. }
  1319. $skPrice = $post['skPrice'] ?? 0;
  1320. if (empty($skPrice) || $skPrice <= 0) {
  1321. util::fail('请填写零售价');
  1322. }
  1323. $hjPrice = $post['hjPrice'] ?? 0;
  1324. if (empty($hjPrice) || $hjPrice <= 0) {
  1325. util::fail('请填写会员价');
  1326. }
  1327. $addPrice = $post['addPrice'] ?? 0;
  1328. if ($addPrice > $price) {
  1329. util::fail('批发价的加价不能大于售价');
  1330. }
  1331. // 图片列表数组转换为字符串
  1332. if (is_array($post['images'])) {
  1333. $post['images'] = implode(',', $post['images']);
  1334. }
  1335. //复制标识
  1336. $post['copy'] = 1;
  1337. //去除无用的字段
  1338. unset($post['viewNum']);
  1339. unset($post['actualSold']);
  1340. unset($post['itemId']);
  1341. unset($post['id']);
  1342. unset($post['delStatus']);
  1343. ProductClass::addProduct($post, $this->shop);
  1344. util::complete('复制成功');
  1345. }
  1346. //下载价格表 ssh 20210922
  1347. public function actionGeneratePriceTable()
  1348. {
  1349. $level = Yii::$app->request->get('level', 0);
  1350. $respond = ProductService::generatePriceTable($this->sjId, $level, $this->mainId);
  1351. $file = $respond['file'] ?? '';
  1352. $shortFile = $respond['shortFile'] ?? '';
  1353. $fileUrl = Yii::$app->params['ghsHost'] . $file;
  1354. util::success(['file' => $fileUrl, 'shortFile' => $shortFile]);
  1355. }
  1356. //下载有库存花材,不含虚拟库存 ssh 20241-28
  1357. public function actionGenerateStockTable()
  1358. {
  1359. $level = Yii::$app->request->get('level', 0);
  1360. $respond = ProductService::generateStockTable($this->sjId, $level, $this->mainId);
  1361. $file = $respond['file'] ?? '';
  1362. $shortFile = $respond['shortFile'] ?? '';
  1363. $fileUrl = Yii::$app->params['ghsHost'] . $file;
  1364. util::success(['file' => $fileUrl, 'shortFile' => $shortFile]);
  1365. }
  1366. public function actionGenerateItemTable()
  1367. {
  1368. $level = Yii::$app->request->get('level', 0);
  1369. $respond = ProductService::generateItemTable($this->sjId, $level, $this->mainId);
  1370. $file = $respond['file'] ?? '';
  1371. $shortFile = $respond['shortFile'] ?? '';
  1372. $fileUrl = Yii::$app->params['ghsHost'] . $file;
  1373. util::success(['file' => $fileUrl, 'shortFile' => $shortFile]);
  1374. }
  1375. //下载条形码 lqh 20211227
  1376. public function actionGenerateBarcodeTable()
  1377. {
  1378. $respond = ProductService::generateBarcodeTable($this->sjId, $this->shopId, $this->mainId);
  1379. $file = $respond['file'] ?? '';
  1380. $shortFile = $respond['shortFile'] ?? '';
  1381. $fileUrl = Yii::$app->params['ghsHost'] . $file;
  1382. util::success(['file' => $fileUrl, 'shortFile' => $shortFile]);
  1383. }
  1384. //批量修改花材的分类 ssh 20230405
  1385. public function actionBatchModifyClass()
  1386. {
  1387. $post = Yii::$app->request->post();
  1388. $shop = $this->shop;
  1389. $sjName = $shop->merchantName ?? '';
  1390. $shopName = $shop->shopName ?? '';
  1391. $sjShopName = $shop->shopName == '首店' ? $sjName : $sjName . ' ' . $shopName;
  1392. //noticeUtil::push($sjShopName . ' 批量移动花材分类', '15280215347');
  1393. $join = $shop->join ?? 0;
  1394. $default = $shop->default ?? 0;
  1395. if ($join == 0 && $default == 0) {
  1396. util::fail('当前直营分店,请切回总店操作');
  1397. }
  1398. $classId = $post['classId'] ?? 0;
  1399. $class = ItemClassClass::getById($classId, true);
  1400. if (empty($class) || $class->mainId != $this->mainId) {
  1401. util::fail('请选择您自己的分类');
  1402. }
  1403. $connection = Yii::$app->db;
  1404. $transaction = $connection->beginTransaction();
  1405. try {
  1406. $className = $class->name ?? '';
  1407. $idsList = $post['ids'] ?? '';
  1408. $ids = json_decode($idsList, true);
  1409. if (empty($ids)) {
  1410. util::fail('请选择花材');
  1411. }
  1412. $list = ProductClass::getAllByCondition(['id' => ['in', $ids]], null, '*', null, true);
  1413. if (empty($list)) {
  1414. util::fail('请选择花材');
  1415. }
  1416. $ptItemList = [];
  1417. foreach ($list as $item) {
  1418. $name = $item->name ?? '';
  1419. if ($item->mainId != $this->mainId) {
  1420. util::fail($name . '不是您的花材');
  1421. }
  1422. $item->classId = $classId;
  1423. $item->save();
  1424. $ptItemId = $item->itemId ?? 0;
  1425. $ptItemList[] = $ptItemId;
  1426. //如果有修改分类,则在多个订单表中同步修改,如需修改,多个地方要同步修改,请搜索关键词item_class_modify_sync
  1427. $itemClassKey = 'item_class_modify_sync';
  1428. Yii::$app->redis->executeCommand('LPUSH', [$itemClassKey, $item->id]);
  1429. }
  1430. $shop = $this->shop;
  1431. if (isset($shop->default) && $shop->default == 1 && isset($shop->dataSync) && $shop->dataSync == 1) {
  1432. //总店修改同步到所有门店
  1433. $sjId = $shop->sjId ?? 0;
  1434. $chainShopList = ShopClass::getAllByCondition(['sjId' => $sjId], null, '*', null, true);
  1435. foreach ($chainShopList as $chainShop) {
  1436. $chainShopId = $chainShop->id ?? 0;
  1437. if ($chainShopId == $shop->id) {
  1438. continue;
  1439. }
  1440. $chainManId = $chainShop->mainId ?? 0;
  1441. $chainAllClassList = ItemClassClass::getAllByCondition(['mainId' => $chainManId], null, '*', null, true);
  1442. if (!empty($chainAllClassList)) {
  1443. foreach ($chainAllClassList as $chainClass) {
  1444. $chainName = $chainClass->name ?? '';
  1445. $chainClassId = $chainClass->id ?? 0;
  1446. if ($chainName == $className) {
  1447. $chainProductList = Productclass::getAllByCondition(['mainId' => $chainManId, 'itemId' => ['in', $ptItemList]], null, '*', null, true);
  1448. if (!empty($chainProductList)) {
  1449. foreach ($chainProductList as $currentProduct) {
  1450. $currentProduct->classId = $chainClassId;
  1451. $currentProduct->save();
  1452. //如果有修改分类,则在多个订单表中同步修改,如需修改,多个地方要同步修改,请搜索关键词item_class_modify_sync
  1453. $itemClassKey = 'item_class_modify_sync';
  1454. Yii::$app->redis->executeCommand('LPUSH', [$itemClassKey, $currentProduct->id]);
  1455. }
  1456. }
  1457. }
  1458. }
  1459. }
  1460. }
  1461. }
  1462. $transaction->commit();
  1463. util::complete('修改成功');
  1464. } catch (\Exception $e) {
  1465. $transaction->rollBack();
  1466. Yii::info("修改失败原因:" . $e->getMessage());
  1467. util::fail('修改失败');
  1468. }
  1469. }
  1470. //批量修改采购人 ssh 20240609
  1471. public function actionBatchModifyCgStaff()
  1472. {
  1473. $post = Yii::$app->request->post();
  1474. $staffId = $post['staffId'] ?? 0;
  1475. $staff = ShopAdminClass::getById($staffId, true);
  1476. if (empty($staff)) {
  1477. util::fail('没有找到这个员工');
  1478. }
  1479. if ($staff->mainId != $this->mainId) {
  1480. util::fail('不是你的员工');
  1481. }
  1482. $staffName = $staff->name ?? '';
  1483. $connection = Yii::$app->db;
  1484. $transaction = $connection->beginTransaction();
  1485. try {
  1486. $idsList = $post['ids'] ?? '';
  1487. $ids = json_decode($idsList, true);
  1488. if (empty($ids)) {
  1489. util::fail('请选择花材');
  1490. }
  1491. $list = ProductClass::getAllByCondition(['id' => ['in', $ids]], null, '*', null, true);
  1492. if (empty($list)) {
  1493. util::fail('请选择花材');
  1494. }
  1495. $shop = $this->shop;
  1496. $bookSn = $shop->bookSn ?? 0;
  1497. foreach ($list as $item) {
  1498. $name = $item->name ?? '';
  1499. if ($item->mainId != $this->mainId) {
  1500. util::fail($name . '不是您的花材');
  1501. }
  1502. $item->cgStaffId = $staffId;
  1503. $item->cgStaffName = $staffName;
  1504. $item->save();
  1505. $itemId = $item->id ?? 0;
  1506. if (!empty($bookSn)) {
  1507. //预订管理的花材需要变化
  1508. BookItemClass::updateByCondition(['bookSn' => $bookSn, 'itemId' => $itemId], ['cgStaffId' => $staffId, 'cgStaffName' => $staffName]);
  1509. }
  1510. }
  1511. $transaction->commit();
  1512. util::complete('修改成功');
  1513. } catch (\Exception $e) {
  1514. $transaction->rollBack();
  1515. Yii::info("修改失败原因:" . $e->getMessage());
  1516. util::fail('修改失败');
  1517. }
  1518. }
  1519. //修改属于成本还是收入选项 ssh 20240514
  1520. public function actionChangeBelongCost()
  1521. {
  1522. $get = Yii::$app->request->get();
  1523. $id = $get['id'] ?? 0;
  1524. $belongCost = $get['belongCost'] ?? 0;
  1525. $info = ProductClass::getById($id, true);
  1526. if (empty($info)) {
  1527. util::fail('没有找到花材');
  1528. }
  1529. if ($info->mainId != $this->mainId) {
  1530. util::fail('不是你的花材哦');
  1531. }
  1532. $info->belongCost = $belongCost;
  1533. $info->save();
  1534. //队列方式去处理
  1535. $redisKey = 'change_belong_cost_item_list';
  1536. $value = $id . '_' . $belongCost;
  1537. Yii::$app->redis->executeCommand('LPUSH', [$redisKey, $value]);
  1538. util::complete('修改成功');
  1539. }
  1540. }