فهرست منبع

read record redis

zz 6 سال پیش
والد
کامیت
80bdfa9a0c

+ 26 - 0
app/Console/Commands/BookTest.php

@@ -73,6 +73,7 @@ class BookTest extends Command
         //$this->sendOrderStats105();
         //$this->you2();
         //$this->transfromUserOrder();
+        //$this->clearUserReadRecord();
     }
 
 
@@ -575,4 +576,29 @@ class BookTest extends Command
 
         }
     }
+
+    private function clearUserReadRecord(){
+        $i = 10000;
+        //$not_uid_key = ['last_read','send_order_id','sign_count','sign_counts','sign_info','sign_day','smart_push','inner_send_order_id','gxhp','property','bind_phone_status','ua'];
+        while ( $i<108655782 ){
+            $last_read = ReadRecordService::getByField($i,'last_read');
+            if(!$last_read){
+                Redis::del('book_read:'.$i);
+            }
+            $last_info = explode(',',explode('_',$last_read));
+            if(time()-$last_info[1]>=5*30*86400 ){
+                $record = Redis::hgetall('book_read:'.$i);
+                $data = [];
+
+                foreach ($record as $k=>$item){
+                    $data[] = ['uid'=>$i,'field'=>$k,'value'=>$item,
+                        'created_at'=>date('Y-m-d H:i:s'),'updated_at'=>date('Y-m-d H:i:s')];
+                }
+                Redis::del('book_read:'.$i);
+                DB::table('read_record_from_redis')->insert($data);
+            }
+            $i++;
+        }
+    }
+
 }

+ 3 - 1
app/Http/Controllers/Wap/User/ReadRecordController.php

@@ -68,7 +68,9 @@ class ReadRecordController extends BaseController
             return response()->error('NOT_LOGIN');
         }
         $this->pageRecord('recent');
-        $res = ReadRecordService::getReadRecord($this->uid);
+        $user = $this->_user_info;
+        $is_check_from_db = (time()-strtotime($user->created_at) >5*30*86400);
+        $res = ReadRecordService::getReadRecord($this->uid,$is_check_from_db);
         if($res){
             $id_arr = [];
             foreach ($res as $key => $value) {

+ 1 - 1
app/Modules/Book/Models/BookConfig.php

@@ -308,7 +308,7 @@ class BookConfig extends Model
             ->leftjoin('book_categories', 'books.category_id', 'book_categories.id')
             ->select('book_configs.bid', 'book_configs.is_on_shelf', 'book_configs.force_subscribe_chapter_seq', 'book_configs.vip_seq', 'book_configs.cp_source', 'book_configs.price', 'book_configs.cover', 'book_configs.book_name',
                 'book_configs.copyright', 'book_configs.created_at', 'book_configs.charge_type', 'book_configs.is_on_shelf', 'books.author', 'books.intro', 'book_categories.category_name',
-                'category_id', 'status', 'chapter_count', 'first_cid', 'last_cid', 'size', 'last_chapter', 'books.keyword', 'book_configs.recommend_index',
+                'category_id', 'status', 'chapter_count', 'first_cid', 'last_cid', 'size', 'last_chapter', 'books.keyword', 'book_configs.recommend_index','book_configs.test_status',
                 'book_configs.is_show_index_content', 'book_configs.click_count', 'book_configs.product_id', 'book_categories.channel_name', 'books.last_cid', 'books.updated_at as last_update_time',
                 'books.last_chapter', 'book_configs.product_id', 'book_configs.copyright_limit_data', 'book_configs.promotion_domain', 'books.name as old_name', 'book_configs.recommend_cid', 'book_configs.is_high_quality'
             )->where('book_configs.bid', $bid)->first();

+ 11 - 0
app/Modules/User/Models/ReadRecordFromRedis.php

@@ -0,0 +1,11 @@
+<?php
+
+namespace App\Modules\User\Models;
+
+use Illuminate\Database\Eloquent\Model;
+
+class ReadRecordFromRedis extends Model
+{
+    protected $table = 'read_record_from_redis';
+    protected $fillable = ['uid','field','value'];
+}

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

@@ -8,6 +8,7 @@
 
 namespace App\Modules\User\Services;
 
+use App\Modules\User\Models\ReadRecordFromRedis;
 use Redis;
 use Hashids;
 use App\Modules\Book\Services\BookConfigService;
@@ -52,8 +53,11 @@ class ReadRecordService
      * @param $uid
      * @return array
      */
-    public static function getReadRecord($uid)
+    public static function getReadRecord($uid,$is_need_check_db=false)
     {
+        if($is_need_check_db){
+            self::resetRecordFromDB($uid);
+        }
         $read_bids = Redis::hgetall('book_read:' . $uid);
         $res = [];
         $i = 0;
@@ -509,4 +513,17 @@ class ReadRecordService
         }catch (\Exception $e){}
         return '';
     }
+
+    private static function resetRecordFromDB($uid)
+    {
+        if(self::getByField($uid,'last_read')){
+            return ;
+        }
+        $record = ReadRecordFromRedis::where('uid',$uid)->select('field','value')->get();
+        if($record->isNotEmpty()){
+            foreach ($record as $item){
+                Redis::hset('book_read:'.$uid,$item->field,$item->value);
+            }
+        }
+    }
 }