ProductController.php 75 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808
  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. if ($requestType == 'hasStockList') {
  367. //有库存的花材列表
  368. $field = 'id,py,cover,name,classId,itemId,price,skPrice,hjPrice,stock,onStock,cost,avCost,addPrice,hjAddPrice,skMore';
  369. $itemInfoData = ProductClass::getAllByCondition($where, ['inTurn' => SORT_DESC, 'actualSold' => SORT_DESC], $field);
  370. if (!empty($itemInfoData)) {
  371. foreach ($itemInfoData as $key => $val) {
  372. //以下参数主要是网页批量改价要用到
  373. $shortCover = $val['cover'] ?? '';
  374. $itemInfoData[$key]['cover'] = imgUtil::groupImg($shortCover) . "?x-oss-process=image/resize,m_fill,h_100,w_100";
  375. $itemInfoData[$key]['shortCover'] = $shortCover;
  376. }
  377. }
  378. } elseif ($requestType == 'hideItem') {
  379. //隐藏花材列表
  380. $field = 'id,py,cover,name,classId,itemId,price,skPrice,hjPrice,stock,onStock,cost,avCost,addPrice,hjAddPrice,skMore';
  381. $itemInfoData = ProductClass::getAllByCondition($where, ['inTurn' => SORT_DESC, 'actualSold' => SORT_DESC], $field);
  382. } elseif ($requestType == 'changePrice') {
  383. $field = 'id,py,cover,name,cost,itemId,classId,addPrice,skPrice,hjPrice,discountPrice,hjDiscountPrice,skDiscountPrice,skMore,hjAddPrice,addPrice,variety,price,hjPrice,stock,onStock,presell,frontHide,reachNum,reachNumDiscount';
  384. $itemInfoData = ProductClass::getAllByCondition($where, ['inTurn' => SORT_DESC, 'actualSold' => SORT_DESC], $field);
  385. $itemInfoData = ProductClass::changePriceGroup($itemInfoData, $level);
  386. } elseif ($requestType == 'changeStock') {
  387. //修改库存列表
  388. $field = 'id,py,cover,name,cost,itemId,status,classId,addPrice,skPrice,discountPrice,skMore,variety,price,stock,frontHide';
  389. $itemInfoData = ProductClass::getAllByCondition($where, ['inTurn' => SORT_DESC, 'actualSold' => SORT_DESC], $field);
  390. $itemInfoData = ProductClass::changeStockGroup($itemInfoData, $level);
  391. } elseif ($requestType == 'kd') {
  392. //开单的花材列表
  393. $field = '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';
  394. $itemInfoData = ProductClass::getAllByCondition($where, ['inTurn' => SORT_DESC, 'actualSold' => SORT_DESC], $field);
  395. $itemInfoData = ProductClass::kdItemGroup($itemInfoData, $level, $custom);
  396. } elseif ($requestType == 'book') {
  397. //预订花材列表
  398. $field = 'id,py,cover,name,cost,itemId,classId,skPrice,variety,price,hjPrice,hjDiscountPrice,skDiscountPrice,discountPrice,stock,weight,stockWarning,presell,ratioType,smallUnit,smallRatio,bigUnit,ratio,frontHide';
  399. $itemInfoData = ProductClass::getAllByCondition($where, ['inTurn' => SORT_DESC, 'actualSold' => SORT_DESC], $field);
  400. $itemInfoData = ProductClass::bookItemGroup($itemInfoData, $level);
  401. } elseif ($requestType == 'itemList') {
  402. //花材列表
  403. $field = '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';
  404. $itemInfoData = ProductClass::getAllByCondition($where, ['inTurn' => SORT_DESC, 'actualSold' => SORT_DESC], $field);
  405. $itemInfoData = ProductClass::itemListGroup($itemInfoData, $level);
  406. } elseif ($requestType == 'cgStaffList') {
  407. unset($where['status']);
  408. $where['delStatus'] = 0;
  409. $field = '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';
  410. $itemInfoData = ProductClass::getAllByCondition($where, ['inTurn' => SORT_DESC, 'actualSold' => SORT_DESC], $field);
  411. $itemInfoData = ProductClass::cgStaffListGroup($itemInfoData, $level);
  412. } elseif ($requestType == 'outList') {
  413. //下架花材列表
  414. $where['status'] = 2;
  415. $where['delStatus'] = 0;
  416. $where['removeStatus'] = 0;
  417. $field = 'id,py,cover,name,cost,itemId,classId,addPrice,skPrice,bigUnit,smallUnit,ratio,ratioType,discountPrice,skMore,variety,price,stock,presell,status';
  418. $itemInfoData = ProductClass::getAllByCondition($where, ['inTurn' => SORT_DESC, 'actualSold' => SORT_DESC], $field);
  419. $itemInfoData = ProductClass::simpleGroup($itemInfoData, $level);
  420. } elseif ($requestType == 'stopList') {
  421. //停用花材列表
  422. unset($where['status']);
  423. $where['delStatus'] = 1;
  424. $where['removeStatus'] = 0;
  425. $field = 'id,py,cover,name,cost,itemId,classId,addPrice,skPrice,bigUnit,smallUnit,ratio,ratioType,discountPrice,skMore,variety,price,stock,presell,status,delStatus';
  426. $itemInfoData = ProductClass::getAllByCondition($where, ['inTurn' => SORT_DESC, 'actualSold' => SORT_DESC], $field);
  427. $itemInfoData = ProductClass::simpleGroup($itemInfoData, $level);
  428. } elseif ($requestType == 'removeList') {
  429. //删除花材列表
  430. unset($where['status']);
  431. $where['delStatus'] = 1;
  432. $where['removeStatus'] = 1;
  433. $field = 'id,py,cover,name,cost,itemId,classId,addPrice,skPrice,bigUnit,smallUnit,ratio,ratioType,discountPrice,skMore,variety,price,stock,presell,status';
  434. $itemInfoData = ProductClass::getAllByCondition($where, ['inTurn' => SORT_DESC, 'actualSold' => SORT_DESC], $field);
  435. $itemInfoData = ProductClass::simpleGroup($itemInfoData, $level);
  436. } elseif ($requestType == 'check') {
  437. $field = 'id,py,cover,name,itemId,classId,variety,price,discountPrice,stock,stockWarning,presell,ratioType,smallUnit,bigUnit,ratio,frontHide';
  438. $itemInfoData = ProductClass::getAllByCondition($where, ['inTurn' => SORT_DESC, 'actualSold' => SORT_DESC], $field);
  439. $itemInfoData = ProductClass::checkItemGroup($itemInfoData, $level);
  440. } elseif ($requestType == 'break') {
  441. $field = 'id,py,cover,name,itemId,classId,variety,price,discountPrice,stock,stockWarning,presell,ratioType,smallUnit,bigUnit,ratio,frontHide';
  442. $itemInfoData = ProductClass::getAllByCondition($where, ['inTurn' => SORT_DESC, 'actualSold' => SORT_DESC], $field);
  443. $itemInfoData = ProductClass::breakItemGroup($itemInfoData, $level);
  444. } elseif ($requestType == 'part') {
  445. //拆散花材
  446. $field = 'id,py,cover,name,itemId,classId,variety,price,discountPrice,stock,stockWarning,presell,ratioType,smallUnit,bigUnit,ratio';
  447. $itemInfoData = ProductClass::getAllByCondition($where, ['inTurn' => SORT_DESC, 'actualSold' => SORT_DESC], $field);
  448. $itemInfoData = ProductClass::partItemGroup($itemInfoData, $level);
  449. } elseif ($requestType == 'stockOut') {
  450. $field = 'id,py,cover,name,itemId,classId,variety,price,discountPrice,stock,stockWarning,presell,ratioType,smallUnit,bigUnit,ratio,smallRatio,frontHide';
  451. $itemInfoData = ProductClass::getAllByCondition($where, ['inTurn' => SORT_DESC, 'actualSold' => SORT_DESC], $field);
  452. $itemInfoData = ProductClass::stockOutGroup($itemInfoData, $level);
  453. } elseif ($requestType == 'cg') {
  454. $field = 'id,py,cover,name,itemId,classId,variety,price,discountPrice,stock,presell,ratioType,smallUnit,bigUnit,ratio,weight,frontHide';
  455. $itemInfoData = ProductClass::getAllByCondition($where, ['inTurn' => SORT_DESC, 'actualSold' => SORT_DESC], $field);
  456. $itemInfoData = ProductClass::cgItemGroup($itemInfoData, $level);
  457. } elseif ($requestType == 'warning') {
  458. $field = 'id,py,cover,name,cost,itemId,classId,skPrice,variety,price,discountPrice,stock,onStock,actualSold,presell,bigUnit,stockWarning,status,frontHide';
  459. $itemInfoData = Product::find()->where("mainId={$this->mainId}")
  460. ->andWhere('`stock`+`onStock`<`stockWarning`')
  461. ->andWhere("delStatus=0")
  462. ->select($field)->asArray()->all();
  463. $itemInfoData = ProductClass::warningGroup($itemInfoData, $level);
  464. } else {
  465. util::fail('没有数据');
  466. }
  467. $data = ProductService::assembleItemData($classInfo, $itemInfoData);
  468. util::success($data);
  469. }
  470. //取出今天有入库的花材 ssh 20221224
  471. public function actionGetStockIn()
  472. {
  473. $py = Yii::$app->request->get('py', '');
  474. $version = Yii::$app->request->get('version', 0);
  475. if ($version == 0) {
  476. util::fail('请先升级版本到1.0.70以上');
  477. }
  478. $classInfo = ItemClassClass::getGhsItemClassAll($this->mainId);
  479. $mainId = $this->mainId ?? 0;
  480. $where['mainId'] = $mainId;
  481. if ($py) {
  482. $pyName = strtolower($py);
  483. $where['py'] = $pyName;
  484. }
  485. $arr = StockInDayClass::getAllByCondition(['mainId' => $mainId], null, '*');
  486. if (empty($arr)) {
  487. util::fail('没有花材需要盘点');
  488. }
  489. $ids = array_column($arr, 'itemId');
  490. $ids = array_unique($ids);
  491. $where['id'] = ['in', $ids];
  492. $level = 1;
  493. $field = 'id,py,cover,name,itemId,classId,variety,price,discountPrice,stock,stockWarning,presell,ratioType,smallUnit,bigUnit,ratio';
  494. $itemInfoData = ProductClass::getAllByCondition($where, ['inTurn' => SORT_DESC, 'actualSold' => SORT_DESC], $field);
  495. $itemInfoData = ProductClass::checkItemGroup($itemInfoData, $level);
  496. $data = ProductService::assembleItemData($classInfo, $itemInfoData);
  497. util::success($data);
  498. }
  499. //按分类列出所有花材
  500. public function actionIndex()
  501. {
  502. $py = Yii::$app->request->get('py', '');
  503. $requestType = Yii::$app->request->get('requestType', 'common');
  504. //默认显示上架商品
  505. $status = Yii::$app->request->get('status', 1);
  506. //默认显示未删除商品
  507. $delStatus = Yii::$app->request->get('delStatus', 0);
  508. $warning = Yii::$app->request->get('warning', 0);
  509. //获取所有当前供货商的分类 (全部、常用)
  510. //根据分类组装分类下的花材信息
  511. //中央ID
  512. $classInfo = ItemClassClass::getGhsItemClassAll($this->mainId);
  513. $where['mainId'] = $this->mainId;
  514. if ($py) {
  515. $pyName = strtolower($py);
  516. $where['py'] = $pyName;
  517. }
  518. if ($requestType == 'hasStock') {
  519. //改价只显示库存大于0的
  520. $where['stock>'] = 0;
  521. }
  522. if (!empty($status)) {
  523. $where['status'] = $status;
  524. }
  525. $where['delStatus'] = $delStatus;
  526. //客户等级
  527. $customId = Yii::$app->request->get('customId', 0);
  528. $level = 1;
  529. if (!empty($customId)) {
  530. $custom = CustomClass::getById($customId, true);
  531. $level = $custom->level ?? 1;
  532. }
  533. if ($warning == 1) {
  534. //库存预警
  535. $field = 'id,py,cover,name,ratio,cost,addPrice,classId,skMore,skPrice,itemId,smallUnit,smallRatio,presellDate,bigUnit,smallUnit,ratioType,variety,price,stock,stockWarning,discountPrice,presell';
  536. $itemInfoData = Product::find()->where("mainId={$this->mainId}")
  537. ->andWhere('`stock`<`stockWarning`')
  538. ->andWhere("delStatus=0")
  539. ->select($field)->asArray()->all();
  540. } else {
  541. $field = 'id,py,cover,name,ratio,cost,addPrice,classId,skMore,skPrice,itemId,smallUnit,smallRatio,presellDate,bigUnit,smallUnit,ratioType,variety,price,stock,stockWarning,discountPrice,presell';
  542. $itemInfoData = ProductClass::getAllByCondition($where, ['inTurn' => SORT_DESC, 'actualSold' => SORT_DESC], $field);
  543. }
  544. $itemInfoData = ProductClass::groupProductInfo($itemInfoData, $level);
  545. $data = ProductService::assembleData($classInfo, $itemInfoData, true);
  546. util::success($data);
  547. }
  548. //所有花材分页和不分页
  549. public function actionList()
  550. {
  551. $get = Yii::$app->request->get();
  552. $where = [];
  553. $classId = Yii::$app->request->get('classId', 0);
  554. if (!empty($classId)) {
  555. $where['classId'] = $classId;
  556. }
  557. $name = Yii::$app->request->get('name', '');
  558. if (empty($name)) {
  559. $py = Yii::$app->request->get('py', '');
  560. $name = !empty($py) ? $py : '';
  561. }
  562. if (!empty($name)) {
  563. if (stringUtil::isLetter($name)) {
  564. $where['py'] = ['like', $name];
  565. } else {
  566. $where['name'] = ['like', $name];
  567. }
  568. }
  569. $status = Yii::$app->request->get('status', 0);
  570. if (!empty($status)) {
  571. $where['status'] = $status;
  572. }
  573. $delStatus = Yii::$app->request->get('delStatus', 0);
  574. if ($delStatus != 2) {
  575. $where['delStatus'] = $delStatus;
  576. }
  577. $where['mainId'] = $this->mainId;
  578. $productIds = Yii::$app->request->get('ids', '');
  579. if (!empty($productIds)) {
  580. $productIdArr = explode(',', $productIds);
  581. if (!empty($productIdArr)) {
  582. $where['id'] = ['in', $productIdArr];
  583. }
  584. }
  585. //输出标准会员价,即批发价,默认显示的是批发价
  586. $level = 1;
  587. $type = Yii::$app->request->get('type', '');
  588. $showPage = Yii::$app->request->get('showPage', 0);
  589. if ($showPage) {
  590. if ($type == 'waring') {
  591. $pro = Product::find()->where("mainId={$this->mainId}")->andWhere('`stock`<`stockWarning`')->select('id')->asArray()->all();
  592. $lackIds = array_column($pro, 'id');
  593. if (empty($lackIds)) {
  594. util::success([]);
  595. }
  596. $lackIds = array_filter(array_unique($lackIds));
  597. $where['id'] = ['in', $lackIds];
  598. $respond = ProductClass::getList("*", $where, "actualSold desc");
  599. } else {
  600. $hasStock = $get['hasStock'] ?? -1;
  601. if ($hasStock == 0) {
  602. $where['stock'] = 0;
  603. }
  604. if ($hasStock == 1) {
  605. $where['stock>'] = 0;
  606. }
  607. $cgStaffId = $get['cgStaffId'] ?? 0;
  608. if (!empty($cgStaffId)) {
  609. $where['cgStaffId'] = $cgStaffId;
  610. }
  611. $respond = ProductClass::getList("*", $where, "inTurn desc");
  612. }
  613. $respond['list'] = ProductClass::groupProductInfo($respond['list'], $level);
  614. $respond['list'] = ProductClass::groupClassName($this->mainId, $respond['list']);
  615. util::success($respond);
  616. } else {
  617. if ($type == 'waring') {
  618. //库存预警 按库存从小到大排序
  619. $data = ProductClass::getAllByCondition($where, ['stock' => SORT_ASC, 'inTurn' => SORT_DESC], "*");
  620. } else {
  621. if (!empty($productIds)) {
  622. //优先按 $productIds 排序 "FIELD(`id`,4,5,6)"=>true
  623. $data = ProductClass::getAllByCondition($where, ["FIELD(`id`,$productIds)" => true, 'inTurn' => SORT_DESC], "*");
  624. } else {
  625. $data = ProductClass::getAllByCondition($where, ['actualSold' => SORT_DESC, 'inTurn' => SORT_DESC], "*");
  626. }
  627. }
  628. $data = ProductClass::groupProductInfo($data, $level);
  629. $data = ProductClass::groupClassName($this->mainId, $data);
  630. if ($type == 'waring') {
  631. //库存预警
  632. $newData = [];
  633. foreach ($data as $v) {
  634. if ($v['stock'] <= $v['stockWarning']) {
  635. $newData[] = $v;
  636. }
  637. }
  638. util::success(['list' => $newData]);
  639. }
  640. util::success(['list' => $data]);
  641. }
  642. }
  643. //所有花材
  644. public function actionAll()
  645. {
  646. $where = [];
  647. $where['mainId'] = $this->mainId;
  648. $classId = Yii::$app->request->get('classId', 0);
  649. if (!empty($classId)) {
  650. $where['classId'] = $classId;
  651. }
  652. $status = Yii::$app->request->get('status', 0);
  653. if (!empty($status)) {
  654. $where['status'] = $status;
  655. }
  656. $delStatus = Yii::$app->request->get('delStatus', 0);
  657. if ($delStatus != 2) {
  658. $where['delStatus'] = $delStatus;
  659. }
  660. //输出标准会员价,即批发价,默认显示的是批发价
  661. $level = 1;
  662. $data = ProductClass::getAllByCondition($where, ['actualSold' => SORT_DESC, 'inTurn' => SORT_DESC], "*");
  663. $data = ProductClass::groupProductInfo($data, $level);
  664. util::success(['list' => $data]);
  665. }
  666. //批量改价
  667. public function actionBatchChangePrice()
  668. {
  669. $shop = $this->shop;
  670. $join = $shop->join ?? 0;
  671. $default = $shop->default ?? 0;
  672. if ($join == 0 && $default == 0) {
  673. //除了小蔡鲜花的蔡总、郑总、苏南3007,其他人直营分店不能改价格,多处要同步修改,关键词 direct_price_change
  674. if (!in_array($this->adminId, [35725, 23659, 29264])) {
  675. util::fail('直营店不能改价');
  676. }
  677. }
  678. $shopAdmin = $this->shopAdmin;
  679. if (!isset($shopAdmin->super) || $shopAdmin->super != 1) {
  680. util::fail('超管才能修改');
  681. }
  682. $shop = $this->shop;
  683. $default = $shop->default ?? 0;
  684. $adminId = $this->adminId ?? 0;
  685. //normal常规改价,cg采购改价
  686. $changeType = Yii::$app->request->post('changeType', 'normal');
  687. $targetId = Yii::$app->request->post('targetId', 0);
  688. $changeParams = ['staffId' => $shopAdmin->id, 'staffName' => $shopAdmin->name, 'changeType' => $changeType, 'targetId' => $targetId];
  689. $post = Yii::$app->request->post();
  690. $data = $post['data'] ?? '';
  691. if (empty($data)) {
  692. util::fail('没有修改');
  693. }
  694. $arr = json_decode($data, true);
  695. if (empty($arr)) {
  696. util::fail('没有修改哦');
  697. }
  698. $appVersion = $post['appVersion'] ?? 0;
  699. if ($appVersion != 1) {
  700. util::fail('请先升级应用');
  701. }
  702. //解决重复请求问题
  703. $cacheKey = 'batch_change_price_' . $targetId;
  704. $has = Yii::$app->redis->executeCommand('GET', [$cacheKey]);
  705. if (!empty($has)) {
  706. util::fail('请5秒后操作');
  707. }
  708. Yii::$app->redis->executeCommand('SETEX', [$cacheKey, 5, 'has']);
  709. $connection = Yii::$app->db;
  710. $transaction = $connection->beginTransaction();
  711. try {
  712. $needNotice = false;
  713. $cg = PurchaseOrderClass::getLockById($targetId);
  714. if (!empty($cg)) {
  715. if (isset($cg->mainId) == false || $cg->mainId != $this->mainId) {
  716. util::fail('不是您的采购单');
  717. }
  718. //批量改价同时入库
  719. if ($cg->status == PurchaseOrderClass::PURCHASE_ORDER_STATUS_SENDING) {
  720. $staff = $this->shopAdmin;
  721. $data = [];
  722. $data['staffId'] = $staff->id ?? 0;
  723. $data['staffName'] = $staff->name ?? '';
  724. $data['adminId'] = $this->adminId ?? 0;
  725. $data['shop'] = $this->shop;
  726. PurchaseOrderClass::putIn($cg, $data);
  727. $needNotice = true;
  728. }
  729. }
  730. $ids = array_column($arr, 'id');
  731. $ids = array_unique(array_filter($ids));
  732. if (empty($ids)) {
  733. util::fail('请选择花材');
  734. }
  735. $sjId = $shop->sjId ?? 0;
  736. $chainShopList = [];
  737. if ($default == 1) {
  738. $chainShopList = ShopClass::getAllByCondition(['sjId' => $sjId, 'join' => 0], null, '*', null, true);
  739. }
  740. $productList = ProductClass::getAllByCondition(['id' => ['in', $ids]], null, '*', 'id', true);
  741. foreach ($arr as $product) {
  742. $productId = $product['id'];
  743. $productInfo = $productList[$productId] ?? [];
  744. if (empty($productInfo)) {
  745. util::fail('没有找到花材');
  746. }
  747. $productName = $productInfo->name ?? '';
  748. if (!isset($product['id'])) {
  749. util::fail('没有花材');
  750. }
  751. if (!isset($product['price']) || !is_numeric($product['price']) || $product['price'] < 0) {
  752. util::fail('请填写' . $productName . '的批发价');
  753. }
  754. $price = $product['price'];
  755. if (!isset($product['skPrice']) || !is_numeric($product['skPrice']) || $product['skPrice'] < 0) {
  756. util::fail('请填写' . $productName . '的零售价');
  757. }
  758. $skPrice = $product['skPrice'];
  759. if (!isset($product['hjPrice']) || !is_numeric($product['hjPrice']) || $product['hjPrice'] < 0) {
  760. util::fail('请填写' . $productName . '的会员价');
  761. }
  762. $hjPrice = $product['hjPrice'] ?? 0;
  763. if (!isset($productInfo->mainId) || $productInfo->mainId != $this->mainId) {
  764. util::fail('无法访问..');
  765. }
  766. if ($hjPrice > $price) {
  767. util::fail($productName . ' 批发价要大于会员价');
  768. }
  769. if ($price > $skPrice) {
  770. util::fail($productName . ' 零售价要大于批发价');
  771. }
  772. $ptItemId = $productInfo->itemId;
  773. ProductClass::changeSinglePrice($shop, $ptItemId, $price, $skPrice, $hjPrice, $changeParams);
  774. //在首店修改需要同步到所有直营店
  775. if ($default == 1 && isset($shop->dataSync) && $shop->dataSync == 1) {
  776. foreach ($chainShopList as $chain) {
  777. if ($chain->id == $shop->id) {
  778. continue;
  779. }
  780. $chainMainId = $chain->mainId ?? 0;
  781. $staff = ShopAdminClass::getByCondition(['mainId' => $chainMainId, 'adminId' => $adminId], true);
  782. $staffId = $staff->id ?? 0;
  783. $staffName = $staff->name ?? '';
  784. $changeParams2 = ['staffId' => $staffId, 'staffName' => $staffName, 'changeType' => $changeType, 'targetId' => $targetId];
  785. ProductClass::changeSinglePrice($chain, $ptItemId, $price, $skPrice, $hjPrice, $changeParams2);
  786. }
  787. }
  788. }
  789. $mainId = $shop->mainId ?? 0;
  790. if (!empty($mainId)) {
  791. //提醒零售收银台界面要刷新,多处要修改,关键词 modify_price_remind_cashier
  792. $staffList = ShopAdminClass::getAllByCondition(['mainId' => $mainId], null, '*', null, true);
  793. if (!empty($staffList)) {
  794. foreach ($staffList as $staff) {
  795. $staffId = $staff->id ?? 0;
  796. Yii::$app->redis->executeCommand('SET', ['cashier_' . $mainId . '_' . $staffId . '_may_refresh', 'yes']);
  797. Yii::$app->redis->executeCommand('SET', ['ghs_cashier_' . $mainId . '_' . $staffId . '_may_refresh', 'yes']);
  798. }
  799. }
  800. }
  801. $transaction->commit();
  802. //入库成功通知相关人员,关键词 put_in_notice
  803. if ($needNotice) {
  804. // $cg = PurchaseOrderClass::getLockById($targetId);
  805. // WxMessageClass::ghsCgEntryInform($shop, $cg);
  806. }
  807. util::complete('操作成功');
  808. } catch (\Exception $e) {
  809. $transaction->rollBack();
  810. $msg = $e->getMessage();
  811. Yii::info("修改失败原因:" . $msg);
  812. noticeUtil::push("修改价格出现失败情况,原因:" . $msg, '15280215347');
  813. util::fail('修改失败');
  814. }
  815. }
  816. //多个花材同时改成一个价 ssh 20231003
  817. public function actionManyItemChangeOnePrice()
  818. {
  819. $shop = $this->shop;
  820. $join = $shop->join ?? 0;
  821. $default = $shop->default ?? 0;
  822. if ($join == 0 && $default == 0) {
  823. util::fail('当前直营分店,只能回总店修改价格');
  824. }
  825. $shopAdmin = $this->shopAdmin;
  826. if (isset($shopAdmin->super) == false || $shopAdmin->super != 1) {
  827. util::fail('超管才能修改');
  828. }
  829. $post = Yii::$app->request->post();
  830. $idsList = $post['ids'] ?? '';
  831. $ids = json_decode($idsList, true);
  832. if (empty($ids)) {
  833. util::fail('请选择花材');
  834. }
  835. $list = ProductClass::getAllByCondition(['id' => ['in', $ids]], null, '*', null, true);
  836. if (empty($list)) {
  837. util::fail('请选择花材哦');
  838. }
  839. $mainId = $this->mainId;
  840. $adminId = $this->adminId ?? 0;
  841. $shop = $this->shop;
  842. $default = $shop->default ?? 0;
  843. $shopAdmin = $this->shopAdmin;
  844. $price = $post['price'] ?? 0;
  845. if (is_numeric($price) == false) {
  846. util::fail('批发价填写错误');
  847. }
  848. $skPrice = $post['skPrice'] ?? 0;
  849. if (is_numeric($skPrice) == false) {
  850. util::fail('散客价填写错误');
  851. }
  852. $hjPrice = $post['hjPrice'] ?? 0;
  853. if (is_numeric($hjPrice) == false) {
  854. util::fail('会员价填写错误');
  855. }
  856. if ($hjPrice > $price) {
  857. util::fail('会员价不能大于批发价');
  858. }
  859. if ($price > $skPrice) {
  860. util::fail('批发价不能大于零售价');
  861. }
  862. $sjId = $shop->sjId ?? 0;
  863. $chainShopList = [];
  864. if ($default == 1) {
  865. $chainShopList = ShopClass::getAllByCondition(['sjId' => $sjId, 'join' => 0], null, '*', null, true);
  866. }
  867. //normal常规改价,cg采购改价
  868. $changeType = Yii::$app->request->post('changeType', 'normal');
  869. $targetId = 0;
  870. $changeParams = ['staffId' => $shopAdmin->id, 'staffName' => $shopAdmin->name, 'changeType' => $changeType, 'targetId' => $targetId];
  871. $connection = Yii::$app->db;
  872. $transaction = $connection->beginTransaction();
  873. try {
  874. foreach ($list as $product) {
  875. if ($product->mainId != $mainId) {
  876. util::fail('修改失败,不是你的花材');
  877. }
  878. $ptItemId = $product->itemId;
  879. ProductClass::changeSinglePrice($shop, $ptItemId, $price, $skPrice, $hjPrice, $changeParams);
  880. //在首店修改需要同步到所有直营店
  881. if ($default == 1 && isset($shop->dataSync) && $shop->dataSync == 1) {
  882. if (!empty($chainShopList)) {
  883. foreach ($chainShopList as $chain) {
  884. if ($chain->id == $shop->id) {
  885. continue;
  886. }
  887. $chainMainId = $chain->mainId ?? 0;
  888. $staff = ShopAdminClass::getByCondition(['mainId' => $chainMainId, 'adminId' => $adminId], true);
  889. $changeParams2 = ['staffId' => $staff->id, 'staffName' => $staff->name, 'changeType' => $changeType, 'targetId' => $targetId];
  890. ProductClass::changeSinglePrice($chain, $ptItemId, $price, $skPrice, $hjPrice, $changeParams2);
  891. }
  892. }
  893. }
  894. }
  895. if (!empty($mainId)) {
  896. //提醒零售收银台界面要刷新,多处要修改,关键词 modify_price_remind_cashier
  897. $staffList = ShopAdminClass::getAllByCondition(['mainId' => $mainId], null, '*', null, true);
  898. if (!empty($staffList)) {
  899. foreach ($staffList as $staff) {
  900. $staffId = $staff->id ?? 0;
  901. Yii::$app->redis->executeCommand('SET', ['cashier_' . $mainId . '_' . $staffId . '_may_refresh', 'yes']);
  902. Yii::$app->redis->executeCommand('SET', ['ghs_cashier_' . $mainId . '_' . $staffId . '_may_refresh', 'yes']);
  903. }
  904. }
  905. }
  906. $transaction->commit();
  907. util::complete('修改成功');
  908. } catch (\Exception $e) {
  909. $transaction->rollBack();
  910. Yii::info("修改失败原因:" . $e->getMessage());
  911. util::fail('修改失败');
  912. }
  913. }
  914. //改价
  915. public function actionChangePrice()
  916. {
  917. $shopAdmin = $this->shopAdmin;
  918. if (isset($shopAdmin->super) == false || $shopAdmin->super != 1) {
  919. util::fail('超管才能修改');
  920. }
  921. $productId = Yii::$app->request->post('productId', 0);
  922. $productInfo = ProductClass::getById($productId, true);
  923. if (empty($productInfo)) {
  924. util::fail("花材不存在");
  925. }
  926. if ($productInfo->mainId != $this->mainId) {
  927. util::fail('没有权限');
  928. }
  929. $price = Yii::$app->request->post('price', '');
  930. if (is_numeric($price) && $price > 0) {
  931. ProductClass::changeSinglePrice($productInfo, $price, ProductClass::PRICE_LABEL_CHANGE);
  932. } else {
  933. $price = bcadd($productInfo->cost, $productInfo->addPrice, 2);
  934. ProductClass::changeSinglePrice($productInfo, $price, ProductClass::PRICE_LABEL_AUTO);
  935. }
  936. util::success(['price' => $price]);
  937. }
  938. //恢复自动调价
  939. public function actionAutoPrice()
  940. {
  941. $productId = Yii::$app->request->post('productId', 0);
  942. $productData = ProductClass::getById($productId);
  943. if (!$productData) {
  944. util::fail("花材不存在");
  945. }
  946. //2021.04.06改为用product中的成本价+加价
  947. $price = bcadd($productData['cost'], $productData['addPrice'], 2);
  948. ProductClass::changeSinglePrice($productId, $this->shopId, $price, ProductClass::PRICE_LABEL_AUTO);
  949. util::complete("操作成功");
  950. }
  951. //修改加价
  952. public function actionChangeAddPrice()
  953. {
  954. $productId = Yii::$app->request->post('productId', 0);
  955. $addPrice = Yii::$app->request->post('addPrice', '');
  956. if ($addPrice < 0) {
  957. util::fail("加价不能小于0");
  958. }
  959. $productData = ProductClass::getProductData($productId, $this->mainId);
  960. if (!$productData) {
  961. util::fail("花材不存在");
  962. }
  963. ProductClass::changeAddPrice($productId, $addPrice);
  964. util::complete();
  965. }
  966. //批量修改更多,包括排序、重量和保质期 ssh 20211211
  967. public function actionBatchChangeMore()
  968. {
  969. $shop = $this->shop;
  970. $default = $shop->default ?? 0;
  971. $join = $shop->join ?? 0;
  972. if ($default == 0 && $join == 0) {
  973. util::fail('当前是直营店,请返回总店修改');
  974. }
  975. $shopAdmin = $this->shopAdmin;
  976. if (isset($shopAdmin->super) == false || $shopAdmin->super != 1) {
  977. util::fail('超管才能操作');
  978. }
  979. $addData = Yii::$app->request->post('addData', '');
  980. if (empty($addData)) {
  981. util::fail('没有花材');
  982. }
  983. $itemData = json_decode($addData, true);
  984. if (is_array($itemData) == false) {
  985. util::fail('没有花材...');
  986. }
  987. $ids = array_column($itemData, 'id');
  988. $infoList = ProductClass::getByIds($ids, null, 'id');
  989. if (empty($infoList)) {
  990. util::fail('没有花材');
  991. }
  992. foreach ($infoList as $info) {
  993. if (isset($info['mainId']) == false || $info['mainId'] != $this->mainId) {
  994. util::fail('不是你的花材不能修改');
  995. }
  996. }
  997. //总店修改同步到所有门店
  998. $sjId = $shop->sjId ?? 0;
  999. $chainShopList = ShopClass::getAllByCondition(['sjId' => $sjId], null, '*', null, true);
  1000. foreach ($itemData as $key => $data) {
  1001. $id = $data['id'] ?? 0;
  1002. unset($data['id']);
  1003. ProductClass::updateById($id, $data);
  1004. $ptItemId = $infoList[$id]['itemId'] ?? 0;
  1005. if (empty($ptItemId)) {
  1006. continue;
  1007. }
  1008. if (isset($shop->default) && $shop->default == 1 && isset($shop->dataSync) && $shop->dataSync == 1) {
  1009. foreach ($chainShopList as $chainShop) {
  1010. $currentMainId = $chainShop->mainId ?? 0;
  1011. if ($currentMainId == $shop->mainId) {
  1012. //前面已经修改过了,不需要重复修改
  1013. continue;
  1014. }
  1015. ProductClass::updateByCondition(['mainId' => $currentMainId, 'itemId' => $ptItemId], $data);
  1016. }
  1017. }
  1018. }
  1019. util::complete('修改成功');
  1020. }
  1021. //批量修改加价 ssh 20211211
  1022. public function actionBatchChangeAddPrice()
  1023. {
  1024. $shop = $this->shop;
  1025. $join = $shop->join ?? 0;
  1026. $default = $shop->default ?? 0;
  1027. if ($join == 0 && $default == 0) {
  1028. util::fail('当前直营分店,请切回总店操作');
  1029. }
  1030. $shopAdmin = $this->shopAdmin;
  1031. if (isset($shopAdmin->super) == false || $shopAdmin->super != 1) {
  1032. util::fail('超管才能操作');
  1033. }
  1034. $post = Yii::$app->request->post();
  1035. $addData = $post['addData'] ?? '';
  1036. if (empty($addData)) {
  1037. util::fail('没有花材');
  1038. }
  1039. $itemData = json_decode($addData, true);
  1040. if (is_array($itemData) == false) {
  1041. util::fail('没有花材...');
  1042. }
  1043. $ids = array_column($itemData, 'id');
  1044. $infoList = ProductClass::getByIds($ids, null, 'id');
  1045. if (empty($infoList)) {
  1046. util::fail('没有花材');
  1047. }
  1048. foreach ($infoList as $info) {
  1049. if (isset($info['mainId']) == false || $info['mainId'] != $this->mainId) {
  1050. util::fail('不能修改别人的花材');
  1051. }
  1052. }
  1053. $appVersion = $post['appVersion'] ?? 0;
  1054. if ($appVersion != 1) {
  1055. util::fail('请先升级应用');
  1056. }
  1057. //总店修改同步到所有门店
  1058. $sjId = $shop->sjId ?? 0;
  1059. $chainShopList = ShopClass::getAllByCondition(['sjId' => $sjId], null, '*', null, true);
  1060. foreach ($itemData as $key => $data) {
  1061. $id = $data['id'] ?? 0;
  1062. unset($data['id']);
  1063. ProductClass::updateById($id, $data);
  1064. $ptItemId = $infoList[$id]['itemId'] ?? 0;
  1065. if (empty($ptItemId)) {
  1066. continue;
  1067. }
  1068. if (isset($shop->default) && $shop->default == 1 && isset($shop->dataSync) && $shop->dataSync == 1) {
  1069. foreach ($chainShopList as $chainShop) {
  1070. if (isset($chainShop->join) && $chainShop->join == 1) {
  1071. continue;
  1072. }
  1073. $currentMainId = $chainShop->mainId ?? 0;
  1074. if ($currentMainId == $shop->mainId) {
  1075. //前面已经修改过了,不需要重复修改
  1076. continue;
  1077. }
  1078. ProductClass::updateByCondition(['mainId' => $currentMainId, 'itemId' => $ptItemId], $data);
  1079. }
  1080. }
  1081. }
  1082. util::complete('修改成功');
  1083. }
  1084. public function actionUpdate()
  1085. {
  1086. $shopAdmin = $this->shopAdmin;
  1087. if (!isset($shopAdmin->super) || $shopAdmin->super != 1) {
  1088. util::fail('超管才能操作');
  1089. }
  1090. $shop = $this->shop;
  1091. $join = $shop->join ?? 0;
  1092. $default = $shop->default ?? 0;
  1093. if ($join == 0 && $default == 0) {
  1094. //因为盘点不能将花材盘成0,所以这边放出入口允许创始人在分店修改分店的花材库存
  1095. if ($shopAdmin->super != 1) {
  1096. util::fail('请先开通超管权限');
  1097. }
  1098. }
  1099. $deadline = $shop->deadline;
  1100. $deadTime = strtotime($deadline);
  1101. if (time() > $deadTime) {
  1102. util::fail('系统已到期,编号1689');
  1103. }
  1104. $post = Yii::$app->request->post();
  1105. $discountPrice = $post['discountPrice'] ?? 0;
  1106. if ($discountPrice > 0) {
  1107. if (empty($post['hjDiscountPrice'])) {
  1108. $addPrice = $post['addPrice'] ?? 0;
  1109. $hjAddPrice = $post['hjAddPrice'] ?? 0;
  1110. $skMore = $post['skMore'] ?? 0;
  1111. $diff = bcsub($addPrice, $hjAddPrice, 2);
  1112. if ($diff > 0 && $discountPrice > $diff) {
  1113. $hjDiscountPrice = bcsub($discountPrice, $diff, 2);
  1114. } else {
  1115. $hjDiscountPrice = $discountPrice;
  1116. }
  1117. $diff = bcsub($skMore, $addPrice, 2);
  1118. if ($diff > 0) {
  1119. $skDiscountPrice = bcadd($diff, $discountPrice, 2);
  1120. } else {
  1121. $skDiscountPrice = $discountPrice;
  1122. }
  1123. $post['skDiscountPrice'] = $skDiscountPrice;
  1124. $post['hjDiscountPrice'] = $hjDiscountPrice;
  1125. }
  1126. $reachNum = $post['reachNum'] ?? 0;
  1127. $reachNumDiscount = $post['reachNumDiscount'] ?? 0;
  1128. if ($reachNum > 0 && $reachNumDiscount > 0) {
  1129. util::fail('特价和满减不能同时进行');
  1130. }
  1131. }
  1132. $post['adminId'] = $this->adminId;
  1133. $post['staffId'] = $this->shopAdmin->id;
  1134. $post['staffName'] = $this->shopAdmin->name;
  1135. // 图片列表数组转换为字符串
  1136. if (is_array($post['images'])) {
  1137. $post['images'] = implode(',', $post['images']);
  1138. }
  1139. $connection = Yii::$app->db;
  1140. $transaction = $connection->beginTransaction();
  1141. try {
  1142. ProductClass::updateProduct($post, $this->shop);
  1143. $transaction->commit();
  1144. util::complete();
  1145. } catch (\Exception $e) {
  1146. Yii::info("操作失败:" . $e->getMessage());
  1147. $transaction->rollBack();
  1148. util::fail('操作失败');
  1149. }
  1150. }
  1151. //上下架状态控制 ssh 20210713
  1152. public function actionStatusUpdate()
  1153. {
  1154. $post = Yii::$app->request->post();
  1155. $shopAdmin = $this->shopAdmin;
  1156. $roleId = $shopAdmin['roleId'] ?? 0;
  1157. $role = AdminRoleClass::getById($roleId);
  1158. $roleName = $role['roleName'] ?? '';
  1159. if ($roleName == '员工') {
  1160. util::fail('无法操作哦');
  1161. }
  1162. $id = $post['id'] ?? 0;
  1163. $status = $post['status'] ?? 1;
  1164. $product = ProductClass::getById($id, true);
  1165. if ($product->mainId != $this->mainId) {
  1166. util::fail('无法操作');
  1167. }
  1168. $product->status = $status;
  1169. if ($status == 2) {
  1170. $product->discountPrice = 0;
  1171. }
  1172. $product->save();
  1173. util::complete();
  1174. }
  1175. //花材展示状态控制 ssh 20231113
  1176. public function actionDelStatusUpdate()
  1177. {
  1178. $post = Yii::$app->request->post();
  1179. $shop = $this->shop;
  1180. $join = $shop->join ?? 0;
  1181. $default = $shop->default ?? 0;
  1182. if ($join == 0 && $default == 0) {
  1183. util::fail('请在首店操作');
  1184. }
  1185. $id = $post['id'] ?? 0;
  1186. $delStatus = $post['delStatus'] ?? 0;
  1187. $product = ProductClass::getById($id, true);
  1188. if ($product->mainId != $this->mainId) {
  1189. util::fail('不是你的花材哦!!');
  1190. }
  1191. //扫码收款、直接收款和特价商品,不可删除,多处要同步修改 system_item
  1192. if (getenv('YII_ENV') == 'production') {
  1193. $systemItem = [78076, 80960, 81004];
  1194. } else {
  1195. $systemItem = [11157, 11156, 11158];
  1196. }
  1197. if (in_array($product->itemId, $systemItem)) {
  1198. util::fail('系统使用花材,不可删除');
  1199. }
  1200. $product->delStatus = $delStatus;
  1201. if ($delStatus == 1) {
  1202. $product->stock = 0;
  1203. $product->status = 2;
  1204. }
  1205. $product->save();
  1206. $ptItemId = $product->itemId ?? 0;
  1207. if (isset($shop->default) && $shop->default == 1 && isset($shop->dataSync) && $shop->dataSync == 1) {
  1208. //总店修改同步到所有门店
  1209. $sjId = $shop->sjId ?? 0;
  1210. $chainShopList = ShopClass::getAllByCondition(['sjId' => $sjId], null, '*', null, true);
  1211. foreach ($chainShopList as $chainShop) {
  1212. $chainShopId = $chainShop->id ?? 0;
  1213. if (isset($chainShop->join) && $chainShop->join == 1) {
  1214. continue;
  1215. }
  1216. if ($chainShopId == $shop->id) {
  1217. continue;
  1218. }
  1219. $chainMainId = $chainShop->mainId ?? 0;
  1220. $chainProduct = ProductClass::getByCondition(['mainId' => $chainMainId, 'itemId' => $ptItemId], true);
  1221. if (!empty($chainProduct)) {
  1222. $chainProduct->delStatus = $delStatus;
  1223. if ($delStatus == 1) {
  1224. $chainProduct->stock = 0;
  1225. $chainProduct->status = 2;
  1226. }
  1227. $chainProduct->save();
  1228. }
  1229. }
  1230. }
  1231. util::complete();
  1232. }
  1233. //详情 shish 20240115
  1234. public function actionDetail()
  1235. {
  1236. $id = Yii::$app->request->get('id', 0);
  1237. $source = Yii::$app->request->get('source', '');
  1238. $respond = ProductClass::getItemInfo($id);
  1239. $ptItemId = $respond['itemId'] ?? 0;
  1240. // 封面图与多花材图片的兼容处理
  1241. if ($respond['images'] == '' && $respond['shortCover'] != '') {
  1242. $respond['images'] = $respond['shortCover'];
  1243. }
  1244. $ptItemInfo = PtItemClass::getById($ptItemId);
  1245. $respond['ptItemInfo'] = $ptItemInfo;
  1246. //通知提醒抹除
  1247. if ($source == 'notify' && $respond['mainId'] == $this->mainId) {
  1248. $staff = $this->shopAdmin;
  1249. $staffId = $this->shopAdminId;
  1250. $notify = NotifyClass::getByCondition(['staffId' => $staffId, 'type' => 1, 'targetId' => $id], true);
  1251. if (!empty($notify)) {
  1252. if ($notify->read == 0) {
  1253. $notify->read = 1;
  1254. $notify->save();
  1255. $notifyNum = $staff->notifyNum;
  1256. if ($notifyNum > 0) {
  1257. $notifyNum--;
  1258. $staff->notifyNum = $notifyNum;
  1259. $staff->save();
  1260. }
  1261. }
  1262. }
  1263. }
  1264. //重复花材
  1265. $repeatList = ProductClass::getAllByCondition(['mainId' => $this->mainId, 'itemId' => $ptItemId, 'delStatus' => 0], null, '*', null, true);
  1266. $repeatId = 0;
  1267. if (!empty($repeatList)) {
  1268. foreach ($repeatList as $repeat) {
  1269. if ($repeat->id != $id) {
  1270. $repeatId = $repeat->id;
  1271. }
  1272. }
  1273. }
  1274. $respond['repeatId'] = $repeatId;
  1275. $cpItemList = CpItemClass::getAllByCondition(['productId' => $id], null, '*', 'cpId');
  1276. $cpInfo = [];
  1277. if (!empty($cpItemList)) {
  1278. $cpIds = array_column($cpItemList, 'cpId');
  1279. $cpList = CpClass::getByIds($cpIds);
  1280. if (!empty($cpList)) {
  1281. foreach ($cpList as $key => $val) {
  1282. $id = $val['id'] ?? 0;
  1283. $name = $val['name'] ?? '';
  1284. $cpInfo[] = ['cpId' => $id, 'cpName' => $name];
  1285. }
  1286. }
  1287. }
  1288. //判断这个花材能否被修改单位比和重量,同步参考ShopController actionMyShop方法,关键词has_right_shop_list
  1289. //判断当前登录的人,在自己有财务权限的main里面,是否包括了这个花材所属的平台id,在这个平台id下所有花材的main
  1290. $adminId = $this->adminId;
  1291. $hasRightRespond = ShopAdminClass::changeWeightRight($adminId, $ptItemId);
  1292. $respond['hasRightChange'] = $hasRightRespond['hasRightChange'];
  1293. $respond['hasRightChangeReason'] = $hasRightRespond['reason'];
  1294. //查出拆散的子花材
  1295. $part = UnitChangeClass::getByCondition(['big' => $id], true);
  1296. $partAcceptItem = 0;
  1297. $partAcceptItemName = '';
  1298. if (!empty($part)) {
  1299. $partAcceptItem = $part->small;
  1300. $small = ProductClass::getByCondition(['id' => $partAcceptItem], true, false, 'id,name');
  1301. $partAcceptItemName = $small->name ?? '';;
  1302. }
  1303. $respond['partAcceptItem'] = $partAcceptItem;
  1304. $respond['partAcceptItemName'] = $partAcceptItemName;
  1305. $respond['cpInfo'] = $cpInfo;
  1306. util::success($respond);
  1307. }
  1308. //新增花材 2021.6.21
  1309. public function actionAdd()
  1310. {
  1311. $post = Yii::$app->request->post();
  1312. $discountPrice = $post['discountPrice'] ?? 0;
  1313. if ($discountPrice > 0) {
  1314. if (isset($post['hjDiscountPrice']) == false || empty($post['hjDiscountPrice'])) {
  1315. $addPrice = $post['addPrice'] ?? 0;
  1316. $hjAddPrice = $post['hjAddPrice'] ?? 0;
  1317. $skMore = $post['skMore'] ?? 0;
  1318. $diff = bcsub($addPrice, $hjAddPrice, 2);
  1319. if ($diff > 0 && $discountPrice > $diff) {
  1320. $hjDiscountPrice = bcsub($discountPrice, $diff, 2);
  1321. } else {
  1322. $hjDiscountPrice = $discountPrice;
  1323. }
  1324. $diff = bcsub($skMore, $addPrice, 2);
  1325. if ($diff > 0) {
  1326. $skDiscountPrice = bcadd($diff, $discountPrice, 2);
  1327. } else {
  1328. $skDiscountPrice = $discountPrice;
  1329. }
  1330. $post['skDiscountPrice'] = $skDiscountPrice;
  1331. $post['hjDiscountPrice'] = $hjDiscountPrice;
  1332. }
  1333. }
  1334. $shop = $this->shop;
  1335. $join = $shop->join ?? 0;
  1336. $default = $shop->default ?? 0;
  1337. if ($join == 0 && $default == 0) {
  1338. util::fail('当前直营分店,请切回总店添加花材');
  1339. }
  1340. $shopAdmin = $this->shopAdmin;
  1341. if (!isset($shopAdmin->super) || $shopAdmin->super != 1) {
  1342. util::fail('管理员才能添加花材');
  1343. }
  1344. $post['sjId'] = $this->sjId;
  1345. $post['adminId'] = $this->adminId;
  1346. $post['mainId'] = $this->mainId;
  1347. $price = $post['price'] ?? 0;
  1348. $addPrice = $post['addPrice'] ?? 0;
  1349. if ($addPrice > $price) {
  1350. //客户添加花材时,经常会出现加价大于售价的怦,这个时候就直接把加价全部设置为0
  1351. $post['addPrice'] = 0;
  1352. $post['hjAddPrice'] = 0;
  1353. $post['skMore'] = 0;
  1354. //util::fail('加价不能大于售价');
  1355. }
  1356. $weight = isset($post['weight']) && is_numeric($post['weight']) ? $post['weight'] : 0;
  1357. if ($weight <= 0) {
  1358. util::fail('请填写重量,最小0.1');
  1359. }
  1360. $post['staffName'] = $shopAdmin->name ?? '';
  1361. // 图片列表数组转换为字符串
  1362. if (is_array($post['images'])) {
  1363. $post['images'] = implode(',', $post['images']);
  1364. }
  1365. ProductClass::addProduct($post, $this->shop);
  1366. util::complete('添加成功');
  1367. }
  1368. //获取拼音缩写 ssh 20210707
  1369. public function actionPy()
  1370. {
  1371. $name = Yii::$app->request->get('name');
  1372. $py = stringUtil::py($name);
  1373. util::success(['py' => $py]);
  1374. }
  1375. //(客户端-批发商)复制花材
  1376. public function actionClone()
  1377. {
  1378. $post = Yii::$app->request->post();
  1379. $discountPrice = $post['discountPrice'] ?? 0;
  1380. if ($discountPrice > 0) {
  1381. if (isset($post['hjDiscountPrice']) == false || empty($post['hjDiscountPrice'])) {
  1382. $addPrice = $post['addPrice'] ?? 0;
  1383. $hjAddPrice = $post['hjAddPrice'] ?? 0;
  1384. $skMore = $post['skMore'] ?? 0;
  1385. $diff = bcsub($addPrice, $hjAddPrice, 2);
  1386. if ($diff > 0 && $discountPrice > $diff) {
  1387. $hjDiscountPrice = bcsub($discountPrice, $diff, 2);
  1388. } else {
  1389. $hjDiscountPrice = $discountPrice;
  1390. }
  1391. $diff = bcsub($skMore, $addPrice, 2);
  1392. if ($diff > 0) {
  1393. $skDiscountPrice = bcadd($diff, $discountPrice, 2);
  1394. } else {
  1395. $skDiscountPrice = $discountPrice;
  1396. }
  1397. $post['skDiscountPrice'] = $skDiscountPrice;
  1398. $post['hjDiscountPrice'] = $hjDiscountPrice;
  1399. }
  1400. }
  1401. $shop = $this->shop;
  1402. $join = $shop->join ?? 0;
  1403. $default = $shop->default ?? 0;
  1404. if ($join == 0 && $default == 0) {
  1405. util::fail('请在首店操作');
  1406. }
  1407. $shopAdmin = $this->shopAdmin;
  1408. if (isset($shopAdmin->super) == false || $shopAdmin->super != 1) {
  1409. util::fail('管理员才能添加花材');
  1410. }
  1411. $post['sjId'] = $this->sjId;
  1412. $post['adminId'] = $this->adminId;
  1413. $post['mainId'] = $this->mainId;
  1414. $post['staffName'] = $shopAdmin->name ?? '';
  1415. $price = $post['price'] ?? 0;
  1416. if (empty($price) || $price <= 0) {
  1417. util::fail('请填写批发价');
  1418. }
  1419. $skPrice = $post['skPrice'] ?? 0;
  1420. if (empty($skPrice) || $skPrice <= 0) {
  1421. util::fail('请填写零售价');
  1422. }
  1423. $hjPrice = $post['hjPrice'] ?? 0;
  1424. if (empty($hjPrice) || $hjPrice <= 0) {
  1425. util::fail('请填写会员价');
  1426. }
  1427. $addPrice = $post['addPrice'] ?? 0;
  1428. if ($addPrice > $price) {
  1429. util::fail('批发价的加价不能大于售价');
  1430. }
  1431. // 图片列表数组转换为字符串
  1432. if (is_array($post['images'])) {
  1433. $post['images'] = implode(',', $post['images']);
  1434. }
  1435. //复制标识
  1436. $post['copy'] = 1;
  1437. //去除无用的字段
  1438. unset($post['viewNum']);
  1439. unset($post['actualSold']);
  1440. unset($post['itemId']);
  1441. unset($post['id']);
  1442. unset($post['delStatus']);
  1443. unset($post['variety']);
  1444. ProductClass::addProduct($post, $this->shop);
  1445. util::complete('复制成功');
  1446. }
  1447. //下载价格表 ssh 20210922
  1448. public function actionGeneratePriceTable()
  1449. {
  1450. $level = Yii::$app->request->get('level', 0);
  1451. $respond = ProductService::generatePriceTable($this->sjId, $level, $this->mainId);
  1452. $file = $respond['file'] ?? '';
  1453. $shortFile = $respond['shortFile'] ?? '';
  1454. $fileUrl = Yii::$app->params['ghsHost'] . $file;
  1455. util::success(['file' => $fileUrl, 'shortFile' => $shortFile]);
  1456. }
  1457. //下载有库存花材,不含虚拟库存 ssh 20241-28
  1458. public function actionGenerateStockTable()
  1459. {
  1460. $level = Yii::$app->request->get('level', 0);
  1461. $respond = ProductService::generateStockTable($this->sjId, $level, $this->mainId);
  1462. $file = $respond['file'] ?? '';
  1463. $shortFile = $respond['shortFile'] ?? '';
  1464. $fileUrl = Yii::$app->params['ghsHost'] . $file;
  1465. util::success(['file' => $fileUrl, 'shortFile' => $shortFile]);
  1466. }
  1467. public function actionGenerateItemTable()
  1468. {
  1469. $level = Yii::$app->request->get('level', 0);
  1470. $respond = ProductService::generateItemTable($this->sjId, $level, $this->mainId);
  1471. $file = $respond['file'] ?? '';
  1472. $shortFile = $respond['shortFile'] ?? '';
  1473. $fileUrl = Yii::$app->params['ghsHost'] . $file;
  1474. util::success(['file' => $fileUrl, 'shortFile' => $shortFile]);
  1475. }
  1476. //下载条形码 lqh 20211227
  1477. public function actionGenerateBarcodeTable()
  1478. {
  1479. $respond = ProductService::generateBarcodeTable($this->sjId, $this->shopId, $this->mainId);
  1480. $file = $respond['file'] ?? '';
  1481. $shortFile = $respond['shortFile'] ?? '';
  1482. $fileUrl = Yii::$app->params['ghsHost'] . $file;
  1483. util::success(['file' => $fileUrl, 'shortFile' => $shortFile]);
  1484. }
  1485. //批量修改花材的分类 ssh 20230405
  1486. public function actionBatchModifyClass()
  1487. {
  1488. $post = Yii::$app->request->post();
  1489. $shop = $this->shop;
  1490. $sjName = $shop->merchantName ?? '';
  1491. $shopName = $shop->shopName ?? '';
  1492. $sjShopName = $shop->shopName == '首店' ? $sjName : $sjName . ' ' . $shopName;
  1493. //noticeUtil::push($sjShopName . ' 批量移动花材分类', '15280215347');
  1494. $join = $shop->join ?? 0;
  1495. $default = $shop->default ?? 0;
  1496. if ($join == 0 && $default == 0) {
  1497. util::fail('当前直营分店,请切回总店操作');
  1498. }
  1499. $classId = $post['classId'] ?? 0;
  1500. $class = ItemClassClass::getById($classId, true);
  1501. if (empty($class) || $class->mainId != $this->mainId) {
  1502. util::fail('请选择您自己的分类');
  1503. }
  1504. $connection = Yii::$app->db;
  1505. $transaction = $connection->beginTransaction();
  1506. try {
  1507. $className = $class->name ?? '';
  1508. $idsList = $post['ids'] ?? '';
  1509. $ids = json_decode($idsList, true);
  1510. if (empty($ids)) {
  1511. util::fail('请选择花材');
  1512. }
  1513. $list = ProductClass::getAllByCondition(['id' => ['in', $ids]], null, '*', null, true);
  1514. if (empty($list)) {
  1515. util::fail('请选择花材');
  1516. }
  1517. $ptItemList = [];
  1518. foreach ($list as $item) {
  1519. $name = $item->name ?? '';
  1520. if ($item->mainId != $this->mainId) {
  1521. util::fail($name . '不是您的花材');
  1522. }
  1523. $item->classId = $classId;
  1524. $item->save();
  1525. $ptItemId = $item->itemId ?? 0;
  1526. $ptItemList[] = $ptItemId;
  1527. //如果有修改分类,则在多个订单表中同步修改,如需修改,多个地方要同步修改,请搜索关键词item_class_modify_sync
  1528. $itemClassKey = 'item_class_modify_sync';
  1529. Yii::$app->redis->executeCommand('LPUSH', [$itemClassKey, $item->id]);
  1530. }
  1531. $shop = $this->shop;
  1532. if (isset($shop->default) && $shop->default == 1 && isset($shop->dataSync) && $shop->dataSync == 1) {
  1533. //总店修改同步到所有门店
  1534. $sjId = $shop->sjId ?? 0;
  1535. $chainShopList = ShopClass::getAllByCondition(['sjId' => $sjId], null, '*', null, true);
  1536. foreach ($chainShopList as $chainShop) {
  1537. $chainShopId = $chainShop->id ?? 0;
  1538. if ($chainShopId == $shop->id) {
  1539. continue;
  1540. }
  1541. $chainManId = $chainShop->mainId ?? 0;
  1542. $chainAllClassList = ItemClassClass::getAllByCondition(['mainId' => $chainManId], null, '*', null, true);
  1543. if (!empty($chainAllClassList)) {
  1544. foreach ($chainAllClassList as $chainClass) {
  1545. $chainName = $chainClass->name ?? '';
  1546. $chainClassId = $chainClass->id ?? 0;
  1547. if ($chainName == $className) {
  1548. $chainProductList = Productclass::getAllByCondition(['mainId' => $chainManId, 'itemId' => ['in', $ptItemList]], null, '*', null, true);
  1549. if (!empty($chainProductList)) {
  1550. foreach ($chainProductList as $currentProduct) {
  1551. $currentProduct->classId = $chainClassId;
  1552. $currentProduct->save();
  1553. //如果有修改分类,则在多个订单表中同步修改,如需修改,多个地方要同步修改,请搜索关键词item_class_modify_sync
  1554. $itemClassKey = 'item_class_modify_sync';
  1555. Yii::$app->redis->executeCommand('LPUSH', [$itemClassKey, $currentProduct->id]);
  1556. }
  1557. }
  1558. }
  1559. }
  1560. }
  1561. }
  1562. }
  1563. $transaction->commit();
  1564. util::complete('修改成功');
  1565. } catch (\Exception $e) {
  1566. $transaction->rollBack();
  1567. Yii::info("修改失败原因:" . $e->getMessage());
  1568. util::fail('修改失败');
  1569. }
  1570. }
  1571. //批量修改采购人 ssh 20240609
  1572. public function actionBatchModifyCgStaff()
  1573. {
  1574. $post = Yii::$app->request->post();
  1575. $staffId = $post['staffId'] ?? 0;
  1576. $staff = ShopAdminClass::getById($staffId, true);
  1577. if (empty($staff)) {
  1578. util::fail('没有找到这个员工');
  1579. }
  1580. if ($staff->mainId != $this->mainId) {
  1581. util::fail('不是你的员工');
  1582. }
  1583. $staffName = $staff->name ?? '';
  1584. $connection = Yii::$app->db;
  1585. $transaction = $connection->beginTransaction();
  1586. try {
  1587. $idsList = $post['ids'] ?? '';
  1588. $ids = json_decode($idsList, true);
  1589. if (empty($ids)) {
  1590. util::fail('请选择花材');
  1591. }
  1592. $list = ProductClass::getAllByCondition(['id' => ['in', $ids]], null, '*', null, true);
  1593. if (empty($list)) {
  1594. util::fail('请选择花材');
  1595. }
  1596. $shop = $this->shop;
  1597. $bookSn = $shop->bookSn ?? 0;
  1598. foreach ($list as $item) {
  1599. $name = $item->name ?? '';
  1600. if ($item->mainId != $this->mainId) {
  1601. util::fail($name . '不是您的花材');
  1602. }
  1603. $item->cgStaffId = $staffId;
  1604. $item->cgStaffName = $staffName;
  1605. $item->save();
  1606. $itemId = $item->id ?? 0;
  1607. if (!empty($bookSn)) {
  1608. //预订管理的花材需要变化
  1609. BookItemClass::updateByCondition(['bookSn' => $bookSn, 'itemId' => $itemId], ['cgStaffId' => $staffId, 'cgStaffName' => $staffName]);
  1610. }
  1611. }
  1612. $transaction->commit();
  1613. util::complete('修改成功');
  1614. } catch (\Exception $e) {
  1615. $transaction->rollBack();
  1616. Yii::info("修改失败原因:" . $e->getMessage());
  1617. util::fail('修改失败');
  1618. }
  1619. }
  1620. //修改属于成本还是收入选项 ssh 20240514
  1621. public function actionChangeBelongCost()
  1622. {
  1623. $get = Yii::$app->request->get();
  1624. $id = $get['id'] ?? 0;
  1625. $belongCost = $get['belongCost'] ?? 0;
  1626. $info = ProductClass::getById($id, true);
  1627. if (empty($info)) {
  1628. util::fail('没有找到花材');
  1629. }
  1630. if ($info->mainId != $this->mainId) {
  1631. util::fail('不是你的花材哦');
  1632. }
  1633. $info->belongCost = $belongCost;
  1634. $info->save();
  1635. //队列方式去处理
  1636. $redisKey = 'change_belong_cost_item_list';
  1637. $value = $id . '_' . $belongCost;
  1638. Yii::$app->redis->executeCommand('LPUSH', [$redisKey, $value]);
  1639. util::complete('修改成功');
  1640. }
  1641. //修改拆散接收的花材 ssh 20251124
  1642. public function actionModifyPartAcceptItem()
  1643. {
  1644. $get = Yii::$app->request->get();
  1645. $smallId = $get['small'] ?? 0;
  1646. $bigId = $get['big'] ?? 0;
  1647. $small = ProductClass::getById($smallId, true);
  1648. if (empty($small)) {
  1649. util::fail('子花材没找到');
  1650. }
  1651. $smallName = $small->name ?? '';
  1652. if ($small->mainId != $this->mainId) {
  1653. util::fail($smallName . '不是你的花材');
  1654. }
  1655. if ($small->ratio != 1) {
  1656. util::fail($smallName . '不是1支装的');
  1657. }
  1658. $big = ProductClass::getById($bigId, true);
  1659. if (empty($big)) {
  1660. util::fail('没有找到花材');
  1661. }
  1662. if ($big->mainId != $this->mainId) {
  1663. util::fail('不是你的花材呢');
  1664. }
  1665. $change = UnitChangeClass::getByCondition(['big' => $bigId], true);
  1666. if (empty($change)) {
  1667. UnitChangeClass::add(['big' => $bigId, 'small' => $smallId], true);
  1668. } else {
  1669. $change->small = $smallId;
  1670. $change->save();
  1671. }
  1672. util::complete('修改成功');
  1673. }
  1674. }