ActivityPublishApply.php
1.68 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
<?php
namespace App\Actions;
use App\Jobs\WechatTemplateMessageJob;
use App\Models\Activity;
use App\Models\SystemRole;
use App\Models\User;
use Carbon\Carbon;
use Lorisleiva\Actions\Concerns\AsAction;
use Lorisleiva\Actions\Concerns\AsJob;
class ActivityPublishApply
{
use AsAction, AsJob;
protected string $template = 'o9i6qtgr4ghtGvU-piimB9_mAaSOAXDDMzqx9zXYkss';
public function handle(Activity $activity): void
{
$activity->loadMissing('user:id,nick_name,real_name');
$roleIds = SystemRole::query()
->whereRelation('permissions', fn($query) => $query->where('guard', 'Admin')->where('system_permissions.name', 'audition-activity-audit-audit'))
->where('system_roles.status', 1)
->pluck('system_roles.id')->toArray();
User::query()
->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)
->distinct()->pluck('users.official_id')
->each(fn($item) => WechatTemplateMessageJob::dispatch($item, $this->template, [
'first' => '厂牌提交试唱发布申请',
'keyword1' => '海星试唱提交了上架申请',
'keyword2' => sprintf('%s(%s)', data_get($activity, 'user.nick_name'), data_get($activity, 'user.real_name')),
'keyword3' => (string)data_get($activity, 'created_at', Carbon::now()->toDateTimeString()),
'keyword4' => sprintf('【%s】活动上架需要您的审核', $activity->getAttribute('song_name')),
'remark' => ''
]));
}
}