<?php 
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2017/11/28/028
 * Time: 16:24
 */

namespace backend\modules\admin\controllers;


use backend\models\searches\TransferSearch;
use backend\models\TransferApi;

class TransferController extends BaseController
{
    public $enableCsrfValidation = false;

    public function actionIndex()
    {
        $request = \Yii::$app->getRequest()->get();
        $params['type'] = (int)$request['type'];
        $params['member_id'] = !empty($request['memberId']) ? (int)$request['memberId'] : '';
        $params['sTime'] = isset($request['sTime']) ? $request['sTime'] : '';
        $params['eTime'] = isset($request['eTime']) ? $request['eTime'] : '';
        return $this->render('index', [
            'data' => $params,
        ]);
    }
    
    /**
     * 同名转账列表
     */
    public function actionTransferAjax()
    {
        $searchModel = new TransferSearch();
        $request = \Yii::$app->getRequest()->getQueryParams();
        $dataProvider = $searchModel->search($request, 'admin');
        return $this->asJson($searchModel->outResult($dataProvider));
    }

    /**
     * 审核修改杠杆
     */
    public function actionType()
    {
        $request = \Yii::$app->getRequest()->post();
        $params['id'] = isset($request['id']) ? (int)$request['id'] : '';
        $params['type'] = isset($request['type']) ? (int)$request['type'] : '';
        $params['admin_name'] = \Yii::$app->getUser()->getIdentity(false)->name;

        $leverApi = new TransferApi();
        $rs = $leverApi->updateType($params);
        return $this->asJson($rs);
    }

    /**
     * 某条记录的备注
     */
    public function actionMemo()
    {
        $request = \Yii::$app->getRequest()->get();
        $params['id'] = isset($request['id']) ? (int)$request['id'] : '';

        $leverApi = new TransferApi();
        $rs = $leverApi->memo($params);
        return $this->renderPartial('memo', [
            'data' => $rs['data'],
        ]);
    }

    /**
     * 更新备注
     */
    public function actionMemoUpdate()
    {
        $request = \Yii::$app->getRequest()->post();
        $params['id'] = isset($request['id']) ? (int)$request['id'] : '';
        $params['memo'] = isset($request['memo']) ? $request['memo'] : '';

        $leverApi = new TransferApi();
        $rs = $leverApi->memoUpdate($params);
        return $this->asJson($rs);
    }
}