<?php

namespace App\Console\Commands;

use App\Models\Log;
use Illuminate\Console\Command;

class DeleteKttQuery extends Command
{
    /**
     * The name and signature of the console command.
     *
     * @var string
     */
    protected $signature = 'delete:ktt_query';

    /**
     * The console command description.
     *
     * @var string
     */
    protected $description = '删除接口历史请求数据';

    /**
     * Create a new command instance.
     *
     * @return void
     */
    public function __construct()
    {
        parent::__construct();
    }

    /**
     * Execute the console command.
     *
     * @return mixed
     */
    public function handle()
    {
        $count = Log::query()->where('target_field', 'pdd.ktt.goods.query.list')
            ->where('created_at', '<', date('Y-m-d H:i:s', strtotime('-1 day')))
            ->delete();
        $this->info('删除商品列表查询: ' . $count);

        $count = Log::query()->where('target_field', 'pdd.ktt.order.list')
            ->where('created_at', '<', date('Y-m-d H:i:s', strtotime('-2 day')))
            ->delete();
        $this->info('删除根据成交时间拉取订单列表: ' . $count);

        $count = Log::query()->where('target_field', 'pdd.ktt.increment.order.query')
            ->where('created_at', '<', date('Y-m-d H:i:s', strtotime('-2 day')))
            ->delete();
        $this->info('删除增量查订单: ' . $count);

        $count = Log::query()->where('target_field', 'pdd.ktt.goods.incr.quantity')
            ->where('created_at', '<', date('Y-m-d H:i:s', strtotime('-3 day')))
            ->delete();
        $this->info('删除快团团更新库存: ' . $count);

        $count = Log::query()->where('target_field', '更新库存')
            ->where('created_at', '<', date('Y-m-d H:i:s', strtotime('-3 day')))
            ->delete();
        $this->info('删除妙选更新库存: ' . $count);

        $count = Log::query()->where('target_field', 'stock')
            ->where('created_at', '<', date('Y-m-d H:i:s', strtotime('-3 day')))
            ->delete();
        $this->info('删除更新库存: ' . $count);
    }
}
