ProductController.php 74 KB

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