ProductController.php 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597
  1. <?php
  2. namespace hd\controllers;
  3. use biz\ghs\classes\GhsClass;
  4. use biz\item\classes\PtItemClass;
  5. use biz\shop\classes\ShopClass;
  6. use biz\shop\classes\ShopExtClass;
  7. use bizGhs\item\classes\ItemClassClass;
  8. use bizGhs\product\classes\ProductClass;
  9. use bizGhs\product\services\ProductService;
  10. use bizHd\admin\classes\ShopAdminClass;
  11. use bizHd\item\classes\ItemClass;
  12. use bizHd\purchase\classes\PurchaseClass;
  13. use common\components\printUtil;
  14. use common\components\stringUtil;
  15. use common\components\util;
  16. use Yii;
  17. class ProductController extends BaseController
  18. {
  19. public $guestAccess = ['ghs-item', 'ghs-product-detail'];
  20. //打印花材的标签 ssh 20220602
  21. public function actionPrint()
  22. {
  23. $get = Yii::$app->request->get();
  24. $id = $get['id'] ?? 0;
  25. $num = $get['num'] ?? 1;
  26. $info = ProductClass::getById($id, true);
  27. if (empty($info)) {
  28. util::fail('没有找到花材');
  29. }
  30. $name = $info->name ?? '';
  31. $ptItemId = $info->itemId ?? 0;
  32. $shopId = $this->shopId;
  33. $ext = ShopExtClass::getByCondition(['shopId' => $shopId], true);
  34. $printLabelSn = $ext->printLabelSn ?? '';
  35. if (empty($printLabelSn)) {
  36. util::fail('请设置标签打印机');
  37. }
  38. $p = new printUtil($printLabelSn);
  39. $unit = $info->ratio . $info->smallUnit . '/' . $info->bigUnit;
  40. if (isset($info->ratioType) && $info->ratioType == 1) {
  41. $unit = '若干' . $info->smallUnit . '/' . $info->bigUnit;
  42. }
  43. $p->times = $num;
  44. $content = '<TEXT x="360" y="30" font="12" w="2" h="2" r="90">' . $name . '</TEXT>';
  45. $content .= '<BC128 x="260" y="30" h="70" s="1" r="90" n="4" w="11">' . $ptItemId . '</BC128>';
  46. $content .= '<TEXT x="60" y="30" font="12" w="2" h="2" r="90">' . $unit . '</TEXT>';
  47. $p->printLabelMsg($content);
  48. util::complete();
  49. }
  50. //新增花材 2021.6.21
  51. public function actionAdd()
  52. {
  53. $post = Yii::$app->request->post();
  54. $shop = $this->shop ?? [];
  55. $pfShopId = $shop->pfShopId ?? 0;
  56. if (!empty($pfShopId)) {
  57. util::fail('请在批发端操作');
  58. }
  59. $shopAdmin = $this->shopAdmin;
  60. if (isset($shopAdmin->super) == false || $shopAdmin->super != 1) {
  61. util::fail('管理员才能添加花材');
  62. }
  63. $post['sjId'] = $this->sjId;
  64. $post['adminId'] = $this->adminId;
  65. $post['mainId'] = $this->mainId;
  66. $price = $post['price'] ?? 0;
  67. if ($price <= 0) {
  68. util::fail('请填写价格');
  69. }
  70. $addPrice = $post['addPrice'] ?? 0;
  71. if ($addPrice > $price) {
  72. util::fail('加价不能大于售价');
  73. }
  74. $post['skPrice'] = $price;
  75. $cost = bcsub($price, $addPrice, 2);
  76. $post['cost'] = $cost;
  77. ItemClass::addItem($post, $this->shop);
  78. util::complete('添加成功');
  79. }
  80. //获取拼音缩写 ssh 20210707
  81. public function actionPy()
  82. {
  83. $name = Yii::$app->request->get('name');
  84. $py = stringUtil::py($name);
  85. util::success(['py' => $py]);
  86. }
  87. //所有花材
  88. public function actionAll()
  89. {
  90. $where = [];
  91. $where['mainId'] = $this->mainId;
  92. $classId = Yii::$app->request->get('classId', 0);
  93. if (!empty($classId)) {
  94. $where['classId'] = $classId;
  95. }
  96. $status = Yii::$app->request->get('status', 0);
  97. if (!empty($status)) {
  98. $where['status'] = $status;
  99. }
  100. $delStatus = Yii::$app->request->get('delStatus', 0);
  101. if ($delStatus != 2) {
  102. $where['delStatus'] = $delStatus;
  103. }
  104. //零售价
  105. $level = 0;
  106. $data = ProductClass::getAllByCondition($where, ['actualSold' => SORT_DESC, 'inTurn' => SORT_DESC], "*");
  107. $data = ProductClass::groupProductInfo($data, $level);
  108. util::success(['list' => $data]);
  109. }
  110. public function actionIndex()
  111. {
  112. $py = Yii::$app->request->get('py', '');
  113. //默认显示上架商品
  114. $status = Yii::$app->request->get('status', 1);
  115. //默认显示未删除商品
  116. $delStatus = Yii::$app->request->get('delStatus', 0);
  117. //获取所有当前供货商的分类 (全部、常用)
  118. //根据分类组装分类下的花材信息
  119. //中央ID
  120. $classIds = ItemClassClass::getGhsItemClassAll($this->mainId);
  121. $where['mainId'] = $this->mainId;
  122. if ($py) {
  123. $pyName = strtolower($py);
  124. $where['py'] = $pyName;
  125. }
  126. if (!empty($status)) {
  127. $where['status'] = $status;
  128. }
  129. $where['delStatus'] = $delStatus;
  130. $level = 0;
  131. $field = 'id,cover,name,cost,itemId,classId,property,skPrice,skMore,addPrice,variety,price,discountPrice,skDiscountPrice,stock,stockWarning,presell,ratioType,smallRatio,smallUnit,bigUnit,ratio,actualSold';
  132. $itemInfoData = ProductClass::getAllByCondition($where, ['inTurn' => SORT_DESC, 'actualSold' => SORT_DESC], $field);
  133. $itemInfoData = ProductClass::groupProductInfo($itemInfoData, $level);
  134. $respond = ProductService::assembleData($classIds, $itemInfoData, true);
  135. $classItem = $respond['classItem'] ?? [];
  136. util::success($classItem);
  137. }
  138. //当前门店所有花材分类
  139. public function actionList()
  140. {
  141. $classId = Yii::$app->request->get('classId', 0);
  142. $pyName = Yii::$app->request->get('py', '');
  143. if ($pyName) {
  144. $pyName = strtolower($pyName);
  145. $where['py'] = $pyName;
  146. }
  147. $where['mainId'] = $this->mainId;
  148. if (!empty($classId)) {
  149. $where['classId'] = $classId;
  150. }
  151. $type = Yii::$app->request->get('type', '');
  152. $showPage = Yii::$app->request->get('showPage', 0);
  153. //需要显示分页
  154. if ($showPage) {
  155. $respond = ProductClass::getList("*", $where, "inTurn desc");
  156. $respond['list'] = ProductClass::groupClassName($this->sjId, $respond['list']);
  157. $respond['list'] = ProductClass::groupProductInfo($respond['list']);
  158. util::success($respond);
  159. }
  160. $data = ProductClass::getAllByCondition($where, "inTurn desc", "*");
  161. $data = ProductClass::groupProductInfo($data);
  162. if ($type == 'waring') {
  163. //库存预警
  164. $newData = [];
  165. foreach ($data as $v) {
  166. if ($v['stock'] <= $v['stockWarning']) {
  167. $newData[] = $v;
  168. }
  169. }
  170. util::success(['list' => $newData]);
  171. }
  172. util::success(['list' => $data]);
  173. }
  174. //批量改价
  175. public function actionBatchChangePrice()
  176. {
  177. $shop = $this->shop ?? [];
  178. $default = $shop->default ?? 0;
  179. $join = $shop->join ?? 0;
  180. $shopAdmin = $this->shopAdmin;
  181. $adminId = $this->adminId ?? 0;
  182. if (isset($shopAdmin->super) == false || $shopAdmin->super != 1) {
  183. util::fail('超管才能修改');
  184. }
  185. if ($join == 0 && $default == 0) {
  186. util::fail('当前直营分店,只能回总店修改价格');
  187. }
  188. //normal常规改价,cg采购改价
  189. $changeType = Yii::$app->request->post('changeType', 'normal');
  190. $doType = Yii::$app->request->post('doType', 0);
  191. $targetId = Yii::$app->request->post('targetId', 0);
  192. $changeParams = ['staffId' => $shopAdmin->id, 'staffName' => $shopAdmin->name, 'changeType' => $changeType, 'targetId' => $targetId];
  193. $post = Yii::$app->request->post();
  194. $data = $post['data'] ?? '';
  195. if (empty($data)) {
  196. util::fail('没有修改');
  197. }
  198. $arr = json_decode($data, true);
  199. if (empty($arr)) {
  200. util::fail('没有修改!');
  201. }
  202. $connection = Yii::$app->db;
  203. $transaction = $connection->beginTransaction();
  204. try {
  205. if ($doType == 0 || $doType == 1) {
  206. $cg = PurchaseClass::getLockById($targetId);
  207. if (!empty($cg)) {
  208. if (isset($cg->mainId) == false || $cg->mainId != $this->mainId) {
  209. util::fail('不是您的采购单');
  210. }
  211. if ($cg->status == PurchaseClass::STATUS_UN_SEND && $cg->book == 1) {
  212. util::fail('预订单只有发货后,才能确认收货');
  213. }
  214. //没有发货则先发货
  215. if ($cg->status == PurchaseClass::STATUS_UN_SEND) {
  216. $cg = PurchaseClass::orderSend($cg, [], true);
  217. }
  218. //确认收货并入库
  219. if ($cg->status == PurchaseClass::STATUS_SENDING) {
  220. PurchaseClass::takeToPutIn($cg);
  221. if ($doType == 1) {
  222. $transaction->commit();
  223. util::complete('入库成功');
  224. }
  225. } else {
  226. util::fail('订单不是待入库状态');
  227. }
  228. } else {
  229. if ($doType == 1) {
  230. util::fail('入库失败,没有找到采购单');
  231. }
  232. }
  233. }
  234. $ids = array_column($arr, 'id');
  235. $ids = array_unique(array_filter($ids));
  236. if (empty($ids)) {
  237. util::fail('请选择花材');
  238. }
  239. $sjId = $shop->sjId ?? 0;
  240. $chainShopList = [];
  241. if ($default == 1) {
  242. $chainShopList = ShopClass::getAllByCondition(['sjId' => $sjId, 'join' => 0], null, '*', null, true);
  243. }
  244. $productList = ProductClass::getAllByCondition(['id' => ['in', $ids]], null, '*', 'id', true);
  245. foreach ($arr as $product) {
  246. if (isset($product['price']) == false) {
  247. util::fail('没有价格');
  248. }
  249. if (isset($product['id']) == false) {
  250. util::fail('没有花材');
  251. }
  252. $price = $product['price'];
  253. $productId = $product['id'];
  254. $productInfo = $productList[$productId] ?? [];
  255. if (empty($productInfo)) {
  256. util::fail('没有找到花材');
  257. }
  258. $productName = $productInfo->name ?? '';
  259. if (isset($product['price']) == false || is_numeric($product['price']) == false || $product['price'] < 0) {
  260. util::fail('请填写' . $productName . '的批发价');
  261. }
  262. if (isset($product['skPrice']) == false || is_numeric($product['skPrice']) == false || $product['skPrice'] < 0) {
  263. util::fail('请填写' . $productName . '的零售价');
  264. }
  265. $skPrice = $product['skPrice'];
  266. if (isset($product['hjPrice']) == false || is_numeric($product['hjPrice']) == false || $product['hjPrice'] < 0) {
  267. util::fail('请填写' . $productName . '的会员价');
  268. }
  269. $hjPrice = $product['hjPrice'] ?? 0;
  270. if (isset($productInfo->mainId) == false || $productInfo->mainId != $this->mainId) {
  271. util::fail('无法访问');
  272. }
  273. if ($hjPrice > $price) {
  274. util::fail($productName . ' 批发价要大于会员价');
  275. }
  276. if ($price > $skPrice) {
  277. util::fail($productName . ' 零售价要大于批发价');
  278. }
  279. $ptItemId = $productInfo->itemId;
  280. ProductClass::changeSinglePrice($shop, $ptItemId, $price, $skPrice, $hjPrice, $changeParams);
  281. //在首店修改需要同步到所有直营店
  282. if ($default == 1 && isset($shop->dataSync) && $shop->dataSync == 1) {
  283. foreach ($chainShopList as $chain) {
  284. if ($chain->id == $shop->id) {
  285. continue;
  286. }
  287. $chainMainId = $chain->mainId ?? 0;
  288. $staff = ShopAdminClass::getByCondition(['mainId' => $chainMainId, 'adminId' => $adminId], true);
  289. $changeParams2 = ['staffId' => $staff->id, 'staffName' => $staff->name, 'changeType' => $changeType, 'targetId' => $targetId];
  290. ProductClass::changeSinglePrice($chain, $ptItemId, $price, $skPrice, $hjPrice, $changeParams2);
  291. }
  292. }
  293. }
  294. $mainId = $shop->mainId ?? 0;
  295. if (!empty($mainId)) {
  296. //提醒零售收银台界面要刷新
  297. $staffList = ShopAdminClass::getAllByCondition(['mainId' => $mainId], null, '*', null, true);
  298. if (!empty($staffList)) {
  299. foreach ($staffList as $staff) {
  300. $staffId = $staff->id ?? 0;
  301. Yii::$app->redis->executeCommand('SET', ['cashier_' . $mainId . '_' . $staffId . '_may_refresh', 'yes']);
  302. Yii::$app->redis->executeCommand('SET', ['ghs_cashier_' . $mainId . '_' . $staffId . '_may_refresh', 'yes']);
  303. }
  304. }
  305. }
  306. $transaction->commit();
  307. util::complete('操作成功');
  308. } catch (\Exception $e) {
  309. $transaction->rollBack();
  310. Yii::info("失败原因:" . $e->getMessage());
  311. util::fail('修改失败');
  312. }
  313. }
  314. //从零售端采购入库,查看供货商的某个门店的product
  315. public function actionGhsItem()
  316. {
  317. $get = Yii::$app->request->get();
  318. $id = $get['id'] ?? 0;
  319. $ghs = GhsClass::getGhsInfo($id);
  320. if (empty($ghs)) {
  321. util::fail('没有找到供货商');
  322. }
  323. $shopId = $ghs['shopId'] ?? 0;
  324. $black = $ghs['black'] ?? 2;
  325. if ($black == 2) {
  326. util::fail('暂无花材');
  327. }
  328. $connection = Yii::$app->db;//事务处理
  329. $transaction = $connection->beginTransaction();
  330. try {
  331. //获取所有当前供货商的分类 (全部、常用)
  332. //根据分类组装分类下的花材信息
  333. $shop = ShopClass::getById($shopId, true);
  334. $mainId = $shop->mainId ?? 0;
  335. $classIds = ItemClassClass::getGhsItemClassAll($mainId);
  336. $where['mainId'] = $mainId;
  337. $where['delStatus'] = 0;
  338. //是否显示全部花材,包括下架的
  339. $showAll = $get['showAll'] ?? 0;
  340. if ($showAll == 0) {
  341. $where['status'] = 1;
  342. }
  343. $where['frontHide'] = 0;
  344. $level = $ghs['giveLevel'] ?? 1;
  345. $field = 'id,py,cover,name,ratio,classId,itemId,weight,smallUnit,bigUnit,smallUnit,smallRatio,ratioType,variety,price,skPrice,skDiscountPrice,hjPrice,hjDiscountPrice,actualSold,stock,stockWarning,discountPrice,presell,presellDate,reachNum,reachNumDiscount';
  346. $itemInfoData = ProductClass::getAllByCondition($where, ['inTurn' => SORT_DESC, 'actualSold' => SORT_DESC], $field);
  347. $itemInfoData = ProductClass::hdCgGroup($itemInfoData, $level);
  348. $myProduct = ProductClass::getAllByCondition(['mainId' => $this->mainId, 'delStatus' => 0], null, 'id,stock,onStock,stockWarning,itemId', 'itemId');
  349. if (!empty($itemInfoData)) {
  350. $myShop = $this->shop;
  351. $myDisplay = isset($myShop->pfShopId) && $myShop->pfShopId > 0 ? 1 : 0;
  352. foreach ($itemInfoData as $key => $val) {
  353. $ptItemId = $val['itemId'] ?? 0;
  354. $myStock = $myProduct[$ptItemId]['stock'] ?? 0;
  355. $myStock = floatval($myStock);
  356. $myOnStock = $myProduct[$ptItemId]['onStock'] ?? 0;
  357. $myStockWarning = $myProduct[$ptItemId]['stockWarning'] ?? 5;
  358. $myLack = bcadd($myStock, $myOnStock, 2) > $myStockWarning ? 0 : 1;
  359. $itemInfoData[$key]['myStock'] = $myStock;
  360. $itemInfoData[$key]['myOnStock'] = $myOnStock;
  361. $itemInfoData[$key]['myStockWarning'] = $myStockWarning;
  362. $itemInfoData[$key]['myLack'] = $myLack;
  363. $itemInfoData[$key]['myDisplay'] = $myDisplay;
  364. }
  365. }
  366. $respond = ProductService::assembleData($classIds, $itemInfoData, true);
  367. $classItem = $respond['classItem'] ?? [];
  368. util::success($classItem);
  369. } catch (\Exception $e) {
  370. $transaction->rollBack();
  371. Yii::info("报错内容:" . $e->getMessage());
  372. util::fail();
  373. }
  374. }
  375. public function actionGhsItemV2()
  376. {
  377. $get = Yii::$app->request->get();
  378. $id = $get['id'] ?? 0;
  379. $ghs = GhsClass::getGhsInfo($id);
  380. if (empty($ghs)) {
  381. util::fail('没有找到供货商');
  382. }
  383. $shopId = $ghs['shopId'] ?? 0;
  384. $black = $ghs['black'] ?? 2;
  385. if ($black == 2) {
  386. util::fail('暂无花材');
  387. }
  388. $connection = Yii::$app->db;//事务处理
  389. $transaction = $connection->beginTransaction();
  390. try {
  391. //获取所有当前供货商的分类 (全部、常用)
  392. //根据分类组装分类下的花材信息
  393. $shop = ShopClass::getById($shopId, true);
  394. $mainId = $shop->mainId ?? 0;
  395. $classIds = ItemClassClass::getGhsItemClassAll($mainId);
  396. $where['mainId'] = $mainId;
  397. $where['delStatus'] = 0;
  398. //是否显示全部花材,包括下架的
  399. $showAll = $get['showAll'] ?? 0;
  400. if ($showAll == 0) {
  401. $where['status'] = 1;
  402. }
  403. $where['frontHide'] = 0;
  404. $level = $ghs['giveLevel'] ?? 1;
  405. $field = 'id,py,cover,name,ratio,classId,itemId,weight,smallUnit,bigUnit,smallUnit,smallRatio,ratioType,variety,price,skPrice,skDiscountPrice,hjPrice,hjDiscountPrice,actualSold,stock,stockWarning,discountPrice,presell,presellDate,reachNum,reachNumDiscount';
  406. $itemInfoData = ProductClass::getAllByCondition($where, ['inTurn' => SORT_DESC, 'actualSold' => SORT_DESC], $field);
  407. $itemInfoData = ProductClass::hdCgGroup($itemInfoData, $level);
  408. $myProduct = ProductClass::getAllByCondition(['mainId' => $this->mainId, 'delStatus' => 0], null, 'id,stock,onStock,stockWarning,itemId', 'itemId');
  409. if (!empty($itemInfoData)) {
  410. $myShop = $this->shop;
  411. $myDisplay = isset($myShop->pfShopId) && $myShop->pfShopId > 0 ? 1 : 0;
  412. foreach ($itemInfoData as $key => $val) {
  413. $ptItemId = $val['itemId'] ?? 0;
  414. $myStock = $myProduct[$ptItemId]['stock'] ?? 0;
  415. $myStock = floatval($myStock);
  416. $myOnStock = $myProduct[$ptItemId]['onStock'] ?? 0;
  417. $myStockWarning = $myProduct[$ptItemId]['stockWarning'] ?? 5;
  418. $myLack = bcadd($myStock, $myOnStock, 2) > $myStockWarning ? 0 : 1;
  419. $itemInfoData[$key]['myStock'] = $myStock;
  420. $itemInfoData[$key]['myOnStock'] = $myOnStock;
  421. $itemInfoData[$key]['myStockWarning'] = $myStockWarning;
  422. $itemInfoData[$key]['myLack'] = $myLack;
  423. $itemInfoData[$key]['myDisplay'] = $myDisplay;
  424. }
  425. }
  426. $respond = ProductService::assembleData($classIds, $itemInfoData, true);
  427. if (isset($respond['classItem']) && !empty($respond['classItem'])) {
  428. foreach ($respond['classItem'] as $bigKey => $bigVal) {
  429. if (isset($bigVal['child']) && !empty($bigVal['child'])) {
  430. foreach ($bigVal['child'] as $key => $val) {
  431. unset($bigVal['child'][$key]['cover']);
  432. unset($bigVal['child'][$key]['actualSold']);
  433. }
  434. $respond['classItem'][$bigKey]['child'] = $bigVal['child'];
  435. }
  436. }
  437. }
  438. util::success($respond);
  439. } catch (\Exception $e) {
  440. $transaction->rollBack();
  441. Yii::info("报错内容:" . $e->getMessage());
  442. util::fail();
  443. }
  444. }
  445. public function actionDetail()
  446. {
  447. $id = Yii::$app->request->get('id', 0);
  448. $respond = ProductClass::getItemInfo($id);
  449. $ptItemId = $respond['itemId'] ?? 0;
  450. $ptItemInfo = PtItemClass::getById($ptItemId);
  451. $respond['ptItemInfo'] = $ptItemInfo;
  452. util::success($respond);
  453. }
  454. public function actionUpdate()
  455. {
  456. $shop = $this->shop ?? [];
  457. $pfShopId = $shop->pfShopId ?? 0;
  458. if (!empty($pfShopId)) {
  459. util::fail('请在批发端操作');
  460. }
  461. $post = Yii::$app->request->post();
  462. $shopAdmin = $this->shopAdmin;
  463. if (isset($shopAdmin->super) == false || $shopAdmin->super != 1) {
  464. util::fail('超管才能修改');
  465. }
  466. $post['adminId'] = $this->adminId;
  467. $post['staffName'] = $this->shopAdmin->name;
  468. ItemClass::updateProduct($post, $this->shop);
  469. util::complete();
  470. }
  471. //批量修改product 排序,成本价,加价
  472. public function actionBatchUpdate()
  473. {
  474. //data = [{id:1,inTurn:10,addPrice:2,cost:10}]
  475. $data = Yii::$app->request->post('data', '');
  476. $type = Yii::$app->request->post('type', '');
  477. if (empty($data) || empty($type)) {
  478. util::fail("参数错误");
  479. }
  480. if (in_array($type, ['inTurn', 'addPrice', 'cost', 'weight', 'ratio']))
  481. $data = json_decode($data, true);
  482. foreach ($data as $v) {
  483. $id = $v['id'];
  484. $val = $v[$type] ?? '';
  485. $where = [];
  486. $where['id'] = $id;
  487. $where['shopId'] = $this->shopId;
  488. $where['sjId'] = $this->sjId;
  489. if (empty($val)) {
  490. util::fail("参数错误1");
  491. }
  492. $data = [
  493. $type => $val
  494. ];
  495. ProductClass::updateByCondition($where, $data);
  496. ProductClass::autoPriceById($id);
  497. }
  498. util::complete();
  499. }
  500. //供货商产品的详情 ssh 20230111
  501. public function actionGhsProductDetail()
  502. {
  503. $get = Yii::$app->request->get();
  504. $id = $get['id'] ?? 0;
  505. $ghsId = $get['ghsId'] ?? 0;
  506. $product = ProductClass::getById($id);
  507. if (empty($product)) {
  508. util::fail('没有花材信息');
  509. }
  510. $ghsInfo = GhsClass::getById($ghsId, true);
  511. $level = $ghsInfo->giveLevel ? $ghsInfo->giveLevel : 1;
  512. $list = ProductClass::groupProductInfo([$product], $level);
  513. $product = current($list);
  514. util::success($product);
  515. }
  516. //批量修改加价 ssh 20211211
  517. public function actionBatchChangeAddPrice()
  518. {
  519. $shopAdmin = $this->shopAdmin;
  520. if (isset($shopAdmin->super) == false || $shopAdmin->super != 1) {
  521. util::fail('超管才能操作');
  522. }
  523. $shop = $this->shop;
  524. $pfShopId = $shop->pfShopId ?? 0;
  525. if (!empty($pfShopId)) {
  526. util::fail('请在批发端操作');
  527. }
  528. $addData = Yii::$app->request->post('addData', '');
  529. if (empty($addData)) {
  530. util::fail('没有花材');
  531. }
  532. $itemData = json_decode($addData, true);
  533. if (is_array($itemData) == false) {
  534. util::fail('没有花材...');
  535. }
  536. $ids = array_column($itemData, 'id');
  537. $infoList = ProductClass::getByIds($ids);
  538. if (empty($infoList)) {
  539. util::fail('没有花材');
  540. }
  541. foreach ($infoList as $info) {
  542. if (isset($info['mainId']) == false || $info['mainId'] != $this->mainId) {
  543. util::fail('非常访问,不是你的花材不能修改');
  544. }
  545. }
  546. foreach ($itemData as $key => $data) {
  547. $id = $data['id'] ?? 0;
  548. ProductClass::updateById($id, $data);
  549. }
  550. util::complete('修改成功');
  551. }
  552. }