ProductController.php 69 KB

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