|
|
|
|
@ -0,0 +1,65 @@
|
|
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
namespace App\Console\Commands;
|
|
|
|
|
|
|
|
|
|
use App\Models\GateLog;
|
|
|
|
|
use App\Models\Visit;
|
|
|
|
|
use Illuminate\Console\Command;
|
|
|
|
|
use Illuminate\Support\Carbon;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 长期访客:最后一条门岗为「离厂」且业务日期早于今天时,将审核状态重置为待进厂(audit_status=1)。
|
|
|
|
|
*/
|
|
|
|
|
class ResetLongTermVisitDailyStatusCommand extends Command
|
|
|
|
|
{
|
|
|
|
|
protected $signature = 'visit:reset-long-term-daily-status';
|
|
|
|
|
|
|
|
|
|
protected $description = '长期访客按日重置:仅当最后一条门岗为离厂且非今日离厂时,置为待进厂';
|
|
|
|
|
|
|
|
|
|
public function handle(): int
|
|
|
|
|
{
|
|
|
|
|
$today = Carbon::today()->format('Y-m-d');
|
|
|
|
|
$count = 0;
|
|
|
|
|
|
|
|
|
|
Visit::query()
|
|
|
|
|
->where('long_time', 1)
|
|
|
|
|
->whereIn('audit_status', [3, 4])
|
|
|
|
|
->orderBy('id')
|
|
|
|
|
->chunkById(200, function ($visits) use ($today, &$count) {
|
|
|
|
|
foreach ($visits as $visit) {
|
|
|
|
|
$lastLog = GateLog::query()
|
|
|
|
|
->where('visit_id', $visit->id)
|
|
|
|
|
->orderByDesc('id')
|
|
|
|
|
->first();
|
|
|
|
|
if (!$lastLog && !empty($visit->code)) {
|
|
|
|
|
$lastLog = GateLog::query()
|
|
|
|
|
->where('code', $visit->code)
|
|
|
|
|
->orderByDesc('id')
|
|
|
|
|
->first();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!$lastLog || (int) $lastLog->action !== 2) {
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$bizDate = null;
|
|
|
|
|
if (!empty($lastLog->biz_date)) {
|
|
|
|
|
$bizDate = Carbon::parse($lastLog->biz_date)->format('Y-m-d');
|
|
|
|
|
} elseif (!empty($lastLog->created_at)) {
|
|
|
|
|
$bizDate = Carbon::parse($lastLog->created_at)->format('Y-m-d');
|
|
|
|
|
}
|
|
|
|
|
if ($bizDate === null || $bizDate >= $today) {
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$visit->audit_status = 1;
|
|
|
|
|
$visit->saveQuietly();
|
|
|
|
|
$count++;
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
$this->info("已重置 {$count} 条长期访客为待进厂(audit_status=1)。");
|
|
|
|
|
|
|
|
|
|
return self::SUCCESS;
|
|
|
|
|
}
|
|
|
|
|
}
|