ItemController.php 40 KB

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