ItemController.php 41 KB

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