ProductController.php 69 KB

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