格式化代码,websocket功能完善
This commit is contained in:
@@ -3,6 +3,8 @@
|
||||
namespace App\Services\Auth;
|
||||
|
||||
use App\Models\Auth\User;
|
||||
use App\Models\System\Notification;
|
||||
use App\Services\System\NotificationService;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Support\Facades\Hash;
|
||||
@@ -16,10 +18,12 @@ use App\Jobs\Auth\UserExportJob;
|
||||
class UserService
|
||||
{
|
||||
protected $departmentService;
|
||||
protected $notificationService;
|
||||
|
||||
public function __construct(DepartmentService $departmentService)
|
||||
public function __construct(DepartmentService $departmentService, NotificationService $notificationService)
|
||||
{
|
||||
$this->departmentService = $departmentService;
|
||||
$this->notificationService = $notificationService;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -29,6 +33,7 @@ class UserService
|
||||
{
|
||||
return Auth::guard('admin')->id();
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取用户列表
|
||||
*/
|
||||
@@ -215,6 +220,12 @@ class UserService
|
||||
}
|
||||
|
||||
DB::commit();
|
||||
|
||||
// 发送更新通知(如果更新的是其他用户)
|
||||
// if ($id !== $this->getCurrentUserId()) {
|
||||
$this->sendUserUpdateNotification($user, $data);
|
||||
// }
|
||||
|
||||
return $user;
|
||||
} catch (\Exception $e) {
|
||||
DB::rollBack();
|
||||
@@ -352,4 +363,52 @@ class UserService
|
||||
'updated_at' => $user->updated_at->toDateTimeString(),
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* 发送用户更新通知
|
||||
*/
|
||||
private function sendUserUpdateNotification(User $user, array $data): void
|
||||
{
|
||||
// 收集被更新的字段
|
||||
$changes = [];
|
||||
|
||||
$fieldLabels = [
|
||||
'username' => '用户名',
|
||||
'real_name' => '姓名',
|
||||
'email' => '邮箱',
|
||||
'phone' => '手机号',
|
||||
'department_id' => '所属部门',
|
||||
'avatar' => '头像',
|
||||
'status' => '状态',
|
||||
'password' => '密码',
|
||||
'role_ids' => '角色',
|
||||
];
|
||||
|
||||
foreach ($data as $key => $value) {
|
||||
if (isset($fieldLabels[$key])) {
|
||||
$changes[] = $fieldLabels[$key];
|
||||
}
|
||||
}
|
||||
|
||||
if (empty($changes)) {
|
||||
return;
|
||||
}
|
||||
|
||||
// 生成通知内容
|
||||
$content = '您的账户信息已被管理员更新,更新的内容:' . implode('、', $changes);
|
||||
|
||||
// 发送通知
|
||||
$this->notificationService->sendToUser(
|
||||
$user->id,
|
||||
'个人信息已更新',
|
||||
$content,
|
||||
Notification::TYPE_INFO,
|
||||
Notification::CATEGORY_SYSTEM,
|
||||
[
|
||||
'user_id' => $user->id,
|
||||
'updated_fields' => $changes,
|
||||
'action_type' => Notification::ACTION_NONE,
|
||||
]
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user