data = $data; $this->hours = $hours; } public function start() { switch ($this->data) { /** * 表pre_wg_tmp_msgs */ case 'wg_tmp_msgs': { WebSocketTmpMsg::where('created_at', '<', Carbon::now()->subHours($this->hours)->toDateTimeString()) ->orderBy('id') ->chunk(500, function ($msgs) { foreach ($msgs as $msg) { $msg->delete(); } }); } break; /** * 表pre_wg_tmp */ case 'tmp': { Tmp::where('created_at', '<', Carbon::now()->subHours($this->hours)->toDateTimeString()) ->orderBy('id') ->chunk(2000, function ($tmps) { foreach ($tmps as $tmp) { $tmp->delete(); } }); } break; } } }