浏览代码

搜索热词

fly 4 年之前
父节点
当前提交
d074524aff

+ 7 - 0
app/Http/Controllers/QuickApp/Book/BookController.php

@@ -7,6 +7,7 @@ use App\Modules\Book\Services\RecoBannerService;
 use Illuminate\Http\Request;
 use App\Http\Controllers\QuickApp\BaseController;
 use App\Http\Controllers\QuickApp\Book\Transformers\BookTransformer;
+use App\Http\Controllers\QuickApp\Book\Transformers\KeywordTransformer;
 use App\Modules\Book\Services\BookConfigService;
 use App\Modules\Book\Services\BookService;
 use App\Modules\Book\Services\BookUrgeUpdateService;
@@ -239,6 +240,12 @@ class BookController extends BaseController
         return response()->pagination(new BookTransformer, $books);
     }
 
+    public function hotWords(Request $request)
+    {
+        $result = BookConfigService::findBookKeywords();
+        return response()->pagination(new KeywordTransformer, $result);
+    }
+
     public function similarRecom(Request $request)
     {
         $category_id = $request->input('category_id');

+ 20 - 0
app/Http/Controllers/QuickApp/Book/Transformers/KeywordTransformer.php

@@ -0,0 +1,20 @@
+<?php
+
+/**
+ * Created by PhpStorm.
+ * Date: 2017/3/31
+ * Time: 14:02
+ */
+
+namespace App\Http\Controllers\QuickApp\Book\Transformers;
+
+class KeywordTransformer
+{
+    public function transform($item)
+    {
+        return [
+            'keyword' => $item->keyword,
+            'sequence' => $item->sequence,
+        ];
+    }
+}

+ 4 - 1
app/Http/Routes/QuickApp/QuickAppRoutes.php

@@ -25,13 +25,16 @@ Route::group(['domain' => env('QUICKAPP_DOMAIN'), 'namespace' => 'App\Http\Contr
 
         // 书库
         Route::get('books/library', 'Book\BookController@library');
+        
+        //热词
+        Route::get('books/hotwords', 'Book\BookController@hotWords');
 
         // 分类列表
         Route::get('books/getCategory', 'Book\BookCategoryController@getCategory');
 
         // 相似推荐
         Route::get('books/similar', 'Book\BookController@similarRecom');
-        
+
         //排行榜
         Route::get('books/rank', 'Book\BookController@rank');
     });

+ 15 - 0
app/Modules/Book/Models/BookKeyword.php

@@ -0,0 +1,15 @@
+<?php
+
+namespace App\Modules\Book\Models;
+
+use Illuminate\Database\Eloquent\Model;
+
+class BookKeyword extends Model
+{
+    protected $table = 'book_keywords';
+    protected $fillable = [
+        'keyword',
+        'status',
+        'sequence',
+    ];
+}

+ 101 - 85
app/Modules/Book/Services/BookConfigService.php

@@ -1,4 +1,5 @@
 <?php
+
 /**
  * Created by PhpStorm.
  * User: tandunzhao
@@ -12,6 +13,7 @@ namespace App\Modules\Book\Services;
 use App\Modules\Book\Models\BookConfig;
 use App\Modules\Product\Services\ProductService;
 use App\Modules\Book\Models\Book;
+use App\Modules\Book\Models\BookKeyword;
 use Redis;
 use DB;
 
@@ -38,7 +40,7 @@ class BookConfigService
      */
     public static function getBooksByIds(array $where, $order = [])
     {
-        if(empty($where)){
+        if (empty($where)) {
             return (object)array();
         }
         if ($order)
@@ -78,7 +80,7 @@ class BookConfigService
      * @param array $where
      * @param array $data
      */
-    public static function getPromotionBooksV2(array $where, array $whereIn, array $data, array $orwhereIn,$whereDeedIn='',$superior_lib='',$keywords='')
+    public static function getPromotionBooksV2(array $where, array $whereIn, array $data, array $orwhereIn, $whereDeedIn = '', $superior_lib = '', $keywords = '')
     {
         //全站派单
         $total_send_order_sum = '(select sum(num) as total_send_order_sum from book_send_order_stats where book_send_order_stats.bid=book_configs.bid) as total_send_order_sum';
@@ -94,43 +96,43 @@ class BookConfigService
         );
         //我的派单数
         $res = BookConfig::join('books', 'book_configs.bid', '=', 'Books.id')
-            ->leftjoin('chapters','books.first_cid','=','chapters.id')
+            ->leftjoin('chapters', 'books.first_cid', '=', 'chapters.id')
             ->leftjoin('book_categories', 'book_categories.id', 'books.category_id')
             ->leftjoin('book_channel_scores', function ($join) use ($data) {
                 $join->where('book_channel_scores.distribution_channel_id', '=', $data['distribution_channel_id'])
                     ->on('book_channel_scores.bid', '=', 'book_configs.bid');
             });
-        if($superior_lib){
-            $res->leftjoin($superior_lib,$superior_lib.'.bid','=','book_configs.bid');
+        if ($superior_lib) {
+            $res->leftjoin($superior_lib, $superior_lib . '.bid', '=', 'book_configs.bid');
         }
 
         $res->select(
-                'book_configs.book_name',
-                'book_configs.bid',
-                'book_categories.category_name',
-                'book_categories.channel_name',
-                'books.chapter_count',
-                'books.size',
-                'book_configs.cover',
-                'book_configs.charge_type',
-                'books.status',
-                'book_channel_scores.score as own_score',
-                'book_configs.recommend_index',
-                'book_configs.editor_recommend',
-                'book_configs.created_at',
-                'book_configs.editor_recommend',
-                DB::raw($total_send_order_sum),
-                DB::raw($week_send_orders),
-                DB::raw($channel_send_orders),
-                'books.first_cid',
-                'chapters.name as first_chapter_name',
-                'books.chapter_count'
+            'book_configs.book_name',
+            'book_configs.bid',
+            'book_categories.category_name',
+            'book_categories.channel_name',
+            'books.chapter_count',
+            'books.size',
+            'book_configs.cover',
+            'book_configs.charge_type',
+            'books.status',
+            'book_channel_scores.score as own_score',
+            'book_configs.recommend_index',
+            'book_configs.editor_recommend',
+            'book_configs.created_at',
+            'book_configs.editor_recommend',
+            DB::raw($total_send_order_sum),
+            DB::raw($week_send_orders),
+            DB::raw($channel_send_orders),
+            'books.first_cid',
+            'chapters.name as first_chapter_name',
+            'books.chapter_count'
         )->where($where);
         if ($whereIn) {
             $res->whereNotIn('book_configs.bid', $whereIn);
         }
-        if($whereDeedIn){
-            $res->whereIn('book_configs.bid',$whereDeedIn);
+        if ($whereDeedIn) {
+            $res->whereIn('book_configs.bid', $whereDeedIn);
         }
 
         $res->where(function ($query) use ($orwhereIn) {
@@ -143,11 +145,11 @@ class BookConfigService
         if ($keywords) {
             $res->where(function ($query) use ($keywords) {
                 $query->where('book_configs.book_name', 'like', '%' . $keywords . '%')
-                     ->orWhere([
-                         ['book_configs.roles','like','%'.$keywords.'%'],
-                         ['book_configs.is_on_shelf','=',2]
-                     ]);
-                    //->orWhere('book_configs.roles', 'like', '%' . $keywords . '%');
+                    ->orWhere([
+                        ['book_configs.roles', 'like', '%' . $keywords . '%'],
+                        ['book_configs.is_on_shelf', '=', 2]
+                    ]);
+                //->orWhere('book_configs.roles', 'like', '%' . $keywords . '%');
             });
         }
         /*if ($orwhere) {
@@ -159,22 +161,20 @@ class BookConfigService
             });
         }*/
         //\Log::info('books_list:books_data:'.json_encode($data));
-        if(in_array($data['order_field'],['total_send_order_sum','week_send_order_sum','order_index']))
-        {
+        if (in_array($data['order_field'], ['total_send_order_sum', 'week_send_order_sum', 'order_index'])) {
             //\Log::info('books_list:order_filed:'.$data['order_field']);
             return $res->orderBy($data['order_field'], $data['order_type'])
                 ->orderBy('recommend_index', 'desc')
                 ->orderBy('books.size', 'desc')
                 ->paginate();
-        }else{
+        } else {
             $res->orderBy($data['order_field'], $data['order_type']);
 
-            if($data['order_field']=='recommend_index'){
-                $res->orderBy('books.size','desc');
+            if ($data['order_field'] == 'recommend_index') {
+                $res->orderBy('books.size', 'desc');
             }
             return $res->paginate();
         }
-
     }
 
     /**
@@ -232,9 +232,9 @@ class BookConfigService
      * @param int $num
      * @return bool
      */
-    public static function getSimpleChannelBookLoop($bid, $num,$uid)
+    public static function getSimpleChannelBookLoop($bid, $num, $uid)
     {
-    	return BookConfig::getSimpleChannelBookLoop($bid, $num,$uid);
+        return BookConfig::getSimpleChannelBookLoop($bid, $num, $uid);
     }
 
     /**
@@ -327,7 +327,7 @@ class BookConfigService
 
     public static function getH5RecommendBooks($uid, $pos, $num)
     {
-    	return BookConfig::getH5RecommendBooks($uid, $pos, $num);
+        return BookConfig::getH5RecommendBooks($uid, $pos, $num);
     }
 
 
@@ -372,72 +372,88 @@ class BookConfigService
      * @param int $bid
      * @return mixed
      */
-    public static function getBookIntroByBid(int $bid ,string $book_name){
+    public static function getBookIntroByBid(int $bid, string $book_name)
+    {
         $where = [];
-        if($bid){
-            $where[] = ['book_configs.bid',$bid];
+        if ($bid) {
+            $where[] = ['book_configs.bid', $bid];
         }
-        if($book_name){
-            $where[] = ['book_configs.book_name','like','%'.$book_name.'%'];
+        if ($book_name) {
+            $where[] = ['book_configs.book_name', 'like', '%' . $book_name . '%'];
         }
-        if(empty($where)){
+        if (empty($where)) {
             return false;
         }
         return BookConfig::where($where)
-            ->join('books','book_configs.bid','=','books.id')
+            ->join('books', 'book_configs.bid', '=', 'books.id')
             ->select(
                 'books.intro',
-                DB::raw('concat(book_configs.book_name,"(",book_configs.bid,")") as book_name'))
+                DB::raw('concat(book_configs.book_name,"(",book_configs.bid,")") as book_name')
+            )
             ->get();
     }
 
-    public static function getBookByIdAndStatus($bid,$status){
-    	return BookConfig::getBookByIdAndStatus($bid,$status);
+    public static function getBookByIdAndStatus($bid, $status)
+    {
+        return BookConfig::getBookByIdAndStatus($bid, $status);
     }
-    public static function get_all_test_books($is_all){
-    	return BookConfig::get_all_test_books($is_all);
+    public static function get_all_test_books($is_all)
+    {
+        return BookConfig::get_all_test_books($is_all);
     }
-    public static function get_test_books($status){
-    	return BookConfig::get_test_books($status);
+    public static function get_test_books($status)
+    {
+        return BookConfig::get_test_books($status);
     }
-    public static function updateTestBook($bid, $status,$plan_push_user_num){
-    	return BookConfig::updateTestBook($bid, $status,$plan_push_user_num);
+    public static function updateTestBook($bid, $status, $plan_push_user_num)
+    {
+        return BookConfig::updateTestBook($bid, $status, $plan_push_user_num);
     }
-    public static function get_all_smart_push_books($is_all){
-    	return BookConfig::get_all_smart_push_books($is_all);
+    public static function get_all_smart_push_books($is_all)
+    {
+        return BookConfig::get_all_smart_push_books($is_all);
     }
 
-    public static function  getHotRandomRecommendBookText($distribution_channel_id,$uid, $num){
-    	return BookConfig::getHotRandomRecommendBookText($distribution_channel_id,$uid, $num);
+    public static function  getHotRandomRecommendBookText($distribution_channel_id, $uid, $num)
+    {
+        return BookConfig::getHotRandomRecommendBookText($distribution_channel_id, $uid, $num);
     }
 
-    public static function  resetBookLibRedis($category_type){
-    	$force_update = true;
-    	$is_high_quality = 1;
-    	$boy = '男频';
-    	$girl = '女频';
-    	\Log::info('resetBookLibRedis,category_type:'.$category_type);
-    	try{
-    		// 更新全库
-    		BookConfig::getLeftRecommendBook($boy, $is_high_quality,$force_update);
-    		BookConfig::getLeftRecommendBook($girl, $is_high_quality,$force_update);
-
-    	}catch(Exception $e){
-    		\Log::info('resetBookLibRedis_ept:'.$e->getMessage());
-    	}
-
+    public static function  resetBookLibRedis($category_type)
+    {
+        $force_update = true;
+        $is_high_quality = 1;
+        $boy = '男频';
+        $girl = '女频';
+        \Log::info('resetBookLibRedis,category_type:' . $category_type);
+        try {
+            // 更新全库
+            BookConfig::getLeftRecommendBook($boy, $is_high_quality, $force_update);
+            BookConfig::getLeftRecommendBook($girl, $is_high_quality, $force_update);
+        } catch (Exception $e) {
+            \Log::info('resetBookLibRedis_ept:' . $e->getMessage());
+        }
     }
 
     public static function getRandomOneHighQualityBook($sex)
     {
-       return BookConfig::join('books','books.id','=','book_configs.bid')
-           ->join('book_categories','books.category_id','=','book_categories.id')
-           ->select('books.intro','books.first_cid','book_configs.cover','book_configs.book_name','book_configs.bid')
-           ->where('book_configs.is_high_quality',1)
-           ->where('book_categories.pid',$sex)
-           ->orderBy('book_configs.bid')
-           ->get()
-           ->random(1)->first();
+        return BookConfig::join('books', 'books.id', '=', 'book_configs.bid')
+            ->join('book_categories', 'books.category_id', '=', 'book_categories.id')
+            ->select('books.intro', 'books.first_cid', 'book_configs.cover', 'book_configs.book_name', 'book_configs.bid')
+            ->where('book_configs.is_high_quality', 1)
+            ->where('book_categories.pid', $sex)
+            ->orderBy('book_configs.bid')
+            ->get()
+            ->random(1)->first();
     }
 
-}
+    public static function findBookKeywords(bool $is_all = false)
+    {
+        $sql = BookKeyword::where('status', 1)->orderBy('sequence');
+        if ($is_all) {
+            return $sql->get();
+        } else {
+            return $sql->paginate(10);
+        }
+    }
+}