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

namespace backend\modules\admin\controllers;

use backend\models\LeverApi;
use backend\models\searches\LeverSearch;

class ModifyLeverController extends BaseController
{
    public $enableCsrfValidation = false;

    public function actionIndex()
    {
        $request = \Yii::$app->getRequest();
        $type = (int)$request->get('type');
        $member_id = !empty($request->get('memberId')) ? (int)$request->get('memberId') : '';
        $sTime = $request->get('sTime');
        $eTime = $request->get('eTime');
        return $this->render('index', [
            'type' => $type,
            'member_id' => $member_id,
            'sTime' => $sTime,
            'eTime' => $eTime,
        ]);
    }

    /**
     * 获取修改杠杆记录
     */
    public function actionLeverAjax()
    {
        $searchModel = new LeverSearch();
        $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'] : '';
        
        $leverApi = new LeverApi();
        $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 LeverApi();
        $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 LeverApi();
        $rs = $leverApi->memoUpdate($params);
        return $this->asJson($rs);
    }
}