ItemController.php 50 KB

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