注册用户,新增用户配置
This commit is contained in:
parent
77dd5c9331
commit
9b096e0060
@ -8,6 +8,7 @@ use App\Model\User as UserModel;
|
|||||||
use App\Model\UserDoctor as UserDoctorModel;
|
use App\Model\UserDoctor as UserDoctorModel;
|
||||||
use App\Model\UserPatient as UserPatientModel;
|
use App\Model\UserPatient as UserPatientModel;
|
||||||
use App\Model\UserPharmacist as UserPharmacistModel;
|
use App\Model\UserPharmacist as UserPharmacistModel;
|
||||||
|
use App\Model\UserSystem;
|
||||||
use App\Utils\Http;
|
use App\Utils\Http;
|
||||||
use App\Utils\Jwt;
|
use App\Utils\Jwt;
|
||||||
use App\Utils\Log;
|
use App\Utils\Log;
|
||||||
@ -42,7 +43,7 @@ class LoginService extends BaseService
|
|||||||
// 获取手机号
|
// 获取手机号
|
||||||
$phone_info = $weChat->getPhone($phone_code);
|
$phone_info = $weChat->getPhone($phone_code);
|
||||||
|
|
||||||
if (empty($phone_info) || empty($phone_info['phone_info']) || empty($phone_info['phone_info']['purePhoneNumber'])){
|
if (empty($phone_info) || empty($phone_info['phone_info']) || empty($phone_info['phone_info']['purePhoneNumber'])) {
|
||||||
return fail(HttpEnumCode::GET_WX_ERROR);
|
return fail(HttpEnumCode::GET_WX_ERROR);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -63,7 +64,7 @@ class LoginService extends BaseService
|
|||||||
// 处理药师特殊情况,后台添加,前台不允许注册
|
// 处理药师特殊情况,后台添加,前台不允许注册
|
||||||
if ($user_type == 3) {
|
if ($user_type == 3) {
|
||||||
Db::rollBack();
|
Db::rollBack();
|
||||||
return fail(HttpEnumCode::HTTP_ERROR,"账号不存在,请联系客服");
|
return fail(HttpEnumCode::HTTP_ERROR, "账号不存在,请联系客服");
|
||||||
}
|
}
|
||||||
|
|
||||||
// 获取用户默认头像oss地址
|
// 获取用户默认头像oss地址
|
||||||
@ -72,7 +73,7 @@ class LoginService extends BaseService
|
|||||||
|
|
||||||
// 新增用户表
|
// 新增用户表
|
||||||
$data = array();
|
$data = array();
|
||||||
$data['user_name'] = 'gdxz' . substr($phone_info['phone_info']['purePhoneNumber'],-4) . mt_rand(10000,99999);
|
$data['user_name'] = 'gdxz' . substr($phone_info['phone_info']['purePhoneNumber'], -4) . mt_rand(10000, 99999);
|
||||||
$data['mobile'] = $phone_info['phone_info']['purePhoneNumber'];
|
$data['mobile'] = $phone_info['phone_info']['purePhoneNumber'];
|
||||||
$data['wx_mobile'] = $phone_info['phone_info']['purePhoneNumber'];
|
$data['wx_mobile'] = $phone_info['phone_info']['purePhoneNumber'];
|
||||||
$data['user_type'] = $user_type;
|
$data['user_type'] = $user_type;
|
||||||
@ -115,17 +116,32 @@ class LoginService extends BaseService
|
|||||||
$client_user_id = $user_doctor['doctor_id'];
|
$client_user_id = $user_doctor['doctor_id'];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 新增用户配置表
|
||||||
|
$params = array();
|
||||||
|
$params['user_id'] = $user['user_id'];
|
||||||
|
$user_system = UserSystem::getOne($params);
|
||||||
|
if (empty($user_system)) {
|
||||||
|
$data = array();
|
||||||
|
$data['user_id'] = $user['user_id'];
|
||||||
|
$data['is_accept_im_message_push'] = 1; // 默认新增一下配置表
|
||||||
|
$user_system = UserSystem::addUserSystem($data);
|
||||||
|
if (empty($user_system)) {
|
||||||
|
Db::rollBack();
|
||||||
|
return fail(HttpEnumCode::SERVER_ERROR);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// 创建im账号
|
// 创建im账号
|
||||||
$account = new Account();
|
$account = new Account();
|
||||||
// 创建单个账号
|
// 创建单个账号
|
||||||
$account->createAccount($user->user_id,$user->user_name,addAliyunOssWebsite($avatar));
|
$account->createAccount($user->user_id, $user->user_name, addAliyunOssWebsite($avatar));
|
||||||
|
|
||||||
if ($user['user_type'] == 1){
|
if ($user['user_type'] == 1) {
|
||||||
// 发放用户优惠卷
|
// 发放用户优惠卷
|
||||||
$CouponService = new CouponService();
|
$CouponService = new CouponService();
|
||||||
|
|
||||||
$res = $CouponService->DistributeCoupon(1,(string)$user->user_id,$user_patient['patient_id']);
|
$res = $CouponService->DistributeCoupon(1, (string)$user->user_id, $user_patient['patient_id']);
|
||||||
if (!$res){
|
if (!$res) {
|
||||||
Db::rollBack();
|
Db::rollBack();
|
||||||
return fail(HttpEnumCode::SERVER_ERROR);
|
return fail(HttpEnumCode::SERVER_ERROR);
|
||||||
}
|
}
|
||||||
@ -144,17 +160,17 @@ class LoginService extends BaseService
|
|||||||
$params['user_id'] = $user->user_id;
|
$params['user_id'] = $user->user_id;
|
||||||
if ($user['user_type'] == 1) {
|
if ($user['user_type'] == 1) {
|
||||||
$result = UserPatientModel::getOne($params);
|
$result = UserPatientModel::getOne($params);
|
||||||
if (!empty($result)){
|
if (!empty($result)) {
|
||||||
$client_user_id = $result['patient_id'];
|
$client_user_id = $result['patient_id'];
|
||||||
}
|
}
|
||||||
} elseif ($user['user_type'] == 2) {
|
} elseif ($user['user_type'] == 2) {
|
||||||
$result = UserDoctorModel::getOne($params);
|
$result = UserDoctorModel::getOne($params);
|
||||||
if (!empty($result)){
|
if (!empty($result)) {
|
||||||
$client_user_id = $result['doctor_id'];
|
$client_user_id = $result['doctor_id'];
|
||||||
}
|
}
|
||||||
} elseif ($user['user_type'] == 3) {
|
} elseif ($user['user_type'] == 3) {
|
||||||
$result = UserPharmacistModel::getOne($params);
|
$result = UserPharmacistModel::getOne($params);
|
||||||
if (!empty($result)){
|
if (!empty($result)) {
|
||||||
$client_user_id = $result['pharmacist_id'];
|
$client_user_id = $result['pharmacist_id'];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -210,7 +226,7 @@ class LoginService extends BaseService
|
|||||||
// 创建单个账号
|
// 创建单个账号
|
||||||
$account->createAccount($user['user_id'], $user['user_name'], $avatar);
|
$account->createAccount($user['user_id'], $user['user_name'], $avatar);
|
||||||
}
|
}
|
||||||
}catch(\Exception $e){
|
} catch (\Exception $e) {
|
||||||
Log::getInstance()->error("IM账号倒入失败");
|
Log::getInstance()->error("IM账号倒入失败");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -224,8 +240,7 @@ class LoginService extends BaseService
|
|||||||
$data = array();
|
$data = array();
|
||||||
$data['login_ip'] = $login_ip ?? "";
|
$data['login_ip'] = $login_ip ?? "";
|
||||||
$data['last_login_at'] = date('Y-m-d H:i:s', time());
|
$data['last_login_at'] = date('Y-m-d H:i:s', time());
|
||||||
|
UserModel::editUser($params, $data);
|
||||||
UserModel::editUser($params,$data);
|
|
||||||
|
|
||||||
// 组合生成token的数据
|
// 组合生成token的数据
|
||||||
$token_user_data = array();
|
$token_user_data = array();
|
||||||
@ -266,16 +281,16 @@ class LoginService extends BaseService
|
|||||||
$user_type = $this->request->input('user_type');
|
$user_type = $this->request->input('user_type');
|
||||||
$wx_code = $this->request->input('wx_code');
|
$wx_code = $this->request->input('wx_code');
|
||||||
|
|
||||||
$app_env = config('app_env','dev');
|
$app_env = config('app_env', 'dev');
|
||||||
if ($app_env != 'dev'){
|
if ($app_env != 'dev') {
|
||||||
$redis = $this->container->get(Redis::class);
|
$redis = $this->container->get(Redis::class);
|
||||||
// 验证验证码
|
// 验证验证码
|
||||||
$sms_code = $redis->get("login_code" . $phone);
|
$sms_code = $redis->get("login_code" . $phone);
|
||||||
if (empty($sms_code)){
|
if (empty($sms_code)) {
|
||||||
return fail(HttpEnumCode::CODE_EXPIRED);
|
return fail(HttpEnumCode::CODE_EXPIRED);
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($sms_code != $code){
|
if ($sms_code != $code) {
|
||||||
return fail(HttpEnumCode::CODE_ERROR);
|
return fail(HttpEnumCode::CODE_ERROR);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -303,7 +318,7 @@ class LoginService extends BaseService
|
|||||||
// 处理药师特殊情况,后台添加,前台不允许注册
|
// 处理药师特殊情况,后台添加,前台不允许注册
|
||||||
if ($user_type == 3) {
|
if ($user_type == 3) {
|
||||||
Db::rollBack();
|
Db::rollBack();
|
||||||
return fail(HttpEnumCode::HTTP_ERROR,"账号不存在,请联系客服");
|
return fail(HttpEnumCode::HTTP_ERROR, "账号不存在,请联系客服");
|
||||||
}
|
}
|
||||||
|
|
||||||
// 获取用户默认头像oss地址
|
// 获取用户默认头像oss地址
|
||||||
@ -312,7 +327,7 @@ class LoginService extends BaseService
|
|||||||
|
|
||||||
// 新增用户表
|
// 新增用户表
|
||||||
$data = array();
|
$data = array();
|
||||||
$data['user_name'] = 'gdxz' . substr($phone,-4) . mt_rand(10000,99999);;
|
$data['user_name'] = 'gdxz' . substr($phone, -4) . mt_rand(10000, 99999);;
|
||||||
$data['mobile'] = $phone;
|
$data['mobile'] = $phone;
|
||||||
$data['wx_mobile'] = $phone;
|
$data['wx_mobile'] = $phone;
|
||||||
$data['user_type'] = $user_type;
|
$data['user_type'] = $user_type;
|
||||||
@ -351,25 +366,40 @@ class LoginService extends BaseService
|
|||||||
return fail(HttpEnumCode::SERVER_ERROR);
|
return fail(HttpEnumCode::SERVER_ERROR);
|
||||||
}
|
}
|
||||||
$client_user_id = $user_doctor['doctor_id'];
|
$client_user_id = $user_doctor['doctor_id'];
|
||||||
}elseif($user['user_type'] == 3){
|
} elseif ($user['user_type'] == 3) {
|
||||||
Db::rollBack();
|
Db::rollBack();
|
||||||
return fail(HttpEnumCode::SERVER_ERROR);
|
return fail(HttpEnumCode::SERVER_ERROR);
|
||||||
}else{
|
} else {
|
||||||
Db::rollBack();
|
Db::rollBack();
|
||||||
return fail(HttpEnumCode::SERVER_ERROR);
|
return fail(HttpEnumCode::SERVER_ERROR);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 新增用户配置表
|
||||||
|
$params = array();
|
||||||
|
$params['user_id'] = $user['user_id'];
|
||||||
|
$user_system = UserSystem::getOne($params);
|
||||||
|
if (empty($user_system)) {
|
||||||
|
$data = array();
|
||||||
|
$data['user_id'] = $user['user_id'];
|
||||||
|
$data['is_accept_im_message_push'] = 1; // 默认新增一下配置表
|
||||||
|
$user_system = UserSystem::addUserSystem($data);
|
||||||
|
if (empty($user_system)) {
|
||||||
|
Db::rollBack();
|
||||||
|
return fail(HttpEnumCode::SERVER_ERROR);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// 创建im账号
|
// 创建im账号
|
||||||
$account = new Account();
|
$account = new Account();
|
||||||
// 创建单个账号
|
// 创建单个账号
|
||||||
$account->createAccount($user->user_id,$user->user_name,addAliyunOssWebsite($avatar));
|
$account->createAccount($user->user_id, $user->user_name, addAliyunOssWebsite($avatar));
|
||||||
|
|
||||||
if ($user['user_type'] == 1){
|
if ($user['user_type'] == 1) {
|
||||||
// 发放用户优惠卷
|
// 发放用户优惠卷
|
||||||
$CouponService = new CouponService();
|
$CouponService = new CouponService();
|
||||||
|
|
||||||
$res = $CouponService->DistributeCoupon(1,(string)$user->user_id,$user_patient['patient_id']);
|
$res = $CouponService->DistributeCoupon(1, (string)$user->user_id, $user_patient['patient_id']);
|
||||||
if (!$res){
|
if (!$res) {
|
||||||
Db::rollBack();
|
Db::rollBack();
|
||||||
return fail(HttpEnumCode::SERVER_ERROR);
|
return fail(HttpEnumCode::SERVER_ERROR);
|
||||||
}
|
}
|
||||||
@ -386,20 +416,20 @@ class LoginService extends BaseService
|
|||||||
$params['user_id'] = $user->user_id;
|
$params['user_id'] = $user->user_id;
|
||||||
if ($user['user_type'] == 1) {
|
if ($user['user_type'] == 1) {
|
||||||
$result = UserPatientModel::getOne($params);
|
$result = UserPatientModel::getOne($params);
|
||||||
if (!empty($result)){
|
if (!empty($result)) {
|
||||||
$client_user_id = $result['patient_id'];
|
$client_user_id = $result['patient_id'];
|
||||||
}
|
}
|
||||||
} elseif ($user['user_type'] == 2) {
|
} elseif ($user['user_type'] == 2) {
|
||||||
$result = UserDoctorModel::getOne($params);
|
$result = UserDoctorModel::getOne($params);
|
||||||
if (!empty($result)){
|
if (!empty($result)) {
|
||||||
$client_user_id = $result['doctor_id'];
|
$client_user_id = $result['doctor_id'];
|
||||||
}
|
}
|
||||||
} elseif ($user['user_type'] == 3) {
|
} elseif ($user['user_type'] == 3) {
|
||||||
$result = UserPharmacistModel::getOne($params);
|
$result = UserPharmacistModel::getOne($params);
|
||||||
if (!empty($result)){
|
if (!empty($result)) {
|
||||||
$client_user_id = $result['pharmacist_id'];
|
$client_user_id = $result['pharmacist_id'];
|
||||||
}
|
}
|
||||||
}else{
|
} else {
|
||||||
Db::rollBack();
|
Db::rollBack();
|
||||||
return fail(HttpEnumCode::SERVER_ERROR);
|
return fail(HttpEnumCode::SERVER_ERROR);
|
||||||
}
|
}
|
||||||
@ -438,6 +468,9 @@ class LoginService extends BaseService
|
|||||||
} elseif ($user['user_type'] == 3) {
|
} elseif ($user['user_type'] == 3) {
|
||||||
$params['pharmacist_id'] = $result['pharmacist_id'];
|
$params['pharmacist_id'] = $result['pharmacist_id'];
|
||||||
$res = UserPharmacistModel::editUserPharmacist($params, $data);
|
$res = UserPharmacistModel::editUserPharmacist($params, $data);
|
||||||
|
} else {
|
||||||
|
Db::rollBack();
|
||||||
|
return fail(HttpEnumCode::USER_STATUS_ERROR);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!$res) {
|
if (!$res) {
|
||||||
@ -455,7 +488,7 @@ class LoginService extends BaseService
|
|||||||
// 创建单个账号
|
// 创建单个账号
|
||||||
$account->createAccount($user['user_id'], $user['user_name'], $avatar);
|
$account->createAccount($user['user_id'], $user['user_name'], $avatar);
|
||||||
}
|
}
|
||||||
}catch(\Exception $e){
|
} catch (\Throwable $e) {
|
||||||
Log::getInstance()->error("IM账号倒入失败");
|
Log::getInstance()->error("IM账号倒入失败");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -469,7 +502,7 @@ class LoginService extends BaseService
|
|||||||
$data = array();
|
$data = array();
|
||||||
$data['login_ip'] = $login_ip ?? "";
|
$data['login_ip'] = $login_ip ?? "";
|
||||||
$data['last_login_at'] = date('Y-m-d H:i:s', time());
|
$data['last_login_at'] = date('Y-m-d H:i:s', time());
|
||||||
UserModel::editUser($params,$data);
|
UserModel::editUser($params, $data);
|
||||||
|
|
||||||
// 组合生成token的数据
|
// 组合生成token的数据
|
||||||
$token_user_data = array();
|
$token_user_data = array();
|
||||||
@ -483,7 +516,9 @@ class LoginService extends BaseService
|
|||||||
$token = $Jwt->encode($token_user_data);
|
$token = $Jwt->encode($token_user_data);
|
||||||
|
|
||||||
// 登录成功,删除验证码
|
// 登录成功,删除验证码
|
||||||
// $redis->del("login_code" . $phone);
|
if ($app_env != 'dev') {
|
||||||
|
$redis->del("login_code" . $phone);
|
||||||
|
}
|
||||||
|
|
||||||
// 组合返回数据
|
// 组合返回数据
|
||||||
$data = array();
|
$data = array();
|
||||||
@ -516,7 +551,7 @@ class LoginService extends BaseService
|
|||||||
$user_info = $this->request->getAttribute("userInfo") ?? [];
|
$user_info = $this->request->getAttribute("userInfo") ?? [];
|
||||||
$wx_code = $this->request->input('wx_code');
|
$wx_code = $this->request->input('wx_code');
|
||||||
|
|
||||||
if (empty($user_info)){
|
if (empty($user_info)) {
|
||||||
return fail(HttpEnumCode::GET_WX_ERROR);
|
return fail(HttpEnumCode::GET_WX_ERROR);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -524,7 +559,7 @@ class LoginService extends BaseService
|
|||||||
$params = array();
|
$params = array();
|
||||||
$params['user_id'] = $user_info['user_id'];
|
$params['user_id'] = $user_info['user_id'];
|
||||||
$user = UserModel::getOne($params);
|
$user = UserModel::getOne($params);
|
||||||
if (empty($user)){
|
if (empty($user)) {
|
||||||
return fail();
|
return fail();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -567,7 +602,7 @@ class LoginService extends BaseService
|
|||||||
$data['open_id'] = $wx_info_data['openid'];
|
$data['open_id'] = $wx_info_data['openid'];
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!empty($data)){
|
if (!empty($data)) {
|
||||||
$data['updated_at'] = date('Y-m-d H:i:s', time());
|
$data['updated_at'] = date('Y-m-d H:i:s', time());
|
||||||
|
|
||||||
$params = array();
|
$params = array();
|
||||||
@ -580,7 +615,7 @@ class LoginService extends BaseService
|
|||||||
} elseif ($user['user_type'] == 3) {
|
} elseif ($user['user_type'] == 3) {
|
||||||
$params['pharmacist_id'] = $result['pharmacist_id'];
|
$params['pharmacist_id'] = $result['pharmacist_id'];
|
||||||
$res = UserPharmacistModel::editUserPharmacist($params, $data);
|
$res = UserPharmacistModel::editUserPharmacist($params, $data);
|
||||||
}else{
|
} else {
|
||||||
$res = false;
|
$res = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -588,9 +623,9 @@ class LoginService extends BaseService
|
|||||||
return fail(HttpEnumCode::SERVER_ERROR);
|
return fail(HttpEnumCode::SERVER_ERROR);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch (\Exception $e) {
|
} catch (\Throwable $e) {
|
||||||
// 此处不进行处理
|
// 此处不进行处理
|
||||||
return fail(HttpEnumCode::GET_WX_ERROR,$e->getMessage());
|
return fail(HttpEnumCode::GET_WX_ERROR, $e->getMessage());
|
||||||
}
|
}
|
||||||
|
|
||||||
return success();
|
return success();
|
||||||
|
|||||||
@ -857,7 +857,13 @@ class UserService extends BaseService
|
|||||||
$params['user_id'] = $user['user_id'];
|
$params['user_id'] = $user['user_id'];
|
||||||
$user_system = UserSystem::getOne($params);
|
$user_system = UserSystem::getOne($params);
|
||||||
if (empty($user_system)){
|
if (empty($user_system)){
|
||||||
return false;
|
$data = array();
|
||||||
|
$data['user_id'] = $user['user_id'];
|
||||||
|
$data['is_accept_im_message_push'] = 1; // 默认新增一下配置表
|
||||||
|
$user_system = UserSystem::addUserSystem($data);
|
||||||
|
if (empty($user_system)){
|
||||||
|
return false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$message = "您有一条新的问诊消息";
|
$message = "您有一条新的问诊消息";
|
||||||
|
|||||||
@ -36,7 +36,7 @@ class Account extends Base
|
|||||||
|
|
||||||
$path = $this->config['base_url'] . $this->version . "/im_open_login_svc/account_import?" . $this->buildRequestParams();
|
$path = $this->config['base_url'] . $this->version . "/im_open_login_svc/account_import?" . $this->buildRequestParams();
|
||||||
return $this->postRequest($path,$options);
|
return $this->postRequest($path,$options);
|
||||||
}catch (\Exception $e) {
|
}catch (\Throwable $e) {
|
||||||
throw new BusinessException($e->getMessage(), HttpEnumCode::SERVER_ERROR);
|
throw new BusinessException($e->getMessage(), HttpEnumCode::SERVER_ERROR);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -74,7 +74,7 @@ class Account extends Base
|
|||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}catch (\Exception $e) {
|
}catch (\Throwable $e) {
|
||||||
throw new BusinessException($e->getMessage(), HttpEnumCode::SERVER_ERROR);
|
throw new BusinessException($e->getMessage(), HttpEnumCode::SERVER_ERROR);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user