ProductController.php 74 KB

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