| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859 | <?phpnamespace App\Console;use App\Models\CheckCard;use Carbon\Carbon;use Illuminate\Console\Scheduling\Schedule;use Illuminate\Foundation\Console\Kernel as ConsoleKernel;use Illuminate\Support\Facades\Log;class Kernel extends ConsoleKernel{    /**     * The Artisan commands provided by your application.     *     * @var array     */    protected $commands = [        //    ];    /**     * Define the application's command schedule.     *     * @param  \Illuminate\Console\Scheduling\Schedule  $schedule     * @return void     */    protected function schedule(Schedule $schedule)    {        // $schedule->command('inspire')        //          ->hourly();        $schedule->call(function () {            $begin = Carbon::today()->toDateTimeString();            $end = Carbon::tomorrow()->toDateTimeString();            Log::info('定时器已经执行');            $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('21:00');    }    /**     * Register the Closure based commands for the application.     *     * @return void     */    protected function commands()    {        require base_path('routes/console.php');    }}
 |