<?php

namespace App\Console\Commands\ProductStats;

use App\Modules\Statistic\Services\ProductionStatsEmailService;

use Illuminate\Console\Command;
use DB;

class DailyProductionStats extends Command
{
    /**
     * The name and signature of the console command.
     *
     * @var string
     */
    protected $signature = 'saveDailyProductsStats';

    /**
     * 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()
    {
        //
        $from_date = date('Y-m-d 00:00:00',strtotime('-1 day'));
        $end_date = date('Y-m-d 23:59:59',strtotime('-1 day'));
        //更新男女频
        DB::update("UPDATE book_updates a  JOIN books b on a.bid=b.id JOIN book_categories c on b.category_id=c.id  set a.channel_name=c.channel_name  WHERE a.update_date= DATE_ADD(date(NOW()),INTERVAL -1 DAY)");
        //ProductionStatsEmailService::setDayStats($from_date,$end_date);
        ProductionStatsEmailService::setDayStatsNew($from_date,$end_date);
    }
}
