|
|
@@ -15,10 +15,11 @@ use App\Helpers\Jwt;
|
|
|
use App\Models\ActionLogModel;
|
|
|
use App\Models\MemberModel;
|
|
|
use App\Services\BaseService;
|
|
|
+use App\Services\MpService;
|
|
|
use App\Services\RedisService;
|
|
|
use App\Services\SmsService;
|
|
|
-use Illuminate\Support\Facades\DB;
|
|
|
use phpQrcode\QRcode;
|
|
|
+use Illuminate\Support\Facades\DB;
|
|
|
|
|
|
/**
|
|
|
* 会员管理-服务类
|
|
|
@@ -134,238 +135,162 @@ class MemberService extends BaseService
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
- * 重置密码
|
|
|
- * @param $params
|
|
|
+ * 授权登录
|
|
|
+ * @param $code
|
|
|
+ * @param array $params
|
|
|
* @return array|false
|
|
|
*/
|
|
|
- public function forget($params)
|
|
|
+ public function mpAuth($code, $params=[])
|
|
|
{
|
|
|
// 账号登录
|
|
|
- $mobile = isset($params['mobile']) ? trim($params['mobile']) : '';
|
|
|
- $password = isset($params['password']) ? trim($params['password']) : '';
|
|
|
- if (empty($params) || empty($mobile) || empty($password)) {
|
|
|
+ if (empty($code)) {
|
|
|
$this->error = 1041;
|
|
|
return false;
|
|
|
}
|
|
|
|
|
|
- // 验证码验证
|
|
|
- $smsCode = isset($params['sms_code']) ? trim($params['sms_code']) : '';
|
|
|
- if (!SmsService::make()->check($mobile, $smsCode, 'reset_password')) {
|
|
|
- $this->error = SmsService::make()->getError();
|
|
|
- return false;
|
|
|
- }
|
|
|
-
|
|
|
- // 验证是否注册
|
|
|
- if (!$userId = $this->model->where(['mobile' => $mobile, 'mark' => 1])->value('id')) {
|
|
|
- $this->error = 1038;
|
|
|
- return false;
|
|
|
- }
|
|
|
-
|
|
|
- if(!$this->model->where(['id'=>$userId])->update(['password'=> get_password($password),'update_time'=>time()])){
|
|
|
- $this->error = 2030;
|
|
|
- return false;
|
|
|
+ // 获取授权用户信息
|
|
|
+ $phone = '';
|
|
|
+ $pcode = isset($params['pcode'])? $params['pcode'] : '';
|
|
|
+ if($pcode){
|
|
|
+ $phoneData = MpService::make()->getPhoneNumber($pcode);
|
|
|
+ $phoneData = isset($phoneData['phone_info'])? $phoneData['phone_info'] : [];
|
|
|
+ $phone = isset($phoneData['phoneNumber'])? $phoneData['phoneNumber'] : '';
|
|
|
}
|
|
|
|
|
|
- // 操作日志
|
|
|
- ActionLogModel::setRecord($userId,['type'=>2,'title'=>'重置密码','content'=>'重置登录密码','module'=>'member']);
|
|
|
- ActionLogModel::record();
|
|
|
-
|
|
|
- $this->error = 2031;
|
|
|
- return true;
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * 账号注册
|
|
|
- * @param $params
|
|
|
- * @return array|false
|
|
|
- */
|
|
|
- public function register($params)
|
|
|
- {
|
|
|
- // 账号登录
|
|
|
- $mobile = isset($params['mobile']) ? trim($params['mobile']) : '';
|
|
|
- $password = isset($params['password']) ? trim($params['password']) : '';
|
|
|
- $nickname = isset($params['nockname']) ? trim($params['nockname']) : '';
|
|
|
- if (empty($params) || empty($mobile) || empty($password)) {
|
|
|
- $this->error = 1041;
|
|
|
+ $userInfo = MpService::make()->getUserInfo($code);
|
|
|
+ $openid = isset($userInfo['openid'])? $userInfo['openid'] : '';
|
|
|
+ if(empty($userInfo)){
|
|
|
+ $this->error = MpService::make()->getError();
|
|
|
return false;
|
|
|
}
|
|
|
|
|
|
- // 验证码验证
|
|
|
- $smsCode = isset($params['sms_code'])? trim($params['sms_code']) : '';
|
|
|
- if (!SmsService::make()->check($mobile, $smsCode, 'register')) {
|
|
|
- $this->error = SmsService::make()->getError();
|
|
|
+ if(empty($openid)){
|
|
|
+ $this->error = 1042;
|
|
|
return false;
|
|
|
}
|
|
|
|
|
|
- // 验证是否注册
|
|
|
- if($this->model->where(['mobile' => $mobile, 'mark' => 1])->value('id')){
|
|
|
- $this->error = 2002;
|
|
|
- return false;
|
|
|
+ $where = ['openid' => $openid, 'mark' => 1];
|
|
|
+ if($phone){
|
|
|
+ $where['mobile'] = $phone;
|
|
|
}
|
|
|
|
|
|
- // 驾驶证
|
|
|
- $drivingLicense = isset($params['driving_license']) && $params['driving_license']? get_image_path($params['driving_license']) : '';
|
|
|
- if (empty($drivingLicense)) {
|
|
|
- $this-> error = 2007;
|
|
|
+ // 验证是否注册,没有则注册
|
|
|
+ $data = $this->model->where($where)
|
|
|
+ ->select(['id','openid', 'mobile', 'user_type', 'nickname','entry_type','need_paper', 'code', 'status'])
|
|
|
+ ->first();
|
|
|
+ $data = $data ? $data->toArray() : [];
|
|
|
+ $userId = isset($data['id']) ? $data['id'] : 0;
|
|
|
+ $status = isset($data['status']) ? $data['status'] : 0;
|
|
|
+ $entryType = isset($data['entry_type']) ? $data['entry_type'] : 0;
|
|
|
+ $needPaper = isset($data['need_paper']) ? $data['need_paper'] : 0;
|
|
|
+ if ($data && $userId && $status != 1) {
|
|
|
+ $this->error = 2011;
|
|
|
return false;
|
|
|
}
|
|
|
|
|
|
- // 行驶证
|
|
|
- $driversLicense = isset($params['drivers_license']) && $params['drivers_license']? get_image_path($params['drivers_license']) : '';
|
|
|
- if (empty($driversLicense)) {
|
|
|
- $this-> error = 2008;
|
|
|
- return false;
|
|
|
- }
|
|
|
|
|
|
- $id = $this->model->max('id') + 1;
|
|
|
$system = isset($params['system'])? $params['system'] : [];
|
|
|
$system = $system && !is_array($system)? json_decode($system,true) : $system;
|
|
|
- $appSources = isset($system['app_sources']) ? $system['app_sources'] : '';
|
|
|
- $uuid = isset($system['uuid']) ? $system['uuid'] : '';
|
|
|
- $data = [
|
|
|
- 'mobile'=> $mobile,
|
|
|
- 'user_type'=> 2,
|
|
|
- 'avatar'=> '',
|
|
|
- 'nickname'=> $nickname ? $nickname : 'DU'.rand(10,99).substr($mobile,-6,6),
|
|
|
- 'realname'=> isset($params['realname'])? trim($params['realname']) : '',
|
|
|
- 'password'=> get_password($password),
|
|
|
- 'car_number'=> isset($params['car_number'])? trim($params['car_number']) : '',
|
|
|
- 'car_type'=> isset($params['car_type'])? trim($params['car_type']) : '',
|
|
|
- 'driving_license'=> $drivingLicense,
|
|
|
- 'drivers_license'=> $driversLicense,
|
|
|
- 'code'=> strtoupper(get_random_code(9, 'D', "{$id}")),
|
|
|
- 'app_uuid' => $uuid,
|
|
|
- 'device' => $appSources == 'android' ? 2 : 1,
|
|
|
- 'create_time'=> time(),
|
|
|
- 'status' => 1,
|
|
|
- 'picker_status' => 1,
|
|
|
- 'confirm_remark' => '',
|
|
|
- 'confirm_status' => 2,
|
|
|
- 'balance' => 0,
|
|
|
- 'deposit' => 0,
|
|
|
- 'mark' => 1,
|
|
|
- 'login_ip' => get_client_ip(),
|
|
|
- ];
|
|
|
+ $appSources = isset($system['app_sources']) && $system['app_sources']? $system['app_sources'] : 'ios';
|
|
|
+ $uuid = isset($system['uuid'])? $system['uuid'] : '';
|
|
|
+ $version = isset($system['app_version'])? $system['app_version'] : '';
|
|
|
+ if(empty($data)){
|
|
|
+ // 手机号码验证
|
|
|
+ if($this->model->where(['mobile'=> $phone,'mark'=>1])->value('id')){
|
|
|
+ $this->error = 2013;
|
|
|
+ return false;
|
|
|
+ }
|
|
|
|
|
|
- if(!$userId = $this->model->insertGetId($data)){
|
|
|
- $this-> error = 2003;
|
|
|
- return false;
|
|
|
+ $userId = $this->model->max('id')+1;
|
|
|
+ $data = [
|
|
|
+ 'nickname'=> $phone? '微信用户'.substr($phone,-6,6) : '微信用户'.$userId,
|
|
|
+ 'openid'=> $openid,
|
|
|
+ 'mobile'=> $phone,
|
|
|
+ 'login_ip'=> get_client_ip(),
|
|
|
+ 'create_time'=> time(),
|
|
|
+ 'login_time'=> time(),
|
|
|
+ 'login_count'=> DB::raw("login_count+1"),
|
|
|
+ 'app_version'=> $version,
|
|
|
+ 'app_uuid'=> $uuid,
|
|
|
+ 'device'=> $appSources=='ios'? 1 : 2,
|
|
|
+ ];
|
|
|
+ if($this->model->insertGetId($data)){
|
|
|
+ $this->error = 2012;
|
|
|
+ return false;
|
|
|
+ }
|
|
|
}
|
|
|
-
|
|
|
+ // 更新登录信息
|
|
|
+ else if(!RedisService::get("caches:members:login_{$userId}")){
|
|
|
+ $updateData = [
|
|
|
+ 'login_ip'=> get_client_ip(),
|
|
|
+ 'create_time'=> time(),
|
|
|
+ 'login_time'=> time(),
|
|
|
+ 'app_uuid'=> $uuid,
|
|
|
+ 'login_count'=> DB::raw("login_count+1"),
|
|
|
+ 'app_version'=> $version,
|
|
|
+ 'device'=> $appSources=='ios'? 1 : 2,
|
|
|
+ ];
|
|
|
+ $this->model->where(['id'=> $userId])->update($updateData);
|
|
|
+ RedisService::set("caches:members:login_{$userId}",$updateData, rand(180,300));
|
|
|
+ }
|
|
|
+
|
|
|
// 获取登录授权token
|
|
|
$jwt = new Jwt('jwt_jd_app');
|
|
|
$token = $jwt->getToken($userId);
|
|
|
|
|
|
// 结果返回
|
|
|
+ $setEntry = $entryType && $needPaper? 1 : 0;
|
|
|
$result = [
|
|
|
'access_token' => $token,
|
|
|
- 'info' => ['uid' => $userId,'nickname' => $data['nickname']],
|
|
|
+ 'info' => ['uid' => $userId,'openid'=>$openid,'set_entry'=>$setEntry,'nickname' => $data['nickname']],
|
|
|
];
|
|
|
|
|
|
- // 注册成功
|
|
|
- $this->error = 2004;
|
|
|
+ // 用户缓存信息
|
|
|
+ $this->error = 2013;
|
|
|
$data['token'] = $token;
|
|
|
- unset($data['password']);
|
|
|
unset($data['mobile']);
|
|
|
- RedisService::keyDel("caches:members:count*");
|
|
|
RedisService::set("auths:info:{$userId}", $data, 24 * 3600);
|
|
|
return $result;
|
|
|
}
|
|
|
|
|
|
-
|
|
|
/**
|
|
|
- * 注册资料重新提交
|
|
|
- * @param $userId
|
|
|
+ * 重置密码
|
|
|
* @param $params
|
|
|
- * @return bool
|
|
|
+ * @return array|false
|
|
|
*/
|
|
|
- public function profileModify($userId, $params)
|
|
|
+ public function forget($params)
|
|
|
{
|
|
|
- $cacheLockKey = "caches:members:profile_modify_{$userId}";
|
|
|
- if(RedisService::get($cacheLockKey)){
|
|
|
- $this->error = 1034;
|
|
|
+ // 账号登录
|
|
|
+ $mobile = isset($params['mobile']) ? trim($params['mobile']) : '';
|
|
|
+ $password = isset($params['password']) ? trim($params['password']) : '';
|
|
|
+ if (empty($params) || empty($mobile) || empty($password)) {
|
|
|
+ $this->error = 1041;
|
|
|
return false;
|
|
|
}
|
|
|
|
|
|
- // 用户验证
|
|
|
- RedisService::set($cacheLockKey, ['user_id'=> $userId,'params'=>$params], rand(2,3));
|
|
|
- $info = $this->model->where(['id' => $userId, 'mark' => 1])
|
|
|
- ->select(['id', 'password','confirm_status', 'status'])
|
|
|
- ->first();
|
|
|
- $confirmStatus = isset($info['confirm_status']) ? $info['confirm_status'] : 0;
|
|
|
- if (!$info || $info['status'] != 1) {
|
|
|
- $this->error = 2016;
|
|
|
- RedisService::clear($cacheLockKey);
|
|
|
+ // 验证码验证
|
|
|
+ $smsCode = isset($params['sms_code']) ? trim($params['sms_code']) : '';
|
|
|
+ if (!SmsService::make()->check($mobile, $smsCode, 'reset_password')) {
|
|
|
+ $this->error = SmsService::make()->getError();
|
|
|
return false;
|
|
|
}
|
|
|
|
|
|
- if($confirmStatus == 1){
|
|
|
- $this->error = 2041;
|
|
|
- RedisService::clear($cacheLockKey);
|
|
|
+ // 验证是否注册
|
|
|
+ if (!$userId = $this->model->where(['mobile' => $mobile, 'mark' => 1])->value('id')) {
|
|
|
+ $this->error = 1038;
|
|
|
return false;
|
|
|
}
|
|
|
|
|
|
- // 验证码验证(不传不验证)
|
|
|
- $mobile = isset($params['mobile'])? trim($params['mobile']) : '';
|
|
|
- $smsCode = isset($params['sms_code'])? trim($params['sms_code']) : '';
|
|
|
- if (isset($params['sms_code']) && !SmsService::make()->check($mobile, $smsCode, 'profile')) {
|
|
|
- $this->error = SmsService::make()->getError();
|
|
|
+ if(!$this->model->where(['id'=>$userId])->update(['password'=> get_password($password),'update_time'=>time()])){
|
|
|
+ $this->error = 2030;
|
|
|
return false;
|
|
|
}
|
|
|
|
|
|
- //
|
|
|
- $data = ['confirm_status'=>2,'confirm_remark'=>'','create_time'=>time(),'update_time' => time()];
|
|
|
-
|
|
|
- // 修改数据(不传不修改)
|
|
|
- if (isset($params['mobile']) && $mobile) {
|
|
|
- $data['mobile'] = $mobile;
|
|
|
- }
|
|
|
-
|
|
|
- $realname = isset($params['realname']) ? trim($params['realname']) : '';
|
|
|
- if (isset($params['realname']) && $realname) {
|
|
|
- $data['realname'] = $realname;
|
|
|
- }
|
|
|
-
|
|
|
- $carType = isset($params['car_type']) ? trim($params['car_type']) : '';
|
|
|
- if (isset($params['car_type']) && $carType) {
|
|
|
- $data['car_type'] = $carType;
|
|
|
- }
|
|
|
-
|
|
|
- $carNumber = isset($params['car_number']) ? trim($params['car_number']) : '';
|
|
|
- if (isset($params['car_number']) && $carNumber) {
|
|
|
- $data['car_number'] = $carNumber;
|
|
|
- }
|
|
|
-
|
|
|
- // 驾驶证
|
|
|
- $drivingLicense = isset($params['driving_license']) && $params['driving_license']? get_image_path($params['driving_license']) : '';
|
|
|
- if (isset($params['driving_license'])){
|
|
|
- if(empty($drivingLicense)) {
|
|
|
- $this-> error = 2007;
|
|
|
- return false;
|
|
|
- }
|
|
|
-
|
|
|
- $data['driving_license'] = $drivingLicense;
|
|
|
- }
|
|
|
-
|
|
|
- // 行驶证
|
|
|
- $driversLicense = isset($params['drivers_license']) && $params['drivers_license']? get_image_path($params['drivers_license']) : '';
|
|
|
- if(isset($params['drivers_license'])){
|
|
|
- if (empty($driversLicense)) {
|
|
|
- $this-> error = 2008;
|
|
|
- return false;
|
|
|
- }
|
|
|
-
|
|
|
- $data['drivers_license'] = $driversLicense;
|
|
|
- }
|
|
|
-
|
|
|
- if (!$this->model->where(['id' => $userId])->update($data)) {
|
|
|
- $this->error = 2010;
|
|
|
- RedisService::clear($cacheLockKey);
|
|
|
- return false;
|
|
|
- }
|
|
|
+ // 操作日志
|
|
|
+ ActionLogModel::setRecord($userId,['type'=>2,'title'=>'重置密码','content'=>'重置登录密码','module'=>'member']);
|
|
|
+ ActionLogModel::record();
|
|
|
|
|
|
- $this->error = 2011;
|
|
|
- RedisService::clear($cacheLockKey);
|
|
|
+ $this->error = 2031;
|
|
|
return true;
|
|
|
}
|
|
|
|
|
|
@@ -382,7 +307,7 @@ class MemberService extends BaseService
|
|
|
return $info;
|
|
|
}
|
|
|
|
|
|
- $defaultField = ['id', 'user_type', 'realname', 'mobile', 'nickname','balance','deposit', 'code', 'openid','picker_status','confirm_status', 'status', 'avatar'];
|
|
|
+ $defaultField = ['id', 'user_type', 'realname', 'mobile', 'nickname','balance', 'code', 'openid', 'status', 'avatar'];
|
|
|
$field = $field ? $field : $defaultField;
|
|
|
if (is_array($where)) {
|
|
|
$info = $this->model->where(['mark' => 1])->where($where)->select($field)->first();
|
|
|
@@ -396,14 +321,6 @@ class MemberService extends BaseService
|
|
|
$info['avatar'] = $info['avatar'] ? get_image_url($info['avatar']) : '';
|
|
|
}
|
|
|
|
|
|
- if (isset($info['driving_license'])) {
|
|
|
- $info['driving_license'] = $info['driving_license'] ? get_image_url($info['driving_license']) : '';
|
|
|
- }
|
|
|
-
|
|
|
- if (isset($info['drivers_license'])) {
|
|
|
- $info['drivers_license'] = $info['drivers_license'] ? get_image_url($info['drivers_license']) : '';
|
|
|
- }
|
|
|
-
|
|
|
if (isset($info['mobile'])) {
|
|
|
$info['mobile_text'] = $info['mobile'] ? format_mobile($info['mobile']) : '';
|
|
|
}
|
|
|
@@ -412,12 +329,6 @@ class MemberService extends BaseService
|
|
|
$info['create_at'] = datetime(strtotime($info['create_time']));
|
|
|
}
|
|
|
|
|
|
- if(isset($info['confirm_remark'])){
|
|
|
- $info['confirm_remark'] = $info['confirm_remark']?format_content($info['confirm_remark']):'';
|
|
|
- }
|
|
|
-
|
|
|
- $info['unread_count'] = intval(MessageService::make()->getUnreadCount($info['id']));
|
|
|
-
|
|
|
RedisService::set($cacheKey, $info, rand(10, 20));
|
|
|
}
|
|
|
|
|
|
@@ -511,11 +422,6 @@ class MemberService extends BaseService
|
|
|
$data['mobile'] = $mobile;
|
|
|
}
|
|
|
|
|
|
- $address = isset($params['address']) ? $params['address'] : '';
|
|
|
- if (isset($params['address']) && $address) {
|
|
|
- $data['address'] = $address;
|
|
|
- }
|
|
|
-
|
|
|
$password = isset($params['password']) ? $params['password'] : '';
|
|
|
$newPassword = isset($params['new_password']) ? $params['new_password'] : '';
|
|
|
if (isset($params['password']) && $password) {
|
|
|
@@ -556,4 +462,46 @@ class MemberService extends BaseService
|
|
|
}
|
|
|
|
|
|
|
|
|
+ /**
|
|
|
+ * 设置入口类型
|
|
|
+ * @param $userId
|
|
|
+ * @param $params
|
|
|
+ * @return bool
|
|
|
+ */
|
|
|
+ public function setEntry($userId, $params)
|
|
|
+ {
|
|
|
+ $cacheLockKey = "caches:members:entry_{$userId}";
|
|
|
+ if(RedisService::get($cacheLockKey)){
|
|
|
+ $this->error = 1034;
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+
|
|
|
+ // 用户验证
|
|
|
+ RedisService::set($cacheLockKey, ['user_id'=> $userId,'params'=>$params], rand(2,3));
|
|
|
+ $info = $this->model->where(['id' => $userId, 'mark' => 1])
|
|
|
+ ->select(['id', 'password', 'status'])
|
|
|
+ ->first();
|
|
|
+ if (!$info || $info['status'] != 1) {
|
|
|
+ $this->error = 1043;
|
|
|
+ RedisService::clear($cacheLockKey);
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+
|
|
|
+ // 密码校验
|
|
|
+ $data = [
|
|
|
+ 'entry_type'=> isset($params['entry_type'])? intval($params['entry_type']) : 0,
|
|
|
+ 'need_paper'=> isset($params['need_paper'])? intval($params['need_paper']) : 0,
|
|
|
+ 'update_time' => time()
|
|
|
+ ];
|
|
|
+
|
|
|
+ if (!$this->model->where(['id' => $userId])->update($data)) {
|
|
|
+ $this->error = 1020;
|
|
|
+ RedisService::clear($cacheLockKey);
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+
|
|
|
+ $this->error = 1019;
|
|
|
+ RedisService::clear($cacheLockKey);
|
|
|
+ return true;
|
|
|
+ }
|
|
|
}
|