ProductController.php 26 KB

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