ProductController.php 66 KB

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