UserApplyCertifyJob.php
1.42 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
<?php
namespace App\Jobs;
use App\Models\SystemRole;
use App\Models\User;
use App\Models\UserCertify;
use App\Notifications\UserCertifyApplyNotification;
use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Foundation\Bus\Dispatchable;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Queue\SerializesModels;
use Illuminate\Support\Facades\Notification;
class UserApplyCertifyJob implements ShouldQueue
{
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
public UserCertify $userCertify;
public function __construct(UserCertify $userCertify)
{
$this->userCertify = $userCertify;
}
public function handle(): void
{
$roleIds = SystemRole::query()
->whereRelation('permissions', fn($query) => $query->where('guard', 'Admin')->where('system_permissions.name', 'user-certify-audit'))
->where('system_roles.status', 1)
->pluck('system_roles.id')->toArray();
$users = User::query()
->selectRaw('users.id,users.nick_name,users.official_id,users.phone,users.area_code')
->join('user_has_roles', 'user_has_roles.user_id', 'users.id')
->whereIn('user_has_roles.role_id', $roleIds)
->where('users.status', 1)->where('users.official_status', 1)
->get();
Notification::send($users, new UserCertifyApplyNotification($this->userCertify));
}
}