zhuchengjie 2 years ago
parent
commit
24db2d1191

+ 3 - 5
app/Http/Controllers/QuickApp/Book/BookController.php

@@ -683,7 +683,8 @@ class BookController extends BaseController
     public function recommend_books(Request $request)
     {
         $package = $request->header('x-package','');
-        $id = $request->get('id',0);
+        $bid = $request->get('bid',0);
+        $priority = $request->get('priority',0);
         if(empty($package)){
             return response()->success([]);
         }
@@ -706,11 +707,8 @@ class BookController extends BaseController
             return response()->success([]);
         }
 
-        $list = ChannelRecommendBooksService::getRecommendBooks($package_info->channel_id,$id);
-        \Log::info($list);
+        $list = ChannelRecommendBooksService::getRecommendBooks($package_info->channel_id,$bid,$priority);
         foreach($list as $item){
-            \Log::info($item);
-
             $this->incrRecommendNum($package_info->channel_id,$item['bid']);
         }
 

+ 4 - 4
app/Modules/Channel/Services/ChannelRecommendBooksService.php

@@ -9,7 +9,7 @@ use App\Modules\Channel\Models\ChannelRecommendBooks;
 class ChannelRecommendBooksService
 {
 
-    static function getRecommendBooks($channel_id,$id,$limit = 3,$data = [])
+    static function getRecommendBooks($channel_id,$bid,$priority,$limit = 3,$data = [])
     {
         if(!isset($channel_id)) return [];
         $query = ChannelRecommendBooks::leftjoin('book_configs','book_configs.bid','channel_recommend_books.bid')
@@ -19,15 +19,15 @@ class ChannelRecommendBooksService
 
         $query->where('channel_recommend_books.channel_id',$channel_id);
 
-        if(!empty($id) && $id != 0){
-            $query->where('channel_recommend_books.id','<',$id);
+        if(!empty($priority) && $priority != 0){
+            $query->where('channel_recommend_books.id','<=',$priority)->where('bid','!=',$bid);
         }
 
         $list = $query->limit($limit)->get()->toArray();
         $lists = array_merge($list,$data);
         if(count($lists) < 3){
             $count = 3 - count($lists);
-            self::getRecommendBooks($channel_id,0,$count,$lists);
+            self::getRecommendBooks($channel_id,$bid,0,$count,$lists);
         }else{
             return $lists;
         }