浏览代码

定时任务

Silent 6 年之前
父节点
当前提交
c07f65a0a9
共有 1 个文件被更改,包括 11 次插入0 次删除
  1. 11 0
      app/Console/Kernel.php

+ 11 - 0
app/Console/Kernel.php

xqd xqd
@@ -2,6 +2,7 @@
 
 namespace App\Console;
 
+use App\Models\CheckCard;
 use Carbon\Carbon;
 use Illuminate\Console\Scheduling\Schedule;
 use Illuminate\Foundation\Console\Kernel as ConsoleKernel;
@@ -30,6 +31,16 @@ class Kernel extends ConsoleKernel
         $schedule->call(function () {
             $begin = Carbon::today()->toDateTimeString();
             $end = Carbon::tomorrow()->toDateTimeString();
+
+            $items = CheckCard::where([
+                ['begin_date_time', '>=', $begin],
+                ['begin_date_time', '<', $end],
+            ])->whereNull('end_date_time')->get();
+
+            foreach($items as $item) {
+                $item->end_date_time = Carbon::createFromTimestamp(strtotime($item->begin_date_time))->addHours(2)->toDateTimeString();
+                $item->save();
+            }
         })->dailyAt('23:50');
     }