Bläddra i källkod

Merge branch 'kuaiyingyong' into kuaiyingyong_wcc

Wang Chen 4 år sedan
förälder
incheckning
72eb76e9a1

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

@@ -10,6 +10,7 @@ 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\Models\BookConfig;
 use App\Modules\Book\Services\BookConfigService;
 use App\Modules\Book\Services\BookService;
 use App\Modules\Book\Services\BookUrgeUpdateService;
@@ -340,4 +341,13 @@ class BookController extends BaseController
         });
         return response()->success($books);
     }
+
+    /**
+     * 限免
+     */
+    public function free(int $sex)
+    {
+        $result = BookConfigService::findFreeBooks($sex);
+        return response()->success($result);
+    }
 }

+ 4 - 5
app/Http/Controllers/QuickApp/Book/ChapterController.php

@@ -96,17 +96,16 @@ class ChapterController extends BaseController
             dispatch($job)->onConnection('rabbitmq')->onQueue('user_rentention_queue');
         }
 
-        if ($chapter->is_vip == 0) {
+        if ($chapter->is_vip == 0 && $chapter->sequence > 1) {
             ReadRecordService::addReadRecord([
                 'uid' => $this->uid, 'bid' => $bid, 'book_name' => $book_info->book_name,
                 'cid' => $cid, 'chapter_name' => $chapter->name
             ]);
-
             return response()->item(new ChapterTransformer, $this->getChapter($bid, $cid, $chapter));
         }
 
-        //已经付费
-        if ($this->getOrderRecord($bid, $cid)) {
+        //已经付费 或者 书籍是否限免
+        if ($this->getOrderRecord($bid, $cid) || BookConfigService::judgeBookIsFree($bid)) {
             ReadRecordService::addReadRecord([
                 'uid' => $this->uid, 'bid' => $bid, 'book_name' => $book_info->book_name,
                 'cid' => $cid, 'chapter_name' => $chapter->name
@@ -474,7 +473,7 @@ class ChapterController extends BaseController
         if (!$send_order_info)  return $force_add_desk_type;
         if ($send_order_info->book_id == $bid) {
             if ($send_order_info->force_add_desk_type == 1 && $send_order_info->force_add_desk_seq) {
-                if($sequence >= $send_order_info->force_add_desk_seq){
+                if ($sequence >= $send_order_info->force_add_desk_seq) {
                     $force_add_desk_type = $send_order_info->force_add_desk_type;
                 }
             }

+ 31 - 101
app/Http/Controllers/QuickApp/User/UserShelfBooksController.php

@@ -11,105 +11,33 @@ use App\Http\Controllers\QuickApp\User\Transformers\UserShelfBooksTransformer;
 use App\Modules\User\Services\ReadRecordService;
 use Hashids;
 use Log;
+
 class UserShelfBooksController extends BaseController
 {
-
-    /**
-     * @apiDefine UserShelfBooks 书架
-     */
-
-
-
-    /**
-     * @apiVersion 1.0.0
-     * @apiDescription 获取书架
-     * @api {get} userShelfBooks 获取书架
-     * @apiParam {String}  [token]  token
-     * @apiHeader {String} [Authorization]  token 两个token任选其一
-     * @apiGroup UserShelfBooks
-     * @apiName getChapter
-     * @apiSuccess {int}         code 状态码
-     * @apiSuccess {String}      msg  信息
-     * @apiSuccess {object}      data 结果集
-     * @apiSuccess {Int}         data.id   编号
-     * @apiSuccess {String}      data.distribution_channel_id   分销
-     * @apiSuccess {Int}         data.uid   uid
-     * @apiSuccess {Int}         data.bid   bid
-     * @apiSuccess {Int}         data.book_name   书名
-     * @apiSuccess {Int}         data.cover   封面
-     * @apiSuccess {Int}         data.last_cid   最后章节id
-     * @apiSuccess {String}      data.last_chapter  最新章节
-     * @apiSuccess {String}      data.last_chapter  最近阅读章节
-     * @apiSuccess {String}      data.recent_cid  最近阅读章节id
-     * @apiSuccessExample {json} Success-Response:
-     *     HTTP/1.1 200 OK
-     *     {
-     *       code: 0,
-     *       msg: "",
-     *       data: {
-     *          [
-     *               {
-     *                   id: 6,
-     *                   uid: 4,
-     *                   distribution_channel_id: 1,
-     *                   bid: 1,
-     *                   book_name: "京华烟云",
-     *                   cover: "https://leyue-bucket.oss-cn-hangzhou.aliyuncs.com/ycsd_cover/covermiddle/0/1.jpg",
-     *                   updated_at: 1511783068,
-     *                   last_cid: 4,
-     *                   recent_cid:5,
-     *                   last_chapter:"最新 第122章 大事不妙",
-     *                   recent_reading_chapter:"最近阅读:第5章 又来?"
-     *
-     *               },
-     *               {
-     *                   id: 7,
-     *                   uid: 4,
-     *                   distribution_channel_id: 1,
-     *                   bid: 1,
-     *                   book_name: "我来好好爱你",
-     *                   cover: "https://leyue-bucket.oss-cn-hangzhou.aliyuncs.com/ycsd_cover/covermiddle/0/11.jpg",
-     *                   updated_at: 1511783068,
-     *                   last_cid: 4,
-     *                   recent_cid:5,
-     *                   last_chapter:"最新 第2556章 又来了个张老三",
-     *                   recent_reading_chapter:"最近阅读:第2551章 又来了个猪八戒"
-     *               }
-     *           ]
-     *       }
-     */
-    public function index(Request $request){
+    public function index(Request $request)
+    {
         $res = UserShelfBooksService::getUserShelfBooksListByUid($this->uid);
-        if($res->isEmpty()){
+        if ($res->isEmpty()) {
             return response()->success();
         }
         $record = ReadRecordService::getReadRecord($this->uid);
-//        $record=array([
-//            'bid'=>1,
-//            'time'=>3,
-//            'cid'=>1,
-//        ],[
-//            'bid'=>2,
-//            'time'=>3,
-//            'cid'=>4,
-//        ]);
-        foreach ($res as &$v){
-            $bid=$v['bid'];
+        foreach ($res as &$v) {
+            $bid = $v['bid'];
             $last_cid = $v['last_cid'];
-            $last_chapter = ChapterService::getChapterNameByID($last_cid,$bid);
-            $v['last_chapter']="最后章节:{$last_chapter['name']}";
-            foreach ($record as $val){
-                if($v['bid'] == $val['bid']){
+            $last_chapter = ChapterService::getChapterNameByID($last_cid, $bid);
+            $v['last_chapter'] = "最后章节:{$last_chapter['name']}";
+            foreach ($record as $val) {
+                if ($v['bid'] == $val['bid']) {
                     $v['updated_at'] = $val['time'];
                     $recent_reading_cid = $val['cid'];
                     $v['recent_cid'] = $recent_reading_cid;
-                    $recent_reading_chapter = ChapterService::getChapterNameById($recent_reading_cid,$bid);
+                    $recent_reading_chapter = ChapterService::getChapterNameById($recent_reading_cid, $bid);
                     $v['recent_reading_chapter'] = "最近阅读:{$recent_reading_chapter['name']}";
                     break;
                 }
             }
         }
-        return response()->collection(new UserShelfBooksTransformer(),$res);
+        return response()->collection(new UserShelfBooksTransformer(), $res);
     }
 
     /**
@@ -131,9 +59,10 @@ class UserShelfBooksController extends BaseController
      *       msg: "",
      *       data: {}
      */
-    public function addShelf(Request $request){
+    public function addShelf(Request $request)
+    {
         $param = $request->except('_url');
-        if(checkParam($param,['bid'])){
+        if (checkParam($param, ['bid'])) {
             return response()->error('LACK_PARAM');
         }
 
@@ -141,13 +70,13 @@ class UserShelfBooksController extends BaseController
         $param['bid'] = Hashids::decode($param['bid'])[0];
         $param['distribution_channel_id'] = $this->distribution_channel_id;
         $res = null;
-        try{
-            $res = UserShelfBooksService::create($param);
-        }catch (\Exception $e){
+        $res = UserShelfBooksService::create($param);
+        try {
+        } catch (\Exception $e) {
             return response()->error('QAPP_PARAM_ERROR');
         }
 
-        if($res){
+        if ($res) {
             return response()->success($res);
         }
         return response()->error('QAPP_SYS_ERROR');
@@ -173,18 +102,19 @@ class UserShelfBooksController extends BaseController
      *       msg: "",
      *       data: {}
      */
-    public function delShelf(Request $request){
+    public function delShelf(Request $request)
+    {
         $bid = $request->input('bid');
-        if(empty($bid)) return response()->error('LACK_PARAM');
+        if (empty($bid)) return response()->error('LACK_PARAM');
         $param['uid'] = $this->uid;
         $param['bid'] = Hashids::decode($bid)[0];
-        $res = UserShelfBooksService::del($this->uid,$param['bid']);
-        if($res){
+        $res = UserShelfBooksService::del($this->uid, $param['bid']);
+        if ($res) {
             return response()->success();
         }
         return response()->error('QAPP_SYS_ERROR');
     }
-    
+
 
     /**
      * @apiVersion 1.0.0
@@ -208,17 +138,17 @@ class UserShelfBooksController extends BaseController
      *               is_on:0
      *           }
      */
-    public function  isOnshelf(Request $request){
+    public function  isOnshelf(Request $request)
+    {
         $bid = $request->input('bid');
-        if(!$bid) return response()->error('LACK_PARAM');
+        if (!$bid) return response()->error('LACK_PARAM');
         $bid = Hashids::decode($bid)[0];
-        $res = UserShelfBooksService::getUserShelfBooksListByUidAndBid($this->uid,$bid);
-        if($res){
+        $res = UserShelfBooksService::getUserShelfBooksListByUidAndBid($this->uid, $bid);
+        if ($res) {
             $data['is_on'] = 1;
-        }else{
+        } else {
             $data['is_on'] = 0;
         }
         return response()->success($data);
     }
-
 }

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

@@ -23,7 +23,7 @@ Route::group(['domain' => env('QUICKAPP_DOMAIN'), 'namespace' => 'App\Http\Contr
 
         // 书库
         Route::get('books/library', 'Book\BookController@library');
-        
+
         //热词
         Route::get('books/hotwords', 'Book\BookController@hotWords');
 
@@ -38,6 +38,8 @@ Route::group(['domain' => env('QUICKAPP_DOMAIN'), 'namespace' => 'App\Http\Contr
     });
 
     Route::group(['prefix' => 'api', 'middleware' => 'jwttoken'], function () {
+        //限免
+        Route::get('books/free/{sex}', 'Book\BookController@free')->where('sex', '\d+');
         // 全局配置
         Route::get('options', 'WelcomeController@getOptions');
         // 客服相关

+ 10 - 0
app/Libs/Push/VPush/VivoPushCommon.php

@@ -0,0 +1,10 @@
+<?php
+
+
+namespace App\Libs\Push\VPush;
+
+
+class VivoPushCommon
+{
+
+}

+ 19 - 0
app/Modules/Book/Models/FreeBook.php

@@ -0,0 +1,19 @@
+<?php
+
+namespace App\Modules\Book\Models;
+
+use Illuminate\Database\Eloquent\Model;
+
+class FreeBook extends Model
+{
+    protected $table = 'free_books';
+    protected $fillable = [
+        'config_id',
+        'bid',
+        'book_name',
+        'sex',
+        'virtual_fee',
+        'charge_amount',
+        'is_enabled',
+    ];
+}

+ 16 - 0
app/Modules/Book/Models/FreeBookConfig.php

@@ -0,0 +1,16 @@
+<?php
+
+namespace App\Modules\Book\Models;
+
+use Illuminate\Database\Eloquent\Model;
+
+class FreeBookConfig extends Model
+{
+    protected $table = 'free_book_config';
+    protected $fillable = [
+        'sex',
+        'name',
+        'end_time',
+        'is_enabled',
+    ];
+}

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

@@ -14,9 +14,12 @@ 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 App\Modules\Book\Models\FreeBook;
+use App\Modules\Book\Models\FreeBookConfig;
 use App\Modules\Book\Models\QappUserSearchBookLog;
 use Redis;
 use DB;
+use Vinkla\Hashids\Facades\Hashids;
 
 class BookConfigService
 {
@@ -465,4 +468,68 @@ class BookConfigService
             'words' => $words,
         ]);
     }
+
+    /**
+     * @return FreeBookConfig
+     */
+    public static function findFreeBookConfig(int $sex)
+    {
+        return FreeBookConfig::where(['sex' => $sex, 'is_enabled' => 1])
+            ->where('end_time', '>=', now())
+            ->orderBy('end_time')
+            ->first();
+    }
+
+    /**
+     * 查找限免书籍
+     * @return array
+     */
+    public static function findFreeBooks(int $sex)
+    {
+        $config = self::findFreeBookConfig($sex);
+        if ($config) {
+            $free_books =  FreeBook::where('config_id', $config->id)
+                ->where('is_enabled', 1)
+                ->get();
+            $bids = $free_books->pluck('bid')->all();
+            $book_configs = BookConfig::whereIn('bid', $bids)
+                ->where('is_on_shelf', 2)
+                ->select('bid', 'book_name', 'cover')
+                ->get();
+            $books = Book::whereIn('id', $bids)->select('id', 'intro')->get();
+            $book_list = $book_configs->transform(function ($item) use ($books) {
+                $book = $books->where('id', $item->bid)->first();
+                return [
+                    'book_id' => Hashids::encode($item->bid),
+                    'cover_url' => $item->cover,
+                    'book_name' => $item->book_name,
+                    'intro' => $book->intro,
+                ];
+            })->all();
+            return [
+                'title' => $config->name,
+                'end_time' => $config->end_time,
+                'list' => $book_list,
+            ];
+        }
+        return [];
+    }
+
+    /**
+     * 判断书籍是否限免
+     * @return bool
+     */
+    public static function judgeBookIsFree(int $bid)
+    {
+        $ids = [];
+        foreach ([1, 2] as $sex) {
+            $config = self::findFreeBookConfig($sex);
+            if ($config) {
+                $ids[] = $config->id;
+            }
+        }
+        return FreeBook::where('bid', $bid)
+            ->whereIn('config_id', $ids)
+            ->where('is_enabled', 1)->exists();
+    }
 }

+ 1 - 2
app/Modules/User/Services/ReadRecordService.php

@@ -127,7 +127,6 @@ class ReadRecordService
         $read_bids = Redis::hgetall('book_read:' . $uid);
         $res = [];
         $i = 0;
-        //self::delBookNameAndChapter($uid);
         foreach ($read_bids as $key => $v) {
             if (in_array($key, self::$not_uid_key)) {
                 continue;
@@ -144,7 +143,7 @@ class ReadRecordService
             if ($a['time'] >= $b['time']) return -1;
             return 1;
         });
-        return $res;
+        return collect($res)->sortByDesc('time')->values()->all();
     }
 
     /**

+ 2 - 1
config/push.php

@@ -27,6 +27,7 @@ return [
             'getAllTags'       => 'https://api-device.push.heytapmobi.com/server/v1/device/get_all_tags',
             'getInvalidRegIds' => 'https://feedback.push.oppomobile.com/server/v1/feedback/fetch_invalid_regidList',
             'fetchPushPermit'  => 'https://feedback.push.oppomobile.com/server/v1/feedback/fetch_push_permit',
-        ]
+        ],
+        'vivo'   => []
     ]
 ];