fly před 5 roky
rodič
revize
0cc1e2bcbb

+ 21 - 26
app/Modules/Book/Services/CrmBookAutoRecommendService.php

@@ -85,9 +85,7 @@ class CrmBookAutoRecommendService
    {
       $value = Redis::get($this->redis_key);
       if ($value) {
-         $result =  json_decode($value, true);
-          if($result) return $result;
-          return  $this->setRecommendBooksRedis();
+         return json_decode($value, true);
       } else {
          return  $this->setRecommendBooksRedis();
       }
@@ -100,28 +98,25 @@ class CrmBookAutoRecommendService
    {
       $recommends = CrmBookAutoRecommend::where('week', $this->this_week)->get();
       $bids = $recommends->pluck('bid')->all();
-      if ($recommends) {
-         $configs = BookConfig::whereIn('bid', $bids)->select('bid', 'cover', 'recommend_index')->get();
-         $books = Book::whereIn('id', $bids)->select('id', 'status', 'intro', 'size', 'last_cid', 'last_chapter')->get();
-         $results = $recommends->map(function ($item) use ($books, $configs) {
-            $bid = $item->bid;
-            $name = $item->name;
-            $category_id = $item->category_id;
-            $category_name = $item->category_name;
-            $config = $configs->where('bid', $bid)->first();
-            $book =  $books->where('id', $bid)->first();
-            $cover = $config->cover;
-            $recommend_index = $config->recommend_index;
-            $intro = $book->intro;
-            $status = $book->status;
-            $size = $book->size;
-            $last_cid = $book->last_cid;
-            $last_chapter = $book->last_chapter;
-            $is_vip = 1;
-            return compact('bid', 'name', 'category_id', 'category_name', 'cover', 'recommend_index', 'status', 'intro', 'size', 'last_cid', 'last_chapter', 'is_vip');
-         })->all();
-         return $results;
-      }
-      return [];
+      $configs = BookConfig::whereIn('bid', $bids)->select('bid', 'cover', 'recommend_index')->get();
+      $books = Book::whereIn('id', $bids)->select('id', 'status', 'intro', 'size', 'last_cid', 'last_chapter')->get();
+      $results = $recommends->map(function ($item) use ($books, $configs) {
+         $bid = $item->bid;
+         $name = $item->name;
+         $category_id = $item->category_id;
+         $category_name = $item->category_name;
+         $config = $configs->where('bid', $bid)->first();
+         $book =  $books->where('id', $bid)->first();
+         $cover = $config->cover;
+         $recommend_index = $config->recommend_index;
+         $intro = $book->intro;
+         $status = $book->status;
+         $size = $book->size;
+         $last_cid = $book->last_cid;
+         $last_chapter = $book->last_chapter;
+         $is_vip = 1;
+         return compact('bid', 'name', 'category_id', 'category_name', 'cover', 'recommend_index', 'status', 'intro', 'size', 'last_cid', 'last_chapter', 'is_vip');
+      })->all();
+      return $results;
    }
 }