ItemController.php 43 KB

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