ProductController.php 25 KB

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