ItemController.php 42 KB

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