ProductController.php 75 KB

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