Ver Fonte

快应用增加版权控制

wangzq há 2 anos atrás
pai
commit
cda2344395

+ 63 - 10
app/Http/Controllers/QuickApp/Book/BookController.php

@@ -9,6 +9,7 @@ use App\Modules\RecommendBook\Services\RecommendService;
 use App\Modules\Book\Services\RecoBannerService;
 use App\Modules\User\Models\QappPackage;
 use App\Modules\User\Services\QappUserService;
+use Hashids\Hashids;
 use Illuminate\Http\Request;
 use App\Http\Controllers\QuickApp\BaseController;
 use App\Http\Controllers\QuickApp\Book\Transformers\BookTransformer;
@@ -169,10 +170,10 @@ class BookController extends BaseController
         $package     = $request->header('x-package', '');
         $brand       = $request->header('x-nbrand', '');
         $codeVersion = $request->header('x-codeversion', '');
-
+        $isAuth = check_qapp_auth($package ,0);
         // 根据包名、平台、版本号判断是否审核
-        if (Utils::checkIsAudit($package, $brand, $codeVersion)) {
-            $result = BookAuditService::getHomeBooksData($sex, $package);
+        if (Utils::checkIsAudit($package, $brand, $codeVersion) && $isAuth === false) {
+            $result = BookAuditService::getHomeBooksData($sex, $package,$isAuth);
             return response()->success($result);
         }
 
@@ -183,7 +184,9 @@ class BookController extends BaseController
             $reco_banner_type = ['FEMALE', 'PUBLIC'];
             $channel          = 2;
         }
+
         $books = (new RecoBannerService)->getByType($reco_banner_type, 2);
+
         $books->transform(function ($item) {
             $result    = $this->getBidCidFromUrl($item->redirect_url);
             $item->bid = $result['bid'];
@@ -196,6 +199,7 @@ class BookController extends BaseController
             return $item;
         });
 
+
         //新判断: 根据包名来获取对应所需的bid
         $qapp_package = QappPackage::getPackageByPackage($package);
         if($qapp_package){
@@ -203,6 +207,20 @@ class BookController extends BaseController
         }else{
             $package_id = 0;
         }
+
+
+        if($isAuth == false  && !$books->isEmpty()){
+            // 未授权快应
+            $bookIds = array_column($books->toArray(),'bid');
+            $bookIds = BookConfigService::checkBookId($bookIds);
+            foreach ($books as &$value){
+                if (!in_array($value->bid,$bookIds)){
+                    $value->redirect_url = "#";
+                }
+            }
+            unset($value);
+        }
+
         \Log::info('un_send_order_book:package_id1:'.$package_id.' $package:'.$package);
         $user =  (new QappUserService)->getGolableUser();
         if(isset($user->uid) && !empty($user->uid)){
@@ -236,10 +254,11 @@ class BookController extends BaseController
      */
     private function getCheckBids($channel,$books,$package_id)
     {
-        $hotBids   = $this->getCheckBooks(QappRecommendService::getRecommendByPacketId($channel, 'hot',$package_id),$channel);
-        $liveBids  = $this->getCheckBooks(QappRecommendService::getRecommendByPacketId($channel, 'live',$package_id),$channel);
-        $recomBids = $this->getCheckBooks(QappRecommendService::getRecommendByPacketId($channel, 'recom',$package_id),$channel);
-        $newBids   = $this->getCheckBooks(QappRecommendService::getRecommendByPacketId($channel, 'new_recom',$package_id),$channel);
+        $isAuthor = check_qapp_auth($package_id,1);
+        $hotBids   = $this->getCheckBooks(QappRecommendService::getRecommendByPacketId($channel, 'hot',$package_id),$channel,$isAuthor);
+        $liveBids  = $this->getCheckBooks(QappRecommendService::getRecommendByPacketId($channel, 'live',$package_id),$channel,$isAuthor);
+        $recomBids = $this->getCheckBooks(QappRecommendService::getRecommendByPacketId($channel, 'recom',$package_id),$channel,$isAuthor);
+        $newBids   = $this->getCheckBooks(QappRecommendService::getRecommendByPacketId($channel, 'new_recom',$package_id),$channel,$isAuthor);
 
         return array_filter([
             ['type' => 'reco_banner', 'lable' => '首页banner', 'books' => $books],
@@ -257,10 +276,21 @@ class BookController extends BaseController
      * @param $channel : 频道
      * @return array
      */
-    private function getCheckBooks($bid_list,$channel)
+    private function getCheckBooks($bid_list,$channel,$is_author)
     {
+
         //获取书本数量
         $count = count($bid_list);
+        if (!$is_author){
+            $where = [
+                ['book_configs.charge_type','!=','BOOK'],
+                ['book_configs.cp_source','=','ycsd'],
+            ];
+        }else{
+            $where = [
+                ['book_configs.charge_type','!=','BOOK'],
+            ];
+        }
         //获取当前有效书本数量
         $book_count = BookConfig::join('books', 'book_configs.bid', '=', 'books.id')
             ->leftjoin('book_categories', 'books.category_id', 'book_categories.id')
@@ -268,8 +298,10 @@ class BookController extends BaseController
             ->where('book_configs.is_on_shelf',2)
             ->where('book_configs.charge_type','!=','BOOK')
             ->whereNotIn('book_configs.cp_source',getHiddenCp())
+            ->where($where)
             ->where('book_categories.pid',$channel)
             ->count();
+
         if($count == $book_count){
             return $bid_list;
         }
@@ -283,7 +315,7 @@ class BookController extends BaseController
             ->leftjoin('book_categories', 'books.category_id', 'book_categories.id')
             ->whereIn('book_configs.bid',$bid_list)
             ->where('book_configs.is_on_shelf',2)
-            ->where('book_configs.charge_type','!=','BOOK')
+            ->where($where)
             ->whereNotIn('book_configs.cp_source',getHiddenCp())
             ->where('book_categories.pid',$channel)
             ->pluck('book_configs.bid')->all();
@@ -293,7 +325,8 @@ class BookController extends BaseController
         $rand_bid = BookConfig::join('books', 'book_configs.bid', '=', 'books.id')
             ->leftjoin('book_categories', 'books.category_id', 'book_categories.id')
             ->where('book_configs.is_on_shelf',2)
-            ->where('book_configs.charge_type','!=','BOOK')
+            // ->where('book_configs.charge_type','!=','BOOK')
+            ->where($where)
             ->whereNotIn('book_configs.cp_source',getHiddenCp())
             ->where('book_categories.pid',$channel)
             ->inRandomOrder()
@@ -366,6 +399,12 @@ class BookController extends BaseController
             $order = ['book_configs.bid', 'desc'];
         }
 
+        // 是否只使用原创书殿的书
+        $isAuth = check_qapp_auth($package ,0);
+        if (!$isAuth){
+            $where['cp_source'] = "ycsd";
+        }
+
         $status = $request->input('status');
         if ($status != '') {
             $where['status'] = $status;
@@ -389,13 +428,18 @@ class BookController extends BaseController
 
     public function similarRecom(Request $request)
     {
+        $package     = $request->header('x-package', '');
         $category_id = $request->input('category_id');
         $bid         = $request->input('bid');
         if (empty($bid) || (empty($category_id) && $category_id != 0)) {
             return response()->error('PARAM_ERROR');
         }
+        $isAuth = check_qapp_auth($package ,0);
         $bid   = BookService::decodeBidStatic($bid);
         $where = ['category_id' => $category_id, 'is_on_shelf' => [2]];
+        if (!$isAuth){
+            $where['cp_source'] = "ycsd";
+        }
         $books = BookConfigService::getBooks($where, [], 4);
         $data  = [];
         foreach ($books as $v) {
@@ -466,6 +510,7 @@ class BookController extends BaseController
         $package     = $request->header('x-package', '');
         $brand       = $request->header('x-nbrand', '');
         $codeVersion = $request->header('x-codeversion', '');
+
         if (Utils::checkIsAudit($package, $brand, $codeVersion)) {
             $bids = [2266, 3838, 9700, 10175, 10301, 3422, 1166, 4546, 9163, 2509,
                 7287,14297,12716,14312,14000,13577,16712,13002,12717,15103,13928,
@@ -475,6 +520,14 @@ class BookController extends BaseController
                 $bids = [159, 2439, 6276, 10074, 5409, 9379, 10323, 9078, 3603, 487];
             }
         }
+        $isAuth = check_qapp_auth($package,0);
+        if (!$isAuth){
+            $rank = config('home.rank');
+            $bids = $rank['male'];
+            if ($sex === 2) {
+                $bids =  $rank['female'];;
+            }
+        }
 
         $books = collectionTransform(new BookTransformer, BookConfigService::getBooksByIds($bids));
         return response()->success($books);

+ 20 - 0
app/Libs/Helpers.php

@@ -814,4 +814,24 @@ function get_real_package($name)
             break;
     }
     return $package;
+}
+
+if (!function_exists("check_qapp_auth")){
+    function check_qapp_auth($package = "",$isPackageId = 0)
+    {
+        if (empty($package)){
+            return  false;
+        }
+
+        if ($isPackageId == 0){
+            $data = \DB::table('qapp_package_info')->where('package','=',$package)->value('cp_author_status');
+        }else{
+            $data = \DB::table('qapp_package_info')->where('id','=',$package)->value('cp_author_status');
+        }
+
+        if ($data == 1){
+            return  true;
+        }
+         return  false;
+    }
 }

+ 3 - 0
app/Modules/Book/Models/BookConfig.php

@@ -160,6 +160,9 @@ class BookConfig extends Model
 
                     $res->where('book_configs.is_current_week_promotion', $v);
                 }
+                if($key == "cp_source"){
+                    $res = $res->where('book_configs.cp_source', '=', $v);
+                }
             }
         }
         $res->whereNotIn('book_configs.cp_source',getHiddenCp());

+ 5 - 1
app/Modules/Book/Services/BookAuditService.php

@@ -14,7 +14,7 @@ class BookAuditService
      * @param $package
      * @return array[]
      */
-    public static function getHomeBooksData($sex, $package): array
+    public static function getHomeBooksData($sex, $package,$is_auth): array
     {
         // 基本配置数据
         $home = config('home.default');
@@ -22,6 +22,10 @@ class BookAuditService
             $home = config('home.new');
         }
 
+        if (!$is_auth){
+            $home = config('home.ycsd');
+        }
+
         // banner
         $banner      = $home['reco_banner'];
         $bannerBooks = $banner[$sex];

+ 8 - 0
app/Modules/Book/Services/BookConfigService.php

@@ -226,4 +226,12 @@ class BookConfigService
         return BookConfig::join('books','books.id','=','book_configs.bid')->
         whereIn('bid',$bids)->select($field)->get();
     }
+
+    // 获取原创书殿书籍id
+    public static function checkBookId($bookId = [])
+    {
+        $bookId = BookConfig::whereIn('bid',$bookId)->where('cp_source','=','ycsd')->pluck('bid');
+
+        return  $bookId->toArray();
+    }
 }

+ 49 - 2
config/home.php

@@ -48,7 +48,7 @@ return [
                 [
                     'redirect_url' => 'views/Detail',
                     'banner_url'   => 'https://cdn-novel.iycdm.com/h5/reco_banner/20200820145004ZQSS.jpg',
-                    'bid'          => 'dPwBa129vND4MRaNodKj7VobmzEO8YZ6', // 11601 最强杀手
+                    'bid'          => 'mqvQ0OXLZE2ba3KnY8RoDNzyJxMBrAVw', // 574 英雄联盟
                     'cid'          => 0
                 ],
             ],
@@ -81,5 +81,52 @@ return [
             'male'   => [12680, 12521, 11748, 12698, 12682, 13261],
             'female' => [11656, 13092, 11666, 2633, 6303, 12739],
         ],
-    ]
+    ],
+    'ycsd'     => [
+        'reco_banner' => [
+            'label'  => '首页banner',
+            'male'   => [
+                [
+                    'redirect_url' => 'views/Detail',
+                    'banner_url'   => 'https://cdn-novel.iycdm.com/h5/reco_banner/20200820145004ZQSS.jpg',
+                    'bid'          => 'dPwBa129vND4MRaNodKj7VobmzEO8YZ6', // 1890 美女总裁的全职保安
+                    'cid'          => 0
+                ],
+            ],
+            'female' => [
+                [
+                    'redirect_url' => 'views/Detail',
+                    'banner_url'   => 'https://cdn-novel.iycdm.com/h5/reco_banner/20200820145001JSWL.jpg',
+                    'bid'          => '2VkOMpjBem8ZNgrxqQKY7d9r5LE03Dwz', // 15720 黑夜见过他深情
+                    'cid'          => 0
+                ],
+            ],
+        ],
+        'hot'         => [
+            'label'  => '今日主推',
+            'male'   => [2951,3488,6033,8531,11045,11713],
+            'female' => [14620,58195,11680,59296,13082,11681],
+        ],
+        'zhibo'       => [
+            'label'  => '大家都在看',
+            'male'   => [13315,14286,14437,14445,14446,14454],
+            'female' => [58950,12331,59297,17055,15720,15537],
+        ],
+        'recom'       => [
+            'label'  => '主编精选',
+            'male'   => [14455,14464,14467,14468,14469,14470],
+            'female' => [11883,22394,12901,60902,11671,4112],
+        ],
+        'new_recom'   => [
+            'label'  => '畅销精品',
+            'male'   => [14472,14475,14478,14555,14614,14938],
+            'female' => [10846,60736,61425,10074,15216,60734],
+        ],
+    ],
+    'rank' =>[
+        'male'   => [15272,15323,15325,15327,15354,15370,15390,15391,15457,15458,15482,15528,15548,15550,15568,15579,15739,15758,15940,15956,16030,16077,16108,16353,17159,58984,59315,17,85,86,94,141,574],
+        'female' => [14163,17055,3697,59004,15720,13082,58950,60902,61012,7567,11671,15537,16133,16184,16220,22393,22394,22395,58329,58801,58864,59020,59295,59293,60238,60736,61425,59297,59579,59813],
+    ],
+
+
 ];