ReferrerService.php 93 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118
  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 ReferrerService
  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. $data = array_merge($main, $detail, $label, $running, ['sku' => $skus]);
  745. $data['goods_sku_json_label'] = [];
  746. $data['goods_label'] = !empty($data['goods_label']) ? explode(',', $data['goods_label']) : [];
  747. $data['goods_json'] = $data['goods_json'] ? json_decode($data['goods_json'], true) : [];
  748. $data['goods_cover'] = getenv('STORAGE_DOMAIN') . $data['goods_cover'];
  749. if (!empty($data['goods_category']) && $data['goods_category'] == 'INDEX') {
  750. $data['goods_recommend_index'] = 'INDEX';
  751. }
  752. // 创建者
  753. $data['creator_username'] = '';
  754. if (!empty($data['creator_user_id'])) {
  755. $data['creator_username'] = SysUser::where('user_id', $data['creator_user_id'])->value('user_name');
  756. }
  757. if (!empty($data['goods_detail_slider_json'])) {
  758. $data['goods_detail_slider_json'] = json_decode($data['goods_detail_slider_json'], true);
  759. // ……
  760. if (isset($data['goods_detail_slider_json']['slider'])) {
  761. $data['goods_detail_slider_json'] = explode(',', $data['goods_detail_slider_json']['slider']);
  762. }
  763. $slider = '';
  764. foreach ($data['goods_detail_slider_json'] as $item) {
  765. $slider .= getenv('STORAGE_DOMAIN') . $item . ',';
  766. }
  767. $data['goods_detail_slider_json'] = rtrim($slider, ',');
  768. }
  769. $extendJson = [];
  770. if (!empty($data['goods_attribute_json'])) {
  771. $extendJson = json_decode($data['goods_attribute_json'], true);
  772. $data['goods_attribute_json'] = $extendJson;
  773. }
  774. if (!empty($extendJson['coupon'])) {
  775. $data['coupon_list'] = $extendJson['coupon'];
  776. }
  777. $data['express_json'] = [];
  778. if (!empty($data['goods_express_json'])) {
  779. $goodsExpressJson = json_decode($data['goods_express_json'], true);
  780. if (isset($goodsExpressJson['express']) && $goodsExpressJson['express'] == 'Y') {
  781. $data['express_json'][] = 'express';
  782. }
  783. if (isset($goodsExpressJson['self']) && $goodsExpressJson['self'] == 'Y') {
  784. $data['express_json'][] = 'self';
  785. }
  786. if (isset($goodsExpressJson['arrival']) && $goodsExpressJson['arrival'] == 'Y') {
  787. $data['express_json'][] = 'arrival';
  788. }
  789. }
  790. // 详情表数据
  791. if (!empty($data['goods_detail_specs_json'])) {
  792. $specsJson = json_decode($data['goods_detail_specs_json'], true);
  793. foreach ($specsJson as $itemSpecsJson) {
  794. if (isset($itemSpecsJson['key']) && $itemSpecsJson['key'] == '课时') {
  795. $data['curriculum']['period'] = $itemSpecsJson['val'];
  796. } elseif (isset($itemSpecsJson['key']) && $itemSpecsJson['key'] == '群体') {
  797. $data['curriculum']['group'] = $itemSpecsJson['val'];
  798. } elseif (isset($itemSpecsJson['key']) && $itemSpecsJson['key'] == '课程') {
  799. $data['curriculum']['course'] = $itemSpecsJson['val'];
  800. }
  801. }
  802. }
  803. return json_success('', $data);
  804. } catch (\Exception $e) {
  805. dump($e->getMessage());
  806. return json_fail("查询错误~");
  807. }
  808. }
  809. /**
  810. * @Desc 添加商品
  811. * @Author Gorden
  812. * @Date 2024/3/11 10:20
  813. *
  814. * @param $params
  815. * @return Response
  816. */
  817. public static function insert($params): Response
  818. {
  819. Db::beginTransaction();
  820. try {
  821. $params['goods_id'] = "GD" . date('ymdHi') . random_string(4, 'up');
  822. // 主表
  823. self::mainInsert($params);
  824. // 商品详情表
  825. self::detailInsert($params);
  826. // 商品标签表
  827. self::labelInsert($params);
  828. // 产品运行控制信息表
  829. self::goodsRunningInsert($params);
  830. // sku表
  831. self::goodsSkuSet($params, 'insert');
  832. // 待上架状态,上架时间大于当前时间
  833. if ($params['goods_status'] == 'PENDING' && strtotime($params['goods_on_addtimes']) > time()) {
  834. $redis = Redis::connection();
  835. $key = date('YmdHi', strtotime($params['goods_on_addtimes']));
  836. $redis->sAdd(Goods::LISTING_KEY_PREFIX . $key, $params['goods_id']);
  837. }
  838. // 自动下架
  839. if (!empty($params['goods_running_off_type']) && $params['goods_running_off_type'] == 'T' && !empty($params['goods_off_addtimes'])) {
  840. $redis = Redis::connection();
  841. $key = Goods::LISTING_OFF_KEY_PREFIX . date('YmdHi', strtotime($params['goods_off_addtimes']));
  842. $redis->sAdd($key, $params['goods_id']);
  843. }
  844. Db::commit();
  845. } catch (\PDOException $e) {
  846. Db::rollBack();
  847. dump($e->getFile() . '(' . $e->getLine() . '):' . $e->getMessage());
  848. return json_fail('数据写入失败~');
  849. } catch (BusinessException $e) {
  850. Db::rollBack();
  851. dump($e->getFile() . '(' . $e->getLine() . '):' . $e->getMessage());
  852. return json_fail($e->getMessage());
  853. } catch (\Exception $e) {
  854. Db::rollBack();
  855. dump($e->getTrace());
  856. return json_fail('数据写入失败~');
  857. }
  858. _syslog("添加商品", "商品名【" . $params['goods_name'] . "】");
  859. return json_success('success');
  860. }
  861. public static function insertRecharge($params)
  862. {
  863. try {
  864. Db::beginTransaction();
  865. $goods = new Goods();
  866. $goods->goods_id = "GD" . date('ymdHi') . random_string(4, 'up');
  867. $goods->join_goods_category_id = 59;
  868. $goods->goods_classify = 'RECHARGE';
  869. $goods->goods_status = $params['goods_status'];
  870. $goods->goods_sort = $params['goods_sort'];
  871. $goods->goods_category = $params['goods_category'];
  872. $goods->goods_name = $params['goods_name'];
  873. $goods->goods_market_price = $params['goods_sales_price'];
  874. $goods->goods_sales_price = $params['goods_sales_price'];
  875. $goods->goods_sku_json = json_encode(['规格' => [$params['goods_sales_price'] . '元']]);
  876. $goods->goods_attribute_json = json_encode(['added' => ['nbr' => $params['goods_rate'] / 100, 'mode' => 'rate'], 'min-count' => 1]);
  877. $goods->goods_cover = '/images/app/common/null-service.png';
  878. $goods->goods_process_json = json_encode(['mode' => 'do_shopping']);
  879. $goods->goods_addtimes = time();
  880. $goods->save();
  881. $sku = new GoodsSku();
  882. $sku->join_sku_goods_id = $goods->goods_id;
  883. $sku->goods_sku_status = $params['goods_status'];
  884. $sku->goods_sku_specs_json = json_encode(['规格' => $params['goods_sales_price'] . '元']);
  885. $sku->goods_sku_market_price = $params['goods_sales_price'];
  886. $sku->goods_sku_sales_price = $params['goods_sales_price'];
  887. $sku->goods_sku_storage_json = json_encode(['storage' => 9999]);
  888. $sku->save();
  889. Db::commit();
  890. return json_success('success');
  891. } catch (\Exception $e) {
  892. Db::rollBack();
  893. return json_fail('添加充值产品失败');
  894. }
  895. }
  896. public static function updateRecharge($params)
  897. {
  898. try {
  899. Db::beginTransaction();
  900. $goods = Goods::where('goods_id', $params['goods_id'])->first();
  901. if (!$goods) {
  902. return json_fail("数据异常");
  903. }
  904. $goods->goods_market_price = $params['goods_sales_price'];
  905. $goods->goods_sales_price = $params['goods_sales_price'];
  906. $goods->goods_status = $params['goods_status'];
  907. $goods->goods_sku_json = json_encode(['规格' => [$params['goods_sales_price'] . '元']]);
  908. $goods->goods_sort = $params['goods_sort'];
  909. if (!empty($goods->goods_attribute_json)) {
  910. $attributeJson = json_decode($goods->goods_attribute_json, true);
  911. $attributeJson['added']['nbr'] = $params['goods_rate'] / 100;
  912. $goods->goods_attribute_json = json_encode($attributeJson);
  913. }
  914. $goods->save();
  915. $sku = GoodsSku::where('join_sku_goods_id', $params['goods_id'])->where('goods_sku_status','ON')->first();
  916. $sku->goods_sku_status = $params['goods_status'];
  917. $sku->goods_sku_specs_json = json_encode(['规格' => $params['goods_sales_price'] . '元']);
  918. $sku->goods_sku_market_price = $params['goods_sales_price'];
  919. $sku->goods_sku_sales_price = $params['goods_sales_price'];
  920. $sku->save();
  921. Db::commit();
  922. return json_success("success");
  923. } catch (\Exception $e) {
  924. Db::rollBack();
  925. dump($e->getMessage());
  926. return json_fail('编辑充值产品失败');
  927. }
  928. }
  929. public static function insertPackage($params): Response
  930. {
  931. Db::beginTransaction();
  932. try {
  933. $params['goods_id'] = "GD" . date('ymdHi') . random_string(4, 'up');
  934. // 主表
  935. self::mainInsert($params);
  936. // 商品详情表
  937. self::detailInsert($params);
  938. // 套包组件表
  939. self::componentUpdate($params, 'insert');
  940. // 商品标签表
  941. self::labelInsert($params);
  942. // 产品运行控制信息表
  943. self::goodsRunningInsert($params);
  944. // sku表
  945. // self::goodsSkuSet($params, 'insert');
  946. // 待上架状态,上架时间大于当前时间
  947. if ($params['goods_status'] == 'PENDING' && strtotime($params['goods_on_addtimes']) > time()) {
  948. $redis = Redis::connection();
  949. $key = date('YmdHi', strtotime($params['goods_on_addtimes']));
  950. $redis->sAdd(Goods::LISTING_KEY_PREFIX . $key, $params['goods_id']);
  951. }
  952. Db::commit();
  953. } catch (\PDOException $e) {
  954. Db::rollBack();
  955. dump($e->getMessage());
  956. return json_fail('数据写入失败~');
  957. } catch (BusinessException $e) {
  958. Db::rollBack();
  959. dump($e->getMessage());
  960. return json_fail($e->getMessage());
  961. } catch (\Exception $e) {
  962. Db::rollBack();
  963. dump($e->getTrace());
  964. return json_fail('数据写入失败~');
  965. }
  966. _syslog("添加套餐", "商品名【" . $params['goods_name'] . "】");
  967. return json_success('success');
  968. }
  969. public static function update($params)
  970. {
  971. Db::beginTransaction();
  972. try {
  973. // 主表
  974. self::mainUpdate($params);
  975. // 商品详情表
  976. self::detailUpdate($params);
  977. // 商品标签表
  978. self::labelUpdate($params);
  979. // 产品运行控制信息表
  980. self::goodsRunningUpdate($params);
  981. // sku表
  982. self::goodsSkuSet($params, 'update');
  983. Db::commit();
  984. } catch (BusinessException $e) {
  985. Db::rollBack();
  986. return json_fail($e->getMessage());
  987. } catch (\Exception $e) {
  988. Db::rollBack();
  989. return json_fail('数据更新失败~');
  990. }
  991. _syslog("编辑商品", "商品名【" . $params['goods_name'] . "】" ?? "商品ID:【" . $params['goods_id'] . "】");
  992. return json_success('success');
  993. }
  994. public static function changeStatus($params)
  995. {
  996. try {
  997. Goods::where('goods_id', $params['goods_id'])->update(['goods_status' => $params['goods_status']]);
  998. return json_success('修改成功');
  999. } catch (\Exception $e) {
  1000. return json_fail('修改状态失败');
  1001. }
  1002. }
  1003. public static function updatePackage($params)
  1004. {
  1005. Db::beginTransaction();
  1006. try {
  1007. // 主表
  1008. self::mainUpdate($params);
  1009. // 商品详情表
  1010. self::detailUpdate($params);
  1011. // 套包组件表
  1012. self::componentUpdate($params, 'update');
  1013. // 商品标签表
  1014. self::labelUpdate($params);
  1015. // 产品运行控制信息表
  1016. self::goodsRunningUpdate($params);
  1017. // sku表
  1018. self::goodsSkuSet($params, 'update');
  1019. Db::commit();
  1020. } catch (BusinessException $e) {
  1021. Db::rollBack();
  1022. return json_fail($e->getMessage());
  1023. } catch (\Exception $e) {
  1024. Db::rollBack();
  1025. dump($e->getTrace());
  1026. return json_fail('数据更新失败~');
  1027. }
  1028. _syslog("编辑套餐", "商品名【" . $params['goods_name'] . "】" ?? "商品ID:【" . $params['goods_id'] . "】");
  1029. return json_success('success');
  1030. }
  1031. /**
  1032. * @Desc 删除商品
  1033. * @Author Gorden
  1034. * @Date 2024/3/28 13:20
  1035. *
  1036. * @param $ids
  1037. * @return Response
  1038. */
  1039. public static function delete($ids)
  1040. {
  1041. if (!$ids) {
  1042. return json_fail("数据错误~");
  1043. }
  1044. if (!is_array($ids)) {
  1045. $ids = [$ids];
  1046. }
  1047. $goods = Goods::whereIn('goods_id', $ids)->get()->toArray();
  1048. if (!$goods) {
  1049. return json_fail("数据错误~");
  1050. }
  1051. // 是否在套包里
  1052. if (GoodsComponent::whereIn('join_component_goods_id', $ids)->exists()) {
  1053. return json_fail("当前商品存在于套包中,请先在套包中删除");
  1054. }
  1055. // 是否已被购买过
  1056. if (OrderSheet::whereIn('join_sheet_goods_id', $ids)->exists()) {
  1057. return json_fail("当前商品已有购买历史,如不在APP显示,请选择【下架】操作");
  1058. }
  1059. // 是否预约过
  1060. if (Appointment::whereIn('join_appointment_goods_id', $ids)->exists()) {
  1061. return json_fail("当前商品已有预约历史,如不在APP显示,请选择【下架】操作");
  1062. }
  1063. Db::beginTransaction();
  1064. try {
  1065. Goods::whereIn('goods_id', $ids)->delete();
  1066. GoodsDetail::whereIn('join_detail_goods_id', $ids)->delete();
  1067. GoodsLabel::whereIn('join_label_goods_id', $ids)->delete();
  1068. GoodsRunning::whereIn('join_running_goods_id', $ids)->delete();
  1069. GoodsSku::whereIn('join_sku_goods_id', $ids)->delete();
  1070. Db::commit();
  1071. _syslog("删除商品 / 套餐", "ID:【" . implode(',', $ids) . "】", $goods);
  1072. return json_success("商品删除成功");
  1073. } catch (\Exception $e) {
  1074. Db::rollBack();
  1075. return json_fail("商品删除失败~");
  1076. }
  1077. }
  1078. /**
  1079. * @Desc 商品主表
  1080. * @Author Gorden
  1081. * @Date 2024/3/11 11:20
  1082. *
  1083. * @param $params
  1084. * @return mixed|string
  1085. * @throws BusinessException
  1086. */
  1087. public static function mainInsert($params)
  1088. {
  1089. if (!empty($params['goods_cover'])) {
  1090. $params['goods_cover'] = str_replace(getenv('STORAGE_DOMAIN'), '', $params['goods_cover']);
  1091. }
  1092. // 如果产品是待处理状态
  1093. if ($params['goods_status'] == 'PENDING') {
  1094. if (strtotime($params['goods_on_addtimes']) <= time()) {
  1095. $params['goods_status'] = 'ON';
  1096. }
  1097. }
  1098. $category = SysCategory::where('category_id', $params['join_goods_category_id'])->first();
  1099. if (!$category) {
  1100. throw new BusinessException("产品分类不存在~");
  1101. }
  1102. if (empty($params['goods_category'])) {
  1103. $params['goods_category'] = $category->category_classify;
  1104. }
  1105. try {
  1106. $model = new Goods();
  1107. $model->goods_id = $params['goods_id'];
  1108. $model->join_goods_category_id = $params['join_goods_category_id'] ?? 0;
  1109. $model->join_goods_supplier_id = $params['join_goods_supplier_id'] ?? 0;
  1110. $model->goods_classify = $params['goods_classify'] ?? '';
  1111. $model->goods_status = $params['goods_status'] ?? '';
  1112. $model->goods_category = $params['goods_category'] ?? '';
  1113. // $model->goods_prefix = $params['goods_prefix'] ?? 】($category->category_name ? '【' . $category->category_name . '' : '');
  1114. $model->goods_prefix = $params['goods_prefix'] ?? '';
  1115. $model->goods_name = $params['goods_name'];
  1116. $model->goods_market_price = $params['goods_market_price'] ?? 0;
  1117. $model->goods_sales_price = $params['goods_sales_price'] ?? 0;
  1118. $model->goods_sku_json = !empty($params['goods_sku_json_label']) ? json_encode($params['goods_sku_json_label']) : json_encode(['规格' => ['标准']]);
  1119. $model->goods_attribute_json = !empty($params['goods_attribute_json']) ? $params['goods_attribute_json'] : '[]';
  1120. $model->goods_title = $params['goods_title'] ?? '';
  1121. $model->goods_cover = $params['goods_cover'] ?? '';
  1122. $model->goods_on_addtimes = isset($params['goods_on_addtimes']) ? strtotime($params['goods_on_addtimes']) : null;
  1123. $model->goods_sort = $params['goods_sort'] ?? null;
  1124. $model->goods_groupby = $params['goods_groupby'] ?? '';
  1125. $model->goods_remark = $params['goods_remark'] ?? '';
  1126. $model->goods_extend_json = $params['goods_extend_json'] ?? '{}';
  1127. $model->is_support_appointment = $params['is_support_appointment'] ?? 'N';
  1128. $model->creator_user_id = JwtToken::getCurrentId();
  1129. $model->goods_addtimes = time();
  1130. $model->goods_updatetimes = time();
  1131. // {"express":"Y","self":"Y","arrival":"Y"}
  1132. $expressJson = [];
  1133. if (!empty($params['express_json'])) {
  1134. if (in_array('express', $params['express_json'])) {
  1135. $expressJson['express'] = 'Y';
  1136. } else {
  1137. $expressJson['express'] = 'N';
  1138. }
  1139. if (in_array('self', $params['express_json'])) {
  1140. $expressJson['self'] = 'Y';
  1141. } else {
  1142. $expressJson['self'] = 'N';
  1143. }
  1144. if (in_array('arrival', $params['express_json'])) {
  1145. $expressJson['arrival'] = 'Y';
  1146. } else {
  1147. $expressJson['arrival'] = 'N';
  1148. }
  1149. $model->goods_express_json = json_encode($expressJson);
  1150. }
  1151. if (!empty($params['is_support_appointment']) && $params['is_support_appointment'] == 'Y' && !empty($params['appointment_times']) && $params['goods_category'] != 'TRAVEL') {
  1152. $times = [];
  1153. $attributeJsonTimeArr = [];
  1154. $personTotal = 0;
  1155. foreach ($params['appointment_times'] as $time) {
  1156. $attributeJsonTimeArr[] = strtotime(date('Y-m-d ') . $time['appointmentTimeStart']);
  1157. $attributeJsonTimeArr[] = strtotime(date('Y-m-d ') . $time['appointmentTimeEnd']);
  1158. $personTotal += $time['person'];
  1159. $times[$time['appointmentTimeStart']] = [
  1160. 'person' => $time['person'],
  1161. 'duration' => $time['appointmentTimeStart'] . '-' . $time['appointmentTimeEnd']
  1162. ];
  1163. }
  1164. $attributeJsonTime = date('H:i', min($attributeJsonTimeArr)) . '至' . date('H:i', max($attributeJsonTimeArr));
  1165. $newDates = [];
  1166. foreach ($params['dates'] as $date) {
  1167. $key = self::$week[$date];
  1168. $newDates[$key] = $date;
  1169. }
  1170. ksort($newDates);
  1171. $currentDate = current($newDates);
  1172. $lastDate = end($newDates);
  1173. $attributeJsonDate = '';
  1174. if (self::$week[$lastDate] - self::$week[$currentDate] + 1 > count($newDates)) {
  1175. $attributeJsonDate = implode(',', $newDates);
  1176. } else if (self::$week[$lastDate] - self::$week[$currentDate] + 1 == count($newDates)) {
  1177. $attributeJsonDate = $currentDate . '至' . $lastDate;
  1178. }
  1179. // if (isset($params['work_time'])){
  1180. // $workTimeStart = date('H:i',strtotime($params['work_time'][0]));
  1181. // $workTimeEnd = date('H:i',strtotime($params['work_time'][1]));
  1182. // $attributeJsonTime = $workTimeStart.'至'.$workTimeEnd;
  1183. // }
  1184. $attributeJson = [
  1185. 'icon' => $model->goods_cover,
  1186. 'date' => $attributeJsonDate,
  1187. // 'time' => $attributeJsonTime,
  1188. 'dates' => $newDates ? array_values($newDates) : [],
  1189. 'times' => $times,
  1190. 'person' => $personTotal
  1191. ];
  1192. // if(isset($params['address'])){
  1193. // $attributeJson['address'] = $params['address'];
  1194. // }
  1195. // if (isset($params['min_count'])){
  1196. // $attributeJson['min-count'] = $params['min_count'];
  1197. // }else{
  1198. // $attributeJson['min-count'] = 1;
  1199. // }
  1200. // if (isset($params['teachers'])){
  1201. // $attributeJson['teachers'] = $params['teachers'];
  1202. // }
  1203. if (!empty($params['appointment_label'])) {
  1204. $attributeJson['label'] = $params['appointment_label'];
  1205. }
  1206. // if (!empty($params['address'])) {
  1207. // $attributeJson['address'] = $params['address'];
  1208. // }
  1209. // if (!empty($params['position'])){
  1210. // $attributeJson['position'] = $params['position'];
  1211. // }
  1212. // if (isset($params['goods_service_premises'])){
  1213. // $attributeJson['service_premises_id'] = $params['goods_service_premises'];
  1214. // }
  1215. $model->goods_attribute_json = json_encode($attributeJson, JSON_UNESCAPED_UNICODE);
  1216. // $times = [];
  1217. // foreach ($params['appointment_times'] as $time) {
  1218. // $times[$time['appointmentTimeStart']] = [
  1219. // 'person' => $time['person'],
  1220. // 'duration' => $time['appointmentTimeStart'] . '-' . $time['appointmentTimeEnd']
  1221. // ];
  1222. // }
  1223. // $model->goods_attribute_json = json_encode([
  1224. // 'icon' => '',
  1225. // 'dates' => $params['dates'] ?? [],
  1226. // 'times' => $times
  1227. // ]);
  1228. }
  1229. if (!empty($params['is_support_appointment']) && $params['is_support_appointment'] == 'Y' && !empty($params['appointment_times']) && $params['goods_category'] == 'TRAVEL') {
  1230. if (!empty($model->goods_attribute_json) && !is_array($model->goods_attribute_json)) {
  1231. $attributeJson = json_decode($model->goods_attribute_json, true);
  1232. } elseif (empty($model->goods_attribute_json)) {
  1233. $attributeJson = [];
  1234. }
  1235. $attributeJson['travel-day'] = $params['travel_day'];
  1236. $attributeJson['travel-begin'] = $params['travel_begin'];
  1237. $attributeJson['travel-night'] = $params['travel_night'];
  1238. $attributeJson['travel-trans'] = $params['travel_trans'];
  1239. $unixs = [];
  1240. foreach ($params['appointment_times'] as $times) {
  1241. $unix = strtotime($times['days']);
  1242. $unixs[$unix] = $times['person'];
  1243. }
  1244. ksort($unixs);
  1245. $months = [];
  1246. foreach ($unixs as $key => $unix) {
  1247. $month = date('Ym', $key);
  1248. $day = date('d', $key);
  1249. $months[$month][$day] = $unix;
  1250. }
  1251. $attributeJson['month'] = $months;
  1252. $model->goods_attribute_json = json_encode($attributeJson, JSON_UNESCAPED_UNICODE);
  1253. }
  1254. if (!empty($params['goods_json']) && $params['join_goods_category_id'] == 65) {
  1255. $goodsJson = json_decode($params['goods_json'], true);
  1256. // foreach ($goodsJson as $key => $item) {
  1257. // $goodsJson[$key]['color'] = hexToRgb($item['color']);
  1258. // }
  1259. //
  1260. $model->goods_json = json_encode($goodsJson);
  1261. } elseif (!empty($params['goods_json']) && $params['join_goods_category_id'] == 43) {
  1262. $goodsJson = json_decode($params['goods_json'], true);
  1263. $newGoodsJson = [];
  1264. foreach ($goodsJson as $item1) {
  1265. if (empty($item1['title'])) {
  1266. continue;
  1267. }
  1268. $newItem1 = [];
  1269. foreach ($item1['items'] as $item2) {
  1270. $newParams = [];
  1271. foreach ($item2['params'] as $param) {
  1272. if (!empty($param[0]) || !empty($param[1])) {
  1273. $newParams[] = $param;
  1274. }
  1275. }
  1276. $newItem1['items'][$item2['key']] = $newParams;
  1277. }
  1278. $newItem1['service'] = $item1['service'] ?? '';
  1279. $newGoodsJson[$item1['title']] = $newItem1;
  1280. }
  1281. $model->goods_json = json_encode($newGoodsJson);
  1282. } else {
  1283. $model->goods_json = '[]';
  1284. }
  1285. if (!empty($params['goods_premisses'])) {
  1286. $attributeJson = [];
  1287. if (!empty($model->goods_attribute_json) && !is_array($model->goods_attribute_json)) {
  1288. $attributeJson = json_decode($model->goods_attribute_json, true);
  1289. } elseif (empty($model->goods_attribute_json)) {
  1290. $attributeJson = [];
  1291. }
  1292. $attributeJson['premisses'] = $params['goods_premisses'];
  1293. $model->goods_attribute_json = json_encode($attributeJson);
  1294. }
  1295. if (!empty($params['goods_theme_color']) && !empty($params['goods_theme_icon'])) {
  1296. if (!empty($model->goods_attribute_json) && !is_array($model->goods_attribute_json)) {
  1297. $attributeJson = json_decode($model->goods_attribute_json, true);
  1298. } elseif (empty($model->goods_attribute_json)) {
  1299. $attributeJson = [];
  1300. }
  1301. $attributeJson['bg'] = $params['goods_theme_color'];
  1302. $attributeJson['icon'] = str_replace(getenv('STORAGE_DOMAIN'), '', $params['goods_theme_icon']);
  1303. $model->goods_attribute_json = json_encode($attributeJson);
  1304. }
  1305. if (!empty($params['address'])) {
  1306. if (!empty($model->goods_attribute_json) && !is_array($model->goods_attribute_json)) {
  1307. $attributeJson = json_decode($model->goods_attribute_json, true);
  1308. } elseif (empty($model->goods_attribute_json)) {
  1309. $attributeJson = [];
  1310. }
  1311. $attributeJson['address'] = $params['address'];
  1312. $model->goods_attribute_json = json_encode($attributeJson);
  1313. }
  1314. if (!empty($params['position'])) {
  1315. if (!empty($model->goods_attribute_json) && !is_array($model->goods_attribute_json)) {
  1316. $attributeJson = json_decode($model->goods_attribute_json, true);
  1317. } elseif (empty($model->goods_attribute_json)) {
  1318. $attributeJson = [];
  1319. }
  1320. $attributeJson['position'] = $params['position'];
  1321. $model->goods_attribute_json = json_encode($attributeJson);
  1322. }
  1323. if (isset($params['goods_service_premises'])) {
  1324. if (!empty($model->goods_attribute_json) && !is_array($model->goods_attribute_json)) {
  1325. $attributeJson = json_decode($model->goods_attribute_json, true);
  1326. } elseif (empty($model->goods_attribute_json)) {
  1327. $attributeJson = [];
  1328. }
  1329. $attributeJson['service_premises_id'] = $params['goods_service_premises'];
  1330. $model->goods_attribute_json = json_encode($attributeJson);
  1331. }
  1332. if (isset($params['min_count'])) {
  1333. if (!empty($model->goods_attribute_json) && !is_array($model->goods_attribute_json)) {
  1334. $attributeJson = json_decode($model->goods_attribute_json, true);
  1335. } elseif (empty($model->goods_attribute_json)) {
  1336. $attributeJson = [];
  1337. }
  1338. $attributeJson['min-count'] = $params['min_count'];
  1339. $model->goods_attribute_json = json_encode($attributeJson);
  1340. }
  1341. if (isset($params['teachers'])) {
  1342. if (!empty($model->goods_attribute_json) && !is_array($model->goods_attribute_json)) {
  1343. $attributeJson = json_decode($model->goods_attribute_json, true);
  1344. } elseif (empty($model->goods_attribute_json)) {
  1345. $attributeJson = [];
  1346. }
  1347. $attributeJson['teachers'] = $params['teachers'];
  1348. $model->goods_attribute_json = json_encode($attributeJson);
  1349. }
  1350. if (isset($params['work_time'])) {
  1351. if (!empty($model->goods_attribute_json) && !is_array($model->goods_attribute_json)) {
  1352. $attributeJson = json_decode($model->goods_attribute_json, true);
  1353. } elseif (empty($model->goods_attribute_json)) {
  1354. $attributeJson = [];
  1355. }
  1356. $workTimeStart = date('H:i', strtotime($params['work_time'][0]));
  1357. $workTimeEnd = date('H:i', strtotime($params['work_time'][1]));
  1358. $attributeJsonTime = $workTimeStart . '至' . $workTimeEnd;
  1359. $attributeJson['time'] = $attributeJsonTime;
  1360. $model->goods_attribute_json = json_encode($attributeJson);
  1361. }
  1362. if (!empty($params['coupon_id']) && !empty($params['coupon_nbr'])) {
  1363. if (!empty($model->goods_attribute_json) && !is_array($model->goods_attribute_json)) {
  1364. $attributeJson = json_decode($model->goods_attribute_json, true);
  1365. } elseif (empty($model->goods_attribute_json)) {
  1366. $attributeJson = [];
  1367. }
  1368. $coupons = Coupon::whereIn('coupon_id', $params['coupon_id'])
  1369. ->select('coupon_id', 'coupon_name')
  1370. ->get()
  1371. ->toArray();
  1372. $couponList = [];
  1373. foreach ($coupons as $coupon) {
  1374. if (isset($params['coupon_nbr'][$coupon['coupon_id']])) {
  1375. $couponList[$coupon['coupon_id']] = [
  1376. 'num' => $params['coupon_nbr'][$coupon['coupon_id']],
  1377. 'name' => $coupon['coupon_name']
  1378. ];
  1379. }
  1380. }
  1381. $attributeJson['coupon'] = $couponList;
  1382. $model->goods_attribute_json = json_encode($attributeJson, JSON_UNESCAPED_UNICODE);
  1383. }
  1384. if ($model->save()) {
  1385. return $model->goods_id;
  1386. }
  1387. // 异常
  1388. throw new BusinessException("数据写入失败~");
  1389. } catch (\Exception $e) {
  1390. dump($e->getMessage());
  1391. throw new BusinessException("数据写入失败~");
  1392. }
  1393. }
  1394. /**
  1395. * @Desc 详情表
  1396. * @Author Gorden
  1397. * @Date 2024/3/11 11:19
  1398. *
  1399. * @param $params
  1400. * @return void
  1401. * @throws BusinessException
  1402. */
  1403. public static function detailInsert($params)
  1404. {
  1405. if (!empty($params['goods_detail_slider_json'])) {
  1406. $params['goods_detail_slider_json'] = str_replace(getenv('STORAGE_DOMAIN'), '', $params['goods_detail_slider_json']);
  1407. $params['goods_detail_slider_json'] = json_encode(['slider' => $params['goods_detail_slider_json']]);
  1408. }
  1409. if (isset($params['curriculum'])) {
  1410. $params['goods_detail_specs_json'] = json_encode([
  1411. [
  1412. 'key' => '课时',
  1413. 'val' => $params['curriculum']['period'] ?? '',
  1414. ],
  1415. [
  1416. 'key' => '群体',
  1417. 'val' => $params['curriculum']['group'] ?? '',
  1418. ],
  1419. [
  1420. 'key' => '课程',
  1421. 'val' => $params['curriculum']['course'] ?? '',
  1422. ],
  1423. ]);
  1424. }
  1425. try {
  1426. $model = new GoodsDetail();
  1427. $model->join_detail_goods_id = $params['goods_id'];
  1428. $model->goods_detail_code_json = $params['goods_detail_code_json'] ?? '{}';
  1429. $model->goods_detail_slider_json = $params['goods_detail_slider_json'] ?? '{}';
  1430. $model->goods_detail_specs_json = $params['goods_detail_specs_json'] ?? '{}';
  1431. $model->goods_detail_content = $params['goods_detail_content'] ?? '';
  1432. if (!$model->save()) {
  1433. // 异常
  1434. throw new BusinessException("轮播图/详情数据写入失败~");
  1435. }
  1436. } catch (\Exception $e) {
  1437. dump($e->getMessage());
  1438. throw new BusinessException("轮播图/详情数据写入失败~");
  1439. }
  1440. }
  1441. public static function componentUpdate($params, $type = 'insert')
  1442. {
  1443. Db::beginTransaction();
  1444. try {
  1445. $goodsSku = '';
  1446. // 有先删除
  1447. if ($type == 'update') {
  1448. GoodsComponent::where('join_component_master_goods_id', $params['goods_id'])->delete();
  1449. $goodsSku = GoodsSku::where('join_sku_goods_id', $params['goods_id'])->first();
  1450. if ($goodsSku) {
  1451. $goodsSku->goods_sku_market_price = $params['goods_market_price'] ?? 0;
  1452. $goodsSku->goods_sku_sales_price = $params['goods_sales_price'] ?? 0;
  1453. $goodsSku->save();
  1454. }
  1455. }
  1456. if ($type == 'insert' || !$goodsSku) {
  1457. Goods::where('goods_id', $params['goods_id'])->update(['goods_sku_json' => '{"规格": ["标准"]}']);
  1458. $skuData = [
  1459. 'join_sku_goods_id' => $params['goods_id'],
  1460. 'goods_sku_status' => 'ON',
  1461. 'goods_sku_specs_json' => '{"规格": "标准"}',
  1462. 'goods_sku_title' => "标准" . $params['goods_name'],
  1463. 'goods_sku_market_price' => $params['goods_market_price'] ?? 0,
  1464. 'goods_sku_sales_price' => $params['goods_sales_price'] ?? 0,
  1465. ];
  1466. GoodsSku::insert($skuData);
  1467. }
  1468. $data = [];
  1469. foreach ($params['goods_content_list'] as $item) {
  1470. if (!in_array($item['goods_id'], $params['join_component_goods_id'])) {
  1471. continue;
  1472. }
  1473. $goods = Goods::where('goods_id', $params['goods_id'])->first();
  1474. if (!$goods) {
  1475. continue;
  1476. }
  1477. $data[] = [
  1478. 'join_component_master_goods_id' => $params['goods_id'],
  1479. 'join_component_goods_id' => $item['goods_id'] ?? '',
  1480. 'join_component_goods_sku_id' => $item['sku_id'] ?? '',
  1481. 'goods_component_price' => $item['goods_sales_price'] ?? '',
  1482. 'goods_component_cover' => $goods->goods_cover,
  1483. 'goods_component_json' => json_encode(['goods_name' => $item['goods_name'], 'nbr' => $item['nbr'], 'sku_id' => $item['sku_id'] ?? '']),
  1484. 'goods_component_addtimes' => time()
  1485. ];
  1486. }
  1487. if ($data) {
  1488. GoodsComponent::insert($data);
  1489. }
  1490. Db::commit();
  1491. } catch (\Exception $e) {
  1492. Db::rollBack();
  1493. dump($e->getMessage());
  1494. throw new BusinessException("数据写入失败~");
  1495. }
  1496. }
  1497. /**
  1498. * @Desc 标签表
  1499. * @Author Gorden
  1500. * @Date 2024/3/11 11:32
  1501. *
  1502. * @param $params
  1503. * @return void
  1504. * @throws BusinessException
  1505. */
  1506. public static function labelInsert($params)
  1507. {
  1508. $model = new GoodsLabel();
  1509. $model->join_label_goods_id = $params['goods_id'];
  1510. $model->goods_label = $params['goods_label'] ? implode(',', $params['goods_label']) : '';
  1511. $model->goods_label_extend_json = !empty($params['goods_label_extend_json']) ? $params['goods_label_extend_json'] : '{}';
  1512. if (!$model->save()) {
  1513. // 异常
  1514. throw new BusinessException('数据写入失败~');
  1515. }
  1516. }
  1517. /**
  1518. * @Desc 产品运行控制信息表
  1519. * @Author Gorden
  1520. * @Date 2024/3/11 11:38
  1521. *
  1522. * @param $params
  1523. * @return void
  1524. * @throws BusinessException
  1525. */
  1526. public static function goodsRunningInsert($params)
  1527. {
  1528. try {
  1529. $model = new GoodsRunning();
  1530. $model->join_running_goods_id = $params['goods_id'];
  1531. $model->goods_running_storage = $params['goods_running_storage'] ?? 0;
  1532. $model->goods_running_sale = $params['goods_running_sale'] ?? 0;
  1533. $model->goods_running_off_type = !empty($params['goods_running_off_type']) ? $params['goods_running_off_type'] : '';
  1534. $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'])]) : '[]';
  1535. if (!$model->save()) {
  1536. throw new BusinessException('数据写入失败');
  1537. }
  1538. } catch (\Exception $e) {
  1539. dump($e->getMessage());
  1540. throw new BusinessException('数据写入失败');
  1541. }
  1542. }
  1543. /**
  1544. * @Desc SKU
  1545. * @Author Gorden
  1546. * @Date 2024/3/11 12:01
  1547. *
  1548. * @param $params
  1549. * @return void
  1550. * @throws BusinessException
  1551. */
  1552. public static function skuInsert($params)
  1553. {
  1554. $model = new GoodsSku();
  1555. $model->join_sku_goods_id = $params['goods_id'];
  1556. $model->goods_sku_status = $params['goods_sku_status'];
  1557. $model->goods_sku_specs_json = $params['goods_sku_specs_json'];
  1558. $model->goods_sku_title = $params['goods_sku_title'];
  1559. $model->goods_sku_images_json = $params['goods_sku_images_json'];
  1560. $model->goods_sku_content = $params['goods_sku_content'];
  1561. $model->goods_sku_market_price = $params['goods_sku_market_price'];
  1562. $model->goods_sku_sales_price = $params['goods_sku_sales_price'];
  1563. $model->goods_sku_storage_json = $params['goods_sku_storage_json'];
  1564. $model->goods_sku_service_json = $params['goods_sku_service_json'];
  1565. $model->goods_sku_extend_json = $params['goods_sku_extend_json'];
  1566. if (!$model->save()) {
  1567. throw new BusinessException('规格数据写入失败~');
  1568. }
  1569. }
  1570. /**
  1571. * @Desc
  1572. * @Author Gorden
  1573. * @Date 2024/3/12 8:44
  1574. *
  1575. * @param $params
  1576. * @return void
  1577. * @throws BusinessException
  1578. */
  1579. public static function mainUpdate($params)
  1580. {
  1581. try {
  1582. $data = self::inputFilter($params, new Goods());
  1583. if (!empty($data['goods_cover'])) {
  1584. $data['goods_cover'] = str_replace(getenv('STORAGE_DOMAIN'), '', $data['goods_cover']);
  1585. }
  1586. $data['goods_on_addtimes'] = isset($data['goods_on_addtimes']) ? strtotime($data['goods_on_addtimes']) : 0;
  1587. $data['goods_sku_json'] = !empty($params['goods_sku_json_label']) ? json_encode($params['goods_sku_json_label']) : json_encode(['规格' => ['标准']]);
  1588. $row = Goods::find($data['goods_id']);
  1589. if ($row->join_goods_category_id != $data['join_goods_category_id']) {
  1590. $category = SysCategory::where('category_id', $params['join_goods_category_id'])->first();
  1591. if (!$category) {
  1592. throw new BusinessException("产品分类不存在~");
  1593. }
  1594. $data['goods_category'] = $category->category_classify ?? '';
  1595. $data['goods_prefix'] = $data['goods_prefix'] ?? ($category->category_name ? '【' . $category->category_name . '】' : '');
  1596. }
  1597. $expressJson = [];
  1598. if (!empty($params['express_json'])) {
  1599. if (in_array('express', $params['express_json'])) {
  1600. $expressJson['express'] = 'Y';
  1601. } else {
  1602. $expressJson['express'] = 'N';
  1603. }
  1604. if (in_array('self', $params['express_json'])) {
  1605. $expressJson['self'] = 'Y';
  1606. } else {
  1607. $expressJson['self'] = 'N';
  1608. }
  1609. if (in_array('arrival', $params['express_json'])) {
  1610. $expressJson['arrival'] = 'Y';
  1611. } else {
  1612. $expressJson['arrival'] = 'N';
  1613. }
  1614. $data['goods_express_json'] = json_encode($expressJson);
  1615. }
  1616. $attributeJson = [];
  1617. if (!empty($row->goods_attribute_json)) {
  1618. $attributeJson = json_decode($row->goods_attribute_json, true);
  1619. }
  1620. if (!empty($params['coupon_id']) && !empty($params['coupon_nbr'])) {
  1621. $coupons = Coupon::whereIn('coupon_id', $params['coupon_id'])
  1622. ->select('coupon_id', 'coupon_name')
  1623. ->get()
  1624. ->toArray();
  1625. $couponList = [];
  1626. foreach ($coupons as $coupon) {
  1627. if (isset($params['coupon_nbr'][$coupon['coupon_id']])) {
  1628. $couponList[$coupon['coupon_id']] = [
  1629. 'num' => $params['coupon_nbr'][$coupon['coupon_id']],
  1630. 'name' => $coupon['coupon_name']
  1631. ];
  1632. }
  1633. }
  1634. $attributeJson['coupon'] = $couponList;
  1635. }
  1636. if (!empty($params['attribute_account'])){
  1637. $attributeJson['account'] = $params['attribute_account'];
  1638. }
  1639. if (!empty($params['attribute_control'])){
  1640. $attributeJson['control'] = $params['attribute_control'];
  1641. }
  1642. $data['goods_attribute_json'] = json_encode($attributeJson, JSON_UNESCAPED_UNICODE);
  1643. foreach ($data as $key => $val) {
  1644. $row->{$key} = $val;
  1645. }
  1646. $row->goods_updatetimes = time();
  1647. $row->save();
  1648. } catch (BusinessException $e) {
  1649. throw new BusinessException($e->getMessage());
  1650. } catch (\Exception $e) {
  1651. dump($e->getTrace());
  1652. throw new BusinessException('数据更新异常~1');
  1653. }
  1654. }
  1655. /**
  1656. * @Desc
  1657. * @Author Gorden
  1658. * @Date 2024/3/12 9:57
  1659. *
  1660. * @param $params
  1661. * @return void
  1662. * @throws BusinessException
  1663. */
  1664. public static function detailUpdate($params)
  1665. {
  1666. try {
  1667. $data = self::inputFilter($params, new GoodsDetail());
  1668. if (!empty($data['goods_detail_slider_json'])) {
  1669. $data['goods_detail_slider_json'] = str_replace(getenv('STORAGE_DOMAIN'), '', $data['goods_detail_slider_json']);
  1670. $data['goods_detail_slider_json'] = json_encode(['slider' => $data['goods_detail_slider_json']]);
  1671. }
  1672. if (isset($params['curriculum'])) {
  1673. $data['goods_detail_specs_json'] = json_encode([
  1674. [
  1675. 'key' => '课时',
  1676. 'val' => $params['curriculum']['period'] ?? '',
  1677. ],
  1678. [
  1679. 'key' => '群体',
  1680. 'val' => $params['curriculum']['group'] ?? '',
  1681. ],
  1682. [
  1683. 'key' => '课程',
  1684. 'val' => $params['curriculum']['course'] ?? '',
  1685. ],
  1686. ]);
  1687. }
  1688. // 根据goods_id 查详情ID
  1689. $detail = GoodsDetail::where('join_detail_goods_id', $params['goods_id'])->first();
  1690. if ($detail) {
  1691. self::doUpdate($detail->join_detail_goods_id, $data, new GoodsDetail());
  1692. } else {
  1693. $data['join_detail_goods_id'] = $params['goods_id'];
  1694. GoodsDetail::insert($data);
  1695. }
  1696. } catch (BusinessException $e) {
  1697. throw new BusinessException($e->getMessage());
  1698. } catch (\Exception $e) {
  1699. dump($e->getMessage());
  1700. throw new BusinessException('轮播图/详情数据更新异常~');
  1701. }
  1702. }
  1703. /**
  1704. * @Desc
  1705. * @Author Gorden
  1706. * @Date 2024/3/12 9:58
  1707. *
  1708. * @param $params
  1709. * @return void
  1710. * @throws BusinessException
  1711. */
  1712. public static function labelUpdate($params)
  1713. {
  1714. try {
  1715. $data = self::inputFilter($params, new GoodsLabel());
  1716. // 根据goods_id 查详情ID
  1717. $detail = GoodsLabel::where('join_label_goods_id', $params['goods_id'])->first();
  1718. if ($detail) {
  1719. self::doUpdate($detail->goods_label_id, $data, new GoodsLabel());
  1720. } else {
  1721. $data['join_label_goods_id'] = $params['goods_id'];
  1722. GoodsLabel::insert($data);
  1723. }
  1724. } catch (BusinessException $e) {
  1725. throw new BusinessException($e->getMessage());
  1726. } catch (\Exception $e) {
  1727. dump($e->getMessage());
  1728. throw new BusinessException('数据更新异常~3');
  1729. }
  1730. }
  1731. /**
  1732. * @Desc
  1733. * @Author Gorden
  1734. * @Date 2024/3/12 9:59
  1735. *
  1736. * @param $params
  1737. * @return void
  1738. * @throws BusinessException
  1739. */
  1740. public static function goodsRunningUpdate($params)
  1741. {
  1742. try {
  1743. $data = self::inputFilter($params, new GoodsRunning());
  1744. // 根据goods_id 查详情ID
  1745. $detail = GoodsRunning::where('join_running_goods_id', $params['goods_id'])->first();
  1746. if (!empty($params['goods_running_off_type']) && $params['goods_running_off_type'] == 'T') {
  1747. $redis = Redis::connection();
  1748. if (!empty($detail->goods_running_off_json)) {
  1749. $goodsRunningOffJson = json_decode($detail->goods_running_off_json, true);
  1750. if (isset($goodsRunningOffJson['time'])) {
  1751. $oldKey = Goods::LISTING_OFF_KEY_PREFIX . date('YmdHi', $goodsRunningOffJson['time']);
  1752. $goodsRunningOffJson['time'] = strtotime($params['goods_off_addtimes']);
  1753. $data['goods_running_off_json'] = json_encode($goodsRunningOffJson);
  1754. // 有老的下架时间,删除老的
  1755. $redis->srem($oldKey, $params['goods_id']);
  1756. } else {
  1757. $goodsRunningOffJson['time'] = strtotime($params['goods_off_addtimes']);
  1758. $data['goods_running_off_json'] = json_encode($goodsRunningOffJson);
  1759. }
  1760. } else {
  1761. $data['goods_running_off_json'] = json_encode(['time' => strtotime($params['goods_off_addtimes'])]);
  1762. }
  1763. // 加入自动下架
  1764. $newKey = Goods::LISTING_OFF_KEY_PREFIX . date('YmdHi', strtotime($params['goods_off_addtimes']));
  1765. $redis->sAdd($newKey, $params['goods_id']);
  1766. } 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') {
  1767. $goodsRunningOffJson = json_decode($detail->goods_running_off_json, true);
  1768. if (isset($goodsRunningOffJson['time'])) {
  1769. $oldKey = Goods::LISTING_OFF_KEY_PREFIX . date('YmdHi', $goodsRunningOffJson['time']);
  1770. $redis = Redis::connection();
  1771. $redis->srem($oldKey, $params['goods_id']);
  1772. }
  1773. }
  1774. if ($detail) {
  1775. self::doUpdate($detail->join_running_goods_id, $data, new GoodsRunning());
  1776. } else {
  1777. // 兼容老数据……
  1778. $data['join_running_goods_id'] = $params['goods_id'];
  1779. GoodsRunning::insert($data);
  1780. }
  1781. } catch (BusinessException $e) {
  1782. throw new BusinessException($e->getMessage());
  1783. } catch (\Exception $e) {
  1784. dump($e->getMessage());
  1785. throw new BusinessException('数据更新异常~');
  1786. }
  1787. }
  1788. /**
  1789. * @Desc sku 设置
  1790. * @Author Gorden
  1791. * @Date 2024/4/10 10:43
  1792. *
  1793. * @param $params
  1794. * @return void
  1795. * @throws BusinessException
  1796. */
  1797. public static function goodsSkuSet($params, $operation = 'insert')
  1798. {
  1799. try {
  1800. Db::beginTransaction();
  1801. $skusOldIds = [];
  1802. if ($operation == 'update') {
  1803. // 查出所有的
  1804. $skusOldIds = GoodsSku::where('join_sku_goods_id', $params['goods_id'])->pluck('goods_sku_id', 'goods_sku_id');
  1805. // 删掉原有的
  1806. // GoodsSku::where('join_sku_goods_id', $params['goods_id'])->delete();
  1807. }
  1808. if (empty($skusOldIds) && empty($params['goods_sku_json_value'])) {
  1809. $skuData = [
  1810. 'join_sku_goods_id' => $params['goods_id'],
  1811. 'goods_sku_status' => 'ON',
  1812. 'goods_sku_specs_json' => '{"规格": "标准"}',
  1813. 'goods_sku_title' => "标准" . $params['goods_name'],
  1814. 'goods_sku_market_price' => $params['goods_market_price'] ?? 0,
  1815. 'goods_sku_sales_price' => $params['goods_sales_price'] ?? 0,
  1816. ];
  1817. GoodsSku::insert($skuData);
  1818. }
  1819. // 入新的
  1820. if (!empty($params['goods_sku_json_value'])) {
  1821. foreach ($params['goods_sku_json_value'] as $item) {
  1822. $skus = explode(',', $item['sku']);
  1823. $skuArr = [];
  1824. for ($i = 1; $i <= count($skus); $i++) {
  1825. $skuName = "skuName" . $i;
  1826. $key = $item[$skuName];
  1827. $skuArr[$key] = $skus[$i - 1];
  1828. }
  1829. $specsJson = json_encode($skuArr);
  1830. $skuTitle = str_replace('-', ',', $item['sku']) . $params['goods_name'];
  1831. if ($operation == 'update' && !empty($item['sku_id'])) {
  1832. $model = GoodsSku::where('goods_sku_id', $item['sku_id'])->where('goods_sku_status','ON')->first();
  1833. if (!$model) {
  1834. $model = new GoodsSku();
  1835. } else {
  1836. unset($skusOldIds[$model->goods_sku_id]);
  1837. }
  1838. } else {
  1839. $model = GoodsSku::where('join_sku_goods_id', $params['goods_id'])->where('goods_sku_status','ON')->where('goods_sku_title', $skuTitle)->first();
  1840. if (!$model) {
  1841. $model = new GoodsSku();
  1842. } else {
  1843. unset($skusOldIds[$model->goods_sku_id]);
  1844. }
  1845. }
  1846. $model->join_sku_goods_id = $params['goods_id'];
  1847. $model->goods_sku_status = $params['goods_status'];
  1848. $model->goods_sku_specs_json = $specsJson;
  1849. $model->goods_sku_title = $skuTitle;
  1850. $model->goods_sku_market_price = $params['goods_market_price'] ?? 0;
  1851. $model->goods_sku_sales_price = $item['price'];
  1852. $model->goods_sku_storage_json = json_encode(['storage' => $item['stock']]);
  1853. $model->save();
  1854. }
  1855. }
  1856. if ($operation == 'update' && !empty($skusOldIds)) {
  1857. // GoodsSku::whereIn('goods_sku_id', $skusOldIds)->delete();
  1858. GoodsSku::whereIn('goods_sku_id', $skusOldIds)->update(['goods_sku_status' => 'DISABLED']);
  1859. }
  1860. Db::commit();
  1861. } catch (\Exception $e) {
  1862. dump($e->getTrace());
  1863. Db::rollBack();
  1864. throw new BusinessException('规格数据更新异常~');
  1865. }
  1866. }
  1867. /**
  1868. * @Desc
  1869. * @Author Gorden
  1870. * @Date 2024/3/12 8:45
  1871. *
  1872. * @param array $data
  1873. * @param $model
  1874. * @return array
  1875. * @throws BusinessException
  1876. */
  1877. private static function inputFilter(array $data, $model): array
  1878. {
  1879. $table = config('database.connections.mysql.prefix') . $model->getTable();
  1880. $allow_column = $model->getConnection()->select("desc `$table`");
  1881. if (!$allow_column) {
  1882. throw new BusinessException('表不存在', 2);
  1883. }
  1884. $columns = array_column($allow_column, 'Type', 'Field');
  1885. foreach ($data as $col => $item) {
  1886. if (!isset($columns[$col])) {
  1887. unset($data[$col]);
  1888. continue;
  1889. }
  1890. // 非字符串类型传空则为null
  1891. if ($item === '' && strpos(strtolower($columns[$col]), 'varchar') === false && strpos(strtolower($columns[$col]), 'text') === false) {
  1892. $data[$col] = null;
  1893. }
  1894. if (is_array($item)) {
  1895. $data[$col] = implode(',', $item);
  1896. }
  1897. if ($item != '' && (strpos(strtolower($columns[$col]), 'varchar') || strpos(strtolower($columns[$col]), 'text'))) {
  1898. // $data[$col] = htmlspecialchars($item);
  1899. }
  1900. }
  1901. if (empty($data['created_at'])) {
  1902. unset($data['created_at']);
  1903. }
  1904. if (empty($data['updated_at'])) {
  1905. unset($data['updated_at']);
  1906. }
  1907. return $data;
  1908. }
  1909. /**
  1910. * @Desc 执行更新
  1911. * @Author Gorden
  1912. * @Date 2024/3/12 8:43
  1913. *
  1914. * @param $id
  1915. * @param $data
  1916. * @param $model
  1917. * @return void
  1918. */
  1919. private static function doUpdate($id, $data, $model)
  1920. {
  1921. $row = $model->find($id);
  1922. foreach ($data as $key => $val) {
  1923. $row->{$key} = $val;
  1924. }
  1925. $row->save();
  1926. }
  1927. /**
  1928. * @Desc 上架定时
  1929. * @Author Gorden
  1930. * @Date 2024/4/11 15:13
  1931. *
  1932. * @return void
  1933. */
  1934. public static function checkListing()
  1935. {
  1936. $key = Goods::LISTING_KEY_PREFIX . date('YmdHi');
  1937. $redis = Redis::connection();
  1938. if (!$redis->exists($key)) {
  1939. return;
  1940. }
  1941. $goodsIds = $redis->sMembers($key);
  1942. if (Goods::whereIn('goods_id', $goodsIds)->update(['goods_status' => 'ON'])) {
  1943. $redis->del($key);
  1944. }
  1945. }
  1946. /**
  1947. * @Desc 自动下架
  1948. * @Author Gorden
  1949. * @Date 2024/4/26 15:26
  1950. *
  1951. * @return void
  1952. */
  1953. public static function checkOffListing()
  1954. {
  1955. $key = Goods::LISTING_OFF_KEY_PREFIX . date('YmdHi');
  1956. $redis = Redis::connection();
  1957. if (!$redis->exists($key)) {
  1958. return;
  1959. }
  1960. $goodsIds = $redis->sMembers($key);
  1961. if (Goods::whereIn('goods_id', $goodsIds)->update(['goods_status' => 'OFF'])) {
  1962. $redis->del($key);
  1963. }
  1964. }
  1965. public static $week = [
  1966. '周一' => 1,
  1967. '周二' => 2,
  1968. '周三' => 3,
  1969. '周四' => 4,
  1970. '周五' => 5,
  1971. '周六' => 6,
  1972. '周日' => 7,
  1973. ];
  1974. }