<?php

namespace app\command;

use app\model\saas\SaasCart;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;

class ClearCart extends Command
{


    protected static string $defaultName = 'clear:cart';
    protected static string $defaultDescription = '清理购物车前一天无效数据';

    protected function execute(InputInterface $input, OutputInterface $output): int
    {
        $output->writeln("清理开始====>" . getDateFull());
        $cartNum = (new SaasCart)->where("create_at","<",getDateFull())->count();
        $output->writeln("共计需清理{$cartNum}条数据====>" . getDateFull());
        $state = (new SaasCart)->where("create_at","<",getDateFull())->delete();
        if (!$state) {
            $output->writeln("清理失败====>" . getDateFull());
        } else {
            $output->writeln("清理完成====>" . getDateFull());
        }
        return self::SUCCESS;
    }

}