<?php
/**
 * zhoulj
 * 2018-05-15
 */

namespace App\Console\Commands\CP;

use App\Modules\CP\Services\GenerateCpBookStatService;
use Illuminate\Console\Command;
use Log;

class fixCpBookStat extends Command
{
    /**
     * 执行命令   php artisan cp_generate_cp_book_stat
     *
     * The name and signature of the console command.
     *
     * @var string
     */
    protected $signature = 'cp_fix_cp_book_stat {--date=}';

    /**
     * The console command description.
     *
     * @var string
     */
    protected $description = '每日CP图书订阅数据修复';

    /**
     * Execute the console command.
     *
     * @return mixed
     */
    public function handle()
    {
        print_r("======每日CP图书订阅数据fix 【任务执行开始】=====" . date("y-m-d H:i:s" . "\n"));
        Log::info("======每日CP图书订阅数据fix【任务执行开始】=====" . date("y-m-d H:i:s" . "\n"));

        // 生成每日统计
        if($this->option('date')){
            $date = $this->option('date');
        }else{
            $date = date("Y-m-d", strtotime('-1 day'));
        }
        GenerateCpBookStatService::fixCpBookDailyStat($date);

        Log::info("======每日CP图书订阅数据fix【任务执行结束】=====" . $date. "\n");
        print_r("======每日CP图书订阅数据fix【任务执行结束】=====" .$date. "\n");
    }
}