|
|
|
|
@ -0,0 +1,72 @@
|
|
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
namespace App\Console\Commands;
|
|
|
|
|
|
|
|
|
|
use App\Models\Visit;
|
|
|
|
|
use App\Models\VisitLog;
|
|
|
|
|
use Illuminate\Console\Command;
|
|
|
|
|
use Illuminate\Support\Facades\Log;
|
|
|
|
|
use Carbon\Carbon;
|
|
|
|
|
|
|
|
|
|
class ResetLongTermVisitsCommand extends Command
|
|
|
|
|
{
|
|
|
|
|
/**
|
|
|
|
|
* The name and signature of the console command.
|
|
|
|
|
*
|
|
|
|
|
* @var string
|
|
|
|
|
*/
|
|
|
|
|
protected $signature = 'visit:reset-long-term';
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* The console command description.
|
|
|
|
|
*
|
|
|
|
|
* @var string
|
|
|
|
|
*/
|
|
|
|
|
protected $description = '重置长期拜访预约的审核状态,每天零点1分执行';
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Execute the console command.
|
|
|
|
|
*/
|
|
|
|
|
public function handle()
|
|
|
|
|
{
|
|
|
|
|
$this->info('开始检查长期拜访预约...');
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
$today = Carbon::today();
|
|
|
|
|
|
|
|
|
|
// 查找长期拜访预约(long_time = 1)且在有效期内(start_date <= 今天 <= end_date)
|
|
|
|
|
$longTermVisits = Visit::where('start_date', '<=', $today)
|
|
|
|
|
->where('end_date', '>=', $today)
|
|
|
|
|
// 3已进厂4已离厂
|
|
|
|
|
->whereIn('audit_status', [3, 4])
|
|
|
|
|
->get();
|
|
|
|
|
|
|
|
|
|
if ($longTermVisits->isEmpty()) {
|
|
|
|
|
$this->info('没有需要重置的长期拜访预约');
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$this->info("找到 {$longTermVisits->count()} 条需要重置的长期拜访预约");
|
|
|
|
|
|
|
|
|
|
$resetCount = 0;
|
|
|
|
|
foreach ($longTermVisits as $visit) {
|
|
|
|
|
// 重置审核状态为已通过(1)
|
|
|
|
|
$visit->audit_status = 1;
|
|
|
|
|
$visit->save();
|
|
|
|
|
|
|
|
|
|
// 记录重置日志
|
|
|
|
|
VisitLog::log($visit->id, VisitLog::TYPE_UPDATE, "系统自动重置:长期拜访预约审核状态已重置为待审核");
|
|
|
|
|
|
|
|
|
|
$resetCount++;
|
|
|
|
|
$this->info("已重置访客:{$visit->name}({$visit->code})");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$this->info("重置完成,共处理 {$resetCount} 条记录");
|
|
|
|
|
Log::info("长期拜访预约重置任务完成,共处理 {$resetCount} 条记录");
|
|
|
|
|
|
|
|
|
|
} catch (\Exception $e) {
|
|
|
|
|
Log::error('重置长期拜访预约失败:' . $e->getMessage());
|
|
|
|
|
$this->error('重置失败:' . $e->getMessage());
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|