ItemController.php 40 KB

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