ProductController.php 73 KB

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