ItemController.php 47 KB

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