ProductController.php 45 KB

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