<?php
namespace backend\modules\admin\controllers;

use backend\models\DepositApi;
use Yii;

class DepositConfigController extends BaseController
{
    /**
     * 入金配置
     * @return string
     */
    public function actionIndex()
    {
        $api = new DepositApi();
        $result = $api->getDepositConfig();
        $config = $result['data'] ? $result['data'] : [];
        return $this->render('index', ['config' => $config]);
    }

    /**
     * 入金设置
     * @return \yii\web\Response
     */
    public function actionConfigAjax()
    {
        $data = Yii::$app->getRequest()->post('config');
        if (empty($data)) {
            return $this->asJson(['isSuccess' => false, 'msg' => '参数非法']);
        }
        $api = new DepositApi();
        $result = $api->setDepositConfig($data);
        if ($result['code'] == 1) {
            return $this->asJson(['isSuccess' => true, 'msg' => '操作成功']);
        } else {
            return $this->asJson(['isSuccess' => false, 'msg' => $result['message']]);
        }
    }
}