<?php
/**
 * Created by PhpStorm.
 * User: tandunzhao
 * Date: 2017/12/5
 * Time: 下午4:24
 */

namespace App\Console\Commands;

use App\Modules\Channel\Services\ChannelService;
use App\Modules\Finance\Services\FinanceService;
use Log;
use Illuminate\Console\Command;

class PaymentStatisticTask extends Command
{
    /**
     * 执行命令   php artisan payment_statistic_task
     *
     * The name and signature of the console command.
     *
     * @var string
     */
    protected $signature = 'payment_statistic_task';

    /**
     * The console command description.
     *
     * @var string
     */
    protected $description = '每日打款报表生成';

    /**
     * Execute the console command.
     *
     * @return mixed
     */
    public function handle()
    {
        print_r("======每日打款报表生成 【任务执行开始】=====".date("y-m-d H:i:s"."\n"));
        Log::info("======每日打款报表生成 【任务执行开始】=====".date("y-m-d H:i:s"."\n"));
        $channels = $this->getAllChannel();
        foreach ($channels as $channel) {
            //print_r($channel->id."=".$channel->name."\n");
            $channelId = $channel->id;
            FinanceService::makeYesterdayWithdrawCashStatistics($channelId);
//            print_r($channelId."=".$channelName."=".$rechargeAmount."\n");
        }
        Log::info("======每日打款报表生成 【任务执行结束】=====".date("y-m-d H:i:s"."\n"));
        print_r("======每日打款报表生成 【任务执行结束】=====".date("y-m-d H:i:s"."\n"));
    }

    /**
     * 获取所有渠道
     * @return mixed
     */
    public function getAllChannel() {
        $channels = ChannelService::getAllChannels();
        return $channels;
    }
}