<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2017/11/22/022
 * Time: 19:25
 */

namespace console\controllers;

use backend\models\Member;
use backend\models\Mt4Trades;

class CacheDepositJobController extends BaseJobController
{
    public function actionRun()
    {
        date_default_timezone_set('Asia/Shanghai');
        $this->outLog("Job start " . date('Y-m-d H:i:s'));
        $cacheRun = $this->redis->get('CacheDepositJob');

        if (!$cacheRun) {
            $this->outLog("Auto cache deposit,".date('Y-m-d H:i:s'));
            $this->redis->set('CacheDepositJob', true);
            $ibs = Member::find()->where(['type' => 2])->asArray()->all();
            // 开始
            foreach ($ibs as $ib) {
                // 缓存统计代理商按天累计入金(不含今天)
                (new Mt4Trades)->findSumDepositByDay($ib['logins']);
                // $this->outLog('Auto cache deposit end,'.date('Y-m-d H:i:s'));
            }
            $this->redis->set("CacheDepositJob", false);
        }
        $this->outLog("Job end, " . date('Y-m-d H:i:s'));
        // $this->redis->del("CacheDepositJob");
    }
}