<?php
/**
 渠道周报数据
 */

namespace App\Console\Commands\DistributionStats;

use Log;
use Illuminate\Console\Command;
use App\Modules\OfficialAccount\Models\TempForceSubscribeUsers;
use App\Modules\OfficialAccount\Services\MsgService;
use App\Modules\SendOrder\Services\SendOrderStatisticsService;
use App\Modules\Channel\Models\Channel;
use DB;

class WeeklyDailyStats extends Command
{
    /**
     * 执行命令  WeeklyDailyStats 123
     *
     * The name and signature of the console command.
     *
     * @var string
     */
    protected $signature = 'WeeklyDailyStats {channel_id}';

    /**
     * The console command description.
     *
     * @var string
     */
    protected $description = '维护渠道周报数据';

    /**
     * Execute the console command.
     *
     * @return mixed
     */
    public function handle()
    {
        ini_set('memory_limit', '1024M');
        print_r('memory_used:'.memory_get_usage()."\n");
        print_r("======维护渠道周报数据【任务执行开始】=====".date("y-m-d H:i:s"."\n"));
        $distribution_channel_id = $this->argument('channel_id');
        if($distribution_channel_id != 'all'){
       		\Log::info('start_getWeeklySendOrderStatistics:'.$distribution_channel_id);
        	SendOrderStatisticsService::getWeeklySendOrderStatistics($distribution_channel_id);
        }else{
        	$distribution_channels = Channel::getAllChannels();
        	// 渠道列表
        	foreach($distribution_channels as $distribution_channel){
        		$distribution_channel_id = $distribution_channel->id;
        		\Log::info('start_getWeeklySendOrderStatistics:'.$distribution_channel_id);
        		SendOrderStatisticsService::getWeeklySendOrderStatistics($distribution_channel_id);
        	}
        }
        
        print_r("======维护渠道周报数据 【任务执行结束】=====".date("y-m-d H:i:s"."\n"));
        print_r('memory_used:'.memory_get_usage()."\n");
    }
}