ProductController.php 73 KB

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