2025-07-11 15:21:00 +08:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
namespace app\common\logic;
|
|
|
|
|
|
|
|
|
|
use app\common\model\User;
|
|
|
|
|
use support\exception\BusinessException;
|
|
|
|
|
|
|
|
|
|
class UserLogic
|
|
|
|
|
{
|
|
|
|
|
/**
|
|
|
|
|
* 用户信息
|
|
|
|
|
*/
|
|
|
|
|
public function userInfo(int $uid)
|
|
|
|
|
{
|
|
|
|
|
$user = User::find($uid);
|
|
|
|
|
|
|
|
|
|
if (!$user) {
|
|
|
|
|
throw new BusinessException('账户不存在', 404);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if ($user->status != 1) {
|
|
|
|
|
throw new BusinessException('账号已禁用', 403);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return $user;
|
|
|
|
|
}
|
2025-07-18 10:04:54 +08:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 用户信息
|
|
|
|
|
*/
|
|
|
|
|
public function edit(int $uid, array $data)
|
|
|
|
|
{
|
|
|
|
|
$user = User::find($uid);
|
|
|
|
|
|
|
|
|
|
if (!$user) {
|
|
|
|
|
throw new BusinessException('账户不存在', 404);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$user->fill($data);
|
|
|
|
|
$user->save();
|
|
|
|
|
|
|
|
|
|
return $user;
|
|
|
|
|
}
|
|
|
|
|
|
2025-07-18 16:45:16 +08:00
|
|
|
/**
|
|
|
|
|
* 修改密码
|
|
|
|
|
*/
|
|
|
|
|
public function savePassword(int $uid, array $data)
|
|
|
|
|
{
|
|
|
|
|
$password = password_hash($data['password_new'], PASSWORD_DEFAULT);
|
|
|
|
|
$res = User::where('id',$uid)->update(['password' => $password]);
|
|
|
|
|
|
|
|
|
|
return $res;
|
|
|
|
|
}
|
|
|
|
|
|
2025-07-23 17:06:48 +08:00
|
|
|
/**
|
|
|
|
|
* 获取用户列表
|
|
|
|
|
*/
|
|
|
|
|
public function getList()
|
|
|
|
|
{
|
|
|
|
|
$list = User::where('status', 1)->orderBy('id', 'desc')->get();
|
|
|
|
|
$arr = [];
|
|
|
|
|
foreach ($list->toArray() as $item) {
|
|
|
|
|
$arr[] = [
|
|
|
|
|
'name' => $item['name'],
|
|
|
|
|
'id' => $item['id'],
|
|
|
|
|
];
|
|
|
|
|
}
|
|
|
|
|
return $arr;
|
|
|
|
|
}
|
2025-07-11 15:21:00 +08:00
|
|
|
}
|