ItemController.php 41 KB

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