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