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-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());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 获取用户信息(包括菜单和权限)
|
|
|
|
|
*/
|
|
|
|
|
public function getUserInfo(int $uid)
|
2025-07-01 19:39:13 +08:00
|
|
|
{
|
2025-07-11 15:21:00 +08:00
|
|
|
$user = $this->logic->userInfo($uid);
|
|
|
|
|
$permService = new PermService();
|
|
|
|
|
$menuTree = $permService->getMenuTree($uid);
|
|
|
|
|
$permissionCodes = $permService->getPermissionCodes($uid);
|
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,
|
|
|
|
|
'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-18 15:15:37 +08:00
|
|
|
'avatar_full' => (!empty($user->avatar))?$ossservice->generatePrivateUrl($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,
|
|
|
|
|
'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-11 15:21:00 +08:00
|
|
|
}
|