handleReminders(); } public function handleReminders() { $now = time(); TodoList::where('status', '<', TodoList::status_two) ->where('del_time', 0) ->where('remind_start', '<=', $now) ->select(TodoList::$field) ->orderBy('id') ->chunkById(10, function ($data) use ($now) { DB::transaction(function () use ($data, $now) { foreach ($data as $todo) { // 单次提醒 if ($todo->remind_interval == 0) { if (empty($todo->last_remind_time)) { $this->sendReminder($todo); $todo->last_remind_time = $now; $todo->save(); } continue; } // 第一次提醒 或 距离上次提醒超过间隔时间 if (empty($todo->last_remind_time) || ($now - $todo->last_remind_time) >= $todo->remind_interval) { $this->sendReminder($todo); $todo->last_remind_time = $now; $todo->save(); } } }); }); } }