GoodsService.php 93 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145
  1. <?php
  2. namespace app\admin\service\goods;
  3. use app\model\Appointment;
  4. use app\model\Goods;
  5. use app\model\GoodsComponent;
  6. use app\model\GoodsDetail;
  7. use app\model\GoodsLabel;
  8. use app\model\GoodsRunning;
  9. use app\model\GoodsSku;
  10. use app\model\OrderSheet;
  11. use app\model\SysCategory;
  12. use app\model\SysDept;
  13. use app\model\SysSerial;
  14. use app\model\SysUser;
  15. use support\Db;
  16. use support\exception\BusinessException;
  17. use support\Redis;
  18. use support\Request;
  19. use support\Response;
  20. use Tinywan\Jwt\JwtToken;
  21. class GoodsService
  22. {
  23. public static function selectAll($goodsIds)
  24. {
  25. $goods = Goods::where('goods_status', 'ON')
  26. ->when($goodsIds != '', function ($query) use ($goodsIds) {
  27. $query->whereIn('goods_id', $goodsIds);
  28. })
  29. ->select('goods_id', 'goods_name')
  30. ->get();
  31. return json_success('', $goods);
  32. }
  33. public static function selectAllByGoodsName($goodsName)
  34. {
  35. $goods = Goods::with('sku')
  36. ->where('goods_status', 'ON')
  37. ->when($goodsName != '', function ($query) use ($goodsName) {
  38. $query->where('goods_name', 'like', "%" . $goodsName . '%');
  39. })
  40. ->select('goods_id', 'goods_name')
  41. ->get()
  42. ->toArray();
  43. foreach ($goods as &$item) {
  44. if (!empty($item['sku'])) {
  45. foreach ($item['sku'] as $key => $sku) {
  46. $specsJson = json_decode($sku['goods_sku_specs_json'], true);
  47. $skuTitle = '';
  48. foreach ($specsJson as $item2) {
  49. if (is_array($item2)) {
  50. $item2 = implode(',', $item2);
  51. }
  52. $skuTitle .= $item2 . '-';
  53. }
  54. $item['sku'][$key]['goods_sku_id'] = strval($item['sku'][$key]['goods_sku_id']);
  55. $item['sku'][$key]['goods_sku_title'] = rtrim($skuTitle, '-');
  56. }
  57. }
  58. }
  59. return json_success('', $goods);
  60. }
  61. public static function selectAllByCategoryForRuleAddComponent($category = "GOODS")
  62. {
  63. $categoryIds = [];
  64. if ($category == 'GOODS') {
  65. $categorySuperIds = [5];
  66. } elseif ($category == 'SERVICE') {
  67. $categorySuperIds = [31, 154, 42, 65, 30, 66, 72, 70];
  68. }
  69. $categorys = SysCategory::whereIn('category_id', $categorySuperIds)->get()->toArray();
  70. foreach ($categorys as $item) {
  71. if (empty($item['category_super_path'])) {
  72. $item['category_super_path'] = '#' . $item['category_id'] . '#';
  73. } else {
  74. $item['category_super_path'] = $item['category_super_path'] . '#' . $item['category_id'] . '#';
  75. }
  76. $categoryIds = SysCategory::where('category_super_path', 'like', '%' . $item['category_super_path'])->pluck('category_id');
  77. $categoryIds = $categoryIds ? $categoryIds->toArray() : [];
  78. $categorySuperIds = array_merge($categorySuperIds, $categoryIds);
  79. }
  80. $categoryIds = array_unique($categorySuperIds);
  81. $goods = Goods::with('sku')
  82. // ->where('goods_classify', $category)
  83. ->when(!empty($categoryIds), function ($query) use ($categoryIds) {
  84. $query->whereIn('join_goods_category_id', $categoryIds);
  85. })->select('goods_id', 'goods_name', 'join_goods_category_id')
  86. ->get()
  87. ->toArray();
  88. foreach ($goods as &$good) {
  89. if (!empty($good['sku'])) {
  90. foreach ($good['sku'] as $key => $sku) {
  91. if (!empty($sku['goods_sku_specs_json'])) {
  92. $specsJson = json_decode($sku['goods_sku_specs_json'], true);
  93. $skuTitle = '';
  94. foreach ($specsJson as $item) {
  95. if (is_array($item)) {
  96. $item = implode(',', $item);
  97. }
  98. $skuTitle .= $item . '-';
  99. }
  100. $good['sku'][$key]['goods_sku_id'] = strval($good['sku'][$key]['goods_sku_id']);
  101. $good['sku'][$key]['goods_sku_title'] = rtrim($skuTitle, '-');
  102. }
  103. unset($good['sku'][$key]['goods_sku_specs_json'], $good['sku'][$key]['join_sku_goods_id']);
  104. }
  105. } else {
  106. $good['sku'] = [];
  107. }
  108. }
  109. return json_success('', $goods);
  110. }
  111. public static function selectPremisesByGoodsId($goodsId)
  112. {
  113. $goods = Goods::where('goods_id', $goodsId)
  114. ->select('goods_id', 'goods_attribute_json')
  115. ->first();
  116. $premisses = [];
  117. if (!empty($goods->goods_attribute_json)) {
  118. $attributeJson = json_decode($goods->goods_attribute_json, true);
  119. if (isset($attributeJson['premisses'])) {
  120. $premisses = SysDept::whereIn('dept_id', $attributeJson['premisses'])
  121. ->select('dept_id', 'dept_name')
  122. ->get()
  123. ->toArray();
  124. }
  125. }
  126. return json_success('', $premisses);
  127. }
  128. public static function select(Request $request, $classify = "GOODS")
  129. {
  130. $page = $request->get('page', 1);
  131. $pageSize = $request->get('pageSize', 20);
  132. $goodsName = $request->get('goods_name', '');
  133. $categoryId = $request->get('join_goods_category_id', null);
  134. $goodsCategory = $request->get('goods_category', null);
  135. if ($categoryId != null) {
  136. $categoryPath = SysCategory::where('category_id', $categoryId)->value('category_super_path');
  137. $categoryPath .= '#' . $categoryId . '#';
  138. $categoryIds = SysCategory::where('category_super_path', 'like', $categoryPath . '%')->pluck('category_id')->toArray();
  139. $categoryIds[] = $categoryId;
  140. if (!empty($categoryIds)) {
  141. $categoryId = $categoryIds;
  142. } else {
  143. $categoryId = [$categoryId];
  144. }
  145. }
  146. $rows = Goods::with([
  147. 'category' => function ($query) {
  148. $query->select('category_id', 'category_name');
  149. },
  150. 'running' => function ($query) {
  151. $query->select('join_running_goods_id', 'goods_running_storage');
  152. },
  153. 'supplier' => function ($query) {
  154. $query->select('supplier_id', 'supplier_name');
  155. },
  156. 'user'=>function($query){
  157. $query->select('user_id', 'user_name');
  158. }
  159. ])->select('goods_id', 'join_goods_category_id', 'join_goods_supplier_id','creator_user_id', 'goods_status', 'goods_sales_price', 'goods_category', 'goods_name', 'goods_title', 'goods_cover', 'goods_sort', 'goods_attribute_json', 'goods_addtimes','goods_updatetimes')
  160. ->when($goodsName != '', function ($query) use ($goodsName) {
  161. $query->where(function ($q) use ($goodsName) {
  162. $q->where('goods_name', 'like', '%' . $goodsName . '%')
  163. ->OrWhere('goods_title', 'like', '%' . $goodsName . '%');
  164. });
  165. })->when($categoryId != null, function ($query) use ($categoryId) {
  166. $query->whereIn('join_goods_category_id', $categoryId);
  167. })->when($goodsCategory != null, function ($query) use ($goodsCategory) {
  168. $query->where('goods_category', $goodsCategory);
  169. })
  170. ->when($classify != '', function ($query) use ($classify,$categoryId) {
  171. if ($classify == 'GOODS' && empty($categoryId)) {
  172. $query->whereIn('join_goods_category_id', ['6', '7', '8', '9', '10', '11', '12', '30']);
  173. } else if($classify != 'GOODS') {
  174. $query->where('goods_classify', $classify);
  175. }
  176. })
  177. ->orderBy('goods_sort', 'DESC')
  178. ->orderBy('goods_addtimes', 'DESC')
  179. ->forPage($page, $pageSize)
  180. ->get()
  181. ->toArray();
  182. $total = Goods::when($goodsName != '', function ($query) use ($goodsName) {
  183. $query->where(function ($q) use ($goodsName) {
  184. $q->where('goods_name', 'like', '%' . $goodsName . '%')
  185. ->OrWhere('goods_title', 'like', '%' . $goodsName . '%');
  186. });
  187. })->when($categoryId != null, function ($query) use ($categoryId) {
  188. $query->whereIn('join_goods_category_id', $categoryId);
  189. })->when($goodsCategory != null, function ($query) use ($goodsCategory) {
  190. $query->where('goods_category', $goodsCategory);
  191. })->when($classify != '', function ($query) use ($classify,$categoryId) {
  192. if ($classify == 'GOODS' && empty($categoryId)) {
  193. $query->whereIn('join_goods_category_id', ['6', '7', '8', '9', '10', '11', '12', '30']);
  194. } else if($classify != 'GOODS') {
  195. $query->where('goods_classify', $classify);
  196. }
  197. })
  198. ->count();
  199. foreach ($rows as &$row) {
  200. $row['goods_cover'] = getenv('STORAGE_DOMAIN') . $row['goods_cover'];
  201. if (isset($row['running'])) {
  202. $row['running']['goods_running_storage'] = intval($row['running']['goods_running_storage']);
  203. }
  204. if (!empty($row['goods_attribute_json'])) {
  205. $row['goods_attribute_json'] = json_decode($row['goods_attribute_json']);
  206. }
  207. }
  208. return json_success('', compact('rows', 'page', 'pageSize', 'total'));
  209. }
  210. public static function selectSpecial(Request $request)
  211. {
  212. $page = $request->get('page');
  213. $pageSize = $request->get('pageSize');
  214. $goodsName = $request->get('goods_name', '');
  215. $categoryId = $request->get('join_goods_category_id', null);
  216. if ($categoryId == null) {
  217. $categoryId = [65, 43];
  218. } elseif (is_string($categoryId)) {
  219. $categoryId = [$categoryId];
  220. }
  221. $rows = Goods::with([
  222. 'category' => function ($query) {
  223. $query->select('category_id', 'category_name');
  224. },
  225. 'running' => function ($query) {
  226. $query->select('join_running_goods_id', 'goods_running_storage');
  227. },
  228. 'supplier' => function ($query) {
  229. $query->select('supplier_id', 'supplier_name');
  230. },
  231. 'user'=>function($query){
  232. $query->select('user_id', 'user_name');
  233. }
  234. ])->select('goods_id', 'join_goods_category_id', 'join_goods_supplier_id','creator_user_id', 'goods_status', 'goods_sales_price', 'goods_category', 'goods_name', 'goods_title', 'goods_cover', 'goods_sort', 'goods_addtimes','goods_updatetimes')
  235. ->when($goodsName != '', function ($query) use ($goodsName) {
  236. $query->where(function ($q) use ($goodsName) {
  237. $q->where('goods_name', 'like', '%' . $goodsName . '%')
  238. ->OrWhere('goods_title', 'like', '%' . $goodsName . '%');
  239. });
  240. })->whereIn('join_goods_category_id', $categoryId)
  241. ->orderBy('goods_sort', 'DESC')
  242. ->orderBy('goods_addtimes', 'DESC')
  243. ->forPage($page, $pageSize)
  244. ->get()
  245. ->toArray();
  246. $total = Goods::when($goodsName != '', function ($query) use ($goodsName) {
  247. $query->where(function ($q) use ($goodsName) {
  248. $q->where('goods_name', 'like', '%' . $goodsName . '%')
  249. ->OrWhere('goods_title', 'like', '%' . $goodsName . '%');
  250. });
  251. })->whereIn('join_goods_category_id', $categoryId)->count();
  252. foreach ($rows as &$row) {
  253. $row['goods_cover'] = getenv('STORAGE_DOMAIN') . $row['goods_cover'];
  254. if (isset($row['running'])) {
  255. $row['running']['goods_running_storage'] = intval($row['running']['goods_running_storage']);
  256. }
  257. }
  258. return json_success('', compact('rows', 'page', 'pageSize', 'total'));
  259. }
  260. public static function selectPicking(Request $request)
  261. {
  262. $page = $request->get('page');
  263. $pageSize = $request->get('pageSize');
  264. $goodsName = $request->get('goods_name', '');
  265. $categorySuperId = $request->get('category_super_id', '');
  266. $categoryIds = $request->get('join_goods_category_id', []);
  267. if (!empty($categorySuperId) && is_array($categoryIds)) {
  268. $category = SysCategory::where('category_id', $categorySuperId)->first();
  269. if (empty($category->category_super_path)) {
  270. $category->category_super_path = '#' . $categorySuperId . '#';
  271. } else {
  272. $category->category_super_path = $category->category_super_path . '#' . $categorySuperId . '#';
  273. }
  274. $categoryIds = SysCategory::where('category_super_path', 'like', '%' . $category->category_super_path)->pluck('category_id');
  275. $categoryIds = $categoryIds ? $categoryIds->toArray() : [];
  276. $categoryIds = array_merge($categoryIds, [$categorySuperId]);
  277. } elseif (!is_array($categoryIds)) {
  278. $categoryIds = [$categoryIds];
  279. }
  280. $rows = Goods::with([
  281. 'category' => function ($query) {
  282. $query->select('category_id', 'category_name');
  283. },
  284. 'running' => function ($query) {
  285. $query->select('join_running_goods_id', 'goods_running_storage');
  286. },
  287. 'supplier' => function ($query) {
  288. $query->select('supplier_id', 'supplier_name');
  289. },
  290. 'user'=>function($query){
  291. $query->select('user_id', 'user_name');
  292. }
  293. ])->select('goods_id', 'join_goods_category_id', 'join_goods_supplier_id','creator_user_id', 'goods_status', 'goods_sales_price', 'goods_category', 'goods_name', 'goods_title', 'goods_cover', 'goods_sort', 'goods_addtimes','goods_updatetimes')
  294. ->when($goodsName != '', function ($query) use ($goodsName) {
  295. $query->where(function ($q) use ($goodsName) {
  296. $q->where('goods_name', 'like', '%' . $goodsName . '%')
  297. ->OrWhere('goods_title', 'like', '%' . $goodsName . '%');
  298. });
  299. })->whereIn('join_goods_category_id', $categoryIds)
  300. ->orderBy('goods_sort', 'DESC')
  301. ->orderBy('goods_addtimes', 'DESC')
  302. ->forPage($page, $pageSize)
  303. ->get()
  304. ->toArray();
  305. $total = Goods::when($goodsName != '', function ($query) use ($goodsName) {
  306. $query->where(function ($q) use ($goodsName) {
  307. $q->where('goods_name', 'like', '%' . $goodsName . '%')
  308. ->OrWhere('goods_title', 'like', '%' . $goodsName . '%');
  309. });
  310. })->whereIn('join_goods_category_id', $categoryIds)
  311. ->count();
  312. foreach ($rows as &$row) {
  313. $row['goods_cover'] = getenv('STORAGE_DOMAIN') . $row['goods_cover'];
  314. if (isset($row['running'])) {
  315. $row['running']['goods_running_storage'] = intval($row['running']['goods_running_storage']);
  316. }
  317. }
  318. return json_success('', compact('rows', 'page', 'pageSize', 'total'));
  319. }
  320. public static function selectPackage(Request $request)
  321. {
  322. $page = $request->get('page');
  323. $pageSize = $request->get('pageSize');
  324. $goodsName = $request->get('goods_name', '');
  325. $categoryId = $request->get('join_goods_category_id', null);
  326. $rows = Goods::with([
  327. 'category' => function ($query) {
  328. $query->select('category_id', 'category_name');
  329. },
  330. 'running' => function ($query) {
  331. $query->select('join_running_goods_id', 'goods_running_storage');
  332. },
  333. 'supplier' => function ($query) {
  334. $query->select('supplier_id', 'supplier_name');
  335. },
  336. 'user'=>function($query){
  337. $query->select('user_id', 'user_name');
  338. }
  339. ])->select('goods_id', 'join_goods_category_id', 'join_goods_supplier_id','creator_user_id', 'goods_status', 'goods_sales_price', 'goods_category', 'goods_name', 'goods_title', 'goods_cover', 'goods_sort', 'goods_addtimes','goods_updatetimes')
  340. ->when($goodsName != '', function ($query) use ($goodsName) {
  341. $query->where(function ($q) use ($goodsName) {
  342. $q->where('goods_name', 'like', '%' . $goodsName . '%')
  343. ->OrWhere('goods_title', 'like', '%' . $goodsName . '%');
  344. });
  345. })->when($categoryId != null, function ($query) use ($categoryId) {
  346. $query->where('join_goods_category_id', $categoryId);
  347. })
  348. ->where('goods_classify', 'PACKAGE')
  349. ->orderBy('goods_sort', 'DESC')
  350. ->orderBy('goods_addtimes', 'DESC')
  351. ->forPage($page, $pageSize)
  352. ->get()
  353. ->toArray();
  354. $total = Goods::when($goodsName != '', function ($query) use ($goodsName) {
  355. $query->where(function ($q) use ($goodsName) {
  356. $q->where('goods_name', 'like', '%' . $goodsName . '%')
  357. ->OrWhere('goods_title', 'like', '%' . $goodsName . '%');
  358. });
  359. })->when($categoryId != null, function ($query) use ($categoryId) {
  360. $query->where('join_goods_category_id', $categoryId);
  361. })->where('goods_classify', 'PACKAGE')->count();
  362. foreach ($rows as &$row) {
  363. $row['goods_cover'] = getenv('STORAGE_DOMAIN') . $row['goods_cover'];
  364. if (isset($row['running'])) {
  365. $row['running']['goods_running_storage'] = intval($row['running']['goods_running_storage']);
  366. }
  367. // if (!empty($row['component'])) {
  368. // $ids = [];
  369. // $contentList = [];
  370. // foreach ($row['component'] as $component) {
  371. // $ids[] = $component['join_component_goods_id'];
  372. // $configJson = json_decode($component['goods_component_config_json'], true);
  373. // $contentList[] = [
  374. // 'goods_name' => $configJson['goods_name'] ?? '',
  375. // 'goods_sales_price' => $component['goods_component_price'],
  376. // 'nbr' => $configJson['nbr'] ?? 0
  377. // ];
  378. // }
  379. //
  380. // $row['join_component_goods_id'] = $ids;
  381. // $row['goodsContentList'] = $contentList;
  382. // }
  383. }
  384. return json_success('', compact('rows', 'page', 'pageSize', 'total'));
  385. }
  386. /**
  387. * @Desc 下拉选择服务商品
  388. * @Author Gorden
  389. * @Date 2024/4/24 13:32
  390. *
  391. * @param Request $request
  392. * @return Response
  393. */
  394. public static function selectList(Request $request, $goodsClassify = "SERVICE")
  395. {
  396. $keywords = $request->get('keywords', '');
  397. $isSupportAppointment = $request->get('is_support_appointment', '');
  398. // if (!$keywords){
  399. // return json_success('暂无数据');
  400. // }
  401. // $categoryIds = SysCategory::whereIn('category_super_id', [5, 31, 32, 42, 66, 70, 72])->pluck('category_id');
  402. $goods = Goods::with('sku')
  403. // ->whereIn('join_goods_category_id', $categoryIds)
  404. ->when($keywords != '', function ($query) use ($keywords) {
  405. $query->where('goods_name', 'like', "%" . $keywords . "%");
  406. })
  407. ->when($goodsClassify != '', function ($query) use ($goodsClassify) {
  408. if($goodsClassify == 'NOPACKAGE'){
  409. $query->where('goods_classify','<>', 'PACKAGE');
  410. }else{
  411. $query->where('goods_classify', $goodsClassify);
  412. }
  413. })
  414. ->when($isSupportAppointment != '', function ($query) use ($isSupportAppointment) {
  415. $query->where('is_support_appointment', $isSupportAppointment);
  416. })
  417. ->select('goods_id', 'goods_name', 'goods_sales_price', 'join_goods_category_id', 'goods_attribute_json')
  418. ->get()
  419. ->toArray();
  420. foreach ($goods as &$good) {
  421. if (!empty($good['sku'])) {
  422. foreach ($good['sku'] as $key => $sku) {
  423. if (!empty($sku['goods_sku_specs_json'])) {
  424. $good['sku'][$key]['goods_sku_specs_json'] = json_decode($sku['goods_sku_specs_json']);
  425. $skuName = '';
  426. foreach ($good['sku'][$key]['goods_sku_specs_json'] as $specsKey => $skuSpecs) {
  427. if (is_array($skuSpecs)) {
  428. $skuName = $skuName . ' ' . $specsKey . ':' . implode(' ', $skuSpecs) . ';';
  429. } else {
  430. $skuName = $skuName . ' ' . $specsKey . ':' . $skuSpecs . ';';
  431. }
  432. }
  433. $good['sku'][$key]['sku_name'] = $skuName;
  434. }
  435. }
  436. } else {
  437. $good['sku'] = [];
  438. }
  439. $good['premisses'] = [];
  440. if (!empty($good['goods_attribute_json'])) {
  441. $attributeJson = json_decode($good['goods_attribute_json'], true);
  442. if (isset($attributeJson['premisses'])) {
  443. $premisses = SysDept::when(!empty($attributeJson['premisses']), function ($query) use ($attributeJson) {
  444. $query->whereIn('dept_id', $attributeJson['premisses']);
  445. })->where('dept_category', '营业场所')
  446. ->select('dept_id', 'dept_name')
  447. ->get();
  448. $good['premisses'] = $premisses;
  449. }
  450. }
  451. }
  452. return json_success('', $goods);
  453. }
  454. /**
  455. * @Desc 商品详情
  456. * @Author Gorden
  457. * @Date 2024/3/28 10:25
  458. *
  459. * @param $goodsId
  460. * @return Response
  461. */
  462. public static function info($goodsId)
  463. {
  464. try {
  465. // 商品主表
  466. $main = Goods::with('category')->where('goods_id', $goodsId)->first();
  467. if (!empty($main)) {
  468. $main = $main->toArray();
  469. $main['goods_sku_json'] = json_decode($main['goods_sku_json'], true);
  470. $main['specList'] = [];
  471. foreach ($main['goods_sku_json'] as $key => $sku) {
  472. $main['specList'][] = [
  473. 'label' => $key,
  474. 'tags' => $sku
  475. ];
  476. }
  477. } else {
  478. $main = [];
  479. }
  480. // 详情表
  481. $detail = GoodsDetail::where('join_detail_goods_id', $goodsId)->first();
  482. if (!empty($detail)) {
  483. $detail = $detail->toArray();
  484. } else {
  485. $detail = [];
  486. }
  487. // 标签表
  488. $label = GoodsLabel::where('join_label_goods_id', $goodsId)->first();
  489. if (!empty($label)) {
  490. $label = $label->toArray();
  491. } else {
  492. $label = [];
  493. }
  494. // Running表
  495. $running = GoodsRunning::where('join_running_goods_id', $goodsId)->first();
  496. if (!empty($running)) {
  497. $running = $running->toArray();
  498. if (!empty($running['goods_running_off_json']) && is_json($running['goods_running_off_json'])) {
  499. $goodsRunningOffJson = json_decode($running['goods_running_off_json'], true);
  500. $running['goods_off_addtimes'] = isset($goodsRunningOffJson['time']) ? date("Y-m-d H:i", $goodsRunningOffJson['time']) : '';
  501. }
  502. $running['goods_running_storage'] = !empty($running['goods_running_storage']) ? intval($running['goods_running_storage']) : '';
  503. $running['goods_running_sale'] = !empty($running['goods_running_sale']) ? intval($running['goods_running_sale']) : '';
  504. } else {
  505. $running = [];
  506. }
  507. // Sku表
  508. $skus = GoodsSku::where('join_sku_goods_id', $goodsId)->get();
  509. if (!empty($skus)) {
  510. $skus = $skus->toArray();
  511. $submitList = [];
  512. foreach ($skus as $key => $sku) {
  513. $skuSpecsJson = json_decode($sku['goods_sku_specs_json'], true);
  514. $skuSpecs = '';
  515. $skuNameValue = [];
  516. $i = 1;
  517. foreach ($skuSpecsJson as $k => $item) {
  518. if (is_array($item)) {
  519. $item = implode(',', $item);
  520. }
  521. $skuSpecs = $skuSpecs . $item . ',';
  522. $skuNameKey = 'skuName' . $i;
  523. $skuValueKey = 'skuValue' . $i;
  524. $skuNameValue[$skuNameKey] = $k;
  525. $skuNameValue[$skuValueKey] = $item;
  526. $skuNameValue[$k] = $item;
  527. $i++;
  528. }
  529. $storage = json_decode($sku['goods_sku_storage_json'], true);
  530. $priceStorage = [
  531. 'sku_id' => $sku['goods_sku_id'],
  532. 'sku' => rtrim($skuSpecs, ',') ?? '',
  533. 'stock' => $storage['storage'] ?? '',
  534. 'price' => $sku['goods_sku_sales_price'] ?? '',
  535. ];
  536. $submitList[] = array_merge($skuNameValue, $priceStorage);
  537. }
  538. $skus['submitList'] = $submitList;
  539. } else {
  540. $skus = [];
  541. }
  542. // 合并数据
  543. $data = array_merge($main, $detail, $label, $running, ['sku' => $skus]);
  544. $data['goods_sku_json_label'] = [];
  545. $data['goods_label'] = !empty($data['goods_label']) ? explode(',', $data['goods_label']) : [];
  546. $data['goods_json'] = $data['goods_json'] ? json_decode($data['goods_json'], true) : [];
  547. $data['goods_cover'] = getenv('STORAGE_DOMAIN') . $data['goods_cover'];
  548. // 创建者
  549. $data['creator_username'] = '';
  550. if (!empty($data['creator_user_id'])){
  551. $data['creator_username'] = SysUser::where('user_id',$data['creator_user_id'])->value('user_name');
  552. }
  553. if (!empty($data['goods_detail_slider_json'])) {
  554. $data['goods_detail_slider_json'] = json_decode($data['goods_detail_slider_json'], true);
  555. // ……
  556. if (isset($data['goods_detail_slider_json']['slider'])) {
  557. $data['goods_detail_slider_json'] = explode(',', $data['goods_detail_slider_json']['slider']);
  558. }
  559. $slider = '';
  560. foreach ($data['goods_detail_slider_json'] as $item) {
  561. $slider .= getenv('STORAGE_DOMAIN') . $item . ',';
  562. }
  563. $data['goods_detail_slider_json'] = rtrim($slider, ',');
  564. }
  565. $extendJson = [];
  566. if (!empty($data['goods_attribute_json'])) {
  567. $extendJson = json_decode($data['goods_attribute_json'], true);
  568. $data['goods_attribute_json'] = $extendJson;
  569. if (isset($extendJson['premisses'])) {
  570. $data['goods_premisses'] = $extendJson['premisses'];
  571. $data['goods_premisses_str'] = SysDept::whereIn('dept_id', $extendJson['premisses'])->pluck('dept_name');
  572. }
  573. if (isset($extendJson['bg'])) {
  574. $data['goods_theme_color'] = $extendJson['bg'];
  575. }
  576. if (isset($extendJson['icon'])) {
  577. $data['goods_theme_icon'] = getenv('STORAGE_DOMAIN') . $extendJson['icon'];
  578. }
  579. if (isset($extendJson['service_premises_id'])){
  580. $data['goods_service_premises'] = $extendJson['service_premises_id'];
  581. }
  582. }
  583. $data['appointment_times'] = [];
  584. if ($data['is_support_appointment'] == 'Y' && isset($extendJson['dates'])) {
  585. $data['dates'] = $extendJson['dates'] ?? [];
  586. if (isset($extendJson['times'])) {
  587. $times = [];
  588. foreach ($extendJson['times'] as $time) {
  589. if (!empty($time['duration'])) {
  590. $startEndTime = explode('-', $time['duration']);
  591. $times[] = [
  592. 'person' => $time['person'],
  593. 'appointmentTimeStart' => $startEndTime[0],
  594. 'appointmentTimeEnd' => $startEndTime[1],
  595. ];
  596. }
  597. }
  598. $data['appointment_times'] = $times;
  599. }
  600. if (isset($extendJson['time'])){
  601. $extendJsonTime = explode('至',$extendJson['time']);
  602. if(isset($extendJsonTime[0]) && isset($extendJsonTime[1])){
  603. $data['work_time'] = [
  604. date('Y-m-d H:i:s',strtotime(date('Y-m-d ').$extendJsonTime[0])),
  605. date('Y-m-d H:i:s',strtotime(date('Y-m-d ').$extendJsonTime[1])),
  606. ];
  607. }
  608. }
  609. if (isset($extendJson['teachers'])){
  610. $data['teachers'] = $extendJson['teachers'];
  611. }
  612. if (isset($extendJson['address'])) {
  613. $data['address'] = $extendJson['address'];
  614. }
  615. if (isset($extendJson['min-count'])){
  616. $data['min_count'] = $extendJson['min-count'];
  617. }
  618. if (isset($extendJson['position'])) {
  619. $data['position'] = $extendJson['position'];
  620. }
  621. if (isset($extendJson['label'])) {
  622. $data['appointment_label'] = $extendJson['label'];
  623. }
  624. }
  625. if (isset($extendJson['month']) && $data['is_support_appointment'] == 'Y'){
  626. $times = [];
  627. foreach ($extendJson['month'] as $monKey => $months){
  628. foreach ($months as $day => $person){
  629. $times[] = [
  630. 'days'=>date('Y-m-d',strtotime($monKey.$day)),
  631. 'person'=>$person
  632. ];
  633. }
  634. }
  635. $data['appointment_times'] = $times;
  636. $data['travel_begin'] = $extendJson['travel-begin'];
  637. $data['travel_day'] = $extendJson['travel-day'];
  638. $data['travel_night'] = $extendJson['travel-night'];
  639. $data['travel_trans'] = $extendJson['travel-trans'];
  640. }
  641. if (!empty($data['goods_json']) && $data['join_goods_category_id'] == 65) {
  642. // foreach ($data['goods_json'] as $key => $datum) {
  643. // $data['goods_json'][$key]['color'] = rgbToHex($datum['color']);
  644. // }
  645. } elseif (!empty($data['goods_json']) && $data['join_goods_category_id'] == 43) {
  646. $goodsJsonNew = [];
  647. foreach ($data['goods_json'] as $key1 => $item1) {
  648. $itemsNew = [];
  649. if (isset($item1['items'])) {
  650. foreach ($item1['items'] as $key2 => $item2) {
  651. $itemsNew[] = [
  652. 'key' => $key2,
  653. 'params' => $item2
  654. ];
  655. }
  656. }
  657. $goodsJsonNew[] = [
  658. 'title' => $key1,
  659. 'service' => $item1['service'] ?? '',
  660. 'items' => $itemsNew
  661. ];
  662. }
  663. $data['goods_json'] = $goodsJsonNew;
  664. }
  665. $data['goods_on_addtimes'] = date('Y-m-d\TH:i:s.u\Z', $data['goods_on_addtimes'] - 60 * 60 * 8);
  666. return json_success('', $data);
  667. } catch (\Exception $e) {
  668. dump($e->getMessage());
  669. return json_fail("查询错误~");
  670. }
  671. }
  672. public static function infoPackage($goodsId)
  673. {
  674. try {
  675. // 商品主表
  676. $main = Goods::where('goods_id', $goodsId)->first();
  677. if (!empty($main)) {
  678. $main = $main->toArray();
  679. $main['goods_sku_json'] = json_decode($main['goods_sku_json'], true);
  680. $main['specList'] = [];
  681. foreach ($main['goods_sku_json'] as $key => $sku) {
  682. $main['specList'][] = [
  683. 'label' => $key,
  684. 'tags' => $sku
  685. ];
  686. }
  687. } else {
  688. $main = [];
  689. }
  690. // 详情表
  691. $detail = GoodsDetail::where('join_detail_goods_id', $goodsId)->first();
  692. if (!empty($detail)) {
  693. $detail = $detail->toArray();
  694. } else {
  695. $detail = [];
  696. }
  697. // 标签表
  698. $label = GoodsLabel::where('join_label_goods_id', $goodsId)->first();
  699. if (!empty($label)) {
  700. $label = $label->toArray();
  701. } else {
  702. $label = [];
  703. }
  704. // Running表
  705. $running = GoodsRunning::where('join_running_goods_id', $goodsId)->first();
  706. if (!empty($running)) {
  707. $running = $running->toArray();
  708. if (!empty($running['goods_running_off_json']) && is_json($running['goods_running_off_json'])) {
  709. $goodsRunningOffJson = json_decode($running['goods_running_off_json'], true);
  710. $running['goods_off_addtimes'] = isset($goodsRunningOffJson['time']) ? date("Y-m-d H:i", $goodsRunningOffJson['time']) : '';
  711. }
  712. } else {
  713. $running = [];
  714. }
  715. // 组件表
  716. $component = GoodsComponent::where('join_component_master_goods_id', $goodsId)->get()->toArray();
  717. $componentArr['join_component_goods_id'] = [];
  718. $componentArr['goodsContentList'] = [];
  719. if ($component) {
  720. $ids = [];
  721. $contentList = [];
  722. foreach ($component as $item) {
  723. if (empty($item['join_component_goods_id'])) {
  724. continue;
  725. }
  726. $skus = GoodsSku::where('join_sku_goods_id', $item['join_component_goods_id'])
  727. ->select('goods_sku_id', 'join_sku_goods_id', 'goods_sku_specs_json', 'goods_sku_sales_price')
  728. ->get()
  729. ->toArray();
  730. foreach ($skus as $key => $sku2) {
  731. if (!empty($sku2['goods_sku_specs_json'])) {
  732. $skus[$key]['goods_sku_specs_json'] = json_decode($sku2['goods_sku_specs_json'], true);
  733. $skuName = '';
  734. foreach ($skus[$key]['goods_sku_specs_json'] as $specsKey => $skuSpecs) {
  735. if (is_array($skuSpecs)) {
  736. $skuName = $skuName . ' ' . $specsKey . ' ' . implode(' ', $skuSpecs);
  737. } else {
  738. $skuName = $skuName . ' ' . $specsKey . ' ' . $skuSpecs;
  739. }
  740. }
  741. $skus[$key]['sku_name'] = $skuName;
  742. }
  743. }
  744. $ids[] = $item['join_component_goods_id'];
  745. $configJson = json_decode($item['goods_component_json'], true);
  746. $contentList[] = [
  747. 'goods_id' => $item['join_component_goods_id'],
  748. 'goods_name' => $configJson['goods_name'] ?? '',
  749. 'goods_sales_price' => $item['goods_component_price'],
  750. 'nbr' => $configJson['nbr'] ?? 0,
  751. 'sku_id' => $configJson['sku_id'] ?? '',
  752. 'skus' => $skus
  753. ];
  754. }
  755. $componentArr['join_component_goods_id'] = $ids;
  756. $componentArr['goodsContentList'] = $contentList;
  757. }
  758. // 合并数据
  759. $data = array_merge($main, $detail, $label, $running, $componentArr);
  760. $data['goods_sku_json_label'] = [];
  761. $data['goods_label'] = !empty($data['goods_label']) ? explode(',', $data['goods_label']) : [];
  762. $data['goods_cover'] = getenv('STORAGE_DOMAIN') . $data['goods_cover'];
  763. if (!empty($data['goods_detail_slider_json'])) {
  764. $data['goods_detail_slider_json'] = json_decode($data['goods_detail_slider_json'], true);
  765. $slider = '';
  766. foreach ($data['goods_detail_slider_json'] as $item) {
  767. $slider .= getenv('STORAGE_DOMAIN') . $item . ',';
  768. }
  769. $data['goods_detail_slider_json'] = rtrim($slider, ',');
  770. }
  771. $extendJson = [];
  772. if (!empty($data['goods_attribute_json'])) {
  773. $extendJson = json_decode($data['goods_attribute_json'], true);
  774. $data['goods_attribute_json'] = $extendJson;
  775. if (isset($extendJson['premisses'])) {
  776. $data['goods_premisses'] = $extendJson['premisses'];
  777. $data['goods_premisses_str'] = SysDept::whereIn('dept_id', $extendJson['premisses'])->pluck('dept_name');
  778. }
  779. }
  780. $data['goods_on_addtimes'] = date('Y-m-d\TH:i:s.u\Z', $data['goods_on_addtimes'] - 60 * 60 * 8);
  781. return json_success('', $data);
  782. } catch (\Exception $e) {
  783. dump($e->getTrace());
  784. return json_fail("查询错误~");
  785. }
  786. }
  787. /**
  788. * @Desc 添加商品
  789. * @Author Gorden
  790. * @Date 2024/3/11 10:20
  791. *
  792. * @param $params
  793. * @return Response
  794. */
  795. public static function insert($params): Response
  796. {
  797. Db::beginTransaction();
  798. try {
  799. $params['goods_id'] = "GD" . sprintf('%016d', SysSerial::getSerial()) . random_string(6, 'up');
  800. // 主表
  801. self::mainInsert($params);
  802. // 商品详情表
  803. self::detailInsert($params);
  804. // 商品标签表
  805. self::labelInsert($params);
  806. // 产品运行控制信息表
  807. self::goodsRunningInsert($params);
  808. // sku表
  809. self::goodsSkuSet($params, 'insert');
  810. // 待上架状态,上架时间大于当前时间
  811. if ($params['goods_status'] == 'PENDING' && strtotime($params['goods_on_addtimes']) > time()) {
  812. $redis = Redis::connection();
  813. $key = date('YmdHi', strtotime($params['goods_on_addtimes']));
  814. $redis->sAdd(Goods::LISTING_KEY_PREFIX . $key, $params['goods_id']);
  815. }
  816. // 自动下架
  817. if (!empty($params['goods_running_off_type']) && $params['goods_running_off_type'] == 'T' && !empty($params['goods_off_addtimes'])) {
  818. $redis = Redis::connection();
  819. $key = Goods::LISTING_OFF_KEY_PREFIX . date('YmdHi', strtotime($params['goods_off_addtimes']));
  820. $redis->sAdd($key, $params['goods_id']);
  821. }
  822. Db::commit();
  823. } catch (\PDOException $e) {
  824. Db::rollBack();
  825. dump($e->getFile() . '(' . $e->getLine() . '):' . $e->getMessage());
  826. return json_fail('数据写入失败~');
  827. } catch (BusinessException $e) {
  828. Db::rollBack();
  829. dump($e->getFile() . '(' . $e->getLine() . '):' . $e->getMessage());
  830. return json_fail($e->getMessage());
  831. } catch (\Exception $e) {
  832. Db::rollBack();
  833. dump($e->getTrace());
  834. return json_fail('数据写入失败~');
  835. }
  836. _syslog("添加商品", "商品名【" . $params['goods_name'] . "】");
  837. return json_success('success');
  838. }
  839. public static function insertRecharge($params)
  840. {
  841. try {
  842. Db::beginTransaction();
  843. $goods = new Goods();
  844. $goods->goods_id = "GD" . date('YmdHis') . random_string(6, 'up');
  845. $goods->join_goods_category_id = 59;
  846. $goods->goods_classify = 'RECHARGE';
  847. $goods->goods_status = $params['goods_status'];
  848. $goods->goods_sort = $params['goods_sort'];
  849. $goods->goods_category = $params['goods_category'];
  850. $goods->goods_name = $params['goods_name'];
  851. $goods->goods_market_price = $params['goods_sales_price'];
  852. $goods->goods_sales_price = $params['goods_sales_price'];
  853. $goods->goods_sku_json = json_encode(['规格' => [$params['goods_sales_price'] . '元']]);
  854. $goods->goods_attribute_json = json_encode(['added' => ['nbr' => $params['goods_rate'] / 100, 'mode' => 'rate'], 'min-count' => 1]);
  855. $goods->goods_cover = '/images/app/common/null-service.png';
  856. $goods->goods_process_json = json_encode(['mode' => 'do_shopping']);
  857. $goods->goods_addtimes = time();
  858. $goods->save();
  859. $sku = new GoodsSku();
  860. $sku->join_sku_goods_id = $goods->goods_id;
  861. $sku->goods_sku_status = $params['goods_status'];
  862. $sku->goods_sku_specs_json = json_encode(['规格' => $params['goods_sales_price'] . '元']);
  863. $sku->goods_sku_market_price = $params['goods_sales_price'];
  864. $sku->goods_sku_sales_price = $params['goods_sales_price'];
  865. $sku->goods_sku_storage_json = json_encode(['storage' => 9999]);
  866. $sku->save();
  867. Db::commit();
  868. return json_success('success');
  869. } catch (\Exception $e) {
  870. Db::rollBack();
  871. return json_fail('添加充值产品失败');
  872. }
  873. }
  874. public static function updateRecharge($params)
  875. {
  876. try {
  877. Db::beginTransaction();
  878. $goods = Goods::where('goods_id', $params['goods_id'])->first();
  879. if (!$goods) {
  880. return json_fail("数据异常");
  881. }
  882. $goods->goods_market_price = $params['goods_sales_price'];
  883. $goods->goods_sales_price = $params['goods_sales_price'];
  884. $goods->goods_status = $params['goods_status'];
  885. $goods->goods_sku_json = json_encode(['规格' => [$params['goods_sales_price'] . '元']]);
  886. $goods->goods_sort = $params['goods_sort'];
  887. if (!empty($goods->goods_attribute_json)) {
  888. $attributeJson = json_decode($goods->goods_attribute_json, true);
  889. $attributeJson['added']['nbr'] = $params['goods_rate'] / 100;
  890. $goods->goods_attribute_json = json_encode($attributeJson);
  891. }
  892. $goods->save();
  893. $sku = GoodsSku::where('join_sku_goods_id', $params['goods_id'])->first();
  894. $sku->goods_sku_status = $params['goods_status'];
  895. $sku->goods_sku_specs_json = json_encode(['规格' => $params['goods_sales_price'] . '元']);
  896. $sku->goods_sku_market_price = $params['goods_sales_price'];
  897. $sku->goods_sku_sales_price = $params['goods_sales_price'];
  898. $sku->save();
  899. Db::commit();
  900. return json_success("success");
  901. } catch (\Exception $e) {
  902. Db::rollBack();
  903. dump($e->getMessage());
  904. return json_fail('编辑充值产品失败');
  905. }
  906. }
  907. public static function insertPackage($params): Response
  908. {
  909. Db::beginTransaction();
  910. try {
  911. $params['goods_id'] = "GD" . sprintf('%016d', SysSerial::getSerial()) . random_string(6, 'up');
  912. // 主表
  913. self::mainInsert($params);
  914. // 商品详情表
  915. self::detailInsert($params);
  916. // 套包组件表
  917. self::componentUpdate($params, 'insert');
  918. // 商品标签表
  919. self::labelInsert($params);
  920. // 产品运行控制信息表
  921. self::goodsRunningInsert($params);
  922. // sku表
  923. // self::goodsSkuSet($params, 'insert');
  924. // 待上架状态,上架时间大于当前时间
  925. if ($params['goods_status'] == 'PENDING' && strtotime($params['goods_on_addtimes']) > time()) {
  926. $redis = Redis::connection();
  927. $key = date('YmdHi', strtotime($params['goods_on_addtimes']));
  928. $redis->sAdd(Goods::LISTING_KEY_PREFIX . $key, $params['goods_id']);
  929. }
  930. Db::commit();
  931. } catch (\PDOException $e) {
  932. Db::rollBack();
  933. dump($e->getMessage());
  934. return json_fail('数据写入失败~');
  935. } catch (BusinessException $e) {
  936. Db::rollBack();
  937. dump($e->getMessage());
  938. return json_fail($e->getMessage());
  939. } catch (\Exception $e) {
  940. Db::rollBack();
  941. dump($e->getTrace());
  942. return json_fail('数据写入失败~');
  943. }
  944. _syslog("添加套餐", "商品名【" . $params['goods_name'] . "】");
  945. return json_success('success');
  946. }
  947. public static function update($params)
  948. {
  949. Db::beginTransaction();
  950. try {
  951. // 主表
  952. self::mainUpdate($params);
  953. // 商品详情表
  954. self::detailUpdate($params);
  955. // 商品标签表
  956. self::labelUpdate($params);
  957. // 产品运行控制信息表
  958. self::goodsRunningUpdate($params);
  959. // sku表
  960. self::goodsSkuSet($params, 'update');
  961. Db::commit();
  962. } catch (BusinessException $e) {
  963. Db::rollBack();
  964. return json_fail($e->getMessage());
  965. } catch (\Exception $e) {
  966. Db::rollBack();
  967. return json_fail('数据更新失败~');
  968. }
  969. _syslog("编辑商品", "商品名【" . $params['goods_name'] . "】" ?? "商品ID:【" . $params['goods_id'] . "】");
  970. return json_success('success');
  971. }
  972. public static function changeStatus($params)
  973. {
  974. try {
  975. Goods::where('goods_id', $params['goods_id'])->update(['goods_status' => $params['goods_status']]);
  976. return json_success('修改成功');
  977. } catch (\Exception $e) {
  978. return json_fail('修改状态失败');
  979. }
  980. }
  981. public static function updatePackage($params)
  982. {
  983. Db::beginTransaction();
  984. try {
  985. // 主表
  986. self::mainUpdate($params);
  987. // 商品详情表
  988. self::detailUpdate($params);
  989. // 套包组件表
  990. self::componentUpdate($params, 'update');
  991. // 商品标签表
  992. self::labelUpdate($params);
  993. // 产品运行控制信息表
  994. self::goodsRunningUpdate($params);
  995. Db::commit();
  996. } catch (BusinessException $e) {
  997. Db::rollBack();
  998. return json_fail($e->getMessage());
  999. } catch (\Exception $e) {
  1000. Db::rollBack();
  1001. dump($e->getTrace());
  1002. return json_fail('数据更新失败~');
  1003. }
  1004. _syslog("编辑套餐", "商品名【" . $params['goods_name'] . "】" ?? "商品ID:【" . $params['goods_id'] . "】");
  1005. return json_success('success');
  1006. }
  1007. /**
  1008. * @Desc 删除商品
  1009. * @Author Gorden
  1010. * @Date 2024/3/28 13:20
  1011. *
  1012. * @param $ids
  1013. * @return Response
  1014. */
  1015. public static function delete($ids)
  1016. {
  1017. if (!$ids) {
  1018. return json_fail("数据错误~");
  1019. }
  1020. if (!is_array($ids)) {
  1021. $ids = [$ids];
  1022. }
  1023. $goods = Goods::whereIn('goods_id', $ids)->get()->toArray();
  1024. if (!$goods) {
  1025. return json_fail("数据错误~");
  1026. }
  1027. // 是否在套包里
  1028. if (GoodsComponent::whereIn('join_component_goods_id',$ids)->exists()){
  1029. return json_fail("当前商品存在于套包中,请先在套包中删除");
  1030. }
  1031. // 是否已被购买过
  1032. if (OrderSheet::whereIn('join_sheet_goods_id',$ids)->exists()){
  1033. return json_fail("当前商品已有购买历史,如不在APP显示,请选择【下架】操作");
  1034. }
  1035. // 是否预约过
  1036. if (Appointment::whereIn('join_appointment_goods_id',$ids)->exists()){
  1037. return json_fail("当前商品已有预约历史,如不在APP显示,请选择【下架】操作");
  1038. }
  1039. Db::beginTransaction();
  1040. try {
  1041. Goods::whereIn('goods_id', $ids)->delete();
  1042. GoodsDetail::whereIn('join_detail_goods_id', $ids)->delete();
  1043. GoodsLabel::whereIn('join_label_goods_id', $ids)->delete();
  1044. GoodsRunning::whereIn('join_running_goods_id', $ids)->delete();
  1045. GoodsSku::whereIn('join_sku_goods_id', $ids)->delete();
  1046. Db::commit();
  1047. _syslog("删除商品 / 套餐", "ID:【" . implode(',', $ids) . "】", $goods);
  1048. return json_success("商品删除成功");
  1049. } catch (\Exception $e) {
  1050. Db::rollBack();
  1051. return json_fail("商品删除失败~");
  1052. }
  1053. }
  1054. /**
  1055. * @Desc 商品主表
  1056. * @Author Gorden
  1057. * @Date 2024/3/11 11:20
  1058. *
  1059. * @param $params
  1060. * @return mixed|string
  1061. * @throws BusinessException
  1062. */
  1063. public static function mainInsert($params)
  1064. {
  1065. if (!empty($params['goods_cover'])) {
  1066. $params['goods_cover'] = str_replace(getenv('STORAGE_DOMAIN'), '', $params['goods_cover']);
  1067. }
  1068. // 如果产品是待处理状态
  1069. if ($params['goods_status'] == 'PENDING') {
  1070. if (strtotime($params['goods_on_addtimes']) <= time()) {
  1071. $params['goods_status'] = 'ON';
  1072. }
  1073. }
  1074. $category = SysCategory::where('category_id', $params['join_goods_category_id'])->first();
  1075. if (!$category) {
  1076. throw new BusinessException("产品分类不存在~");
  1077. }
  1078. if (empty($params['goods_category'])) {
  1079. $params['goods_category'] = $category->category_classify;
  1080. }
  1081. try {
  1082. $model = new Goods();
  1083. $model->goods_id = $params['goods_id'];
  1084. $model->join_goods_category_id = $params['join_goods_category_id'] ?? 0;
  1085. $model->join_goods_supplier_id = $params['join_goods_supplier_id'] ?? 0;
  1086. $model->goods_classify = $params['goods_classify'] ?? '';
  1087. $model->goods_status = $params['goods_status'] ?? '';
  1088. $model->goods_category = $params['goods_category'] ?? '';
  1089. // $model->goods_prefix = $params['goods_prefix'] ?? 】($category->category_name ? '【' . $category->category_name . '' : '');
  1090. $model->goods_prefix = $params['goods_prefix'] ?? '';
  1091. $model->goods_name = $params['goods_name'];
  1092. $model->goods_market_price = $params['goods_market_price'] ?? 0;
  1093. $model->goods_sales_price = $params['goods_sales_price'] ?? 0;
  1094. $model->goods_sku_json = !empty($params['goods_sku_json_label']) ? json_encode($params['goods_sku_json_label']) : json_encode(['规格' => ['标准']]);
  1095. $model->goods_attribute_json = !empty($params['goods_attribute_json']) ? $params['goods_attribute_json'] : '[]';
  1096. $model->goods_title = $params['goods_title'] ?? '';
  1097. $model->goods_cover = $params['goods_cover'] ?? '';
  1098. $model->goods_on_addtimes = isset($params['goods_on_addtimes']) ? strtotime($params['goods_on_addtimes']) : null;
  1099. $model->goods_sort = $params['goods_sort'] ?? null;
  1100. $model->goods_groupby = $params['goods_groupby'] ?? '';
  1101. $model->goods_remark = $params['goods_remark'] ?? '';
  1102. $model->goods_extend_json = $params['goods_extend_json'] ?? '{}';
  1103. $model->is_support_appointment = $params['is_support_appointment'] ?? 'N';
  1104. $model->creator_user_id = JwtToken::getCurrentId();
  1105. $model->goods_addtimes = time();
  1106. $model->goods_updatetimes = time();
  1107. if (!empty($params['is_support_appointment']) && $params['is_support_appointment'] == 'Y' && !empty($params['appointment_times']) && $params['goods_category'] != 'TRAVEL') {
  1108. $times = [];
  1109. $attributeJsonTimeArr = [];
  1110. $personTotal = 0;
  1111. foreach ($params['appointment_times'] as $time) {
  1112. $attributeJsonTimeArr[] = strtotime(date('Y-m-d ') . $time['appointmentTimeStart']);
  1113. $attributeJsonTimeArr[] = strtotime(date('Y-m-d ') . $time['appointmentTimeEnd']);
  1114. $personTotal += $time['person'];
  1115. $times[$time['appointmentTimeStart']] = [
  1116. 'person' => $time['person'],
  1117. 'duration' => $time['appointmentTimeStart'] . '-' . $time['appointmentTimeEnd']
  1118. ];
  1119. }
  1120. $attributeJsonTime = date('H:i', min($attributeJsonTimeArr)) . '至' . date('H:i', max($attributeJsonTimeArr));
  1121. $newDates = [];
  1122. foreach ($params['dates'] as $date) {
  1123. $key = self::$week[$date];
  1124. $newDates[$key] = $date;
  1125. }
  1126. ksort($newDates);
  1127. $currentDate = current($newDates);
  1128. $lastDate = end($newDates);
  1129. $attributeJsonDate = '';
  1130. if (self::$week[$lastDate] - self::$week[$currentDate] + 1 > count($newDates)) {
  1131. $attributeJsonDate = implode(',', $newDates);
  1132. } else if (self::$week[$lastDate] - self::$week[$currentDate] + 1 == count($newDates)) {
  1133. $attributeJsonDate = $currentDate . '至' . $lastDate;
  1134. }
  1135. if (isset($params['work_time'])){
  1136. $workTimeStart = date('H:i',strtotime($params['work_time'][0]));
  1137. $workTimeEnd = date('H:i',strtotime($params['work_time'][1]));
  1138. $attributeJsonTime = $workTimeStart.'至'.$workTimeEnd;
  1139. }
  1140. $attributeJson = [
  1141. 'icon' => $model->goods_cover,
  1142. 'date' => $attributeJsonDate,
  1143. 'time' => $attributeJsonTime,
  1144. 'dates' => $newDates ? array_values($newDates) : [],
  1145. 'times' => $times,
  1146. 'person' => $personTotal
  1147. ];
  1148. if(isset($params['address'])){
  1149. $attributeJson['address'] = $params['address'];
  1150. }
  1151. if (isset($params['min_count'])){
  1152. $attributeJson['min-count'] = $params['min_count'];
  1153. }else{
  1154. $attributeJson['min-count'] = 1;
  1155. }
  1156. if (isset($params['teachers'])){
  1157. $attributeJson['teachers'] = $params['teachers'];
  1158. }
  1159. if (!empty($params['appointment_label'])) {
  1160. $attributeJson['label'] = $params['appointment_label'];
  1161. }
  1162. // if (!empty($params['address'])) {
  1163. // $attributeJson['address'] = $params['address'];
  1164. // }
  1165. // if (!empty($params['position'])){
  1166. // $attributeJson['position'] = $params['position'];
  1167. // }
  1168. // if (isset($params['goods_service_premises'])){
  1169. // $attributeJson['service_premises_id'] = $params['goods_service_premises'];
  1170. // }
  1171. $model->goods_attribute_json = json_encode($attributeJson, JSON_UNESCAPED_UNICODE);
  1172. // $times = [];
  1173. // foreach ($params['appointment_times'] as $time) {
  1174. // $times[$time['appointmentTimeStart']] = [
  1175. // 'person' => $time['person'],
  1176. // 'duration' => $time['appointmentTimeStart'] . '-' . $time['appointmentTimeEnd']
  1177. // ];
  1178. // }
  1179. // $model->goods_attribute_json = json_encode([
  1180. // 'icon' => '',
  1181. // 'dates' => $params['dates'] ?? [],
  1182. // 'times' => $times
  1183. // ]);
  1184. }
  1185. if (!empty($params['is_support_appointment']) && $params['is_support_appointment'] == 'Y' && !empty($params['appointment_times']) && $params['goods_category'] == 'TRAVEL') {
  1186. if (!empty($model->goods_attribute_json) && !is_array($model->goods_attribute_json)) {
  1187. $attributeJson = json_decode($model->goods_attribute_json, true);
  1188. } elseif (empty($model->goods_attribute_json)) {
  1189. $attributeJson = [];
  1190. }
  1191. $attributeJson['travel-day'] = $params['travel_day'];
  1192. $attributeJson['travel-begin'] = $params['travel_begin'];
  1193. $attributeJson['travel-night'] = $params['travel_night'];
  1194. $attributeJson['travel-trans'] = $params['travel_trans'];
  1195. $unixs = [];
  1196. foreach ($params['appointment_times'] as $times) {
  1197. $unix = strtotime($times['days']);
  1198. $unixs[$unix] = $times['person'];
  1199. }
  1200. ksort($unixs);
  1201. $months = [];
  1202. foreach ($unixs as $key => $unix) {
  1203. $month = date('Ym', $key);
  1204. $day = date('d', $key);
  1205. $months[$month][$day] = $unix;
  1206. }
  1207. $attributeJson['month'] = $months;
  1208. $model->goods_attribute_json = json_encode($attributeJson, JSON_UNESCAPED_UNICODE);
  1209. }
  1210. if (!empty($params['goods_json']) && $params['join_goods_category_id'] == 65) {
  1211. $goodsJson = json_decode($params['goods_json'], true);
  1212. // foreach ($goodsJson as $key => $item) {
  1213. // $goodsJson[$key]['color'] = hexToRgb($item['color']);
  1214. // }
  1215. //
  1216. $model->goods_json = json_encode($goodsJson);
  1217. } elseif (!empty($params['goods_json']) && $params['join_goods_category_id'] == 43) {
  1218. $goodsJson = json_decode($params['goods_json'], true);
  1219. $newGoodsJson = [];
  1220. foreach ($goodsJson as $item1) {
  1221. if (empty($item1['title'])) {
  1222. continue;
  1223. }
  1224. $newItem1 = [];
  1225. foreach ($item1['items'] as $item2) {
  1226. $newParams = [];
  1227. foreach ($item2['params'] as $param) {
  1228. if (!empty($param[0]) || !empty($param[1])) {
  1229. $newParams[] = $param;
  1230. }
  1231. }
  1232. $newItem1['items'][$item2['key']] = $newParams;
  1233. }
  1234. $newItem1['service'] = $item1['service'] ?? '';
  1235. $newGoodsJson[$item1['title']] = $newItem1;
  1236. }
  1237. $model->goods_json = json_encode($newGoodsJson);
  1238. } else {
  1239. $model->goods_json = '[]';
  1240. }
  1241. if (!empty($params['goods_premisses'])) {
  1242. $attributeJson = [];
  1243. if (!empty($model->goods_attribute_json) && !is_array($model->goods_attribute_json)) {
  1244. $attributeJson = json_decode($model->goods_attribute_json, true);
  1245. } elseif (empty($model->goods_attribute_json)) {
  1246. $attributeJson = [];
  1247. }
  1248. $attributeJson['premisses'] = $params['goods_premisses'];
  1249. $model->goods_attribute_json = json_encode($attributeJson);
  1250. }
  1251. if (!empty($params['goods_theme_color']) && !empty($params['goods_theme_icon'])) {
  1252. if (!empty($model->goods_attribute_json) && !is_array($model->goods_attribute_json)) {
  1253. $attributeJson = json_decode($model->goods_attribute_json, true);
  1254. } elseif (empty($model->goods_attribute_json)) {
  1255. $attributeJson = [];
  1256. }
  1257. $attributeJson['bg'] = $params['goods_theme_color'];
  1258. $attributeJson['icon'] = str_replace(getenv('STORAGE_DOMAIN'), '', $params['goods_theme_icon']);
  1259. $model->goods_attribute_json = json_encode($attributeJson);
  1260. }
  1261. if (!empty($params['address'])) {
  1262. if (!empty($model->goods_attribute_json) && !is_array($model->goods_attribute_json)) {
  1263. $attributeJson = json_decode($model->goods_attribute_json, true);
  1264. } elseif (empty($model->goods_attribute_json)) {
  1265. $attributeJson = [];
  1266. }
  1267. $attributeJson['address'] = $params['address'];
  1268. $model->goods_attribute_json = json_encode($attributeJson);
  1269. }
  1270. if (!empty($params['position'])){
  1271. if (!empty($model->goods_attribute_json) && !is_array($model->goods_attribute_json)) {
  1272. $attributeJson = json_decode($model->goods_attribute_json, true);
  1273. } elseif (empty($model->goods_attribute_json)) {
  1274. $attributeJson = [];
  1275. }
  1276. $attributeJson['position'] = $params['position'];
  1277. $model->goods_attribute_json = json_encode($attributeJson);
  1278. }
  1279. if (isset($params['goods_service_premises'])){
  1280. if (!empty($model->goods_attribute_json) && !is_array($model->goods_attribute_json)) {
  1281. $attributeJson = json_decode($model->goods_attribute_json, true);
  1282. } elseif (empty($model->goods_attribute_json)) {
  1283. $attributeJson = [];
  1284. }
  1285. $attributeJson['service_premises_id'] = $params['goods_service_premises'];
  1286. $model->goods_attribute_json = json_encode($attributeJson);
  1287. }
  1288. if ($model->save()) {
  1289. return $model->goods_id;
  1290. }
  1291. // 异常
  1292. throw new BusinessException("数据写入失败~");
  1293. } catch (\Exception $e) {
  1294. dump($e->getMessage());
  1295. throw new BusinessException("数据写入失败~");
  1296. }
  1297. }
  1298. /**
  1299. * @Desc 详情表
  1300. * @Author Gorden
  1301. * @Date 2024/3/11 11:19
  1302. *
  1303. * @param $params
  1304. * @return void
  1305. * @throws BusinessException
  1306. */
  1307. public static function detailInsert($params)
  1308. {
  1309. if (!empty($params['goods_detail_slider_json'])) {
  1310. $params['goods_detail_slider_json'] = str_replace(getenv('STORAGE_DOMAIN'), '', $params['goods_detail_slider_json']);
  1311. $params['goods_detail_slider_json'] = json_encode(['slider' => $params['goods_detail_slider_json']]);
  1312. }
  1313. try {
  1314. $model = new GoodsDetail();
  1315. $model->join_detail_goods_id = $params['goods_id'];
  1316. $model->goods_detail_code_json = $params['goods_detail_code_json'] ?? '{}';
  1317. $model->goods_detail_slider_json = $params['goods_detail_slider_json'] ?? '{}';
  1318. $model->goods_detail_specs_json = $params['goods_detail_specs_json'] ?? '{}';
  1319. $model->goods_detail_content = $params['goods_detail_content'] ?? '';
  1320. if (!$model->save()) {
  1321. // 异常
  1322. throw new BusinessException("轮播图/详情数据写入失败~");
  1323. }
  1324. } catch (\Exception $e) {
  1325. dump($e->getMessage());
  1326. throw new BusinessException("轮播图/详情数据写入失败~");
  1327. }
  1328. }
  1329. public static function componentUpdate($params, $type = 'insert')
  1330. {
  1331. Db::beginTransaction();
  1332. try {
  1333. $goodsSku = '';
  1334. // 有先删除
  1335. if ($type == 'update') {
  1336. GoodsComponent::where('join_component_master_goods_id', $params['goods_id'])->delete();
  1337. $goodsSku = GoodsSku::where('join_sku_goods_id',$params['goods_id'])->first();
  1338. if ($goodsSku){
  1339. $goodsSku->goods_sku_market_price = $params['goods_market_price'] ?? 0;
  1340. $goodsSku->goods_sku_sales_price = $params['goods_sales_price'] ?? 0;
  1341. $goodsSku->save();
  1342. }
  1343. }
  1344. if ($type == 'insert' || !$goodsSku){
  1345. Goods::where('goods_id', $params['goods_id'])->update(['goods_sku_json' => '{"规格": ["标准"]}']);
  1346. $skuData = [
  1347. 'join_sku_goods_id' => $params['goods_id'],
  1348. 'goods_sku_status' => 'ON',
  1349. 'goods_sku_specs_json' => '{"规格": "标准"}',
  1350. 'goods_sku_title' => "标准" . $params['goods_name'],
  1351. 'goods_sku_market_price' => $params['goods_market_price'] ?? 0,
  1352. 'goods_sku_sales_price' => $params['goods_sales_price'] ?? 0,
  1353. ];
  1354. GoodsSku::insert($skuData);
  1355. }
  1356. $data = [];
  1357. foreach ($params['goods_content_list'] as $item) {
  1358. if(!in_array($item['goods_id'],$params['join_component_goods_id'])){
  1359. continue;
  1360. }
  1361. $goods = Goods::where('goods_id', $params['goods_id'])->first();
  1362. if (!$goods) {
  1363. continue;
  1364. }
  1365. $data[] = [
  1366. 'join_component_master_goods_id' => $params['goods_id'],
  1367. 'join_component_goods_id' => $item['goods_id'] ?? '',
  1368. 'join_component_goods_sku_id' => $item['sku_id'] ?? '',
  1369. 'goods_component_price' => $item['goods_sales_price'] ?? '',
  1370. 'goods_component_cover' => $goods->goods_cover,
  1371. 'goods_component_json' => json_encode(['goods_name' => $item['goods_name'], 'nbr' => $item['nbr'], 'sku_id' => $item['sku_id'] ?? '']),
  1372. 'goods_component_addtimes' => time()
  1373. ];
  1374. }
  1375. if ($data) {
  1376. GoodsComponent::insert($data);
  1377. }
  1378. Db::commit();
  1379. } catch (\Exception $e) {
  1380. Db::rollBack();
  1381. dump($e->getMessage());
  1382. throw new BusinessException("数据写入失败~");
  1383. }
  1384. }
  1385. /**
  1386. * @Desc 标签表
  1387. * @Author Gorden
  1388. * @Date 2024/3/11 11:32
  1389. *
  1390. * @param $params
  1391. * @return void
  1392. * @throws BusinessException
  1393. */
  1394. public static function labelInsert($params)
  1395. {
  1396. $model = new GoodsLabel();
  1397. $model->join_label_goods_id = $params['goods_id'];
  1398. $model->goods_label = $params['goods_label'] ? implode(',', $params['goods_label']) : '';
  1399. $model->goods_label_extend_json = !empty($params['goods_label_extend_json']) ? $params['goods_label_extend_json'] : '{}';
  1400. if (!$model->save()) {
  1401. // 异常
  1402. throw new BusinessException('数据写入失败~');
  1403. }
  1404. }
  1405. /**
  1406. * @Desc 产品运行控制信息表
  1407. * @Author Gorden
  1408. * @Date 2024/3/11 11:38
  1409. *
  1410. * @param $params
  1411. * @return void
  1412. * @throws BusinessException
  1413. */
  1414. public static function goodsRunningInsert($params)
  1415. {
  1416. try {
  1417. $model = new GoodsRunning();
  1418. $model->join_running_goods_id = $params['goods_id'];
  1419. $model->goods_running_storage = $params['goods_running_storage'] ?? 0;
  1420. $model->goods_running_sale = $params['goods_running_sale'] ?? 0;
  1421. $model->goods_running_off_type = !empty($params['goods_running_off_type']) ? $params['goods_running_off_type'] : '';
  1422. $model->goods_running_off_json = !empty($params['goods_running_off_type']) && $params['goods_running_off_type'] == 'T' && !empty($params['goods_off_addtimes']) ? json_encode(['time' => strtotime($params['goods_off_addtimes'])]) : '[]';
  1423. if (!$model->save()) {
  1424. throw new BusinessException('数据写入失败');
  1425. }
  1426. } catch (\Exception $e) {
  1427. dump($e->getMessage());
  1428. throw new BusinessException('数据写入失败');
  1429. }
  1430. }
  1431. /**
  1432. * @Desc SKU
  1433. * @Author Gorden
  1434. * @Date 2024/3/11 12:01
  1435. *
  1436. * @param $params
  1437. * @return void
  1438. * @throws BusinessException
  1439. */
  1440. public static function skuInsert($params)
  1441. {
  1442. $model = new GoodsSku();
  1443. $model->join_sku_goods_id = $params['goods_id'];
  1444. $model->goods_sku_status = $params['goods_sku_status'];
  1445. $model->goods_sku_specs_json = $params['goods_sku_specs_json'];
  1446. $model->goods_sku_title = $params['goods_sku_title'];
  1447. $model->goods_sku_images_json = $params['goods_sku_images_json'];
  1448. $model->goods_sku_content = $params['goods_sku_content'];
  1449. $model->goods_sku_market_price = $params['goods_sku_market_price'];
  1450. $model->goods_sku_sales_price = $params['goods_sku_sales_price'];
  1451. $model->goods_sku_storage_json = $params['goods_sku_storage_json'];
  1452. $model->goods_sku_service_json = $params['goods_sku_service_json'];
  1453. $model->goods_sku_extend_json = $params['goods_sku_extend_json'];
  1454. if (!$model->save()) {
  1455. throw new BusinessException('规格数据写入失败~');
  1456. }
  1457. }
  1458. /**
  1459. * @Desc
  1460. * @Author Gorden
  1461. * @Date 2024/3/12 8:44
  1462. *
  1463. * @param $params
  1464. * @return void
  1465. * @throws BusinessException
  1466. */
  1467. public static function mainUpdate($params)
  1468. {
  1469. try {
  1470. $data = self::inputFilter($params, new Goods());
  1471. if (!empty($data['goods_cover'])) {
  1472. $data['goods_cover'] = str_replace(getenv('STORAGE_DOMAIN'), '', $data['goods_cover']);
  1473. }
  1474. $data['goods_on_addtimes'] = isset($data['goods_on_addtimes']) ? strtotime($data['goods_on_addtimes']) : 0;
  1475. $data['goods_sku_json'] = !empty($params['goods_sku_json_label']) ? json_encode($params['goods_sku_json_label']) : json_encode(['规格' => ['标准']]);
  1476. $row = Goods::find($data['goods_id']);
  1477. if ($row->join_goods_category_id != $data['join_goods_category_id']) {
  1478. $category = SysCategory::where('category_id', $params['join_goods_category_id'])->first();
  1479. if (!$category) {
  1480. throw new BusinessException("产品分类不存在~");
  1481. }
  1482. $data['goods_category'] = $category->category_classify ?? '';
  1483. $data['goods_prefix'] = $data['goods_prefix'] ?? ($category->category_name ? '【' . $category->category_name . '】' : '');
  1484. }
  1485. // 上架时间有变动
  1486. if ($data['goods_status'] == 'PENDING' && $row->goods_on_addtimes != $data['goods_on_addtimes']) {
  1487. $redis = Redis::connection();
  1488. // 删掉原来的
  1489. $oldKey = Goods::LISTING_KEY_PREFIX . date('YmdHi', $row->goods_on_addtimes);
  1490. $redis->srem($oldKey, $data['goods_id']);
  1491. // 加入新的
  1492. $newKey = Goods::LISTING_KEY_PREFIX . date('YmdHi', $data['goods_on_addtimes']);
  1493. $redis->sadd($newKey, $data['goods_id']);
  1494. }
  1495. if (!empty($params['is_support_appointment']) && $params['is_support_appointment'] == 'Y' && !empty($params['appointment_times']) && $params['goods_category'] != 'TRAVEL') {
  1496. $attributeJson = [];
  1497. if (!empty($row->goods_attribute_json)) {
  1498. $attributeJson = json_decode($row->goods_attribute_json, true);
  1499. }
  1500. $times = [];
  1501. $attributeJsonTimeArr = [];
  1502. $personTotal = 0;
  1503. foreach ($params['appointment_times'] as $time) {
  1504. $attributeJsonTimeArr[] = strtotime(date('Y-m-d ') . $time['appointmentTimeStart']);
  1505. $attributeJsonTimeArr[] = strtotime(date('Y-m-d ') . $time['appointmentTimeEnd']);
  1506. $personTotal += $time['person'];
  1507. $times[$time['appointmentTimeStart']] = [
  1508. 'person' => $time['person'],
  1509. 'duration' => $time['appointmentTimeStart'] . '-' . $time['appointmentTimeEnd']
  1510. ];
  1511. }
  1512. $attributeJsonTime = date('H:i', min($attributeJsonTimeArr)) . '至' . date('H:i', max($attributeJsonTimeArr));
  1513. $newDates = [];
  1514. foreach ($params['dates'] as $date) {
  1515. $key = self::$week[$date];
  1516. $newDates[$key] = $date;
  1517. }
  1518. ksort($newDates);
  1519. $currentDate = current($newDates);
  1520. $lastDate = end($newDates);
  1521. $attributeJsonDate = '';
  1522. if (self::$week[$lastDate] - self::$week[$currentDate] + 1 > count($newDates)) {
  1523. $attributeJsonDate = implode(',', $newDates);
  1524. } else if (self::$week[$lastDate] - self::$week[$currentDate] + 1 == count($newDates)) {
  1525. $attributeJsonDate = $currentDate . '至' . $lastDate;
  1526. }
  1527. $attributeJson['date'] = $attributeJsonDate;
  1528. $attributeJson['icon'] = $data['goods_cover'] ?? '';
  1529. $attributeJson['time'] = $attributeJsonTime;
  1530. $attributeJson['dates'] = $newDates ? array_values($newDates) : [];
  1531. $attributeJson['times'] = $times;
  1532. $attributeJson['person'] = $personTotal;
  1533. if (isset($params['work_time'])){
  1534. $workTimeStart = date('H:i',strtotime($params['work_time'][0]));
  1535. $workTimeEnd = date('H:i',strtotime($params['work_time'][1]));
  1536. $attributeJson['time'] = $workTimeStart.'至'.$workTimeEnd;
  1537. }
  1538. if (!empty($params['appointment_label'])) {
  1539. $attributeJson['label'] = $params['appointment_label'];
  1540. }
  1541. // if (!empty($params['address'])) {
  1542. // $attributeJson['address'] = $params['address'];
  1543. // }
  1544. // if (!empty($params['position'])){
  1545. // $attributeJson['position'] = $params['position'];
  1546. // }
  1547. // if (isset($params['goods_service_premises'])){
  1548. // $attributeJson['service_premises_id'] = $params['goods_service_premises'];
  1549. // }
  1550. if (isset($params['min_count'])){
  1551. $attributeJson['min-count'] = $params['min_count'];
  1552. }else{
  1553. $attributeJson['min-count'] = 1;
  1554. }
  1555. if (isset($params['teachers'])){
  1556. $attributeJson['teachers'] = $params['teachers'];
  1557. }
  1558. $data['goods_attribute_json'] = json_encode($attributeJson, JSON_UNESCAPED_UNICODE);
  1559. }
  1560. if (!empty($params['is_support_appointment']) && $params['is_support_appointment'] == 'Y' && !empty($params['appointment_times']) && $params['goods_category'] == 'TRAVEL') {
  1561. $attributeJson = [];
  1562. if (!empty($row->goods_attribute_json)) {
  1563. $attributeJson = json_decode($row->goods_attribute_json, true);
  1564. }
  1565. $attributeJson['travel-day'] = $params['travel_day'];
  1566. $attributeJson['travel-begin'] = $params['travel_begin'];
  1567. $attributeJson['travel-night'] = $params['travel_night'];
  1568. $attributeJson['travel-trans'] = $params['travel_trans'];
  1569. $unixs = [];
  1570. foreach ($params['appointment_times'] as $times) {
  1571. $unix = strtotime($times['days']);
  1572. $unixs[$unix] = $times['person'];
  1573. }
  1574. ksort($unixs);
  1575. $months = [];
  1576. foreach ($unixs as $key => $unix) {
  1577. $month = date('Ym', $key);
  1578. $day = date('d', $key);
  1579. $months[$month][$day] = $unix;
  1580. }
  1581. $attributeJson['month'] = $months;
  1582. $data['goods_attribute_json'] = json_encode($attributeJson, JSON_UNESCAPED_UNICODE);
  1583. }
  1584. if (!empty($params['goods_premisses'])) {
  1585. if (!empty($data['goods_attribute_json']) && !is_array($data['goods_attribute_json'])) {
  1586. if (is_json($data['goods_attribute_json'])) {
  1587. $data['goods_attribute_json'] = json_decode($data['goods_attribute_json'], true);
  1588. } else {
  1589. $data['goods_attribute_json'] = [];
  1590. }
  1591. } elseif (empty($data['goods_attribute_json'])) {
  1592. $data['goods_attribute_json'] = [];
  1593. }
  1594. $data['goods_attribute_json']['premisses'] = $params['goods_premisses'];
  1595. $data['goods_attribute_json'] = json_encode($data['goods_attribute_json']);
  1596. }
  1597. if (!empty($data['goods_json']) && $data['join_goods_category_id'] == 65) {
  1598. // $goodsJson = json_decode($data['goods_json'], true);
  1599. // foreach ($goodsJson as $key => $item) {
  1600. // $goodsJson[$key]['color'] = hexToRgb($item['color']);
  1601. // }
  1602. //
  1603. // $data['goods_json'] = json_encode($goodsJson);
  1604. } elseif (!empty($data['goods_json']) && $data['join_goods_category_id'] == 43) {
  1605. $goodsJson = json_decode($data['goods_json'], true);
  1606. $newGoodsJson = [];
  1607. foreach ($goodsJson as $item1) {
  1608. if (empty($item1['title'])) {
  1609. continue;
  1610. }
  1611. $newItem1 = [];
  1612. foreach ($item1['items'] as $item2) {
  1613. $newParams = [];
  1614. foreach ($item2['params'] as $param) {
  1615. if (!empty($param[0]) || !empty($param[1])) {
  1616. $newParams[] = $param;
  1617. }
  1618. }
  1619. $newItem1['items'][$item2['key']] = $newParams;
  1620. }
  1621. $newItem1['service'] = $item1['service'];
  1622. $newGoodsJson[$item1['title']] = $newItem1;
  1623. }
  1624. $data['goods_json'] = json_encode($newGoodsJson);
  1625. } else {
  1626. $data['goods_json'] = '[]';
  1627. }
  1628. if (!empty($params['goods_theme_color']) && !empty($params['goods_theme_icon'])) {
  1629. if (!empty($data['goods_attribute_json']) && !is_array($data['goods_attribute_json'])) {
  1630. if (is_json($data['goods_attribute_json'])) {
  1631. $data['goods_attribute_json'] = json_decode($data['goods_attribute_json'], true);
  1632. } else {
  1633. $data['goods_attribute_json'] = [];
  1634. }
  1635. } elseif (empty($data['goods_attribute_json'])) {
  1636. $data['goods_attribute_json'] = [];
  1637. }
  1638. $data['goods_attribute_json']['bg'] = $params['goods_theme_color'];
  1639. $data['goods_attribute_json']['icon'] = str_replace(getenv('STORAGE_DOMAIN'), '', $params['goods_theme_icon']);
  1640. $data['goods_attribute_json'] = json_encode($data['goods_attribute_json']);
  1641. }
  1642. if (!empty($params['address'])) {
  1643. if (!empty($data['goods_attribute_json']) && !is_array($data['goods_attribute_json'])) {
  1644. if (is_json($data['goods_attribute_json'])) {
  1645. $data['goods_attribute_json'] = json_decode($data['goods_attribute_json'], true);
  1646. } else {
  1647. $data['goods_attribute_json'] = [];
  1648. }
  1649. } elseif (empty($data['goods_attribute_json'])) {
  1650. $data['goods_attribute_json'] = [];
  1651. }
  1652. $data['goods_attribute_json']['address'] = $params['address'];
  1653. $data['goods_attribute_json'] = json_encode($data['goods_attribute_json']);
  1654. }
  1655. if (!empty($params['position'])){
  1656. if (!empty($data['goods_attribute_json']) && !is_array($data['goods_attribute_json'])) {
  1657. if (is_json($data['goods_attribute_json'])) {
  1658. $data['goods_attribute_json'] = json_decode($data['goods_attribute_json'], true);
  1659. } else {
  1660. $data['goods_attribute_json'] = [];
  1661. }
  1662. } elseif (empty($data['goods_attribute_json'])) {
  1663. $data['goods_attribute_json'] = [];
  1664. }
  1665. $data['goods_attribute_json']['position'] = $params['position'];
  1666. $data['goods_attribute_json'] = json_encode($data['goods_attribute_json']);
  1667. }
  1668. if (isset($params['goods_service_premises'])){
  1669. if (!empty($data['goods_attribute_json']) && !is_array($data['goods_attribute_json'])) {
  1670. if (is_json($data['goods_attribute_json'])) {
  1671. $data['goods_attribute_json'] = json_decode($data['goods_attribute_json'], true);
  1672. } else {
  1673. $data['goods_attribute_json'] = [];
  1674. }
  1675. } elseif (empty($data['goods_attribute_json'])) {
  1676. $data['goods_attribute_json'] = [];
  1677. }
  1678. $data['goods_attribute_json']['service_premises_id'] = $params['goods_service_premises'];
  1679. $data['goods_attribute_json'] = json_encode($data['goods_attribute_json']);
  1680. }
  1681. foreach ($data as $key => $val) {
  1682. $row->{$key} = $val;
  1683. }
  1684. $row->goods_updatetimes = time();
  1685. $row->save();
  1686. } catch (BusinessException $e) {
  1687. throw new BusinessException($e->getMessage());
  1688. } catch (\Exception $e) {
  1689. dump($e->getTrace());
  1690. throw new BusinessException('数据更新异常~1');
  1691. }
  1692. }
  1693. /**
  1694. * @Desc
  1695. * @Author Gorden
  1696. * @Date 2024/3/12 9:57
  1697. *
  1698. * @param $params
  1699. * @return void
  1700. * @throws BusinessException
  1701. */
  1702. public static function detailUpdate($params)
  1703. {
  1704. try {
  1705. $data = self::inputFilter($params, new GoodsDetail());
  1706. if (!empty($data['goods_detail_slider_json'])) {
  1707. $data['goods_detail_slider_json'] = str_replace(getenv('STORAGE_DOMAIN'), '', $data['goods_detail_slider_json']);
  1708. $data['goods_detail_slider_json'] = json_encode(['slider' => $data['goods_detail_slider_json']]);
  1709. }
  1710. // 根据goods_id 查详情ID
  1711. $detail = GoodsDetail::where('join_detail_goods_id', $params['goods_id'])->first();
  1712. if ($detail) {
  1713. self::doUpdate($detail->join_detail_goods_id, $data, new GoodsDetail());
  1714. } else {
  1715. $data['join_detail_goods_id'] = $params['goods_id'];
  1716. GoodsDetail::insert($data);
  1717. }
  1718. } catch (BusinessException $e) {
  1719. throw new BusinessException($e->getMessage());
  1720. } catch (\Exception $e) {
  1721. dump($e->getMessage());
  1722. throw new BusinessException('轮播图/详情数据更新异常~');
  1723. }
  1724. }
  1725. /**
  1726. * @Desc
  1727. * @Author Gorden
  1728. * @Date 2024/3/12 9:58
  1729. *
  1730. * @param $params
  1731. * @return void
  1732. * @throws BusinessException
  1733. */
  1734. public static function labelUpdate($params)
  1735. {
  1736. try {
  1737. $data = self::inputFilter($params, new GoodsLabel());
  1738. // 根据goods_id 查详情ID
  1739. $detail = GoodsLabel::where('join_label_goods_id', $params['goods_id'])->first();
  1740. if ($detail) {
  1741. self::doUpdate($detail->goods_label_id, $data, new GoodsLabel());
  1742. } else {
  1743. $data['join_label_goods_id'] = $params['goods_id'];
  1744. GoodsLabel::insert($data);
  1745. }
  1746. } catch (BusinessException $e) {
  1747. throw new BusinessException($e->getMessage());
  1748. } catch (\Exception $e) {
  1749. dump($e->getMessage());
  1750. throw new BusinessException('数据更新异常~3');
  1751. }
  1752. }
  1753. /**
  1754. * @Desc
  1755. * @Author Gorden
  1756. * @Date 2024/3/12 9:59
  1757. *
  1758. * @param $params
  1759. * @return void
  1760. * @throws BusinessException
  1761. */
  1762. public static function goodsRunningUpdate($params)
  1763. {
  1764. try {
  1765. $data = self::inputFilter($params, new GoodsRunning());
  1766. // 根据goods_id 查详情ID
  1767. $detail = GoodsRunning::where('join_running_goods_id', $params['goods_id'])->first();
  1768. if (!empty($params['goods_running_off_type']) && $params['goods_running_off_type'] == 'T') {
  1769. $redis = Redis::connection();
  1770. if (!empty($detail->goods_running_off_json)) {
  1771. $goodsRunningOffJson = json_decode($detail->goods_running_off_json, true);
  1772. if (isset($goodsRunningOffJson['time'])) {
  1773. $oldKey = Goods::LISTING_OFF_KEY_PREFIX . date('YmdHi', $goodsRunningOffJson['time']);
  1774. $goodsRunningOffJson['time'] = strtotime($params['goods_off_addtimes']);
  1775. $data['goods_running_off_json'] = json_encode($goodsRunningOffJson);
  1776. // 有老的下架时间,删除老的
  1777. $redis->srem($oldKey, $params['goods_id']);
  1778. } else {
  1779. $goodsRunningOffJson['time'] = strtotime($params['goods_off_addtimes']);
  1780. $data['goods_running_off_json'] = json_encode($goodsRunningOffJson);
  1781. }
  1782. } else {
  1783. $data['goods_running_off_json'] = json_encode(['time' => strtotime($params['goods_off_addtimes'])]);
  1784. }
  1785. // 加入自动下架
  1786. $newKey = Goods::LISTING_OFF_KEY_PREFIX . date('YmdHi', strtotime($params['goods_off_addtimes']));
  1787. $redis->sAdd($newKey, $params['goods_id']);
  1788. } else if (!empty($params['goods_running_off_type']) && !empty($detail->goods_running_off_type) && $params['goods_running_off_type'] == 'H' && $detail->goods_running_off_type == 'T') {
  1789. $goodsRunningOffJson = json_decode($detail->goods_running_off_json, true);
  1790. if (isset($goodsRunningOffJson['time'])) {
  1791. $oldKey = Goods::LISTING_OFF_KEY_PREFIX . date('YmdHi', $goodsRunningOffJson['time']);
  1792. $redis = Redis::connection();
  1793. $redis->srem($oldKey, $params['goods_id']);
  1794. }
  1795. }
  1796. if ($detail) {
  1797. self::doUpdate($detail->join_running_goods_id, $data, new GoodsRunning());
  1798. } else {
  1799. // 兼容老数据……
  1800. $data['join_running_goods_id'] = $params['goods_id'];
  1801. GoodsRunning::insert($data);
  1802. }
  1803. } catch (BusinessException $e) {
  1804. throw new BusinessException($e->getMessage());
  1805. } catch (\Exception $e) {
  1806. dump($e->getMessage());
  1807. throw new BusinessException('数据更新异常~');
  1808. }
  1809. }
  1810. /**
  1811. * @Desc sku 设置
  1812. * @Author Gorden
  1813. * @Date 2024/4/10 10:43
  1814. *
  1815. * @param $params
  1816. * @return void
  1817. * @throws BusinessException
  1818. */
  1819. public static function goodsSkuSet($params, $operation = 'insert')
  1820. {
  1821. try {
  1822. Db::beginTransaction();
  1823. $skusOldIds = [];
  1824. if ($operation == 'update') {
  1825. // 查出所有的
  1826. $skusOldIds = GoodsSku::where('join_sku_goods_id', $params['goods_id'])->pluck('goods_sku_id', 'goods_sku_id');
  1827. // 删掉原有的
  1828. // GoodsSku::where('join_sku_goods_id', $params['goods_id'])->delete();
  1829. }
  1830. if (empty($skusOldIds) && empty($params['goods_sku_json_value'])) {
  1831. $skuData = [
  1832. 'join_sku_goods_id' => $params['goods_id'],
  1833. 'goods_sku_status' => 'ON',
  1834. 'goods_sku_specs_json' => '{"规格": "标准"}',
  1835. 'goods_sku_title' => "标准" . $params['goods_name'],
  1836. 'goods_sku_market_price' => $params['goods_market_price'] ?? 0,
  1837. 'goods_sku_sales_price' => $params['goods_sales_price'] ?? 0,
  1838. ];
  1839. GoodsSku::insert($skuData);
  1840. }
  1841. // 入新的
  1842. if (!empty($params['goods_sku_json_value'])) {
  1843. foreach ($params['goods_sku_json_value'] as $item) {
  1844. $skus = explode(',', $item['sku']);
  1845. $skuArr = [];
  1846. for ($i = 1; $i <= count($skus); $i++) {
  1847. $skuName = "skuName" . $i;
  1848. $key = $item[$skuName];
  1849. $skuArr[$key] = $skus[$i - 1];
  1850. }
  1851. $specsJson = json_encode($skuArr);
  1852. $skuTitle = str_replace('-', ',', $item['sku']) . $params['goods_name'];
  1853. if ($operation == 'update' && !empty($item['sku_id'])) {
  1854. $model = GoodsSku::where('goods_sku_id', $item['sku_id'])->first();
  1855. if (!$model) {
  1856. $model = new GoodsSku();
  1857. } else {
  1858. unset($skusOldIds[$model->goods_sku_id]);
  1859. }
  1860. } else {
  1861. $model = GoodsSku::where('join_sku_goods_id', $params['goods_id'])->where('goods_sku_title', $skuTitle)->first();
  1862. if (!$model) {
  1863. $model = new GoodsSku();
  1864. } else {
  1865. unset($skusOldIds[$model->goods_sku_id]);
  1866. }
  1867. }
  1868. $model->join_sku_goods_id = $params['goods_id'];
  1869. $model->goods_sku_status = $params['goods_status'];
  1870. $model->goods_sku_specs_json = $specsJson;
  1871. $model->goods_sku_title = $skuTitle;
  1872. $model->goods_sku_market_price = $params['goods_market_price'] ?? 0;
  1873. $model->goods_sku_sales_price = $item['price'];
  1874. $model->goods_sku_storage_json = json_encode(['storage' => $item['stock']]);
  1875. $model->save();
  1876. }
  1877. }
  1878. if ($operation == 'update' && !empty($skusOldIds)) {
  1879. GoodsSku::whereIn('goods_sku_id', $skusOldIds)->delete();
  1880. }
  1881. Db::commit();
  1882. } catch (\Exception $e) {
  1883. dump($e->getTrace());
  1884. Db::rollBack();
  1885. throw new BusinessException('规格数据更新异常~');
  1886. }
  1887. }
  1888. /**
  1889. * @Desc
  1890. * @Author Gorden
  1891. * @Date 2024/3/12 8:45
  1892. *
  1893. * @param array $data
  1894. * @param $model
  1895. * @return array
  1896. * @throws BusinessException
  1897. */
  1898. private static function inputFilter(array $data, $model): array
  1899. {
  1900. $table = config('database.connections.mysql.prefix') . $model->getTable();
  1901. $allow_column = $model->getConnection()->select("desc `$table`");
  1902. if (!$allow_column) {
  1903. throw new BusinessException('表不存在', 2);
  1904. }
  1905. $columns = array_column($allow_column, 'Type', 'Field');
  1906. foreach ($data as $col => $item) {
  1907. if (!isset($columns[$col])) {
  1908. unset($data[$col]);
  1909. continue;
  1910. }
  1911. // 非字符串类型传空则为null
  1912. if ($item === '' && strpos(strtolower($columns[$col]), 'varchar') === false && strpos(strtolower($columns[$col]), 'text') === false) {
  1913. $data[$col] = null;
  1914. }
  1915. if (is_array($item)) {
  1916. $data[$col] = implode(',', $item);
  1917. }
  1918. if ($item != '' && (strpos(strtolower($columns[$col]), 'varchar') || strpos(strtolower($columns[$col]), 'text'))) {
  1919. $data[$col] = htmlspecialchars($item);
  1920. }
  1921. }
  1922. if (empty($data['created_at'])) {
  1923. unset($data['created_at']);
  1924. }
  1925. if (empty($data['updated_at'])) {
  1926. unset($data['updated_at']);
  1927. }
  1928. return $data;
  1929. }
  1930. /**
  1931. * @Desc 执行更新
  1932. * @Author Gorden
  1933. * @Date 2024/3/12 8:43
  1934. *
  1935. * @param $id
  1936. * @param $data
  1937. * @param $model
  1938. * @return void
  1939. */
  1940. private static function doUpdate($id, $data, $model)
  1941. {
  1942. $row = $model->find($id);
  1943. foreach ($data as $key => $val) {
  1944. $row->{$key} = $val;
  1945. }
  1946. $row->save();
  1947. }
  1948. /**
  1949. * @Desc 上架定时
  1950. * @Author Gorden
  1951. * @Date 2024/4/11 15:13
  1952. *
  1953. * @return void
  1954. */
  1955. public static function checkListing()
  1956. {
  1957. $key = Goods::LISTING_KEY_PREFIX . date('YmdHi');
  1958. $redis = Redis::connection();
  1959. if (!$redis->exists($key)) {
  1960. return;
  1961. }
  1962. $goodsIds = $redis->sMembers($key);
  1963. if (Goods::whereIn('goods_id', $goodsIds)->update(['goods_status' => 'ON'])) {
  1964. $redis->del($key);
  1965. }
  1966. }
  1967. /**
  1968. * @Desc 自动下架
  1969. * @Author Gorden
  1970. * @Date 2024/4/26 15:26
  1971. *
  1972. * @return void
  1973. */
  1974. public static function checkOffListing()
  1975. {
  1976. $key = Goods::LISTING_OFF_KEY_PREFIX . date('YmdHi');
  1977. $redis = Redis::connection();
  1978. if (!$redis->exists($key)) {
  1979. return;
  1980. }
  1981. $goodsIds = $redis->sMembers($key);
  1982. if (Goods::whereIn('goods_id', $goodsIds)->update(['goods_status' => 'OFF'])) {
  1983. $redis->del($key);
  1984. }
  1985. }
  1986. public static $week = [
  1987. '周一' => 1,
  1988. '周二' => 2,
  1989. '周三' => 3,
  1990. '周四' => 4,
  1991. '周五' => 5,
  1992. '周六' => 6,
  1993. '周日' => 7,
  1994. ];
  1995. }