ItemController.php 43 KB

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