params = $params; } public function handle() { $video_ids = $this->params['video_ids']; try { $cache = make(CacheInterface::class); $video_ads = make(VideoService::class)->getAdList('video_home'); for ($i=1; $i<= 20; $i++) { if ($cache->has('video:home:' . $i)) { $cache->delete('video:home:' . $i); } $cache->rememberForever( 'video:home:' . $i, function () use ($video_ads, $i, $video_ids) { //$start= ($i - 1) * 5; //$video_ids = array_slice($video_ids, $start, 5); $video_data = []; $result = VideoModel::query() ->select(['id','title', 'cover', 'smu', 'like', 'uid', 'from']) ->with(['category:type.id as type_id,type.title','user']) ->where('status', 1) ->whereIn('id', $video_ids) ->inRandomOrder() ->get()->toArray(); foreach ($result as $k => $v) { // $result[$k]['smu'] = make(VideoService::class) // ->getPlayUrl($result[$k]['from'], $result[$k]['smu']); // $result[$k]['user']['avatar'] = make(CommonService::class) // ->getImageUrl($result[$k]['user']['avatar']); foreach ($result[$k]['category'] as $ck => $t) { unset($result[$k]['category'][$ck]['pivot']); } } foreach ($result as $k => $v) { $video_data[$k] = [ 'type' => 'v', 'video' => $v, ]; } if ($video_ads) { $video_ad = collect($video_ads) ->random(1) ->first(); $video_data[count($video_data)] = [ 'type' => 'a', 'ad' => $video_ad, ]; } unset($result); return $video_data; } ); } } catch (\Exception $exception) { logger('AddHomeJob', [$exception->getMessage()]); } } }