<?php
namespace backend\controllers;

use backend\helpers\RandomHelper;
use backend\models\Mt4Trades;
use common\helpers\MtKit;
use common\lib\Mt4Deposit;
use common\lib\Mt4ManagerApi;

class TestController extends BaseController
{
    public function actionTestOpenUser()
    {
        $result = MtKit::openUser(629060, RandomHelper::getRandomStringForMt4(), RandomHelper::getRandomStringForMt4(), RandomHelper::getRandomStringForMt4(),
            '测试' . time(), 'XCBVARSTDUSD', 'test@qq.com', '13800000000', 100, '中国', '广东', '深圳', 'sz', '', '', 0);
        return $this->outJson(1, $result);
    }

    public function actionTestOpenUserDemo()
    {
        $result = MtKit::openUserDemo(null, RandomHelper::getRandomStringForMt4(), RandomHelper::getRandomStringForMt4(), RandomHelper::getRandomStringForMt4(),
            '测试' . time(), 1, 'test@qq.com', '13800000000', 100, 'China', null, 'sz', 'sz', null, null, null);
        return $this->outJson(1, $result);
    }

    public function actionTestDeposit()
    {
        $query = Mt4Trades::find();
        $query->where(['LOGIN' => 20000021, 'CLOSE_TIME' => '1970-01-01 00:00:00']);
        $query->andWhere(['<', 'CMD', 2]);
        $result = $query->count();
        $api = new Mt4ManagerApi();
       // $result = $api->balance('deposit', '20000021', 100);
        $result = $api->userUpdate('20000005', ['enable_read_only' => 0]);
        return $this->outJson(1, $result);
    }

    public function actionTestGroups()
    {
        $result = MtKit::getGroups();
        return $this->outJson(1, $result);
    }
}

