GoodsService.php 117 KB

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