DeleteApiLog.php 952 B

12345678910111213141516171819202122232425262728293031323334353637383940
  1. <?php
  2. namespace app\command;
  3. use app\common\model\shared\SharedProsperityPartnerConsumeUpdateLog;
  4. use app\common\repositories\shared\SharedProsperityRecommendConfigRepository;
  5. use think\console\Command;
  6. use think\console\Input;
  7. use think\console\Output;
  8. use think\facade\Db;
  9. class DeleteApiLog extends Command
  10. {
  11. // 上级
  12. const DAY = 10;
  13. protected function configure()
  14. {
  15. // 指令配置
  16. $this->setName('deleteApiLog')
  17. ->setDescription('定时删除api日志');
  18. }
  19. protected function execute(Input $input, Output $output)
  20. {
  21. $output->writeln('定时任务执行中...');
  22. $this->delete();
  23. $output->writeln('定时任务执行完成');
  24. }
  25. private function delete()
  26. {
  27. $time = time() - self::DAY * 24 * 60 * 60;
  28. $time = date('Y-m-d', $time);
  29. Db::name('api_request_log')->where('create_time', '<', $time)->limit(1000)->delete();
  30. }
  31. }