ItemController.php 50 KB

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