Jelajahi Sumber

division user 1

zz 6 tahun lalu
induk
melakukan
fd459d9ddd

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

@@ -17,7 +17,7 @@ use DB;
 class ReadRecordService
 {
 
-    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'];
+    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'];
 
     /**
      * 获取
@@ -499,4 +499,14 @@ class ReadRecordService
         }
         return '';
     }
+
+    public static function setByField(int $uid,$field,$value){
+        if(!in_array($field,self::$not_uid_key)){
+            return false;
+        }
+        try{
+            return Redis::hset('book_read:' . $uid,$field,$value);
+        }catch (\Exception $e){}
+        return '';
+    }
 }

+ 81 - 2
app/Modules/User/Services/UserDivisionPropertyService.php

@@ -13,8 +13,26 @@ use DB;
 
 class userDivisionPropertyService
 {
+
+    const PROPERTY='property';
+
+    public static function getUserProperty($uid){
+        if(($result = self::getUserPropertyFromRedis($uid)))  return $result;
+
+        if(($result = self::getUserPropertyFromTable($uid))) return $result;
+
+        return self::getUserPropertyFromStats($uid);
+    }
+
+    public static function getUserPropertyFromRedis($uid){
+        return ReadRecordService::getByField($uid,self::PROPERTY);
+    }
     public static function getUserPropertyFromTable($uid){
-        return UserDivisionProperty::where('uid',$uid)->where('is_enable',1)->select('property','created_at')->first();
+        $result = UserDivisionProperty::where('uid',$uid)->where('is_enable',1)->select('property','created_at')->first();
+        if($result){
+            return $result->property;
+        }
+        return '';
     }
 
     public static function getUserPropertyFromStats($uid){
@@ -34,7 +52,68 @@ and o.created_at>=f.subscribe_time and o.created_at <= DATE_ADD(f.subscribe_time
             return $item[0]['subscribe_time'];
         });
 
-        print_r($sort->all());
+        foreach ($sort as $key=>$v){
+            if(isset($v[0]) && !empty($v[0])){
+                $charge_amount = $v[0]['price']?$v[0]['price']:0;
+                if($charge_amount >=50){
+                    self::createUser($uid,'high');
+                    ReadRecordService::setByField($uid,self::PROPERTY,'high');
+                    return 'high';
+                }
+                if(time()-strtotime($v[0]['subscribe_time']) >= 3*86400){
+                    //强关时间大于3天
+                    if($charge_amount >=50){
+                        self::createUser($uid,'high');
+                        ReadRecordService::setByField($uid,self::PROPERTY,'high');
+                        return 'high';
+                    }elseif($charge_amount>2){
+                        self::createUser($uid,'medium');
+                        ReadRecordService::setByField($uid,self::PROPERTY,'medium');
+                        return 'medium';
+                    }elseif ($charge_amount==2){
+                        self::createUser($uid,'low');
+                        ReadRecordService::setByField($uid,self::PROPERTY,'low');
+                        return 'low';
+                    }else{
+                        self::createUser($uid,'none');
+                        ReadRecordService::setByField($uid,self::PROPERTY,'none');
+                        return 'none';
+                    }
+                }
+            }
+        }
+        return '';
+    }
+
+    public static function createUser($uid,$property){
+        UserDivisionProperty::where('uid',$uid)->update(['is_enable'=>0]);
+        UserDivisionProperty::create([
+            'uid'=>$uid,
+            'property'=>$property,
+            'is_enable'=>1
+        ]);
+    }
+
+    public static function getUserBindPhoneStatus($uid,$page){
+        $value_format = 'sign_readrecord_%s_%s';
+        if( !($property = self::getUserProperty($uid)) ){
+            return '';
+        }
+        $result = [
+            'sign'=>0,
+            'readrecord'=>0,
+            'is_bind'=>0,
+            'bind_day'=>0
+        ];
+        $info = ReadRecordService::getByField($uid,'bind_phone_status');
+        if($info){
+            $info = json_decode($info,1);
+        }else{
+            $page == 'sign' && $result['sign'] = 1;
+            $page == 'readrecord' && $result['readrecord'] = 1;
+            ReadRecordService::setByField($uid,'bind_phone_status',json_encode($result));
+        }
 
+        return $result;
     }
 }