ProductController.php 30 KB

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