path = root_path() . 'crontab.txt'; $content = '重置中!'; if (!file_exists($this->path)) { fopen($this->path, 'w'); } if (date('d') != 10) { $content = file_get_contents($this->path); } file_put_contents($this->path, $content . date('Y-m-d H:i:s') . ':' . $text . PHP_EOL); } public function configure() { //设置每天2点执行 $this->dailyAt('02:00'); } /** * 执行任务 * @return mixed */ protected function execute() { if(date('H:i')!='02:00'){ return false; } try { $config=Config::getSystemInfo(); $status=$config['chatInfo']['msgClear'] ?? false; $days=$config['chatInfo']['msgClearDay'] ?? 0; if($status && $days){ $time=time() - ($days * $this->daytime); $where[]=['create_time','<',$time]; $res = Message::where($where)->select(); $group_id_arr = []; foreach ($res as $resRes) { $resRes->force()->delete(); File::syncDelFile($resRes->file_id); if ($resRes['is_group'] == 1) { $group_id_arr[] = $resRes['to_user']; } } if ($group_id_arr) { GroupUser::editGroupUser([['group_id','in',array_unique($group_id_arr)]], ['unread' => 0]); } } print "****************消息清理成功******************\n"; } catch (Exception $e) { print '消息清理失败:'.$e->getMessage()."\n"; } } }