ProductController.php 28 KB

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