ProductController.php 67 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613
  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. //除了小蔡鲜花的蔡总、郑总,其他人直营分店不能改价格
  577. if(!in_array($this->adminId,[35725,23659])){
  578. util::fail('直营店不能改价');
  579. }
  580. }
  581. $shopAdmin = $this->shopAdmin;
  582. if (isset($shopAdmin->super) == false || $shopAdmin->super != 1) {
  583. util::fail('超管才能修改');
  584. }
  585. $shop = $this->shop;
  586. $default = $shop->default ?? 0;
  587. $adminId = $this->adminId ?? 0;
  588. //normal常规改价,cg采购改价
  589. $changeType = Yii::$app->request->post('changeType', 'normal');
  590. $targetId = Yii::$app->request->post('targetId', 0);
  591. $changeParams = ['staffId' => $shopAdmin->id, 'staffName' => $shopAdmin->name, 'changeType' => $changeType, 'targetId' => $targetId];
  592. $post = Yii::$app->request->post();
  593. $data = $post['data'] ?? '';
  594. if (empty($data)) {
  595. util::fail('没有修改');
  596. }
  597. $arr = json_decode($data, true);
  598. if (empty($arr)) {
  599. util::fail('没有修改哦');
  600. }
  601. $appVersion = $post['appVersion'] ?? 0;
  602. if ($appVersion != 1) {
  603. util::fail('请先升级应用');
  604. }
  605. //解决重复请求问题
  606. $cacheKey = 'batch_change_price_' . $targetId;
  607. $has = Yii::$app->redis->executeCommand('GET', [$cacheKey]);
  608. if (!empty($has)) {
  609. util::fail('请5秒后操作');
  610. }
  611. Yii::$app->redis->executeCommand('SETEX', [$cacheKey, 5, 'has']);
  612. $connection = Yii::$app->db;
  613. $transaction = $connection->beginTransaction();
  614. try {
  615. $needNotice = false;
  616. $cg = PurchaseOrderClass::getLockById($targetId);
  617. if (!empty($cg)) {
  618. if (isset($cg->mainId) == false || $cg->mainId != $this->mainId) {
  619. util::fail('不是您的采购单');
  620. }
  621. //批量改价同时入库
  622. if ($cg->status == PurchaseOrderClass::PURCHASE_ORDER_STATUS_SENDING) {
  623. $staff = $this->shopAdmin;
  624. $data = [];
  625. $data['staffId'] = $staff->id ?? 0;
  626. $data['staffName'] = $staff->name ?? '';
  627. $data['adminId'] = $this->adminId ?? 0;
  628. $data['shop'] = $this->shop;
  629. PurchaseOrderClass::putIn($cg, $data);
  630. $needNotice = true;
  631. }
  632. }
  633. $ids = array_column($arr, 'id');
  634. $ids = array_unique(array_filter($ids));
  635. if (empty($ids)) {
  636. util::fail('请选择花材');
  637. }
  638. $sjId = $shop->sjId ?? 0;
  639. $chainShopList = [];
  640. if ($default == 1) {
  641. $chainShopList = ShopClass::getAllByCondition(['sjId' => $sjId, 'join' => 0], null, '*', null, true);
  642. }
  643. $productList = ProductClass::getAllByCondition(['id' => ['in', $ids]], null, '*', 'id', true);
  644. foreach ($arr as $product) {
  645. $productId = $product['id'];
  646. $productInfo = $productList[$productId] ?? [];
  647. if (empty($productInfo)) {
  648. util::fail('没有找到花材');
  649. }
  650. $productName = $productInfo->name ?? '';
  651. if (isset($product['id']) == false) {
  652. util::fail('没有花材');
  653. }
  654. if (isset($product['price']) == false || is_numeric($product['price']) == false || $product['price'] < 0) {
  655. util::fail('请填写' . $productName . '的批发价');
  656. }
  657. $price = $product['price'];
  658. if (isset($product['skPrice']) == false || is_numeric($product['skPrice']) == false || $product['skPrice'] < 0) {
  659. util::fail('请填写' . $productName . '的零售价');
  660. }
  661. $skPrice = $product['skPrice'];
  662. if (isset($product['hjPrice']) == false || is_numeric($product['hjPrice']) == false || $product['hjPrice'] < 0) {
  663. util::fail('请填写' . $productName . '的会员价');
  664. }
  665. $hjPrice = $product['hjPrice'] ?? 0;
  666. if (isset($productInfo->mainId) == false || $productInfo->mainId != $this->mainId) {
  667. util::fail('无法访问');
  668. }
  669. if ($hjPrice > $price) {
  670. util::fail($productName . ' 批发价要大于会员价');
  671. }
  672. if ($price > $skPrice) {
  673. util::fail($productName . ' 零售价要大于批发价');
  674. }
  675. $ptItemId = $productInfo->itemId;
  676. ProductClass::changeSinglePrice($shop, $ptItemId, $price, $skPrice, $hjPrice, $changeParams);
  677. //在首店修改需要同步到所有直营店
  678. if ($default == 1 && isset($shop->dataSync) && $shop->dataSync == 1) {
  679. foreach ($chainShopList as $chain) {
  680. if ($chain->id == $shop->id) {
  681. continue;
  682. }
  683. $chainMainId = $chain->mainId ?? 0;
  684. $staff = ShopAdminClass::getByCondition(['mainId' => $chainMainId, 'adminId' => $adminId], true);
  685. $staffId = $staff->id ?? 0;
  686. $staffName = $staff->name ?? '';
  687. $changeParams2 = ['staffId' => $staffId, 'staffName' => $staffName, 'changeType' => $changeType, 'targetId' => $targetId];
  688. ProductClass::changeSinglePrice($chain, $ptItemId, $price, $skPrice, $hjPrice, $changeParams2);
  689. }
  690. }
  691. }
  692. $mainId = $shop->mainId ?? 0;
  693. if (!empty($mainId)) {
  694. //提醒零售收银台界面要刷新
  695. $staffList = ShopAdminClass::getAllByCondition(['mainId' => $mainId], null, '*', null, true);
  696. if (!empty($staffList)) {
  697. foreach ($staffList as $staff) {
  698. $staffId = $staff->id ?? 0;
  699. Yii::$app->redis->executeCommand('SET', ['cashier_' . $mainId . '_' . $staffId . '_may_refresh', 'yes']);
  700. Yii::$app->redis->executeCommand('SET', ['ghs_cashier_' . $mainId . '_' . $staffId . '_may_refresh', 'yes']);
  701. }
  702. }
  703. }
  704. $transaction->commit();
  705. //入库成功通知相关人员,关键词 put_in_notice
  706. if ($needNotice) {
  707. // $cg = PurchaseOrderClass::getLockById($targetId);
  708. // WxMessageClass::ghsCgEntryInform($shop, $cg);
  709. }
  710. util::complete('操作成功');
  711. } catch (\Exception $e) {
  712. $transaction->rollBack();
  713. $msg = $e->getMessage();
  714. Yii::info("修改失败原因:" . $msg);
  715. noticeUtil::push("修改价格出现失败情况,原因:" . $msg, '15280215347');
  716. util::fail('修改失败');
  717. }
  718. }
  719. //多个花材同时改成一个价 ssh 20231003
  720. public function actionManyItemChangeOnePrice()
  721. {
  722. $shop = $this->shop;
  723. $join = $shop->join ?? 0;
  724. $default = $shop->default ?? 0;
  725. if ($join == 0 && $default == 0) {
  726. util::fail('当前直营分店,只能回总店修改价格');
  727. }
  728. $shopAdmin = $this->shopAdmin;
  729. if (isset($shopAdmin->super) == false || $shopAdmin->super != 1) {
  730. util::fail('超管才能修改');
  731. }
  732. $post = Yii::$app->request->post();
  733. $idsList = $post['ids'] ?? '';
  734. $ids = json_decode($idsList, true);
  735. if (empty($ids)) {
  736. util::fail('请选择花材');
  737. }
  738. $list = ProductClass::getAllByCondition(['id' => ['in', $ids]], null, '*', null, true);
  739. if (empty($list)) {
  740. util::fail('请选择花材哦');
  741. }
  742. $mainId = $this->mainId;
  743. $adminId = $this->adminId ?? 0;
  744. $shop = $this->shop;
  745. $default = $shop->default ?? 0;
  746. $shopAdmin = $this->shopAdmin;
  747. $price = $post['price'] ?? 0;
  748. if (is_numeric($price) == false) {
  749. util::fail('批发价填写错误');
  750. }
  751. $skPrice = $post['skPrice'] ?? 0;
  752. if (is_numeric($skPrice) == false) {
  753. util::fail('散客价填写错误');
  754. }
  755. $hjPrice = $post['hjPrice'] ?? 0;
  756. if (is_numeric($hjPrice) == false) {
  757. util::fail('会员价填写错误');
  758. }
  759. if ($hjPrice > $price) {
  760. util::fail('会员价不能大于批发价');
  761. }
  762. if ($price > $skPrice) {
  763. util::fail('批发价不能大于零售价');
  764. }
  765. $sjId = $shop->sjId ?? 0;
  766. $chainShopList = [];
  767. if ($default == 1) {
  768. $chainShopList = ShopClass::getAllByCondition(['sjId' => $sjId, 'join' => 0], null, '*', null, true);
  769. }
  770. //normal常规改价,cg采购改价
  771. $changeType = Yii::$app->request->post('changeType', 'normal');
  772. $targetId = 0;
  773. $changeParams = ['staffId' => $shopAdmin->id, 'staffName' => $shopAdmin->name, 'changeType' => $changeType, 'targetId' => $targetId];
  774. $connection = Yii::$app->db;
  775. $transaction = $connection->beginTransaction();
  776. try {
  777. foreach ($list as $product) {
  778. if ($product->mainId != $mainId) {
  779. util::fail('修改失败,不是你的花材');
  780. }
  781. $ptItemId = $product->itemId;
  782. ProductClass::changeSinglePrice($shop, $ptItemId, $price, $skPrice, $hjPrice, $changeParams);
  783. //在首店修改需要同步到所有直营店
  784. if ($default == 1 && isset($shop->dataSync) && $shop->dataSync == 1) {
  785. if (!empty($chainShopList)) {
  786. foreach ($chainShopList as $chain) {
  787. if ($chain->id == $shop->id) {
  788. continue;
  789. }
  790. $chainMainId = $chain->mainId ?? 0;
  791. $staff = ShopAdminClass::getByCondition(['mainId' => $chainMainId, 'adminId' => $adminId], true);
  792. $changeParams2 = ['staffId' => $staff->id, 'staffName' => $staff->name, 'changeType' => $changeType, 'targetId' => $targetId];
  793. ProductClass::changeSinglePrice($chain, $ptItemId, $price, $skPrice, $hjPrice, $changeParams2);
  794. }
  795. }
  796. }
  797. }
  798. if (!empty($mainId)) {
  799. //提醒零售收银台界面要刷新
  800. $staffList = ShopAdminClass::getAllByCondition(['mainId' => $mainId], null, '*', null, true);
  801. if (!empty($staffList)) {
  802. foreach ($staffList as $staff) {
  803. $staffId = $staff->id ?? 0;
  804. Yii::$app->redis->executeCommand('SET', ['cashier_' . $mainId . '_' . $staffId . '_may_refresh', 'yes']);
  805. Yii::$app->redis->executeCommand('SET', ['ghs_cashier_' . $mainId . '_' . $staffId . '_may_refresh', 'yes']);
  806. }
  807. }
  808. }
  809. $transaction->commit();
  810. util::complete('修改成功');
  811. } catch (\Exception $e) {
  812. $transaction->rollBack();
  813. Yii::info("修改失败原因:" . $e->getMessage());
  814. util::fail('修改失败');
  815. }
  816. }
  817. //改价
  818. public function actionChangePrice()
  819. {
  820. $shopAdmin = $this->shopAdmin;
  821. if (isset($shopAdmin->super) == false || $shopAdmin->super != 1) {
  822. util::fail('超管才能修改');
  823. }
  824. $productId = Yii::$app->request->post('productId', 0);
  825. $productInfo = ProductClass::getById($productId, true);
  826. if (empty($productInfo)) {
  827. util::fail("花材不存在");
  828. }
  829. if ($productInfo->mainId != $this->mainId) {
  830. util::fail('没有权限');
  831. }
  832. $price = Yii::$app->request->post('price', '');
  833. if (is_numeric($price) && $price > 0) {
  834. ProductClass::changeSinglePrice($productInfo, $price, ProductClass::PRICE_LABEL_CHANGE);
  835. } else {
  836. $price = bcadd($productInfo->cost, $productInfo->addPrice, 2);
  837. ProductClass::changeSinglePrice($productInfo, $price, ProductClass::PRICE_LABEL_AUTO);
  838. }
  839. util::success(['price' => $price]);
  840. }
  841. //恢复自动调价
  842. public function actionAutoPrice()
  843. {
  844. $productId = Yii::$app->request->post('productId', 0);
  845. $productData = ProductClass::getById($productId);
  846. if (!$productData) {
  847. util::fail("花材不存在");
  848. }
  849. //2021.04.06改为用product中的成本价+加价
  850. $price = bcadd($productData['cost'], $productData['addPrice'], 2);
  851. ProductClass::changeSinglePrice($productId, $this->shopId, $price, ProductClass::PRICE_LABEL_AUTO);
  852. util::complete("操作成功");
  853. }
  854. //修改加价
  855. public function actionChangeAddPrice()
  856. {
  857. $productId = Yii::$app->request->post('productId', 0);
  858. $addPrice = Yii::$app->request->post('addPrice', '');
  859. if ($addPrice < 0) {
  860. util::fail("加价不能小于0");
  861. }
  862. $productData = ProductClass::getProductData($productId, $this->mainId);
  863. if (!$productData) {
  864. util::fail("花材不存在");
  865. }
  866. ProductClass::changeAddPrice($productId, $addPrice);
  867. util::complete();
  868. }
  869. //批量修改更多,包括排序、重量和保质期 ssh 20211211
  870. public function actionBatchChangeMore()
  871. {
  872. $shop = $this->shop;
  873. $default = $shop->default ?? 0;
  874. if ($default == 0) {
  875. util::fail('当前直营分店,请返回总店修改');
  876. }
  877. $shopAdmin = $this->shopAdmin;
  878. if (isset($shopAdmin->super) == false || $shopAdmin->super != 1) {
  879. util::fail('超管才能操作');
  880. }
  881. $addData = Yii::$app->request->post('addData', '');
  882. if (empty($addData)) {
  883. util::fail('没有花材');
  884. }
  885. $itemData = json_decode($addData, true);
  886. if (is_array($itemData) == false) {
  887. util::fail('没有花材...');
  888. }
  889. $ids = array_column($itemData, 'id');
  890. $infoList = ProductClass::getByIds($ids, null, 'id');
  891. if (empty($infoList)) {
  892. util::fail('没有花材');
  893. }
  894. foreach ($infoList as $info) {
  895. if (isset($info['mainId']) == false || $info['mainId'] != $this->mainId) {
  896. util::fail('不是你的花材不能修改');
  897. }
  898. }
  899. //总店修改同步到所有门店
  900. $sjId = $shop->sjId ?? 0;
  901. $chainShopList = ShopClass::getAllByCondition(['sjId' => $sjId], null, '*', null, true);
  902. foreach ($itemData as $key => $data) {
  903. $id = $data['id'] ?? 0;
  904. unset($data['id']);
  905. ProductClass::updateById($id, $data);
  906. $ptItemId = $infoList[$id]['itemId'] ?? 0;
  907. if (empty($ptItemId)) {
  908. continue;
  909. }
  910. if (isset($shop->default) && $shop->default == 1 && isset($shop->dataSync) && $shop->dataSync == 1) {
  911. foreach ($chainShopList as $chainShop) {
  912. $currentMainId = $chainShop->mainId ?? 0;
  913. if ($currentMainId == $shop->mainId) {
  914. //前面已经修改过了,不需要重复修改
  915. continue;
  916. }
  917. ProductClass::updateByCondition(['mainId' => $currentMainId, 'itemId' => $ptItemId], $data);
  918. }
  919. }
  920. }
  921. util::complete('修改成功');
  922. }
  923. //批量修改加价 ssh 20211211
  924. public function actionBatchChangeAddPrice()
  925. {
  926. $shop = $this->shop;
  927. $join = $shop->join ?? 0;
  928. $default = $shop->default ?? 0;
  929. if ($join == 0 && $default == 0) {
  930. util::fail('当前直营分店,请切回总店操作');
  931. }
  932. $shopAdmin = $this->shopAdmin;
  933. if (isset($shopAdmin->super) == false || $shopAdmin->super != 1) {
  934. util::fail('超管才能操作');
  935. }
  936. $post = Yii::$app->request->post();
  937. $addData = $post['addData'] ?? '';
  938. if (empty($addData)) {
  939. util::fail('没有花材');
  940. }
  941. $itemData = json_decode($addData, true);
  942. if (is_array($itemData) == false) {
  943. util::fail('没有花材...');
  944. }
  945. $ids = array_column($itemData, 'id');
  946. $infoList = ProductClass::getByIds($ids, null, 'id');
  947. if (empty($infoList)) {
  948. util::fail('没有花材');
  949. }
  950. foreach ($infoList as $info) {
  951. if (isset($info['mainId']) == false || $info['mainId'] != $this->mainId) {
  952. util::fail('不能修改别人的花材');
  953. }
  954. }
  955. $appVersion = $post['appVersion'] ?? 0;
  956. if ($appVersion != 1) {
  957. util::fail('请先升级应用');
  958. }
  959. //总店修改同步到所有门店
  960. $sjId = $shop->sjId ?? 0;
  961. $chainShopList = ShopClass::getAllByCondition(['sjId' => $sjId], null, '*', null, true);
  962. foreach ($itemData as $key => $data) {
  963. $id = $data['id'] ?? 0;
  964. unset($data['id']);
  965. ProductClass::updateById($id, $data);
  966. $ptItemId = $infoList[$id]['itemId'] ?? 0;
  967. if (empty($ptItemId)) {
  968. continue;
  969. }
  970. if (isset($shop->default) && $shop->default == 1 && isset($shop->dataSync) && $shop->dataSync == 1) {
  971. foreach ($chainShopList as $chainShop) {
  972. if (isset($chainShop->join) && $chainShop->join == 1) {
  973. continue;
  974. }
  975. $currentMainId = $chainShop->mainId ?? 0;
  976. if ($currentMainId == $shop->mainId) {
  977. //前面已经修改过了,不需要重复修改
  978. continue;
  979. }
  980. ProductClass::updateByCondition(['mainId' => $currentMainId, 'itemId' => $ptItemId], $data);
  981. }
  982. }
  983. }
  984. util::complete('修改成功');
  985. }
  986. public function actionUpdate()
  987. {
  988. $shopAdmin = $this->shopAdmin;
  989. if (isset($shopAdmin->super) == false || $shopAdmin->super != 1) {
  990. util::fail('超管才能操作');
  991. }
  992. $shop = $this->shop;
  993. $join = $shop->join ?? 0;
  994. $default = $shop->default ?? 0;
  995. if ($join == 0 && $default == 0) {
  996. //因为盘点不能将花材盘成0,所以这边放出入口允许创始人在分店修改分店的花材库存
  997. if ($shopAdmin->super != 1) {
  998. util::fail('请先开通超管权限');
  999. }
  1000. }
  1001. $post = Yii::$app->request->post();
  1002. $discountPrice = $post['discountPrice'] ?? 0;
  1003. if ($discountPrice > 0) {
  1004. if (isset($post['hjDiscountPrice']) == false || empty($post['hjDiscountPrice'])) {
  1005. $addPrice = $post['addPrice'] ?? 0;
  1006. $hjAddPrice = $post['hjAddPrice'] ?? 0;
  1007. $skMore = $post['skMore'] ?? 0;
  1008. $diff = bcsub($addPrice, $hjAddPrice, 2);
  1009. if ($diff > 0 && $discountPrice > $diff) {
  1010. $hjDiscountPrice = bcsub($discountPrice, $diff, 2);
  1011. } else {
  1012. $hjDiscountPrice = $discountPrice;
  1013. }
  1014. $diff = bcsub($skMore, $addPrice, 2);
  1015. if ($diff > 0) {
  1016. $skDiscountPrice = bcadd($diff, $discountPrice, 2);
  1017. } else {
  1018. $skDiscountPrice = $discountPrice;
  1019. }
  1020. $post['skDiscountPrice'] = $skDiscountPrice;
  1021. $post['hjDiscountPrice'] = $hjDiscountPrice;
  1022. }
  1023. $reachNum = $post['reachNum'] ?? 0;
  1024. $reachNumDiscount = $post['reachNumDiscount'] ?? 0;
  1025. if ($reachNum > 0 && $reachNumDiscount > 0) {
  1026. util::fail('特价和满减不能同时进行');
  1027. }
  1028. }
  1029. $post['adminId'] = $this->adminId;
  1030. $post['staffId'] = $this->shopAdmin->id;
  1031. $post['staffName'] = $this->shopAdmin->name;
  1032. $connection = Yii::$app->db;
  1033. $transaction = $connection->beginTransaction();
  1034. try {
  1035. ProductClass::updateProduct($post, $this->shop);
  1036. $transaction->commit();
  1037. util::complete();
  1038. } catch (\Exception $e) {
  1039. Yii::info("操作失败:" . $e->getMessage());
  1040. $transaction->rollBack();
  1041. util::fail('操作失败');
  1042. }
  1043. }
  1044. //上下架状态控制 ssh 20210713
  1045. public function actionStatusUpdate()
  1046. {
  1047. $post = Yii::$app->request->post();
  1048. $shopAdmin = $this->shopAdmin;
  1049. $roleId = $shopAdmin['roleId'] ?? 0;
  1050. $role = AdminRoleClass::getById($roleId);
  1051. $roleName = $role['roleName'] ?? '';
  1052. if ($roleName == '员工') {
  1053. util::fail('无法操作哦');
  1054. }
  1055. $id = $post['id'] ?? 0;
  1056. $status = $post['status'] ?? 1;
  1057. $product = ProductClass::getById($id, true);
  1058. if ($product->mainId != $this->mainId) {
  1059. util::fail('无法操作');
  1060. }
  1061. $product->status = $status;
  1062. if ($status == 2) {
  1063. $product->discountPrice = 0;
  1064. }
  1065. $product->save();
  1066. util::complete();
  1067. }
  1068. //花材展示状态控制 ssh 20231113
  1069. public function actionDelStatusUpdate()
  1070. {
  1071. $post = Yii::$app->request->post();
  1072. $shop = $this->shop;
  1073. $join = $shop->join ?? 0;
  1074. $default = $shop->default ?? 0;
  1075. if ($join == 0 && $default == 0) {
  1076. util::fail('请在首店操作');
  1077. }
  1078. $id = $post['id'] ?? 0;
  1079. $delStatus = $post['delStatus'] ?? 0;
  1080. $product = ProductClass::getById($id, true);
  1081. if ($product->mainId != $this->mainId) {
  1082. util::fail('不是你的花材哦!!');
  1083. }
  1084. $product->delStatus = $delStatus;
  1085. if ($delStatus == 1) {
  1086. $product->stock = 0;
  1087. $product->status = 2;
  1088. }
  1089. $product->save();
  1090. $ptItemId = $product->itemId ?? 0;
  1091. if (isset($shop->default) && $shop->default == 1 && isset($shop->dataSync) && $shop->dataSync == 1) {
  1092. //总店修改同步到所有门店
  1093. $sjId = $shop->sjId ?? 0;
  1094. $chainShopList = ShopClass::getAllByCondition(['sjId' => $sjId], null, '*', null, true);
  1095. foreach ($chainShopList as $chainShop) {
  1096. $chainShopId = $chainShop->id ?? 0;
  1097. if (isset($chainShop->join) && $chainShop->join == 1) {
  1098. continue;
  1099. }
  1100. if ($chainShopId == $shop->id) {
  1101. continue;
  1102. }
  1103. $chainMainId = $chainShop->mainId ?? 0;
  1104. $chainProduct = ProductClass::getByCondition(['mainId' => $chainMainId, 'itemId' => $ptItemId], true);
  1105. if (!empty($chainProduct)) {
  1106. $chainProduct->delStatus = $delStatus;
  1107. if ($delStatus == 1) {
  1108. $chainProduct->stock = 0;
  1109. $chainProduct->status = 2;
  1110. }
  1111. $chainProduct->save();
  1112. }
  1113. }
  1114. }
  1115. util::complete();
  1116. }
  1117. //详情 shish 20240115
  1118. public function actionDetail()
  1119. {
  1120. $id = Yii::$app->request->get('id', 0);
  1121. $source = Yii::$app->request->get('source', '');
  1122. $respond = ProductClass::getItemInfo($id);
  1123. $ptItemId = $respond['itemId'] ?? 0;
  1124. $ptItemInfo = PtItemClass::getById($ptItemId);
  1125. $respond['ptItemInfo'] = $ptItemInfo;
  1126. //通知提醒抹除
  1127. if ($source == 'notify' && $respond['mainId'] == $this->mainId) {
  1128. $staff = $this->shopAdmin;
  1129. $staffId = $this->shopAdminId;
  1130. $notify = NotifyClass::getByCondition(['staffId' => $staffId, 'type' => 1, 'targetId' => $id], true);
  1131. if (!empty($notify)) {
  1132. if ($notify->read == 0) {
  1133. $notify->read = 1;
  1134. $notify->save();
  1135. $notifyNum = $staff->notifyNum;
  1136. if ($notifyNum > 0) {
  1137. $notifyNum--;
  1138. $staff->notifyNum = $notifyNum;
  1139. $staff->save();
  1140. }
  1141. }
  1142. }
  1143. }
  1144. //重复花材
  1145. $repeatList = ProductClass::getAllByCondition(['mainId' => $this->mainId, 'itemId' => $ptItemId, 'delStatus' => 0], null, '*', null, true);
  1146. $repeatId = 0;
  1147. if (!empty($repeatList)) {
  1148. foreach ($repeatList as $repeat) {
  1149. if ($repeat->id != $id) {
  1150. $repeatId = $repeat->id;
  1151. }
  1152. }
  1153. }
  1154. $respond['repeatId'] = $repeatId;
  1155. $cpItemList = CpItemClass::getAllByCondition(['productId' => $id], null, '*', 'cpId');
  1156. $cpInfo = [];
  1157. if (!empty($cpItemList)) {
  1158. $cpIds = array_column($cpItemList, 'cpId');
  1159. $cpList = CpClass::getByIds($cpIds);
  1160. if (!empty($cpList)) {
  1161. foreach ($cpList as $key => $val) {
  1162. $id = $val['id'] ?? 0;
  1163. $name = $val['name'] ?? '';
  1164. $cpInfo[] = ['cpId' => $id, 'cpName' => $name];
  1165. }
  1166. }
  1167. }
  1168. $respond['cpInfo'] = $cpInfo;
  1169. util::success($respond);
  1170. }
  1171. //新增花材 2021.6.21
  1172. public function actionAdd()
  1173. {
  1174. $post = Yii::$app->request->post();
  1175. //临时兼容,2023.7.1后可以删除
  1176. $appVersion = $post['appVersion'] ?? 0;
  1177. if ($appVersion != 1) {
  1178. util::fail('请先升级应用');
  1179. }
  1180. $discountPrice = $post['discountPrice'] ?? 0;
  1181. if ($discountPrice > 0) {
  1182. if (isset($post['hjDiscountPrice']) == false || empty($post['hjDiscountPrice'])) {
  1183. $addPrice = $post['addPrice'] ?? 0;
  1184. $hjAddPrice = $post['hjAddPrice'] ?? 0;
  1185. $skMore = $post['skMore'] ?? 0;
  1186. $diff = bcsub($addPrice, $hjAddPrice, 2);
  1187. if ($diff > 0 && $discountPrice > $diff) {
  1188. $hjDiscountPrice = bcsub($discountPrice, $diff, 2);
  1189. } else {
  1190. $hjDiscountPrice = $discountPrice;
  1191. }
  1192. $diff = bcsub($skMore, $addPrice, 2);
  1193. if ($diff > 0) {
  1194. $skDiscountPrice = bcadd($diff, $discountPrice, 2);
  1195. } else {
  1196. $skDiscountPrice = $discountPrice;
  1197. }
  1198. $post['skDiscountPrice'] = $skDiscountPrice;
  1199. $post['hjDiscountPrice'] = $hjDiscountPrice;
  1200. }
  1201. }
  1202. $shop = $this->shop;
  1203. $join = $shop->join ?? 0;
  1204. $default = $shop->default ?? 0;
  1205. if ($join == 0 && $default == 0) {
  1206. util::fail('当前直营分店,请切回总店添加花材');
  1207. }
  1208. $shopAdmin = $this->shopAdmin;
  1209. if (isset($shopAdmin->super) == false || $shopAdmin->super != 1) {
  1210. util::fail('管理员才能添加花材');
  1211. }
  1212. $post['sjId'] = $this->sjId;
  1213. $post['adminId'] = $this->adminId;
  1214. $post['mainId'] = $this->mainId;
  1215. $price = $post['price'] ?? 0;
  1216. $addPrice = $post['addPrice'] ?? 0;
  1217. if ($addPrice > $price) {
  1218. util::fail('加价不能大于售价');
  1219. }
  1220. $weight = isset($post['weight']) && is_numeric($post['weight']) ? $post['weight'] : 0;
  1221. if ($weight <= 0) {
  1222. util::fail('请填写重量,最小0.1');
  1223. }
  1224. $post['staffName'] = $shopAdmin->name ?? '';
  1225. ProductClass::addProduct($post, $this->shop);
  1226. util::complete('添加成功');
  1227. }
  1228. //获取拼音缩写 ssh 20210707
  1229. public function actionPy()
  1230. {
  1231. $name = Yii::$app->request->get('name');
  1232. $py = stringUtil::py($name);
  1233. util::success(['py' => $py]);
  1234. }
  1235. //(客户端-批发商)复制花材
  1236. public function actionClone()
  1237. {
  1238. $post = Yii::$app->request->post();
  1239. $appVersion = $post['appVersion'] ?? 0;
  1240. if ($appVersion != 1) {
  1241. util::fail('请先升级应用');
  1242. }
  1243. $discountPrice = $post['discountPrice'] ?? 0;
  1244. if ($discountPrice > 0) {
  1245. if (isset($post['hjDiscountPrice']) == false || empty($post['hjDiscountPrice'])) {
  1246. $addPrice = $post['addPrice'] ?? 0;
  1247. $hjAddPrice = $post['hjAddPrice'] ?? 0;
  1248. $skMore = $post['skMore'] ?? 0;
  1249. $diff = bcsub($addPrice, $hjAddPrice, 2);
  1250. if ($diff > 0 && $discountPrice > $diff) {
  1251. $hjDiscountPrice = bcsub($discountPrice, $diff, 2);
  1252. } else {
  1253. $hjDiscountPrice = $discountPrice;
  1254. }
  1255. $diff = bcsub($skMore, $addPrice, 2);
  1256. if ($diff > 0) {
  1257. $skDiscountPrice = bcadd($diff, $discountPrice, 2);
  1258. } else {
  1259. $skDiscountPrice = $discountPrice;
  1260. }
  1261. $post['skDiscountPrice'] = $skDiscountPrice;
  1262. $post['hjDiscountPrice'] = $hjDiscountPrice;
  1263. }
  1264. }
  1265. $shop = $this->shop;
  1266. $join = $shop->join ?? 0;
  1267. $default = $shop->default ?? 0;
  1268. if ($join == 0 && $default == 0) {
  1269. util::fail('请在首店操作');
  1270. }
  1271. $shopAdmin = $this->shopAdmin;
  1272. if (isset($shopAdmin->super) == false || $shopAdmin->super != 1) {
  1273. util::fail('管理员才能添加花材');
  1274. }
  1275. $post['sjId'] = $this->sjId;
  1276. $post['adminId'] = $this->adminId;
  1277. $post['mainId'] = $this->mainId;
  1278. $post['staffName'] = $shopAdmin->name ?? '';
  1279. $price = $post['price'] ?? 0;
  1280. if (empty($price) || $price <= 0) {
  1281. util::fail('请填写批发价');
  1282. }
  1283. $skPrice = $post['skPrice'] ?? 0;
  1284. if (empty($skPrice) || $skPrice <= 0) {
  1285. util::fail('请填写零售价');
  1286. }
  1287. $hjPrice = $post['hjPrice'] ?? 0;
  1288. if (empty($hjPrice) || $hjPrice <= 0) {
  1289. util::fail('请填写会员价');
  1290. }
  1291. $addPrice = $post['addPrice'] ?? 0;
  1292. if ($addPrice > $price) {
  1293. util::fail('批发价的加价不能大于售价');
  1294. }
  1295. //复制标识
  1296. $post['copy'] = 1;
  1297. //去除无用的字段
  1298. unset($post['viewNum']);
  1299. unset($post['actualSold']);
  1300. unset($post['itemId']);
  1301. unset($post['id']);
  1302. unset($post['delStatus']);
  1303. ProductClass::addProduct($post, $this->shop);
  1304. util::complete('复制成功');
  1305. }
  1306. //下载价格表 ssh 20210922
  1307. public function actionGeneratePriceTable()
  1308. {
  1309. $level = Yii::$app->request->get('level', 0);
  1310. $respond = ProductService::generatePriceTable($this->sjId, $level, $this->mainId);
  1311. $file = $respond['file'] ?? '';
  1312. $shortFile = $respond['shortFile'] ?? '';
  1313. $fileUrl = Yii::$app->params['ghsHost'] . $file;
  1314. util::success(['file' => $fileUrl, 'shortFile' => $shortFile]);
  1315. }
  1316. //下载有库存花材,不含虚拟库存 ssh 20241-28
  1317. public function actionGenerateStockTable()
  1318. {
  1319. $level = Yii::$app->request->get('level', 0);
  1320. $respond = ProductService::generateStockTable($this->sjId, $level, $this->mainId);
  1321. $file = $respond['file'] ?? '';
  1322. $shortFile = $respond['shortFile'] ?? '';
  1323. $fileUrl = Yii::$app->params['ghsHost'] . $file;
  1324. util::success(['file' => $fileUrl, 'shortFile' => $shortFile]);
  1325. }
  1326. public function actionGenerateItemTable()
  1327. {
  1328. $level = Yii::$app->request->get('level', 0);
  1329. $respond = ProductService::generateItemTable($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. //下载条形码 lqh 20211227
  1336. public function actionGenerateBarcodeTable()
  1337. {
  1338. $respond = ProductService::generateBarcodeTable($this->sjId, $this->shopId, $this->mainId);
  1339. $file = $respond['file'] ?? '';
  1340. $shortFile = $respond['shortFile'] ?? '';
  1341. $fileUrl = Yii::$app->params['ghsHost'] . $file;
  1342. util::success(['file' => $fileUrl, 'shortFile' => $shortFile]);
  1343. }
  1344. //批量修改花材的分类 ssh 20230405
  1345. public function actionBatchModifyClass()
  1346. {
  1347. $post = Yii::$app->request->post();
  1348. $shop = $this->shop;
  1349. $sjName = $shop->merchantName ?? '';
  1350. $shopName = $shop->shopName ?? '';
  1351. $sjShopName = $shop->shopName == '首店' ? $sjName : $sjName . ' ' . $shopName;
  1352. //noticeUtil::push($sjShopName . ' 批量移动花材分类', '15280215347');
  1353. $join = $shop->join ?? 0;
  1354. $default = $shop->default ?? 0;
  1355. if ($join == 0 && $default == 0) {
  1356. util::fail('当前直营分店,请切回总店操作');
  1357. }
  1358. $classId = $post['classId'] ?? 0;
  1359. $class = ItemClassClass::getById($classId, true);
  1360. if (empty($class) || $class->mainId != $this->mainId) {
  1361. util::fail('请选择您自己的分类');
  1362. }
  1363. $connection = Yii::$app->db;
  1364. $transaction = $connection->beginTransaction();
  1365. try {
  1366. $className = $class->name ?? '';
  1367. $idsList = $post['ids'] ?? '';
  1368. $ids = json_decode($idsList, true);
  1369. if (empty($ids)) {
  1370. util::fail('请选择花材');
  1371. }
  1372. $list = ProductClass::getAllByCondition(['id' => ['in', $ids]], null, '*', null, true);
  1373. if (empty($list)) {
  1374. util::fail('请选择花材');
  1375. }
  1376. $ptItemList = [];
  1377. foreach ($list as $item) {
  1378. $name = $item->name ?? '';
  1379. if ($item->mainId != $this->mainId) {
  1380. util::fail($name . '不是您的花材');
  1381. }
  1382. $item->classId = $classId;
  1383. $item->save();
  1384. $ptItemId = $item->itemId ?? 0;
  1385. $ptItemList[] = $ptItemId;
  1386. //如果有修改分类,则在多个订单表中同步修改,如需修改,多个地方要同步修改,请搜索关键词item_class_modify_sync
  1387. $itemClassKey = 'item_class_modify_sync';
  1388. Yii::$app->redis->executeCommand('LPUSH', [$itemClassKey, $item->id]);
  1389. }
  1390. $shop = $this->shop;
  1391. if (isset($shop->default) && $shop->default == 1 && isset($shop->dataSync) && $shop->dataSync == 1) {
  1392. //总店修改同步到所有门店
  1393. $sjId = $shop->sjId ?? 0;
  1394. $chainShopList = ShopClass::getAllByCondition(['sjId' => $sjId], null, '*', null, true);
  1395. foreach ($chainShopList as $chainShop) {
  1396. $chainShopId = $chainShop->id ?? 0;
  1397. if ($chainShopId == $shop->id) {
  1398. continue;
  1399. }
  1400. $chainManId = $chainShop->mainId ?? 0;
  1401. $chainAllClassList = ItemClassClass::getAllByCondition(['mainId' => $chainManId], null, '*', null, true);
  1402. if (!empty($chainAllClassList)) {
  1403. foreach ($chainAllClassList as $chainClass) {
  1404. $chainName = $chainClass->name ?? '';
  1405. $chainClassId = $chainClass->id ?? 0;
  1406. if ($chainName == $className) {
  1407. $chainProductList = Productclass::getAllByCondition(['mainId' => $chainManId, 'itemId' => ['in', $ptItemList]], null, '*', null, true);
  1408. if (!empty($chainProductList)) {
  1409. foreach ($chainProductList as $currentProduct) {
  1410. $currentProduct->classId = $chainClassId;
  1411. $currentProduct->save();
  1412. //如果有修改分类,则在多个订单表中同步修改,如需修改,多个地方要同步修改,请搜索关键词item_class_modify_sync
  1413. $itemClassKey = 'item_class_modify_sync';
  1414. Yii::$app->redis->executeCommand('LPUSH', [$itemClassKey, $currentProduct->id]);
  1415. }
  1416. }
  1417. }
  1418. }
  1419. }
  1420. }
  1421. }
  1422. $transaction->commit();
  1423. util::complete('修改成功');
  1424. } catch (\Exception $e) {
  1425. $transaction->rollBack();
  1426. Yii::info("修改失败原因:" . $e->getMessage());
  1427. util::fail('修改失败');
  1428. }
  1429. }
  1430. //批量修改采购人 ssh 20240609
  1431. public function actionBatchModifyCgStaff()
  1432. {
  1433. $post = Yii::$app->request->post();
  1434. $staffId = $post['staffId'] ?? 0;
  1435. $staff = ShopAdminClass::getById($staffId, true);
  1436. if (empty($staff)) {
  1437. util::fail('没有找到这个员工');
  1438. }
  1439. if ($staff->mainId != $this->mainId) {
  1440. util::fail('不是你的员工');
  1441. }
  1442. $staffName = $staff->name ?? '';
  1443. $connection = Yii::$app->db;
  1444. $transaction = $connection->beginTransaction();
  1445. try {
  1446. $idsList = $post['ids'] ?? '';
  1447. $ids = json_decode($idsList, true);
  1448. if (empty($ids)) {
  1449. util::fail('请选择花材');
  1450. }
  1451. $list = ProductClass::getAllByCondition(['id' => ['in', $ids]], null, '*', null, true);
  1452. if (empty($list)) {
  1453. util::fail('请选择花材');
  1454. }
  1455. $shop = $this->shop;
  1456. $bookSn = $shop->bookSn ?? 0;
  1457. foreach ($list as $item) {
  1458. $name = $item->name ?? '';
  1459. if ($item->mainId != $this->mainId) {
  1460. util::fail($name . '不是您的花材');
  1461. }
  1462. $item->cgStaffId = $staffId;
  1463. $item->cgStaffName = $staffName;
  1464. $item->save();
  1465. $itemId = $item->id ?? 0;
  1466. if (!empty($bookSn)) {
  1467. //预订管理的花材需要变化
  1468. BookItemClass::updateByCondition(['bookSn' => $bookSn, 'itemId' => $itemId], ['cgStaffId' => $staffId, 'cgStaffName' => $staffName]);
  1469. }
  1470. }
  1471. $transaction->commit();
  1472. util::complete('修改成功');
  1473. } catch (\Exception $e) {
  1474. $transaction->rollBack();
  1475. Yii::info("修改失败原因:" . $e->getMessage());
  1476. util::fail('修改失败');
  1477. }
  1478. }
  1479. //修改属于成本还是收入选项 ssh 20240514
  1480. public function actionChangeBelongCost()
  1481. {
  1482. $get = Yii::$app->request->get();
  1483. $id = $get['id'] ?? 0;
  1484. $belongCost = $get['belongCost'] ?? 0;
  1485. $info = ProductClass::getById($id, true);
  1486. if (empty($info)) {
  1487. util::fail('没有找到花材');
  1488. }
  1489. if ($info->mainId != $this->mainId) {
  1490. util::fail('不是你的花材哦');
  1491. }
  1492. $info->belongCost = $belongCost;
  1493. $info->save();
  1494. //队列方式去处理
  1495. $redisKey = 'change_belong_cost_item_list';
  1496. $value = $id . '_' . $belongCost;
  1497. Yii::$app->redis->executeCommand('LPUSH', [$redisKey, $value]);
  1498. util::complete('修改成功');
  1499. }
  1500. }