ItemController.php 49 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413
  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 20260527
  686. public function actionUpdateItemRemark()
  687. {
  688. $get = Yii::$app->request->get();
  689. $id = $get['id'] ?? 0;
  690. $itemRemark = trim($get['itemRemark'] ?? '');
  691. if (empty($itemRemark)) {
  692. util::fail('请填写备注');
  693. }
  694. if (mb_strlen($itemRemark) > 200) {
  695. util::fail('备注不能超过200字');
  696. }
  697. $info = ItemClass::getById($id, true);
  698. if (empty($info)) {
  699. util::fail('没有找到花材');
  700. }
  701. if ($info->mainId != $this->mainId) {
  702. util::fail('无法操作');
  703. }
  704. $info->itemRemark = $itemRemark;
  705. $info->save();
  706. util::complete('保存成功');
  707. }
  708. public function actionClearItemRemark()
  709. {
  710. $get = Yii::$app->request->get();
  711. $id = $get['id'] ?? 0;
  712. $info = ItemClass::getById($id, true);
  713. if (empty($info)) {
  714. util::fail('没有找到花材');
  715. }
  716. if ($info->mainId != $this->mainId) {
  717. util::fail('无法操作');
  718. }
  719. $info->itemRemark = '';
  720. $info->save();
  721. util::complete('清除成功');
  722. }
  723. //批量隐藏和显示花材 ssh 20260131
  724. public function actionBatchChangeFrontHide()
  725. {
  726. $post = Yii::$app->request->post();
  727. $ids = $post['ids'] ?? 0;
  728. $ids = trim($ids);
  729. if (empty($ids)) {
  730. util::fail('请选花材');
  731. }
  732. $frontHide = $post['frontHide'] ?? 0;
  733. $arr = json_decode($ids, true);
  734. if (empty($arr)) {
  735. util::fail('请选花材呢');
  736. }
  737. $list = ItemClass::getAllByCondition(['id' => ['in', $arr]], null, 'id,frontHide,mainId', null, true);
  738. if (!empty($list)) {
  739. foreach ($list as $key => $currentItem) {
  740. if ($currentItem->mainId == $this->mainId) {
  741. $currentItem->frontHide = $frontHide;
  742. $currentItem->frontUse = $frontHide;
  743. $currentItem->save();
  744. }
  745. }
  746. }
  747. util::complete('操作成功');
  748. }
  749. //检测是否要刷新
  750. public function actionCheckRefresh()
  751. {
  752. $mainId = $this->mainId;
  753. $staffId = $this->shopAdminId;
  754. $respond = Yii::$app->redis->executeCommand('GET', ['ghs_cashier_' . $mainId . '_' . $staffId . '_may_refresh']);
  755. if ($respond == 'yes') {
  756. util::success(['remind' => 1]);
  757. }
  758. util::complete();
  759. }
  760. //批量恢复花材 ssh 20230206
  761. public function actionBatchRecover()
  762. {
  763. $post = Yii::$app->request->post();
  764. $string = $post['ids'] ?? '';
  765. $ids = json_decode($string, true);
  766. $ids = array_unique(array_filter($ids));
  767. if (empty($ids)) {
  768. util::fail('请选择花材6');
  769. }
  770. $infoList = ItemClass::getAllByCondition(['id' => ['in', $ids]], null, 'id,name,mainId,status,delStatus,removeStatus', null, true);
  771. if (empty($infoList)) {
  772. util::fail('请选择花材哦8');
  773. }
  774. foreach ($infoList as $info) {
  775. if ($info->mainId != $this->mainId) {
  776. util::fail('请选择自己的花材');
  777. }
  778. $info->removeStatus = 0;
  779. $info->save();
  780. }
  781. util::complete('操作成功');
  782. }
  783. //批量删除花材 ssh 202302026
  784. public function actionBatchRemove()
  785. {
  786. $post = Yii::$app->request->post();
  787. $string = $post['ids'] ?? '';
  788. $ids = json_decode($string, true);
  789. $ids = array_unique(array_filter($ids));
  790. if (empty($ids)) {
  791. util::fail('请选择花材7');
  792. }
  793. $infoList = ItemClass::getAllByCondition(['id' => ['in', $ids]], null, 'id,name,mainId,status,delStatus,removeStatus', null, true);
  794. if (empty($infoList)) {
  795. util::fail('请选择花材哦10');
  796. }
  797. foreach ($infoList as $info) {
  798. if ($info->mainId != $this->mainId) {
  799. util::fail('请选择自己的花材');
  800. }
  801. $name = $info->name ?? '';
  802. if ($info->delStatus != 1) {
  803. util::fail($name . ' 停用了才能删除');
  804. }
  805. $info->removeStatus = 1;
  806. $info->save();
  807. }
  808. util::complete('操作成功');
  809. }
  810. //批量启用花材 ssh 20230206
  811. public function actionBatchEnable()
  812. {
  813. $post = Yii::$app->request->post();
  814. $string = $post['ids'] ?? '';
  815. $ids = json_decode($string, true);
  816. $ids = array_unique(array_filter($ids));
  817. if (empty($ids)) {
  818. util::fail('请选择花材11');
  819. }
  820. $infoList = ItemClass::getAllByCondition(['id' => ['in', $ids]], null, 'id,name,mainId,status,delStatus,removeStatus', null, true);
  821. if (empty($infoList)) {
  822. util::fail('请选择花材哦12');
  823. }
  824. foreach ($infoList as $info) {
  825. if ($info->mainId != $this->mainId) {
  826. util::fail('请选择自己的花材');
  827. }
  828. $info->delStatus = 0;
  829. $info->save();
  830. }
  831. util::complete('操作成功');
  832. }
  833. //批量停用花材 20230206
  834. public function actionBatchStop()
  835. {
  836. $post = Yii::$app->request->post();
  837. $string = $post['ids'] ?? '';
  838. $ids = json_decode($string, true);
  839. $ids = array_unique(array_filter($ids));
  840. if (empty($ids)) {
  841. util::fail('请选择花材13');
  842. }
  843. $infoList = ItemClass::getAllByCondition(['id' => ['in', $ids]], null, 'id,name,mainId,status,delStatus,removeStatus', null, true);
  844. if (empty($infoList)) {
  845. util::fail('请选择花材哦14');
  846. }
  847. foreach ($infoList as $info) {
  848. if ($info->mainId != $this->mainId) {
  849. util::fail('请选择自己的花材');
  850. }
  851. $name = $info->name ?? '';
  852. if ($info->status != 2) {
  853. util::fail($name . ' 下载了才能停用');
  854. }
  855. $info->delStatus = 1;
  856. $info->save();
  857. }
  858. util::complete('操作成功');
  859. }
  860. //获取给散客下单的花材海报 ssh 20220111
  861. public function actionGetSkPoster()
  862. {
  863. $get = Yii::$app->request->get();
  864. $id = $get['id'] ?? 0;
  865. $item = ItemClass::getById($id, true);
  866. if (empty($item) || $item->mainId != $this->mainId) {
  867. util::fail('获取失败');
  868. }
  869. $cover = $item->cover ?? '';
  870. if (empty($cover)) {
  871. util::fail('获取失败');
  872. }
  873. $merchant = WxOpenClass::getMallWxInfo();
  874. $page = 'pages/item/detail';
  875. $ptStyle = dict::getDict('ptStyle', 'mall');
  876. $shop = $this->shop;
  877. $lsShopId = $shop->lsShopId ?? 0;
  878. //scene不能超过32个字条
  879. $scene = "id=" . $id . '&a=' . $lsShopId;
  880. $miniCode = miniUtil::generateUnlimitedMiniCode($merchant, $page, $scene, $ptStyle);
  881. $miniCode = $miniCode . '?x-oss-process=image/resize,m_fill,h_200,w_200';
  882. $miniCodeBase64 = stringUtil::ossBase64($miniCode);
  883. Yii::$app->params['ptStyle'] = dict::getDict('ptStyle', 'hd');
  884. $prefix = imgUtil::getPrefix();
  885. $price = $item->skPrice ?? 0;
  886. if ($item->discountPrice > 0) {
  887. $skMore = $item->skMore ?? 0;
  888. $price = bcadd($item->discountPrice, $skMore, 2);
  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. //下载商品码,用于花市卖花 ssh 20240823
  931. public function actionDownMiniCode()
  932. {
  933. $get = Yii::$app->request->get();
  934. $id = $get['id'] ?? 0;
  935. $item = ItemClass::getById($id, true);
  936. if (empty($item)) {
  937. util::fail('没有找到花材');
  938. }
  939. if ($item->mainId != $this->mainId) {
  940. util::fail('不是你的花材');
  941. }
  942. $merchant = WxOpenClass::getWxInfo();
  943. $page = 'admin/ghsProduct/detail';
  944. $ptStyle = dict::getDict('ptStyle', 'hd');
  945. //小程序码,scene不能超过32个字条
  946. $scene = "id=" . $id . '&sId=' . $this->shopId;
  947. $miniCode = miniUtil::generateUnlimitedMiniCode($merchant, $page, $scene, $ptStyle);
  948. $miniCode = $miniCode . '?x-oss-process=image/resize,m_fill,h_450,w_450';
  949. $miniCodeBase64 = stringUtil::ossBase64($miniCode);
  950. $prefix = imgUtil::getPrefix();
  951. $url = $prefix . 'poster/mini_bg.jpg?x-oss-process=image';
  952. //小程序码
  953. $url .= '/watermark,image_' . $miniCodeBase64 . ',g_north,x_0,y_25';
  954. $name = $item->name ?? '';
  955. $nameBase64 = stringUtil::ossBase64($name);
  956. //标题
  957. $url .= '/watermark,text_' . $nameBase64 . ',g_south,x_0,y_35';
  958. $file = fopen($url, "rb");
  959. Header("Content-type: application/octet-stream ");
  960. Header("Accept-Ranges: bytes ");
  961. Header("Content-Disposition: attachment;filename={$name}.jpg");
  962. $contents = "";
  963. while (!feof($file)) {
  964. $contents .= fread($file, 8192);
  965. }
  966. echo $contents;
  967. fclose($file);
  968. }
  969. //获取给花店下单的花材海报 ssh 20220111
  970. public function actionGetHdPoster()
  971. {
  972. $get = Yii::$app->request->get();
  973. $id = $get['id'] ?? 0;
  974. $item = ItemClass::getById($id, true);
  975. if (empty($item) || $item->mainId != $this->mainId) {
  976. util::fail('获取失败');
  977. }
  978. $cover = $item->cover ?? '';
  979. if (empty($cover)) {
  980. util::fail('获取失败');
  981. }
  982. $merchant = WxOpenClass::getWxInfo();
  983. $page = 'admin/ghsProduct/detail';
  984. $ptStyle = dict::getDict('ptStyle', 'hd');
  985. //小程序码,scene不能超过32个字条
  986. $scene = "id=" . $id . '&sId=' . $this->shopId;
  987. $miniCode = miniUtil::generateUnlimitedMiniCode($merchant, $page, $scene, $ptStyle);
  988. $miniCode = $miniCode . '?x-oss-process=image/resize,m_fill,h_200,w_200';
  989. $miniCodeBase64 = stringUtil::ossBase64($miniCode);
  990. Yii::$app->params['ptStyle'] = dict::getDict('ptStyle', 'ghs');
  991. $prefix = imgUtil::getPrefix();
  992. $price = $item->price ?? 0;
  993. if ($item->discountPrice > 0) {
  994. $price = $item->discountPrice;
  995. }
  996. $newPrice = '¥' . floatval($price);
  997. $priceBase64 = stringUtil::ossBase64($newPrice);
  998. $name = $item->name ?? '';
  999. $nameBase64 = stringUtil::ossBase64($name);
  1000. $staff = $this->shopAdmin;
  1001. $staffName = $staff->name ?? '';
  1002. $newStaffName = $staffName . ' 为您推荐';
  1003. $staffNameBase64 = stringUtil::ossBase64($newStaffName);
  1004. //花材主图
  1005. $itemCover = $cover . '?x-oss-process=image/resize,m_fill,h_750,w_750';
  1006. $itemCoverBase64 = stringUtil::ossBase64($itemCover);
  1007. $logoBase64 = '';
  1008. if (in_array($this->mainId, [52, 1459, 13495])) {
  1009. $logo = 'poster/hyxh_ncd_logo.png?x-oss-process=image/resize,m_fill,h_90,w_90';
  1010. if ($this->mainId == 1459) {
  1011. $logo = 'poster/hyxh_gcd_logo.png?x-oss-process=image/resize,m_fill,h_90,w_90';
  1012. }
  1013. if ($this->mainId == 13495) {
  1014. $logo = 'poster/hyxh_hzd_logo.png?x-oss-process=image/resize,m_fill,h_90,w_90';
  1015. }
  1016. $logoBase64 = stringUtil::ossBase64($logo);
  1017. }
  1018. $url = $prefix . 'poster/1234.jpg?x-oss-process=image';
  1019. //花材主图
  1020. $url .= '/watermark,image_' . $itemCoverBase64 . ',g_nw,x_0,y_0';
  1021. //小程序码
  1022. $url .= '/watermark,image_' . $miniCodeBase64 . ',g_se';
  1023. if (!empty($logoBase64)) {
  1024. //logo
  1025. $url .= '/watermark,image_' . $logoBase64 . ',g_se,x_65,y_65';
  1026. }
  1027. //为你推荐
  1028. $url .= '/watermark,text_' . $staffNameBase64 . ',g_sw,x_18,y_235,color_8B8989,type_d3F5LW1pY3JvaGVp,size_30';
  1029. //标题
  1030. $url .= '/watermark,text_' . $nameBase64 . ',g_sw,x_18,y_145';
  1031. //价格
  1032. $url .= '/watermark,text_' . $priceBase64 . ',g_sw,x_18,y_50,color_EE2C2C,type_d3F5LW1pY3JvaGVp,size_50';
  1033. $respond = ['imgUrl' => $url];
  1034. util::success($respond);
  1035. }
  1036. //是否有C级价格大于B级的 ssh 20221204
  1037. public function actionGetErrorPrice()
  1038. {
  1039. $shop = $this->shop;
  1040. $ret = ItemClass::errorPrice($shop);
  1041. $list = $ret['data'] ?? [];
  1042. $map = $ret['map'] ?? [];
  1043. util::success(['list' => $list, 'map' => $map]);
  1044. }
  1045. //列出所有花材,包括特价花材列表 ssh 20220315
  1046. public function actionShowList()
  1047. {
  1048. $get = Yii::$app->request->get();
  1049. $customId = $get['customId'] ?? 0;
  1050. $custom = CustomClass::getById($customId, true);
  1051. $where['mainId'] = $this->mainId;
  1052. $where['delStatus'] = 0;
  1053. $where['status'] = 1;
  1054. $list = ItemClass::getShowList($where, $custom);
  1055. $mainId = $this->mainId;
  1056. $get = Yii::$app->request->get();
  1057. $isCashier = $get['isCashier'] ?? 0;
  1058. if ($isCashier == 1) {
  1059. //去掉收银台提示价格更新
  1060. $staffId = $this->shopAdminId;
  1061. Yii::$app->redis->executeCommand('DEL', ['ghs_cashier_' . $mainId . '_' . $staffId . '_may_refresh']);
  1062. }
  1063. $productList = [];
  1064. if (!empty($list)) {
  1065. foreach ($list as $key => $item) {
  1066. if (!empty($item)) {
  1067. $productList = array_merge($productList, $item);
  1068. }
  1069. }
  1070. }
  1071. util::success(['list' => $list, 'productList' => $productList]);
  1072. }
  1073. public function actionAdd()
  1074. {
  1075. util::fail('开发中');
  1076. }
  1077. //批量添加花材
  1078. public function actionBatchAdd()
  1079. {
  1080. $shopAdmin = $this->shopAdmin;
  1081. if (isset($shopAdmin->super) == false || $shopAdmin->super != 1) {
  1082. util::fail('超管才能操作');
  1083. }
  1084. $post = Yii::$app->request->post();
  1085. //[{"itemId":"1175","classId":"3548","price":"5","skPrice":"8","cost":"1","name":"卡娜百合"}]
  1086. $data = $post['data'];
  1087. if (empty($data)) {
  1088. util::fail("请选花材");
  1089. }
  1090. $data = json_decode($data, true);
  1091. if (is_array($data) == false || empty($data)) {
  1092. util::fail("请选花材");
  1093. }
  1094. $shop = $this->shop;
  1095. $shopId = $this->shopId;
  1096. $mainId = $this->mainId;
  1097. $sjId = $this->sjId;
  1098. $adminId = $this->adminId;
  1099. $ids = array_column($data, 'itemId');
  1100. $ids = array_unique(array_filter($ids));
  1101. $has = ProductClass::getByCondition(['mainId' => $mainId, 'itemId' => ['in', $ids]]);
  1102. if (!empty($has)) {
  1103. $hasName = $has->name ?? '';
  1104. util::fail($hasName . " 已经添加过了");
  1105. }
  1106. $ptItemInfo = PtItemClass::getAllByCondition(['id' => ['in', $ids]], null, '*', 'id');
  1107. $connection = Yii::$app->db;
  1108. $transaction = $connection->beginTransaction();
  1109. try {
  1110. foreach ($data as $v) {
  1111. $ptItemId = $v['itemId'] ?? 0;
  1112. $ratio = $ptItemInfo[$ptItemId]['ratio'] ?? 20;
  1113. $shelfLife = $ptItemInfo[$ptItemId]['shelfLife'] ?? 7;
  1114. $ratioType = $ptItemInfo[$ptItemId]['ratioType'] ?? 0;
  1115. $variety = $ptItemInfo[$ptItemId]['variety'] ?? 0;
  1116. $stockWarning = $ptItemInfo[$ptItemId]['stockWarning'] ?? 5;
  1117. $weight = $ptItemInfo[$ptItemId]['weight'] ?? 1;
  1118. $bigUnit = $ptItemInfo[$ptItemId]['bigUnit'] ?? '扎';
  1119. $smallUnit = $ptItemInfo[$ptItemId]['smallUnit'] ?? '支';
  1120. $bigUnitId = $ptItemInfo[$ptItemId]['bigUnitId'] ?? 1;
  1121. $smallUnitId = $ptItemInfo[$ptItemId]['smallUnitId'] ?? 2;
  1122. $cover = $ptItemInfo[$ptItemId]['cover'] ?? 'default-img.png';
  1123. $v['ratio'] = $ratio;
  1124. $v['cover'] = $cover;
  1125. $v['shelfLife'] = $shelfLife;
  1126. $v['ratioType'] = $ratioType;
  1127. $v['variety'] = $variety;
  1128. $v['stockWarning'] = $stockWarning;
  1129. $v['weight'] = $weight;
  1130. $v['bigUnit'] = $bigUnit;
  1131. $v['smallUnit'] = $smallUnit;
  1132. $v['bigUnitId'] = $bigUnitId;
  1133. $v['smallUnitId'] = $smallUnitId;
  1134. $v['adminId'] = $adminId;
  1135. $v['sjId'] = $sjId;
  1136. $v['shopId'] = $shopId;
  1137. $v['mainId'] = $mainId;
  1138. $v['staffName'] = $shopAdmin->name ?? '';
  1139. $name = $v['name'] ?? '';
  1140. $price = is_numeric($v['price']) ? $v['price'] : 0;
  1141. $skPrice = is_numeric($v['skPrice']) ? $v['skPrice'] : 0;
  1142. $cost = is_numeric($v['cost']) ? $v['cost'] : 0;
  1143. if ($price <= 0) {
  1144. util::fail("请填写{$name}的批发价");
  1145. }
  1146. if ($skPrice <= 0) {
  1147. util::fail("请填写{$name}的零售价");
  1148. }
  1149. if ($cost <= 0) {
  1150. util::fail("请填写{$name}的成本价");
  1151. }
  1152. if ($price > $skPrice) {
  1153. util::fail("{$name}的批发价比零售价还高");
  1154. }
  1155. if ($cost > $price) {
  1156. util::fail("{$name}的成本价比批发价还高");
  1157. }
  1158. $skMore = bcsub($skPrice, $price, 2);
  1159. $addPrice = bcsub($price, $cost, 2);
  1160. $v['skMore'] = $skMore;
  1161. $v['addPrice'] = $addPrice;
  1162. $v['hjAddPrice'] = $addPrice;
  1163. $v['hjPrice'] = $price;
  1164. ProductClass::addProduct($v, $shop);
  1165. }
  1166. $transaction->commit();
  1167. util::complete('添加成功');
  1168. } catch (Exception $e) {
  1169. $transaction->rollBack();
  1170. util::fail();
  1171. }
  1172. }
  1173. public function actionDelete()
  1174. {
  1175. util::fail('不能删除哦!');
  1176. }
  1177. //获取平台里的花材信息
  1178. public function actionPlatformItem()
  1179. {
  1180. $py = Yii::$app->request->get('py', '');
  1181. $where = [];
  1182. if ($py) {
  1183. $where = ['py' => $py];
  1184. }
  1185. $list = PtItemClass::getItemList($where);
  1186. util::success($list);
  1187. }
  1188. //列出需要进行颜色管理的花材 ssh 20220820
  1189. public function actionColorList()
  1190. {
  1191. $mainId = $this->mainId ?? 0;
  1192. $list = ItemClass::getAllByCondition(['mainId' => $mainId, 'variety' => 1], null, '*');
  1193. util::success(['list' => $list]);
  1194. }
  1195. //多颜色管理启用与停用 ssh 20221229
  1196. public function actionChangeVariety()
  1197. {
  1198. $get = Yii::$app->request->get();
  1199. $id = $get['id'] ?? 0;
  1200. $variety = $get['variety'] ?? 0;
  1201. $info = ItemClass::getById($id, true);
  1202. if (empty($info) || $info->mainId != $this->mainId) {
  1203. util::fail('操作失败');
  1204. }
  1205. $info->variety = $variety;
  1206. $info->save();
  1207. util::complete('操作成功');
  1208. }
  1209. //拆散花材 ssh 20221229
  1210. public function actionBreakItem()
  1211. {
  1212. util::fail('开发中');
  1213. util::complete();
  1214. }
  1215. //批量修改花材的负责人 ssh 20240718
  1216. public function actionChangeCgStaff()
  1217. {
  1218. $get = Yii::$app->request->get();
  1219. $beforeId = $get['beforeId'] ?? 0;
  1220. $newId = $get['newId'] ?? 0;
  1221. if (empty($beforeId) || empty($newId)) {
  1222. util::fail('员工信息有问题');
  1223. }
  1224. $new = ShopAdminClass::getById($newId, true);
  1225. if (empty($new) || $new->mainId != $this->mainId) {
  1226. util::fail('错误的员工信息');
  1227. }
  1228. $before = ShopAdminClass::getById($beforeId, true);
  1229. if (empty($before) || $before->mainId != $this->mainId) {
  1230. util::fail('错误的员工信息2');
  1231. }
  1232. $newName = $new->name ?? '';
  1233. ItemClass::updateByCondition(['mainId' => $this->mainId, 'cgStaffId' => $beforeId], ['cgStaffId' => $newId, 'cgStaffName' => $newName]);
  1234. $shop = $this->shop;
  1235. $bookSn = $shop->bookSn ?? 0;
  1236. if (!empty($bookSn)) {
  1237. BookItemClass::updateByCondition(['bookSn' => $bookSn, 'cgStaffId' => $beforeId], ['cgStaffId' => $newId, 'cgStaffName' => $newName]);
  1238. }
  1239. util::complete('修改成功');
  1240. }
  1241. //获取花材描述
  1242. public function actionDesc()
  1243. {
  1244. $itemId = Yii::$app->request->get('itemId', 0);
  1245. $picText = PicTextGhsItemClass::getByCondition(['mainId' => $this->mainId, 'ghsItemId' => $itemId, 'delStatus' => 0], true);
  1246. if (empty($picText)) {
  1247. // 适配前端的返回处理 -- 本来要使用 util::fail()
  1248. util::success('not_exist');
  1249. }
  1250. if ($picText->mainId != $this->mainId) {
  1251. util::fail('没有找到描述');
  1252. }
  1253. util::success($picText);
  1254. }
  1255. //创建花材描述(花材介绍)
  1256. public function actionCreateDesc()
  1257. {
  1258. $form = new \ghs\models\item\CreateDescForm();
  1259. $form->load(Yii::$app->request->post(), '');
  1260. if (!$form->validateForm()) {
  1261. return;
  1262. }
  1263. $data = $form->attributes;
  1264. $exists = PicTextGhsItemClass::exists(['mainId' => $this->mainId, 'ghsItemId' => $data['itemId'], 'delStatus' => 0]);
  1265. if ($exists) {
  1266. util::fail('该商品已存在图文内容,请勿重复添加');
  1267. }
  1268. $data['mainId'] = $this->mainId;
  1269. $data['ghsItemId'] = $data['itemId'];
  1270. $result = PicTextGhsItemClass::add($data);
  1271. if ($result) {
  1272. util::success($result);
  1273. }
  1274. util::fail('创建失败');
  1275. }
  1276. //更新花材描述(花材介绍)
  1277. public function actionUpdateDesc()
  1278. {
  1279. $form = new \ghs\models\item\CreateDescForm();
  1280. $form->load(Yii::$app->request->post(), '');
  1281. if (!$form->validateForm()) {
  1282. return;
  1283. }
  1284. $data = $form->attributes;
  1285. $id = $data['id'];
  1286. $info = PicTextGhsItemClass::getById($id, false, 'id');
  1287. if (empty($info)) {
  1288. util::fail('描述不存在');
  1289. }
  1290. $data['mainId'] = $this->mainId;
  1291. $result = PicTextGhsItemClass::updateById($id, $data);
  1292. if ($result) {
  1293. util::success($result);
  1294. }
  1295. util::fail('更新失败');
  1296. }
  1297. public function actionChangeVirtualStock()
  1298. {
  1299. $get = Yii::$app->request->get();
  1300. $id = $get['id'] ?? 0;
  1301. $virtualStock = $get['virtualStock'] ?? 0;
  1302. $item = ItemClass::getById($id, true);
  1303. if (empty($item)) {
  1304. util::fail('没有找到花材');
  1305. }
  1306. if ($item->mainId != $this->mainId) {
  1307. util::fail('不是你的花材');
  1308. }
  1309. $item->virtualStock = $virtualStock;
  1310. $item->save();
  1311. util::complete('修改成功');
  1312. }
  1313. }