Merge branch 'feature/user0812' into develop_bm

# Conflicts:
#	app/admin/service/UserService.php
#	config/route.php
This commit is contained in:
2025-08-13 09:51:26 +08:00
14 changed files with 379 additions and 8 deletions
+36
View File
@@ -19,6 +19,42 @@ class UserController extends BaseController
$this->service = new UserService();
}
/**
* 修改密码
* @param Request $request
* @return \support\Response
* @throws \Random\RandomException
*/
public function savePassword(Request $request)
{
try {
$data = $this->validate($this->service->getValidator(), $request->post(), 'password');
$data = $request->all();
$result = $this->service->savePassword($request,$data);;
return $this->success($result, '编辑成功');
} catch (\Throwable $e) {
return $this->error($e->getMessage());
}
}
/**
* 更新
*
* @param Request $request 请求对象
* @return mixed 返回更新成功的数据或信息
*/
public function edit(Request $request)
{
try {
$data = $this->validate($this->service->getValidator(), $request->post(), 'update');
$res = $this->service->serviceUpdate($request, $data);
return $this->success([], '更新成功');
} catch (\Throwable $e) {
return $this->error($e->getMessage());
}
}
/**
* 列表页数据格式化
*
+27 -1
View File
@@ -3,9 +3,10 @@
namespace app\admin\service;
use app\admin\logic\UserLogic;
use app\admin\validate\UserValidate;
use app\common\traits\crud\CrudServiceTrait;
use app\common\model\User;
use app\common\validate\UserValidate;
use support\exception\BusinessException;
use support\Request;
class UserService
@@ -31,6 +32,14 @@ class UserService
return new $this->validator;
}
/** 更新 */
public function serviceUpdate(Request $request, array $data = [])
{
$data = $this->preProcess('Update', $data, $request);
$config = $this->buildQueryConfig($request, 'edit');
$updated = $this->logicUpdateBy($config, $data);
return $this->postProcess('Update', $data);
}
/**
* 构造 CrudUtil 查询配置
@@ -75,6 +84,12 @@ class UserService
case 'destroy':
$config['where']['id'] = $p['id'];
break;
case 'savePassword':
$config['where']['id'] = $p['id'];
break;
case 'edit':
$config['where']['id'] = $request->user->uid;
break;
}
return $config;
@@ -103,4 +118,15 @@ class UserService
{
return (new UserLogic())->updateUserResources($data);
}
/**
* 修改用户密码
*/
public function savePassword(Request $request, array $data)
{
$config = $this->buildQueryConfig($request, 'savePassword');
$data['password'] = password_hash($data['password'], PASSWORD_DEFAULT);
$user = $this->logicUpdateBy($config,$data);
return $user;
}
}