Wang Chen 4 年之前
父節點
當前提交
e46914e089

+ 43 - 0
app/Console/Commands/Test.php

@@ -0,0 +1,43 @@
+<?php
+
+
+namespace App\Console\Commands;
+
+
+use App\Libs\Utils;
+use Hashids;
+use Illuminate\Console\Command;
+
+class Test extends Command
+{
+    /**
+     * The name and signature of the console command.
+     *
+     * @var string
+     */
+    protected $signature = 'test {bid}';
+
+    /**
+     * The console command description.
+     *
+     * @var string
+     */
+    protected $description = '测试';
+
+    /**
+     * Execute the console command.
+     *
+     * @return mixed
+     */
+    public function handle()
+    {
+        $bid   = $this->argument('bid');
+        $enBid = Hashids::encode($bid);
+
+        $enHotBids = array_map(function ($bid) {
+            return Utils::getEncodeId($bid);
+        }, [$bid]);
+
+        dd($bid, $enBid, $enHotBids);
+    }
+}

+ 1 - 0
app/Console/Kernel.php

@@ -37,6 +37,7 @@ class Kernel extends ConsoleKernel
         Commands\updateFromNewYunqi::class,
         Commands\CheckOrderStatus::class,
         Commands\NewVersionPrepare::class,
+        Commands\Test::class,
     ];
 
     /**

+ 56 - 43
app/Http/Controllers/QuickApp/Book/BookController.php

@@ -2,6 +2,8 @@
 
 namespace App\Http\Controllers\QuickApp\Book;
 
+use App\Libs\Utils;
+use App\Modules\Book\Services\BookAuditService;
 use App\Modules\RecommendBook\Services\RecommendService;
 use App\Modules\Book\Services\RecoBannerService;
 use Illuminate\Http\Request;
@@ -22,7 +24,7 @@ class BookController extends BaseController
 {
     public function index(Request $request, $bid)
     {
-        $bid = BookService::decodeBidStatic($bid);
+        $bid       = BookService::decodeBidStatic($bid);
         $book_info = BookConfigService::getBookById($bid);
         if (!$book_info) {
             return response()->error('QAPP_SYS_ERROR');
@@ -30,18 +32,18 @@ class BookController extends BaseController
         if (!in_array($book_info->is_on_shelf, [2])) {
             return response()->error('QAPP_OFF_SHELF');
         }
-        $is_on_shelf = UserShelfBooksService::getUserShelfBooksListByUidAndBid($this->uid, $bid);
+        $is_on_shelf                   = UserShelfBooksService::getUserShelfBooksListByUidAndBid($this->uid, $bid);
         $book_info['is_on_user_shelf'] = 0;
 
         if ($is_on_shelf) {
             $book_info['is_on_user_shelf'] = 1;
         }
-        $last_chapter = ChapterService::getChapterNameById($book_info['last_cid'], $bid);
+        $last_chapter                     = ChapterService::getChapterNameById($book_info['last_cid'], $bid);
         $book_info['last_chapter_is_vip'] = $last_chapter['is_vip'];
-        $book_info['is_need_charge'] = $this->isNeedCharge($bid, $last_chapter, $book_info);
-        $record = ReadRecordService::getBookReadRecordStatic($this->uid, $bid);
+        $book_info['is_need_charge']      = $this->isNeedCharge($bid, $last_chapter, $book_info);
+        $record                           = ReadRecordService::getBookReadRecordStatic($this->uid, $bid);
         if ($record) {
-            $book_info['record_chapter_id'] = $record['record_chapter_id'];
+            $book_info['record_chapter_id']   = $record['record_chapter_id'];
             $book_info['record_chapter_name'] = $record['record_chapter_name'];
         }
         return response()->item(new BookTransformer(), $book_info);
@@ -69,7 +71,7 @@ class BookController extends BaseController
         //章节订购记录
         $chapterOrder = new ChapterOrderService();
 
-        if ($chapterOrder->checkIsOrdered($uid, $bid, $chapter_id))  return true;
+        if ($chapterOrder->checkIsOrdered($uid, $bid, $chapter_id)) return true;
 
         return false;
     }
@@ -114,7 +116,7 @@ class BookController extends BaseController
                 return $this->isBookNeedCharge($bid, $price);
             default:
                 $price = $last_chapter->is_vip ? $this->getPrice($book_info, $last_chapter->size) : 0;
-                return  $last_chapter->is_vip ? $this->isChapterNeedCharge($bid, $last_chapter->id, $price) : false;
+                return $last_chapter->is_vip ? $this->isChapterNeedCharge($bid, $last_chapter->id, $price) : false;
         }
     }
 
@@ -128,7 +130,7 @@ class BookController extends BaseController
     {
         if ($book_info->charge_type == 'BOOK')
             return $book_info->price * 100;
-        return   ceil($chapter_size / 100);
+        return ceil($chapter_size / 100);
     }
 
     /**
@@ -136,17 +138,27 @@ class BookController extends BaseController
      */
     public function getBookLists(Request $request, $sex)
     {
+        // 获取基本数据
+        $package     = $request->header('x-package', '');
+        $brand       = strtolower($request->header('x-nbrand', ''));
+        $codeVersion = $request->header('x-codeversion', '');
+
+        // 根据包名、平台、版本号判断是否审核
+        if (Utils::checkIsAudit($package, $brand, $codeVersion)) {
+            $result = BookAuditService::getHomeBooksData($sex);
+            return response()->success($result);
+        }
 
         if ($sex == 'male') {
-            $channel = 1;
+            $channel          = 1;
             $reco_banner_type = ['MALE', 'PUBLIC'];
         } else {
             $reco_banner_type = ['FEMALE', 'PUBLIC'];
-            $channel = 2;
+            $channel          = 2;
         }
         $books = (new RecoBannerService)->getByType($reco_banner_type, 2);
         $books->transform(function ($item) {
-            $result = $this->getBidCidFromUrl($item->redirect_url);
+            $result    = $this->getBidCidFromUrl($item->redirect_url);
             $item->bid = $result['bid'];
             $item->cid = $result['cid'];
             if ($result['cid']) {
@@ -156,19 +168,11 @@ class BookController extends BaseController
             }
             return $item;
         });
-        $package   = $request->header('x-package', '');
-        $checkOpen = env('CHECK_OPEN', false);
-        if ($checkOpen && $package === 'com.juyu.kuaiying.rmyq') {
-            $hotBids   = config('home.hot.' . $sex);
-            $liveBids  = config('home.live.' . $sex);
-            $recomBids = config('home.recom.' . $sex);
-            $newBids   = config('home.new_recom.' . $sex);
-        } else {
-            $hotBids   = RecommendService::getRecommendIdsStatic($channel, 'hot');
-            $liveBids  = RecommendService::getRecommendIdsStatic($channel, 'live');
-            $recomBids = RecommendService::getRecommendIdsStatic($channel, 'recom');
-            $newBids   = RecommendService::getRecommendIdsStatic($channel, 'new_recom');
-        }
+
+        $hotBids   = RecommendService::getRecommendIdsStatic($channel, 'hot');
+        $liveBids  = RecommendService::getRecommendIdsStatic($channel, 'live');
+        $recomBids = RecommendService::getRecommendIdsStatic($channel, 'recom');
+        $newBids   = RecommendService::getRecommendIdsStatic($channel, 'new_recom');
 
         $result = [
             ['type' => 'reco_banner', 'lable' => '首页banner', 'books' => $books],
@@ -198,10 +202,10 @@ class BookController extends BaseController
 
     public function library(Request $request)
     {
-        $where = [];
-        $order = [];
+        $where                = [];
+        $order                = [];
         $where['is_on_shelf'] = [2];
-        $category_id = $request->input('category_id');
+        $category_id          = $request->input('category_id');
         if ($category_id) {
             if ($category_id == 1) {
                 $where['channel_name'] = '男频';
@@ -217,8 +221,8 @@ class BookController extends BaseController
             BookConfigService::saveUserSearchLog($key, $uid);
         }
         $where['key'] = $key;
-        $order_field = $request->input('order_field');
-        $order_seq = $request->input('order_seq');
+        $order_field  = $request->input('order_field');
+        $order_seq    = $request->input('order_seq');
         if ($order_field != '' && in_array($order_field, ['recommend_index', 'click_count', 'update', 'size', 'create'])) {
             if ($order_field == 'update') {
                 $order = ['book_configs.updated_at', 'desc'];
@@ -235,12 +239,21 @@ class BookController extends BaseController
                 $order = [$order_field, 'desc'];
             }
         }
+
+        // 审核状态默认值
+        $package     = $request->header('x-package', '');
+        $brand       = strtolower($request->header('x-nbrand', ''));
+        $codeVersion = $request->header('x-codeversion', '');
+        if ($order_field === 'recommend_index' && Utils::checkIsAudit($package, $brand, $codeVersion)) {
+            $order = ['id', 'desc'];
+        }
+
         $status = $request->input('status');
         if ($status != '') {
             $where['status'] = $status;
         }
         $page_size = $request->input('page_size', 15);
-        $books = BookConfigService::getBooks($where, $order, $page_size);
+        $books     = BookConfigService::getBooks($where, $order, $page_size);
         return response()->pagination(new BookTransformer, $books);
     }
 
@@ -253,14 +266,14 @@ class BookController extends BaseController
     public function similarRecom(Request $request)
     {
         $category_id = $request->input('category_id');
-        $bid = $request->input('bid');
+        $bid         = $request->input('bid');
         if (empty($bid) || empty($category_id)) {
             return response()->error('PARAM_ERROR');
         }
-        $bid = BookService::decodeBidStatic($bid);
+        $bid   = BookService::decodeBidStatic($bid);
         $where = ['category_id' => $category_id, 'is_on_shelf' => [2]];
         $books = BookConfigService::getBooks($where, [], 4);
-        $data = [];
+        $data  = [];
         foreach ($books as $v) {
             if ($v->bid != $bid && count($data) < 3) {
                 $data[] = $v;
@@ -275,21 +288,21 @@ class BookController extends BaseController
         if (empty($bid)) {
             return response()->error('PARAM_ERROR');
         }
-        $bid = BookService::decodeBidStatic($bid);
-        $book_info = BookConfigService::getBookById($bid);
-        $res = BookConfigService::getRecommendBooks($bid, $book_info->channel_name);
+        $bid         = BookService::decodeBidStatic($bid);
+        $book_info   = BookConfigService::getBookById($bid);
+        $res         = BookConfigService::getRecommendBooks($bid, $book_info->channel_name);
         $urge_status = 0;
         if ($book_info->status == 0 && !BookUrgeUpdateService::isHadUrged($this->uid, $bid)) {
             $urge_status = 1;
         }
         $recommend_result = collectionTransform(new BookTransformer(), $res);
-        $book_status = [
-            'status' => $book_info->status,
+        $book_status      = [
+            'status'      => $book_info->status,
             'urge_status' => $urge_status
         ];
-        $data = [
+        $data             = [
             'recommend_result' => $recommend_result,
-            'book_status' => $book_status
+            'book_status'      => $book_status
         ];
         return response()->success($data);
     }
@@ -313,9 +326,9 @@ class BookController extends BaseController
     public function recommen()
     {
         $reco_banner_type = ['FEMALE', 'PUBLIC'];
-        $books = (new RecoBannerService)->getByType($reco_banner_type, 2);
+        $books            = (new RecoBannerService)->getByType($reco_banner_type, 2);
         $books->transform(function ($item) {
-            $result = $this->getBidCidFromUrl($item->redirect_url);
+            $result    = $this->getBidCidFromUrl($item->redirect_url);
             $item->bid = $result['bid'];
             $item->cid = $result['cid'];
             if ($result['cid']) {

+ 29 - 29
app/Http/Controllers/QuickApp/Book/Transformers/BookTransformer.php

@@ -15,37 +15,37 @@ class BookTransformer
     public function transform($book)
     {
         return [
-            'book_id' => Hashids::encode($book->bid),
-            'book_name' => $book->book_name,
-            'book_summary' => $book->intro,
-            'book_author' => $book->author,
-            'cover_url' => $book->cover,
-            'book_word_count' => $book->size,
-            'book_chapter_total' => $book->chapter_count,
-            'book_category_id' => $book->category_id,
-            'book_category' => $book->category_name,
-            'book_end_status' => $book->status,
-            'book_published_time' =>  $book->updated_at ?? '',
-            'copyright' =>  $book->copyright ?? '',
-            'charge_type' =>  $book->charge_type ?? '',
+            'book_id'                    => Hashids::encode($book->bid),
+            'book_name'                  => $book->book_name,
+            'book_summary'               => $book->intro,
+            'book_author'                => $book->author,
+            'cover_url'                  => $book->cover,
+            'book_word_count'            => $book->size,
+            'book_chapter_total'         => $book->chapter_count,
+            'book_category_id'           => $book->category_id,
+            'book_category'              => $book->category_name,
+            'book_end_status'            => $book->status,
+            'book_published_time'        => $book->updated_at ?? '',
+            'copyright'                  => $book->copyright ?? '',
+            'charge_type'                => $book->charge_type ?? '',
             'force_subscribe_chapter_id' => $book->force_subscribe_chapter_seq,
-            'update_time' => $book->updated_at ?? '',
+            'update_time'                => $book->updated_at ?? '',
             // 'is_on_shelf' => $book->is_on_shelf ?? 0,
-            'book_price' => $book->price ?? 0,
-            'keyword' => $book->keyword,
-            'recommend_index' => $book->recommend_index,
-            'is_show_index_content' => $book->is_show_index_content,
-            'click_count' => $book->click_count,
-            'product_id' => $book->product_id,
-            'sex_preference' => $book->channel_name,
-            'last_cid' => $book->last_cid,
-            'last_chapter' => $book->last_chapter,
-            'first_cid' => $book->first_cid,
-            'is_on_user_shelf' => $book->is_on_user_shelf,
-            'last_chapter_is_vip' => $book->last_chapter_is_vip ?? 0,
-            'is_need_charge' => $book->is_need_charge ? 1 : 0,
-            'record_chapter_id' => $book->record_chapter_id ?? 0,
-            'record_chapter_name' => $book->record_chapter_name ?? '',
+            'book_price'                 => $book->price ?? 0,
+            'keyword'                    => $book->keyword,
+            'recommend_index'            => $book->recommend_index,
+            'is_show_index_content'      => $book->is_show_index_content,
+            'click_count'                => $book->click_count,
+            'product_id'                 => $book->product_id,
+            'sex_preference'             => $book->channel_name,
+            'last_cid'                   => $book->last_cid,
+            'last_chapter'               => $book->last_chapter,
+            'first_cid'                  => $book->first_cid,
+            'is_on_user_shelf'           => $book->is_on_user_shelf,
+            'last_chapter_is_vip'        => $book->last_chapter_is_vip ?? 0,
+            'is_need_charge'             => $book->is_need_charge ? 1 : 0,
+            'record_chapter_id'          => $book->record_chapter_id ?? 0,
+            'record_chapter_name'        => $book->record_chapter_name ?? '',
         ];
     }
 }

+ 5 - 5
app/Http/Controllers/QuickApp/WelcomeController.php

@@ -116,11 +116,11 @@ class WelcomeController extends BaseController
 
         // 获取派单信息
         $adPositions = [];
-        if ($sendOrderId) {
-            $sendOrder      = QappSendOrder::getSendOrderById($sendOrderId);
-            $channelAccount = QappChannelAccount::getByAccount(getProp($sendOrder, 'account'));
-            $adPositions    = AdPositionService::getInstance()->getAdPositions($this->uid, getProp($channelAccount, 'id'));
-        }
+        // if ($sendOrderId) {
+        //     $sendOrder      = QappSendOrder::getSendOrderById($sendOrderId);
+        //     $channelAccount = QappChannelAccount::getByAccount(getProp($sendOrder, 'account'));
+        //     $adPositions    = AdPositionService::getInstance()->getAdPositions($this->uid, getProp($channelAccount, 'id'));
+        // }
 
         // 配置
         $data = [

+ 29 - 0
app/Libs/Utils.php

@@ -60,6 +60,35 @@ class Utils
     }
 
     /**
+     * 加密批量bid
+     * @param $bids
+     * @return array
+     */
+    public static function getEncodeIds($bids)
+    {
+        return array_map(function ($bid) {
+            return Hashids::encode($bid);
+        }, $bids);
+    }
+
+    /**
+     * 审核状态判断,true为审核状态,false默认
+     * @param $package
+     * @param $brand
+     * @param $codeVersion
+     * @return bool
+     */
+    public static function checkIsAudit($package, $brand, $codeVersion): bool
+    {
+        $audit = getProp(config('audit'), $package, []);
+        if ($audit && $brand === getProp($audit, 'brand') && $codeVersion === getProp($audit, 'codeVersion')) {
+            return true;
+        }
+
+        return false;
+    }
+
+    /**
      * 获取redis的key
      * @param       $keyStr // 例如:wap.rank_page
      * @param array $args // 例如:[10, 2000]

+ 5 - 0
app/Modules/AdPosition/Services/AdPositionService.php

@@ -21,6 +21,11 @@ class AdPositionService
      */
     public function getAdPositions($uid, $accountId): array
     {
+        // 参数判断
+        if (empty($uid) || empty($accountId)) {
+            return [];
+        }
+
         // 获取广告位
         $positions = AdPosition::getAllValidAdPositions();
         if (empty($positions)) {

+ 61 - 0
app/Modules/Book/Services/BookAuditService.php

@@ -0,0 +1,61 @@
+<?php
+
+
+namespace App\Modules\Book\Services;
+
+
+use App\Http\Controllers\QuickApp\Book\Transformers\BookTransformer;
+
+class BookAuditService
+{
+    /**
+     * 审核数据
+     * @param $sex
+     * @return array
+     */
+    public static function getHomeBooksData($sex): array
+    {
+        // 基本配置数据
+        $home = config('home');
+
+        // banner
+        $banner      = $home['reco_banner'];
+        $bannerBooks = $banner[$sex];
+
+        // 模块
+        [$hot, $live, $recom, $new] = [$home['hot'], $home['zhibo'], $home['recom'], $home['new_recom']];
+        [$hotBids, $liveBids, $recomBids, $newBids] = [$hot[$sex], $live[$sex], $recom[$sex], $new[$sex]];
+
+        // 一次性获取书籍列表
+        $bids  = array_merge($hotBids, $liveBids, $recomBids, $newBids);
+        $books = BookConfigService::getBooksByIds($bids);
+
+        return [
+            [
+                'type'  => 'reco_banner',
+                'lable' => $banner['label'],
+                'books' => $bannerBooks
+            ],
+            [
+                'type'  => 'hot',
+                'lable' => $hot['label'],
+                'books' => collectionTransform(new BookTransformer, collect($books)->whereIn('bid', $hotBids)->all())
+            ],
+            [
+                'type'  => 'zhibo',
+                'lable' => $live['label'],
+                'books' => collectionTransform(new BookTransformer, collect($books)->whereIn('bid', $liveBids)->all())
+            ],
+            [
+                'type'  => 'recom',
+                'lable' => $recom['label'],
+                'books' => collectionTransform(new BookTransformer, collect($books)->whereIn('bid', $recomBids)->all())
+            ],
+            [
+                'type'  => 'new_recom',
+                'lable' => $new['label'],
+                'books' => collectionTransform(new BookTransformer, collect($books)->whereIn('bid', $newBids)->all())
+            ],
+        ];
+    }
+}

+ 7 - 0
config/audit.php

@@ -0,0 +1,7 @@
+<?php
+return [
+    'com.app.kyy.xjxs' => [
+        'brand'       => 'huawei',
+        'codeVersion' => '0.0.2'
+    ],
+];

+ 45 - 4
config/home.php

@@ -1,18 +1,59 @@
 <?php
 return [
-    'hot'       => [
+    'reco_banner' => [
+        'label'  => '首页banner',
+        'male'   => [
+            [
+                'redirect_url' => 'views/Detail',
+                'banner_url'   => 'https://cdn-novel.iycdm.com/h5/reco_banner/20200820145102SYGL.jpg',
+                'bid'          => 'vEY8QJe51DA9WKoekOg7Bj6bmGM2qPXr', // 11529 神医归来
+                'cid'          => 0
+            ],
+            [
+                'redirect_url' => 'views/Detail',
+                'banner_url'   => 'https://cdn-novel.iycdm.com/h5/reco_banner/20200820145004ZQSS.jpg',
+                'bid'          => 'pNo6A7wqQmB1WgQ5NrgDjkOM9VZn2vXe', // 11601 最强杀手
+                'cid'          => 0
+            ],
+        ],
+        'female' => [
+            [
+                'redirect_url' => 'views/Detail',
+                'banner_url'   => 'https://cdn-novel.iycdm.com/h5/reco_banner/20200820145001JSWL.jpg',
+                'bid'          => '2JWv0Xk1B3yqYRPkqYg6Gejno54PZrO9', // 10479 江山万里不如你
+                'cid'          => 0
+            ],
+            [
+                'redirect_url' => 'views/Detail',
+                'banner_url'   => 'https://cdn-novel.iycdm.com/h5/reco_banner/20200820145101JJDZXQ.jpg',
+                'bid'          => '0DNW9mYOqL7XGg3NpxlPk16eQx45dB8w', // 10467 将军的掌心妻
+                'cid'          => 0
+            ],
+            [
+                'redirect_url' => 'views/Detail',
+                'banner_url'   => 'https://cdn-novel.iycdm.com/h5/reco_banner/20200820145103SSYF.jpg',
+                'bid'          => '0DNW9mYOqL7XGg3N3YlPk16eQx45dB8w', // 10823 圣手医妃
+                'cid'          => 0
+            ]
+        ],
+    ],
+    'hot'         => [
+        'label'  => '今日主推',
         'male'   => [11601, 11529, 3365, 11833, 11543, 10377],
         'female' => [1479, 7836, 7891, 8129, 8167, 8337],
     ],
-    'live'      => [
+    'zhibo'       => [
+        'label'  => '大家都在看',
         'male'   => [11696, 2533, 6458, 9024, 11457, 11498],
         'female' => [8469, 8557, 9117, 9997, 8148, 8476],
     ],
-    'recom'     => [
+    'recom'       => [
+        'label'  => '主编精选',
         'male'   => [11506, 11674, 11826, 2563, 11499, 9509],
         'female' => [9423, 9248, 9973, 9990, 11766, 7629],
     ],
-    'new_recom' => [
+    'new_recom'   => [
+        'label'  => '畅销精品',
         'male'   => [10986, 11674, 10375, 10378, 11496, 11501],
         'female' => [10139, 9248, 7854, 1576, 1952, 2434],
     ],

+ 5 - 1
config/option.php

@@ -5,6 +5,10 @@ return [
         'com.beidao.kuaiying.zsy' => [
             'customerAccount' => 'zhenzhenyd',
             'customerImage'   => 'https://cdn-novel.iycdm.com/static/img/kefu20190331.png'
-        ]
+        ],
+        'com.app.kyy.xjxs'        => [
+            'customerAccount' => 'youyou1552',
+            'customerImage'   => 'http://zhuishuyun.oss-cn-hangzhou.aliyuncs.com/service/customimage_868_1552544217.%E5%AE%A2%E6%9C%8D.jpg'
+        ],
     ]
 ];