ProductController.php 29 KB

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