ProductController.php 68 KB

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