ProductController.php 72 KB

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