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

namespace App\Console\Commands\CP;

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

class GenerateCpBookBetweenStat extends Command
{
    /**
     * 执行命令   php artisan cp_generate_cp_book_between_stat 2018-10-01 2018-11-01
     *
     * The name and signature of the console command.
     *
     * @var string
     */
    protected $signature = 'cp_generate_cp_book_between_stat {start_date} {end_date}';

    /**
     * The console command description.
     *
     * @var string
     */
    protected $description = 'CP图书订阅指定时间区间数据生成';

    /**
     * Execute the console command.
     * 注意：start_date <= 计算区间 <= end_date
     * @return mixed
     */
    public function handle()
    {
        print_r("======CP图书订阅指定时间区间数据生成 【任务执行开始】=====" . date("y-m-d H:i:s" . "\n"));
        Log::info("======CP图书订阅指定时间区间数据生成【任务执行开始】=====" . date("y-m-d H:i:s" . "\n"));
        
        $start_date = $this->argument('start_date');
        $end_date = $this->argument('end_date');
        if(empty($start_date) || empty($end_date)){
        	Log::info('GenerateCpBookBetweenStat param null:start_date:'.$start_date.' end_date:'.$end_date);
        }
        $month = date('Y-m',strtotime($start_date));
        $calculate_date = $end_date;
        $end_date = date('Y-m-d',strtotime($end_date) - 24*3600);
        Log::info('start_date:'.$start_date.' end_date:'.$end_date.' month:'.$month.' calculate_date:'.$calculate_date);

        GenerateCpBookStatService::generateCpBookBetweenStat($start_date,$end_date,$month,$calculate_date);

        Log::info("======CP图书订阅指定时间区间数据生成 【任务执行结束】=====" . date("y-m-d H:i:s" . "\n"));
        print_r("======CP图书订阅指定时间区间数据生成 【任务执行结束】=====" . date("y-m-d H:i:s" . "\n"));
    }
}