ItemController.php 40 KB

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