ItemController.php 45 KB

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