|
|
@@ -186,8 +186,7 @@ class MemberService extends BaseService
|
|
|
$this->error = '账号已被冻结,请来奶昔客服~';
|
|
|
return false;
|
|
|
}
|
|
|
-
|
|
|
- $coupon = [];
|
|
|
+
|
|
|
$system = isset($params['system']) ? $params['system'] : [];
|
|
|
$system = $system && !is_array($system) ? json_decode($system, true) : $system;
|
|
|
$appSources = isset($system['app_sources']) && $system['app_sources'] ? $system['app_sources'] : 'ios';
|
|
|
@@ -207,17 +206,31 @@ class MemberService extends BaseService
|
|
|
$inviteInfo = $this->model->where(['id' => $rid, 'mark' => 1])
|
|
|
->select(['id', 'parent_id', 'parents', 'status'])
|
|
|
->first();
|
|
|
+ $rid = isset($inviteInfo['id']) ? $inviteInfo['id'] : 0;
|
|
|
$parents = isset($inviteInfo['parents']) ? $inviteInfo['parents'] : '';
|
|
|
if ($inviteInfo) {
|
|
|
$parents = $parents ? $parents . $rid . ',' : ",{$rid},";
|
|
|
+ }else{
|
|
|
+ $rid = 1;
|
|
|
+ $parents = ',1,';
|
|
|
}
|
|
|
+
|
|
|
+
|
|
|
}else{
|
|
|
$rid = 1;
|
|
|
$parents = ',1,';
|
|
|
}
|
|
|
|
|
|
- // 用户节点推荐人
|
|
|
-
|
|
|
+ // 滑落节点
|
|
|
+ $pointId = 0;
|
|
|
+ $points = '';
|
|
|
+ if($rid>0){
|
|
|
+ $pointId = $this->getPointParentId($rid);
|
|
|
+ if($pointId){
|
|
|
+ $pointParent = $this->model->where(['id'=> $pointId,'mark'=>1])->select(['id','points'])->first();
|
|
|
+ $points = isset($pointParent['points']) ? $pointId.','.$pointParent['points'] : ($pointId ? $pointId . ',' : '');
|
|
|
+ }
|
|
|
+ }
|
|
|
|
|
|
DB::beginTransaction();
|
|
|
$data = [
|
|
|
@@ -227,6 +240,8 @@ class MemberService extends BaseService
|
|
|
'avatar' => $avatar,
|
|
|
'parent_id' => $rid,
|
|
|
'parents' => $parents,
|
|
|
+ 'point_id' => $pointId,
|
|
|
+ 'points' => $points,
|
|
|
'code' => get_random_code(9, 'Q', $userId),
|
|
|
'password' => get_password('a123456'),
|
|
|
'login_ip' => get_client_ip(),
|
|
|
@@ -244,7 +259,6 @@ class MemberService extends BaseService
|
|
|
}
|
|
|
|
|
|
|
|
|
-
|
|
|
DB::commit();
|
|
|
} // 更新登录信息
|
|
|
else if (!RedisService::get("caches:members:login_{$userId}")) {
|
|
|
@@ -269,7 +283,6 @@ class MemberService extends BaseService
|
|
|
$result = [
|
|
|
'access_token' => $token,
|
|
|
'info' => ['uid' => $userId, 'openid' => $openid, 'mobile' => $data['mobile']],
|
|
|
- 'coupon'=>$coupon
|
|
|
];
|
|
|
|
|
|
// 用户缓存信息
|
|
|
@@ -281,6 +294,53 @@ class MemberService extends BaseService
|
|
|
return $result;
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 获取点对点上级节点
|
|
|
+ * @param $userId 推荐人ID
|
|
|
+ * @return int|mixed
|
|
|
+ */
|
|
|
+ public function getPointParentId($userId)
|
|
|
+ {
|
|
|
+ if($userId<=0){
|
|
|
+ return 0;
|
|
|
+ }
|
|
|
+
|
|
|
+ $userList = $this->model->where(['mark'=> 1])->whereRaw('FIND_IN_SET(?,points)', $userId)->select(['id','point_id','points'])->orderBy('create_time','asc')->get();
|
|
|
+ $userList = $userList? $userList->toArray() : [];
|
|
|
+ if(count($userList) < 3){
|
|
|
+ return $userId;
|
|
|
+ }
|
|
|
+
|
|
|
+ $users = [];
|
|
|
+ foreach($userList as $item){
|
|
|
+ $points = isset($item['points']) && $item['points']? explode(',', $item['points']) : [];
|
|
|
+ $points = array_filter($points);
|
|
|
+
|
|
|
+ $users[$item['id']]['pointLen'] = count($points);
|
|
|
+ $users[$item['id']]['children'] = isset($users[$item['id']]['children'])? $users[$item['id']]['children'] : 0;
|
|
|
+ $users[$item['point_id']]['children'] = isset($users[$item['point_id']]['children'])? $users[$item['point_id']]['children'] + 1 : 1;
|
|
|
+ }
|
|
|
+
|
|
|
+ //var_dump($users);
|
|
|
+ $pointId = 0;
|
|
|
+ $tempPointLen = 0;
|
|
|
+ $tempChildren = 0;
|
|
|
+ foreach ($userList as $item) {
|
|
|
+ $id = isset($item['id'])? $item['id'] : 0;
|
|
|
+ $children = isset($users[$id]['children'])? $users[$id]['children'] : 0;
|
|
|
+ $pointLen = isset($users[$id]['pointLen'])? $users[$id]['pointLen'] : 0;
|
|
|
+ if($pointLen<=$tempPointLen || $pointId == 0){
|
|
|
+ if($children <$tempChildren || $pointId == 0){
|
|
|
+ $pointId = $id;
|
|
|
+ $tempPointLen = $pointLen;
|
|
|
+ $tempChildren = $children;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ return $pointId;
|
|
|
+ }
|
|
|
+
|
|
|
|
|
|
/**
|
|
|
* 重置密码
|