ProductController.php 27 KB

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