<?php 
namespace backend\models;

class DepositApi extends BaseApi
{
    public $apiUrl = 'deposit';

    /**
     * 入金列表
     * @param array $data
     * @return array
     */
    public function getDepositList($data = [])
    {
        $result = $this->get($this->apiUrl . '/index', $data);
        if ($result['code'] == 1) {
            return $this->returnArray(1, $result['data'], '获取入金记录成功');
        } else {
            return $this->returnArray(0, [], '获取入金记录失败');
        }
    }

    /**
     * 入金统计
     * @param int $type
     * @return array
     */
    public function sumDepositByType($type)
    {
        $data['type'] = $type;
        $result = $this->get($this->apiUrl . '/sum-deposit', $data);
        if ($result['code'] == 1) {
            return $this->returnArray(1, $result['data'], 'SUCCESS');
        } else {
            return $this->returnArray(0, [], 'FAILED');
        }
    }

    /**
     * 补单
     * @param int $id
     * @param string $admin_name
     * @return array
     */
    public function patchIntoGold($id, $admin_name = '')
    {
        $data = [
            'id' => $id,
            'admin_name' => $admin_name,
        ];
        $result = $this->post($this->apiUrl . '/patch-into-gold', $data);
        if ($result['code'] == 1) {
            return $this->returnArray(1, $result['data'], 'SUCCESS');
        } else {
            return $this->returnArray(0, [], 'FAILED');
        }
    }

    /**
     * 获取入金配置
     * @return array
     */
    public function getDepositConfig()
    {
        $result = $this->get($this->apiUrl . '/get-deposit-config');
        if ($result['code'] == 1) {
            return $this->returnArray(1, $result['data'], 'SUCCESS');
        } else {
            return $this->returnArray(0, [], 'FAILED');
        }
    }

    /**
     * 设置入金配置
     * @param string|array $config
     * @return array
     */
    public function setDepositConfig($config)
    {
        $data = [];
        if (is_array($config)) {
            $config = json_encode($config, 320);
        }
        $data['config'] = $config;
        $result = $this->post($this->apiUrl . '/set-deposit-config', $data);
        if ($result['code'] == 1) {
            return $this->returnArray(1, $result['data'], 'SUCCESS');
        } else {
            return $this->returnArray(0, [], $result['message']);
        }
    }
}