Files
fdesk/app/common/service/UserService.php
T

113 lines
3.1 KiB
PHP
Raw Normal View History

2025-07-01 19:39:13 +08:00
<?php
namespace app\common\service;
2025-07-11 15:21:00 +08:00
use app\common\logic\UserLogic;
2025-07-18 15:15:37 +08:00
use app\common\model\Corp;
2025-07-18 16:45:16 +08:00
use app\common\model\User;
2025-07-23 17:06:48 +08:00
use app\common\utils\CrudUtil;
2025-07-18 14:07:04 +08:00
use app\crm\model\Country;
2025-07-18 16:45:16 +08:00
use support\exception\BusinessException;
2025-07-01 19:39:13 +08:00
class UserService
{
2025-07-11 15:21:00 +08:00
protected $logic;
public function __construct()
{
$this->logic = (new UserLogic());
}
/**
* 获取用户信息(包括菜单和权限)
*/
2025-07-25 18:10:11 +08:00
public function getUserInfo(int $uid, string $systemCode)
2025-07-01 19:39:13 +08:00
{
2025-07-11 15:21:00 +08:00
$user = $this->logic->userInfo($uid);
$permService = new PermService();
2025-07-25 18:10:11 +08:00
$menuTree = $permService->getMenuTree($uid, $systemCode);
$permissionCodes = $permService->getPermissionCodes($uid, $systemCode);
2025-07-01 19:39:13 +08:00
return [
2025-07-11 15:21:00 +08:00
'user' => [
'id' => $user->id,
'name' => $user->name,
'avatar' => $user->avatar,
'phone' => $user->phone,
'email' => $user->email,
'status' => $user->status,
'roles' => $user->roles->pluck('name')
],
'menu' => $menuTree,
'permissions' => $permissionCodes
2025-07-01 19:39:13 +08:00
];
}
2025-07-18 10:04:54 +08:00
2025-07-18 14:07:04 +08:00
/**
* 获取用户信息(包括菜单和权限)
*/
2025-07-18 15:15:37 +08:00
public function getUser(int $uid, $corp_abbr)
2025-07-18 14:07:04 +08:00
{
$user = $this->logic->userInfo($uid);
2025-07-18 15:15:37 +08:00
$corp_name = Corp::where('abbr', $corp_abbr)->value('name');
$ossservice = new OssService();
2025-07-18 14:07:04 +08:00
return [
'id' => $user->id,
2025-07-29 09:32:23 +08:00
'sn' => $user->sn,
2025-07-18 14:07:04 +08:00
'name' => $user->name,
'position' => $user->position,
'socialize' => $user->socialize,
'socialize_pic' => $user->socialize_pic,
2025-07-18 15:15:37 +08:00
'socialize_pic_full' => (!empty($user->socialize_pic))?$ossservice->generatePrivateUrl($user->socialize_pic):'',
2025-07-18 14:07:04 +08:00
'country_id' => $user->country_id,
'country_txt' => Country::where('id',$user->country_id)->value('cn_addr'),
'avatar' => $user->avatar,
2025-07-29 10:06:06 +08:00
'avatar_full' => $user->avatar,
2025-07-18 14:07:04 +08:00
'phone' => $user->phone,
2025-07-18 15:15:37 +08:00
'corp_name' => $corp_name,
2025-07-18 14:07:04 +08:00
'email' => $user->email,
2025-07-29 10:13:50 +08:00
'sex' => $user->sex,
2025-07-18 14:07:04 +08:00
'status' => $user->status,
'roles' => $user->roles->pluck('name')
];
}
2025-07-18 10:04:54 +08:00
/**
2025-07-18 16:45:16 +08:00
* 编辑用户信息
2025-07-18 10:04:54 +08:00
*/
public function edit(int $uid, array $data)
{
unset($data['password']);
unset($data['phone']);
unset($data['email']);
unset($data['sn']);
$user = $this->logic->edit($uid,$data);
return $user;
}
2025-07-18 16:45:16 +08:00
/**
* 修改用户密码
*/
public function savePassword(int $uid, array $data)
{
// 对密码进行哈希处理
$password = $data['password'];
$user = User::find($uid);
if (!password_verify($password, $user->password)) {
throw new BusinessException('密码错误');
}
$user = $this->logic->savePassword($uid,$data);
return $user;
}
2025-07-23 17:06:48 +08:00
/**
* 获取用户列表
*/
public function getList()
{
return $this->logic->getList();
}
2025-07-11 15:21:00 +08:00
}