ProductController.php 23 KB

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