修改登录发放优惠卷

This commit is contained in:
wucongxing 2023-11-07 18:52:39 +08:00
parent 3aed48b9a6
commit 90e411aff8
3 changed files with 218 additions and 149 deletions

View File

@ -14,6 +14,7 @@ class SendStationMessageProducer extends ProducerMessage
* @param $data
* [
* "user_id":"用户id接受者",
* "user_type":"用户类型(接受者)",
* "notice_type":"消息类型1:医生服务通知 2:医生系统公告 3:患者系统消息)",
* "notice_system_type":"系统消息类型(患者端系统消息存在 1:服务消息 2:福利消息 3:退款消息 4:物流消息)",
* "inquiry_type:"问诊类型(医生端服务通知存在 1:专家问诊 2:快速问诊 3:公益问诊 4:问诊购药)",

View File

@ -27,7 +27,7 @@ class CouponService extends BaseService
* @param string $user_id 用户id
* @return bool
*/
protected function GrantUserCoupon(string $coupon_id,string $user_id): bool
public function GrantUserCoupon(string $coupon_id,string $user_id): bool
{
// 获取患者数据
$params = array();
@ -97,7 +97,7 @@ class CouponService extends BaseService
'user_coupon_id' => (string)$user_coupon->user_coupon_id, // 优惠卷金额
'coupon_price' => $coupon['coupon_price'], // 优惠卷金额
'application_scope' => $coupon['application_scope'], // 适用范围1:全场通用 2:问诊 3:按品牌适用 4:按类别类别适用 5:单品使用)
'inquiry_type' => $coupon['inquiry_type'], // 关联问诊类型,逗号分隔,适用范围为问诊时存在生效1:专家问诊 2:快速问诊 3:公益问诊 4:问诊购药 5:检测)
'inquiry_type' => $coupon['inquiry_type'], // 关联问诊类型,application_scope=问诊时存在生效,逗号分隔1:专家问诊 2:快速问诊 3:公益问诊 4:问诊购药 5:检测)
'valid_type' => $coupon['valid_type'], // 有效类型1:绝对时效xxx-xxx时间段有效 2:相对时效 n天内有效
'valid_days' => $coupon['valid_days'], // 自领取之日起有效天数
'valid_start_time' => $coupon['valid_start_time'], // 开始使用时间

View File

@ -38,6 +38,7 @@ class LoginService extends BaseService
$wx_code = $this->request->input('wx_code');
$user_type = $this->request->input('user_type');
try {
$weChat = new Wechat($user_type);
// 获取手机号
@ -52,15 +53,23 @@ class LoginService extends BaseService
if (empty($wx_info_data['session_key']) || empty($wx_info_data['openid'])) {
return fail(HttpEnumCode::GET_WX_ERROR);
}
}catch (\Throwable $e){
return fail(HttpEnumCode::GET_WX_ERROR);
}
Db::beginTransaction();
// 定义是否新注册用户标识
$is_new_register = 0;
try {
// 获取用户信息
$params = array();
$params['mobile'] = $phone_info['phone_info']['purePhoneNumber'];
$user = UserModel::getOne($params);
// 新用户
if (empty($user)){
Db::beginTransaction();
try {
// 处理药师特殊情况,后台添加,前台不允许注册
if ($user_type == 3) {
Db::rollBack();
@ -144,18 +153,22 @@ class LoginService extends BaseService
// 创建单个账号
$account->createAccount($user->user_id, $user->user_name, addAliyunOssWebsite($avatar));
if ($user['user_type'] == 1) {
// 发放注册用户优惠卷
$CouponService = new CouponService();
$res = $CouponService->GrantRegisterCoupon($user->user_id);
if (!$res) {
// 标识为新注册用户
$is_new_register = 1;
}catch (\Throwable $e){
Db::rollBack();
return fail(HttpEnumCode::SERVER_ERROR);
return fail(HttpEnumCode::SERVER_ERROR, $e->getMessage());
}
Db::commit();
}
} else {
// 已注册用户
// 重复注册不同端
if (!empty($user)){
Db::beginTransaction();
try {
// 判断是否重复注册不同端
if ($user_type != $user['user_type']) {
Db::rollBack();
$result = UserTypeToString($user['user_type']);
@ -216,12 +229,21 @@ class LoginService extends BaseService
} elseif ($user['user_type'] == 3) {
$params['pharmacist_id'] = $result['pharmacist_id'];
$res = UserPharmacistModel::editUserPharmacist($params, $data);
}else{
Db::rollBack();
return fail(HttpEnumCode::SERVER_ERROR);
}
if (!$res) {
Db::rollBack();
return fail(HttpEnumCode::SERVER_ERROR);
}
}catch (\Throwable $e){
Db::rollBack();
return fail(HttpEnumCode::SERVER_ERROR, $e->getMessage());
}
Db::commit();
try {
$avatar = addAliyunOssWebsite($user['avatar']);
@ -234,9 +256,30 @@ class LoginService extends BaseService
$account->createAccount($user['user_id'], $user['user_name'], $avatar);
}
} catch (\Throwable $e) {
Log::getInstance()->error("IM账号倒入失败");
Log::getInstance()->error("IM账号导入失败");
}
}
// 发放优惠卷-患者
Db::beginTransaction();
try {
if ($user['user_type'] == 1 && $is_new_register == 1) {
$CouponService = new CouponService();
$res = $CouponService->GrantRegisterCoupon($user->user_id);
if (!$res) {
Db::rollBack();
return fail(HttpEnumCode::SERVER_ERROR);
}
}
}catch (\Throwable $e){
Db::rollBack();
return fail(HttpEnumCode::SERVER_ERROR, $e->getMessage());
}
Db::commit();
// 记录用户登陆记录
$Http = new Http();
@ -249,6 +292,7 @@ class LoginService extends BaseService
$data['last_login_at'] = date('Y-m-d H:i:s', time());
UserModel::editUser($params, $data);
// 组合生成token的数据
$token_user_data = array();
$token_user_data['user_id'] = (string)$user['user_id']; // 用户id
@ -266,13 +310,7 @@ class LoginService extends BaseService
$data['user_id'] = (string)$user['user_id'];
$data['client_user_id'] = (string)$client_user_id;
Db::commit();
return success($data);
} catch (\Exception $e) {
Db::rollBack();
return fail(HttpEnumCode::SERVER_ERROR, $e->getMessage());
}
}
/**
@ -309,19 +347,24 @@ class LoginService extends BaseService
$wx_info_data = $weChat->codeToSession($wx_code);
$session_key = $wx_info_data['session_key'] ?? "";
$open_id = $wx_info_data['openid'] ?? "";
} catch (\Exception $e) {
} catch (\Throwable $e) {
// 此处不进行处理
Log::getInstance()->info($e->getMessage());
}
Db::beginTransaction();
// 定义是否新注册用户标识
$is_new_register = 0;
try {
// 获取用户信息
$params = array();
$params['mobile'] = $phone;
$user = UserModel::getOne($params);
// 新用户
if (empty($user)) {
Db::beginTransaction();
try {
// 处理药师特殊情况,后台添加,前台不允许注册
if ($user_type == 3) {
Db::rollBack();
@ -409,16 +452,21 @@ class LoginService extends BaseService
// 创建单个账号
$account->createAccount($user->user_id, $user->user_name, addAliyunOssWebsite($avatar));
if ($user['user_type'] == 1) {
// 发放注册用户优惠卷
$CouponService = new CouponService();
$res = $CouponService->GrantRegisterCoupon($user->user_id);
if (!$res) {
// 标识为新注册用户
$is_new_register = 1;
}catch (\Throwable $e){
Db::rollBack();
return fail(HttpEnumCode::SERVER_ERROR);
return fail(HttpEnumCode::HTTP_ERROR, $e->getMessage());
}
Db::commit();
}
} else {
// 已注册用户
if (!empty($user)){
Db::beginTransaction();
try {
// 已注册用户
if ($user_type != $user['user_type']) {
Db::rollBack();
@ -491,6 +539,12 @@ class LoginService extends BaseService
Db::rollBack();
return fail(HttpEnumCode::SERVER_ERROR);
}
}catch (\Throwable $e){
Db::rollBack();
return fail(HttpEnumCode::HTTP_ERROR, $e->getMessage());
}
Db::commit();
try {
$avatar = addAliyunOssWebsite($user['avatar']);
@ -503,10 +557,29 @@ class LoginService extends BaseService
$account->createAccount($user['user_id'], $user['user_name'], $avatar);
}
} catch (\Throwable $e) {
Log::getInstance()->error("IM账号入失败");
Log::getInstance()->error("IM账号入失败");
}
}
// 发放优惠卷-患者
Db::beginTransaction();
try {
if ($user['user_type'] == 1 && $is_new_register == 1) {
$CouponService = new CouponService();
$res = $CouponService->GrantRegisterCoupon($user->user_id);
if (!$res) {
Db::rollBack();
return fail(HttpEnumCode::SERVER_ERROR);
}
}
}catch (\Throwable $e){
Db::rollBack();
return fail(HttpEnumCode::SERVER_ERROR, $e->getMessage());
}
Db::commit();
// 记录用户登陆记录
$Http = new Http();
$login_ip = $Http->getIp();
@ -542,11 +615,6 @@ class LoginService extends BaseService
Db::commit();
return success($data);
} catch (\Throwable $e) {
Db::rollBack();
return fail(HttpEnumCode::HTTP_ERROR, $e->getMessage());
}
}
/**