ProductController.php 30 KB

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