ItemController.php 48 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351
  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. $onStock = $get['onStock'] ?? 0;
  392. $where['mainId'] = $this->mainId;
  393. if ($requestType == 'kd') {
  394. $where['delStatus'] = 0;
  395. $where['status'] = 1;
  396. } elseif ($requestType == 'itemList') {
  397. $where['delStatus'] = 0;
  398. if ($lookStock == 1) {
  399. $where['stock>'] = 0;
  400. }
  401. if ($lookStock == 2) {
  402. $where['stock'] = 0;
  403. }
  404. if($onStock == 1){
  405. $where['onStock>'] = 0;
  406. }
  407. unset($where['status']);
  408. } elseif ($requestType == 'changePrice') {
  409. $where['delStatus'] = 0;
  410. $where['stock>'] = 0;
  411. } elseif ($requestType == 'hasStockList') {
  412. $where['delStatus'] = 0;
  413. $where['stock>'] = 0;
  414. } elseif ($requestType == 'book') {
  415. $where['delStatus'] = 0;
  416. unset($where['status']);
  417. } elseif ($requestType == 'outList') {
  418. $where['delStatus'] = 0;
  419. $where['status'] = 2;
  420. $where['removeStatus'] = 0;
  421. } elseif ($requestType == 'stopList') {
  422. $where['delStatus'] = 1;
  423. unset($where['status']);
  424. $where['removeStatus'] = 0;
  425. } elseif ($requestType == 'removeList') {
  426. $where['delStatus'] = 1;
  427. unset($where['status']);
  428. $where['removeStatus'] = 1;
  429. } elseif ($requestType == 'cg') {
  430. $where['delStatus'] = 0;
  431. unset($where['status']);
  432. } elseif ($requestType == 'changeStock') {
  433. $where['delStatus'] = 0;
  434. unset($where['status']);
  435. } elseif ($requestType == 'check') {
  436. $where['delStatus'] = 0;
  437. unset($where['status']);
  438. } elseif ($requestType == 'stockOut') {
  439. $where['delStatus'] = 0;
  440. $where['status'] = 1;
  441. } elseif ($requestType == 'break') {
  442. $where['delStatus'] = 0;
  443. $where['status'] = 1;
  444. } elseif ($requestType == 'part') {
  445. $where['delStatus'] = 0;
  446. $where['status'] = 1;
  447. } else {
  448. util::fail('没有定义的请求方式');
  449. }
  450. if (!empty($search)) {
  451. if (stringUtil::isLetter($search)) {
  452. $search = strtolower($search);
  453. $where['py'] = ['like', $search];
  454. } else {
  455. $where['name'] = ['like', $search];
  456. }
  457. } else {
  458. if (!empty($classId)) {
  459. if ($classId == -1) {
  460. $where['discountPrice>'] = 0;
  461. } elseif ($classId == -2) {
  462. $where['reachNum>'] = 0;
  463. } elseif ($classId == -3) {
  464. $where['presell'] = 1;
  465. } else {
  466. $where['classId'] = $classId;
  467. }
  468. }
  469. }
  470. $customId = $get['customId'] ?? 0;
  471. $custom = CustomClass::getById($customId, true);
  472. if (!empty($custom)) {
  473. if ($custom->ownMainId != $this->mainId) {
  474. util::fail('不是你的客户');
  475. }
  476. }
  477. $level = $custom->level ?? 1;
  478. $field = '*';
  479. //只查我负责的花材
  480. $globalCgMyCharge = $get['globalCgMyCharge'] ?? 0;
  481. $needCgList = [];
  482. $shop = $this->shop;
  483. $bookSn = $shop->bookSn ?? 0;
  484. $staff = $this->shopAdmin;
  485. $staffId = $staff->id ?? 0;
  486. if (!empty($bookSn)) {
  487. $biList = BookItemClass::getAllByCondition(['bookSn' => $bookSn, 'cgStaffId' => $staffId], null, '*', null, true);
  488. if (!empty($biList)) {
  489. $myIds = [];
  490. foreach ($biList as $biInfo) {
  491. $biProductId = $biInfo->itemId ?? 0;
  492. if ($biInfo->needCgNum > 0) {
  493. $myIds[] = $biProductId;
  494. $needCgList[$biProductId] = $biInfo->needCgNum;
  495. }
  496. }
  497. if ($globalCgMyCharge == 1) {
  498. if (!empty($myIds)) {
  499. $where['id'] = ['in', $myIds];
  500. } else {
  501. $where['id'] = ['in', [0]];
  502. }
  503. }
  504. } else {
  505. if ($globalCgMyCharge == 1) {
  506. $where['id'] = ['in', [0]];
  507. }
  508. }
  509. }
  510. $result = ProductClass::getList($field, $where, ['inTurn' => SORT_DESC, 'actualSold' => SORT_DESC]);
  511. $list = $result['list'] ?? [];
  512. if ($requestType == 'hasStockList') {
  513. util::fail('无效方式');
  514. } elseif ($requestType == 'changePrice') {
  515. $list = ProductClass::changePriceGroup($list, $level);
  516. } elseif ($requestType == 'changeStock') {
  517. $list = ProductClass::changeStockGroup($list, $level);
  518. } elseif ($requestType == 'kd') {
  519. $list = ProductClass::kdItemGroup($list, $level, $custom);
  520. } elseif ($requestType == 'book') {
  521. $list = ProductClass::bookItemGroup($list, $level);
  522. } elseif ($requestType == 'itemList') {
  523. $list = ProductClass::itemListGroup($list, $level);
  524. } elseif ($requestType == 'outList') {
  525. $list = ProductClass::simpleGroup($list, $level);
  526. } elseif ($requestType == 'stopList') {
  527. $list = ProductClass::simpleGroup($list, $level);
  528. } elseif ($requestType == 'removeList') {
  529. $list = ProductClass::simpleGroup($list, $level);
  530. } elseif ($requestType == 'check') {
  531. $list = ProductClass::checkItemGroup($list, $level);
  532. } elseif ($requestType == 'break') {
  533. $list = ProductClass::breakItemGroup($list, $level);
  534. } elseif ($requestType == 'part') {
  535. $list = ProductClass::partItemGroup($list, $level);
  536. } elseif ($requestType == 'stockOut') {
  537. $list = ProductClass::stockOutGroup($list, $level);
  538. } elseif ($requestType == 'cg') {
  539. $list = ProductClass::cgItemGroup($list, $level);
  540. } elseif ($requestType == 'warning') {
  541. util::fail('无效方式');
  542. // $itemInfoData = Product::find()->where("mainId={$this->mainId}")
  543. // ->andWhere('`stock`+`onStock`<`stockWarning`')
  544. // ->andWhere("delStatus=0")
  545. // ->select($field)->asArray()->all();
  546. // $itemInfoData = ProductClass::warningGroup($itemInfoData, $level);
  547. } else {
  548. util::fail('没有数据');
  549. }
  550. if (!empty($needCgList)) {
  551. //采购人采自己花材需要知道要采多少
  552. if (!empty($list)) {
  553. foreach ($list as $key => $val) {
  554. $productId = $val['id'] ?? 0;
  555. if (isset($needCgList[$productId])) {
  556. $needCgNum = $needCgList[$productId];
  557. $list[$key]['needCgNum'] = $needCgNum;
  558. }
  559. }
  560. }
  561. }
  562. if (!empty($list) && $classId == -1) {
  563. //限购的排在最前面,多处同步修改limit_ahead
  564. $list = arrayUtil::arraySort($list, 'limitBuy');
  565. }
  566. $result['list'] = $list;
  567. util::success($result);
  568. }
  569. //花材申请平台认证 ssh 20231125
  570. public function actionApplyAuth()
  571. {
  572. $get = Yii::$app->request->get();
  573. $id = $get['id'] ?? 0;
  574. $info = ItemClass::getById($id, true);
  575. if (empty($info)) {
  576. util::fail('没有找到花材');
  577. }
  578. if ($info->mainId != $this->mainId) {
  579. util::fail('不是你的花材哦');
  580. }
  581. $shop = $this->shop;
  582. $sjName = $shop->merchantName ?? '';
  583. $shopName = $shop->shopName ?? '';
  584. $name = $shopName == '首店' ? $sjName : $sjName . ' ' . $shopName;
  585. $ptItemId = $info->itemId ?? 0;
  586. $ptItem = PtItemClass::getById($ptItemId, true);
  587. if (empty($ptItem)) {
  588. util::fail('没有找到平台花材');
  589. }
  590. $ptItemName = $ptItem->name ?? '';
  591. noticeUtil::push($name . " 申请将【{$ptItemName}/{$ptItemId}】进行认证", '15280215347');
  592. util::complete();
  593. }
  594. //简单花材的列表
  595. public function actionSimpleList()
  596. {
  597. $get = Yii::$app->request->get();
  598. $name = $get['name'] ?? '';
  599. $num = $get['num'] ?? 0;
  600. $where = ['mainId' => $this->mainId, 'delStatus' => 0];
  601. if (!empty($name)) {
  602. if (stringUtil::isLetter($name)) {
  603. $where['py'] = ['like', $name];
  604. } else {
  605. $where['name'] = ['like', $name];
  606. }
  607. }
  608. $respond = ItemClass::getSimpleList($where, $num);
  609. util::success($respond);
  610. }
  611. //可借库存的花材列表 ssh 20240720
  612. public function actionGetLoanList()
  613. {
  614. $get = Yii::$app->request->get();
  615. $name = $get['name'] ?? '';
  616. $where = ['mainId' => $this->mainId, 'delStatus' => 0];
  617. if (!empty($name)) {
  618. if (stringUtil::isLetter($name)) {
  619. $where['py'] = ['like', $name];
  620. } else {
  621. $where['name'] = ['like', $name];
  622. }
  623. }
  624. $shop = $this->shop;
  625. $respond = ItemClass::getLoanList($where, $shop);
  626. util::success($respond);
  627. }
  628. //全部花材取消隐藏 ssh 20260201
  629. public function actionCancelAllItemHide()
  630. {
  631. $mainId = $this->mainId;
  632. ItemClass::updateByCondition(['mainId' => $mainId, 'frontHide' => 1], ['frontHide' => 0, 'frontUse' => 0]);
  633. util::complete('操作成功');
  634. }
  635. //分类下的花材取消隐藏 sssh 20260201
  636. public function actionCancelClassItemHide()
  637. {
  638. $get = Yii::$app->request->get();
  639. $classId = $get['classId'] ?? 0;
  640. $mainId = $this->mainId;
  641. ItemClass::updateByCondition(['mainId' => $mainId, 'classId' => $classId, 'frontHide' => 1], ['frontHide' => 0, 'frontUse' => 0]);
  642. util::complete('操作成功');
  643. }
  644. //单个花材的显示和隐藏 ssh 20260201
  645. public function actionChangeFrontHide()
  646. {
  647. $get = Yii::$app->request->get();
  648. $id = $get['id'] ?? 0;
  649. $status = $get['status'] ?? '';
  650. if (!is_numeric($status)) {
  651. util::fail('请选择方式');
  652. }
  653. $info = ItemClass::getById($id, true);
  654. if (empty($info)) {
  655. util::fail('没有找到花材');
  656. }
  657. if ($info->mainId != $this->mainId) {
  658. util::fail('无法操作');
  659. }
  660. $info->frontHide = $status;
  661. $info->frontUse = $status;
  662. $info->save();
  663. util::complete();
  664. }
  665. //批量隐藏和显示花材 ssh 20260131
  666. public function actionBatchChangeFrontHide()
  667. {
  668. $post = Yii::$app->request->post();
  669. $ids = $post['ids'] ?? 0;
  670. $ids = trim($ids);
  671. if (empty($ids)) {
  672. util::fail('请选花材');
  673. }
  674. $frontHide = $post['frontHide'] ?? 0;
  675. $arr = json_decode($ids, true);
  676. if (empty($arr)) {
  677. util::fail('请选花材呢');
  678. }
  679. $list = ItemClass::getAllByCondition(['id' => ['in', $arr]], null, 'id,frontHide,mainId', null, true);
  680. if (!empty($list)) {
  681. foreach ($list as $key => $currentItem) {
  682. if ($currentItem->mainId == $this->mainId) {
  683. $currentItem->frontHide = $frontHide;
  684. $currentItem->frontUse = $frontHide;
  685. $currentItem->save();
  686. }
  687. }
  688. }
  689. util::complete('操作成功');
  690. }
  691. //检测是否要刷新
  692. public function actionCheckRefresh()
  693. {
  694. $mainId = $this->mainId;
  695. $staffId = $this->shopAdminId;
  696. $respond = Yii::$app->redis->executeCommand('GET', ['ghs_cashier_' . $mainId . '_' . $staffId . '_may_refresh']);
  697. if ($respond == 'yes') {
  698. util::success(['remind' => 1]);
  699. }
  700. util::complete();
  701. }
  702. //批量恢复花材 ssh 20230206
  703. public function actionBatchRecover()
  704. {
  705. $post = Yii::$app->request->post();
  706. $string = $post['ids'] ?? '';
  707. $ids = json_decode($string, true);
  708. $ids = array_unique(array_filter($ids));
  709. if (empty($ids)) {
  710. util::fail('请选择花材6');
  711. }
  712. $infoList = ItemClass::getAllByCondition(['id' => ['in', $ids]], null, 'id,name,mainId,status,delStatus,removeStatus', null, true);
  713. if (empty($infoList)) {
  714. util::fail('请选择花材哦8');
  715. }
  716. foreach ($infoList as $info) {
  717. if ($info->mainId != $this->mainId) {
  718. util::fail('请选择自己的花材');
  719. }
  720. $info->removeStatus = 0;
  721. $info->save();
  722. }
  723. util::complete('操作成功');
  724. }
  725. //批量删除花材 ssh 202302026
  726. public function actionBatchRemove()
  727. {
  728. $post = Yii::$app->request->post();
  729. $string = $post['ids'] ?? '';
  730. $ids = json_decode($string, true);
  731. $ids = array_unique(array_filter($ids));
  732. if (empty($ids)) {
  733. util::fail('请选择花材7');
  734. }
  735. $infoList = ItemClass::getAllByCondition(['id' => ['in', $ids]], null, 'id,name,mainId,status,delStatus,removeStatus', null, true);
  736. if (empty($infoList)) {
  737. util::fail('请选择花材哦10');
  738. }
  739. foreach ($infoList as $info) {
  740. if ($info->mainId != $this->mainId) {
  741. util::fail('请选择自己的花材');
  742. }
  743. $name = $info->name ?? '';
  744. if ($info->delStatus != 1) {
  745. util::fail($name . ' 停用了才能删除');
  746. }
  747. $info->removeStatus = 1;
  748. $info->save();
  749. }
  750. util::complete('操作成功');
  751. }
  752. //批量启用花材 ssh 20230206
  753. public function actionBatchEnable()
  754. {
  755. $post = Yii::$app->request->post();
  756. $string = $post['ids'] ?? '';
  757. $ids = json_decode($string, true);
  758. $ids = array_unique(array_filter($ids));
  759. if (empty($ids)) {
  760. util::fail('请选择花材11');
  761. }
  762. $infoList = ItemClass::getAllByCondition(['id' => ['in', $ids]], null, 'id,name,mainId,status,delStatus,removeStatus', null, true);
  763. if (empty($infoList)) {
  764. util::fail('请选择花材哦12');
  765. }
  766. foreach ($infoList as $info) {
  767. if ($info->mainId != $this->mainId) {
  768. util::fail('请选择自己的花材');
  769. }
  770. $info->delStatus = 0;
  771. $info->save();
  772. }
  773. util::complete('操作成功');
  774. }
  775. //批量停用花材 20230206
  776. public function actionBatchStop()
  777. {
  778. $post = Yii::$app->request->post();
  779. $string = $post['ids'] ?? '';
  780. $ids = json_decode($string, true);
  781. $ids = array_unique(array_filter($ids));
  782. if (empty($ids)) {
  783. util::fail('请选择花材13');
  784. }
  785. $infoList = ItemClass::getAllByCondition(['id' => ['in', $ids]], null, 'id,name,mainId,status,delStatus,removeStatus', null, true);
  786. if (empty($infoList)) {
  787. util::fail('请选择花材哦14');
  788. }
  789. foreach ($infoList as $info) {
  790. if ($info->mainId != $this->mainId) {
  791. util::fail('请选择自己的花材');
  792. }
  793. $name = $info->name ?? '';
  794. if ($info->status != 2) {
  795. util::fail($name . ' 下载了才能停用');
  796. }
  797. $info->delStatus = 1;
  798. $info->save();
  799. }
  800. util::complete('操作成功');
  801. }
  802. //获取给散客下单的花材海报 ssh 20220111
  803. public function actionGetSkPoster()
  804. {
  805. $get = Yii::$app->request->get();
  806. $id = $get['id'] ?? 0;
  807. $item = ItemClass::getById($id, true);
  808. if (empty($item) || $item->mainId != $this->mainId) {
  809. util::fail('获取失败');
  810. }
  811. $cover = $item->cover ?? '';
  812. if (empty($cover)) {
  813. util::fail('获取失败');
  814. }
  815. $merchant = WxOpenClass::getMallWxInfo();
  816. $page = 'pages/item/detail';
  817. $ptStyle = dict::getDict('ptStyle', 'mall');
  818. $shop = $this->shop;
  819. $lsShopId = $shop->lsShopId ?? 0;
  820. //scene不能超过32个字条
  821. $scene = "id=" . $id . '&a=' . $lsShopId;
  822. $miniCode = miniUtil::generateUnlimitedMiniCode($merchant, $page, $scene, $ptStyle);
  823. $miniCode = $miniCode . '?x-oss-process=image/resize,m_fill,h_200,w_200';
  824. $miniCodeBase64 = stringUtil::ossBase64($miniCode);
  825. Yii::$app->params['ptStyle'] = dict::getDict('ptStyle', 'hd');
  826. $prefix = imgUtil::getPrefix();
  827. $price = $item->skPrice ?? 0;
  828. if ($item->discountPrice > 0) {
  829. $skMore = $item->skMore ?? 0;
  830. $price = bcadd($item->discountPrice, $skMore, 2);
  831. }
  832. $newPrice = '¥' . floatval($price);
  833. $priceBase64 = stringUtil::ossBase64($newPrice);
  834. $name = $item->name ?? '';
  835. $nameBase64 = stringUtil::ossBase64($name);
  836. $staff = $this->shopAdmin;
  837. $staffName = $staff->name ?? '';
  838. $newStaffName = $staffName . ' 为您推荐';
  839. $staffNameBase64 = stringUtil::ossBase64($newStaffName);
  840. //花材主图
  841. $itemCover = $cover . '?x-oss-process=image/resize,m_fill,h_750,w_750';
  842. $itemCoverBase64 = stringUtil::ossBase64($itemCover);
  843. $logoBase64 = '';
  844. if (in_array($this->mainId, [52, 1459, 13495])) {
  845. $logo = 'poster/hyxh_ncd_logo.png?x-oss-process=image/resize,m_fill,h_90,w_90';
  846. if ($this->mainId == 1459) {
  847. $logo = 'poster/hyxh_gcd_logo.png?x-oss-process=image/resize,m_fill,h_90,w_90';
  848. }
  849. if ($this->mainId == 13495) {
  850. $logo = 'poster/hyxh_hzd_logo.png?x-oss-process=image/resize,m_fill,h_90,w_90';
  851. }
  852. $logoBase64 = stringUtil::ossBase64($logo);
  853. }
  854. $url = $prefix . 'poster/1234.jpg?x-oss-process=image';
  855. //花材主图
  856. $url .= '/watermark,image_' . $itemCoverBase64 . ',g_nw,x_0,y_0';
  857. //小程序码
  858. $url .= '/watermark,image_' . $miniCodeBase64 . ',g_se';
  859. if (!empty($logoBase64)) {
  860. //logo
  861. $url .= '/watermark,image_' . $logoBase64 . ',g_se,x_65,y_65';
  862. }
  863. //为你推荐
  864. $url .= '/watermark,text_' . $staffNameBase64 . ',g_sw,x_18,y_235,color_8B8989,type_d3F5LW1pY3JvaGVp,size_30';
  865. //标题
  866. $url .= '/watermark,text_' . $nameBase64 . ',g_sw,x_18,y_145';
  867. //价格
  868. $url .= '/watermark,text_' . $priceBase64 . ',g_sw,x_18,y_50,color_EE2C2C,type_d3F5LW1pY3JvaGVp,size_50';
  869. $respond = ['imgUrl' => $url];
  870. util::success($respond);
  871. }
  872. //下载商品码,用于花市卖花 ssh 20240823
  873. public function actionDownMiniCode()
  874. {
  875. $get = Yii::$app->request->get();
  876. $id = $get['id'] ?? 0;
  877. $item = ItemClass::getById($id, true);
  878. if (empty($item)) {
  879. util::fail('没有找到花材');
  880. }
  881. if ($item->mainId != $this->mainId) {
  882. util::fail('不是你的花材');
  883. }
  884. $merchant = WxOpenClass::getWxInfo();
  885. $page = 'admin/ghsProduct/detail';
  886. $ptStyle = dict::getDict('ptStyle', 'hd');
  887. //小程序码,scene不能超过32个字条
  888. $scene = "id=" . $id . '&sId=' . $this->shopId;
  889. $miniCode = miniUtil::generateUnlimitedMiniCode($merchant, $page, $scene, $ptStyle);
  890. $miniCode = $miniCode . '?x-oss-process=image/resize,m_fill,h_450,w_450';
  891. $miniCodeBase64 = stringUtil::ossBase64($miniCode);
  892. $prefix = imgUtil::getPrefix();
  893. $url = $prefix . 'poster/mini_bg.jpg?x-oss-process=image';
  894. //小程序码
  895. $url .= '/watermark,image_' . $miniCodeBase64 . ',g_north,x_0,y_25';
  896. $name = $item->name ?? '';
  897. $nameBase64 = stringUtil::ossBase64($name);
  898. //标题
  899. $url .= '/watermark,text_' . $nameBase64 . ',g_south,x_0,y_35';
  900. $file = fopen($url, "rb");
  901. Header("Content-type: application/octet-stream ");
  902. Header("Accept-Ranges: bytes ");
  903. Header("Content-Disposition: attachment;filename={$name}.jpg");
  904. $contents = "";
  905. while (!feof($file)) {
  906. $contents .= fread($file, 8192);
  907. }
  908. echo $contents;
  909. fclose($file);
  910. }
  911. //获取给花店下单的花材海报 ssh 20220111
  912. public function actionGetHdPoster()
  913. {
  914. $get = Yii::$app->request->get();
  915. $id = $get['id'] ?? 0;
  916. $item = ItemClass::getById($id, true);
  917. if (empty($item) || $item->mainId != $this->mainId) {
  918. util::fail('获取失败');
  919. }
  920. $cover = $item->cover ?? '';
  921. if (empty($cover)) {
  922. util::fail('获取失败');
  923. }
  924. $merchant = WxOpenClass::getWxInfo();
  925. $page = 'admin/ghsProduct/detail';
  926. $ptStyle = dict::getDict('ptStyle', 'hd');
  927. //小程序码,scene不能超过32个字条
  928. $scene = "id=" . $id . '&sId=' . $this->shopId;
  929. $miniCode = miniUtil::generateUnlimitedMiniCode($merchant, $page, $scene, $ptStyle);
  930. $miniCode = $miniCode . '?x-oss-process=image/resize,m_fill,h_200,w_200';
  931. $miniCodeBase64 = stringUtil::ossBase64($miniCode);
  932. Yii::$app->params['ptStyle'] = dict::getDict('ptStyle', 'ghs');
  933. $prefix = imgUtil::getPrefix();
  934. $price = $item->price ?? 0;
  935. if ($item->discountPrice > 0) {
  936. $price = $item->discountPrice;
  937. }
  938. $newPrice = '¥' . floatval($price);
  939. $priceBase64 = stringUtil::ossBase64($newPrice);
  940. $name = $item->name ?? '';
  941. $nameBase64 = stringUtil::ossBase64($name);
  942. $staff = $this->shopAdmin;
  943. $staffName = $staff->name ?? '';
  944. $newStaffName = $staffName . ' 为您推荐';
  945. $staffNameBase64 = stringUtil::ossBase64($newStaffName);
  946. //花材主图
  947. $itemCover = $cover . '?x-oss-process=image/resize,m_fill,h_750,w_750';
  948. $itemCoverBase64 = stringUtil::ossBase64($itemCover);
  949. $logoBase64 = '';
  950. if (in_array($this->mainId, [52, 1459, 13495])) {
  951. $logo = 'poster/hyxh_ncd_logo.png?x-oss-process=image/resize,m_fill,h_90,w_90';
  952. if ($this->mainId == 1459) {
  953. $logo = 'poster/hyxh_gcd_logo.png?x-oss-process=image/resize,m_fill,h_90,w_90';
  954. }
  955. if ($this->mainId == 13495) {
  956. $logo = 'poster/hyxh_hzd_logo.png?x-oss-process=image/resize,m_fill,h_90,w_90';
  957. }
  958. $logoBase64 = stringUtil::ossBase64($logo);
  959. }
  960. $url = $prefix . 'poster/1234.jpg?x-oss-process=image';
  961. //花材主图
  962. $url .= '/watermark,image_' . $itemCoverBase64 . ',g_nw,x_0,y_0';
  963. //小程序码
  964. $url .= '/watermark,image_' . $miniCodeBase64 . ',g_se';
  965. if (!empty($logoBase64)) {
  966. //logo
  967. $url .= '/watermark,image_' . $logoBase64 . ',g_se,x_65,y_65';
  968. }
  969. //为你推荐
  970. $url .= '/watermark,text_' . $staffNameBase64 . ',g_sw,x_18,y_235,color_8B8989,type_d3F5LW1pY3JvaGVp,size_30';
  971. //标题
  972. $url .= '/watermark,text_' . $nameBase64 . ',g_sw,x_18,y_145';
  973. //价格
  974. $url .= '/watermark,text_' . $priceBase64 . ',g_sw,x_18,y_50,color_EE2C2C,type_d3F5LW1pY3JvaGVp,size_50';
  975. $respond = ['imgUrl' => $url];
  976. util::success($respond);
  977. }
  978. //是否有C级价格大于B级的 ssh 20221204
  979. public function actionGetErrorPrice()
  980. {
  981. $shop = $this->shop;
  982. $ret = ItemClass::errorPrice($shop);
  983. $list = $ret['data'] ?? [];
  984. $map = $ret['map'] ?? [];
  985. util::success(['list' => $list, 'map' => $map]);
  986. }
  987. //列出所有花材,包括特价花材列表 ssh 20220315
  988. public function actionShowList()
  989. {
  990. $get = Yii::$app->request->get();
  991. $customId = $get['customId'] ?? 0;
  992. $custom = CustomClass::getById($customId, true);
  993. $where['mainId'] = $this->mainId;
  994. $where['delStatus'] = 0;
  995. $where['status'] = 1;
  996. $list = ItemClass::getShowList($where, $custom);
  997. $mainId = $this->mainId;
  998. $get = Yii::$app->request->get();
  999. $isCashier = $get['isCashier'] ?? 0;
  1000. if ($isCashier == 1) {
  1001. //去掉收银台提示价格更新
  1002. $staffId = $this->shopAdminId;
  1003. Yii::$app->redis->executeCommand('DEL', ['ghs_cashier_' . $mainId . '_' . $staffId . '_may_refresh']);
  1004. }
  1005. $productList = [];
  1006. if (!empty($list)) {
  1007. foreach ($list as $key => $item) {
  1008. if (!empty($item)) {
  1009. $productList = array_merge($productList, $item);
  1010. }
  1011. }
  1012. }
  1013. util::success(['list' => $list, 'productList' => $productList]);
  1014. }
  1015. public function actionAdd()
  1016. {
  1017. util::fail('开发中');
  1018. }
  1019. //批量添加花材
  1020. public function actionBatchAdd()
  1021. {
  1022. $shopAdmin = $this->shopAdmin;
  1023. if (isset($shopAdmin->super) == false || $shopAdmin->super != 1) {
  1024. util::fail('超管才能操作');
  1025. }
  1026. $post = Yii::$app->request->post();
  1027. //[{"itemId":"1175","classId":"3548","price":"5","skPrice":"8","cost":"1","name":"卡娜百合"}]
  1028. $data = $post['data'];
  1029. if (empty($data)) {
  1030. util::fail("请选花材");
  1031. }
  1032. $data = json_decode($data, true);
  1033. if (is_array($data) == false || empty($data)) {
  1034. util::fail("请选花材");
  1035. }
  1036. $shop = $this->shop;
  1037. $shopId = $this->shopId;
  1038. $mainId = $this->mainId;
  1039. $sjId = $this->sjId;
  1040. $adminId = $this->adminId;
  1041. $ids = array_column($data, 'itemId');
  1042. $ids = array_unique(array_filter($ids));
  1043. $has = ProductClass::getByCondition(['mainId' => $mainId, 'itemId' => ['in', $ids]]);
  1044. if (!empty($has)) {
  1045. $hasName = $has->name ?? '';
  1046. util::fail($hasName . " 已经添加过了");
  1047. }
  1048. $ptItemInfo = PtItemClass::getAllByCondition(['id' => ['in', $ids]], null, '*', 'id');
  1049. $connection = Yii::$app->db;
  1050. $transaction = $connection->beginTransaction();
  1051. try {
  1052. foreach ($data as $v) {
  1053. $ptItemId = $v['itemId'] ?? 0;
  1054. $ratio = $ptItemInfo[$ptItemId]['ratio'] ?? 20;
  1055. $shelfLife = $ptItemInfo[$ptItemId]['shelfLife'] ?? 7;
  1056. $ratioType = $ptItemInfo[$ptItemId]['ratioType'] ?? 0;
  1057. $variety = $ptItemInfo[$ptItemId]['variety'] ?? 0;
  1058. $stockWarning = $ptItemInfo[$ptItemId]['stockWarning'] ?? 5;
  1059. $weight = $ptItemInfo[$ptItemId]['weight'] ?? 1;
  1060. $bigUnit = $ptItemInfo[$ptItemId]['bigUnit'] ?? '扎';
  1061. $smallUnit = $ptItemInfo[$ptItemId]['smallUnit'] ?? '支';
  1062. $bigUnitId = $ptItemInfo[$ptItemId]['bigUnitId'] ?? 1;
  1063. $smallUnitId = $ptItemInfo[$ptItemId]['smallUnitId'] ?? 2;
  1064. $cover = $ptItemInfo[$ptItemId]['cover'] ?? 'default-img.png';
  1065. $v['ratio'] = $ratio;
  1066. $v['cover'] = $cover;
  1067. $v['shelfLife'] = $shelfLife;
  1068. $v['ratioType'] = $ratioType;
  1069. $v['variety'] = $variety;
  1070. $v['stockWarning'] = $stockWarning;
  1071. $v['weight'] = $weight;
  1072. $v['bigUnit'] = $bigUnit;
  1073. $v['smallUnit'] = $smallUnit;
  1074. $v['bigUnitId'] = $bigUnitId;
  1075. $v['smallUnitId'] = $smallUnitId;
  1076. $v['adminId'] = $adminId;
  1077. $v['sjId'] = $sjId;
  1078. $v['shopId'] = $shopId;
  1079. $v['mainId'] = $mainId;
  1080. $v['staffName'] = $shopAdmin->name ?? '';
  1081. $name = $v['name'] ?? '';
  1082. $price = is_numeric($v['price']) ? $v['price'] : 0;
  1083. $skPrice = is_numeric($v['skPrice']) ? $v['skPrice'] : 0;
  1084. $cost = is_numeric($v['cost']) ? $v['cost'] : 0;
  1085. if ($price <= 0) {
  1086. util::fail("请填写{$name}的批发价");
  1087. }
  1088. if ($skPrice <= 0) {
  1089. util::fail("请填写{$name}的零售价");
  1090. }
  1091. if ($cost <= 0) {
  1092. util::fail("请填写{$name}的成本价");
  1093. }
  1094. if ($price > $skPrice) {
  1095. util::fail("{$name}的批发价比零售价还高");
  1096. }
  1097. if ($cost > $price) {
  1098. util::fail("{$name}的成本价比批发价还高");
  1099. }
  1100. $skMore = bcsub($skPrice, $price, 2);
  1101. $addPrice = bcsub($price, $cost, 2);
  1102. $v['skMore'] = $skMore;
  1103. $v['addPrice'] = $addPrice;
  1104. $v['hjAddPrice'] = $addPrice;
  1105. $v['hjPrice'] = $price;
  1106. ProductClass::addProduct($v, $shop);
  1107. }
  1108. $transaction->commit();
  1109. util::complete('添加成功');
  1110. } catch (Exception $e) {
  1111. $transaction->rollBack();
  1112. util::fail();
  1113. }
  1114. }
  1115. public function actionDelete()
  1116. {
  1117. util::fail('不能删除哦!');
  1118. }
  1119. //获取平台里的花材信息
  1120. public function actionPlatformItem()
  1121. {
  1122. $py = Yii::$app->request->get('py', '');
  1123. $where = [];
  1124. if ($py) {
  1125. $where = ['py' => $py];
  1126. }
  1127. $list = PtItemClass::getItemList($where);
  1128. util::success($list);
  1129. }
  1130. //列出需要进行颜色管理的花材 ssh 20220820
  1131. public function actionColorList()
  1132. {
  1133. $mainId = $this->mainId ?? 0;
  1134. $list = ItemClass::getAllByCondition(['mainId' => $mainId, 'variety' => 1], null, '*');
  1135. util::success(['list' => $list]);
  1136. }
  1137. //多颜色管理启用与停用 ssh 20221229
  1138. public function actionChangeVariety()
  1139. {
  1140. $get = Yii::$app->request->get();
  1141. $id = $get['id'] ?? 0;
  1142. $variety = $get['variety'] ?? 0;
  1143. $info = ItemClass::getById($id, true);
  1144. if (empty($info) || $info->mainId != $this->mainId) {
  1145. util::fail('操作失败');
  1146. }
  1147. $info->variety = $variety;
  1148. $info->save();
  1149. util::complete('操作成功');
  1150. }
  1151. //拆散花材 ssh 20221229
  1152. public function actionBreakItem()
  1153. {
  1154. util::fail('开发中');
  1155. util::complete();
  1156. }
  1157. //批量修改花材的负责人 ssh 20240718
  1158. public function actionChangeCgStaff()
  1159. {
  1160. $get = Yii::$app->request->get();
  1161. $beforeId = $get['beforeId'] ?? 0;
  1162. $newId = $get['newId'] ?? 0;
  1163. if (empty($beforeId) || empty($newId)) {
  1164. util::fail('员工信息有问题');
  1165. }
  1166. $new = ShopAdminClass::getById($newId, true);
  1167. if (empty($new) || $new->mainId != $this->mainId) {
  1168. util::fail('错误的员工信息');
  1169. }
  1170. $before = ShopAdminClass::getById($beforeId, true);
  1171. if (empty($before) || $before->mainId != $this->mainId) {
  1172. util::fail('错误的员工信息2');
  1173. }
  1174. $newName = $new->name ?? '';
  1175. ItemClass::updateByCondition(['mainId' => $this->mainId, 'cgStaffId' => $beforeId], ['cgStaffId' => $newId, 'cgStaffName' => $newName]);
  1176. $shop = $this->shop;
  1177. $bookSn = $shop->bookSn ?? 0;
  1178. if (!empty($bookSn)) {
  1179. BookItemClass::updateByCondition(['bookSn' => $bookSn, 'cgStaffId' => $beforeId], ['cgStaffId' => $newId, 'cgStaffName' => $newName]);
  1180. }
  1181. util::complete('修改成功');
  1182. }
  1183. //获取花材描述
  1184. public function actionDesc()
  1185. {
  1186. $itemId = Yii::$app->request->get('itemId', 0);
  1187. $picText = PicTextGhsItemClass::getByCondition(['mainId' => $this->mainId, 'ghsItemId' => $itemId, 'delStatus' => 0], true);
  1188. if (empty($picText)) {
  1189. // 适配前端的返回处理 -- 本来要使用 util::fail()
  1190. util::success('not_exist');
  1191. }
  1192. if ($picText->mainId != $this->mainId) {
  1193. util::fail('没有找到描述');
  1194. }
  1195. util::success($picText);
  1196. }
  1197. //创建花材描述(花材介绍)
  1198. public function actionCreateDesc()
  1199. {
  1200. $form = new \ghs\models\item\CreateDescForm();
  1201. $form->load(Yii::$app->request->post(), '');
  1202. if (!$form->validateForm()) {
  1203. return;
  1204. }
  1205. $data = $form->attributes;
  1206. $exists = PicTextGhsItemClass::exists(['mainId' => $this->mainId, 'ghsItemId' => $data['itemId'], 'delStatus' => 0]);
  1207. if ($exists) {
  1208. util::fail('该商品已存在图文内容,请勿重复添加');
  1209. }
  1210. $data['mainId'] = $this->mainId;
  1211. $data['ghsItemId'] = $data['itemId'];
  1212. $result = PicTextGhsItemClass::add($data);
  1213. if ($result) {
  1214. util::success($result);
  1215. }
  1216. util::fail('创建失败');
  1217. }
  1218. //更新花材描述(花材介绍)
  1219. public function actionUpdateDesc()
  1220. {
  1221. $form = new \ghs\models\item\CreateDescForm();
  1222. $form->load(Yii::$app->request->post(), '');
  1223. if (!$form->validateForm()) {
  1224. return;
  1225. }
  1226. $data = $form->attributes;
  1227. $id = $data['id'];
  1228. $info = PicTextGhsItemClass::getById($id, false, 'id');
  1229. if (empty($info)) {
  1230. util::fail('描述不存在');
  1231. }
  1232. $data['mainId'] = $this->mainId;
  1233. $result = PicTextGhsItemClass::updateById($id, $data);
  1234. if ($result) {
  1235. util::success($result);
  1236. }
  1237. util::fail('更新失败');
  1238. }
  1239. public function actionChangeVirtualStock()
  1240. {
  1241. $get = Yii::$app->request->get();
  1242. $id = $get['id'] ?? 0;
  1243. $virtualStock = $get['virtualStock'] ?? 0;
  1244. $item = ItemClass::getById($id, true);
  1245. if (empty($item)) {
  1246. util::fail('没有找到花材');
  1247. }
  1248. if ($item->mainId != $this->mainId) {
  1249. util::fail('不是你的花材');
  1250. }
  1251. $item->virtualStock = $virtualStock;
  1252. $item->save();
  1253. util::complete('修改成功');
  1254. }
  1255. }