From a221698605c8c586eb91806288135634d32e05da Mon Sep 17 00:00:00 2001 From: liutong <836164388@qq.com> Date: Fri, 30 May 2025 16:41:14 +0800 Subject: [PATCH] =?UTF-8?q?feat(api):=20=E6=B7=BB=E5=8A=A0=E5=BF=98?= =?UTF-8?q?=E8=AE=B0=E5=AF=86=E7=A0=81=E5=8A=9F=E8=83=BD-=20=E5=9C=A8=20Co?= =?UTF-8?q?mmon=20=E6=8E=A7=E5=88=B6=E5=99=A8=E4=B8=AD=E6=B7=BB=E5=8A=A0?= =?UTF-8?q?=20forgetPassword=20=E6=96=B9=E6=B3=95=EF=BC=8C=E7=94=A8?= =?UTF-8?q?=E4=BA=8E=E9=87=8D=E7=BD=AE=E5=AF=86=E7=A0=81=20-=20=E5=9C=A8?= =?UTF-8?q?=E8=B7=AF=E7=94=B1=E6=96=87=E4=BB=B6=E4=B8=AD=E6=B7=BB=E5=8A=A0?= =?UTF-8?q?=E5=AF=B9=E5=BA=94=E7=9A=84=20API=20=E8=B7=AF=E7=94=B1=20-=20?= =?UTF-8?q?=E5=9C=A8=20CommonService=20=E4=B8=AD=E5=AE=9E=E7=8E=B0=20forge?= =?UTF-8?q?tPassword=20=E6=96=B9=E6=B3=95=EF=BC=8C=E6=A0=B9=E6=8D=AE?= =?UTF-8?q?=E7=94=A8=E6=88=B7=E7=B1=BB=E5=9E=8B=E9=87=8D=E7=BD=AE=E5=AF=86?= =?UTF-8?q?=E7=A0=81=20-=20=E6=94=AF=E6=8C=81=E5=AD=A6=E7=94=9F=E5=92=8C?= =?UTF-8?q?=E5=91=98=E5=B7=A5=E4=B8=A4=E7=A7=8D=E7=94=A8=E6=88=B7=E7=B1=BB?= =?UTF-8?q?=E5=9E=8B=E7=9A=84=E5=AF=86=E7=A0=81=E9=87=8D=E7=BD=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../api/controller/apiController/Common.php | 26 +++++++++ niucloud/app/api/route/route.php | 6 ++- .../service/api/apiService/CommonService.php | 54 +++++++++++++++++++ 3 files changed, 84 insertions(+), 2 deletions(-) diff --git a/niucloud/app/api/controller/apiController/Common.php b/niucloud/app/api/controller/apiController/Common.php index 27a570ee..9011ea0e 100644 --- a/niucloud/app/api/controller/apiController/Common.php +++ b/niucloud/app/api/controller/apiController/Common.php @@ -35,4 +35,30 @@ class Common extends BaseApiService } return success($res); } + + //忘记密码-通过短信验证码进行密码重置(学生/员工通用) + public function forgetPassword(Request $request) + { + $phone = $request->param('phone', '');//手机号 + $code = $request->param('code', '');//短信验证码 + $code_type = $request->param('code_type', '');//短信验证码类型(发送/验证 短信验证码的类型)|修改密码=editPassword + $password = $request->param('password', '');//新密码 + $user_type = $request->param('user_type', '');//用户类型|customer=学生|personnel=员工(销售/教师) + + if (empty($phone) || empty($code) || empty($code_type) || empty($password) || empty($user_type)) { + return fail('缺少必填参数'); + } + + //@todo 验证短信验证码是否正确(等发送短信验证码接入后在写) + //... + + + //重置密码 + $res = (new CommonService())->forgetPassword($phone, $password, $user_type); + if(!$res['code']){ + return fail($res['msg']); + } + return success([]); + + } } diff --git a/niucloud/app/api/route/route.php b/niucloud/app/api/route/route.php index 35b6b234..55ac4def 100644 --- a/niucloud/app/api/route/route.php +++ b/niucloud/app/api/route/route.php @@ -176,8 +176,8 @@ Route::group(function () { Route::post('personnelLogin', 'login.Login/personnelLogin'); //获取字典 Route::get('common/getDictionary', 'apiController.Common/getDictionary'); - //员工端-修改密码操作 - Route::post('personnel/edidPassword', 'apiController.Personnel/edidPassword'); + //忘记密码-通过短信验证码进行密码重置(学生/员工通用) + Route::post('common/forgetPassword', 'apiController.Common/forgetPassword'); @@ -209,6 +209,8 @@ Route::group(function () { Route::post('personnel/edit', 'apiController.Personnel/edit'); //员工端-验证旧密码是否正确 Route::post('personnel/checkOldPwd', 'apiController.Personnel/checkOldPwd'); + //员工端-修改密码操作(通过旧密码修改新密码) + Route::post('personnel/edidPassword', 'apiController.Personnel/edidPassword'); //员工端-获取全部人员列表 diff --git a/niucloud/app/service/api/apiService/CommonService.php b/niucloud/app/service/api/apiService/CommonService.php index 26654fd4..5a41285a 100644 --- a/niucloud/app/service/api/apiService/CommonService.php +++ b/niucloud/app/service/api/apiService/CommonService.php @@ -12,6 +12,8 @@ namespace app\service\api\apiService; use app\model\dict\Dict; +use app\model\member\Member; +use app\model\sys\SysUser; use core\base\BaseApiService; /** @@ -43,6 +45,58 @@ class CommonService extends BaseApiService } + /** + * 忘记密码功能 - 根据用户类型重置密码 + * @param string $phone 用户手机号 + * @param string $new_password 用户新密码 + * @param string $user_type 用户类型|customer=学生|personnel=员工(销售/教师) + */ + public function forgetPassword($phone, $new_password, $user_type){ + if($user_type == 'personnel'){ + //重置员工(销售/教师)密码 + $update = SysUser::where('username', $phone)->update([ + 'password' => create_password($new_password),//创建密码 + 'update_time' => time(), + ]); + if (!$update) { + $res = [ + 'code' => 0, + 'msg' => '操作失败', + 'data' => [] + ]; + } else { + $res = [ + 'code' => 1, + 'msg' => '操作成功', + 'data' => [] + ]; + } + return $res; + }else{ + //重置用户(学生)密码 + $update = Member::where('username', $phone)->update([ + 'password' => create_password($new_password),//创建密码 + 'update_time' => time(), + ]); + if (!$update) { + $res = [ + 'code' => 0, + 'msg' => '操作失败', + 'data' => [] + ]; + } else { + $res = [ + 'code' => 1, + 'msg' => '操作成功', + 'data' => [] + ]; + } + return $res; + } + + + } + /** * 对比新旧数据改变 * @param array $old_data 旧数据