Merge branch 'master' of ssh://47.101.48.251:/data/git/visitor

master
lion 10 months ago
commit 943c7cb353

@ -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());
}
}
}

@ -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');
}
/**

@ -6,14 +6,18 @@ 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 = [];
protected $guarded = ['id'];
protected $casts = [
'created_at' => 'datetime:Y-m-d H:i:s',
'updated_at' => 'datetime:Y-m-d H:i:s',

@ -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'];

@ -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');
}
}

@ -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();

Loading…
Cancel
Save