* @return JsonResponse */ public function index(): JsonResponse { $banners = Banner::query()->ofPosition(Banner::POSITION_INDEX)->get(); $centers = Banner::query()->ofPosition(Banner::POSITION_INDEX_CENTER)->get(); $show_goods_id = app('Conf_mall')['show_score_goods_id'] ?? 0; $show_goods = ''; if ($show_goods_id > 0) { $show_goods = Goods::find($show_goods_id); } $goods = Goods::query() // ->where('id', '<>', $show_goods_id) ->shown() ->where('channel', Goods::CHANNEL_SCORE) ->get(); $videos = Video::query() ->shown() ->get(); $memories = Article::query() ->whereHas('categories', function ($q) { $q->where('slug', 'MEMORY'); }) ->inRandomOrder() ->take(10) ->get(); $memoriesData = []; $all = $memories->count() * 30; foreach ($memories as $key => $memory) { $id = ++$key; $memoriesData[] = [ 'id' => $memory->id, 'title' => $memory->title, 'description' => $memory->description, 'zIndex' => $id, 'left' => (int) bcsub($all, bcmul($key, 30)), 'image' => $memory->cover_url, 'animation' => null, ]; } $healths = Article::query() ->whereHas('categories', function ($q) { $q->where('slug', 'HEALTH'); }) ->inRandomOrder() ->take(3) ->get(); $data = [ 'show_goods' => $show_goods ? new GoodsBaseResource($show_goods) : '', 'videos' => VideoResource::collection($videos), 'goods' => GoodsBaseResource::collection($goods), 'banners' => BannerResource::collection($banners), 'center' => BannerResource::collection($centers), 'memories' => $memoriesData, 'healths' => ArticleBaseResource::collection($healths), 'categories' => [ 'memory' => Category::query()->where('slug', 'MEMORY')->value('id') ?? 0, 'health' => Category::query()->where('slug', 'HEALTH')->value('id') ?? 0, ], ]; return $this->success($data); } }