ProductController.php 25 KB

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