NewCustomerService.php 93 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119
  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 NewCustomerService
  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->updator_user_id = JwtToken::getCurrentId();
  1648. $row->save();
  1649. } catch (BusinessException $e) {
  1650. throw new BusinessException($e->getMessage());
  1651. } catch (\Exception $e) {
  1652. dump($e->getTrace());
  1653. throw new BusinessException('数据更新异常~1');
  1654. }
  1655. }
  1656. /**
  1657. * @Desc
  1658. * @Author Gorden
  1659. * @Date 2024/3/12 9:57
  1660. *
  1661. * @param $params
  1662. * @return void
  1663. * @throws BusinessException
  1664. */
  1665. public static function detailUpdate($params)
  1666. {
  1667. try {
  1668. $data = self::inputFilter($params, new GoodsDetail());
  1669. if (!empty($data['goods_detail_slider_json'])) {
  1670. $data['goods_detail_slider_json'] = str_replace(getenv('STORAGE_DOMAIN'), '', $data['goods_detail_slider_json']);
  1671. $data['goods_detail_slider_json'] = json_encode(['slider' => $data['goods_detail_slider_json']]);
  1672. }
  1673. if (isset($params['curriculum'])) {
  1674. $data['goods_detail_specs_json'] = json_encode([
  1675. [
  1676. 'key' => '课时',
  1677. 'val' => $params['curriculum']['period'] ?? '',
  1678. ],
  1679. [
  1680. 'key' => '群体',
  1681. 'val' => $params['curriculum']['group'] ?? '',
  1682. ],
  1683. [
  1684. 'key' => '课程',
  1685. 'val' => $params['curriculum']['course'] ?? '',
  1686. ],
  1687. ]);
  1688. }
  1689. // 根据goods_id 查详情ID
  1690. $detail = GoodsDetail::where('join_detail_goods_id', $params['goods_id'])->first();
  1691. if ($detail) {
  1692. self::doUpdate($detail->join_detail_goods_id, $data, new GoodsDetail());
  1693. } else {
  1694. $data['join_detail_goods_id'] = $params['goods_id'];
  1695. GoodsDetail::insert($data);
  1696. }
  1697. } catch (BusinessException $e) {
  1698. throw new BusinessException($e->getMessage());
  1699. } catch (\Exception $e) {
  1700. dump($e->getMessage());
  1701. throw new BusinessException('轮播图/详情数据更新异常~');
  1702. }
  1703. }
  1704. /**
  1705. * @Desc
  1706. * @Author Gorden
  1707. * @Date 2024/3/12 9:58
  1708. *
  1709. * @param $params
  1710. * @return void
  1711. * @throws BusinessException
  1712. */
  1713. public static function labelUpdate($params)
  1714. {
  1715. try {
  1716. $data = self::inputFilter($params, new GoodsLabel());
  1717. // 根据goods_id 查详情ID
  1718. $detail = GoodsLabel::where('join_label_goods_id', $params['goods_id'])->first();
  1719. if ($detail) {
  1720. self::doUpdate($detail->goods_label_id, $data, new GoodsLabel());
  1721. } else {
  1722. $data['join_label_goods_id'] = $params['goods_id'];
  1723. GoodsLabel::insert($data);
  1724. }
  1725. } catch (BusinessException $e) {
  1726. throw new BusinessException($e->getMessage());
  1727. } catch (\Exception $e) {
  1728. dump($e->getMessage());
  1729. throw new BusinessException('数据更新异常~3');
  1730. }
  1731. }
  1732. /**
  1733. * @Desc
  1734. * @Author Gorden
  1735. * @Date 2024/3/12 9:59
  1736. *
  1737. * @param $params
  1738. * @return void
  1739. * @throws BusinessException
  1740. */
  1741. public static function goodsRunningUpdate($params)
  1742. {
  1743. try {
  1744. $data = self::inputFilter($params, new GoodsRunning());
  1745. // 根据goods_id 查详情ID
  1746. $detail = GoodsRunning::where('join_running_goods_id', $params['goods_id'])->first();
  1747. if (!empty($params['goods_running_off_type']) && $params['goods_running_off_type'] == 'T') {
  1748. $redis = Redis::connection();
  1749. if (!empty($detail->goods_running_off_json)) {
  1750. $goodsRunningOffJson = json_decode($detail->goods_running_off_json, true);
  1751. if (isset($goodsRunningOffJson['time'])) {
  1752. $oldKey = Goods::LISTING_OFF_KEY_PREFIX . date('YmdHi', $goodsRunningOffJson['time']);
  1753. $goodsRunningOffJson['time'] = strtotime($params['goods_off_addtimes']);
  1754. $data['goods_running_off_json'] = json_encode($goodsRunningOffJson);
  1755. // 有老的下架时间,删除老的
  1756. $redis->srem($oldKey, $params['goods_id']);
  1757. } else {
  1758. $goodsRunningOffJson['time'] = strtotime($params['goods_off_addtimes']);
  1759. $data['goods_running_off_json'] = json_encode($goodsRunningOffJson);
  1760. }
  1761. } else {
  1762. $data['goods_running_off_json'] = json_encode(['time' => strtotime($params['goods_off_addtimes'])]);
  1763. }
  1764. // 加入自动下架
  1765. $newKey = Goods::LISTING_OFF_KEY_PREFIX . date('YmdHi', strtotime($params['goods_off_addtimes']));
  1766. $redis->sAdd($newKey, $params['goods_id']);
  1767. } 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') {
  1768. $goodsRunningOffJson = json_decode($detail->goods_running_off_json, true);
  1769. if (isset($goodsRunningOffJson['time'])) {
  1770. $oldKey = Goods::LISTING_OFF_KEY_PREFIX . date('YmdHi', $goodsRunningOffJson['time']);
  1771. $redis = Redis::connection();
  1772. $redis->srem($oldKey, $params['goods_id']);
  1773. }
  1774. }
  1775. if ($detail) {
  1776. self::doUpdate($detail->join_running_goods_id, $data, new GoodsRunning());
  1777. } else {
  1778. // 兼容老数据……
  1779. $data['join_running_goods_id'] = $params['goods_id'];
  1780. GoodsRunning::insert($data);
  1781. }
  1782. } catch (BusinessException $e) {
  1783. throw new BusinessException($e->getMessage());
  1784. } catch (\Exception $e) {
  1785. dump($e->getMessage());
  1786. throw new BusinessException('数据更新异常~');
  1787. }
  1788. }
  1789. /**
  1790. * @Desc sku 设置
  1791. * @Author Gorden
  1792. * @Date 2024/4/10 10:43
  1793. *
  1794. * @param $params
  1795. * @return void
  1796. * @throws BusinessException
  1797. */
  1798. public static function goodsSkuSet($params, $operation = 'insert')
  1799. {
  1800. try {
  1801. Db::beginTransaction();
  1802. $skusOldIds = [];
  1803. if ($operation == 'update') {
  1804. // 查出所有的
  1805. $skusOldIds = GoodsSku::where('join_sku_goods_id', $params['goods_id'])->pluck('goods_sku_id', 'goods_sku_id');
  1806. // 删掉原有的
  1807. // GoodsSku::where('join_sku_goods_id', $params['goods_id'])->delete();
  1808. }
  1809. if (empty($skusOldIds) && empty($params['goods_sku_json_value'])) {
  1810. $skuData = [
  1811. 'join_sku_goods_id' => $params['goods_id'],
  1812. 'goods_sku_status' => 'ON',
  1813. 'goods_sku_specs_json' => '{"规格": "标准"}',
  1814. 'goods_sku_title' => "标准" . $params['goods_name'],
  1815. 'goods_sku_market_price' => $params['goods_market_price'] ?? 0,
  1816. 'goods_sku_sales_price' => $params['goods_sales_price'] ?? 0,
  1817. ];
  1818. GoodsSku::insert($skuData);
  1819. }
  1820. // 入新的
  1821. if (!empty($params['goods_sku_json_value'])) {
  1822. foreach ($params['goods_sku_json_value'] as $item) {
  1823. $skus = explode(',', $item['sku']);
  1824. $skuArr = [];
  1825. for ($i = 1; $i <= count($skus); $i++) {
  1826. $skuName = "skuName" . $i;
  1827. $key = $item[$skuName];
  1828. $skuArr[$key] = $skus[$i - 1];
  1829. }
  1830. $specsJson = json_encode($skuArr);
  1831. $skuTitle = str_replace('-', ',', $item['sku']) . $params['goods_name'];
  1832. if ($operation == 'update' && !empty($item['sku_id'])) {
  1833. $model = GoodsSku::where('goods_sku_id', $item['sku_id'])->where('goods_sku_status','ON')->first();
  1834. if (!$model) {
  1835. $model = new GoodsSku();
  1836. } else {
  1837. unset($skusOldIds[$model->goods_sku_id]);
  1838. }
  1839. } else {
  1840. $model = GoodsSku::where('join_sku_goods_id', $params['goods_id'])->where('goods_sku_status','ON')->where('goods_sku_title', $skuTitle)->first();
  1841. if (!$model) {
  1842. $model = new GoodsSku();
  1843. } else {
  1844. unset($skusOldIds[$model->goods_sku_id]);
  1845. }
  1846. }
  1847. $model->join_sku_goods_id = $params['goods_id'];
  1848. $model->goods_sku_status = $params['goods_status'];
  1849. $model->goods_sku_specs_json = $specsJson;
  1850. $model->goods_sku_title = $skuTitle;
  1851. $model->goods_sku_market_price = $params['goods_market_price'] ?? 0;
  1852. $model->goods_sku_sales_price = $item['price'];
  1853. $model->goods_sku_storage_json = json_encode(['storage' => $item['stock']]);
  1854. $model->save();
  1855. }
  1856. }
  1857. if ($operation == 'update' && !empty($skusOldIds)) {
  1858. // GoodsSku::whereIn('goods_sku_id', $skusOldIds)->delete();
  1859. GoodsSku::whereIn('goods_sku_id', $skusOldIds)->update(['goods_sku_status' => 'DISABLED']);
  1860. }
  1861. Db::commit();
  1862. } catch (\Exception $e) {
  1863. dump($e->getTrace());
  1864. Db::rollBack();
  1865. throw new BusinessException('规格数据更新异常~');
  1866. }
  1867. }
  1868. /**
  1869. * @Desc
  1870. * @Author Gorden
  1871. * @Date 2024/3/12 8:45
  1872. *
  1873. * @param array $data
  1874. * @param $model
  1875. * @return array
  1876. * @throws BusinessException
  1877. */
  1878. private static function inputFilter(array $data, $model): array
  1879. {
  1880. $table = config('database.connections.mysql.prefix') . $model->getTable();
  1881. $allow_column = $model->getConnection()->select("desc `$table`");
  1882. if (!$allow_column) {
  1883. throw new BusinessException('表不存在', 2);
  1884. }
  1885. $columns = array_column($allow_column, 'Type', 'Field');
  1886. foreach ($data as $col => $item) {
  1887. if (!isset($columns[$col])) {
  1888. unset($data[$col]);
  1889. continue;
  1890. }
  1891. // 非字符串类型传空则为null
  1892. if ($item === '' && strpos(strtolower($columns[$col]), 'varchar') === false && strpos(strtolower($columns[$col]), 'text') === false) {
  1893. $data[$col] = null;
  1894. }
  1895. if (is_array($item)) {
  1896. $data[$col] = implode(',', $item);
  1897. }
  1898. if ($item != '' && (strpos(strtolower($columns[$col]), 'varchar') || strpos(strtolower($columns[$col]), 'text'))) {
  1899. // $data[$col] = htmlspecialchars($item);
  1900. }
  1901. }
  1902. if (empty($data['created_at'])) {
  1903. unset($data['created_at']);
  1904. }
  1905. if (empty($data['updated_at'])) {
  1906. unset($data['updated_at']);
  1907. }
  1908. return $data;
  1909. }
  1910. /**
  1911. * @Desc 执行更新
  1912. * @Author Gorden
  1913. * @Date 2024/3/12 8:43
  1914. *
  1915. * @param $id
  1916. * @param $data
  1917. * @param $model
  1918. * @return void
  1919. */
  1920. private static function doUpdate($id, $data, $model)
  1921. {
  1922. $row = $model->find($id);
  1923. foreach ($data as $key => $val) {
  1924. $row->{$key} = $val;
  1925. }
  1926. $row->save();
  1927. }
  1928. /**
  1929. * @Desc 上架定时
  1930. * @Author Gorden
  1931. * @Date 2024/4/11 15:13
  1932. *
  1933. * @return void
  1934. */
  1935. public static function checkListing()
  1936. {
  1937. $key = Goods::LISTING_KEY_PREFIX . date('YmdHi');
  1938. $redis = Redis::connection();
  1939. if (!$redis->exists($key)) {
  1940. return;
  1941. }
  1942. $goodsIds = $redis->sMembers($key);
  1943. if (Goods::whereIn('goods_id', $goodsIds)->update(['goods_status' => 'ON'])) {
  1944. $redis->del($key);
  1945. }
  1946. }
  1947. /**
  1948. * @Desc 自动下架
  1949. * @Author Gorden
  1950. * @Date 2024/4/26 15:26
  1951. *
  1952. * @return void
  1953. */
  1954. public static function checkOffListing()
  1955. {
  1956. $key = Goods::LISTING_OFF_KEY_PREFIX . date('YmdHi');
  1957. $redis = Redis::connection();
  1958. if (!$redis->exists($key)) {
  1959. return;
  1960. }
  1961. $goodsIds = $redis->sMembers($key);
  1962. if (Goods::whereIn('goods_id', $goodsIds)->update(['goods_status' => 'OFF'])) {
  1963. $redis->del($key);
  1964. }
  1965. }
  1966. public static $week = [
  1967. '周一' => 1,
  1968. '周二' => 2,
  1969. '周三' => 3,
  1970. '周四' => 4,
  1971. '周五' => 5,
  1972. '周六' => 6,
  1973. '周日' => 7,
  1974. ];
  1975. }