ActivityWorkAuditFail.php 1.15 KB
<?php

namespace App\Actions;

use App\Enums\ActivityWorkStatusEnum;
use App\Models\ActivityUser;
use App\Models\Views\ActivityWork;
use App\Notifications\ActivitySingerSubmitWorkRejectNotification;
use App\Notifications\ActivitySubmitWorkRejectNotification;
use Lorisleiva\Actions\Concerns\AsAction;
use Lorisleiva\Actions\Concerns\AsJob;

class ActivityWorkAuditFail
{
    use AsAction, AsJob;

    public function handle(ActivityWork $work): void
    {
        ActivityUser::query()->whereKey($work->getKey())->update(['status' => ActivityWorkStatusEnum::REJECT]);
        $this->pushUserNotification($work);
        $this->pushBusinessNotification($work);
    }

    /**
     * @param \App\Models\Views\ActivityWork $work
     * @return void
     */
    private function pushUserNotification(ActivityWork $work): void
    {
        $work->user?->notify(new ActivitySubmitWorkRejectNotification($work));
    }

    /**
     * @param \App\Models\Views\ActivityWork $work
     * @return void
     */
    private function pushBusinessNotification(ActivityWork $work): void
    {
        $work->business?->notify(new ActivitySingerSubmitWorkRejectNotification($work));
    }
}