ProductController.php 73 KB

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