setName('weworksingle_chat_file_delete') ->setDescription('企业微信聊天文件本地删除'); } protected function execute(Input $input, Output $output) { $output->writeln("企业微信聊天文件本地删除开始:" . date('Y-m-d H:i:s')); $list = WeworksingleChatFile::where([['local_delete', '=', 1], ['is_local', '=', 0]])->order('id asc')->select()->toArray(); foreach ($list as $k => $v) { $local_delete = true; if (!empty($v['path'])) { $path = public_path() . $v['path']; if (file_exists($path)) { @unlink($path);//删除本地文件 if (file_exists($path)) { $local_delete = false; } } } if (!empty($v['other_path'])) { $path = public_path() . $v['other_path']; if (file_exists($path)) { @unlink($path);//删除本地文件 if (file_exists($path)) { $local_delete = false; } } } if ($local_delete) { WeworksingleChatFile::where('id', '=', $v['id'])->save(['local_delete'=> 0]); } } $file_path = public_path() . 'weworksingle_file'; @rmdir($file_path); $output->writeln("企业微信聊天文件本地删除结束: " . date('Y-m-d H:i:s')); } }