ProductController.php 71 KB

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