ProductController.php 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750
  1. <?php
  2. /**
  3. * User: admin
  4. * Date Time: 2021/1/15 20:36
  5. */
  6. namespace ghs\controllers;
  7. use biz\admin\classes\AdminRoleClass;
  8. use biz\ghs\classes\GhsClass;
  9. use biz\item\classes\PtItemClass;
  10. use bizGhs\custom\classes\CustomClass;
  11. use bizGhs\item\classes\ItemClassClass;
  12. use bizGhs\merchant\classes\ShopClass;
  13. use bizGhs\product\classes\ProductClass;
  14. use bizGhs\product\models\Product;
  15. use bizGhs\product\services\ProductService;
  16. use bizGhs\shop\classes\ShopAdminClass;
  17. use common\components\printUtil;
  18. use common\components\stringUtil;
  19. use common\components\util;
  20. use Yii;
  21. class ProductController extends BaseController
  22. {
  23. public $guestAccess = ['index'];
  24. //取消特价 ssh 20220901
  25. public function actionCancelDiscount()
  26. {
  27. $get = Yii::$app->request->get();
  28. $id = $get['id'] ?? 0;
  29. $info = ProductClass::getById($id, true);
  30. ProductClass::check($info, $this->mainId);
  31. $info->discountPrice = 0;
  32. $info->save();
  33. util::complete();
  34. }
  35. //打印花材的标签 ssh 20220602
  36. public function actionPrint()
  37. {
  38. $get = Yii::$app->request->get();
  39. $id = $get['id'] ?? 0;
  40. $num = $get['num'] ?? 1;
  41. $info = ProductClass::getById($id, true);
  42. if (empty($info)) {
  43. util::fail('没有找到花材');
  44. }
  45. $name = $info->name ?? '';
  46. $ptItemId = $info->itemId ?? 0;
  47. $mainId = $info->mainId ?? 0;
  48. $ext = $this->shopExt;
  49. $printLabelSn = $ext->printLabelSn ?? '';
  50. if (empty($printLabelSn)) {
  51. util::fail('请设置标签打印机');
  52. }
  53. $p = new printUtil($printLabelSn);
  54. $unit = $info->ratio . $info->smallUnit . '/' . $info->bigUnit;
  55. $p->times = $num;
  56. $content = '<TEXT x="360" y="30" font="12" w="2" h="2" r="90">' . $name . '</TEXT>';
  57. $content .= '<BC128 x="260" y="30" h="80" s="1" r="90" n="5" w="12">' . $ptItemId . '</BC128>';
  58. if (in_array($mainId, [52, 1459])) {
  59. $content .= '<TEXT x="80" y="30" font="12" w="2" h="2" r="90">惠雅鲜花</TEXT>';
  60. } else {
  61. $content .= '<TEXT x="80" y="30" font="12" w="2" h="2" r="90">' . $unit . '</TEXT>';
  62. }
  63. $content .= '<QR x="30" y="390" e="L" w="5">' . Yii::$app->params['mallHost'] . "/item/show-info?id=" . $id . '</QR>';
  64. $content .= '<TEXT x="220" y="400" font="12" w="1" h="1" r="90">扫码看价格</TEXT>';
  65. $p->printLabelMsg($content);
  66. util::complete();
  67. }
  68. //按分类列出所有花材
  69. public function actionIndex()
  70. {
  71. $py = Yii::$app->request->get('py', '');
  72. $requestType = Yii::$app->request->get('requestType', 'common');
  73. //默认显示上架商品
  74. $status = Yii::$app->request->get('status', 1);
  75. //默认显示未删除商品
  76. $delStatus = Yii::$app->request->get('delStatus', 0);
  77. //获取所有当前供货商的分类 (全部、常用)
  78. //根据分类组装分类下的花材信息
  79. //中央ID
  80. $classIds = ItemClassClass::getGhsItemClassAll($this->mainId);
  81. $where['mainId'] = $this->mainId;
  82. if ($py) {
  83. $pyName = strtolower($py);
  84. $where['py'] = $pyName;
  85. }
  86. if ($requestType == 'hasStock') {
  87. //改价只显示库存大于0的
  88. $where['stock>'] = 0;
  89. }
  90. if (!empty($status)) {
  91. $where['status'] = $status;
  92. }
  93. $where['delStatus'] = $delStatus;
  94. //客户等级
  95. $customId = Yii::$app->request->get('customId', 0);
  96. $level = 1;
  97. if (!empty($customId)) {
  98. $custom = CustomClass::getById($customId, true);
  99. $level = $custom->level ?? 1;
  100. }
  101. $itemInfoData = ProductClass::getAllByCondition($where, ['inTurn' => SORT_DESC, 'actualSold' => SORT_DESC], "*");
  102. $itemInfoData = ProductClass::groupProductInfo($itemInfoData, $level);
  103. $data = ProductService::assembleData($classIds, $itemInfoData, true);
  104. util::success($data);
  105. }
  106. //所有花材分页和不分页
  107. public function actionList()
  108. {
  109. $where = [];
  110. $classId = Yii::$app->request->get('classId', 0);
  111. if (!empty($classId)) {
  112. $where['classId'] = $classId;
  113. }
  114. $name = Yii::$app->request->get('name', '');
  115. if (empty($name)) {
  116. $py = Yii::$app->request->get('py', '');
  117. $name = !empty($py) ? $py : '';
  118. }
  119. if (!empty($name)) {
  120. if (stringUtil::isLetter($name)) {
  121. $where['py'] = ['like', $name];
  122. } else {
  123. $where['name'] = ['like', $name];
  124. }
  125. }
  126. $status = Yii::$app->request->get('status', 0);
  127. if (!empty($status)) {
  128. $where['status'] = $status;
  129. }
  130. $delStatus = Yii::$app->request->get('delStatus', 0);
  131. if ($delStatus != 2) {
  132. $where['delStatus'] = $delStatus;
  133. }
  134. $where['mainId'] = $this->mainId;
  135. $productIds = Yii::$app->request->get('ids', '');
  136. if (!empty($productIds)) {
  137. $productIdArr = explode(',', $productIds);
  138. if (!empty($productIdArr)) {
  139. $where['id'] = ['in', $productIdArr];
  140. }
  141. }
  142. //输出标准会员价,即花店价,默认显示的是花店价
  143. $level = 1;
  144. $type = Yii::$app->request->get('type', '');
  145. $showPage = Yii::$app->request->get('showPage', 0);
  146. if ($showPage) {
  147. if ($type == 'waring') {
  148. $pro = Product::find()->where("mainId={$this->mainId}")->andWhere('`stock`<`stockWarning`')->select('id')->asArray()->all();
  149. $lackIds = array_column($pro, 'id');
  150. if (empty($lackIds)) {
  151. util::success([]);
  152. }
  153. $lackIds = array_filter(array_unique($lackIds));
  154. $where['id'] = ['in', $lackIds];
  155. $respond = ProductClass::getList("*", $where, "actualSold desc");
  156. } else {
  157. $respond = ProductClass::getList("*", $where, "inTurn desc");
  158. }
  159. $respond['list'] = ProductClass::groupProductInfo($respond['list'], $level);
  160. $respond['list'] = ProductClass::groupClassName($this->sjId, $respond['list']);
  161. util::success($respond);
  162. } else {
  163. if ($type == 'waring') {
  164. //库存预警 按库存从小到大排序
  165. $data = ProductClass::getAllByCondition($where, ['stock' => SORT_ASC, 'inTurn' => SORT_DESC], "*");
  166. } else {
  167. if (!empty($productIds)) {
  168. //优先按 $productIds 排序 "FIELD(`id`,4,5,6)"=>true
  169. $data = ProductClass::getAllByCondition($where, ["FIELD(`id`,$productIds)" => true, 'inTurn' => SORT_DESC], "*");
  170. } else {
  171. $data = ProductClass::getAllByCondition($where, ['actualSold' => SORT_DESC, 'inTurn' => SORT_DESC], "*");
  172. }
  173. }
  174. $data = ProductClass::groupProductInfo($data, $level);
  175. $data = ProductClass::groupClassName($this->sjId, $data);
  176. if ($type == 'waring') {
  177. //库存预警
  178. $newData = [];
  179. foreach ($data as $v) {
  180. if ($v['stock'] <= $v['stockWarning']) {
  181. $newData[] = $v;
  182. }
  183. }
  184. util::success(['list' => $newData]);
  185. }
  186. util::success(['list' => $data]);
  187. }
  188. }
  189. //所有花材
  190. public function actionAll()
  191. {
  192. $where = [];
  193. $where['mainId'] = $this->mainId;
  194. $classId = Yii::$app->request->get('classId', 0);
  195. if (!empty($classId)) {
  196. $where['classId'] = $classId;
  197. }
  198. $status = Yii::$app->request->get('status', 0);
  199. if (!empty($status)) {
  200. $where['status'] = $status;
  201. }
  202. $delStatus = Yii::$app->request->get('delStatus', 0);
  203. if ($delStatus != 2) {
  204. $where['delStatus'] = $delStatus;
  205. }
  206. //输出标准会员价,即花店价,默认显示的是花店价
  207. $level = 1;
  208. $data = ProductClass::getAllByCondition($where, ['actualSold' => SORT_DESC, 'inTurn' => SORT_DESC], "*");
  209. $data = ProductClass::groupProductInfo($data, $level);
  210. util::success(['list' => $data]);
  211. }
  212. //批量改价
  213. public function actionBatchChangePrice()
  214. {
  215. $shop = $this->shop;
  216. $join = $shop->join ?? 0;
  217. $default = $shop->default ?? 0;
  218. if ($join == 0 && $default == 0) {
  219. util::fail('请在首店操作');
  220. }
  221. $shopAdmin = $this->shopAdmin;
  222. if (isset($shopAdmin->super) == false || $shopAdmin->super != 1) {
  223. util::fail('超管才能修改');
  224. }
  225. $shop = $this->shop;
  226. $default = $shop->default ?? 0;
  227. $data = Yii::$app->request->post('data', '');
  228. if (empty($data)) {
  229. util::fail('没有修改');
  230. }
  231. $arr = json_decode($data, true);
  232. if (empty($arr)) {
  233. util::fail('没有修改哦');
  234. }
  235. $connection = Yii::$app->db;
  236. $transaction = $connection->beginTransaction();
  237. try {
  238. $ids = array_column($arr, 'id');
  239. $ids = array_unique(array_filter($ids));
  240. if (empty($ids)) {
  241. util::fail('请选择花材');
  242. }
  243. $sjId = $shop->sjId ?? 0;
  244. $chainShopList = [];
  245. if ($default == 1) {
  246. $chainShopList = ShopClass::getAllByCondition(['sjId' => $sjId, 'join' => 0], null, '*', null, true);
  247. }
  248. $productList = ProductClass::getAllByCondition(['id' => ['in', $ids]], null, '*', 'id', true);
  249. foreach ($arr as $product) {
  250. $productId = $product['id'];
  251. $productInfo = $productList[$productId] ?? [];
  252. if (empty($productInfo)) {
  253. util::fail('没有找到花材');
  254. }
  255. $productName = $productInfo->name ?? '';
  256. if (isset($product['id']) == false) {
  257. util::fail('没有花材');
  258. }
  259. if (isset($product['price']) == false || is_numeric($product['price']) == false || $product['price'] < 0) {
  260. util::fail('请填写' . $productName . '的花店价');
  261. }
  262. $price = $product['price'];
  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($productInfo->mainId) == false || $productInfo->mainId != $this->mainId) {
  268. util::fail('没有权限访问');
  269. }
  270. if (empty($price)) {
  271. continue;
  272. }
  273. $ptItemId = $productInfo->itemId;
  274. ProductClass::changeSinglePrice($shop, $ptItemId, $price, $skPrice);
  275. //在首店修改需要同步到所有直营店
  276. if ($default == 1) {
  277. foreach ($chainShopList as $chain) {
  278. if ($chain->id == $shop->id) {
  279. continue;
  280. }
  281. ProductClass::changeSinglePrice($chain, $ptItemId, $price, $skPrice);
  282. }
  283. }
  284. }
  285. $mainId = $shop->mainId ?? 0;
  286. if (!empty($mainId)) {
  287. //提醒零售收银台界面要刷新
  288. $staffList = ShopAdminClass::getAllByCondition(['mainId' => $mainId], null, '*', null, true);
  289. if (!empty($staffList)) {
  290. foreach ($staffList as $staff) {
  291. $staffId = $staff->id ?? 0;
  292. Yii::$app->redis->executeCommand('SET', ['cashier_' . $mainId . '_' . $staffId . '_may_refresh', 'yes']);
  293. }
  294. }
  295. }
  296. $transaction->commit();
  297. util::complete('修改成功');
  298. } catch (\Exception $e) {
  299. $transaction->rollBack();
  300. Yii::info("修改失败原因:" . $e->getMessage());
  301. util::fail('修改失败');
  302. }
  303. }
  304. //改价
  305. public function actionChangePrice()
  306. {
  307. $shopAdmin = $this->shopAdmin;
  308. if (isset($shopAdmin->super) == false || $shopAdmin->super != 1) {
  309. util::fail('超管才能修改');
  310. }
  311. $productId = Yii::$app->request->post('productId', 0);
  312. $productInfo = ProductClass::getById($productId, true);
  313. if (empty($productInfo)) {
  314. util::fail("花材不存在");
  315. }
  316. if ($productInfo->mainId != $this->mainId) {
  317. util::fail('没有权限');
  318. }
  319. $price = Yii::$app->request->post('price', '');
  320. if (is_numeric($price) && $price > 0) {
  321. ProductClass::changeSinglePrice($productInfo, $price, ProductClass::PRICE_LABEL_CHANGE);
  322. } else {
  323. $price = bcadd($productInfo->cost, $productInfo->addPrice, 2);
  324. ProductClass::changeSinglePrice($productInfo, $price, ProductClass::PRICE_LABEL_AUTO);
  325. }
  326. util::success(['price' => $price]);
  327. }
  328. //恢复自动调价
  329. public function actionAutoPrice()
  330. {
  331. $productId = Yii::$app->request->post('productId', 0);
  332. $productData = ProductClass::getById($productId);
  333. if (!$productData) {
  334. util::fail("花材不存在");
  335. }
  336. //2021.04.06改为用product中的成本价+加价
  337. $price = bcadd($productData['cost'], $productData['addPrice'], 2);
  338. ProductClass::changeSinglePrice($productId, $this->shopId, $price, ProductClass::PRICE_LABEL_AUTO);
  339. util::complete("操作成功");
  340. }
  341. //修改加价
  342. public function actionChangeAddPrice()
  343. {
  344. $productId = Yii::$app->request->post('productId', 0);
  345. $addPrice = Yii::$app->request->post('addPrice', '');
  346. if ($addPrice < 0) {
  347. util::fail("加价不能小于0");
  348. }
  349. $productData = ProductClass::getProductData($productId, $this->mainId);
  350. if (!$productData) {
  351. util::fail("花材不存在");
  352. }
  353. ProductClass::changeAddPrice($productId, $addPrice);
  354. util::complete();
  355. }
  356. //批量修改更多,包括排序、重量和保质期 ssh 20211211
  357. public function actionBatchChangeMore()
  358. {
  359. $shop = $this->shop;
  360. $default = $shop->default ?? 0;
  361. if ($default == 0) {
  362. util::fail('请在首店修改');
  363. }
  364. $shopAdmin = $this->shopAdmin;
  365. if (isset($shopAdmin->super) == false || $shopAdmin->super != 1) {
  366. util::fail('超管才能操作');
  367. }
  368. $addData = Yii::$app->request->post('addData', '');
  369. if (empty($addData)) {
  370. util::fail('没有花材');
  371. }
  372. $itemData = json_decode($addData, true);
  373. if (is_array($itemData) == false) {
  374. util::fail('没有花材...');
  375. }
  376. $ids = array_column($itemData, 'id');
  377. $infoList = ProductClass::getByIds($ids,null,'id');
  378. if (empty($infoList)) {
  379. util::fail('没有花材');
  380. }
  381. foreach ($infoList as $info) {
  382. if (isset($info['mainId']) == false || $info['mainId'] != $this->mainId) {
  383. util::fail('不是你的花材不能修改');
  384. }
  385. }
  386. //首店修改同步到所有直营店
  387. $sjId = $shop->sjId ?? 0;
  388. $chainShopList = ShopClass::getAllByCondition(['sjId' => $sjId], null, '*', null, true);
  389. foreach ($itemData as $key => $data) {
  390. $id = $data['id'] ?? 0;
  391. unset($data['id']);
  392. ProductClass::updateById($id, $data);
  393. $ptItemId = $infoList[$id]['itemId'] ?? 0;
  394. if (empty($ptItemId)) {
  395. continue;
  396. }
  397. if (isset($shop->default) && $shop->default == 1) {
  398. foreach ($chainShopList as $chainShop) {
  399. $currentMainId = $chainShop->mainId ?? 0;
  400. if ($currentMainId == $shop->mainId) {
  401. //前面已经修改过了,不需要重复修改
  402. continue;
  403. }
  404. ProductClass::updateByCondition(['mainId' => $currentMainId, 'itemId' => $ptItemId], $data);
  405. }
  406. }
  407. }
  408. util::complete('修改成功');
  409. }
  410. //批量修改加价 ssh 20211211
  411. public function actionBatchChangeAddPrice()
  412. {
  413. $shop = $this->shop;
  414. $join = $shop->join ?? 0;
  415. $default = $shop->default ?? 0;
  416. if ($join == 0 && $default == 0) {
  417. util::fail('请在首店操作');
  418. }
  419. $shopAdmin = $this->shopAdmin;
  420. if (isset($shopAdmin->super) == false || $shopAdmin->super != 1) {
  421. util::fail('超管才能操作');
  422. }
  423. $addData = Yii::$app->request->post('addData', '');
  424. if (empty($addData)) {
  425. util::fail('没有花材');
  426. }
  427. $itemData = json_decode($addData, true);
  428. if (is_array($itemData) == false) {
  429. util::fail('没有花材...');
  430. }
  431. $ids = array_column($itemData, 'id');
  432. $infoList = ProductClass::getByIds($ids, null, 'id');
  433. if (empty($infoList)) {
  434. util::fail('没有花材');
  435. }
  436. foreach ($infoList as $info) {
  437. if (isset($info['mainId']) == false || $info['mainId'] != $this->mainId) {
  438. util::fail('不能修改别人的花材');
  439. }
  440. }
  441. //首店修改同步到所有直营店
  442. $sjId = $shop->sjId ?? 0;
  443. $chainShopList = ShopClass::getAllByCondition(['sjId' => $sjId], null, '*', null, true);
  444. foreach ($itemData as $key => $data) {
  445. $id = $data['id'] ?? 0;
  446. unset($data['id']);
  447. ProductClass::updateById($id, $data);
  448. $ptItemId = $infoList[$id]['itemId'] ?? 0;
  449. if (empty($ptItemId)) {
  450. continue;
  451. }
  452. if (isset($shop->default) && $shop->default == 1) {
  453. foreach ($chainShopList as $chainShop) {
  454. if (isset($chainShop->join) && $chainShop->join == 1) {
  455. continue;
  456. }
  457. $currentMainId = $chainShop->mainId ?? 0;
  458. if ($currentMainId == $shop->mainId) {
  459. //前面已经修改过了,不需要重复修改
  460. continue;
  461. }
  462. ProductClass::updateByCondition(['mainId' => $currentMainId, 'itemId' => $ptItemId], $data);
  463. }
  464. }
  465. }
  466. util::complete('修改成功');
  467. }
  468. public function actionUpdate()
  469. {
  470. $shopAdmin = $this->shopAdmin;
  471. if (isset($shopAdmin->super) == false || $shopAdmin->super != 1) {
  472. util::fail('超管才能操作');
  473. }
  474. $shop = $this->shop;
  475. $join = $shop->join ?? 0;
  476. $default = $shop->default ?? 0;
  477. if ($join == 0 && $default == 0) {
  478. //因为盘点不能将花材盘成0,所以这边放出入口允许创始人在分店修改分店的花材库存
  479. if ($shopAdmin->super != 1) {
  480. util::fail('请先开通超管权限');
  481. }
  482. }
  483. $post = Yii::$app->request->post();
  484. $post['adminId'] = $this->adminId;
  485. $post['staffName'] = $this->shopAdmin->name;
  486. ProductClass::updateProduct($post, $this->shop);
  487. util::complete();
  488. }
  489. //上下架状态控制 ssh 20210713
  490. public function actionStatusUpdate()
  491. {
  492. $post = Yii::$app->request->post();
  493. $shopAdmin = $this->shopAdmin;
  494. $roleId = $shopAdmin['roleId'] ?? 0;
  495. $role = AdminRoleClass::getById($roleId);
  496. $roleName = $role['roleName'] ?? '';
  497. if ($roleName == '员工') {
  498. util::fail('没有权限操作哦');
  499. }
  500. $id = $post['id'] ?? 0;
  501. $status = $post['status'] ?? 1;
  502. $product = ProductClass::getById($id, true);
  503. if ($product->mainId != $this->mainId) {
  504. util::fail('没有权限操作');
  505. }
  506. $product->status = $status;
  507. if ($status == 2) {
  508. $product->discountPrice = 0;
  509. }
  510. $product->save();
  511. util::complete();
  512. }
  513. //花材展示状态控制 ssh 20210804
  514. public function actionDelStatusUpdate()
  515. {
  516. $post = Yii::$app->request->post();
  517. $shop = $this->shop;
  518. $join = $shop->join ?? 0;
  519. $default = $shop->default ?? 0;
  520. if ($join == 0 && $default == 0) {
  521. util::fail('请在首店操作');
  522. }
  523. $shopAdmin = $this->shopAdmin;
  524. $roleId = $shopAdmin['roleId'] ?? 0;
  525. $role = AdminRoleClass::getById($roleId);
  526. $roleName = $role['roleName'] ?? '';
  527. if ($roleName == '员工') {
  528. util::fail('没有权限操作');
  529. }
  530. $id = $post['id'] ?? 0;
  531. $delStatus = $post['delStatus'] ?? 0;
  532. $product = ProductClass::getById($id, true);
  533. if ($product->mainId != $this->mainId) {
  534. util::fail('没有权限操作');
  535. }
  536. $product->delStatus = $delStatus;
  537. $product->save();
  538. $ptItemId = $product->itemId ?? 0;
  539. if (isset($shop->default) && $shop->default == 1) {
  540. //首店修改同步到所有直营店
  541. $sjId = $shop->sjId ?? 0;
  542. $chainShopList = ShopClass::getAllByCondition(['sjId' => $sjId], null, '*', null, true);
  543. foreach ($chainShopList as $chainShop) {
  544. $chainShopId = $chainShop->id ?? 0;
  545. if (isset($chainShop->join) && $chainShop->join == 1) {
  546. continue;
  547. }
  548. if ($chainShopId == $shop->id) {
  549. continue;
  550. }
  551. $chainMainId = $chainShop->mainId ?? 0;
  552. $chainProduct = ProductClass::getByCondition(['mainId' => $chainMainId, 'itemId' => $ptItemId], true);
  553. if (!empty($chainProduct)) {
  554. $chainProduct->delStatus = $delStatus;
  555. $chainProduct->save();
  556. }
  557. }
  558. }
  559. util::complete();
  560. }
  561. //详情 ruidian 2021.5.3
  562. public function actionDetail()
  563. {
  564. $id = Yii::$app->request->get('id', 0);
  565. $respond = ProductClass::getItemInfo($id);
  566. $ptItemId = $respond['itemId'] ?? 0;
  567. $ptItemInfo = PtItemClass::getById($ptItemId);
  568. $respond['ptItemInfo'] = $ptItemInfo;
  569. util::success($respond);
  570. }
  571. //新增花材 2021.6.21
  572. public function actionAdd()
  573. {
  574. $post = Yii::$app->request->post();
  575. $shop = $this->shop;
  576. $default = $shop->default ?? 0;
  577. if ($default == 0) {
  578. util::fail('请在首店添加,分店只能修改花材');
  579. }
  580. $shopAdmin = $this->shopAdmin;
  581. if (isset($shopAdmin->super) == false || $shopAdmin->super != 1) {
  582. util::fail('管理员才能添加花材');
  583. }
  584. $post['sjId'] = $this->sjId;
  585. $post['adminId'] = $this->adminId;
  586. $post['mainId'] = $this->mainId;
  587. $price = $post['price'] ?? 0;
  588. $addPrice = $post['addPrice'] ?? 0;
  589. if ($addPrice > $price) {
  590. util::fail('加价不能大于售价');
  591. }
  592. $cost = bcsub($price, $addPrice, 2);
  593. $post['cost'] = $cost;
  594. $post['staffName'] = $shopAdmin->name ?? '';
  595. ProductClass::addProduct($post, $this->shop);
  596. util::complete('添加成功');
  597. }
  598. //获取拼音缩写 ssh 20210707
  599. public function actionPy()
  600. {
  601. $name = Yii::$app->request->get('name');
  602. $py = stringUtil::py($name);
  603. util::success(['py' => $py]);
  604. }
  605. //(客户端-批发商)复制花材
  606. public function actionClone()
  607. {
  608. $post = Yii::$app->request->post();
  609. $shop = $this->shop;
  610. $join = $shop->join ?? 0;
  611. $default = $shop->default ?? 0;
  612. if ($join == 0 && $default == 0) {
  613. util::fail('请在首店操作');
  614. }
  615. $shopAdmin = $this->shopAdmin;
  616. if (isset($shopAdmin->super) == false || $shopAdmin->super != 1) {
  617. util::fail('管理员才能添加花材');
  618. }
  619. $shop = $this->shop;
  620. $default = $shop->default ?? 0;
  621. if ($default != 1) {
  622. util::fail('请在总店添加');
  623. }
  624. $post['sjId'] = $this->sjId;
  625. $post['adminId'] = $this->adminId;
  626. $post['mainId'] = $this->mainId;
  627. $post['staffName'] = $shopAdmin->name ?? '';
  628. $price = $post['price'] ?? 0;
  629. $addPrice = $post['addPrice'] ?? 0;
  630. if ($addPrice > $price) {
  631. util::fail('加价不能大于售价');
  632. }
  633. $cost = bcsub($price, $addPrice, 2);
  634. $post['cost'] = $cost;
  635. $post['copy'] = 1; //复制标识
  636. //去除无用的字段
  637. unset($post['viewNum']);
  638. unset($post['actualSold']);
  639. unset($post['itemId']);
  640. unset($post['id']);
  641. unset($post['delStatus']);
  642. ProductClass::addProduct($post, $this->shop);
  643. util::complete('复制成功');
  644. }
  645. //下载价格表 ssh 20210922
  646. public function actionGeneratePriceTable()
  647. {
  648. $level = Yii::$app->request->get('level', 0);
  649. $respond = ProductService::generatePriceTable($this->sjId, $level, $this->mainId);
  650. $file = $respond['file'] ?? '';
  651. $shortFile = $respond['shortFile'] ?? '';
  652. $fileUrl = Yii::$app->params['ghsHost'] . $file;
  653. util::success(['file' => $fileUrl, 'shortFile' => $shortFile]);
  654. }
  655. //下载条形码 lqh 20211227
  656. public function actionGenerateBarcodeTable()
  657. {
  658. $respond = ProductService::generateBarcodeTable($this->sjId, $this->shopId, $this->mainId);
  659. $file = $respond['file'] ?? '';
  660. $shortFile = $respond['shortFile'] ?? '';
  661. $fileUrl = Yii::$app->params['ghsHost'] . $file;
  662. util::success(['file' => $fileUrl, 'shortFile' => $shortFile]);
  663. }
  664. }