|
@@ -17,6 +17,8 @@ use DB;
|
|
|
|
|
|
class ReadRecordService
|
|
|
{
|
|
|
+ //阅读记录数
|
|
|
+ const RECORD_COUNT = 50;
|
|
|
|
|
|
private static $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'];
|
|
|
|
|
@@ -58,6 +60,7 @@ class ReadRecordService
|
|
|
if($is_need_check_db){
|
|
|
self::resetRecordFromDB($uid);
|
|
|
}
|
|
|
+ self::delTheLastRecord($uid);
|
|
|
$read_bids = Redis::hgetall('book_read:' . $uid);
|
|
|
$res = [];
|
|
|
$i = 0;
|
|
@@ -127,6 +130,10 @@ class ReadRecordService
|
|
|
//Redis::hset('book_read:'.$uid, $bid, $cid."_".time());
|
|
|
Redis::hset('book_read:' . $uid, $bid, "{$cid}_" . time());*/
|
|
|
Redis::hmset('book_read:' . $uid,'last_read', "{$bid}_{$cid}_" . time(),$bid, "{$cid}_" . time());
|
|
|
+ $num = random_int(1,100);
|
|
|
+ if($num <=3){
|
|
|
+ self::delTheLastRecord($uid);
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
/**
|
|
@@ -528,4 +535,34 @@ class ReadRecordService
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
+ //删除多余的阅读纪律
|
|
|
+ public static function delTheLastRecord($uid){
|
|
|
+ $length = Redis::hlen('book_read:'.$uid);
|
|
|
+ if($length <= self::RECORD_COUNT+count(self::$not_uid_key)){
|
|
|
+ return ;
|
|
|
+ }
|
|
|
+ $read_bids = Redis::hgetall('book_read:' . $uid);
|
|
|
+ $i = 0;
|
|
|
+ foreach ($read_bids as $key => $v) {
|
|
|
+ if(in_array($key,self::$not_uid_key)){
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ $record = explode('_', $v);
|
|
|
+ $latest_read_cid = $record[0];
|
|
|
+ $latest_read_time = $record[count($record) - 1];
|
|
|
+ $res[$i++] = [ 'bid' => $key, 'cid' => (int)$latest_read_cid, 'time' => (int)$latest_read_time];
|
|
|
+ }
|
|
|
+ usort($res, function ($a, $b) {
|
|
|
+ if ($a['time'] >= $b['time']) return -1;
|
|
|
+ return 1;
|
|
|
+ });
|
|
|
+
|
|
|
+ $j = 0;
|
|
|
+ foreach ($res as $v){
|
|
|
+ if($j++ >=self::RECORD_COUNT){
|
|
|
+ Redis::hdel('book_read:'.$uid,$v['bid']);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|