ItemController.php 50 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426
  1. <?php
  2. /**
  3. * 供货商端花材管理控制器
  4. * 主要用途:供货商(批发商)后台管理花材,例如:获取花材列表、修改或清除花材展示备注说明、隐藏/显示花材等。
  5. * 使用角色:供货商管理员。
  6. * 解决问题:在总店修改或清除花材备注说明时,不管分店是直营还是加盟,均同步更新花材备注。
  7. */
  8. namespace ghs\controllers;
  9. use bizGhs\merchant\classes\ShopClass;
  10. use biz\item\classes\PtItemClass;
  11. use biz\item\classes\UnitClass;
  12. use biz\shop\classes\ShopExtClass;
  13. use bizGhs\book\classes\BookItemClass;
  14. use bizGhs\custom\classes\CustomClass;
  15. use bizGhs\item\classes\ItemClass;
  16. use bizGhs\shop\classes\ShopAdminClass;
  17. use common\components\arrayUtil;
  18. use bizGhs\pictext\classes\PicTextGhsItemClass;
  19. use common\components\dict;
  20. use common\components\imgUtil;
  21. use common\components\miniUtil;
  22. use common\components\noticeUtil;
  23. use common\components\PosterUtil;
  24. use common\components\stringUtil;
  25. use common\components\util;
  26. use bizGhs\product\classes\ProductClass;
  27. use bizHd\wx\classes\WxOpenClass;
  28. use Yii;
  29. class ItemController extends BaseController
  30. {
  31. //花材已购客户列表 ssh 20250710
  32. public function actionHasLimitBuyCustomList()
  33. {
  34. $get = Yii::$app->request->get();
  35. $id = $get['id'] ?? '';
  36. $item = ItemClass::getById($id, true);
  37. if (empty($item)) {
  38. util::fail('没有找到花材');
  39. }
  40. if ($item->mainId != $this->mainId) {
  41. util::fail('不是你的花材');
  42. }
  43. $customList = ProductClass::getHasLimitBuyList($item);
  44. util::success(['customList' => $customList]);
  45. }
  46. //清空单个客户的已购 ssh 20250710
  47. public function actionClearOneLimitBuy()
  48. {
  49. $get = Yii::$app->request->get();
  50. $productId = $get['productId'] ?? '';
  51. $customId = $get['customId'] ?? 0;
  52. $item = ItemClass::getById($productId, true);
  53. if (empty($item)) {
  54. util::fail('没有找到花材');
  55. }
  56. if ($item->mainId != $this->mainId) {
  57. util::fail('不是你的花材');
  58. }
  59. $custom = CustomClass::getById($customId, true);
  60. if (empty($custom)) {
  61. util::fail('没有客户');
  62. }
  63. if ($custom->ownMainId != $this->mainId) {
  64. util::fail('不是你的客户');
  65. }
  66. ProductClass::baseClearLimitBuy($productId, $customId);
  67. util::complete('清除成功');
  68. }
  69. //取消花材全部客户的已限数,重新开始计算
  70. public function actionClearLimitBuy()
  71. {
  72. $get = Yii::$app->request->get();
  73. $id = $get['id'] ?? '';
  74. $item = ItemClass::getById($id, true);
  75. if (empty($item)) {
  76. util::fail('没有找到花材');
  77. }
  78. if ($item->mainId != $this->mainId) {
  79. util::fail('不是你的花材');
  80. }
  81. ProductClass::clearLimitBuyCache($id, false);
  82. util::complete('清除成功');
  83. }
  84. //取消限购:将 limitBuy 置为 0
  85. public function actionCancelLimitBuy()
  86. {
  87. $get = Yii::$app->request->get();
  88. $id = intval($get['id'] ?? 0);
  89. $item = ItemClass::getById($id, true);
  90. if (empty($item)) {
  91. util::fail('没有找到花材');
  92. }
  93. if ($item->mainId != $this->mainId) {
  94. util::fail('不是你的花材');
  95. }
  96. $oldLimitBuy = intval($item->limitBuy ?? 0);
  97. if ($oldLimitBuy <= 0) {
  98. util::complete('已取消限购');
  99. }
  100. ProductClass::clearLimitBuyByProductId($id, $oldLimitBuy);
  101. ProductClass::clearLimitBuyCache($id);
  102. util::complete('取消限购成功');
  103. }
  104. public function actionModifyWeight()
  105. {
  106. $shop = $this->shop;
  107. if ($shop->default == 0) {
  108. util::fail('请在总店(首店)修改');
  109. }
  110. $get = Yii::$app->request->get();
  111. $id = $get['id'] ?? '';
  112. $weight = $get['weight'] ?? 1;
  113. if ($weight <= 0) {
  114. util::fail('重量不能小于0');
  115. }
  116. $item = ItemClass::getById($id, true);
  117. if (empty($item)) {
  118. util::fail('没有找到花材');
  119. }
  120. if ($item->mainId != $this->mainId) {
  121. util::fail('不是你的花材');
  122. }
  123. $adminId = $this->adminId;
  124. $ptItemId = $item->itemId ?? 0;
  125. $respond = ShopAdminClass::changeWeightRight($adminId, $ptItemId);
  126. $hasRightChange = $respond['hasRightChange'];
  127. if ($hasRightChange == 0) {
  128. util::fail('不能修改');
  129. }
  130. $ptItem = PtItemClass::getById($ptItemId, true);
  131. if (empty($ptItem)) {
  132. util::fail('花材信息缺失');
  133. }
  134. $connection = Yii::$app->db;
  135. $transaction = $connection->beginTransaction();
  136. try {
  137. $ptItem->weight = $weight;
  138. $ptItem->save();
  139. ItemClass::updateByCondition(['itemId' => $ptItemId], ['weight' => $weight]);
  140. $transaction->commit();
  141. util::complete('修改成功');
  142. } catch (\Exception $e) {
  143. $transaction->rollBack();
  144. Yii::info("修改失败原因:" . $e->getMessage());
  145. util::fail('修改失败');
  146. }
  147. }
  148. public function actionModifyRatio()
  149. {
  150. $shop = $this->shop;
  151. if ($shop->default == 0) {
  152. util::fail('请在总店(首店)修改');
  153. }
  154. $get = Yii::$app->request->get();
  155. $id = $get['id'] ?? '';
  156. $ratio = $get['ratio'] ?? 20;
  157. if ($ratio < 1) {
  158. util::fail('单位比不能小于1');
  159. }
  160. $item = ItemClass::getById($id, true);
  161. if (empty($item)) {
  162. util::fail('没有找到花材');
  163. }
  164. if ($item->mainId != $this->mainId) {
  165. util::fail('不是你的花材');
  166. }
  167. $adminId = $this->adminId;
  168. $ptItemId = $item->itemId ?? 0;
  169. $respond = ShopAdminClass::changeWeightRight($adminId, $ptItemId);
  170. $hasRightChange = $respond['hasRightChange'];
  171. if ($hasRightChange == 0) {
  172. util::fail('不能修改');
  173. }
  174. $ptItem = PtItemClass::getById($ptItemId, true);
  175. if (empty($ptItem)) {
  176. util::fail('花材信息缺失');
  177. }
  178. $connection = Yii::$app->db;
  179. $transaction = $connection->beginTransaction();
  180. try {
  181. $ptItem->ratio = $ratio;
  182. $ptItem->save();
  183. ItemClass::updateByCondition(['itemId' => $ptItemId], ['ratio' => $ratio]);
  184. $transaction->commit();
  185. util::complete('修改成功');
  186. } catch (\Exception $e) {
  187. $transaction->rollBack();
  188. Yii::info("修改失败原因:" . $e->getMessage());
  189. util::fail('修改失败');
  190. }
  191. }
  192. public function actionModifyUnit()
  193. {
  194. $shop = $this->shop;
  195. if ($shop->default == 0) {
  196. util::fail('请在总店(首店)修改');
  197. }
  198. $get = Yii::$app->request->get();
  199. $id = $get['id'] ?? '';
  200. $unitId = $get['unitId'] ?? 1;
  201. $unit = UnitClass::getById($unitId, true);
  202. $type = $get['type'] ?? 'big';
  203. if (empty($unit)) {
  204. util::fail('没有找到单位');
  205. }
  206. $unitName = $unit->name;
  207. $item = ItemClass::getById($id, true);
  208. if (empty($item)) {
  209. util::fail('没有找到花材');
  210. }
  211. if ($item->mainId != $this->mainId) {
  212. util::fail('不是你的花材');
  213. }
  214. $adminId = $this->adminId;
  215. $ptItemId = $item->itemId ?? 0;
  216. $respond = ShopAdminClass::changeWeightRight($adminId, $ptItemId);
  217. $hasRightChange = $respond['hasRightChange'];
  218. if ($hasRightChange == 0) {
  219. util::fail('不能修改');
  220. }
  221. $ptItem = PtItemClass::getById($ptItemId, true);
  222. if (empty($ptItem)) {
  223. util::fail('花材信息缺失');
  224. }
  225. $connection = Yii::$app->db;
  226. $transaction = $connection->beginTransaction();
  227. try {
  228. if ($type == 'big') {
  229. $ptItem->bigUnit = $unitName;
  230. $ptItem->bigUnitId = $unitId;
  231. $ptItem->save();
  232. ItemClass::updateByCondition(['itemId' => $ptItemId], ['bigUnit' => $unitName, 'bigUnitId' => $unitId]);
  233. } else {
  234. $ptItem->smallUnit = $unitName;
  235. $ptItem->smallUnitId = $unitId;
  236. $ptItem->save();
  237. ItemClass::updateByCondition(['itemId' => $ptItemId], ['smallUnit' => $unitName, 'smallUnitId' => $unitId]);
  238. }
  239. $transaction->commit();
  240. util::complete('修改成功');
  241. } catch (\Exception $e) {
  242. $transaction->rollBack();
  243. Yii::info("修改失败原因:" . $e->getMessage());
  244. util::fail('修改失败');
  245. }
  246. }
  247. //挪到处理区 ssh 20250418
  248. public function actionMoveToLosing()
  249. {
  250. //避免重复提交
  251. util::checkRepeatCommit($this->adminId, 4);
  252. $get = Yii::$app->request->get();
  253. $id = $get['id'] ?? '';
  254. $num = $get['num'] ?? 0;
  255. $item = ItemClass::getById($id, true);
  256. if (empty($item)) {
  257. util::fail('没有找到花材');
  258. }
  259. if ($item->mainId != $this->mainId) {
  260. util::fail('不是你的花材');
  261. }
  262. if ($num <= 0) {
  263. util::fail('请输入数量');
  264. }
  265. $remark = '挪到处理区';
  266. $staff = $this->shopAdmin;
  267. $staffName = $staff->name ?? '';
  268. $staffId = $staff->id;
  269. $adminId = $this->adminId;
  270. $params = [
  271. 'staffId' => $staffId,
  272. 'staffName' => $staffName,
  273. 'adminId' => $adminId,
  274. 'remark' => $remark,
  275. ];
  276. $connection = Yii::$app->db;
  277. $transaction = $connection->beginTransaction();
  278. try {
  279. $shop = $this->shop;
  280. ItemClass::moveLose($item, $num, $shop, $params);
  281. $transaction->commit();
  282. util::complete('挪动成功');
  283. } catch (\Exception $e) {
  284. $transaction->rollBack();
  285. Yii::info("挪动失败原因:" . $e->getMessage());
  286. util::fail('挪动失败');
  287. }
  288. }
  289. //设为处理区用的花材 ssh 20250418
  290. public function actionSetLosing()
  291. {
  292. $get = Yii::$app->request->get();
  293. $id = $get['id'] ?? '';
  294. $item = ItemClass::getById($id, true);
  295. if (empty($item)) {
  296. util::fail('没有找到花材');
  297. }
  298. if ($item->mainId != $this->mainId) {
  299. util::fail('不是你的花材');
  300. }
  301. $shopAdmin = $this->shopAdmin;
  302. if ($shopAdmin->founder == 1) {
  303. util::fail('请用超管手机操作');
  304. }
  305. $shopId = $this->shopId;
  306. $ext = ShopExtClass::getByCondition(['shopId' => $shopId], true);
  307. if (empty($ext)) {
  308. util::fail('设置失败,没有找到门店信息');
  309. }
  310. $ext->losingItem = $id;
  311. $ext->save();
  312. util::complete('设置成功');
  313. }
  314. //增加和减少半扎 ssh 20250417
  315. public function actionChangeHalf()
  316. {
  317. util::fail('此功能已停用');
  318. $post = Yii::$app->request->post();
  319. $productId = $post['productId'] ?? '';
  320. $add = $post['add'] ?? 0;
  321. $remark = $post['remark'] ?? '';
  322. $product = ProductClass::getLockById($productId);
  323. if (empty($product)) {
  324. util::fail('没有找到花材');
  325. }
  326. if ($product->mainId != $this->mainId) {
  327. util::fail('不是你的花材');
  328. }
  329. if ($product->ratioType == 1) {
  330. util::fail('若干扎的花材不能减半份');
  331. }
  332. //避免重复提交
  333. util::checkRepeatCommit($this->adminId, 4);
  334. $connection = Yii::$app->db;
  335. $transaction = $connection->beginTransaction();
  336. try {
  337. $shop = $this->shop;
  338. $staff = $this->shopAdmin;
  339. $staffName = $staff->name ?? '';
  340. $staffId = $staff->id;
  341. $adminId = $this->adminId;
  342. $params = [
  343. 'staffId' => $staffId,
  344. 'staffName' => $staffName,
  345. 'adminId' => $adminId,
  346. 'remark' => $remark,
  347. ];
  348. ItemClass::modifyHalf($shop, $product, $params, $add);
  349. $product = ProductClass::getLockById($productId);
  350. $stock = $product->stock;
  351. $stock = floatval($stock);
  352. $transaction->commit();
  353. util::success(['stock' => $stock]);
  354. } catch (\Exception $e) {
  355. $transaction->rollBack();
  356. Yii::info("加减半份失败原因:" . $e->getMessage());
  357. util::fail('加减半份失败');
  358. }
  359. }
  360. //修改一个花材的采购人 ssh 20240719
  361. public function actionModifyCgStaff()
  362. {
  363. $get = Yii::$app->request->get();
  364. $id = $get['id'] ?? 0;
  365. $staffId = $get['staffId'] ?? 0;
  366. $item = ItemClass::getById($id, true);
  367. if (empty($item)) {
  368. util::fail('没有找到花材');
  369. }
  370. if ($item->mainId != $this->mainId) {
  371. util::fail('不是你的花材');
  372. }
  373. $staff = ShopAdminClass::getById($staffId, true);
  374. if (empty($staff) || $staff->mainId != $this->mainId) {
  375. util::fail('不是你的员工');
  376. }
  377. $staffName = $staff->name ?? '';
  378. $item->cgStaffId = $staffId;
  379. $item->cgStaffName = $staffName;
  380. $item->save();
  381. $shop = $this->shop;
  382. $bookSn = $shop->bookSn ?? 0;
  383. if (!empty($bookSn)) {
  384. BookItemClass::updateByCondition(['bookSn' => $bookSn, 'itemId' => $id], ['cgStaffId' => $staffId, 'cgStaffName' => $staffName]);
  385. }
  386. util::complete('修改成功');
  387. }
  388. //获取花材最新信息,库存 ssh 20240318
  389. public function actionGetNewInfo()
  390. {
  391. $post = Yii::$app->request->post();
  392. $str = $post['data'] ?? '';
  393. if (empty($str)) {
  394. util::fail('请传花材信息');
  395. }
  396. $arr = json_decode($str, true);
  397. if (empty($arr)) {
  398. util::fail('请传花材信息哈');
  399. }
  400. $ids = array_column($arr, 'productId');
  401. $list = ItemClass::getAllByCondition(['id' => ['in', $ids]], null, 'id,name,stock,mainId', 'id', true);
  402. if (!empty($list)) {
  403. foreach ($list as $item) {
  404. if ($item->mainId != $this->mainId) {
  405. util::fail('不是你的花材');
  406. }
  407. }
  408. }
  409. util::success(['list' => $list]);
  410. }
  411. //列出所有花材 ssh 20240222
  412. public function actionGetItemList()
  413. {
  414. $get = Yii::$app->request->get();
  415. $search = $get['search'] ?? '';
  416. $requestType = $get['requestType'] ?? 'kd';
  417. $classId = $get['classId'] ?? 0;
  418. $lookStock = $get['lookStock'] ?? 0;
  419. $onStock = $get['onStock'] ?? 0;
  420. $where['mainId'] = $this->mainId;
  421. if ($requestType == 'kd') {
  422. $where['delStatus'] = 0;
  423. $where['status'] = 1;
  424. } elseif ($requestType == 'itemList') {
  425. $where['delStatus'] = 0;
  426. if ($lookStock == 1) {
  427. $where['stock>'] = 0;
  428. }
  429. if ($lookStock == 2) {
  430. $where['stock'] = 0;
  431. }
  432. if($onStock == 1){
  433. $where['onStock>'] = 0;
  434. }
  435. unset($where['status']);
  436. } elseif ($requestType == 'changePrice') {
  437. $where['delStatus'] = 0;
  438. $where['stock>'] = 0;
  439. } elseif ($requestType == 'hasStockList') {
  440. $where['delStatus'] = 0;
  441. $where['stock>'] = 0;
  442. } elseif ($requestType == 'book') {
  443. $where['delStatus'] = 0;
  444. unset($where['status']);
  445. } elseif ($requestType == 'outList') {
  446. $where['delStatus'] = 0;
  447. $where['status'] = 2;
  448. $where['removeStatus'] = 0;
  449. } elseif ($requestType == 'stopList') {
  450. $where['delStatus'] = 1;
  451. unset($where['status']);
  452. $where['removeStatus'] = 0;
  453. } elseif ($requestType == 'removeList') {
  454. $where['delStatus'] = 1;
  455. unset($where['status']);
  456. $where['removeStatus'] = 1;
  457. } elseif ($requestType == 'cg') {
  458. $where['delStatus'] = 0;
  459. unset($where['status']);
  460. } elseif ($requestType == 'changeStock') {
  461. $where['delStatus'] = 0;
  462. unset($where['status']);
  463. } elseif ($requestType == 'check') {
  464. $where['delStatus'] = 0;
  465. unset($where['status']);
  466. } elseif ($requestType == 'stockOut') {
  467. $where['delStatus'] = 0;
  468. $where['status'] = 1;
  469. } elseif ($requestType == 'break') {
  470. $where['delStatus'] = 0;
  471. $where['status'] = 1;
  472. } elseif ($requestType == 'part') {
  473. $where['delStatus'] = 0;
  474. $where['status'] = 1;
  475. } elseif ($requestType == 'warning') {
  476. $where['delStatus'] = 0;
  477. unset($where['status']);
  478. if ($lookStock == 1) {
  479. $where['stock>'] = 0;
  480. }
  481. if ($lookStock == 2) {
  482. $where['stock'] = 0;
  483. }
  484. if ($onStock == 1) {
  485. $where['onStock>'] = 0;
  486. }
  487. } else {
  488. util::fail('没有定义的请求方式');
  489. }
  490. if (!empty($search)) {
  491. if (stringUtil::isLetter($search)) {
  492. $search = strtolower($search);
  493. $where['py'] = ['like', $search];
  494. } else {
  495. $where['name'] = ['like', $search];
  496. }
  497. } else {
  498. if (!empty($classId)) {
  499. if ($classId == -1) {
  500. $where['discountPrice>'] = 0;
  501. } elseif ($classId == -2) {
  502. $where['reachNum>'] = 0;
  503. } elseif ($classId == -3) {
  504. $where['presell'] = 1;
  505. } else {
  506. $where['classId'] = $classId;
  507. }
  508. }
  509. }
  510. $customId = $get['customId'] ?? 0;
  511. $custom = CustomClass::getById($customId, true);
  512. if (!empty($custom)) {
  513. if ($custom->ownMainId != $this->mainId) {
  514. util::fail('不是你的客户');
  515. }
  516. }
  517. $level = $custom->level ?? 1;
  518. //只查我负责的花材
  519. $globalCgMyCharge = $get['globalCgMyCharge'] ?? 0;
  520. $needCgList = [];
  521. $shop = $this->shop;
  522. $bookSn = $shop->bookSn ?? 0;
  523. $staff = $this->shopAdmin;
  524. $staffId = $staff->id ?? 0;
  525. if (!empty($bookSn)) {
  526. $biList = BookItemClass::getAllByCondition(['bookSn' => $bookSn, 'cgStaffId' => $staffId], null, '*', null, true);
  527. if (!empty($biList)) {
  528. $myIds = [];
  529. foreach ($biList as $biInfo) {
  530. $biProductId = $biInfo->itemId ?? 0;
  531. if ($biInfo->needCgNum > 0) {
  532. $myIds[] = $biProductId;
  533. $needCgList[$biProductId] = $biInfo->needCgNum;
  534. }
  535. }
  536. if ($globalCgMyCharge == 1) {
  537. if (!empty($myIds)) {
  538. $where['id'] = ['in', $myIds];
  539. } else {
  540. $where['id'] = ['in', [0]];
  541. }
  542. }
  543. } else {
  544. if ($globalCgMyCharge == 1) {
  545. $where['id'] = ['in', [0]];
  546. }
  547. }
  548. }
  549. $field = '*';
  550. if ($requestType == 'warning') {
  551. $result = ProductClass::warningList($where, ['inTurn' => SORT_DESC, 'actualSold' => SORT_DESC]);
  552. } else {
  553. $result = ProductClass::getList($field, $where, ['inTurn' => SORT_DESC, 'actualSold' => SORT_DESC]);
  554. }
  555. $list = $result['list'] ?? [];
  556. if ($requestType == 'hasStockList') {
  557. util::fail('无效方式');
  558. } elseif ($requestType == 'changePrice') {
  559. $list = ProductClass::changePriceGroup($list, $level);
  560. } elseif ($requestType == 'changeStock') {
  561. $list = ProductClass::changeStockGroup($list, $level);
  562. } elseif ($requestType == 'kd') {
  563. $list = ProductClass::kdItemGroup($list, $level, $custom);
  564. } elseif ($requestType == 'book') {
  565. $list = ProductClass::bookItemGroup($list, $level);
  566. } elseif ($requestType == 'itemList') {
  567. $list = ProductClass::itemListGroup($list, $level);
  568. } elseif ($requestType == 'outList') {
  569. $list = ProductClass::simpleGroup($list, $level);
  570. } elseif ($requestType == 'stopList') {
  571. $list = ProductClass::simpleGroup($list, $level);
  572. } elseif ($requestType == 'removeList') {
  573. $list = ProductClass::simpleGroup($list, $level);
  574. } elseif ($requestType == 'check') {
  575. $list = ProductClass::checkItemGroup($list, $level);
  576. } elseif ($requestType == 'break') {
  577. $list = ProductClass::breakItemGroup($list, $level);
  578. } elseif ($requestType == 'part') {
  579. $list = ProductClass::partItemGroup($list, $level);
  580. } elseif ($requestType == 'stockOut') {
  581. $list = ProductClass::stockOutGroup($list, $level);
  582. } elseif ($requestType == 'cg') {
  583. $list = ProductClass::cgItemGroup($list, $level);
  584. } elseif ($requestType == 'warning') {
  585. $list = ProductClass::itemListGroup($list, $level);
  586. } else {
  587. util::fail('没有数据');
  588. }
  589. if (!empty($needCgList)) {
  590. //采购人采自己花材需要知道要采多少
  591. if (!empty($list)) {
  592. foreach ($list as $key => $val) {
  593. $productId = $val['id'] ?? 0;
  594. if (isset($needCgList[$productId])) {
  595. $needCgNum = $needCgList[$productId];
  596. $list[$key]['needCgNum'] = $needCgNum;
  597. }
  598. }
  599. }
  600. }
  601. if (!empty($list) && $classId == -1) {
  602. //限购的排在最前面,多处同步修改limit_ahead
  603. $list = arrayUtil::arraySort($list, 'limitBuy');
  604. }
  605. $result['list'] = $list;
  606. util::success($result);
  607. }
  608. //花材申请平台认证 ssh 20231125
  609. public function actionApplyAuth()
  610. {
  611. $get = Yii::$app->request->get();
  612. $id = $get['id'] ?? 0;
  613. $info = ItemClass::getById($id, true);
  614. if (empty($info)) {
  615. util::fail('没有找到花材');
  616. }
  617. if ($info->mainId != $this->mainId) {
  618. util::fail('不是你的花材哦');
  619. }
  620. $shop = $this->shop;
  621. $sjName = $shop->merchantName ?? '';
  622. $shopName = $shop->shopName ?? '';
  623. $name = $shopName == '首店' ? $sjName : $sjName . ' ' . $shopName;
  624. $ptItemId = $info->itemId ?? 0;
  625. $ptItem = PtItemClass::getById($ptItemId, true);
  626. if (empty($ptItem)) {
  627. util::fail('没有找到平台花材');
  628. }
  629. $ptItemName = $ptItem->name ?? '';
  630. noticeUtil::push($name . " 申请将【{$ptItemName}/{$ptItemId}】进行认证", '15280215347');
  631. util::complete();
  632. }
  633. //简单花材的列表
  634. public function actionSimpleList()
  635. {
  636. $get = Yii::$app->request->get();
  637. $name = $get['name'] ?? '';
  638. $num = $get['num'] ?? 0;
  639. $where = ['mainId' => $this->mainId, 'delStatus' => 0];
  640. if (!empty($name)) {
  641. if (stringUtil::isLetter($name)) {
  642. $where['py'] = ['like', $name];
  643. } else {
  644. $where['name'] = ['like', $name];
  645. }
  646. }
  647. $respond = ItemClass::getSimpleList($where, $num);
  648. util::success($respond);
  649. }
  650. //可借库存的花材列表 ssh 20240720
  651. public function actionGetLoanList()
  652. {
  653. $get = Yii::$app->request->get();
  654. $name = $get['name'] ?? '';
  655. $where = ['mainId' => $this->mainId, 'delStatus' => 0];
  656. if (!empty($name)) {
  657. if (stringUtil::isLetter($name)) {
  658. $where['py'] = ['like', $name];
  659. } else {
  660. $where['name'] = ['like', $name];
  661. }
  662. }
  663. $shop = $this->shop;
  664. $respond = ItemClass::getLoanList($where, $shop);
  665. util::success($respond);
  666. }
  667. //全部花材取消隐藏 ssh 20260201
  668. public function actionCancelAllItemHide()
  669. {
  670. $mainId = $this->mainId;
  671. ItemClass::updateByCondition(['mainId' => $mainId, 'frontHide' => 1], ['frontHide' => 0, 'frontUse' => 0]);
  672. util::complete('操作成功');
  673. }
  674. //分类下的花材取消隐藏 sssh 20260201
  675. public function actionCancelClassItemHide()
  676. {
  677. $get = Yii::$app->request->get();
  678. $classId = $get['classId'] ?? 0;
  679. $mainId = $this->mainId;
  680. ItemClass::updateByCondition(['mainId' => $mainId, 'classId' => $classId, 'frontHide' => 1], ['frontHide' => 0, 'frontUse' => 0]);
  681. util::complete('操作成功');
  682. }
  683. //单个花材的显示和隐藏 ssh 20260201
  684. public function actionChangeFrontHide()
  685. {
  686. $get = Yii::$app->request->get();
  687. $id = $get['id'] ?? 0;
  688. $status = $get['status'] ?? '';
  689. if (!is_numeric($status)) {
  690. util::fail('请选择方式');
  691. }
  692. $info = ItemClass::getById($id, true);
  693. if (empty($info)) {
  694. util::fail('没有找到花材');
  695. }
  696. if ($info->mainId != $this->mainId) {
  697. util::fail('无法操作');
  698. }
  699. $info->frontHide = $status;
  700. $info->frontUse = $status;
  701. $info->save();
  702. util::complete();
  703. }
  704. /**
  705. * 修改花材展示备注说明 (供货商端)
  706. * 职责:更新指定供货商花材的备注内容。如果当前店铺是总店,则需将修改同步到该商户下的所有分店(不论直营还是加盟店)。
  707. * 入参:id (花材ID,来自 GET 传参), itemRemark (备注内容,来自 GET 传参)
  708. * 返回:保存成功提示(JSON 格式)
  709. * 副作用:会更新该供货商下所有分店对应花材的备注说明。
  710. */
  711. public function actionUpdateItemRemark()
  712. {
  713. $get = Yii::$app->request->get();
  714. $id = $get['id'] ?? 0;
  715. $itemRemark = trim($get['itemRemark'] ?? '');
  716. if (empty($itemRemark)) {
  717. util::fail('请填写备注');
  718. }
  719. if (mb_strlen($itemRemark) > 200) {
  720. util::fail('备注不能超过200字');
  721. }
  722. $info = ItemClass::getById($id, true);
  723. if (empty($info)) {
  724. util::fail('没有找到花材');
  725. }
  726. if ($info->mainId != $this->mainId) {
  727. util::fail('无法操作');
  728. }
  729. $info->itemRemark = $itemRemark;
  730. $info->save();
  731. // 复杂分支:若当前店铺是总店(default = 1),不管分店是直营还是加盟,都需要将修改后的花材备注同步至旗下所有分店,保证全渠道花材备注的一致性
  732. $shop = $this->shop;
  733. if (isset($shop->default) && $shop->default == 1) {
  734. $sjId = $shop->sjId ?? 0;
  735. $ptItemId = $info->itemId ?? 0;
  736. $chainShopList = ShopClass::getAllByCondition(['sjId' => $sjId], null, '*', null, true);
  737. foreach ($chainShopList as $chainShop) {
  738. $chainShopId = $chainShop->id ?? 0;
  739. if ($chainShopId == $shop->id) {
  740. continue;
  741. }
  742. $chainMainId = $chainShop->mainId ?? 0;
  743. $chainProduct = ItemClass::getByCondition(['mainId' => $chainMainId, 'itemId' => $ptItemId], true);
  744. if (empty($chainProduct)) {
  745. continue;
  746. }
  747. $chainProduct->itemRemark = $itemRemark;
  748. $chainProduct->save();
  749. }
  750. }
  751. util::complete('保存成功');
  752. }
  753. /**
  754. * 清除花材展示备注说明 (供货商端)
  755. * 职责:清空指定供货商花材的备注内容。如果当前店铺是总店,则需同步清除商户下的所有分店(不论直营还是加盟店)对应花材的备注内容。
  756. * 入参:id (花材ID,来自 GET 传参)
  757. * 返回:清除成功提示(JSON 格式)
  758. * 副作用:会清空该供货商下所有分店对应花材的备注说明。
  759. */
  760. public function actionClearItemRemark()
  761. {
  762. $get = Yii::$app->request->get();
  763. $id = $get['id'] ?? 0;
  764. $info = ItemClass::getById($id, true);
  765. if (empty($info)) {
  766. util::fail('没有找到花材');
  767. }
  768. if ($info->mainId != $this->mainId) {
  769. util::fail('无法操作');
  770. }
  771. $info->itemRemark = '';
  772. $info->save();
  773. // 复杂分支:若当前店铺是总店(default = 1),不管分店是直营还是加盟,都需要同步清空其花材备注说明,确保全渠道数据同步与统一
  774. $shop = $this->shop;
  775. if (isset($shop->default) && $shop->default == 1) {
  776. $sjId = $shop->sjId ?? 0;
  777. $ptItemId = $info->itemId ?? 0;
  778. $chainShopList = ShopClass::getAllByCondition(['sjId' => $sjId], null, '*', null, true);
  779. foreach ($chainShopList as $chainShop) {
  780. $chainShopId = $chainShop->id ?? 0;
  781. if ($chainShopId == $shop->id) {
  782. continue;
  783. }
  784. $chainMainId = $chainShop->mainId ?? 0;
  785. $chainProduct = ItemClass::getByCondition(['mainId' => $chainMainId, 'itemId' => $ptItemId], true);
  786. if (empty($chainProduct)) {
  787. continue;
  788. }
  789. $chainProduct->itemRemark = '';
  790. $chainProduct->save();
  791. }
  792. }
  793. util::complete('清除成功');
  794. }
  795. //批量隐藏和显示花材 ssh 20260131
  796. public function actionBatchChangeFrontHide()
  797. {
  798. $post = Yii::$app->request->post();
  799. $ids = $post['ids'] ?? 0;
  800. $ids = trim($ids);
  801. if (empty($ids)) {
  802. util::fail('请选花材');
  803. }
  804. $frontHide = $post['frontHide'] ?? 0;
  805. $arr = json_decode($ids, true);
  806. if (empty($arr)) {
  807. util::fail('请选花材呢');
  808. }
  809. $list = ItemClass::getAllByCondition(['id' => ['in', $arr]], null, 'id,frontHide,mainId', null, true);
  810. if (!empty($list)) {
  811. foreach ($list as $key => $currentItem) {
  812. if ($currentItem->mainId == $this->mainId) {
  813. $currentItem->frontHide = $frontHide;
  814. $currentItem->frontUse = $frontHide;
  815. $currentItem->save();
  816. }
  817. }
  818. }
  819. util::complete('操作成功');
  820. }
  821. //检测是否要刷新
  822. public function actionCheckRefresh()
  823. {
  824. $mainId = $this->mainId;
  825. $staffId = $this->shopAdminId;
  826. $respond = Yii::$app->redis->executeCommand('GET', ['ghs_cashier_' . $mainId . '_' . $staffId . '_may_refresh']);
  827. if ($respond == 'yes') {
  828. util::success(['remind' => 1]);
  829. }
  830. util::complete();
  831. }
  832. //批量恢复花材 ssh 20230206
  833. public function actionBatchRecover()
  834. {
  835. $post = Yii::$app->request->post();
  836. $string = $post['ids'] ?? '';
  837. $ids = json_decode($string, true);
  838. $ids = array_unique(array_filter($ids));
  839. if (empty($ids)) {
  840. util::fail('请选择花材6');
  841. }
  842. $infoList = ItemClass::getAllByCondition(['id' => ['in', $ids]], null, 'id,name,mainId,status,delStatus,removeStatus', null, true);
  843. if (empty($infoList)) {
  844. util::fail('请选择花材哦8');
  845. }
  846. foreach ($infoList as $info) {
  847. if ($info->mainId != $this->mainId) {
  848. util::fail('请选择自己的花材');
  849. }
  850. $info->removeStatus = 0;
  851. $info->save();
  852. }
  853. util::complete('操作成功');
  854. }
  855. //批量删除花材 ssh 202302026
  856. public function actionBatchRemove()
  857. {
  858. $post = Yii::$app->request->post();
  859. $string = $post['ids'] ?? '';
  860. $ids = json_decode($string, true);
  861. $ids = array_unique(array_filter($ids));
  862. if (empty($ids)) {
  863. util::fail('请选择花材7');
  864. }
  865. $infoList = ItemClass::getAllByCondition(['id' => ['in', $ids]], null, 'id,name,mainId,status,delStatus,removeStatus', null, true);
  866. if (empty($infoList)) {
  867. util::fail('请选择花材哦10');
  868. }
  869. foreach ($infoList as $info) {
  870. if ($info->mainId != $this->mainId) {
  871. util::fail('请选择自己的花材');
  872. }
  873. $name = $info->name ?? '';
  874. if ($info->delStatus != 1) {
  875. util::fail($name . ' 停用了才能删除');
  876. }
  877. $info->removeStatus = 1;
  878. $info->save();
  879. }
  880. util::complete('操作成功');
  881. }
  882. //批量启用花材 ssh 20230206
  883. public function actionBatchEnable()
  884. {
  885. $post = Yii::$app->request->post();
  886. $string = $post['ids'] ?? '';
  887. $ids = json_decode($string, true);
  888. $ids = array_unique(array_filter($ids));
  889. if (empty($ids)) {
  890. util::fail('请选择花材11');
  891. }
  892. $infoList = ItemClass::getAllByCondition(['id' => ['in', $ids]], null, 'id,name,mainId,status,delStatus,removeStatus', null, true);
  893. if (empty($infoList)) {
  894. util::fail('请选择花材哦12');
  895. }
  896. foreach ($infoList as $info) {
  897. if ($info->mainId != $this->mainId) {
  898. util::fail('请选择自己的花材');
  899. }
  900. $info->delStatus = 0;
  901. $info->save();
  902. }
  903. util::complete('操作成功');
  904. }
  905. //批量停用花材 20230206
  906. public function actionBatchStop()
  907. {
  908. $post = Yii::$app->request->post();
  909. $string = $post['ids'] ?? '';
  910. $ids = json_decode($string, true);
  911. $ids = array_unique(array_filter($ids));
  912. if (empty($ids)) {
  913. util::fail('请选择花材13');
  914. }
  915. $infoList = ItemClass::getAllByCondition(['id' => ['in', $ids]], null, 'id,name,mainId,status,delStatus,removeStatus', null, true);
  916. if (empty($infoList)) {
  917. util::fail('请选择花材哦14');
  918. }
  919. foreach ($infoList as $info) {
  920. if ($info->mainId != $this->mainId) {
  921. util::fail('请选择自己的花材');
  922. }
  923. $name = $info->name ?? '';
  924. if ($info->status != 2) {
  925. util::fail($name . ' 下载了才能停用');
  926. }
  927. $info->delStatus = 1;
  928. $info->save();
  929. }
  930. util::complete('操作成功');
  931. }
  932. //获取给散客下单的花材海报 ssh 20220111
  933. public function actionGetSkPoster()
  934. {
  935. $get = Yii::$app->request->get();
  936. $id = $get['id'] ?? 0;
  937. $item = ItemClass::getById($id, true);
  938. if (empty($item) || $item->mainId != $this->mainId) {
  939. util::fail('获取失败');
  940. }
  941. $cover = $item->cover ?? '';
  942. if (empty($cover)) {
  943. util::fail('获取失败');
  944. }
  945. $cover = imgUtil::normalizeOssObjectPath($cover);
  946. $merchant = WxOpenClass::getMallWxInfo();
  947. $page = 'pages/item/detail';
  948. $ptStyle = dict::getDict('ptStyle', 'mall');
  949. $shop = $this->shop;
  950. $lsShopId = $shop->lsShopId ?? 0;
  951. $scene = 'id=' . $id . '&a=' . $lsShopId;
  952. $envVersion = miniUtil::normalizeMiniEnvVersion(Yii::$app->request->get('env_version', 'release'));
  953. $miniCode = miniUtil::generateUnlimitedMiniCode($merchant, $page, $scene, $ptStyle, $envVersion);
  954. Yii::$app->params['ptStyle'] = dict::getDict('ptStyle', 'hd');
  955. $prefix = imgUtil::getPrefix();
  956. $price = $item->skPrice ?? 0;
  957. if ($item->discountPrice > 0) {
  958. $skMore = $item->skMore ?? 0;
  959. $price = bcadd($item->discountPrice, $skMore, 2);
  960. }
  961. $staff = $this->shopAdmin;
  962. $staffName = $staff->name ?? '';
  963. $url = PosterUtil::buildMallItemPosterUrl($prefix, PosterUtil::withShopAndRemark([
  964. 'cover' => $cover,
  965. 'miniCode' => $miniCode,
  966. 'priceText' => '¥' . floatval($price),
  967. 'name' => $item->name ?? '',
  968. 'staffText' => $staffName . ' 为您推荐',
  969. 'mainId' => $this->mainId,
  970. ], $this->shop, $this->sj ?? null, $item));
  971. util::success(['imgUrl' => $url]);
  972. }
  973. //下载商品码,用于花市卖花 ssh 20240823
  974. public function actionDownMiniCode()
  975. {
  976. $get = Yii::$app->request->get();
  977. $id = $get['id'] ?? 0;
  978. $item = ItemClass::getById($id, true);
  979. if (empty($item)) {
  980. util::fail('没有找到花材');
  981. }
  982. if ($item->mainId != $this->mainId) {
  983. util::fail('不是你的花材');
  984. }
  985. $merchant = WxOpenClass::getWxInfo();
  986. $page = 'admin/ghsProduct/detail';
  987. $ptStyle = dict::getDict('ptStyle', 'hd');
  988. //小程序码,scene不能超过32个字条
  989. $scene = "id=" . $id . '&sId=' . $this->shopId;
  990. $miniCode = miniUtil::generateUnlimitedMiniCode($merchant, $page, $scene, $ptStyle);
  991. $miniCode = $miniCode . '?x-oss-process=image/resize,m_fill,h_450,w_450';
  992. $miniCodeBase64 = stringUtil::ossBase64($miniCode);
  993. $prefix = imgUtil::getPrefix();
  994. $url = $prefix . 'poster/mini_bg.jpg?x-oss-process=image';
  995. //小程序码
  996. $url .= '/watermark,image_' . $miniCodeBase64 . ',g_north,x_0,y_25';
  997. $name = $item->name ?? '';
  998. $nameBase64 = stringUtil::ossBase64($name);
  999. //标题
  1000. $url .= '/watermark,text_' . $nameBase64 . ',g_south,x_0,y_35';
  1001. $file = fopen($url, "rb");
  1002. Header("Content-type: application/octet-stream ");
  1003. Header("Accept-Ranges: bytes ");
  1004. Header("Content-Disposition: attachment;filename={$name}.jpg");
  1005. $contents = "";
  1006. while (!feof($file)) {
  1007. $contents .= fread($file, 8192);
  1008. }
  1009. echo $contents;
  1010. fclose($file);
  1011. }
  1012. //获取给花店下单的花材海报 ssh 20220111
  1013. public function actionGetHdPoster()
  1014. {
  1015. $get = Yii::$app->request->get();
  1016. $id = $get['id'] ?? 0;
  1017. $item = ItemClass::getById($id, true);
  1018. if (empty($item) || $item->mainId != $this->mainId) {
  1019. util::fail('获取失败');
  1020. }
  1021. $cover = $item->cover ?? '';
  1022. if (empty($cover)) {
  1023. util::fail('获取失败');
  1024. }
  1025. $cover = imgUtil::normalizeOssObjectPath($cover);
  1026. $merchant = WxOpenClass::getWxInfo();
  1027. $page = 'admin/ghsProduct/detail';
  1028. $ptStyle = dict::getDict('ptStyle', 'hd');
  1029. $scene = 'id=' . $id . '&sId=' . $this->shopId;
  1030. $envVersion = miniUtil::normalizeMiniEnvVersion(Yii::$app->request->get('env_version', 'release'));
  1031. $miniCode = miniUtil::generateUnlimitedMiniCode($merchant, $page, $scene, $ptStyle, $envVersion);
  1032. Yii::$app->params['ptStyle'] = dict::getDict('ptStyle', 'ghs');
  1033. $prefix = imgUtil::getPrefix();
  1034. $price = $item->price ?? 0;
  1035. if ($item->discountPrice > 0) {
  1036. $price = $item->discountPrice;
  1037. }
  1038. $staff = $this->shopAdmin;
  1039. $staffName = $staff->name ?? '';
  1040. $url = PosterUtil::buildGhsHdItemPosterUrl($prefix, PosterUtil::withShopAndRemark([
  1041. 'cover' => $cover,
  1042. 'miniCode' => $miniCode,
  1043. 'priceText' => '¥' . floatval($price),
  1044. 'name' => $item->name ?? '',
  1045. 'staffText' => $staffName . ' 为您推荐',
  1046. 'mainId' => $this->mainId,
  1047. ], $this->shop, $this->sj ?? null, $item));
  1048. util::success(['imgUrl' => $url]);
  1049. }
  1050. //是否有C级价格大于B级的 ssh 20221204
  1051. public function actionGetErrorPrice()
  1052. {
  1053. $shop = $this->shop;
  1054. $ret = ItemClass::errorPrice($shop);
  1055. $list = $ret['data'] ?? [];
  1056. $map = $ret['map'] ?? [];
  1057. util::success(['list' => $list, 'map' => $map]);
  1058. }
  1059. //列出所有花材,包括特价花材列表 ssh 20220315
  1060. public function actionShowList()
  1061. {
  1062. $get = Yii::$app->request->get();
  1063. $customId = $get['customId'] ?? 0;
  1064. $custom = CustomClass::getById($customId, true);
  1065. $where['mainId'] = $this->mainId;
  1066. $where['delStatus'] = 0;
  1067. $where['status'] = 1;
  1068. $list = ItemClass::getShowList($where, $custom);
  1069. $mainId = $this->mainId;
  1070. $get = Yii::$app->request->get();
  1071. $isCashier = $get['isCashier'] ?? 0;
  1072. if ($isCashier == 1) {
  1073. //去掉收银台提示价格更新
  1074. $staffId = $this->shopAdminId;
  1075. Yii::$app->redis->executeCommand('DEL', ['ghs_cashier_' . $mainId . '_' . $staffId . '_may_refresh']);
  1076. }
  1077. $productList = [];
  1078. if (!empty($list)) {
  1079. foreach ($list as $key => $item) {
  1080. if (!empty($item)) {
  1081. $productList = array_merge($productList, $item);
  1082. }
  1083. }
  1084. }
  1085. util::success(['list' => $list, 'productList' => $productList]);
  1086. }
  1087. public function actionAdd()
  1088. {
  1089. util::fail('开发中');
  1090. }
  1091. //批量添加花材
  1092. public function actionBatchAdd()
  1093. {
  1094. $shopAdmin = $this->shopAdmin;
  1095. if (isset($shopAdmin->super) == false || $shopAdmin->super != 1) {
  1096. util::fail('超管才能操作');
  1097. }
  1098. $post = Yii::$app->request->post();
  1099. //[{"itemId":"1175","classId":"3548","price":"5","skPrice":"8","cost":"1","name":"卡娜百合"}]
  1100. $data = $post['data'];
  1101. if (empty($data)) {
  1102. util::fail("请选花材");
  1103. }
  1104. $data = json_decode($data, true);
  1105. if (is_array($data) == false || empty($data)) {
  1106. util::fail("请选花材");
  1107. }
  1108. $shop = $this->shop;
  1109. $shopId = $this->shopId;
  1110. $mainId = $this->mainId;
  1111. $sjId = $this->sjId;
  1112. $adminId = $this->adminId;
  1113. $ids = array_column($data, 'itemId');
  1114. $ids = array_unique(array_filter($ids));
  1115. $has = ProductClass::getByCondition(['mainId' => $mainId, 'itemId' => ['in', $ids]]);
  1116. if (!empty($has)) {
  1117. $hasName = $has->name ?? '';
  1118. util::fail($hasName . " 已经添加过了");
  1119. }
  1120. $ptItemInfo = PtItemClass::getAllByCondition(['id' => ['in', $ids]], null, '*', 'id');
  1121. $connection = Yii::$app->db;
  1122. $transaction = $connection->beginTransaction();
  1123. try {
  1124. foreach ($data as $v) {
  1125. $ptItemId = $v['itemId'] ?? 0;
  1126. $ratio = $ptItemInfo[$ptItemId]['ratio'] ?? 20;
  1127. $shelfLife = $ptItemInfo[$ptItemId]['shelfLife'] ?? 7;
  1128. $ratioType = $ptItemInfo[$ptItemId]['ratioType'] ?? 0;
  1129. $variety = $ptItemInfo[$ptItemId]['variety'] ?? 0;
  1130. $stockWarning = $ptItemInfo[$ptItemId]['stockWarning'] ?? 5;
  1131. $weight = $ptItemInfo[$ptItemId]['weight'] ?? 1;
  1132. $bigUnit = $ptItemInfo[$ptItemId]['bigUnit'] ?? '扎';
  1133. $smallUnit = $ptItemInfo[$ptItemId]['smallUnit'] ?? '支';
  1134. $bigUnitId = $ptItemInfo[$ptItemId]['bigUnitId'] ?? 1;
  1135. $smallUnitId = $ptItemInfo[$ptItemId]['smallUnitId'] ?? 2;
  1136. $cover = $ptItemInfo[$ptItemId]['cover'] ?? 'default-img.png';
  1137. $v['ratio'] = $ratio;
  1138. $v['cover'] = $cover;
  1139. $v['shelfLife'] = $shelfLife;
  1140. $v['ratioType'] = $ratioType;
  1141. $v['variety'] = $variety;
  1142. $v['stockWarning'] = $stockWarning;
  1143. $v['weight'] = $weight;
  1144. $v['bigUnit'] = $bigUnit;
  1145. $v['smallUnit'] = $smallUnit;
  1146. $v['bigUnitId'] = $bigUnitId;
  1147. $v['smallUnitId'] = $smallUnitId;
  1148. $v['adminId'] = $adminId;
  1149. $v['sjId'] = $sjId;
  1150. $v['shopId'] = $shopId;
  1151. $v['mainId'] = $mainId;
  1152. $v['staffName'] = $shopAdmin->name ?? '';
  1153. $name = $v['name'] ?? '';
  1154. $price = is_numeric($v['price']) ? $v['price'] : 0;
  1155. $skPrice = is_numeric($v['skPrice']) ? $v['skPrice'] : 0;
  1156. $cost = is_numeric($v['cost']) ? $v['cost'] : 0;
  1157. if ($price <= 0) {
  1158. util::fail("请填写{$name}的批发价");
  1159. }
  1160. if ($skPrice <= 0) {
  1161. util::fail("请填写{$name}的零售价");
  1162. }
  1163. if ($cost <= 0) {
  1164. util::fail("请填写{$name}的成本价");
  1165. }
  1166. if ($price > $skPrice) {
  1167. util::fail("{$name}的批发价比零售价还高");
  1168. }
  1169. if ($cost > $price) {
  1170. util::fail("{$name}的成本价比批发价还高");
  1171. }
  1172. $skMore = bcsub($skPrice, $price, 2);
  1173. $addPrice = bcsub($price, $cost, 2);
  1174. $v['skMore'] = $skMore;
  1175. $v['addPrice'] = $addPrice;
  1176. $v['hjAddPrice'] = $addPrice;
  1177. $v['hjPrice'] = $price;
  1178. ProductClass::addProduct($v, $shop);
  1179. }
  1180. $transaction->commit();
  1181. util::complete('添加成功');
  1182. } catch (Exception $e) {
  1183. $transaction->rollBack();
  1184. util::fail();
  1185. }
  1186. }
  1187. public function actionDelete()
  1188. {
  1189. util::fail('不能删除哦!');
  1190. }
  1191. //获取平台里的花材信息
  1192. public function actionPlatformItem()
  1193. {
  1194. $py = Yii::$app->request->get('py', '');
  1195. $where = [];
  1196. if ($py) {
  1197. $where = ['py' => $py];
  1198. }
  1199. $list = PtItemClass::getItemList($where);
  1200. util::success($list);
  1201. }
  1202. //列出需要进行颜色管理的花材 ssh 20220820
  1203. public function actionColorList()
  1204. {
  1205. $mainId = $this->mainId ?? 0;
  1206. $list = ItemClass::getAllByCondition(['mainId' => $mainId, 'variety' => 1], null, '*');
  1207. util::success(['list' => $list]);
  1208. }
  1209. //多颜色管理启用与停用 ssh 20221229
  1210. public function actionChangeVariety()
  1211. {
  1212. $get = Yii::$app->request->get();
  1213. $id = $get['id'] ?? 0;
  1214. $variety = $get['variety'] ?? 0;
  1215. $info = ItemClass::getById($id, true);
  1216. if (empty($info) || $info->mainId != $this->mainId) {
  1217. util::fail('操作失败');
  1218. }
  1219. $info->variety = $variety;
  1220. $info->save();
  1221. util::complete('操作成功');
  1222. }
  1223. //拆散花材 ssh 20221229
  1224. public function actionBreakItem()
  1225. {
  1226. util::fail('开发中');
  1227. util::complete();
  1228. }
  1229. //批量修改花材的负责人 ssh 20240718
  1230. public function actionChangeCgStaff()
  1231. {
  1232. $get = Yii::$app->request->get();
  1233. $beforeId = $get['beforeId'] ?? 0;
  1234. $newId = $get['newId'] ?? 0;
  1235. if (empty($beforeId) || empty($newId)) {
  1236. util::fail('员工信息有问题');
  1237. }
  1238. $new = ShopAdminClass::getById($newId, true);
  1239. if (empty($new) || $new->mainId != $this->mainId) {
  1240. util::fail('错误的员工信息');
  1241. }
  1242. $before = ShopAdminClass::getById($beforeId, true);
  1243. if (empty($before) || $before->mainId != $this->mainId) {
  1244. util::fail('错误的员工信息2');
  1245. }
  1246. $newName = $new->name ?? '';
  1247. ItemClass::updateByCondition(['mainId' => $this->mainId, 'cgStaffId' => $beforeId], ['cgStaffId' => $newId, 'cgStaffName' => $newName]);
  1248. $shop = $this->shop;
  1249. $bookSn = $shop->bookSn ?? 0;
  1250. if (!empty($bookSn)) {
  1251. BookItemClass::updateByCondition(['bookSn' => $bookSn, 'cgStaffId' => $beforeId], ['cgStaffId' => $newId, 'cgStaffName' => $newName]);
  1252. }
  1253. util::complete('修改成功');
  1254. }
  1255. //获取花材描述
  1256. public function actionDesc()
  1257. {
  1258. $itemId = Yii::$app->request->get('itemId', 0);
  1259. $picText = PicTextGhsItemClass::getByCondition(['mainId' => $this->mainId, 'ghsItemId' => $itemId, 'delStatus' => 0], true);
  1260. if (empty($picText)) {
  1261. // 适配前端的返回处理 -- 本来要使用 util::fail()
  1262. util::success('not_exist');
  1263. }
  1264. if ($picText->mainId != $this->mainId) {
  1265. util::fail('没有找到描述');
  1266. }
  1267. util::success($picText);
  1268. }
  1269. //创建花材描述(花材介绍)
  1270. public function actionCreateDesc()
  1271. {
  1272. $form = new \ghs\models\item\CreateDescForm();
  1273. $form->load(Yii::$app->request->post(), '');
  1274. if (!$form->validateForm()) {
  1275. return;
  1276. }
  1277. $data = $form->attributes;
  1278. $exists = PicTextGhsItemClass::exists(['mainId' => $this->mainId, 'ghsItemId' => $data['itemId'], 'delStatus' => 0]);
  1279. if ($exists) {
  1280. util::fail('该商品已存在图文内容,请勿重复添加');
  1281. }
  1282. $data['mainId'] = $this->mainId;
  1283. $data['ghsItemId'] = $data['itemId'];
  1284. $result = PicTextGhsItemClass::add($data);
  1285. if ($result) {
  1286. util::success($result);
  1287. }
  1288. util::fail('创建失败');
  1289. }
  1290. //更新花材描述(花材介绍)
  1291. public function actionUpdateDesc()
  1292. {
  1293. $form = new \ghs\models\item\CreateDescForm();
  1294. $form->load(Yii::$app->request->post(), '');
  1295. if (!$form->validateForm()) {
  1296. return;
  1297. }
  1298. $data = $form->attributes;
  1299. $id = $data['id'];
  1300. $info = PicTextGhsItemClass::getById($id, false, 'id');
  1301. if (empty($info)) {
  1302. util::fail('描述不存在');
  1303. }
  1304. $data['mainId'] = $this->mainId;
  1305. $result = PicTextGhsItemClass::updateById($id, $data);
  1306. if ($result) {
  1307. util::success($result);
  1308. }
  1309. util::fail('更新失败');
  1310. }
  1311. public function actionChangeVirtualStock()
  1312. {
  1313. $get = Yii::$app->request->get();
  1314. $id = $get['id'] ?? 0;
  1315. $virtualStock = $get['virtualStock'] ?? 0;
  1316. $item = ItemClass::getById($id, true);
  1317. if (empty($item)) {
  1318. util::fail('没有找到花材');
  1319. }
  1320. if ($item->mainId != $this->mainId) {
  1321. util::fail('不是你的花材');
  1322. }
  1323. $item->virtualStock = $virtualStock;
  1324. $item->save();
  1325. util::complete('修改成功');
  1326. }
  1327. }