with(compact('month')); } public function bookshow(Request $request) { $booklists = (new CrmBookAutoRecommendService)->getRecommendBooksFromRedis(); $book_models = collect($booklists)->groupBy('category_id') ->map(function ($item, $key) { $category = collect($item)->first(); $category_id = $category['category_id']; $category_name = $category['category_name']; $books = collect($item)->sortByDesc('recommend_index')->values()->transform(function ($item) { $item['star'] = intval(($item['recommend_index'] - 50) / 10); $item['link'] = sprintf( '%s://site%s.%s.com/detail?id=%s', env('PROTOCOL'), encodeDistributionChannelId($this->getUserColumnValue('channel_id')), env('CUSTOM_HOST'), Hashids::encode($item['bid']) ); return $item; })->take(4)->all(); return compact('category_id', 'category_name', 'books'); })->all(); $annually_monthly_user = new AnnuallyMonthlyUser(); $is_annually_monthly_user = $annually_monthly_user->is_monthly || $annually_monthly_user->is_annually; return view('crm.bookshow')->with(compact('book_models','is_annually_monthly_user')); } public function booklist(Request $request) { $month = date('n'); $category_id = $request->get('category_id', 0); $books = []; if ($category_id) { $booklists = (new CrmBookAutoRecommendService)->getRecommendBooksFromRedis(); $books = collect($booklists)->where('category_id', $category_id)->transform(function ($item) { $item['link'] = sprintf( '%s://site%s.%s.com/detail?id=%s', env('PROTOCOL'), encodeDistributionChannelId($this->getUserColumnValue('channel_id')), env('CUSTOM_HOST'), Hashids::encode($item['bid']) ); return $item; })->all(); } return view('crm.booklist', compact('books', 'month')); #->with(compact('books', 'month')); } private function getUserColumnValue(string $column) { $user = app()->make('user'); if ($user) { return $user->$column; } } }