ItemController.php 47 KB

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