浏览代码

Merge branch 'yunqi' into stabble

zz 6 年之前
父节点
当前提交
66484661e1

+ 6 - 9
app/Console/Commands/YqBook.php

@@ -5,6 +5,7 @@ namespace App\Console\Commands;
 use App\Modules\Book\Models\Chapter;
 use App\Modules\Book\Models\Book;
 use App\Modules\Book\Models\BookConfig;
+use App\Modules\YunQi\Services\BookYunqiService;
 use Illuminate\Console\Command;
 use GuzzleHttp\Client;
 use GuzzleHttp\Psr7\Request;
@@ -96,26 +97,22 @@ class YqBook extends Command
             'cover'=>$book_info['cover'],
             'keyword'=>$book_info['keyword'],
             'chapter_count'=>$book_info['chapter_count'],
+            'category_name'=>$book_info['category_name'],
+            'status'=>$book_info['status'],
             'size'=>$book_info['size']
         ]);
         BookConfig::create([
             'bid'=>$book->id,
             'force_subscribe_chapter_seq'=>10,
             'price'=>8.99,
-            'cover'=>$book_info['book_name'],
+            'book_name'=>$book_info['book_name'],
+            'cover'=>$book_info['cover'],
             'promotion_domain'=>'iycdm.com',
             'charge_type'=>isset($book_info['charge_type'])?$book_info['charge_type']:'CHAPTER',
             'is_on_shelf'=>10,
             'cp_source'=>'yunqi',
         ]);
-
-        DB::table('book_yunqi')->insert([
-            'bid'=>$book->id,
-            'yq_bid'=>$bid,
-            'type'=>'DEFAULT',
-            'created_at'=>date('Y-m-d H:i:s'),
-            'updated_at'=>date('Y-m-d H:i:s')
-        ]);
+        BookYunqiService::create($book->id,$bid);
         return $book;
     }
 

+ 10 - 0
app/Http/Controllers/Wap/Book/ChapterController.php

@@ -2,6 +2,7 @@
 
 namespace App\Http\Controllers\Wap\Book;
 
+use App\Console\Commands\YqBook;
 use App\Modules\Book\Models\DataAnalysisBookConfig;
 use App\Modules\Book\Services\BookService;
 use App\Modules\Book\Services\ChapterCommentsService;
@@ -12,6 +13,7 @@ use App\Modules\Statistic\Services\DataAnalysisChapterService;
 use App\Modules\Statistic\Services\DataAnalysisSelectUserService;
 use App\Modules\Statistic\Services\WapVisitStatService;
 use App\Modules\Subscribe\Services\OrderService;
+use App\Modules\YunQi\Services\BookUserService;
 use Illuminate\Http\Request;
 use App\Http\Controllers\Wap\BaseController;
 use Cookie;
@@ -1232,6 +1234,14 @@ class ChapterController extends BaseController
             $chapter_order = ChapterOrderService::checkBookIsOrdered($this->uid, $book_info->bid);
             if (!$chapter_order) return true;
         }
+
+        if($book_info->is_on_shelf == 10){
+            $yq_book_user = BookUserService::selectUser($this->uid);
+            if($yq_book_user && $yq_book_user->type == 'ENABLE'){
+                return false;
+            }
+            return true;
+        }
         return false;
     }
 

文件差异内容过多而无法显示
+ 509 - 248
app/Http/Middleware/ReadOauth.php


+ 11 - 0
app/Modules/YunQi/Models/BookUser.php

@@ -0,0 +1,11 @@
+<?php
+
+namespace App\Modules\YunQi\Models;
+
+use Illuminate\Database\Eloquent\Model;
+
+class BookUser extends Model
+{
+    protected $table = 'yq_book_user';
+    protected $fillable = ['uid','area','type','bid','flag'];
+}

+ 11 - 0
app/Modules/YunQi/Models/BookYunqi.php

@@ -0,0 +1,11 @@
+<?php
+
+namespace App\Modules\YunQi\Models;
+
+use Illuminate\Database\Eloquent\Model;
+
+class BookYunqi extends Model
+{
+    protected $table = 'book_yunqi';
+    protected $fillable = ['bid','yq_bid','type'];
+}

+ 11 - 0
app/Modules/YunQi/Models/YqZsyTest.php

@@ -0,0 +1,11 @@
+<?php
+
+namespace App\Modules\YunQi\Models;
+
+use Illuminate\Database\Eloquent\Model;
+
+class YqZsyTest extends Model
+{
+    protected $table = 'yq_zsy_test';
+    protected $fillable = ['bid','type','limit_area'];
+}

+ 47 - 0
app/Modules/YunQi/Services/BookUserService.php

@@ -0,0 +1,47 @@
+<?php
+/**
+ * Created by PhpStorm.
+ * User: z-yang
+ * Date: 2019/1/10
+ * Time: 11:30
+ */
+
+namespace App\Modules\YunQi\Services;
+
+use App\Modules\YunQi\Models\BookUser;
+use Redis;
+
+class BookUserService
+{
+    public static function getByUid($uid){
+        return BookUser::where('uid',$uid)->select('id','uid','area','type','bid','flag')->first();
+    }
+
+    public static function updateUser($uid,$data){
+        return BookUser::where('uid',$uid)->update($data);
+    }
+
+
+    public static function popUser($uid){
+        try{
+            Redis::srem('YQ_USER_TEST_BOOK:USER',$uid);
+        }catch (\Exception $e){}
+    }
+
+    public static function isUserInRedis($uid){
+        return Redis::SISMEMBER('YQ_USER_TEST_BOOK:USER',$uid);
+    }
+
+    /**
+     * 判断用户是否存在
+     * @param $uid
+     * @return bool
+     */
+    public static function selectUser($uid){
+        if(!self::isUserInRedis($uid)){
+            return null;
+        }
+        $user = self::getByUid($uid);
+        return $user;
+    }
+}

+ 39 - 0
app/Modules/YunQi/Services/BookYunqiService.php

@@ -0,0 +1,39 @@
+<?php
+/**
+ * Created by PhpStorm.
+ * User: z-yang
+ * Date: 2019/1/10
+ * Time: 11:31
+ */
+
+namespace App\Modules\YunQi\Services;
+
+
+use App\Modules\YunQi\Models\BookYunqi;
+use Redis;
+
+class BookYunqiService
+{
+    public static function create($bid,$yq_bid){
+       $type = 'DEFAULT';
+        if(self::getByBid($bid)){
+            return false;
+        }
+       return BookYunqi::create(compact('bid','yq_bid','type'));
+    }
+
+    public static function getByBid($bid){
+        if(empty($bid))return false;
+        return BookYunqi::where('bid',$bid)->select('bid','type','id')->first();
+    }
+
+    public static function getRandomBooks($num=1):array{
+        $books = BookYunqi::select('bid')->get();
+        if($books->count()<=0){
+            return [];
+        }
+        $num = $books->count()>$num ?$num:$books->count();
+        return $books->random($num)->pluck('bid')->all();
+    }
+
+}

+ 37 - 0
app/Modules/YunQi/Services/YqZsyTestService.php

@@ -0,0 +1,37 @@
+<?php
+/**
+ * Created by PhpStorm.
+ * User: z-yang
+ * Date: 2019/1/11
+ * Time: 9:50
+ */
+
+namespace App\Modules\YunQi\Services;
+
+use App\Modules\OfficialAccount\Services\ForceSubscribeService;
+use App\Modules\YunQi\Models\YqZsyTest;
+
+class YqZsyTestService
+{
+    public static function getRandomBooks($uid,$num=1):array{
+        $sex = ForceSubscribeService::getSimpleSexByUid($uid);
+        if($sex == 1){
+            $channel_name = '男频';
+        }else{
+            $channel_name = '女频';
+        }
+        $books = YqZsyTest::join('books','books.id','=','yq_zsy_test.bid')
+            ->join('book_categories','book_categories.id','=','books.category_id')
+            ->where('book_categories.channel_name',$channel_name)
+            ->select('yq_zsy_test.bid')->where('type','yunqi')->get();
+        if($books->count()<=0){
+            return [];
+        }
+        $num = $books->count()>$num ?$num:$books->count();
+        return $books->random($num)->pluck('bid')->all();
+    }
+
+    public static function getByBid($bid){
+        return YqZsyTest::where('bid',$bid)->select('id','bid','type')->first();
+    }
+}