From 2e1834fda2f84c6e01d0bd67616980ccfe47cc6d Mon Sep 17 00:00:00 2001 From: wucongxing8150 <815046773@qq.com> Date: Tue, 5 Mar 2024 17:29:07 +0800 Subject: [PATCH] =?UTF-8?q?=E8=BA=AB=E4=BB=BD=E8=AE=A4=E8=AF=81=E6=96=B0?= =?UTF-8?q?=E5=A2=9E=E5=8C=BB=E7=94=9F=E9=82=AE=E7=AE=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/Model/User.php | 3 ++- app/Request/DoctorAuthRequest.php | 3 +++ app/Services/DoctorAuthService.php | 43 ++++++++++++++++++++++++++++++ app/Utils/PcreMatch.php | 18 +++++++++++++ extend/Wechat/Wechat.php | 6 ----- 5 files changed, 66 insertions(+), 7 deletions(-) diff --git a/app/Model/User.php b/app/Model/User.php index 99d7c37..925b593 100644 --- a/app/Model/User.php +++ b/app/Model/User.php @@ -22,6 +22,7 @@ use Hyperf\Snowflake\Concern\Snowflake; * @property int $register_method 注册方式(1:微信小程序 2:后台添加 ) * @property int $age 年龄 * @property int $sex 性别(0:未知 1:男 2:女) + * @property string $email 邮箱 * @property string $avatar 头像 * @property int $is_online 是否在线(0:不在线 1:在线) * @property string $login_at 小程序登陆时间 @@ -43,7 +44,7 @@ class User extends Model /** * The attributes that are mass assignable. */ - protected array $fillable = ['user_id', 'user_name', 'user_account', 'mobile', 'wx_mobile', 'user_password', 'salt', 'user_type', 'user_status', 'register_method', 'age', 'sex', 'avatar', 'is_online', 'login_at', 'im_login_at', 'login_ip', 'created_by', 'created_at', 'updated_at']; + protected array $fillable = ['user_id', 'user_name', 'user_account', 'mobile', 'wx_mobile', 'user_password', 'salt', 'user_type', 'user_status', 'register_method', 'age', 'sex', 'email', 'avatar', 'is_online', 'login_at', 'im_login_at', 'login_ip', 'created_by', 'created_at', 'updated_at']; protected string $primaryKey = "user_id"; diff --git a/app/Request/DoctorAuthRequest.php b/app/Request/DoctorAuthRequest.php index 13ed055..002b886 100644 --- a/app/Request/DoctorAuthRequest.php +++ b/app/Request/DoctorAuthRequest.php @@ -28,6 +28,7 @@ class DoctorAuthRequest extends FormRequest // 'work_cert', 'doctor_expertise', 'source', + 'email', ], 'addAuthMulti' => [ // 新增多点执业认证信息 'id_card_front', @@ -73,6 +74,7 @@ class DoctorAuthRequest extends FormRequest 'id_card_back' => 'required|url', 'sign_image' => 'required|url', 'source' => 'required|integer|min:1|max:2', + 'email' => 'required', ]; } @@ -117,6 +119,7 @@ class DoctorAuthRequest extends FormRequest 'source.integer' => HttpEnumCode::getMessage(HttpEnumCode::CLIENT_HTTP_ERROR), 'source.min' => HttpEnumCode::getMessage(HttpEnumCode::CLIENT_HTTP_ERROR), 'source.max' => HttpEnumCode::getMessage(HttpEnumCode::CLIENT_HTTP_ERROR), + 'email.required' => HttpEnumCode::getMessage(HttpEnumCode::CLIENT_HTTP_ERROR), ]; } } diff --git a/app/Services/DoctorAuthService.php b/app/Services/DoctorAuthService.php index 471e6d2..74d8a89 100644 --- a/app/Services/DoctorAuthService.php +++ b/app/Services/DoctorAuthService.php @@ -337,6 +337,16 @@ class DoctorAuthService extends BaseService $UserDoctorService = new UserDoctorService(); $result['doctor_expertise'] = $UserDoctorService->getDoctorSelectedExpertise($doctor['doctor_id']); + // 获取用户邮箱 + $result['email'] = ""; + + $params = array(); + $params['user_id'] = $doctor['user_id']; + $user = User::getOne($params); + if (!empty($user)){ + $result['email'] = $user['email']; + } + return success($result); } @@ -369,8 +379,17 @@ class DoctorAuthService extends BaseService return fail(HttpEnumCode::HTTP_ERROR, "审核中,暂不允许修改"); } + // 获取用户数据 + $params = array(); + $params['user_id'] = $doctor['user_id']; + $user = User::getOne($params); + if (empty($user)){ + return fail(HttpEnumCode::HTTP_ERROR, "用户错误"); + } + // 组合存储数据 $doctor_data = array();// 医生 + $user_data = array();// 用户 $doctor_info_data = array();// 医生详情 // 头像 @@ -428,6 +447,16 @@ class DoctorAuthService extends BaseService $doctor_data['be_good_at'] = $request_params['be_good_at']; } + // 邮箱 + if ($user['email'] != $request_params['email']) { + // 验证邮箱 + $res = PcreMatch::validateEmail($request_params['email']); + if (!$res){ + return fail(HttpEnumCode::HTTP_ERROR, "请填写正确邮箱"); + } + $user_data['email'] = $request_params['email']; + } + // 身份认证 if ($request_params['source'] == 1){ // 获取医生详情数据 @@ -602,6 +631,20 @@ class DoctorAuthService extends BaseService } } + // 修改用户邮箱 + if (!empty($user_data)){ + $params = array(); + $params['user_id'] = $user['user_id']; + + $data = array(); + $data['email'] = $request_params['email']; + $res = User::editUser($params, $data); + if (!$res) { + Db::rollBack(); + return fail(HttpEnumCode::SERVER_ERROR); + } + } + Db::commit(); } catch (\Exception $e) { Db::rollBack(); diff --git a/app/Utils/PcreMatch.php b/app/Utils/PcreMatch.php index 47a995f..e848169 100644 --- a/app/Utils/PcreMatch.php +++ b/app/Utils/PcreMatch.php @@ -61,4 +61,22 @@ class PcreMatch return str_replace(config('alibaba.oss.custom_domain_name'),"",$path); } + + /** + * 验证邮箱是否有效 + * @param $email + * @return bool + */ + public static function validateEmail($email): bool + { + // 正则表达式 + $pattern = '/^[\w.%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$/'; + + // 使用 preg_match 进行匹配 + if (preg_match($pattern, $email)) { + return true; // 有效的电子邮件地址 + } else { + return false; // 无效的电子邮件地址 + } + } } \ No newline at end of file diff --git a/extend/Wechat/Wechat.php b/extend/Wechat/Wechat.php index d7dd1d7..edefd57 100644 --- a/extend/Wechat/Wechat.php +++ b/extend/Wechat/Wechat.php @@ -4,15 +4,10 @@ namespace Extend\Wechat; use App\Constants\HttpEnumCode; use App\Exception\BusinessException; -use App\Factory\CacheFactory; -use App\Factory\ProdRedisFactory; use EasyWeChat\Kernel\Exceptions\BadResponseException; use EasyWeChat\Kernel\Exceptions\InvalidArgumentException; use EasyWeChat\Kernel\HttpClient\AccessTokenAwareClient; use EasyWeChat\MiniApp\Application; -use Hyperf\Cache\Cache; -use Hyperf\Redis\Redis; -//use Hyperf\Utils\ApplicationContext; use Psr\Container\ContainerExceptionInterface; use Psr\Container\NotFoundExceptionInterface; use Psr\SimpleCache\CacheInterface; @@ -22,7 +17,6 @@ use Symfony\Contracts\HttpClient\Exception\RedirectionExceptionInterface; use Symfony\Contracts\HttpClient\Exception\ServerExceptionInterface; use Symfony\Contracts\HttpClient\Exception\TransportExceptionInterface; use Hyperf\Context\ApplicationContext; -use Hyperf\Guzzle\CoroutineHandler; /**