ProductController.php 28 KB

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