|
|
@@ -385,26 +385,52 @@ class MemberService extends BaseService
|
|
|
// 授权
|
|
|
$email = isset($params['email']) ? trim($params['email']) : '';
|
|
|
$mobile = isset($params['mobile']) ? trim($params['mobile']) : '';
|
|
|
+ $registerType = isset($params['type']) ? intval($params['type']) : 1;
|
|
|
$nickname = isset($params['nickname']) ? trim($params['nickname']) : '';
|
|
|
$code = isset($params['code']) ? trim($params['code']) : '';
|
|
|
$scene = isset($params['scene']) ? $params['scene'] : '';
|
|
|
$appSources = isset($params['app_sources']) ? $params['app_sources'] : '';
|
|
|
$inviteCode = isset($params['invite_code']) ? $params['invite_code'] : '';
|
|
|
- if (empty($params) || empty($email) || $code <= 0) {
|
|
|
+ if (empty($params) || $code <= 0 || !in_array($registerType,[1,2])) {
|
|
|
$this->error = 2014;
|
|
|
return false;
|
|
|
}
|
|
|
|
|
|
- // 验证码
|
|
|
- if (!EmailService::make()->check($email, $code, $scene)) {
|
|
|
- $this->error = EmailService::make()->getError();
|
|
|
- return false;
|
|
|
- }
|
|
|
+ // 邮箱注册
|
|
|
+ if($registerType == 1){
|
|
|
+ if(empty($email)){
|
|
|
+ $this->error = 2014;
|
|
|
+ return false;
|
|
|
+ }
|
|
|
|
|
|
- // 验证是否注册
|
|
|
- if($this->model->where(['email'=> $email,'mark'=>1])->value('id')){
|
|
|
- $this->error = 2009;
|
|
|
- return false;
|
|
|
+ // 验证码
|
|
|
+ if (!EmailService::make()->check($email, $code, $scene)) {
|
|
|
+ $this->error = EmailService::make()->getError();
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+
|
|
|
+ // 验证是否注册
|
|
|
+ if($this->model->where(['email'=> $email,'mark'=>1])->value('id')){
|
|
|
+ $this->error = 2009;
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ }else if($registerType == 2){
|
|
|
+ if(empty($mobile)){
|
|
|
+ $this->error = 2014;
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+
|
|
|
+ // 验证码
|
|
|
+ if (!SmsService::make()->check($mobile, $code, $scene)) {
|
|
|
+ $this->error = SmsService::make()->getError();
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+
|
|
|
+ // 验证是否注册
|
|
|
+ if($this->model->where(['mobile'=> $mobile,'mark'=>1])->value('id')){
|
|
|
+ $this->error = 2009;
|
|
|
+ return false;
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
// 推荐人
|
|
|
@@ -438,7 +464,6 @@ class MemberService extends BaseService
|
|
|
$city = isset($ipData['city'])? $ipData['city'] : '';
|
|
|
$emailName = explode('@', $email)[0];
|
|
|
|
|
|
-
|
|
|
// 钱包
|
|
|
$data = [
|
|
|
'parent_id' => $parentId,
|
|
|
@@ -446,8 +471,8 @@ class MemberService extends BaseService
|
|
|
'points' => $points,
|
|
|
'openid' => '',
|
|
|
'avatar' => '',
|
|
|
- 'nickname' => $nickname ? $nickname : '用户'.substr($emailName,-8,8),
|
|
|
- 'username' => $email,
|
|
|
+ 'nickname' => $nickname ? $nickname : 'XL'.substr($emailName,-8,8),
|
|
|
+ 'username' => $registerType==1? $email : $mobile,
|
|
|
'password' => get_password('xl123456'),
|
|
|
'code' => strtoupper(get_random_code(9, 'X', "{$id}")),
|
|
|
'email' => $email,
|
|
|
@@ -456,6 +481,7 @@ class MemberService extends BaseService
|
|
|
'parents' => $parents,
|
|
|
'province_id' => CityService::make()->getFieldByName($province),
|
|
|
'city_id' => CityService::make()->getFieldByName($city),
|
|
|
+ '$city' => $city,
|
|
|
'app_uuid' => isset($system['uuid']) ? $system['uuid'] : '',
|
|
|
'device' => $appSources == 'android' ? 2 : 1,
|
|
|
'status' => 1,
|
|
|
@@ -555,112 +581,34 @@ class MemberService extends BaseService
|
|
|
{
|
|
|
// 授权
|
|
|
$mobile = isset($params['mobile']) ? $params['mobile'] : '';
|
|
|
- $code = isset($params['sms_code']) ? $params['sms_code'] : '';
|
|
|
- $smsType = isset($params['sms_type']) ? $params['sms_type'] : '';
|
|
|
- $nickname = isset($params['nickname']) ? $params['nickname'] : '';
|
|
|
- $openid = isset($params['openid']) ? $params['openid'] : '';
|
|
|
- $avatar = isset($params['avatar']) ? $params['avatar'] : '';
|
|
|
- $regType = isset($params['type']) ? $params['type'] : 'app';
|
|
|
+ $code = isset($params['code']) ? $params['code'] : '';
|
|
|
+ $scene = isset($params['scene']) ? $params['scene'] : '';
|
|
|
$appSources = isset($params['app_sources']) ? $params['app_sources'] : '';
|
|
|
- $inviteCode = isset($params['invite_code']) ? $params['invite_code'] : '';
|
|
|
- if (empty($params) || empty($mobile) || $code <= 0) {
|
|
|
+ if (empty($params) || empty($email) || empty($scene) || $code <= 0) {
|
|
|
$this->error = 2014;
|
|
|
return false;
|
|
|
}
|
|
|
|
|
|
// 验证码
|
|
|
- if (!SmsService::make()->check($mobile, $code, $smsType?$smsType:'login')) {
|
|
|
+ if (!SmsService::make()->check($mobile, $code, $scene)) {
|
|
|
$this->error = SmsService::make()->getError();
|
|
|
return false;
|
|
|
}
|
|
|
|
|
|
- // 推荐人
|
|
|
- $parentId = 0;
|
|
|
- $parents = '';
|
|
|
- if ($inviteCode) {
|
|
|
- $inviteInfo = $this->model->where(['code' => $inviteCode, 'mark' => 1])
|
|
|
- ->select(['id', 'parents', 'parent_id'])
|
|
|
- ->first();
|
|
|
- $parentId = isset($inviteInfo['id']) ? $inviteInfo['id'] : 0;
|
|
|
- $parents = isset($inviteInfo['parents']) ? $inviteInfo['parents'] . $parentId . ',' : ($parentId ? $parentId . ',' : '');
|
|
|
- }
|
|
|
-
|
|
|
// 验证是否注册,没有则注册
|
|
|
- $data = $this->model->with(['merchant','mechanic'])->where(['mobile' => $mobile, 'mark' => 1])->select(['id', 'openid', 'username', 'parent_id', 'code', 'push_cid', 'status'])->first();
|
|
|
+ $data = $this->model->where(['mobile' => $mobile, 'mark' => 1])->select(['id', 'username','point_id','mobile', 'parent_id', 'code', 'status'])->first();
|
|
|
$data = $data ? $data->toArray() : [];
|
|
|
+
|
|
|
$userId = isset($data['id']) ? $data['id'] : 0;
|
|
|
$status = isset($data['status']) ? $data['status'] : 0;
|
|
|
- if ($userId && $status != 1) {
|
|
|
- $this->error = 2015;
|
|
|
+ if(empty($data) || $userId<=0){
|
|
|
+ $this->error = 2001;
|
|
|
return false;
|
|
|
}
|
|
|
|
|
|
- // 是否是商家或技师,有订单提醒
|
|
|
- $noticeUser = ['id'=> 0,'uid'=>$userId,'type'=>1];
|
|
|
- $merchant = isset($data['merchant'])? $data['merchant'] : [];
|
|
|
- $merchantStatus = isset($merchant['status'])? $merchant['status'] : 0;
|
|
|
- $mechanic = isset($data['mechanic'])? $data['mechanic'] : [];
|
|
|
- $mechanicStatus = isset($mechanic['status'])? $mechanic['status'] : 0;
|
|
|
- if($merchantStatus==2){
|
|
|
- $uid = isset($merchant['id'])? $merchant['id'] : 0;
|
|
|
- if($uid>0){
|
|
|
- $noticeUser = ['id'=>$uid,'type'=>2,'uid'=> $userId];
|
|
|
- }
|
|
|
- }else if($mechanicStatus == 2){
|
|
|
- $uid = isset($mechanic['id'])? $mechanic['id'] : 0;
|
|
|
- if($uid>0){
|
|
|
- $noticeUser = ['id'=>$uid,'type'=>3,'uid'=>$userId];
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- $pushCid = isset($params['push_cid']) ? $params['push_cid'] : '';
|
|
|
- if (!$userId) {
|
|
|
- $id = $this->model->max('id') + 1;
|
|
|
- $data = [
|
|
|
- 'parent_id' => $parentId,
|
|
|
- 'openid' => $openid,
|
|
|
- 'avatar' => $avatar,
|
|
|
- 'nickname' => $nickname ? $nickname : get_random_code(4, '用户u').substr($mobile,-4,4),
|
|
|
- 'username' => get_username($id),
|
|
|
- 'password' => get_password('123456'),
|
|
|
- 'code' => strtoupper(get_random_code(8, 'D', "{$id}")),
|
|
|
- 'mobile' => $mobile,
|
|
|
- 'parents' => $parents,
|
|
|
- 'push_cid' => isset($params['push_cid']) ? $params['push_cid'] : '',
|
|
|
- 'app_uuid' => isset($params['uuid']) ? $params['uuid'] : '',
|
|
|
- 'device' => $appSources == 'android' ? 2 : 1,
|
|
|
- 'status' => 1,
|
|
|
- 'balance' => 0,
|
|
|
- 'score' => 0,
|
|
|
- 'mark' => 1,
|
|
|
- 'login_time' => time(),
|
|
|
- 'login_ip' => get_client_ip(),
|
|
|
- 'create_time' => time(),
|
|
|
- ];
|
|
|
-
|
|
|
- $userId = $this->model->insertGetId($data);
|
|
|
- } elseif ($regType != 'h5') {
|
|
|
- // 登录更新
|
|
|
- $updateData = [
|
|
|
- 'app_uuid' => isset($params['uuid']) ? $params['uuid'] : '',
|
|
|
- 'login_count' => DB::raw("login_count+1"),
|
|
|
- 'login_time' => time(),
|
|
|
- 'login_ip' => get_client_ip(),
|
|
|
- 'update_time' => time(),
|
|
|
- ];
|
|
|
- if ($pushCid) {
|
|
|
- $updateData['push_cid'] = $pushCid;
|
|
|
- }
|
|
|
- $this->model->where(['id' => $userId])->update($updateData);
|
|
|
- }
|
|
|
-
|
|
|
- // H5 邀请注册,无需登录
|
|
|
- if ($regType == 'h5') {
|
|
|
- $this->error = $status ? 2023 : 2022;
|
|
|
- return [
|
|
|
- 'app_url' => ConfigService::make()->getConfigByCode("app_{$appSources}_url"),
|
|
|
- 'info' => ['uid' => $userId, 'invite_id' => $parentId, 'username' => $data['username']],
|
|
|
- ];
|
|
|
+ if ($status != 1) {
|
|
|
+ $this->error = 2015;
|
|
|
+ return false;
|
|
|
}
|
|
|
|
|
|
// 获取登录授权token
|
|
|
@@ -670,16 +618,28 @@ class MemberService extends BaseService
|
|
|
// 结果返回
|
|
|
$result = [
|
|
|
'access_token' => $token,
|
|
|
- 'info' => ['uid' => $userId,'notice_user'=>$noticeUser, 'openid' => $data['openid'], 'username' => $data['username']],
|
|
|
+ 'info' => ['uid' => $userId,'parent_id'=> $data['parent_id'], 'username' => $data['username']],
|
|
|
];
|
|
|
|
|
|
// 用户信息
|
|
|
+ $ip = get_client_ip();
|
|
|
+ $updateData = [
|
|
|
+ 'login_time' => time(),
|
|
|
+ 'login_ip' => $ip,
|
|
|
+ ];
|
|
|
+
|
|
|
+ if(!RedisService::get("caches:member:updateArea:{$userId}")){
|
|
|
+ $ipData = ToolService::make()->getIpAddress($ip,'');
|
|
|
+ $province = isset($ipData['regionName'])? $ipData['regionName'] : '';
|
|
|
+ $city = isset($ipData['city'])? $ipData['city'] : '';
|
|
|
+ $updateData['province_id'] = CityService::make()->getFieldByName($province);
|
|
|
+ $updateData['city_id'] = CityService::make()->getFieldByName($city);
|
|
|
+ }
|
|
|
+
|
|
|
+ $this->model->where(['id'=> $userId])->update($updateData);
|
|
|
$this->error = 2004;
|
|
|
$data['token'] = $token;
|
|
|
- unset($data['password']);
|
|
|
- // 实现初始化账单明细表
|
|
|
- AccountLogModel::where('id','<=',1)->value('id');
|
|
|
- RedisService::clear( "caches:map:{$userId}");
|
|
|
+ RedisService::set("caches:member:updateArea:{$userId}", $updateData, 3600);
|
|
|
RedisService::set("auths:info:{$userId}", $data, 3 * 24 * 3600);
|
|
|
return $result;
|
|
|
}
|