|
@@ -9,6 +9,7 @@
|
|
|
namespace App\Modules\User\Services;
|
|
|
|
|
|
use App\Modules\User\Models\UserDivisionCpcProperty;
|
|
|
+use App\Modules\User\Models\UserDivisionCpcPropertyV2;
|
|
|
use DB;
|
|
|
|
|
|
class UserDivisionCpcPropertyService
|
|
@@ -213,4 +214,77 @@ WHERE u.openid in (SELECT openid from users WHERE id = %s)";
|
|
|
);
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
+ /**
|
|
|
+ * Openid一对一注册uid,充值超过30元直接成为高净值用户,否则注册3天后做净值分档;
|
|
|
+ * Openid一对多注册uid,注册3天以上成为有效uid,有效uid充值总额比uid个数;
|
|
|
+ * 净值区间无论一对一注册uid还是一对多注册uid:
|
|
|
+ * 低净值:0<充值<10,openid数占比35.51%,充值占比6.03%;
|
|
|
+ * 中净值:10=<充值<=30,openid数占比32.89%,充值占比23.81%;
|
|
|
+ * 高净值:充值>30,openid数占比31.60%,充值占比70.16%;
|
|
|
+ * @param $uid
|
|
|
+ */
|
|
|
+ public static function calculateUserPropertyV2($uid)
|
|
|
+ {
|
|
|
+ $sql = "SELECT users.id as uid,users.openid,users.created_at as register,(select SUM(price) from orders where orders.uid = users.id and `status` = 'PAID') as price FROM users
|
|
|
+WHERE openid in (SELECT openid FROM users WHERE id = $uid)";
|
|
|
+ $result = DB::select($sql);
|
|
|
+ if (!$result) return [];
|
|
|
+ if(count($result) == 1 ){
|
|
|
+ if($result[0]->price && $result[0]->price>30){
|
|
|
+ return ['openid'=>$result[0]->openid,'property'=>'high'];
|
|
|
+ }
|
|
|
+ if(time()-strtotime($result[0]->register) < 3*86400){
|
|
|
+ return ['openid'=>$result[0]->openid,'property'=>'undefined'];
|
|
|
+ }
|
|
|
+ }
|
|
|
+ $valid_user_num = 0;
|
|
|
+ $amount = 0;
|
|
|
+ $openid = '';
|
|
|
+ $all_amount = 0;
|
|
|
+ foreach ($result as $item){
|
|
|
+ $openid = $item->openid;
|
|
|
+ if($item->price) $all_amount += $item->price;
|
|
|
+ if(time()-strtotime($item->register) < 3*86400) continue;
|
|
|
+ if($item->price) $amount += $item->price;
|
|
|
+ $valid_user_num += 1;
|
|
|
+ }
|
|
|
+ if(!$valid_user_num){
|
|
|
+ if($all_amount)return ['openid'=>$openid,'property'=>'undefined'];
|
|
|
+ return [];
|
|
|
+ }
|
|
|
+
|
|
|
+ $average_amount = $amount/$valid_user_num;
|
|
|
+ if($average_amount >30){
|
|
|
+ return ['openid'=>$openid,'property'=>'high'];
|
|
|
+ }elseif ($average_amount >=10){
|
|
|
+ return ['openid'=>$openid,'property'=>'medium'];
|
|
|
+ }else{
|
|
|
+ return ['openid'=>$openid,'property'=>'low'];
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ public static function userLevelV2($openid){
|
|
|
+ $result = UserDivisionCpcPropertyV2::where('openid',$openid)->where('is_enable',1)->select('property')->first();
|
|
|
+ if($result)
|
|
|
+ return $result->property;
|
|
|
+ return 'none';
|
|
|
+ }
|
|
|
+
|
|
|
+ public static function getUserPropertyV2($uid){
|
|
|
+ $result = UserDivisionCpcPropertyV2::join('users','users.openid','=','user_division_cpc_property_v2.openid')
|
|
|
+ ->where('users.id',$uid)
|
|
|
+ ->select('user_division_cpc_property_v2.property')->first();
|
|
|
+ if($result)
|
|
|
+ return $result->property;
|
|
|
+ return '';
|
|
|
+ }
|
|
|
+
|
|
|
+ public static function updateV2($openid,$property=''){
|
|
|
+ if(empty($property)) return ;
|
|
|
+ $update_info = [];
|
|
|
+ $property && $update_info['property'] = $property;
|
|
|
+
|
|
|
+ UserDivisionCpcPropertyV2::where('openid',$openid)->where('is_enable',1)->update($update_info);
|
|
|
+ }
|
|
|
}
|