ClearCart.php 1.0 KB

12345678910111213141516171819202122232425262728293031
  1. <?php
  2. namespace app\command;
  3. use app\model\saas\SaasCart;
  4. use Symfony\Component\Console\Command\Command;
  5. use Symfony\Component\Console\Input\InputInterface;
  6. use Symfony\Component\Console\Output\OutputInterface;
  7. class ClearCart extends Command
  8. {
  9. protected static string $defaultName = 'clear:cart';
  10. protected static string $defaultDescription = '清理购物车前一天无效数据';
  11. protected function execute(InputInterface $input, OutputInterface $output): int
  12. {
  13. $output->writeln("清理开始====>" . getDateFull());
  14. $cartNum = (new SaasCart)->where("create_at","<",getDateFull())->count();
  15. $output->writeln("共计需清理{$cartNum}条数据====>" . getDateFull());
  16. $state = (new SaasCart)->where("create_at","<",getDateFull())->delete();
  17. if (!$state) {
  18. $output->writeln("清理失败====>" . getDateFull());
  19. } else {
  20. $output->writeln("清理完成====>" . getDateFull());
  21. }
  22. return self::SUCCESS;
  23. }
  24. }