ActivityStatusRecordCommand.php 1.49 KB
<?php

namespace App\Console\Commands;

use App\Enums\ActivityAuditStatusEnum;
use App\Enums\ActivityStatusEnum;
use App\Models\Activity;
use DB;
use Illuminate\Console\Command;

class ActivityStatusRecordCommand extends Command
{
    /**
     * The name and signature of the console command.
     *
     * @var string
     */
    protected $signature = 'activity:status-record';

    /**
     * The console command description.
     *
     * @var string
     */
    protected $description = '记录活动状态节点';

    /**
     * Execute the console command.
     *
     * @return int
     */
    public function handle(): int
    {
        DB::table('activity_status_records')->updateOrInsert(
            ['time' => today()->toDateString()],
            [
                'up'    => Activity::query()->where('activitys.audit_status', ActivityAuditStatusEnum::SUCCESS)->where('activitys.status', ActivityStatusEnum::UP)->count(),
                'down'  => Activity::query()->where('activitys.audit_status', ActivityAuditStatusEnum::SUCCESS)->where('activitys.status', ActivityStatusEnum::DOWN)->count(),
                'match' => Activity::query()->where('activitys.audit_status', ActivityAuditStatusEnum::SUCCESS)->where('activitys.status', ActivityStatusEnum::MATCH)->count(),
                'send'  => Activity::query()->where('activitys.audit_status', ActivityAuditStatusEnum::SUCCESS)->where('activitys.status', ActivityStatusEnum::SEND)->count(),
            ]
        );

        return self::SUCCESS;
    }
}