ExcelFileDelListen.php 835 B

123456789101112131415161718192021222324252627282930
  1. <?php
  2. namespace ln\listens;
  3. use app\common\repositories\store\ExcelRepository;
  4. use ln\services\TimerService;
  5. use Swoole\Timer;
  6. use think\facade\Log;
  7. use ln\interfaces\ListenerInterface;
  8. class ExcelFileDelListen extends TimerService implements ListenerInterface
  9. {
  10. public function handle($event): void
  11. {
  12. $this->tick(1000 * 60 * 60, function () {
  13. $make = app()->make(ExcelRepository::class);
  14. $time = date('Y-m-d H:i:s', strtotime("-" . 3 . " day"));
  15. $data = $make->getDelByTime($time);
  16. foreach ($data as $id => $path) {
  17. try {
  18. $make->del($id, $path);
  19. } catch (\Exception $e) {
  20. Log::info('自动删除导出文件失败' . var_export($id, true));
  21. }
  22. }
  23. });
  24. }
  25. }