From b58e61dfc0d56e539aa34f2707623067578c821c Mon Sep 17 00:00:00 2001 From: cody <648753004@qq.com> Date: Mon, 27 Oct 2025 13:58:01 +0800 Subject: [PATCH 1/4] =?UTF-8?q?=E5=8F=98=E6=9B=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Commands/ResetLongTermVisitsCommand.php | 72 +++++++++++++++++++ app/Console/Kernel.php | 11 +-- app/Models/Visit.php | 24 +++++++ app/Models/VisitLog.php | 37 ++++++++-- ...3_03_29_133905_create_visit_logs_table.php | 1 + 5 files changed, 137 insertions(+), 8 deletions(-) create mode 100644 app/Console/Commands/ResetLongTermVisitsCommand.php diff --git a/app/Console/Commands/ResetLongTermVisitsCommand.php b/app/Console/Commands/ResetLongTermVisitsCommand.php new file mode 100644 index 0000000..7ebb4d9 --- /dev/null +++ b/app/Console/Commands/ResetLongTermVisitsCommand.php @@ -0,0 +1,72 @@ +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()); + } + } +} diff --git a/app/Console/Kernel.php b/app/Console/Kernel.php index 5438ecc..f78441e 100644 --- a/app/Console/Kernel.php +++ b/app/Console/Kernel.php @@ -16,10 +16,13 @@ class Kernel extends ConsoleKernel protected function schedule(Schedule $schedule) { // 每天18:00发送未核销拜访预约提醒 - $schedule->command('visit:reminder') - ->dailyAt('18:00') - ->withoutOverlapping() - ->runInBackground(); +// $schedule->command('visit:reminder') +// ->dailyAt('18:00') +// ->withoutOverlapping() +// ->runInBackground(); + + // 每天00:01重置长期拜访预约审核状态 + $schedule->command('visit:reset-long-term')->dailyAt('00:01'); } /** diff --git a/app/Models/Visit.php b/app/Models/Visit.php index 9456da5..48c2be2 100644 --- a/app/Models/Visit.php +++ b/app/Models/Visit.php @@ -6,6 +6,30 @@ use EasyWeChat\Factory; class Visit extends SoftDeletesModel { + // 审核状态常量 + const AUDIT_STATUS_PENDING_STUDY = -1; // 待学习 + const AUDIT_STATUS_PENDING = 0; // 待审核 + const AUDIT_STATUS_APPROVED = 1; // 通过 + const AUDIT_STATUS_REJECTED = 2; // 驳回 + const AUDIT_STATUS_ENTERED = 3; // 已进厂 + const AUDIT_STATUS_LEFT = 4; // 已离厂 + const AUDIT_STATUS_CANCELLED = 5; // 已取消 + + // 访客类型常量 + const TYPE_VISITOR = 1; // 普通访客 + const TYPE_VISITOR_CAR = 2; // 访客车辆 + const TYPE_LOGISTICS_CAR = 3; // 物流车辆 + + // 证件类型常量 + const CREDENT_ID_CARD = 1; // 身份证 + const CREDENT_PASSPORT = 2; // 护照 + + // 用餐类型常量 + const MEAL_TYPE_BREAKFAST = 1; // 早餐 + const MEAL_TYPE_LUNCH = 2; // 午餐 + const MEAL_TYPE_DINNER = 3; // 晚餐 + const MEAL_TYPE_ALL_DAY = 4; // 全天 + protected $guarded = ['id']; protected $appends = ['type_text', 'audit_status_text', 'file_detail', 'vehicle_images_detail']; diff --git a/app/Models/VisitLog.php b/app/Models/VisitLog.php index b2cce3b..7c4c41b 100644 --- a/app/Models/VisitLog.php +++ b/app/Models/VisitLog.php @@ -4,8 +4,35 @@ namespace App\Models; class VisitLog extends CommonModel { + // 日志类型常量 + const TYPE_CREATE = 'create'; // 创建申请 + const TYPE_UPDATE = 'update'; // 更新申请 + const TYPE_AUDIT = 'audit'; // 审核 + const TYPE_APPROVE = 'approve'; // 通过 + const TYPE_REJECT = 'reject'; // 驳回 + const TYPE_ENTER = 'enter'; // 进厂 + const TYPE_LEAVE = 'leave'; // 离厂 + const TYPE_CANCEL = 'cancel'; // 取消 + const TYPE_STUDY = 'study'; // 学习 + const TYPE_EXAM = 'exam'; // 考试 + protected $guarded = ['id']; + /** + * 创建拜访日志 + */ + public static function log($visitId, $type, $remark = '') + { + return self::create([ + 'visit_id' => $visitId, + 'type' => $type, + 'remark' => $remark, + 'admin_id' => 0, // 系统操作 + 'department_id' => 0, + 'user_id' => 0, + ]); + } + public static function add($admin, $user, $visit_id, $remark) { return self::create([ @@ -17,12 +44,14 @@ class VisitLog extends CommonModel ]); } - public function admin(){ - return $this->hasOne(Admin::class,'id','admin_id'); + public function admin() + { + return $this->hasOne(Admin::class, 'id', 'admin_id'); } - public function user(){ - return $this->hasOne(User::class,'id','user_id'); + public function user() + { + return $this->hasOne(User::class, 'id', 'user_id'); } } diff --git a/database/migrations/2023_03_29_133905_create_visit_logs_table.php b/database/migrations/2023_03_29_133905_create_visit_logs_table.php index 12be6dc..68c0450 100644 --- a/database/migrations/2023_03_29_133905_create_visit_logs_table.php +++ b/database/migrations/2023_03_29_133905_create_visit_logs_table.php @@ -21,6 +21,7 @@ class CreateVisitLogsTable extends Migration $table->integer('user_id')->nullable(); $table->integer('visit_id')->nullable(); $table->string('remark')->nullable(); + $table->string('type')->nullable(); $table->dateTime('created_at')->nullable(); $table->dateTime('updated_at')->nullable(); $table->softDeletes(); From 3ebad993c2fb35e2f4535401969d37a760c2bdc3 Mon Sep 17 00:00:00 2001 From: cody <648753004@qq.com> Date: Mon, 27 Oct 2025 14:03:54 +0800 Subject: [PATCH 2/4] =?UTF-8?q?=E5=8F=98=E6=9B=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/Console/Commands/ResetLongTermVisitsCommand.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/Console/Commands/ResetLongTermVisitsCommand.php b/app/Console/Commands/ResetLongTermVisitsCommand.php index 7ebb4d9..9d08c3e 100644 --- a/app/Console/Commands/ResetLongTermVisitsCommand.php +++ b/app/Console/Commands/ResetLongTermVisitsCommand.php @@ -55,7 +55,7 @@ class ResetLongTermVisitsCommand extends Command $visit->save(); // 记录重置日志 - VisitLog::log($visit->id, VisitLog::TYPE_UPDATE, "系统自动重置:长期拜访预约审核状态已重置为待审核"); + // VisitLog::log($visit->id, VisitLog::TYPE_UPDATE, "系统自动重置:长期拜访预约审核状态已重置为待审核"); $resetCount++; $this->info("已重置访客:{$visit->name}({$visit->code})"); From bf94fce74959322a097bc2f29349bd89529e4ee2 Mon Sep 17 00:00:00 2001 From: cody <648753004@qq.com> Date: Mon, 27 Oct 2025 14:07:20 +0800 Subject: [PATCH 3/4] =?UTF-8?q?=E5=8F=98=E6=9B=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/Models/CommonModel.php | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/app/Models/CommonModel.php b/app/Models/CommonModel.php index b8e4e14..0a63a6c 100755 --- a/app/Models/CommonModel.php +++ b/app/Models/CommonModel.php @@ -6,11 +6,15 @@ use DateTimeInterface; use Illuminate\Database\Eloquent\Model; use Illuminate\Support\Carbon; use Illuminate\Support\Facades\Cache; +use OwenIt\Auditing\Contracts\Auditable; -class CommonModel extends Model + +class CommonModel extends Model implements Auditable { use DynamicallyTableModelTrait; use FilterRequestColumnModelTrait; + use \OwenIt\Auditing\Auditable; + protected $table; protected $guarded = []; From 5f86f80684c90d9788033e5ab468ef6c8f6afda5 Mon Sep 17 00:00:00 2001 From: cody <648753004@qq.com> Date: Mon, 27 Oct 2025 14:07:30 +0800 Subject: [PATCH 4/4] =?UTF-8?q?=E5=8F=98=E6=9B=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/Models/CommonModel.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/Models/CommonModel.php b/app/Models/CommonModel.php index 0a63a6c..e6be0dd 100755 --- a/app/Models/CommonModel.php +++ b/app/Models/CommonModel.php @@ -17,7 +17,7 @@ class CommonModel extends Model implements Auditable protected $table; - protected $guarded = []; + protected $guarded = ['id']; protected $casts = [ 'created_at' => 'datetime:Y-m-d H:i:s', 'updated_at' => 'datetime:Y-m-d H:i:s',