<?php
namespace backend\models;

use Yii;

class Mt4UserApi extends BaseApi
{
    public $apiUrl = 'mt4-user';

    /**
     * 获取用户信息
     * @param int $login
     * @param null|string $from
     * @return array
     */
    public function getUserInfo($login, $from = null)
    {
        $data = [];
        if ($from == 'admin') {
            $data['from'] = $from;
        }
        $data['login'] = $login;
        $result = $this->get($this->apiUrl . '/info', $data);
        if ($result['code'] == 1) {
            return $this->returnArray(1, $result['data'], '获取用户信息成功');
        } else {
            return $this->returnArray(0, [], '获取用户信息失败');
        }
    }

    /**
     * @param array $data
     * @return array
     */
    public function getList($data)
    {
        $data['member_id']  = Yii::$app->user->id;
        $result = $this->post($this->apiUrl . '/list', $data);
        if ($result['code'] == 1) {
            return $this->returnArray(1, $result['data']);
        } else {
            return $this->returnArray(0, [], $result['message']);
        }
    }

    /**
     * MT4账户列表
     * @param array $data
     * @return array
     */
    public function getPagelist($data)
    {
        $result = $this->get($this->apiUrl . '/pagelist', $data);
        if ($result['code'] == 1) {
            return $this->returnArray(1, $result['data']);
        } else {
            return $this->returnArray(0, [], $result['message']);
        }
    }
}