ProductController.php 30 KB

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