ItemController.php 48 KB

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