WeworksingleChatFileDelete.php 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. <?php
  2. namespace app\command;
  3. use app\model\WeworksingleChatFile;
  4. use think\console\Command;
  5. use think\console\Input;
  6. use think\console\Output;
  7. class WeworksingleChatFileDelete extends Command
  8. {
  9. protected function configure()
  10. {
  11. $this->setName('weworksingle_chat_file_delete')
  12. ->setDescription('企业微信聊天文件本地删除');
  13. }
  14. protected function execute(Input $input, Output $output)
  15. {
  16. $output->writeln("企业微信聊天文件本地删除开始:" . date('Y-m-d H:i:s'));
  17. $list = WeworksingleChatFile::where([['local_delete', '=', 1], ['is_local', '=', 0]])->order('id asc')->select()->toArray();
  18. foreach ($list as $k => $v) {
  19. $local_delete = true;
  20. if (!empty($v['path'])) {
  21. $path = public_path() . $v['path'];
  22. if (file_exists($path)) {
  23. @unlink($path);//删除本地文件
  24. if (file_exists($path)) {
  25. $local_delete = false;
  26. }
  27. }
  28. }
  29. if (!empty($v['other_path'])) {
  30. $path = public_path() . $v['other_path'];
  31. if (file_exists($path)) {
  32. @unlink($path);//删除本地文件
  33. if (file_exists($path)) {
  34. $local_delete = false;
  35. }
  36. }
  37. }
  38. if ($local_delete) {
  39. WeworksingleChatFile::where('id', '=', $v['id'])->save(['local_delete'=> 0]);
  40. }
  41. }
  42. $file_path = public_path() . 'weworksingle_file';
  43. @rmdir($file_path);
  44. $output->writeln("企业微信聊天文件本地删除结束: " . date('Y-m-d H:i:s'));
  45. }
  46. }