ProductController.php 28 KB

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