ProductController.php 72 KB

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