ProductController.php 25 KB

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