ItemController.php 46 KB

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