ProductController.php 70 KB

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