ProductController.php 45 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115
  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 bizGhs\custom\classes\CustomClass;
  10. use bizGhs\item\classes\ItemClass;
  11. use bizGhs\item\classes\ItemClassClass;
  12. use bizGhs\merchant\classes\ShopClass;
  13. use bizGhs\order\classes\PurchaseOrderClass;
  14. use bizGhs\product\classes\ProductClass;
  15. use bizGhs\product\models\Product;
  16. use bizGhs\product\services\ProductService;
  17. use bizGhs\shop\classes\ShopAdminClass;
  18. use bizGhs\stock\classes\StockInDayClass;
  19. use common\components\printUtil;
  20. use common\components\stringUtil;
  21. use common\components\util;
  22. use Yii;
  23. class ProductController extends BaseController
  24. {
  25. public $guestAccess = ['index'];
  26. //停止预售 ssh 20230224
  27. public function actionCancelPreSell()
  28. {
  29. $get = Yii::$app->request->get();
  30. $id = $get['id'] ?? 0;
  31. $info = ProductClass::getById($id, true);
  32. ProductClass::check($info, $this->mainId);
  33. if ($info->stock > 0) {
  34. util::fail('没有库存才能停止预售');
  35. }
  36. $info->presell = 0;
  37. $info->presellDate = '';
  38. $info->save();
  39. util::complete();
  40. }
  41. //修改预售 ssh 20221214
  42. public function actionChangePresell()
  43. {
  44. $post = Yii::$app->request->post();
  45. $id = $post['id'] ?? 0;
  46. $info = ProductClass::getById($id, true);
  47. ProductClass::check($info, $this->mainId);
  48. $str = $post['date'] ?? '';
  49. $presell = $post['presell'] ?? 0;
  50. $newStr = '';
  51. if ($presell == 1) {
  52. if (empty($str)) {
  53. util::fail('请填写预售日期');
  54. }
  55. $arr = json_decode($str, true);
  56. if (empty($arr)) {
  57. util::fail('请填写预售日期');
  58. }
  59. $new = [];
  60. foreach ($arr as $date) {
  61. $new[] = strtotime($date);
  62. }
  63. $new = array_unique(array_filter($new));
  64. asort($new);
  65. $newStr = implode(',', $new);
  66. }
  67. $info->presell = $presell;
  68. $info->presellDate = $newStr;
  69. $info->discountPrice = 0;
  70. $info->save();
  71. util::complete();
  72. }
  73. //取消特价 ssh 20220901
  74. public function actionCancelDiscount()
  75. {
  76. $get = Yii::$app->request->get();
  77. $id = $get['id'] ?? 0;
  78. $info = ProductClass::getById($id, true);
  79. ProductClass::check($info, $this->mainId);
  80. $info->discountPrice = 0;
  81. $info->save();
  82. util::complete();
  83. }
  84. //打印花材的标签 ssh 20220602
  85. public function actionPrint()
  86. {
  87. $get = Yii::$app->request->get();
  88. $id = $get['id'] ?? 0;
  89. $num = $get['num'] ?? 1;
  90. $type = $get['type'] ?? 0;
  91. $info = ProductClass::getById($id, true);
  92. if (empty($info)) {
  93. util::fail('没有找到花材');
  94. }
  95. $name = $info->name ?? '';
  96. $ptItemId = $info->itemId ?? 0;
  97. $mainId = $info->mainId ?? 0;
  98. $ext = $this->shopExt;
  99. $printLabelSn = $ext->printLabelSn ?? '';
  100. if (empty($printLabelSn)) {
  101. util::fail('请设置标签打印机');
  102. }
  103. $p = new printUtil($printLabelSn);
  104. $unit = $info->ratio . $info->smallUnit . '/' . $info->bigUnit;
  105. $p->times = $num;
  106. if (stringUtil::getWordNum($name) > 7) {
  107. $content = '<TEXT x="30" y="30" font="12" w="1" h="1" r="0">' . $name . '</TEXT>';
  108. } else {
  109. $content = '<TEXT x="30" y="30" font="12" w="2" h="2" r="0">' . $name . '</TEXT>';
  110. }
  111. //杭州斗南批发店
  112. if (isset($get['type']) == false && $this->shopId == 4608) {
  113. $content .= '<QR x="35" y="100" e="L" w="5">' . Yii::$app->params['mallHost'] . "/item/show-info?id=" . $id . '</QR>';
  114. $content .= '<TEXT x="40" y="270" font="12" w="1" h="1" r="0">扫码看价格</TEXT>';
  115. } else {
  116. if ($type == 0) {
  117. //打标签
  118. $content .= '<BC128 x="30" y="115" h="75" s="1" r="0" n="3" w="10">' . $ptItemId . '</BC128>';
  119. if (in_array($mainId, [52, 1459])) {
  120. $content .= '<TEXT x="30" y="250" font="12" w="2" h="2" r="0">惠雅鲜花</TEXT>';
  121. } else {
  122. $content .= '<TEXT x="30" y="250" font="12" w="2" h="2" r="0">' . $unit . '</TEXT>';
  123. }
  124. } else {
  125. //打价码
  126. $content .= '<QR x="35" y="100" e="L" w="5">' . Yii::$app->params['mallHost'] . "/item/show-info?id=" . $id . '</QR>';
  127. $content .= '<TEXT x="40" y="270" font="12" w="1" h="1" r="0">扫码看价格</TEXT>';
  128. }
  129. }
  130. $p->printLabelMsg($content);
  131. util::complete();
  132. }
  133. //取出今天有入库的花材 ssh 20221024
  134. public function actionStockIn()
  135. {
  136. $py = Yii::$app->request->get('py', '');
  137. $version = Yii::$app->request->get('version', 0);
  138. if ($version == 0) {
  139. util::fail('请先升级版本到1.0.70以上');
  140. }
  141. $classInfo = ItemClassClass::getGhsItemClassAll($this->mainId);
  142. $mainId = $this->mainId ?? 0;
  143. $where['mainId'] = $mainId;
  144. if ($py) {
  145. $pyName = strtolower($py);
  146. $where['py'] = $pyName;
  147. }
  148. $arr = StockInDayClass::getAllByCondition(['mainId' => $mainId], null, '*');
  149. if (empty($arr)) {
  150. util::fail('没有花材需要盘点');
  151. }
  152. $ids = array_column($arr, 'itemId');
  153. $ids = array_unique($ids);
  154. $where['id'] = ['in', $ids];
  155. $level = 1;
  156. $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';
  157. $itemInfoData = ProductClass::getAllByCondition($where, ['inTurn' => SORT_DESC, 'actualSold' => SORT_DESC], $field);
  158. $itemInfoData = ProductClass::groupProductInfo($itemInfoData, $level);
  159. $data = ProductService::assembleData($classInfo, $itemInfoData, true);
  160. util::success($data);
  161. }
  162. //按分类列出所有花材
  163. public function actionShow()
  164. {
  165. $py = Yii::$app->request->get('py', '');
  166. $requestType = Yii::$app->request->get('requestType', 'common');
  167. //默认显示上架商品
  168. $status = Yii::$app->request->get('status', 1);
  169. //默认显示未删除商品
  170. $delStatus = Yii::$app->request->get('delStatus', 0);
  171. //获取所有当前供货商的分类 (全部、常用)
  172. //根据分类组装分类下的花材信息
  173. //中央ID
  174. $classInfo = ItemClassClass::getGhsItemClassAll($this->mainId);
  175. $where['mainId'] = $this->mainId;
  176. if ($py) {
  177. $pyName = strtolower($py);
  178. $where['py'] = $pyName;
  179. }
  180. //改价和全部有库存花材列表
  181. if ($requestType == 'changePrice' || $requestType == 'hasStockList') {
  182. $where['stock>'] = 0;
  183. }
  184. if (!empty($status)) {
  185. $where['status'] = $status;
  186. }
  187. $where['delStatus'] = $delStatus;
  188. //客户等级
  189. $customId = Yii::$app->request->get('customId', 0);
  190. $level = 1;
  191. if (!empty($customId)) {
  192. $custom = CustomClass::getById($customId, true);
  193. $level = $custom->level ?? 1;
  194. }
  195. $itemInfoData = [];
  196. if ($requestType == 'hasStockList') {
  197. //有库存的花材列表
  198. $field = 'id,py,name,classId,itemId,price,skPrice,stock';
  199. $itemInfoData = ProductClass::getAllByCondition($where, ['inTurn' => SORT_DESC, 'actualSold' => SORT_DESC], $field);
  200. } elseif ($requestType == 'changePrice') {
  201. //修改价格列表
  202. $field = 'id,py,cover,name,cost,itemId,classId,addPrice,skPrice,discountPrice,skMore,variety,price,stock,presell';
  203. $itemInfoData = ProductClass::getAllByCondition($where, ['inTurn' => SORT_DESC, 'actualSold' => SORT_DESC], $field);
  204. $itemInfoData = ProductClass::changePriceGroup($itemInfoData, $level);
  205. } elseif ($requestType == 'kd') {
  206. //开单的花材列表
  207. $field = 'id,py,cover,name,cost,itemId,classId,skPrice,variety,price,discountPrice,stock,stockWarning,presell,ratioType,smallUnit,smallRatio,bigUnit,ratio';
  208. $itemInfoData = ProductClass::getAllByCondition($where, ['inTurn' => SORT_DESC, 'actualSold' => SORT_DESC], $field);
  209. $itemInfoData = ProductClass::kdItemGroup($itemInfoData, $level);
  210. } elseif ($requestType == 'itemList') {
  211. //花材列表
  212. $field = 'id,py,cover,name,cost,itemId,classId,skPrice,bigUnit,smallUnit,ratio,ratioType,variety,price,discountPrice,skMore,stock,actualSold,stockWarning,status,presell';
  213. $itemInfoData = ProductClass::getAllByCondition($where, ['inTurn' => SORT_DESC, 'actualSold' => SORT_DESC], $field);
  214. $itemInfoData = ProductClass::itemListGroup($itemInfoData, $level);
  215. } elseif ($requestType == 'outList') {
  216. //下架花材列表
  217. $where['status'] = 2;
  218. $where['delStatus'] = 0;
  219. $where['removeStatus'] = 0;
  220. $field = 'id,py,cover,name,cost,itemId,classId,addPrice,skPrice,bigUnit,smallUnit,ratio,ratioType,discountPrice,skMore,variety,price,stock,presell,status';
  221. $itemInfoData = ProductClass::getAllByCondition($where, ['inTurn' => SORT_DESC, 'actualSold' => SORT_DESC], $field);
  222. $itemInfoData = ProductClass::simpleGroup($itemInfoData, $level);
  223. } elseif ($requestType == 'stopList') {
  224. //停用花材列表
  225. $where['delStatus'] = 1;
  226. $where['removeStatus'] = 0;
  227. $field = 'id,py,cover,name,cost,itemId,classId,addPrice,skPrice,bigUnit,smallUnit,ratio,ratioType,discountPrice,skMore,variety,price,stock,presell,status';
  228. $itemInfoData = ProductClass::getAllByCondition($where, ['inTurn' => SORT_DESC, 'actualSold' => SORT_DESC], $field);
  229. $itemInfoData = ProductClass::simpleGroup($itemInfoData, $level);
  230. } elseif ($requestType == 'removeList') {
  231. //删除花材列表
  232. $where['delStatus'] = 1;
  233. $where['removeStatus'] = 1;
  234. $field = 'id,py,cover,name,cost,itemId,classId,addPrice,skPrice,bigUnit,smallUnit,ratio,ratioType,discountPrice,skMore,variety,price,stock,presell,status';
  235. $itemInfoData = ProductClass::getAllByCondition($where, ['inTurn' => SORT_DESC, 'actualSold' => SORT_DESC], $field);
  236. $itemInfoData = ProductClass::simpleGroup($itemInfoData, $level);
  237. } elseif ($requestType == 'check') {
  238. //盘点花材列表
  239. $field = 'id,py,cover,name,itemId,classId,variety,price,discountPrice,stock,stockWarning,presell,ratioType,smallUnit,bigUnit,ratio';
  240. $itemInfoData = ProductClass::getAllByCondition($where, ['inTurn' => SORT_DESC, 'actualSold' => SORT_DESC], $field);
  241. $itemInfoData = ProductClass::checkItemGroup($itemInfoData, $level);
  242. } elseif ($requestType == 'break') {
  243. //报损花材
  244. $field = 'id,py,cover,name,itemId,classId,variety,price,discountPrice,stock,stockWarning,presell,ratioType,smallUnit,bigUnit,ratio';
  245. $itemInfoData = ProductClass::getAllByCondition($where, ['inTurn' => SORT_DESC, 'actualSold' => SORT_DESC], $field);
  246. $itemInfoData = ProductClass::breakItemGroup($itemInfoData, $level);
  247. } elseif ($requestType == 'part') {
  248. //报损花材
  249. $field = 'id,py,cover,name,itemId,classId,variety,price,discountPrice,stock,stockWarning,presell,ratioType,smallUnit,bigUnit,ratio';
  250. $itemInfoData = ProductClass::getAllByCondition($where, ['inTurn' => SORT_DESC, 'actualSold' => SORT_DESC], $field);
  251. $itemInfoData = ProductClass::partItemGroup($itemInfoData, $level);
  252. } elseif ($requestType == 'stockOut') {
  253. //出库花材
  254. $field = 'id,py,cover,name,itemId,classId,variety,price,discountPrice,stock,stockWarning,presell,ratioType,smallUnit,bigUnit,ratio,smallRatio';
  255. $itemInfoData = ProductClass::getAllByCondition($where, ['inTurn' => SORT_DESC, 'actualSold' => SORT_DESC], $field);
  256. $itemInfoData = ProductClass::stockOutGroup($itemInfoData, $level);
  257. } elseif ($requestType == 'cg') {
  258. //采购花材
  259. $field = 'id,py,cover,name,itemId,classId,variety,price,discountPrice,stock,presell,ratioType,smallUnit,bigUnit,ratio,weight';
  260. $itemInfoData = ProductClass::getAllByCondition($where, ['inTurn' => SORT_DESC, 'actualSold' => SORT_DESC], $field);
  261. $itemInfoData = ProductClass::cgItemGroup($itemInfoData, $level);
  262. } elseif ($requestType == 'warning') {
  263. //库存预警
  264. $field = 'id,py,cover,name,cost,itemId,classId,skPrice,variety,price,discountPrice,stock,actualSold,presell,bigUnit,stockWarning,status';
  265. $itemInfoData = Product::find()->where("mainId={$this->mainId}")
  266. ->andWhere('`stock`<`stockWarning`')
  267. ->andWhere("delStatus=0")
  268. ->select($field)->asArray()->all();
  269. $itemInfoData = ProductClass::warningGroup($itemInfoData, $level);
  270. } else {
  271. util::fail('没有数据');
  272. }
  273. $data = ProductService::assembleItemData($classInfo, $itemInfoData);
  274. util::success($data);
  275. }
  276. //取出今天有入库的花材 ssh 20221224
  277. public function actionGetStockIn()
  278. {
  279. $py = Yii::$app->request->get('py', '');
  280. $version = Yii::$app->request->get('version', 0);
  281. if ($version == 0) {
  282. util::fail('请先升级版本到1.0.70以上');
  283. }
  284. $classInfo = ItemClassClass::getGhsItemClassAll($this->mainId);
  285. $mainId = $this->mainId ?? 0;
  286. $where['mainId'] = $mainId;
  287. if ($py) {
  288. $pyName = strtolower($py);
  289. $where['py'] = $pyName;
  290. }
  291. $arr = StockInDayClass::getAllByCondition(['mainId' => $mainId], null, '*');
  292. if (empty($arr)) {
  293. util::fail('没有花材需要盘点');
  294. }
  295. $ids = array_column($arr, 'itemId');
  296. $ids = array_unique($ids);
  297. $where['id'] = ['in', $ids];
  298. $level = 1;
  299. $field = 'id,py,cover,name,itemId,classId,variety,price,discountPrice,stock,stockWarning,presell,ratioType,smallUnit,bigUnit,ratio';
  300. $itemInfoData = ProductClass::getAllByCondition($where, ['inTurn' => SORT_DESC, 'actualSold' => SORT_DESC], $field);
  301. $itemInfoData = ProductClass::checkItemGroup($itemInfoData, $level);
  302. $data = ProductService::assembleItemData($classInfo, $itemInfoData);
  303. util::success($data);
  304. }
  305. //按分类列出所有花材
  306. public function actionIndex()
  307. {
  308. $py = Yii::$app->request->get('py', '');
  309. $requestType = Yii::$app->request->get('requestType', 'common');
  310. //默认显示上架商品
  311. $status = Yii::$app->request->get('status', 1);
  312. //默认显示未删除商品
  313. $delStatus = Yii::$app->request->get('delStatus', 0);
  314. $warning = Yii::$app->request->get('warning', 0);
  315. //获取所有当前供货商的分类 (全部、常用)
  316. //根据分类组装分类下的花材信息
  317. //中央ID
  318. $classInfo = ItemClassClass::getGhsItemClassAll($this->mainId);
  319. $where['mainId'] = $this->mainId;
  320. if ($py) {
  321. $pyName = strtolower($py);
  322. $where['py'] = $pyName;
  323. }
  324. if ($requestType == 'hasStock') {
  325. //改价只显示库存大于0的
  326. $where['stock>'] = 0;
  327. }
  328. if (!empty($status)) {
  329. $where['status'] = $status;
  330. }
  331. $where['delStatus'] = $delStatus;
  332. //客户等级
  333. $customId = Yii::$app->request->get('customId', 0);
  334. $level = 1;
  335. if (!empty($customId)) {
  336. $custom = CustomClass::getById($customId, true);
  337. $level = $custom->level ?? 1;
  338. }
  339. if ($warning == 1) {
  340. //库存预警
  341. $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';
  342. $itemInfoData = Product::find()->where("mainId={$this->mainId}")
  343. ->andWhere('`stock`<`stockWarning`')
  344. ->andWhere("delStatus=0")
  345. ->select($field)->asArray()->all();
  346. } else {
  347. $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';
  348. $itemInfoData = ProductClass::getAllByCondition($where, ['inTurn' => SORT_DESC, 'actualSold' => SORT_DESC], $field);
  349. }
  350. $itemInfoData = ProductClass::groupProductInfo($itemInfoData, $level);
  351. $data = ProductService::assembleData($classInfo, $itemInfoData, true);
  352. util::success($data);
  353. }
  354. //所有花材分页和不分页
  355. public function actionList()
  356. {
  357. $where = [];
  358. $classId = Yii::$app->request->get('classId', 0);
  359. if (!empty($classId)) {
  360. $where['classId'] = $classId;
  361. }
  362. $name = Yii::$app->request->get('name', '');
  363. if (empty($name)) {
  364. $py = Yii::$app->request->get('py', '');
  365. $name = !empty($py) ? $py : '';
  366. }
  367. if (!empty($name)) {
  368. if (stringUtil::isLetter($name)) {
  369. $where['py'] = ['like', $name];
  370. } else {
  371. $where['name'] = ['like', $name];
  372. }
  373. }
  374. $status = Yii::$app->request->get('status', 0);
  375. if (!empty($status)) {
  376. $where['status'] = $status;
  377. }
  378. $delStatus = Yii::$app->request->get('delStatus', 0);
  379. if ($delStatus != 2) {
  380. $where['delStatus'] = $delStatus;
  381. }
  382. $where['mainId'] = $this->mainId;
  383. $productIds = Yii::$app->request->get('ids', '');
  384. if (!empty($productIds)) {
  385. $productIdArr = explode(',', $productIds);
  386. if (!empty($productIdArr)) {
  387. $where['id'] = ['in', $productIdArr];
  388. }
  389. }
  390. //输出标准会员价,即花店价,默认显示的是花店价
  391. $level = 1;
  392. $type = Yii::$app->request->get('type', '');
  393. $showPage = Yii::$app->request->get('showPage', 0);
  394. if ($showPage) {
  395. if ($type == 'waring') {
  396. $pro = Product::find()->where("mainId={$this->mainId}")->andWhere('`stock`<`stockWarning`')->select('id')->asArray()->all();
  397. $lackIds = array_column($pro, 'id');
  398. if (empty($lackIds)) {
  399. util::success([]);
  400. }
  401. $lackIds = array_filter(array_unique($lackIds));
  402. $where['id'] = ['in', $lackIds];
  403. $respond = ProductClass::getList("*", $where, "actualSold desc");
  404. } else {
  405. $respond = ProductClass::getList("*", $where, "inTurn desc");
  406. }
  407. $respond['list'] = ProductClass::groupProductInfo($respond['list'], $level);
  408. $respond['list'] = ProductClass::groupClassName($this->sjId, $respond['list']);
  409. util::success($respond);
  410. } else {
  411. if ($type == 'waring') {
  412. //库存预警 按库存从小到大排序
  413. $data = ProductClass::getAllByCondition($where, ['stock' => SORT_ASC, 'inTurn' => SORT_DESC], "*");
  414. } else {
  415. if (!empty($productIds)) {
  416. //优先按 $productIds 排序 "FIELD(`id`,4,5,6)"=>true
  417. $data = ProductClass::getAllByCondition($where, ["FIELD(`id`,$productIds)" => true, 'inTurn' => SORT_DESC], "*");
  418. } else {
  419. $data = ProductClass::getAllByCondition($where, ['actualSold' => SORT_DESC, 'inTurn' => SORT_DESC], "*");
  420. }
  421. }
  422. $data = ProductClass::groupProductInfo($data, $level);
  423. $data = ProductClass::groupClassName($this->sjId, $data);
  424. if ($type == 'waring') {
  425. //库存预警
  426. $newData = [];
  427. foreach ($data as $v) {
  428. if ($v['stock'] <= $v['stockWarning']) {
  429. $newData[] = $v;
  430. }
  431. }
  432. util::success(['list' => $newData]);
  433. }
  434. util::success(['list' => $data]);
  435. }
  436. }
  437. //所有花材
  438. public function actionAll()
  439. {
  440. $where = [];
  441. $where['mainId'] = $this->mainId;
  442. $classId = Yii::$app->request->get('classId', 0);
  443. if (!empty($classId)) {
  444. $where['classId'] = $classId;
  445. }
  446. $status = Yii::$app->request->get('status', 0);
  447. if (!empty($status)) {
  448. $where['status'] = $status;
  449. }
  450. $delStatus = Yii::$app->request->get('delStatus', 0);
  451. if ($delStatus != 2) {
  452. $where['delStatus'] = $delStatus;
  453. }
  454. //输出标准会员价,即花店价,默认显示的是花店价
  455. $level = 1;
  456. $data = ProductClass::getAllByCondition($where, ['actualSold' => SORT_DESC, 'inTurn' => SORT_DESC], "*");
  457. $data = ProductClass::groupProductInfo($data, $level);
  458. util::success(['list' => $data]);
  459. }
  460. //批量改价
  461. public function actionBatchChangePrice()
  462. {
  463. $shop = $this->shop;
  464. $join = $shop->join ?? 0;
  465. $default = $shop->default ?? 0;
  466. if ($join == 0 && $default == 0) {
  467. util::fail('当前直营分店,请切回总店修改');
  468. }
  469. $shopAdmin = $this->shopAdmin;
  470. if (isset($shopAdmin->super) == false || $shopAdmin->super != 1) {
  471. util::fail('超管才能修改');
  472. }
  473. $shop = $this->shop;
  474. $default = $shop->default ?? 0;
  475. $adminId = $this->adminId ?? 0;
  476. //normal常规改价,cg采购改价
  477. $changeType = Yii::$app->request->post('changeType', 'normal');
  478. $targetId = Yii::$app->request->post('targetId', 0);
  479. $changeParams = ['staffId' => $shopAdmin->id, 'staffName' => $shopAdmin->name, 'changeType' => $changeType, 'targetId' => $targetId];
  480. $data = Yii::$app->request->post('data', '');
  481. if (empty($data)) {
  482. util::fail('没有修改');
  483. }
  484. $arr = json_decode($data, true);
  485. if (empty($arr)) {
  486. util::fail('没有修改哦');
  487. }
  488. $connection = Yii::$app->db;
  489. $transaction = $connection->beginTransaction();
  490. try {
  491. $cg = PurchaseOrderClass::getLockById($targetId);
  492. if (!empty($cg)) {
  493. if (isset($cg->mainId) == false || $cg->mainId != $this->mainId) {
  494. util::fail('不是您的采购单');
  495. }
  496. //批量改价同时入库
  497. if ($cg->status == PurchaseOrderClass::PURCHASE_ORDER_STATUS_SENDING) {
  498. $staff = $this->shopAdmin;
  499. $data = [];
  500. $data['staffId'] = $staff->id ?? 0;
  501. $data['staffName'] = $staff->name ?? '';
  502. $data['adminId'] = $this->adminId ?? 0;
  503. PurchaseOrderClass::putIn($cg, $data);
  504. }
  505. }
  506. $ids = array_column($arr, 'id');
  507. $ids = array_unique(array_filter($ids));
  508. if (empty($ids)) {
  509. util::fail('请选择花材');
  510. }
  511. $sjId = $shop->sjId ?? 0;
  512. $chainShopList = [];
  513. if ($default == 1) {
  514. $chainShopList = ShopClass::getAllByCondition(['sjId' => $sjId, 'join' => 0], null, '*', null, true);
  515. }
  516. $productList = ProductClass::getAllByCondition(['id' => ['in', $ids]], null, '*', 'id', true);
  517. foreach ($arr as $product) {
  518. $productId = $product['id'];
  519. $productInfo = $productList[$productId] ?? [];
  520. if (empty($productInfo)) {
  521. util::fail('没有找到花材');
  522. }
  523. $productName = $productInfo->name ?? '';
  524. if (isset($product['id']) == false) {
  525. util::fail('没有花材');
  526. }
  527. if (isset($product['price']) == false || is_numeric($product['price']) == false || $product['price'] < 0) {
  528. util::fail('请填写' . $productName . '的花店价');
  529. }
  530. $price = $product['price'];
  531. if (isset($product['skPrice']) == false || is_numeric($product['skPrice']) == false || $product['skPrice'] < 0) {
  532. util::fail('请填写' . $productName . '的散客价');
  533. }
  534. $skPrice = $product['skPrice'];
  535. if (isset($productInfo->mainId) == false || $productInfo->mainId != $this->mainId) {
  536. util::fail('没有权限访问');
  537. }
  538. if (empty($price)) {
  539. continue;
  540. }
  541. $ptItemId = $productInfo->itemId;
  542. ProductClass::changeSinglePrice($shop, $ptItemId, $price, $skPrice, $changeParams);
  543. //在首店修改需要同步到所有直营店
  544. if ($default == 1 && isset($shop->dataSync) && $shop->dataSync == 1) {
  545. foreach ($chainShopList as $chain) {
  546. if ($chain->id == $shop->id) {
  547. continue;
  548. }
  549. $chainMainId = $chain->mainId ?? 0;
  550. $staff = ShopAdminClass::getByCondition(['mainId' => $chainMainId, 'adminId' => $adminId], true);
  551. $changeParams2 = ['staffId' => $staff->id, 'staffName' => $staff->name, 'changeType' => $changeType, 'targetId' => $targetId];
  552. ProductClass::changeSinglePrice($chain, $ptItemId, $price, $skPrice, $changeParams2);
  553. }
  554. }
  555. }
  556. $mainId = $shop->mainId ?? 0;
  557. if (!empty($mainId)) {
  558. //提醒零售收银台界面要刷新
  559. $staffList = ShopAdminClass::getAllByCondition(['mainId' => $mainId], null, '*', null, true);
  560. if (!empty($staffList)) {
  561. foreach ($staffList as $staff) {
  562. $staffId = $staff->id ?? 0;
  563. Yii::$app->redis->executeCommand('SET', ['cashier_' . $mainId . '_' . $staffId . '_may_refresh', 'yes']);
  564. Yii::$app->redis->executeCommand('SET', ['ghs_cashier_' . $mainId . '_' . $staffId . '_may_refresh', 'yes']);
  565. }
  566. }
  567. }
  568. $transaction->commit();
  569. util::complete('操作成功');
  570. } catch (\Exception $e) {
  571. $transaction->rollBack();
  572. Yii::info("修改失败原因:" . $e->getMessage());
  573. util::fail('修改失败');
  574. }
  575. }
  576. //改价
  577. public function actionChangePrice()
  578. {
  579. $shopAdmin = $this->shopAdmin;
  580. if (isset($shopAdmin->super) == false || $shopAdmin->super != 1) {
  581. util::fail('超管才能修改');
  582. }
  583. $productId = Yii::$app->request->post('productId', 0);
  584. $productInfo = ProductClass::getById($productId, true);
  585. if (empty($productInfo)) {
  586. util::fail("花材不存在");
  587. }
  588. if ($productInfo->mainId != $this->mainId) {
  589. util::fail('没有权限');
  590. }
  591. $price = Yii::$app->request->post('price', '');
  592. if (is_numeric($price) && $price > 0) {
  593. ProductClass::changeSinglePrice($productInfo, $price, ProductClass::PRICE_LABEL_CHANGE);
  594. } else {
  595. $price = bcadd($productInfo->cost, $productInfo->addPrice, 2);
  596. ProductClass::changeSinglePrice($productInfo, $price, ProductClass::PRICE_LABEL_AUTO);
  597. }
  598. util::success(['price' => $price]);
  599. }
  600. //恢复自动调价
  601. public function actionAutoPrice()
  602. {
  603. $productId = Yii::$app->request->post('productId', 0);
  604. $productData = ProductClass::getById($productId);
  605. if (!$productData) {
  606. util::fail("花材不存在");
  607. }
  608. //2021.04.06改为用product中的成本价+加价
  609. $price = bcadd($productData['cost'], $productData['addPrice'], 2);
  610. ProductClass::changeSinglePrice($productId, $this->shopId, $price, ProductClass::PRICE_LABEL_AUTO);
  611. util::complete("操作成功");
  612. }
  613. //修改加价
  614. public function actionChangeAddPrice()
  615. {
  616. $productId = Yii::$app->request->post('productId', 0);
  617. $addPrice = Yii::$app->request->post('addPrice', '');
  618. if ($addPrice < 0) {
  619. util::fail("加价不能小于0");
  620. }
  621. $productData = ProductClass::getProductData($productId, $this->mainId);
  622. if (!$productData) {
  623. util::fail("花材不存在");
  624. }
  625. ProductClass::changeAddPrice($productId, $addPrice);
  626. util::complete();
  627. }
  628. //批量修改更多,包括排序、重量和保质期 ssh 20211211
  629. public function actionBatchChangeMore()
  630. {
  631. $shop = $this->shop;
  632. $default = $shop->default ?? 0;
  633. if ($default == 0) {
  634. util::fail('当前直营分店,请切回总店修改');
  635. }
  636. $shopAdmin = $this->shopAdmin;
  637. if (isset($shopAdmin->super) == false || $shopAdmin->super != 1) {
  638. util::fail('超管才能操作');
  639. }
  640. $addData = Yii::$app->request->post('addData', '');
  641. if (empty($addData)) {
  642. util::fail('没有花材');
  643. }
  644. $itemData = json_decode($addData, true);
  645. if (is_array($itemData) == false) {
  646. util::fail('没有花材...');
  647. }
  648. $ids = array_column($itemData, 'id');
  649. $infoList = ProductClass::getByIds($ids, null, 'id');
  650. if (empty($infoList)) {
  651. util::fail('没有花材');
  652. }
  653. foreach ($infoList as $info) {
  654. if (isset($info['mainId']) == false || $info['mainId'] != $this->mainId) {
  655. util::fail('不是你的花材不能修改');
  656. }
  657. }
  658. //总店修改同步到所有门店
  659. $sjId = $shop->sjId ?? 0;
  660. $chainShopList = ShopClass::getAllByCondition(['sjId' => $sjId], null, '*', null, true);
  661. foreach ($itemData as $key => $data) {
  662. $id = $data['id'] ?? 0;
  663. unset($data['id']);
  664. ProductClass::updateById($id, $data);
  665. $ptItemId = $infoList[$id]['itemId'] ?? 0;
  666. if (empty($ptItemId)) {
  667. continue;
  668. }
  669. if (isset($shop->default) && $shop->default == 1 && isset($shop->dataSync) && $shop->dataSync == 1) {
  670. foreach ($chainShopList as $chainShop) {
  671. $currentMainId = $chainShop->mainId ?? 0;
  672. if ($currentMainId == $shop->mainId) {
  673. //前面已经修改过了,不需要重复修改
  674. continue;
  675. }
  676. ProductClass::updateByCondition(['mainId' => $currentMainId, 'itemId' => $ptItemId], $data);
  677. }
  678. }
  679. }
  680. util::complete('修改成功');
  681. }
  682. //批量修改加价 ssh 20211211
  683. public function actionBatchChangeAddPrice()
  684. {
  685. $shop = $this->shop;
  686. $join = $shop->join ?? 0;
  687. $default = $shop->default ?? 0;
  688. if ($join == 0 && $default == 0) {
  689. util::fail('当前直营分店,请切回总店操作');
  690. }
  691. $shopAdmin = $this->shopAdmin;
  692. if (isset($shopAdmin->super) == false || $shopAdmin->super != 1) {
  693. util::fail('超管才能操作');
  694. }
  695. $addData = Yii::$app->request->post('addData', '');
  696. if (empty($addData)) {
  697. util::fail('没有花材');
  698. }
  699. $itemData = json_decode($addData, true);
  700. if (is_array($itemData) == false) {
  701. util::fail('没有花材...');
  702. }
  703. $ids = array_column($itemData, 'id');
  704. $infoList = ProductClass::getByIds($ids, null, 'id');
  705. if (empty($infoList)) {
  706. util::fail('没有花材');
  707. }
  708. foreach ($infoList as $info) {
  709. if (isset($info['mainId']) == false || $info['mainId'] != $this->mainId) {
  710. util::fail('不能修改别人的花材');
  711. }
  712. }
  713. //总店修改同步到所有门店
  714. $sjId = $shop->sjId ?? 0;
  715. $chainShopList = ShopClass::getAllByCondition(['sjId' => $sjId], null, '*', null, true);
  716. foreach ($itemData as $key => $data) {
  717. $id = $data['id'] ?? 0;
  718. unset($data['id']);
  719. ProductClass::updateById($id, $data);
  720. $ptItemId = $infoList[$id]['itemId'] ?? 0;
  721. if (empty($ptItemId)) {
  722. continue;
  723. }
  724. if (isset($shop->default) && $shop->default == 1 && isset($shop->dataSync) && $shop->dataSync == 1) {
  725. foreach ($chainShopList as $chainShop) {
  726. if (isset($chainShop->join) && $chainShop->join == 1) {
  727. continue;
  728. }
  729. $currentMainId = $chainShop->mainId ?? 0;
  730. if ($currentMainId == $shop->mainId) {
  731. //前面已经修改过了,不需要重复修改
  732. continue;
  733. }
  734. ProductClass::updateByCondition(['mainId' => $currentMainId, 'itemId' => $ptItemId], $data);
  735. }
  736. }
  737. }
  738. util::complete('修改成功');
  739. }
  740. public function actionUpdate()
  741. {
  742. $shopAdmin = $this->shopAdmin;
  743. if (isset($shopAdmin->super) == false || $shopAdmin->super != 1) {
  744. util::fail('超管才能操作');
  745. }
  746. $shop = $this->shop;
  747. $join = $shop->join ?? 0;
  748. $default = $shop->default ?? 0;
  749. if ($join == 0 && $default == 0) {
  750. //因为盘点不能将花材盘成0,所以这边放出入口允许创始人在分店修改分店的花材库存
  751. if ($shopAdmin->super != 1) {
  752. util::fail('请先开通超管权限');
  753. }
  754. }
  755. $post = Yii::$app->request->post();
  756. $post['adminId'] = $this->adminId;
  757. $post['staffId'] = $this->shopAdmin->id;
  758. $post['staffName'] = $this->shopAdmin->name;
  759. ProductClass::updateProduct($post, $this->shop);
  760. util::complete();
  761. }
  762. //上下架状态控制 ssh 20210713
  763. public function actionStatusUpdate()
  764. {
  765. $post = Yii::$app->request->post();
  766. $shopAdmin = $this->shopAdmin;
  767. $roleId = $shopAdmin['roleId'] ?? 0;
  768. $role = AdminRoleClass::getById($roleId);
  769. $roleName = $role['roleName'] ?? '';
  770. if ($roleName == '员工') {
  771. util::fail('没有权限操作哦');
  772. }
  773. $id = $post['id'] ?? 0;
  774. $status = $post['status'] ?? 1;
  775. $product = ProductClass::getById($id, true);
  776. if ($product->mainId != $this->mainId) {
  777. util::fail('没有权限操作');
  778. }
  779. $product->status = $status;
  780. if ($status == 2) {
  781. $product->discountPrice = 0;
  782. }
  783. $product->save();
  784. util::complete();
  785. }
  786. //花材展示状态控制 ssh 20210804
  787. public function actionDelStatusUpdate()
  788. {
  789. $post = Yii::$app->request->post();
  790. $shop = $this->shop;
  791. $join = $shop->join ?? 0;
  792. $default = $shop->default ?? 0;
  793. if ($join == 0 && $default == 0) {
  794. util::fail('请在首店操作');
  795. }
  796. $shopAdmin = $this->shopAdmin;
  797. $roleId = $shopAdmin['roleId'] ?? 0;
  798. $role = AdminRoleClass::getById($roleId);
  799. $roleName = $role['roleName'] ?? '';
  800. if ($roleName == '员工') {
  801. util::fail('没有权限操作');
  802. }
  803. $id = $post['id'] ?? 0;
  804. $delStatus = $post['delStatus'] ?? 0;
  805. $product = ProductClass::getById($id, true);
  806. if ($product->mainId != $this->mainId) {
  807. util::fail('没有权限操作');
  808. }
  809. $product->delStatus = $delStatus;
  810. $product->save();
  811. $ptItemId = $product->itemId ?? 0;
  812. if (isset($shop->default) && $shop->default == 1 && isset($shop->dataSync) && $shop->dataSync == 1) {
  813. //总店修改同步到所有门店
  814. $sjId = $shop->sjId ?? 0;
  815. $chainShopList = ShopClass::getAllByCondition(['sjId' => $sjId], null, '*', null, true);
  816. foreach ($chainShopList as $chainShop) {
  817. $chainShopId = $chainShop->id ?? 0;
  818. if (isset($chainShop->join) && $chainShop->join == 1) {
  819. continue;
  820. }
  821. if ($chainShopId == $shop->id) {
  822. continue;
  823. }
  824. $chainMainId = $chainShop->mainId ?? 0;
  825. $chainProduct = ProductClass::getByCondition(['mainId' => $chainMainId, 'itemId' => $ptItemId], true);
  826. if (!empty($chainProduct)) {
  827. $chainProduct->delStatus = $delStatus;
  828. $chainProduct->save();
  829. }
  830. }
  831. }
  832. util::complete();
  833. }
  834. //详情 ruidian 2021.5.3
  835. public function actionDetail()
  836. {
  837. $id = Yii::$app->request->get('id', 0);
  838. $respond = ProductClass::getItemInfo($id);
  839. $ptItemId = $respond['itemId'] ?? 0;
  840. $ptItemInfo = PtItemClass::getById($ptItemId);
  841. $respond['ptItemInfo'] = $ptItemInfo;
  842. util::success($respond);
  843. }
  844. //新增花材 2021.6.21
  845. public function actionAdd()
  846. {
  847. $post = Yii::$app->request->post();
  848. $shop = $this->shop;
  849. $join = $shop->join ?? 0;
  850. $default = $shop->default ?? 0;
  851. if ($join == 0 && $default == 0) {
  852. util::fail('当前直营分店,请切回总店添加花材');
  853. }
  854. $shopAdmin = $this->shopAdmin;
  855. if (isset($shopAdmin->super) == false || $shopAdmin->super != 1) {
  856. util::fail('管理员才能添加花材');
  857. }
  858. $post['sjId'] = $this->sjId;
  859. $post['adminId'] = $this->adminId;
  860. $post['mainId'] = $this->mainId;
  861. $price = $post['price'] ?? 0;
  862. $addPrice = $post['addPrice'] ?? 0;
  863. if ($addPrice > $price) {
  864. util::fail('加价不能大于售价');
  865. }
  866. $weight = isset($post['weight']) && is_numeric($post['weight']) ? $post['weight'] : 0;
  867. if ($weight <= 0) {
  868. util::fail('请填写重量,最小0.1');
  869. }
  870. $post['staffName'] = $shopAdmin->name ?? '';
  871. ProductClass::addProduct($post, $this->shop);
  872. util::complete('添加成功');
  873. }
  874. //获取拼音缩写 ssh 20210707
  875. public function actionPy()
  876. {
  877. $name = Yii::$app->request->get('name');
  878. $py = stringUtil::py($name);
  879. util::success(['py' => $py]);
  880. }
  881. //(客户端-批发商)复制花材
  882. public function actionClone()
  883. {
  884. $post = Yii::$app->request->post();
  885. $shop = $this->shop;
  886. $join = $shop->join ?? 0;
  887. $default = $shop->default ?? 0;
  888. if ($join == 0 && $default == 0) {
  889. util::fail('请在首店操作');
  890. }
  891. $shopAdmin = $this->shopAdmin;
  892. if (isset($shopAdmin->super) == false || $shopAdmin->super != 1) {
  893. util::fail('管理员才能添加花材');
  894. }
  895. $post['sjId'] = $this->sjId;
  896. $post['adminId'] = $this->adminId;
  897. $post['mainId'] = $this->mainId;
  898. $post['staffName'] = $shopAdmin->name ?? '';
  899. $price = $post['price'] ?? 0;
  900. $addPrice = $post['addPrice'] ?? 0;
  901. if ($addPrice > $price) {
  902. util::fail('加价不能大于售价');
  903. }
  904. //复制标识
  905. $post['copy'] = 1;
  906. //去除无用的字段
  907. unset($post['viewNum']);
  908. unset($post['actualSold']);
  909. unset($post['itemId']);
  910. unset($post['id']);
  911. unset($post['delStatus']);
  912. ProductClass::addProduct($post, $this->shop);
  913. util::complete('复制成功');
  914. }
  915. //下载价格表 ssh 20210922
  916. public function actionGeneratePriceTable()
  917. {
  918. $level = Yii::$app->request->get('level', 0);
  919. $respond = ProductService::generatePriceTable($this->sjId, $level, $this->mainId);
  920. $file = $respond['file'] ?? '';
  921. $shortFile = $respond['shortFile'] ?? '';
  922. $fileUrl = Yii::$app->params['ghsHost'] . $file;
  923. util::success(['file' => $fileUrl, 'shortFile' => $shortFile]);
  924. }
  925. public function actionGenerateItemTable()
  926. {
  927. $level = Yii::$app->request->get('level', 0);
  928. $respond = ProductService::generateItemTable($this->sjId, $level, $this->mainId);
  929. $file = $respond['file'] ?? '';
  930. $shortFile = $respond['shortFile'] ?? '';
  931. $fileUrl = Yii::$app->params['ghsHost'] . $file;
  932. util::success(['file' => $fileUrl, 'shortFile' => $shortFile]);
  933. }
  934. //下载条形码 lqh 20211227
  935. public function actionGenerateBarcodeTable()
  936. {
  937. $respond = ProductService::generateBarcodeTable($this->sjId, $this->shopId, $this->mainId);
  938. $file = $respond['file'] ?? '';
  939. $shortFile = $respond['shortFile'] ?? '';
  940. $fileUrl = Yii::$app->params['ghsHost'] . $file;
  941. util::success(['file' => $fileUrl, 'shortFile' => $shortFile]);
  942. }
  943. //批量修改花材的分类 ssh 20230405
  944. public function actionBatchModifyClass()
  945. {
  946. $post = Yii::$app->request->post();
  947. $shop = $this->shop;
  948. $join = $shop->join ?? 0;
  949. $default = $shop->default ?? 0;
  950. if ($join == 0 && $default == 0) {
  951. util::fail('当前直营分店,请切回总店操作');
  952. }
  953. $classId = $post['classId'] ?? 0;
  954. $class = ItemClassClass::getById($classId, true);
  955. if (empty($class) || $class->mainId != $this->mainId) {
  956. util::fail('请选择您自己的分类');
  957. }
  958. $connection = Yii::$app->db;
  959. $transaction = $connection->beginTransaction();
  960. try {
  961. $className = $class->name ?? '';
  962. $idsList = $post['ids'] ?? '';
  963. $ids = json_decode($idsList, true);
  964. if (empty($ids)) {
  965. util::fail('请选择花材');
  966. }
  967. $list = ProductClass::getAllByCondition(['id' => ['in', $ids]], null, '*', null, true);
  968. if (empty($list)) {
  969. util::fail('请选择花材');
  970. }
  971. $ptItemList = [];
  972. foreach ($list as $item) {
  973. $name = $item->name ?? '';
  974. if ($item->mainId != $this->mainId) {
  975. util::fail($name . '不是您的花材');
  976. }
  977. $item->classId = $classId;
  978. $item->save();
  979. $ptItemId = $item->itemId ?? 0;
  980. $ptItemList[] = $ptItemId;
  981. }
  982. $shop = $this->shop;
  983. if (isset($shop->default) && $shop->default == 1 && isset($shop->dataSync) && $shop->dataSync == 1) {
  984. //总店修改同步到所有门店
  985. $sjId = $shop->sjId ?? 0;
  986. $chainShopList = ShopClass::getAllByCondition(['sjId' => $sjId], null, '*', null, true);
  987. foreach ($chainShopList as $chainShop) {
  988. $chainShopId = $chainShop->id ?? 0;
  989. if ($chainShopId == $shop->id) {
  990. continue;
  991. }
  992. $chainManId = $chainShop->mainId ?? 0;
  993. $chainAllClassList = ItemClassClass::getAllByCondition(['mainId' => $chainManId], null, '*', null, true);
  994. if (!empty($chainAllClassList)) {
  995. foreach ($chainAllClassList as $chainClass) {
  996. $chainName = $chainClass->name ?? '';
  997. $chainClassId = $chainClass->id ?? 0;
  998. if ($chainName == $className) {
  999. $chainProductList = Productclass::getAllByCondition(['mainId' => $chainManId, 'itemId' => ['in', $ptItemList]], null, '*', null, true);
  1000. if (!empty($chainProductList)) {
  1001. foreach ($chainProductList as $currentProduct) {
  1002. $currentProduct->classId = $chainClassId;
  1003. $currentProduct->save();
  1004. }
  1005. }
  1006. }
  1007. }
  1008. }
  1009. }
  1010. }
  1011. $transaction->commit();
  1012. util::complete('修改成功');
  1013. } catch (\Exception $e) {
  1014. $transaction->rollBack();
  1015. Yii::info("修改失败原因:" . $e->getMessage());
  1016. util::fail('修改失败');
  1017. }
  1018. }
  1019. }