ProductController.php 73 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796
  1. <?php
  2. /**
  3. * User: admin
  4. * Date Time: 2021/1/15 20:36
  5. */
  6. namespace ghs\controllers;
  7. use biz\admin\classes\AdminRoleClass;
  8. use biz\item\classes\PtItemClass;
  9. use bizGhs\book\classes\BookItemClass;
  10. use bizGhs\cp\classes\CpClass;
  11. use bizGhs\cp\classes\CpItemClass;
  12. use bizGhs\custom\classes\CustomClass;
  13. use bizGhs\item\classes\ItemClassClass;
  14. use bizGhs\item\classes\UnitChangeClass;
  15. use bizGhs\merchant\classes\ShopClass;
  16. use bizGhs\notify\classes\NotifyClass;
  17. use bizGhs\order\classes\CheckOrderClass;
  18. use bizGhs\order\classes\PurchaseOrderClass;
  19. use bizGhs\product\classes\ProductClass;
  20. use bizGhs\product\models\Product;
  21. use bizGhs\product\services\ProductService;
  22. use bizGhs\shop\classes\ShopAdminClass;
  23. use bizGhs\stock\classes\StockInDayClass;
  24. use common\components\imgUtil;
  25. use common\components\noticeUtil;
  26. use common\components\printUtil;
  27. use common\components\stringUtil;
  28. use common\components\util;
  29. use bizGhs\stock\classes\OnStockRecordClass;
  30. use Yii;
  31. class ProductController extends BaseController
  32. {
  33. public $guestAccess = ['index'];
  34. //修改平均成本 ssh 2025114
  35. public function actionModifyAvCost()
  36. {
  37. $get = Yii::$app->request->get();
  38. $id = $get['id'] ?? 0;
  39. $amount = $get['avCost'] ?? 0;
  40. $product = ProductClass::getById($id, true);
  41. if (empty($product)) {
  42. util::fail('没有找到花材');
  43. }
  44. if ($product->mainId != $this->mainId) {
  45. util::fail('不是你的花材');
  46. }
  47. $product->avCost = $amount;
  48. $product->save();
  49. util::complete('修改成功');
  50. }
  51. //修改路上库存 ssh 20231219
  52. public function actionModifyOnStock()
  53. {
  54. $get = Yii::$app->request->get();
  55. $id = $get['id'] ?? 0;
  56. $onStock = $get['onStock'] ?? 0;
  57. $info = ProductClass::getLockById($id);
  58. ProductClass::check($info, $this->mainId);
  59. $oldOnStock = $info->onStock ?? 0;
  60. $newOnStock = $onStock;
  61. $num = bcsub($newOnStock, $oldOnStock);
  62. $num = abs($num);
  63. $staff = $this->shopAdmin;
  64. $staffName = $staff->name ?? '';
  65. $onRecord = [];
  66. $onRecord['sjId'] = $this->sjId;
  67. $onRecord['shopId'] = $this->shopId;
  68. $onRecord['mainId'] = $this->mainId;
  69. $onRecord['orderSn'] = '';
  70. $onRecord['productId'] = $id;
  71. $onRecord['itemId'] = $info->itemId ?? 0;
  72. $onRecord['relateName'] = $staffName;
  73. $onRecord['itemNum'] = $num;
  74. $onRecord['oldStock'] = $oldOnStock;
  75. $onRecord['newStock'] = $newOnStock;
  76. $onRecord['ptStyle'] = 2;
  77. OnStockRecordClass::modify($onRecord);
  78. $info->onStock = $newOnStock;
  79. $info->save();
  80. util::complete('修改成功');
  81. }
  82. //停止预售 ssh 20230224
  83. public function actionCancelPreSell()
  84. {
  85. $get = Yii::$app->request->get();
  86. $id = $get['id'] ?? 0;
  87. $clearStock = $get['clearStock'] ?? -1;
  88. if($clearStock == -1){
  89. util::fail('请选择是否清库存');
  90. }
  91. $info = ProductClass::getById($id, true);
  92. ProductClass::check($info, $this->mainId);
  93. $info->presell = 0;
  94. $info->presellDate = '';
  95. $info->save();
  96. if ($clearStock == 1) {
  97. // 清库存,参考项目里的盘点功能,盘点成0
  98. $staff = $this->shopAdmin;
  99. $modifyData = [
  100. 'remark' => '停止预售清库存',
  101. 'sjId' => $this->sjId,
  102. 'shopId' => $this->shopId,
  103. 'adminId' => $this->adminId,
  104. 'mainId' => $this->mainId,
  105. 'staffName' => $staff->name ?? '',
  106. 'itemInfo' => [['productId' => $id, 'bigNum' => 0, 'smallNum' => 0]],
  107. ];
  108. CheckOrderClass::opOrder($modifyData, false, false);
  109. }
  110. util::complete();
  111. }
  112. //修改预售 ssh 20221214
  113. public function actionChangePresell()
  114. {
  115. $post = Yii::$app->request->post();
  116. $id = $post['id'] ?? 0;
  117. $info = ProductClass::getById($id, true);
  118. ProductClass::check($info, $this->mainId);
  119. try{
  120. $str = $post['date'] ?? '';
  121. $presell = $post['presell'] ?? 0;
  122. $newStr = '';
  123. if ($presell == 1) {
  124. if (empty($str)) {
  125. util::fail('请填写预售日期');
  126. }
  127. $arr = json_decode($str, true);
  128. if (empty($arr)) {
  129. util::fail('请填写预售日期');
  130. }
  131. $new = [];
  132. foreach ($arr as $date) {
  133. $new[] = strtotime($date);
  134. }
  135. $new = array_unique(array_filter($new));
  136. sort($new);
  137. $newStr = implode(',', $new);
  138. //使用redis缓存来保存某用户设置了某花材的预售
  139. $redis = Yii::$app->redis;
  140. $redis->set('product_presell:'.$id, $new[0]);
  141. } else {
  142. $redis = Yii::$app->redis;
  143. if ($redis->exists('product_presell:'.$id)) {
  144. $redis->del('product_presell:'.$id);
  145. }
  146. }
  147. $info->presell = $presell;
  148. $info->presellDate = $newStr;
  149. $info->discountPrice = 0;
  150. $info->save();
  151. }catch(\Exception $e){
  152. // 失败情况,要把缓存删除
  153. if ($presell == 1) {
  154. $redis = Yii::$app->redis;
  155. if ($redis->exists('product_presell:'.$id)) {
  156. $redis->del('product_presell:'.$id);
  157. }
  158. }
  159. }
  160. util::complete();
  161. }
  162. //取消满减 ssh 20231216
  163. public function actionCancelFullOff()
  164. {
  165. $get = Yii::$app->request->get();
  166. $id = $get['id'] ?? 0;
  167. $info = ProductClass::getById($id, true);
  168. ProductClass::check($info, $this->mainId);
  169. $info->reachNum = 0;
  170. $info->reachNumDiscount = 0;
  171. $info->save();
  172. util::complete('取消成功');
  173. }
  174. //取消特价 ssh 20220901
  175. public function actionCancelDiscount()
  176. {
  177. $get = Yii::$app->request->get();
  178. $id = $get['id'] ?? 0;
  179. $info = ProductClass::getById($id, true);
  180. ProductClass::check($info, $this->mainId);
  181. $info->discountPrice = 0;
  182. $info->skDiscountPrice = 0;
  183. $info->hjDiscountPrice = 0;
  184. $info->save();
  185. util::complete('取消成功');
  186. }
  187. //打印花材的标签 ssh 20220602
  188. public function actionPrint()
  189. {
  190. $get = Yii::$app->request->get();
  191. $id = $get['id'] ?? 0;
  192. $num = $get['num'] ?? 1;
  193. $num = floatval($num);
  194. $num = (int)$num;
  195. $type = $get['type'] ?? 0;
  196. $priceOption = $get['priceOption'] ?? 0;
  197. $info = ProductClass::getById($id, true);
  198. if (empty($info)) {
  199. util::fail('没有找到花材');
  200. }
  201. $priceMap = CustomClass::$levelPriceKeyMap;
  202. $addPriceMap = CustomClass::$levelAddPriceKeyMap;
  203. $price = ProductClass::getFinalPrice($info, 0, $priceMap, $addPriceMap);
  204. $price = floatval($price);
  205. $hyPrice = ProductClass::getFinalPrice($info, 1, $priceMap, $addPriceMap);
  206. $hyPrice = floatval($hyPrice);
  207. $name = $info->name ?? '';
  208. $name = preg_replace('/\s{2,}/', ' ', $name ?? '');
  209. $ptItemId = $info->itemId ?? 0;
  210. $mainId = $info->mainId ?? 0;
  211. $ext = $this->shopExt;
  212. $printLabelSn = $ext->printLabelSn ?? '';
  213. if (empty($printLabelSn)) {
  214. util::fail('请设置标签打印机');
  215. }
  216. $p = new printUtil($printLabelSn);
  217. $unit = $info->ratio . $info->smallUnit . '装';
  218. if (isset($info->ratioType) && $info->ratioType == 1) {
  219. $unit = '若干' . $info->smallUnit . '装';
  220. }
  221. $p->times = $num;
  222. if ($priceOption == 2) {
  223. // 每7个汉字截取一次(支持汉字、字母、数字混合),多处需要同步修改,关键词 label_print_substr
  224. $content = '';
  225. $len = mb_strlen($name, 'UTF-8');
  226. $baseNum = 30;
  227. $u = 0;
  228. for ($i = 0; $i < $len; $i += 6) {
  229. $currentName = mb_substr($name, $i, 6, 'UTF-8');
  230. $number = $baseNum + 90 * $u;
  231. $u++;
  232. $content .= '<TEXT x="10" y="' . $number . '" font="12" w="3" h="3" r="0">' . $currentName . '</TEXT>';
  233. }
  234. } else {
  235. if (stringUtil::getWordNum($name) > 8) {
  236. $content = '<TEXT x="30" y="30" font="12" w="1" h="2" r="0">' . $name . '</TEXT>';
  237. } else {
  238. $content = '<TEXT x="30" y="30" font="12" w="2" h="2" r="0">' . $name . '</TEXT>';
  239. }
  240. }
  241. if ($type == 0) {
  242. if ($priceOption != 2) {
  243. //打标签
  244. $content .= '<BC128 x="30" y="115" h="75" s="1" r="0" n="3" w="10">' . $ptItemId . '</BC128>';
  245. if (in_array($mainId, [52, 1459])) {
  246. $content .= '<TEXT x="30" y="250" font="12" w="2" h="2" r="0">惠雅鲜花</TEXT>';
  247. } elseif ($mainId == 16948) {
  248. $content .= '<TEXT x="30" y="250" font="12" w="2" h="2" r="0">淘花里鲜花</TEXT>';
  249. } elseif ($mainId == 72057) {
  250. $content .= '<TEXT x="30" y="250" font="12" w="2" h="2" r="0">淘花里小榄店</TEXT>';
  251. } else {
  252. if ($priceOption == 0) {
  253. $content .= '<TEXT x="30" y="250" font="12" w="2" h="2" r="0">' . $unit . '</TEXT>';
  254. } else {
  255. $content .= '<TEXT x="30" y="250" font="12" w="2" h="2" r="0">' . $unit . ' ' . $price . '元</TEXT>';
  256. }
  257. }
  258. }
  259. } else {
  260. if (getenv('YII_ENV') == 'production') {
  261. $doublePrice = [52, 1459];
  262. } else {
  263. $doublePrice = [];
  264. }
  265. if (in_array($this->mainId, $doublePrice)) {
  266. //惠雅鲜花,打价格,显示正价和会员价,多处同步修改,关键词 hy_print_label_price ssh 20260101
  267. $content .= '<TEXT x="35" y="90" font="12" w="2" h="2" r="0">----------</TEXT>';
  268. $content .= '<TEXT x="35" y="150" font="12" w="2" h="2" r="0">正价 ' . $price . '元</TEXT>';
  269. $content .= '<TEXT x="35" y="230" font="12" w="2" h="2" r="0">会员价 ' . $hyPrice . '元</TEXT>';
  270. } elseif ($this->mainId == 4556) {
  271. //打价格,显示零售价,并且不带元,杭州斗南鲜花不要带元
  272. $content .= '<TEXT x="35" y="150" font="12" w="4" h="4" r="0">' . $price . '</TEXT>';
  273. } else {
  274. $content .= '<TEXT x="35" y="150" font="12" w="4" h="4" r="0">' . $price . '元</TEXT>';
  275. }
  276. }
  277. $p->printLabelMsg($content);
  278. util::complete();
  279. }
  280. //取出今天有入库的花材 ssh 20221024
  281. public function actionStockIn()
  282. {
  283. $py = Yii::$app->request->get('py', '');
  284. $version = Yii::$app->request->get('version', 0);
  285. if ($version == 0) {
  286. util::fail('请先升级版本到1.0.70以上');
  287. }
  288. $classInfo = ItemClassClass::getGhsItemClassAll($this->mainId);
  289. $mainId = $this->mainId ?? 0;
  290. $where['mainId'] = $mainId;
  291. if ($py) {
  292. $pyName = strtolower($py);
  293. $where['py'] = $pyName;
  294. }
  295. $arr = StockInDayClass::getAllByCondition(['mainId' => $mainId], null, '*');
  296. if (empty($arr)) {
  297. util::fail('没有花材需要盘点');
  298. }
  299. $ids = array_column($arr, 'itemId');
  300. $ids = array_unique($ids);
  301. $where['id'] = ['in', $ids];
  302. $level = 1;
  303. $field = 'id,py,cover,name,ratio,cost,addPrice,classId,skMore,skPrice,itemId,smallUnit,smallRatio,presellDate,bigUnit,smallUnit,ratioType,variety,price,stock,stockWarning,discountPrice,presell,presellDate';
  304. $itemInfoData = ProductClass::getAllByCondition($where, ['inTurn' => SORT_DESC, 'actualSold' => SORT_DESC], $field);
  305. $itemInfoData = ProductClass::groupProductInfo($itemInfoData, $level);
  306. $data = ProductService::assembleData($classInfo, $itemInfoData, true);
  307. util::success($data);
  308. }
  309. //按分类列出所有花材
  310. public function actionShow()
  311. {
  312. $py = Yii::$app->request->get('py', '');
  313. $name = Yii::$app->request->get('name', '');
  314. $requestType = Yii::$app->request->get('requestType', 'common');
  315. //默认显示上架商品
  316. $status = Yii::$app->request->get('status', 1);
  317. //默认显示未删除商品
  318. $delStatus = Yii::$app->request->get('delStatus', 0);
  319. $classId = Yii::$app->request->get('classId', 0);
  320. //获取所有当前供货商的分类 (全部、常用)
  321. //根据分类组装分类下的花材信息
  322. //中央ID
  323. $classInfo = ItemClassClass::getGhsItemClassAll($this->mainId);
  324. $where['mainId'] = $this->mainId;
  325. if ($py) {
  326. $pyName = strtolower($py);
  327. $where['py'] = $pyName;
  328. }
  329. //改价和全部有库存花材列表
  330. if ($requestType == 'changePrice' || $requestType == 'hasStockList') {
  331. $where['stock>'] = 0;
  332. }
  333. if (!empty($status)) {
  334. $where['status'] = $status;
  335. if ($requestType == 'itemList') {
  336. unset($where['status']);
  337. }
  338. }
  339. if ($requestType == 'book') {
  340. unset($where['status']);
  341. }
  342. $where['delStatus'] = $delStatus;
  343. if (!empty($classId)) {
  344. $where['classId'] = $classId;
  345. }
  346. if (!empty($name)) {
  347. if (stringUtil::isLetter($name)) {
  348. $name = strtolower($name);
  349. $where['py'] = ['like', $name];
  350. } else {
  351. $where['name'] = ['like', $name];
  352. }
  353. }
  354. if ($requestType == 'hideItem') {
  355. $where['frontHide'] = 1;
  356. }
  357. //客户等级
  358. $customId = Yii::$app->request->get('customId', 0);
  359. $level = 1;
  360. $custom = [];
  361. if (!empty($customId)) {
  362. $custom = CustomClass::getById($customId, true);
  363. $level = $custom->level ?? 1;
  364. }
  365. $itemInfoData = [];
  366. $fieldMap = [
  367. 'hasStockList' => 'id,py,cover,name,classId,itemId,price,skPrice,hjPrice,stock,onStock,cost,avCost,addPrice,hjAddPrice,skMore,limitBuy',
  368. 'hideItem' => 'id,py,cover,name,classId,itemId,price,skPrice,hjPrice,stock,onStock,cost,avCost,addPrice,hjAddPrice,skMore,limitBuy',
  369. 'changePrice' => 'id,py,cover,name,cost,itemId,classId,addPrice,skPrice,hjPrice,discountPrice,hjDiscountPrice,skDiscountPrice,skMore,hjAddPrice,variety,price,stock,onStock,presell,frontHide,reachNum,reachNumDiscount,limitBuy',
  370. 'changeStock' => 'id,py,cover,name,cost,itemId,status,classId,addPrice,skPrice,discountPrice,skMore,variety,price,stock,frontHide,limitBuy',
  371. 'kd' => 'id,py,cover,name,cost,itemId,classId,skPrice,variety,price,hjPrice,hjDiscountPrice,skDiscountPrice,discountPrice,stock,weight,stockWarning,presell,ratioType,smallUnit,smallRatio,bigUnit,ratio,frontHide,reachNum,reachNumDiscount,limitBuy',
  372. 'book' => 'id,py,cover,name,cost,itemId,classId,skPrice,variety,price,hjPrice,hjDiscountPrice,skDiscountPrice,discountPrice,stock,weight,stockWarning,presell,ratioType,smallUnit,smallRatio,bigUnit,ratio,frontHide,limitBuy',
  373. 'itemList' => 'id,py,cover,name,cost,avCost,itemId,classId,skPrice,variety,price,hjPrice,discountPrice,hjDiscountPrice,skDiscountPrice,stock,onStock,actualSold,status,ratio,ratioType,presell,frontHide,auth,reachNum,reachNumDiscount,addPrice,hjAddPrice,skMore,limitBuy',
  374. 'cgStaffList' => 'id,py,cover,name,cost,itemId,classId,skPrice,variety,price,hjPrice,discountPrice,hjDiscountPrice,skDiscountPrice,stock,onStock,actualSold,status,ratio,ratioType,presell,frontHide,auth,reachNum,reachNumDiscount,cgStaffId,cgStaffName,limitBuy',
  375. 'outList' => 'id,py,cover,name,cost,itemId,classId,addPrice,skPrice,bigUnit,smallUnit,ratio,ratioType,discountPrice,skMore,variety,price,stock,presell,status,limitBuy',
  376. 'stopList' => 'id,py,cover,name,cost,itemId,classId,addPrice,skPrice,bigUnit,smallUnit,ratio,ratioType,discountPrice,skMore,variety,price,stock,presell,status,delStatus,limitBuy',
  377. 'removeList' => 'id,py,cover,name,cost,itemId,classId,addPrice,skPrice,bigUnit,smallUnit,ratio,ratioType,discountPrice,skMore,variety,price,stock,presell,status,limitBuy',
  378. 'check' => 'id,py,cover,name,itemId,classId,variety,price,discountPrice,stock,stockWarning,presell,ratioType,smallUnit,bigUnit,ratio,frontHide,limitBuy',
  379. 'break' => 'id,py,cover,name,itemId,classId,variety,price,discountPrice,stock,stockWarning,presell,ratioType,smallUnit,bigUnit,ratio,frontHide,limitBuy',
  380. 'part' => 'id,py,cover,name,itemId,classId,variety,price,discountPrice,stock,stockWarning,presell,ratioType,smallUnit,bigUnit,ratio,limitBuy',
  381. 'stockOut' => 'id,py,cover,name,itemId,classId,variety,price,discountPrice,stock,stockWarning,presell,ratioType,smallUnit,bigUnit,ratio,smallRatio,frontHide,limitBuy',
  382. 'cg' => 'id,py,cover,name,itemId,classId,variety,price,discountPrice,stock,presell,ratioType,smallUnit,bigUnit,ratio,weight,frontHide,limitBuy',
  383. 'warning' => 'id,py,cover,name,cost,itemId,classId,skPrice,variety,price,discountPrice,stock,onStock,actualSold,presell,bigUnit,stockWarning,status,frontHide,limitBuy',
  384. ];
  385. if (!isset($fieldMap[$requestType])) {
  386. util::fail('没有数据');
  387. }
  388. $field = $fieldMap[$requestType];
  389. // 获取数据
  390. if ($requestType == 'warning') {
  391. $itemInfoData = Product::find()->where("mainId={$this->mainId}")
  392. ->andWhere('`stock`+`onStock`<`stockWarning`')
  393. ->andWhere("delStatus=0")
  394. ->select($field)->asArray()->all();
  395. } else {
  396. // 处理特殊的 where 条件
  397. if ($requestType == 'cgStaffList') {
  398. unset($where['status']);
  399. $where['delStatus'] = 0;
  400. } elseif ($requestType == 'outList') {
  401. $where['status'] = 2;
  402. $where['delStatus'] = 0;
  403. $where['removeStatus'] = 0;
  404. } elseif ($requestType == 'stopList') {
  405. unset($where['status']);
  406. $where['delStatus'] = 1;
  407. $where['removeStatus'] = 0;
  408. } elseif ($requestType == 'removeList') {
  409. unset($where['status']);
  410. $where['delStatus'] = 1;
  411. $where['removeStatus'] = 1;
  412. }
  413. $itemInfoData = ProductClass::getAllByCondition($where, ['inTurn' => SORT_DESC, 'actualSold' => SORT_DESC], $field);
  414. }
  415. // 数据后处理
  416. if ($requestType == 'hasStockList') {
  417. if (!empty($itemInfoData)) {
  418. foreach ($itemInfoData as $key => $val) {
  419. $shortCover = $val['cover'] ?? '';
  420. $itemInfoData[$key]['cover'] = imgUtil::groupImg($shortCover) . "?x-oss-process=image/resize,m_fill,h_100,w_100";
  421. $itemInfoData[$key]['shortCover'] = $shortCover;
  422. }
  423. }
  424. } elseif ($requestType == 'changePrice') {
  425. $itemInfoData = ProductClass::changePriceGroup($itemInfoData, $level);
  426. } elseif ($requestType == 'changeStock') {
  427. $itemInfoData = ProductClass::changeStockGroup($itemInfoData, $level);
  428. } elseif ($requestType == 'kd') {
  429. $itemInfoData = ProductClass::kdItemGroup($itemInfoData, $level, $custom);
  430. } elseif ($requestType == 'book') {
  431. $itemInfoData = ProductClass::bookItemGroup($itemInfoData, $level);
  432. } elseif ($requestType == 'itemList') {
  433. $itemInfoData = ProductClass::itemListGroup($itemInfoData, $level);
  434. } elseif ($requestType == 'cgStaffList') {
  435. $itemInfoData = ProductClass::cgStaffListGroup($itemInfoData, $level);
  436. } elseif (in_array($requestType, ['outList', 'stopList', 'removeList'])) {
  437. $itemInfoData = ProductClass::simpleGroup($itemInfoData, $level);
  438. } elseif ($requestType == 'check') {
  439. $itemInfoData = ProductClass::checkItemGroup($itemInfoData, $level);
  440. } elseif ($requestType == 'break') {
  441. $itemInfoData = ProductClass::breakItemGroup($itemInfoData, $level);
  442. } elseif ($requestType == 'part') {
  443. $itemInfoData = ProductClass::partItemGroup($itemInfoData, $level);
  444. } elseif ($requestType == 'stockOut') {
  445. $itemInfoData = ProductClass::stockOutGroup($itemInfoData, $level);
  446. } elseif ($requestType == 'cg') {
  447. $itemInfoData = ProductClass::cgItemGroup($itemInfoData, $level);
  448. } elseif ($requestType == 'warning') {
  449. $itemInfoData = ProductClass::warningGroup($itemInfoData, $level);
  450. }
  451. $data = ProductService::assembleItemData($classInfo, $itemInfoData);
  452. util::success($data);
  453. }
  454. //取出今天有入库的花材 ssh 20221224
  455. public function actionGetStockIn()
  456. {
  457. $py = Yii::$app->request->get('py', '');
  458. $version = Yii::$app->request->get('version', 0);
  459. if ($version == 0) {
  460. util::fail('请先升级版本到1.0.70以上');
  461. }
  462. $classInfo = ItemClassClass::getGhsItemClassAll($this->mainId);
  463. $mainId = $this->mainId ?? 0;
  464. $where['mainId'] = $mainId;
  465. if ($py) {
  466. $pyName = strtolower($py);
  467. $where['py'] = $pyName;
  468. }
  469. $arr = StockInDayClass::getAllByCondition(['mainId' => $mainId], null, '*');
  470. if (empty($arr)) {
  471. util::fail('没有花材需要盘点');
  472. }
  473. $ids = array_column($arr, 'itemId');
  474. $ids = array_unique($ids);
  475. $where['id'] = ['in', $ids];
  476. $level = 1;
  477. $field = 'id,py,cover,name,itemId,classId,variety,price,discountPrice,stock,stockWarning,presell,ratioType,smallUnit,bigUnit,ratio';
  478. $itemInfoData = ProductClass::getAllByCondition($where, ['inTurn' => SORT_DESC, 'actualSold' => SORT_DESC], $field);
  479. $itemInfoData = ProductClass::checkItemGroup($itemInfoData, $level);
  480. $data = ProductService::assembleItemData($classInfo, $itemInfoData);
  481. util::success($data);
  482. }
  483. //按分类列出所有花材
  484. public function actionIndex()
  485. {
  486. $py = Yii::$app->request->get('py', '');
  487. $requestType = Yii::$app->request->get('requestType', 'common');
  488. //默认显示上架商品
  489. $status = Yii::$app->request->get('status', 1);
  490. //默认显示未删除商品
  491. $delStatus = Yii::$app->request->get('delStatus', 0);
  492. $warning = Yii::$app->request->get('warning', 0);
  493. //获取所有当前供货商的分类 (全部、常用)
  494. //根据分类组装分类下的花材信息
  495. //中央ID
  496. $classInfo = ItemClassClass::getGhsItemClassAll($this->mainId);
  497. $where['mainId'] = $this->mainId;
  498. if ($py) {
  499. $pyName = strtolower($py);
  500. $where['py'] = $pyName;
  501. }
  502. if ($requestType == 'hasStock') {
  503. //改价只显示库存大于0的
  504. $where['stock>'] = 0;
  505. }
  506. if (!empty($status)) {
  507. $where['status'] = $status;
  508. }
  509. $where['delStatus'] = $delStatus;
  510. //客户等级
  511. $customId = Yii::$app->request->get('customId', 0);
  512. $level = 1;
  513. if (!empty($customId)) {
  514. $custom = CustomClass::getById($customId, true);
  515. $level = $custom->level ?? 1;
  516. }
  517. if ($warning == 1) {
  518. //库存预警
  519. $field = 'id,py,cover,name,ratio,cost,addPrice,classId,skMore,skPrice,itemId,smallUnit,smallRatio,presellDate,bigUnit,smallUnit,ratioType,variety,price,stock,stockWarning,discountPrice,presell';
  520. $itemInfoData = Product::find()->where("mainId={$this->mainId}")
  521. ->andWhere('`stock`<`stockWarning`')
  522. ->andWhere("delStatus=0")
  523. ->select($field)->asArray()->all();
  524. } else {
  525. $field = 'id,py,cover,name,ratio,cost,addPrice,classId,skMore,skPrice,itemId,smallUnit,smallRatio,presellDate,bigUnit,smallUnit,ratioType,variety,price,stock,stockWarning,discountPrice,presell';
  526. $itemInfoData = ProductClass::getAllByCondition($where, ['inTurn' => SORT_DESC, 'actualSold' => SORT_DESC], $field);
  527. }
  528. $itemInfoData = ProductClass::groupProductInfo($itemInfoData, $level);
  529. $data = ProductService::assembleData($classInfo, $itemInfoData, true);
  530. util::success($data);
  531. }
  532. //所有花材分页和不分页
  533. public function actionList()
  534. {
  535. $get = Yii::$app->request->get();
  536. $where = [];
  537. $classId = Yii::$app->request->get('classId', 0);
  538. if (!empty($classId)) {
  539. $where['classId'] = $classId;
  540. }
  541. $name = Yii::$app->request->get('name', '');
  542. if (empty($name)) {
  543. $py = Yii::$app->request->get('py', '');
  544. $name = !empty($py) ? $py : '';
  545. }
  546. if (!empty($name)) {
  547. if (stringUtil::isLetter($name)) {
  548. $where['py'] = ['like', $name];
  549. } else {
  550. $where['name'] = ['like', $name];
  551. }
  552. }
  553. $status = Yii::$app->request->get('status', 0);
  554. if (!empty($status)) {
  555. $where['status'] = $status;
  556. }
  557. $delStatus = Yii::$app->request->get('delStatus', 0);
  558. if ($delStatus != 2) {
  559. $where['delStatus'] = $delStatus;
  560. }
  561. $where['mainId'] = $this->mainId;
  562. $productIds = Yii::$app->request->get('ids', '');
  563. if (!empty($productIds)) {
  564. $productIdArr = explode(',', $productIds);
  565. if (!empty($productIdArr)) {
  566. $where['id'] = ['in', $productIdArr];
  567. }
  568. }
  569. //输出标准会员价,即批发价,默认显示的是批发价
  570. $level = 1;
  571. $type = Yii::$app->request->get('type', '');
  572. $showPage = Yii::$app->request->get('showPage', 0);
  573. if ($showPage) {
  574. if ($type == 'waring') {
  575. $pro = Product::find()->where("mainId={$this->mainId}")->andWhere('`stock`<`stockWarning`')->select('id')->asArray()->all();
  576. $lackIds = array_column($pro, 'id');
  577. if (empty($lackIds)) {
  578. util::success([]);
  579. }
  580. $lackIds = array_filter(array_unique($lackIds));
  581. $where['id'] = ['in', $lackIds];
  582. $respond = ProductClass::getList("*", $where, "actualSold desc");
  583. } else {
  584. $hasStock = $get['hasStock'] ?? -1;
  585. if ($hasStock == 0) {
  586. $where['stock'] = 0;
  587. }
  588. if ($hasStock == 1) {
  589. $where['stock>'] = 0;
  590. }
  591. $cgStaffId = $get['cgStaffId'] ?? 0;
  592. if (!empty($cgStaffId)) {
  593. $where['cgStaffId'] = $cgStaffId;
  594. }
  595. $respond = ProductClass::getList("*", $where, "inTurn desc");
  596. }
  597. $respond['list'] = ProductClass::groupProductInfo($respond['list'], $level);
  598. $respond['list'] = ProductClass::groupClassName($this->mainId, $respond['list']);
  599. util::success($respond);
  600. } else {
  601. if ($type == 'waring') {
  602. //库存预警 按库存从小到大排序
  603. $data = ProductClass::getAllByCondition($where, ['stock' => SORT_ASC, 'inTurn' => SORT_DESC], "*");
  604. } else {
  605. if (!empty($productIds)) {
  606. //优先按 $productIds 排序 "FIELD(`id`,4,5,6)"=>true
  607. $data = ProductClass::getAllByCondition($where, ["FIELD(`id`,$productIds)" => true, 'inTurn' => SORT_DESC], "*");
  608. } else {
  609. $data = ProductClass::getAllByCondition($where, ['actualSold' => SORT_DESC, 'inTurn' => SORT_DESC], "*");
  610. }
  611. }
  612. $data = ProductClass::groupProductInfo($data, $level);
  613. $data = ProductClass::groupClassName($this->mainId, $data);
  614. if ($type == 'waring') {
  615. //库存预警
  616. $newData = [];
  617. foreach ($data as $v) {
  618. if ($v['stock'] <= $v['stockWarning']) {
  619. $newData[] = $v;
  620. }
  621. }
  622. util::success(['list' => $newData]);
  623. }
  624. util::success(['list' => $data]);
  625. }
  626. }
  627. //所有花材
  628. public function actionAll()
  629. {
  630. $where = [];
  631. $where['mainId'] = $this->mainId;
  632. $classId = Yii::$app->request->get('classId', 0);
  633. if (!empty($classId)) {
  634. $where['classId'] = $classId;
  635. }
  636. $status = Yii::$app->request->get('status', 0);
  637. if (!empty($status)) {
  638. $where['status'] = $status;
  639. }
  640. $delStatus = Yii::$app->request->get('delStatus', 0);
  641. if ($delStatus != 2) {
  642. $where['delStatus'] = $delStatus;
  643. }
  644. //输出标准会员价,即批发价,默认显示的是批发价
  645. $level = 1;
  646. $data = ProductClass::getAllByCondition($where, ['actualSold' => SORT_DESC, 'inTurn' => SORT_DESC], "*");
  647. $data = ProductClass::groupProductInfo($data, $level);
  648. util::success(['list' => $data]);
  649. }
  650. //批量改价
  651. public function actionBatchChangePrice()
  652. {
  653. $shop = $this->shop;
  654. $join = $shop->join ?? 0;
  655. $default = $shop->default ?? 0;
  656. if ($join == 0 && $default == 0) {
  657. //除了小蔡鲜花的蔡总、郑总、苏南3007,其他人直营分店不能改价格,多处要同步修改,关键词 direct_price_change
  658. if (!in_array($this->adminId, [35725, 23659, 29264])) {
  659. util::fail('直营店不能改价');
  660. }
  661. }
  662. $shopAdmin = $this->shopAdmin;
  663. if (!isset($shopAdmin->super) || $shopAdmin->super != 1) {
  664. util::fail('超管才能修改');
  665. }
  666. $shop = $this->shop;
  667. $default = $shop->default ?? 0;
  668. $adminId = $this->adminId ?? 0;
  669. //normal常规改价,cg采购改价
  670. $changeType = Yii::$app->request->post('changeType', 'normal');
  671. $targetId = Yii::$app->request->post('targetId', 0);
  672. $changeParams = ['staffId' => $shopAdmin->id, 'staffName' => $shopAdmin->name, 'changeType' => $changeType, 'targetId' => $targetId];
  673. $post = Yii::$app->request->post();
  674. $data = $post['data'] ?? '';
  675. if (empty($data)) {
  676. util::fail('没有修改');
  677. }
  678. $arr = json_decode($data, true);
  679. if (empty($arr)) {
  680. util::fail('没有修改哦');
  681. }
  682. $appVersion = $post['appVersion'] ?? 0;
  683. if ($appVersion != 1) {
  684. util::fail('请先升级应用');
  685. }
  686. //解决重复请求问题
  687. $cacheKey = 'batch_change_price_' . $targetId;
  688. $has = Yii::$app->redis->executeCommand('GET', [$cacheKey]);
  689. if (!empty($has)) {
  690. util::fail('请5秒后操作');
  691. }
  692. Yii::$app->redis->executeCommand('SETEX', [$cacheKey, 5, 'has']);
  693. $connection = Yii::$app->db;
  694. $transaction = $connection->beginTransaction();
  695. try {
  696. $needNotice = false;
  697. $cg = PurchaseOrderClass::getLockById($targetId);
  698. if (!empty($cg)) {
  699. if (isset($cg->mainId) == false || $cg->mainId != $this->mainId) {
  700. util::fail('不是您的采购单');
  701. }
  702. //批量改价同时入库
  703. if ($cg->status == PurchaseOrderClass::PURCHASE_ORDER_STATUS_SENDING) {
  704. $staff = $this->shopAdmin;
  705. $data = [];
  706. $data['staffId'] = $staff->id ?? 0;
  707. $data['staffName'] = $staff->name ?? '';
  708. $data['adminId'] = $this->adminId ?? 0;
  709. $data['shop'] = $this->shop;
  710. PurchaseOrderClass::putIn($cg, $data);
  711. $needNotice = true;
  712. }
  713. }
  714. $ids = array_column($arr, 'id');
  715. $ids = array_unique(array_filter($ids));
  716. if (empty($ids)) {
  717. util::fail('请选择花材');
  718. }
  719. $sjId = $shop->sjId ?? 0;
  720. $chainShopList = [];
  721. if ($default == 1) {
  722. $chainShopList = ShopClass::getAllByCondition(['sjId' => $sjId, 'join' => 0], null, '*', null, true);
  723. }
  724. $productList = ProductClass::getAllByCondition(['id' => ['in', $ids]], null, '*', 'id', true);
  725. foreach ($arr as $product) {
  726. $productId = $product['id'];
  727. $productInfo = $productList[$productId] ?? [];
  728. if (empty($productInfo)) {
  729. util::fail('没有找到花材');
  730. }
  731. $productName = $productInfo->name ?? '';
  732. if (!isset($product['id'])) {
  733. util::fail('没有花材');
  734. }
  735. if (!isset($product['price']) || !is_numeric($product['price']) || $product['price'] < 0) {
  736. util::fail('请填写' . $productName . '的批发价');
  737. }
  738. $price = $product['price'];
  739. if (!isset($product['skPrice']) || !is_numeric($product['skPrice']) || $product['skPrice'] < 0) {
  740. util::fail('请填写' . $productName . '的零售价');
  741. }
  742. $skPrice = $product['skPrice'];
  743. if (!isset($product['hjPrice']) || !is_numeric($product['hjPrice']) || $product['hjPrice'] < 0) {
  744. util::fail('请填写' . $productName . '的会员价');
  745. }
  746. $hjPrice = $product['hjPrice'] ?? 0;
  747. if (!isset($productInfo->mainId) || $productInfo->mainId != $this->mainId) {
  748. util::fail('无法访问..');
  749. }
  750. if ($hjPrice > $price) {
  751. util::fail($productName . ' 批发价要大于会员价');
  752. }
  753. if ($price > $skPrice) {
  754. util::fail($productName . ' 零售价要大于批发价');
  755. }
  756. $ptItemId = $productInfo->itemId;
  757. ProductClass::changeSinglePrice($shop, $ptItemId, $price, $skPrice, $hjPrice, $changeParams);
  758. //在首店修改需要同步到所有直营店
  759. if ($default == 1 && isset($shop->dataSync) && $shop->dataSync == 1) {
  760. foreach ($chainShopList as $chain) {
  761. if ($chain->id == $shop->id) {
  762. continue;
  763. }
  764. $chainMainId = $chain->mainId ?? 0;
  765. $staff = ShopAdminClass::getByCondition(['mainId' => $chainMainId, 'adminId' => $adminId], true);
  766. $staffId = $staff->id ?? 0;
  767. $staffName = $staff->name ?? '';
  768. $changeParams2 = ['staffId' => $staffId, 'staffName' => $staffName, 'changeType' => $changeType, 'targetId' => $targetId];
  769. ProductClass::changeSinglePrice($chain, $ptItemId, $price, $skPrice, $hjPrice, $changeParams2);
  770. }
  771. }
  772. }
  773. $mainId = $shop->mainId ?? 0;
  774. if (!empty($mainId)) {
  775. //提醒零售收银台界面要刷新,多处要修改,关键词 modify_price_remind_cashier
  776. $staffList = ShopAdminClass::getAllByCondition(['mainId' => $mainId], null, '*', null, true);
  777. if (!empty($staffList)) {
  778. foreach ($staffList as $staff) {
  779. $staffId = $staff->id ?? 0;
  780. Yii::$app->redis->executeCommand('SET', ['cashier_' . $mainId . '_' . $staffId . '_may_refresh', 'yes']);
  781. Yii::$app->redis->executeCommand('SET', ['ghs_cashier_' . $mainId . '_' . $staffId . '_may_refresh', 'yes']);
  782. }
  783. }
  784. }
  785. $transaction->commit();
  786. //入库成功通知相关人员,关键词 put_in_notice
  787. if ($needNotice) {
  788. // $cg = PurchaseOrderClass::getLockById($targetId);
  789. // WxMessageClass::ghsCgEntryInform($shop, $cg);
  790. }
  791. util::complete('操作成功');
  792. } catch (\Exception $e) {
  793. $transaction->rollBack();
  794. $msg = $e->getMessage();
  795. Yii::info("修改失败原因:" . $msg);
  796. noticeUtil::push("修改价格出现失败情况,原因:" . $msg, '15280215347');
  797. util::fail('修改失败');
  798. }
  799. }
  800. //多个花材同时改成一个价 ssh 20231003
  801. public function actionManyItemChangeOnePrice()
  802. {
  803. $shop = $this->shop;
  804. $join = $shop->join ?? 0;
  805. $default = $shop->default ?? 0;
  806. if ($join == 0 && $default == 0) {
  807. util::fail('当前直营分店,只能回总店修改价格');
  808. }
  809. $shopAdmin = $this->shopAdmin;
  810. if (isset($shopAdmin->super) == false || $shopAdmin->super != 1) {
  811. util::fail('超管才能修改');
  812. }
  813. $post = Yii::$app->request->post();
  814. $idsList = $post['ids'] ?? '';
  815. $ids = json_decode($idsList, true);
  816. if (empty($ids)) {
  817. util::fail('请选择花材');
  818. }
  819. $list = ProductClass::getAllByCondition(['id' => ['in', $ids]], null, '*', null, true);
  820. if (empty($list)) {
  821. util::fail('请选择花材哦');
  822. }
  823. $mainId = $this->mainId;
  824. $adminId = $this->adminId ?? 0;
  825. $shop = $this->shop;
  826. $default = $shop->default ?? 0;
  827. $shopAdmin = $this->shopAdmin;
  828. $price = $post['price'] ?? 0;
  829. if (is_numeric($price) == false) {
  830. util::fail('批发价填写错误');
  831. }
  832. $skPrice = $post['skPrice'] ?? 0;
  833. if (is_numeric($skPrice) == false) {
  834. util::fail('散客价填写错误');
  835. }
  836. $hjPrice = $post['hjPrice'] ?? 0;
  837. if (is_numeric($hjPrice) == false) {
  838. util::fail('会员价填写错误');
  839. }
  840. if ($hjPrice > $price) {
  841. util::fail('会员价不能大于批发价');
  842. }
  843. if ($price > $skPrice) {
  844. util::fail('批发价不能大于零售价');
  845. }
  846. $sjId = $shop->sjId ?? 0;
  847. $chainShopList = [];
  848. if ($default == 1) {
  849. $chainShopList = ShopClass::getAllByCondition(['sjId' => $sjId, 'join' => 0], null, '*', null, true);
  850. }
  851. //normal常规改价,cg采购改价
  852. $changeType = Yii::$app->request->post('changeType', 'normal');
  853. $targetId = 0;
  854. $changeParams = ['staffId' => $shopAdmin->id, 'staffName' => $shopAdmin->name, 'changeType' => $changeType, 'targetId' => $targetId];
  855. $connection = Yii::$app->db;
  856. $transaction = $connection->beginTransaction();
  857. try {
  858. foreach ($list as $product) {
  859. if ($product->mainId != $mainId) {
  860. util::fail('修改失败,不是你的花材');
  861. }
  862. $ptItemId = $product->itemId;
  863. ProductClass::changeSinglePrice($shop, $ptItemId, $price, $skPrice, $hjPrice, $changeParams);
  864. //在首店修改需要同步到所有直营店
  865. if ($default == 1 && isset($shop->dataSync) && $shop->dataSync == 1) {
  866. if (!empty($chainShopList)) {
  867. foreach ($chainShopList as $chain) {
  868. if ($chain->id == $shop->id) {
  869. continue;
  870. }
  871. $chainMainId = $chain->mainId ?? 0;
  872. $staff = ShopAdminClass::getByCondition(['mainId' => $chainMainId, 'adminId' => $adminId], true);
  873. $changeParams2 = ['staffId' => $staff->id, 'staffName' => $staff->name, 'changeType' => $changeType, 'targetId' => $targetId];
  874. ProductClass::changeSinglePrice($chain, $ptItemId, $price, $skPrice, $hjPrice, $changeParams2);
  875. }
  876. }
  877. }
  878. }
  879. if (!empty($mainId)) {
  880. //提醒零售收银台界面要刷新,多处要修改,关键词 modify_price_remind_cashier
  881. $staffList = ShopAdminClass::getAllByCondition(['mainId' => $mainId], null, '*', null, true);
  882. if (!empty($staffList)) {
  883. foreach ($staffList as $staff) {
  884. $staffId = $staff->id ?? 0;
  885. Yii::$app->redis->executeCommand('SET', ['cashier_' . $mainId . '_' . $staffId . '_may_refresh', 'yes']);
  886. Yii::$app->redis->executeCommand('SET', ['ghs_cashier_' . $mainId . '_' . $staffId . '_may_refresh', 'yes']);
  887. }
  888. }
  889. }
  890. $transaction->commit();
  891. util::complete('修改成功');
  892. } catch (\Exception $e) {
  893. $transaction->rollBack();
  894. Yii::info("修改失败原因:" . $e->getMessage());
  895. util::fail('修改失败');
  896. }
  897. }
  898. //改价
  899. public function actionChangePrice()
  900. {
  901. $shopAdmin = $this->shopAdmin;
  902. if (isset($shopAdmin->super) == false || $shopAdmin->super != 1) {
  903. util::fail('超管才能修改');
  904. }
  905. $productId = Yii::$app->request->post('productId', 0);
  906. $productInfo = ProductClass::getById($productId, true);
  907. if (empty($productInfo)) {
  908. util::fail("花材不存在");
  909. }
  910. if ($productInfo->mainId != $this->mainId) {
  911. util::fail('没有权限');
  912. }
  913. $price = Yii::$app->request->post('price', '');
  914. if (is_numeric($price) && $price > 0) {
  915. ProductClass::changeSinglePrice($productInfo, $price, ProductClass::PRICE_LABEL_CHANGE);
  916. } else {
  917. $price = bcadd($productInfo->cost, $productInfo->addPrice, 2);
  918. ProductClass::changeSinglePrice($productInfo, $price, ProductClass::PRICE_LABEL_AUTO);
  919. }
  920. util::success(['price' => $price]);
  921. }
  922. //恢复自动调价
  923. public function actionAutoPrice()
  924. {
  925. $productId = Yii::$app->request->post('productId', 0);
  926. $productData = ProductClass::getById($productId);
  927. if (!$productData) {
  928. util::fail("花材不存在");
  929. }
  930. //2021.04.06改为用product中的成本价+加价
  931. $price = bcadd($productData['cost'], $productData['addPrice'], 2);
  932. ProductClass::changeSinglePrice($productId, $this->shopId, $price, ProductClass::PRICE_LABEL_AUTO);
  933. util::complete("操作成功");
  934. }
  935. //修改加价
  936. public function actionChangeAddPrice()
  937. {
  938. $productId = Yii::$app->request->post('productId', 0);
  939. $addPrice = Yii::$app->request->post('addPrice', '');
  940. if ($addPrice < 0) {
  941. util::fail("加价不能小于0");
  942. }
  943. $productData = ProductClass::getProductData($productId, $this->mainId);
  944. if (!$productData) {
  945. util::fail("花材不存在");
  946. }
  947. ProductClass::changeAddPrice($productId, $addPrice);
  948. util::complete();
  949. }
  950. //批量修改更多,包括排序、重量和保质期 ssh 20211211
  951. public function actionBatchChangeMore()
  952. {
  953. $shop = $this->shop;
  954. $default = $shop->default ?? 0;
  955. $join = $shop->join ?? 0;
  956. if ($default == 0 && $join == 0) {
  957. util::fail('当前是直营店,请返回总店修改');
  958. }
  959. $shopAdmin = $this->shopAdmin;
  960. if (isset($shopAdmin->super) == false || $shopAdmin->super != 1) {
  961. util::fail('超管才能操作');
  962. }
  963. $addData = Yii::$app->request->post('addData', '');
  964. if (empty($addData)) {
  965. util::fail('没有花材');
  966. }
  967. $itemData = json_decode($addData, true);
  968. if (is_array($itemData) == false) {
  969. util::fail('没有花材...');
  970. }
  971. $ids = array_column($itemData, 'id');
  972. $infoList = ProductClass::getByIds($ids, null, 'id');
  973. if (empty($infoList)) {
  974. util::fail('没有花材');
  975. }
  976. foreach ($infoList as $info) {
  977. if (isset($info['mainId']) == false || $info['mainId'] != $this->mainId) {
  978. util::fail('不是你的花材不能修改');
  979. }
  980. }
  981. //总店修改同步到所有门店
  982. $sjId = $shop->sjId ?? 0;
  983. $chainShopList = ShopClass::getAllByCondition(['sjId' => $sjId], null, '*', null, true);
  984. foreach ($itemData as $key => $data) {
  985. $id = $data['id'] ?? 0;
  986. unset($data['id']);
  987. ProductClass::updateById($id, $data);
  988. $ptItemId = $infoList[$id]['itemId'] ?? 0;
  989. if (empty($ptItemId)) {
  990. continue;
  991. }
  992. if (isset($shop->default) && $shop->default == 1 && isset($shop->dataSync) && $shop->dataSync == 1) {
  993. foreach ($chainShopList as $chainShop) {
  994. $currentMainId = $chainShop->mainId ?? 0;
  995. if ($currentMainId == $shop->mainId) {
  996. //前面已经修改过了,不需要重复修改
  997. continue;
  998. }
  999. ProductClass::updateByCondition(['mainId' => $currentMainId, 'itemId' => $ptItemId], $data);
  1000. }
  1001. }
  1002. }
  1003. util::complete('修改成功');
  1004. }
  1005. //批量修改加价 ssh 20211211
  1006. public function actionBatchChangeAddPrice()
  1007. {
  1008. $shop = $this->shop;
  1009. $join = $shop->join ?? 0;
  1010. $default = $shop->default ?? 0;
  1011. if ($join == 0 && $default == 0) {
  1012. util::fail('当前直营分店,请切回总店操作');
  1013. }
  1014. $shopAdmin = $this->shopAdmin;
  1015. if (isset($shopAdmin->super) == false || $shopAdmin->super != 1) {
  1016. util::fail('超管才能操作');
  1017. }
  1018. $post = Yii::$app->request->post();
  1019. $addData = $post['addData'] ?? '';
  1020. if (empty($addData)) {
  1021. util::fail('没有花材');
  1022. }
  1023. $itemData = json_decode($addData, true);
  1024. if (is_array($itemData) == false) {
  1025. util::fail('没有花材...');
  1026. }
  1027. $ids = array_column($itemData, 'id');
  1028. $infoList = ProductClass::getByIds($ids, null, 'id');
  1029. if (empty($infoList)) {
  1030. util::fail('没有花材');
  1031. }
  1032. foreach ($infoList as $info) {
  1033. if (isset($info['mainId']) == false || $info['mainId'] != $this->mainId) {
  1034. util::fail('不能修改别人的花材');
  1035. }
  1036. }
  1037. $appVersion = $post['appVersion'] ?? 0;
  1038. if ($appVersion != 1) {
  1039. util::fail('请先升级应用');
  1040. }
  1041. //总店修改同步到所有门店
  1042. $sjId = $shop->sjId ?? 0;
  1043. $chainShopList = ShopClass::getAllByCondition(['sjId' => $sjId], null, '*', null, true);
  1044. foreach ($itemData as $key => $data) {
  1045. $id = $data['id'] ?? 0;
  1046. unset($data['id']);
  1047. ProductClass::updateById($id, $data);
  1048. $ptItemId = $infoList[$id]['itemId'] ?? 0;
  1049. if (empty($ptItemId)) {
  1050. continue;
  1051. }
  1052. if (isset($shop->default) && $shop->default == 1 && isset($shop->dataSync) && $shop->dataSync == 1) {
  1053. foreach ($chainShopList as $chainShop) {
  1054. if (isset($chainShop->join) && $chainShop->join == 1) {
  1055. continue;
  1056. }
  1057. $currentMainId = $chainShop->mainId ?? 0;
  1058. if ($currentMainId == $shop->mainId) {
  1059. //前面已经修改过了,不需要重复修改
  1060. continue;
  1061. }
  1062. ProductClass::updateByCondition(['mainId' => $currentMainId, 'itemId' => $ptItemId], $data);
  1063. }
  1064. }
  1065. }
  1066. util::complete('修改成功');
  1067. }
  1068. public function actionUpdate()
  1069. {
  1070. $shopAdmin = $this->shopAdmin;
  1071. if (!isset($shopAdmin->super) || $shopAdmin->super != 1) {
  1072. util::fail('超管才能操作');
  1073. }
  1074. $shop = $this->shop;
  1075. $join = $shop->join ?? 0;
  1076. $default = $shop->default ?? 0;
  1077. if ($join == 0 && $default == 0) {
  1078. //因为盘点不能将花材盘成0,所以这边放出入口允许创始人在分店修改分店的花材库存
  1079. if ($shopAdmin->super != 1) {
  1080. util::fail('请先开通超管权限');
  1081. }
  1082. }
  1083. $deadline = $shop->deadline;
  1084. $deadTime = strtotime($deadline);
  1085. if (time() > $deadTime) {
  1086. util::fail('系统已到期,编号1689');
  1087. }
  1088. $post = Yii::$app->request->post();
  1089. $discountPrice = $post['discountPrice'] ?? 0;
  1090. if ($discountPrice > 0) {
  1091. if (empty($post['hjDiscountPrice'])) {
  1092. $addPrice = $post['addPrice'] ?? 0;
  1093. $hjAddPrice = $post['hjAddPrice'] ?? 0;
  1094. $skMore = $post['skMore'] ?? 0;
  1095. $diff = bcsub($addPrice, $hjAddPrice, 2);
  1096. if ($diff > 0 && $discountPrice > $diff) {
  1097. $hjDiscountPrice = bcsub($discountPrice, $diff, 2);
  1098. } else {
  1099. $hjDiscountPrice = $discountPrice;
  1100. }
  1101. $diff = bcsub($skMore, $addPrice, 2);
  1102. if ($diff > 0) {
  1103. $skDiscountPrice = bcadd($diff, $discountPrice, 2);
  1104. } else {
  1105. $skDiscountPrice = $discountPrice;
  1106. }
  1107. $post['skDiscountPrice'] = $skDiscountPrice;
  1108. $post['hjDiscountPrice'] = $hjDiscountPrice;
  1109. }
  1110. $reachNum = $post['reachNum'] ?? 0;
  1111. $reachNumDiscount = $post['reachNumDiscount'] ?? 0;
  1112. if ($reachNum > 0 && $reachNumDiscount > 0) {
  1113. util::fail('特价和满减不能同时进行');
  1114. }
  1115. }
  1116. $post['adminId'] = $this->adminId;
  1117. $post['staffId'] = $this->shopAdmin->id;
  1118. $post['staffName'] = $this->shopAdmin->name;
  1119. // 图片列表数组转换为字符串
  1120. if (is_array($post['images'])) {
  1121. $post['images'] = implode(',', $post['images']);
  1122. }
  1123. $connection = Yii::$app->db;
  1124. $transaction = $connection->beginTransaction();
  1125. try {
  1126. ProductClass::updateProduct($post, $this->shop, 'ghs');
  1127. $transaction->commit();
  1128. util::complete();
  1129. } catch (\Exception $e) {
  1130. Yii::info("操作失败:" . $e->getMessage());
  1131. $transaction->rollBack();
  1132. util::fail('操作失败');
  1133. }
  1134. }
  1135. //上下架状态控制 ssh 20210713
  1136. public function actionStatusUpdate()
  1137. {
  1138. $post = Yii::$app->request->post();
  1139. $shopAdmin = $this->shopAdmin;
  1140. $roleId = $shopAdmin['roleId'] ?? 0;
  1141. $role = AdminRoleClass::getById($roleId);
  1142. $roleName = $role['roleName'] ?? '';
  1143. if ($roleName == '员工') {
  1144. util::fail('无法操作哦');
  1145. }
  1146. $id = $post['id'] ?? 0;
  1147. $status = $post['status'] ?? 1;
  1148. $product = ProductClass::getById($id, true);
  1149. if ($product->mainId != $this->mainId) {
  1150. util::fail('无法操作');
  1151. }
  1152. $product->status = $status;
  1153. if ($status == 2) {
  1154. $product->discountPrice = 0;
  1155. }
  1156. $product->save();
  1157. util::complete();
  1158. }
  1159. //花材展示状态控制 ssh 20231113
  1160. public function actionDelStatusUpdate()
  1161. {
  1162. $post = Yii::$app->request->post();
  1163. $shop = $this->shop;
  1164. $join = $shop->join ?? 0;
  1165. $default = $shop->default ?? 0;
  1166. if ($join == 0 && $default == 0) {
  1167. util::fail('请在首店操作');
  1168. }
  1169. $id = $post['id'] ?? 0;
  1170. $delStatus = $post['delStatus'] ?? 0;
  1171. $product = ProductClass::getById($id, true);
  1172. if ($product->mainId != $this->mainId) {
  1173. util::fail('不是你的花材哦!!');
  1174. }
  1175. //扫码收款、直接收款和特价商品,不可删除,多处要同步修改 system_item
  1176. if (getenv('YII_ENV') == 'production') {
  1177. $systemItem = [78076, 80960, 81004];
  1178. } else {
  1179. $systemItem = [11157, 11156, 11158];
  1180. }
  1181. if (in_array($product->itemId, $systemItem)) {
  1182. util::fail('系统使用花材,不可删除');
  1183. }
  1184. $product->delStatus = $delStatus;
  1185. if ($delStatus == 1) {
  1186. $product->stock = 0;
  1187. $product->status = 2;
  1188. }
  1189. $product->save();
  1190. $ptItemId = $product->itemId ?? 0;
  1191. if (isset($shop->default) && $shop->default == 1 && isset($shop->dataSync) && $shop->dataSync == 1) {
  1192. //总店修改同步到所有门店
  1193. $sjId = $shop->sjId ?? 0;
  1194. $chainShopList = ShopClass::getAllByCondition(['sjId' => $sjId], null, '*', null, true);
  1195. foreach ($chainShopList as $chainShop) {
  1196. $chainShopId = $chainShop->id ?? 0;
  1197. if (isset($chainShop->join) && $chainShop->join == 1) {
  1198. continue;
  1199. }
  1200. if ($chainShopId == $shop->id) {
  1201. continue;
  1202. }
  1203. $chainMainId = $chainShop->mainId ?? 0;
  1204. $chainProduct = ProductClass::getByCondition(['mainId' => $chainMainId, 'itemId' => $ptItemId], true);
  1205. if (!empty($chainProduct)) {
  1206. $chainProduct->delStatus = $delStatus;
  1207. if ($delStatus == 1) {
  1208. $chainProduct->stock = 0;
  1209. $chainProduct->status = 2;
  1210. }
  1211. $chainProduct->save();
  1212. }
  1213. }
  1214. }
  1215. util::complete();
  1216. }
  1217. //详情 shish 20240115
  1218. public function actionDetail()
  1219. {
  1220. $id = Yii::$app->request->get('id', 0);
  1221. $source = Yii::$app->request->get('source', '');
  1222. $respond = ProductClass::getItemInfo($id);
  1223. $ptItemId = $respond['itemId'] ?? 0;
  1224. // 封面图与多花材图片的兼容处理
  1225. if ($respond['images'] == '' && $respond['shortCover'] != '') {
  1226. $respond['images'] = $respond['shortCover'];
  1227. }
  1228. $ptItemInfo = PtItemClass::getById($ptItemId);
  1229. $respond['ptItemInfo'] = $ptItemInfo;
  1230. //通知提醒抹除
  1231. if ($source == 'notify' && $respond['mainId'] == $this->mainId) {
  1232. $staff = $this->shopAdmin;
  1233. $staffId = $this->shopAdminId;
  1234. $notify = NotifyClass::getByCondition(['staffId' => $staffId, 'type' => 1, 'targetId' => $id], true);
  1235. if (!empty($notify)) {
  1236. if ($notify->read == 0) {
  1237. $notify->read = 1;
  1238. $notify->save();
  1239. $notifyNum = $staff->notifyNum;
  1240. if ($notifyNum > 0) {
  1241. $notifyNum--;
  1242. $staff->notifyNum = $notifyNum;
  1243. $staff->save();
  1244. }
  1245. }
  1246. }
  1247. }
  1248. //重复花材
  1249. $repeatList = ProductClass::getAllByCondition(['mainId' => $this->mainId, 'itemId' => $ptItemId, 'delStatus' => 0], null, '*', null, true);
  1250. $repeatId = 0;
  1251. if (!empty($repeatList)) {
  1252. foreach ($repeatList as $repeat) {
  1253. if ($repeat->id != $id) {
  1254. $repeatId = $repeat->id;
  1255. }
  1256. }
  1257. }
  1258. $respond['repeatId'] = $repeatId;
  1259. $cpItemList = CpItemClass::getAllByCondition(['productId' => $id], null, '*', 'cpId');
  1260. $cpInfo = [];
  1261. if (!empty($cpItemList)) {
  1262. $cpIds = array_column($cpItemList, 'cpId');
  1263. $cpList = CpClass::getByIds($cpIds);
  1264. if (!empty($cpList)) {
  1265. foreach ($cpList as $key => $val) {
  1266. $id = $val['id'] ?? 0;
  1267. $name = $val['name'] ?? '';
  1268. $cpInfo[] = ['cpId' => $id, 'cpName' => $name];
  1269. }
  1270. }
  1271. }
  1272. //判断这个花材能否被修改单位比和重量,同步参考ShopController actionMyShop方法,关键词has_right_shop_list
  1273. //判断当前登录的人,在自己有财务权限的main里面,是否包括了这个花材所属的平台id,在这个平台id下所有花材的main
  1274. $adminId = $this->adminId;
  1275. $hasRightRespond = ShopAdminClass::changeWeightRight($adminId, $ptItemId);
  1276. $respond['hasRightChange'] = $hasRightRespond['hasRightChange'];
  1277. $respond['hasRightChangeReason'] = $hasRightRespond['reason'];
  1278. //查出拆散的子花材
  1279. $part = UnitChangeClass::getByCondition(['big' => $id], true);
  1280. $partAcceptItem = 0;
  1281. $partAcceptItemName = '';
  1282. if (!empty($part)) {
  1283. $partAcceptItem = $part->small;
  1284. $small = ProductClass::getByCondition(['id' => $partAcceptItem], true, false, 'id,name');
  1285. $partAcceptItemName = $small->name ?? '';;
  1286. }
  1287. $respond['partAcceptItem'] = $partAcceptItem;
  1288. $respond['partAcceptItemName'] = $partAcceptItemName;
  1289. $respond['cpInfo'] = $cpInfo;
  1290. util::success($respond);
  1291. }
  1292. //新增花材 2021.6.21
  1293. public function actionAdd()
  1294. {
  1295. $post = Yii::$app->request->post();
  1296. $discountPrice = $post['discountPrice'] ?? 0;
  1297. if ($discountPrice > 0) {
  1298. if (isset($post['hjDiscountPrice']) == false || empty($post['hjDiscountPrice'])) {
  1299. $addPrice = $post['addPrice'] ?? 0;
  1300. $hjAddPrice = $post['hjAddPrice'] ?? 0;
  1301. $skMore = $post['skMore'] ?? 0;
  1302. $diff = bcsub($addPrice, $hjAddPrice, 2);
  1303. if ($diff > 0 && $discountPrice > $diff) {
  1304. $hjDiscountPrice = bcsub($discountPrice, $diff, 2);
  1305. } else {
  1306. $hjDiscountPrice = $discountPrice;
  1307. }
  1308. $diff = bcsub($skMore, $addPrice, 2);
  1309. if ($diff > 0) {
  1310. $skDiscountPrice = bcadd($diff, $discountPrice, 2);
  1311. } else {
  1312. $skDiscountPrice = $discountPrice;
  1313. }
  1314. $post['skDiscountPrice'] = $skDiscountPrice;
  1315. $post['hjDiscountPrice'] = $hjDiscountPrice;
  1316. }
  1317. }
  1318. $shop = $this->shop;
  1319. $join = $shop->join ?? 0;
  1320. $default = $shop->default ?? 0;
  1321. if ($join == 0 && $default == 0) {
  1322. util::fail('当前直营分店,请切回总店添加花材');
  1323. }
  1324. $shopAdmin = $this->shopAdmin;
  1325. if (!isset($shopAdmin->super) || $shopAdmin->super != 1) {
  1326. util::fail('管理员才能添加花材');
  1327. }
  1328. $post['sjId'] = $this->sjId;
  1329. $post['adminId'] = $this->adminId;
  1330. $post['mainId'] = $this->mainId;
  1331. $price = $post['price'] ?? 0;
  1332. $addPrice = $post['addPrice'] ?? 0;
  1333. if ($addPrice > $price) {
  1334. //客户添加花材时,经常会出现加价大于售价的怦,这个时候就直接把加价全部设置为0
  1335. $post['addPrice'] = 0;
  1336. $post['hjAddPrice'] = 0;
  1337. $post['skMore'] = 0;
  1338. //util::fail('加价不能大于售价');
  1339. }
  1340. $weight = isset($post['weight']) && is_numeric($post['weight']) ? $post['weight'] : 0;
  1341. if ($weight <= 0) {
  1342. util::fail('请填写重量,最小0.1');
  1343. }
  1344. $post['staffName'] = $shopAdmin->name ?? '';
  1345. // 图片列表数组转换为字符串
  1346. if (is_array($post['images'])) {
  1347. $post['images'] = implode(',', $post['images']);
  1348. }
  1349. ProductClass::addProduct($post, $this->shop);
  1350. util::complete('添加成功');
  1351. }
  1352. //获取拼音缩写 ssh 20210707
  1353. public function actionPy()
  1354. {
  1355. $name = Yii::$app->request->get('name');
  1356. $py = stringUtil::py($name);
  1357. util::success(['py' => $py]);
  1358. }
  1359. //(客户端-批发商)复制花材
  1360. public function actionClone()
  1361. {
  1362. $post = Yii::$app->request->post();
  1363. $discountPrice = $post['discountPrice'] ?? 0;
  1364. if ($discountPrice > 0) {
  1365. if (isset($post['hjDiscountPrice']) == false || empty($post['hjDiscountPrice'])) {
  1366. $addPrice = $post['addPrice'] ?? 0;
  1367. $hjAddPrice = $post['hjAddPrice'] ?? 0;
  1368. $skMore = $post['skMore'] ?? 0;
  1369. $diff = bcsub($addPrice, $hjAddPrice, 2);
  1370. if ($diff > 0 && $discountPrice > $diff) {
  1371. $hjDiscountPrice = bcsub($discountPrice, $diff, 2);
  1372. } else {
  1373. $hjDiscountPrice = $discountPrice;
  1374. }
  1375. $diff = bcsub($skMore, $addPrice, 2);
  1376. if ($diff > 0) {
  1377. $skDiscountPrice = bcadd($diff, $discountPrice, 2);
  1378. } else {
  1379. $skDiscountPrice = $discountPrice;
  1380. }
  1381. $post['skDiscountPrice'] = $skDiscountPrice;
  1382. $post['hjDiscountPrice'] = $hjDiscountPrice;
  1383. }
  1384. }
  1385. $shop = $this->shop;
  1386. $join = $shop->join ?? 0;
  1387. $default = $shop->default ?? 0;
  1388. if ($join == 0 && $default == 0) {
  1389. util::fail('请在首店操作');
  1390. }
  1391. $shopAdmin = $this->shopAdmin;
  1392. if (isset($shopAdmin->super) == false || $shopAdmin->super != 1) {
  1393. util::fail('管理员才能添加花材');
  1394. }
  1395. $post['sjId'] = $this->sjId;
  1396. $post['adminId'] = $this->adminId;
  1397. $post['mainId'] = $this->mainId;
  1398. $post['staffName'] = $shopAdmin->name ?? '';
  1399. $price = $post['price'] ?? 0;
  1400. if (empty($price) || $price <= 0) {
  1401. util::fail('请填写批发价');
  1402. }
  1403. $skPrice = $post['skPrice'] ?? 0;
  1404. if (empty($skPrice) || $skPrice <= 0) {
  1405. util::fail('请填写零售价');
  1406. }
  1407. $hjPrice = $post['hjPrice'] ?? 0;
  1408. if (empty($hjPrice) || $hjPrice <= 0) {
  1409. util::fail('请填写会员价');
  1410. }
  1411. $addPrice = $post['addPrice'] ?? 0;
  1412. if ($addPrice > $price) {
  1413. util::fail('批发价的加价不能大于售价');
  1414. }
  1415. // 图片列表数组转换为字符串
  1416. if (is_array($post['images'])) {
  1417. $post['images'] = implode(',', $post['images']);
  1418. }
  1419. //复制标识
  1420. $post['copy'] = 1;
  1421. //去除无用的字段
  1422. unset($post['viewNum']);
  1423. unset($post['actualSold']);
  1424. unset($post['itemId']);
  1425. unset($post['id']);
  1426. unset($post['delStatus']);
  1427. unset($post['variety']);
  1428. ProductClass::addProduct($post, $this->shop);
  1429. util::complete('复制成功');
  1430. }
  1431. //下载价格表 ssh 20210922
  1432. public function actionGeneratePriceTable()
  1433. {
  1434. $level = Yii::$app->request->get('level', 0);
  1435. $respond = ProductService::generatePriceTable($this->sjId, $level, $this->mainId);
  1436. $file = $respond['file'] ?? '';
  1437. $shortFile = $respond['shortFile'] ?? '';
  1438. $fileUrl = Yii::$app->params['ghsHost'] . $file;
  1439. util::success(['file' => $fileUrl, 'shortFile' => $shortFile]);
  1440. }
  1441. //下载有库存花材,不含虚拟库存 ssh 20241-28
  1442. public function actionGenerateStockTable()
  1443. {
  1444. $level = Yii::$app->request->get('level', 0);
  1445. $respond = ProductService::generateStockTable($this->sjId, $level, $this->mainId);
  1446. $file = $respond['file'] ?? '';
  1447. $shortFile = $respond['shortFile'] ?? '';
  1448. $fileUrl = Yii::$app->params['ghsHost'] . $file;
  1449. util::success(['file' => $fileUrl, 'shortFile' => $shortFile]);
  1450. }
  1451. public function actionGenerateItemTable()
  1452. {
  1453. $level = Yii::$app->request->get('level', 0);
  1454. $respond = ProductService::generateItemTable($this->sjId, $level, $this->mainId);
  1455. $file = $respond['file'] ?? '';
  1456. $shortFile = $respond['shortFile'] ?? '';
  1457. $fileUrl = Yii::$app->params['ghsHost'] . $file;
  1458. util::success(['file' => $fileUrl, 'shortFile' => $shortFile]);
  1459. }
  1460. //下载条形码 lqh 20211227
  1461. public function actionGenerateBarcodeTable()
  1462. {
  1463. $respond = ProductService::generateBarcodeTable($this->sjId, $this->shopId, $this->mainId);
  1464. $file = $respond['file'] ?? '';
  1465. $shortFile = $respond['shortFile'] ?? '';
  1466. $fileUrl = Yii::$app->params['ghsHost'] . $file;
  1467. util::success(['file' => $fileUrl, 'shortFile' => $shortFile]);
  1468. }
  1469. //批量修改花材的分类 ssh 20230405
  1470. public function actionBatchModifyClass()
  1471. {
  1472. $post = Yii::$app->request->post();
  1473. $shop = $this->shop;
  1474. $sjName = $shop->merchantName ?? '';
  1475. $shopName = $shop->shopName ?? '';
  1476. $sjShopName = $shop->shopName == '首店' ? $sjName : $sjName . ' ' . $shopName;
  1477. //noticeUtil::push($sjShopName . ' 批量移动花材分类', '15280215347');
  1478. $join = $shop->join ?? 0;
  1479. $default = $shop->default ?? 0;
  1480. if ($join == 0 && $default == 0) {
  1481. util::fail('当前直营分店,请切回总店操作');
  1482. }
  1483. $classId = $post['classId'] ?? 0;
  1484. $class = ItemClassClass::getById($classId, true);
  1485. if (empty($class) || $class->mainId != $this->mainId) {
  1486. util::fail('请选择您自己的分类');
  1487. }
  1488. $connection = Yii::$app->db;
  1489. $transaction = $connection->beginTransaction();
  1490. try {
  1491. $className = $class->name ?? '';
  1492. $idsList = $post['ids'] ?? '';
  1493. $ids = json_decode($idsList, true);
  1494. if (empty($ids)) {
  1495. util::fail('请选择花材');
  1496. }
  1497. $list = ProductClass::getAllByCondition(['id' => ['in', $ids]], null, '*', null, true);
  1498. if (empty($list)) {
  1499. util::fail('请选择花材');
  1500. }
  1501. $ptItemList = [];
  1502. foreach ($list as $item) {
  1503. $name = $item->name ?? '';
  1504. if ($item->mainId != $this->mainId) {
  1505. util::fail($name . '不是您的花材');
  1506. }
  1507. $item->classId = $classId;
  1508. $item->save();
  1509. $ptItemId = $item->itemId ?? 0;
  1510. $ptItemList[] = $ptItemId;
  1511. //如果有修改分类,则在多个订单表中同步修改,如需修改,多个地方要同步修改,请搜索关键词item_class_modify_sync
  1512. $itemClassKey = 'item_class_modify_sync';
  1513. Yii::$app->redis->executeCommand('LPUSH', [$itemClassKey, $item->id]);
  1514. }
  1515. $shop = $this->shop;
  1516. if (isset($shop->default) && $shop->default == 1 && isset($shop->dataSync) && $shop->dataSync == 1) {
  1517. //总店修改同步到所有门店
  1518. $sjId = $shop->sjId ?? 0;
  1519. $chainShopList = ShopClass::getAllByCondition(['sjId' => $sjId], null, '*', null, true);
  1520. foreach ($chainShopList as $chainShop) {
  1521. $chainShopId = $chainShop->id ?? 0;
  1522. if ($chainShopId == $shop->id) {
  1523. continue;
  1524. }
  1525. $chainManId = $chainShop->mainId ?? 0;
  1526. $chainAllClassList = ItemClassClass::getAllByCondition(['mainId' => $chainManId], null, '*', null, true);
  1527. if (!empty($chainAllClassList)) {
  1528. foreach ($chainAllClassList as $chainClass) {
  1529. $chainName = $chainClass->name ?? '';
  1530. $chainClassId = $chainClass->id ?? 0;
  1531. if ($chainName == $className) {
  1532. $chainProductList = Productclass::getAllByCondition(['mainId' => $chainManId, 'itemId' => ['in', $ptItemList]], null, '*', null, true);
  1533. if (!empty($chainProductList)) {
  1534. foreach ($chainProductList as $currentProduct) {
  1535. $currentProduct->classId = $chainClassId;
  1536. $currentProduct->save();
  1537. //如果有修改分类,则在多个订单表中同步修改,如需修改,多个地方要同步修改,请搜索关键词item_class_modify_sync
  1538. $itemClassKey = 'item_class_modify_sync';
  1539. Yii::$app->redis->executeCommand('LPUSH', [$itemClassKey, $currentProduct->id]);
  1540. }
  1541. }
  1542. }
  1543. }
  1544. }
  1545. }
  1546. }
  1547. $transaction->commit();
  1548. util::complete('修改成功');
  1549. } catch (\Exception $e) {
  1550. $transaction->rollBack();
  1551. Yii::info("修改失败原因:" . $e->getMessage());
  1552. util::fail('修改失败');
  1553. }
  1554. }
  1555. //批量修改采购人 ssh 20240609
  1556. public function actionBatchModifyCgStaff()
  1557. {
  1558. $post = Yii::$app->request->post();
  1559. $staffId = $post['staffId'] ?? 0;
  1560. $staff = ShopAdminClass::getById($staffId, true);
  1561. if (empty($staff)) {
  1562. util::fail('没有找到这个员工');
  1563. }
  1564. if ($staff->mainId != $this->mainId) {
  1565. util::fail('不是你的员工');
  1566. }
  1567. $staffName = $staff->name ?? '';
  1568. $connection = Yii::$app->db;
  1569. $transaction = $connection->beginTransaction();
  1570. try {
  1571. $idsList = $post['ids'] ?? '';
  1572. $ids = json_decode($idsList, true);
  1573. if (empty($ids)) {
  1574. util::fail('请选择花材');
  1575. }
  1576. $list = ProductClass::getAllByCondition(['id' => ['in', $ids]], null, '*', null, true);
  1577. if (empty($list)) {
  1578. util::fail('请选择花材');
  1579. }
  1580. $shop = $this->shop;
  1581. $bookSn = $shop->bookSn ?? 0;
  1582. foreach ($list as $item) {
  1583. $name = $item->name ?? '';
  1584. if ($item->mainId != $this->mainId) {
  1585. util::fail($name . '不是您的花材');
  1586. }
  1587. $item->cgStaffId = $staffId;
  1588. $item->cgStaffName = $staffName;
  1589. $item->save();
  1590. $itemId = $item->id ?? 0;
  1591. if (!empty($bookSn)) {
  1592. //预订管理的花材需要变化
  1593. BookItemClass::updateByCondition(['bookSn' => $bookSn, 'itemId' => $itemId], ['cgStaffId' => $staffId, 'cgStaffName' => $staffName]);
  1594. }
  1595. }
  1596. $transaction->commit();
  1597. util::complete('修改成功');
  1598. } catch (\Exception $e) {
  1599. $transaction->rollBack();
  1600. Yii::info("修改失败原因:" . $e->getMessage());
  1601. util::fail('修改失败');
  1602. }
  1603. }
  1604. //修改属于成本还是收入选项 ssh 20240514
  1605. public function actionChangeBelongCost()
  1606. {
  1607. $get = Yii::$app->request->get();
  1608. $id = $get['id'] ?? 0;
  1609. $belongCost = $get['belongCost'] ?? 0;
  1610. $info = ProductClass::getById($id, true);
  1611. if (empty($info)) {
  1612. util::fail('没有找到花材');
  1613. }
  1614. if ($info->mainId != $this->mainId) {
  1615. util::fail('不是你的花材哦');
  1616. }
  1617. $info->belongCost = $belongCost;
  1618. $info->save();
  1619. //队列方式去处理
  1620. $redisKey = 'change_belong_cost_item_list';
  1621. $value = $id . '_' . $belongCost;
  1622. Yii::$app->redis->executeCommand('LPUSH', [$redisKey, $value]);
  1623. util::complete('修改成功');
  1624. }
  1625. //修改拆散接收的花材 ssh 20251124
  1626. public function actionModifyPartAcceptItem()
  1627. {
  1628. $get = Yii::$app->request->get();
  1629. $smallId = $get['small'] ?? 0;
  1630. $bigId = $get['big'] ?? 0;
  1631. $small = ProductClass::getById($smallId, true);
  1632. if (empty($small)) {
  1633. util::fail('子花材没找到');
  1634. }
  1635. $smallName = $small->name ?? '';
  1636. if ($small->mainId != $this->mainId) {
  1637. util::fail($smallName . '不是你的花材');
  1638. }
  1639. if ($small->ratio != 1) {
  1640. util::fail($smallName . '不是1支装的');
  1641. }
  1642. $big = ProductClass::getById($bigId, true);
  1643. if (empty($big)) {
  1644. util::fail('没有找到花材');
  1645. }
  1646. if ($big->mainId != $this->mainId) {
  1647. util::fail('不是你的花材呢');
  1648. }
  1649. $change = UnitChangeClass::getByCondition(['big' => $bigId], true);
  1650. if (empty($change)) {
  1651. UnitChangeClass::add(['big' => $bigId, 'small' => $smallId], true);
  1652. } else {
  1653. $change->small = $smallId;
  1654. $change->save();
  1655. }
  1656. util::complete('修改成功');
  1657. }
  1658. }