ProductController.php 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629
  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. $shopId = $shop->id ?? 0;
  180. $default = $shop->default ?? 0;
  181. $join = $shop->join ?? 0;
  182. $shopAdmin = $this->shopAdmin;
  183. $adminId = $this->adminId ?? 0;
  184. if (getenv('YII_ENV') == 'production') {
  185. //小蔡鲜花的几个分店的零售店不能修改体系
  186. if (in_array($shopId, [29153, 29155, 29157, 29162, 29164])) {
  187. util::fail('本店无法改价');
  188. }
  189. } else {
  190. if (in_array($shopId, [36545])) {
  191. util::fail('本店无法改价哦');
  192. }
  193. }
  194. if (isset($shopAdmin->super) == false || $shopAdmin->super != 1) {
  195. util::fail('超管才能修改');
  196. }
  197. if ($join == 0 && $default == 0) {
  198. util::fail('当前直营分店,只能回总店修改价格');
  199. }
  200. //normal常规改价,cg采购改价
  201. $changeType = Yii::$app->request->post('changeType', 'normal');
  202. $doType = Yii::$app->request->post('doType', 0);
  203. $targetId = Yii::$app->request->post('targetId', 0);
  204. $changeParams = ['staffId' => $shopAdmin->id, 'staffName' => $shopAdmin->name, 'changeType' => $changeType, 'targetId' => $targetId];
  205. $post = Yii::$app->request->post();
  206. $data = $post['data'] ?? '';
  207. if (empty($data)) {
  208. util::fail('没有修改');
  209. }
  210. $arr = json_decode($data, true);
  211. if (empty($arr)) {
  212. util::fail('没有修改!');
  213. }
  214. $connection = Yii::$app->db;
  215. $transaction = $connection->beginTransaction();
  216. try {
  217. if ($doType == 0 || $doType == 1) {
  218. $cg = PurchaseClass::getLockById($targetId);
  219. if (!empty($cg)) {
  220. if (isset($cg->mainId) == false || $cg->mainId != $this->mainId) {
  221. util::fail('不是您的采购单');
  222. }
  223. if ($cg->status == PurchaseClass::STATUS_UN_SEND && $cg->book == 1) {
  224. util::fail('预订单只有发货后,才能确认收货');
  225. }
  226. //没有发货则先发货
  227. if ($cg->status == PurchaseClass::STATUS_UN_SEND) {
  228. $cg = PurchaseClass::orderSend($cg, [], true);
  229. }
  230. //确认收货并入库
  231. if ($cg->status == PurchaseClass::STATUS_SENDING) {
  232. PurchaseClass::takeToPutIn($cg);
  233. if ($doType == 1) {
  234. $transaction->commit();
  235. util::complete('入库成功');
  236. }
  237. } else {
  238. util::fail('订单不是待入库状态');
  239. }
  240. } else {
  241. if ($doType == 1) {
  242. util::fail('入库失败,没有找到采购单');
  243. }
  244. }
  245. }
  246. $ids = array_column($arr, 'id');
  247. $ids = array_unique(array_filter($ids));
  248. if (empty($ids)) {
  249. util::fail('请选择花材');
  250. }
  251. $sjId = $shop->sjId ?? 0;
  252. $chainShopList = [];
  253. if ($default == 1) {
  254. $chainShopList = ShopClass::getAllByCondition(['sjId' => $sjId, 'join' => 0], null, '*', null, true);
  255. }
  256. $productList = ProductClass::getAllByCondition(['id' => ['in', $ids]], null, '*', 'id', true);
  257. foreach ($arr as $product) {
  258. if (isset($product['price']) == false) {
  259. util::fail('没有价格');
  260. }
  261. if (isset($product['id']) == false) {
  262. util::fail('没有花材');
  263. }
  264. $price = $product['price'];
  265. $productId = $product['id'];
  266. $productInfo = $productList[$productId] ?? [];
  267. if (empty($productInfo)) {
  268. util::fail('没有找到花材');
  269. }
  270. $productName = $productInfo->name ?? '';
  271. if (isset($product['price']) == false || is_numeric($product['price']) == false || $product['price'] < 0) {
  272. util::fail('请填写' . $productName . '的批发价');
  273. }
  274. if (isset($product['skPrice']) == false || is_numeric($product['skPrice']) == false || $product['skPrice'] < 0) {
  275. util::fail('请填写' . $productName . '的零售价');
  276. }
  277. $skPrice = $product['skPrice'];
  278. if (isset($product['hjPrice']) == false || is_numeric($product['hjPrice']) == false || $product['hjPrice'] < 0) {
  279. util::fail('请填写' . $productName . '的会员价');
  280. }
  281. $hjPrice = $product['hjPrice'] ?? 0;
  282. if (isset($productInfo->mainId) == false || $productInfo->mainId != $this->mainId) {
  283. util::fail('无法访问');
  284. }
  285. if ($hjPrice > $price) {
  286. util::fail($productName . ' 批发价要大于会员价');
  287. }
  288. if ($price > $skPrice) {
  289. util::fail($productName . ' 零售价要大于批发价');
  290. }
  291. $ptItemId = $productInfo->itemId;
  292. ProductClass::changeSinglePrice($shop, $ptItemId, $price, $skPrice, $hjPrice, $changeParams);
  293. //在首店修改需要同步到所有直营店
  294. if ($default == 1 && isset($shop->dataSync) && $shop->dataSync == 1) {
  295. foreach ($chainShopList as $chain) {
  296. if ($chain->id == $shop->id) {
  297. continue;
  298. }
  299. $chainMainId = $chain->mainId ?? 0;
  300. $staff = ShopAdminClass::getByCondition(['mainId' => $chainMainId, 'adminId' => $adminId], true);
  301. $changeParams2 = ['staffId' => $staff->id, 'staffName' => $staff->name, 'changeType' => $changeType, 'targetId' => $targetId];
  302. ProductClass::changeSinglePrice($chain, $ptItemId, $price, $skPrice, $hjPrice, $changeParams2);
  303. }
  304. }
  305. }
  306. $mainId = $shop->mainId ?? 0;
  307. if (!empty($mainId)) {
  308. //提醒零售收银台界面要刷新
  309. $staffList = ShopAdminClass::getAllByCondition(['mainId' => $mainId], null, '*', null, true);
  310. if (!empty($staffList)) {
  311. foreach ($staffList as $staff) {
  312. $staffId = $staff->id ?? 0;
  313. Yii::$app->redis->executeCommand('SET', ['cashier_' . $mainId . '_' . $staffId . '_may_refresh', 'yes']);
  314. Yii::$app->redis->executeCommand('SET', ['ghs_cashier_' . $mainId . '_' . $staffId . '_may_refresh', 'yes']);
  315. }
  316. }
  317. }
  318. $transaction->commit();
  319. util::complete('操作成功');
  320. } catch (\Exception $e) {
  321. $transaction->rollBack();
  322. Yii::info("失败原因:" . $e->getMessage());
  323. util::fail('修改失败');
  324. }
  325. }
  326. //从零售端采购入库,查看供货商的某个门店的product
  327. public function actionGhsItem()
  328. {
  329. $get = Yii::$app->request->get();
  330. $id = $get['id'] ?? 0;
  331. $ghs = GhsClass::getGhsInfo($id);
  332. if (empty($ghs)) {
  333. util::fail('没有找到供货商');
  334. }
  335. $shopId = $ghs['shopId'] ?? 0;
  336. $black = $ghs['black'] ?? 2;
  337. if ($black == 2) {
  338. util::fail('暂无花材');
  339. }
  340. $connection = Yii::$app->db;//事务处理
  341. $transaction = $connection->beginTransaction();
  342. try {
  343. //获取所有当前供货商的分类 (全部、常用)
  344. //根据分类组装分类下的花材信息
  345. $shop = ShopClass::getById($shopId, true);
  346. $mainId = $shop->mainId ?? 0;
  347. $classIds = ItemClassClass::getGhsItemClassAll($mainId);
  348. $where['mainId'] = $mainId;
  349. $where['delStatus'] = 0;
  350. //是否显示全部花材,包括下架的
  351. $showAll = $get['showAll'] ?? 0;
  352. if ($showAll == 0) {
  353. $where['status'] = 1;
  354. }
  355. $where['frontHide'] = 0;
  356. $level = $ghs['giveLevel'] ?? 1;
  357. $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';
  358. $itemInfoData = ProductClass::getAllByCondition($where, ['inTurn' => SORT_DESC, 'actualSold' => SORT_DESC], $field);
  359. $itemInfoData = ProductClass::hdCgGroup($itemInfoData, $level);
  360. $myProduct = ProductClass::getAllByCondition(['mainId' => $this->mainId, 'delStatus' => 0], null, 'id,stock,onStock,stockWarning,itemId', 'itemId');
  361. if (!empty($itemInfoData)) {
  362. $myShop = $this->shop;
  363. $myDisplay = isset($myShop->pfShopId) && $myShop->pfShopId > 0 ? 1 : 0;
  364. foreach ($itemInfoData as $key => $val) {
  365. $ptItemId = $val['itemId'] ?? 0;
  366. $myStock = $myProduct[$ptItemId]['stock'] ?? 0;
  367. $myStock = floatval($myStock);
  368. $myOnStock = $myProduct[$ptItemId]['onStock'] ?? 0;
  369. $myStockWarning = $myProduct[$ptItemId]['stockWarning'] ?? 5;
  370. $myLack = bcadd($myStock, $myOnStock, 2) > $myStockWarning ? 0 : 1;
  371. $itemInfoData[$key]['myStock'] = $myStock;
  372. $itemInfoData[$key]['myOnStock'] = $myOnStock;
  373. $itemInfoData[$key]['myStockWarning'] = $myStockWarning;
  374. $itemInfoData[$key]['myLack'] = $myLack;
  375. $itemInfoData[$key]['myDisplay'] = $myDisplay;
  376. }
  377. }
  378. $respond = ProductService::assembleData($classIds, $itemInfoData, true);
  379. $classItem = $respond['classItem'] ?? [];
  380. util::success($classItem);
  381. } catch (\Exception $e) {
  382. $transaction->rollBack();
  383. Yii::info("报错内容:" . $e->getMessage());
  384. util::fail();
  385. }
  386. }
  387. public function actionGhsItemV2()
  388. {
  389. $get = Yii::$app->request->get();
  390. $id = $get['id'] ?? 0;
  391. $ghs = GhsClass::getGhsInfo($id);
  392. if (empty($ghs)) {
  393. util::fail('没有找到供货商');
  394. }
  395. $shopId = $ghs['shopId'] ?? 0;
  396. $black = $ghs['black'] ?? 2;
  397. if ($black == 2) {
  398. util::fail('暂无花材');
  399. }
  400. $connection = Yii::$app->db;//事务处理
  401. $transaction = $connection->beginTransaction();
  402. try {
  403. //获取所有当前供货商的分类 (全部、常用)
  404. //根据分类组装分类下的花材信息
  405. $shop = ShopClass::getById($shopId, true);
  406. $mainId = $shop->mainId ?? 0;
  407. $classIds = ItemClassClass::getGhsItemClassAll($mainId);
  408. $where['mainId'] = $mainId;
  409. $where['delStatus'] = 0;
  410. //是否显示全部花材,包括下架的
  411. $showAll = $get['showAll'] ?? 0;
  412. if ($showAll == 0) {
  413. $where['status'] = 1;
  414. }
  415. $where['frontHide'] = 0;
  416. $level = $ghs['giveLevel'] ?? 1;
  417. $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';
  418. $itemInfoData = ProductClass::getAllByCondition($where, ['inTurn' => SORT_DESC, 'actualSold' => SORT_DESC], $field);
  419. $itemInfoData = ProductClass::hdCgGroup($itemInfoData, $level);
  420. $myProduct = ProductClass::getAllByCondition(['mainId' => $this->mainId, 'delStatus' => 0], null, 'id,stock,onStock,stockWarning,itemId', 'itemId');
  421. if (!empty($itemInfoData)) {
  422. $myShop = $this->shop;
  423. $myDisplay = isset($myShop->pfShopId) && $myShop->pfShopId > 0 ? 1 : 0;
  424. foreach ($itemInfoData as $key => $val) {
  425. $ptItemId = $val['itemId'] ?? 0;
  426. $myStock = $myProduct[$ptItemId]['stock'] ?? 0;
  427. $myStock = floatval($myStock);
  428. $myOnStock = $myProduct[$ptItemId]['onStock'] ?? 0;
  429. $myStockWarning = $myProduct[$ptItemId]['stockWarning'] ?? 5;
  430. $myLack = bcadd($myStock, $myOnStock, 2) > $myStockWarning ? 0 : 1;
  431. $itemInfoData[$key]['myStock'] = $myStock;
  432. $itemInfoData[$key]['myOnStock'] = $myOnStock;
  433. $itemInfoData[$key]['myStockWarning'] = $myStockWarning;
  434. $itemInfoData[$key]['myLack'] = $myLack;
  435. $itemInfoData[$key]['myDisplay'] = $myDisplay;
  436. }
  437. }
  438. $respond = ProductService::assembleData($classIds, $itemInfoData, true);
  439. if ($showAll == 1) {
  440. if (isset($respond['classItem']) && !empty($respond['classItem'])) {
  441. foreach ($respond['classItem'] as $bigKey => $bigVal) {
  442. if (isset($bigVal['child']) && !empty($bigVal['child'])) {
  443. foreach ($bigVal['child'] as $key => $val) {
  444. unset($bigVal['child'][$key]['cover']);
  445. unset($bigVal['child'][$key]['actualSold']);
  446. unset($bigVal['child'][$key]['defaultGradePrice']);
  447. unset($bigVal['child'][$key]['discountPrice']);
  448. unset($bigVal['child'][$key]['hjDiscountPrice']);
  449. unset($bigVal['child'][$key]['hjPrice']);
  450. unset($bigVal['child'][$key]['presellDateShow']);
  451. unset($bigVal['child'][$key]['prePrice']);
  452. unset($bigVal['child'][$key]['print']);
  453. unset($bigVal['child'][$key]['reachNum']);
  454. unset($bigVal['child'][$key]['reachNumDiscount']);
  455. unset($bigVal['child'][$key]['reachPrice']);
  456. unset($bigVal['child'][$key]['skDiscountPrice']);
  457. unset($bigVal['child'][$key]['skPrice']);
  458. unset($bigVal['child'][$key]['bigUnit']);
  459. unset($bigVal['child'][$key]['weight']);
  460. unset($bigVal['child'][$key]['stockWarning']);
  461. //unset($bigVal['child'][$key]['smallPrice']);
  462. //unset($bigVal['child'][$key]['smallRatio']);
  463. }
  464. $respond['classItem'][$bigKey]['child'] = $bigVal['child'];
  465. }
  466. }
  467. }
  468. }
  469. util::success($respond);
  470. } catch (\Exception $e) {
  471. $transaction->rollBack();
  472. Yii::info("报错内容:" . $e->getMessage());
  473. util::fail();
  474. }
  475. }
  476. public function actionDetail()
  477. {
  478. $id = Yii::$app->request->get('id', 0);
  479. $respond = ProductClass::getItemInfo($id);
  480. $ptItemId = $respond['itemId'] ?? 0;
  481. $ptItemInfo = PtItemClass::getById($ptItemId);
  482. $respond['ptItemInfo'] = $ptItemInfo;
  483. util::success($respond);
  484. }
  485. public function actionUpdate()
  486. {
  487. $shop = $this->shop ?? [];
  488. $pfShopId = $shop->pfShopId ?? 0;
  489. if (!empty($pfShopId)) {
  490. util::fail('请在批发端操作');
  491. }
  492. $post = Yii::$app->request->post();
  493. $shopAdmin = $this->shopAdmin;
  494. if (isset($shopAdmin->super) == false || $shopAdmin->super != 1) {
  495. util::fail('超管才能修改');
  496. }
  497. $post['adminId'] = $this->adminId;
  498. $post['staffName'] = $this->shopAdmin->name;
  499. ItemClass::updateProduct($post, $this->shop);
  500. util::complete();
  501. }
  502. //批量修改product 排序,成本价,加价
  503. public function actionBatchUpdate()
  504. {
  505. //data = [{id:1,inTurn:10,addPrice:2,cost:10}]
  506. $data = Yii::$app->request->post('data', '');
  507. $type = Yii::$app->request->post('type', '');
  508. if (empty($data) || empty($type)) {
  509. util::fail("参数错误");
  510. }
  511. if (in_array($type, ['inTurn', 'addPrice', 'cost', 'weight', 'ratio']))
  512. $data = json_decode($data, true);
  513. foreach ($data as $v) {
  514. $id = $v['id'];
  515. $val = $v[$type] ?? '';
  516. $where = [];
  517. $where['id'] = $id;
  518. $where['shopId'] = $this->shopId;
  519. $where['sjId'] = $this->sjId;
  520. if (empty($val)) {
  521. util::fail("参数错误1");
  522. }
  523. $data = [
  524. $type => $val
  525. ];
  526. ProductClass::updateByCondition($where, $data);
  527. ProductClass::autoPriceById($id);
  528. }
  529. util::complete();
  530. }
  531. //供货商产品的详情 ssh 20230111
  532. public function actionGhsProductDetail()
  533. {
  534. $get = Yii::$app->request->get();
  535. $id = $get['id'] ?? 0;
  536. $ghsId = $get['ghsId'] ?? 0;
  537. $product = ProductClass::getById($id);
  538. if (empty($product)) {
  539. util::fail('没有花材信息');
  540. }
  541. $ghsInfo = GhsClass::getById($ghsId, true);
  542. $level = isset($ghsInfo->giveLevel) ? $ghsInfo->giveLevel : 1;
  543. $list = ProductClass::groupProductInfo([$product], $level);
  544. $product = current($list);
  545. util::success($product);
  546. }
  547. //批量修改加价 ssh 20211211
  548. public function actionBatchChangeAddPrice()
  549. {
  550. $shopAdmin = $this->shopAdmin;
  551. if (isset($shopAdmin->super) == false || $shopAdmin->super != 1) {
  552. util::fail('超管才能操作');
  553. }
  554. $shop = $this->shop;
  555. $pfShopId = $shop->pfShopId ?? 0;
  556. if (!empty($pfShopId)) {
  557. util::fail('请在批发端操作');
  558. }
  559. $addData = Yii::$app->request->post('addData', '');
  560. if (empty($addData)) {
  561. util::fail('没有花材');
  562. }
  563. $itemData = json_decode($addData, true);
  564. if (is_array($itemData) == false) {
  565. util::fail('没有花材...');
  566. }
  567. $ids = array_column($itemData, 'id');
  568. $infoList = ProductClass::getByIds($ids);
  569. if (empty($infoList)) {
  570. util::fail('没有花材');
  571. }
  572. foreach ($infoList as $info) {
  573. if (isset($info['mainId']) == false || $info['mainId'] != $this->mainId) {
  574. util::fail('非常访问,不是你的花材不能修改');
  575. }
  576. }
  577. foreach ($itemData as $key => $data) {
  578. $id = $data['id'] ?? 0;
  579. ProductClass::updateById($id, $data);
  580. }
  581. util::complete('修改成功');
  582. }
  583. }