<?php
/**
 *------Create thems Controller------
 *------SCWPHP  Version 1.0.0------
 *------Dev Model Jions------
 *------Create Time 2017-06-13 15:41:29------
 */
namespace App\Api\Controller;
use Biz\Account\AccountManager;

class Money extends BaseController {
    public $money;
	public function init() {
		$this->money = new \Biz\Money\MoneyHandle;
	}
	/**
	 * 绑银行卡接口
	 */
	public function Bind_bank() {
		$account_identity = $this->verifyPar('account_identity', 'post'); //用户唯一id
		$bank_address = $this->verifyPar('bank_address', 'post'); //开户银行所在地
		$bank_name = $this->verifyPar('bank_name', 'post'); //银行名称
		$bank_no = $this->verifyPar('bank_no', 'post'); //银行卡号
		$bank_user = $this->verifyPar('bank_user', 'post'); //开户人姓名
		$pay_pwd = $this->verifyPar('pay_pwd', 'post'); //支付密码
		$sure_pwd = $this->verifyPar('sure_pwd', 'post'); //确认密码
		//$money = new \Biz\Money\MoneyHandle();
		$res = $this->money->bind_bank($account_identity, $bank_address, $bank_name, $bank_no, $bank_user, $pay_pwd, $sure_pwd);
		Render($res, '1', lang()->get('success'));
	}

	/**
	 * 设置交易密码接口
	 */
	public function Set_payPwd() {
		$account_identity = $this->verifyPar('account_identity', 'post'); //用户唯一id
		$pay_pwd = $this->verifyPar('pay_pwd', 'post'); //支付密码
		$sure_pwd = $this->verifyPar('sure_pwd', 'post'); //确认密码
		//$money = new \Biz\Money\MoneyHandle();
		$res = $this->money->setPayPwd($account_identity, $pay_pwd, $sure_pwd);
        Render($res, '1', lang()->get('success'));
	}

    /**
     * 设置交易密码接口 ,新增
     */
    public function SetPayPwd() {
        //$account_identity = isset($_SESSION['uinfo']['account_identity']) ? $_SESSION['uinfo']['account_identity'] : '';
        $am=new AccountManager();
        $uinfo=$am->getCurrentUser ();
        $account_identity=$uinfo?$uinfo->account_identity:'';
        $pay_pwd = $this->verifyPar('pay_pwd', 'post'); //支付密码
        $sure_pwd = $this->verifyPar('sure_pwd', 'post'); //确认密码
        //$money = new \Biz\Money\MoneyHandle();
        $res = $this->money->setPayPwd($account_identity, $pay_pwd, $sure_pwd);
        Render('', $res, '');
    }
    /**
     * 检测用户是否设置交易密码
     */
    public function CheckSetPayPwd() {
        $am=new AccountManager();
        $uinfo=$am->getCurrentUser ();
        $account_identity=$uinfo?$uinfo->account_identity:'';
        $res = $this->money->checkPayPwd($account_identity);
        Render('', $res, '');
    }

	/**
	 * 修改银行卡状态接口
	 */
	public function ChangeStatus() {
		$account_identity = $this->verifyPar('account_identity', 'post'); //用户唯一id
		$pay_pwd = $this->verifyPar('pay_pwd', 'post'); //支付密码
		$bank_no = $this->verifyPar('bank_no', 'post'); //银行卡号
		$type = $this->verifyPar('type', 'post'); //修改状态
		//$money = new \Biz\Money\MoneyHandle();
		$res = $this->money->bankStatus($account_identity, $bank_no, $pay_pwd, $type);
		Render($res, '1', lang()->get('success'));
	}

	/**
	 * 提现申请接口
	 */
	public function TakeMoney() {
		$money = $this->verifyPar('money', 'post'); //提现金额
		$account_identity = $this->verifyPar('account_identity', 'post'); //用户唯一id
		$pwd = $this->verifyPar('pay_pwd', 'post'); //支付密码
		//$money123 = new \Biz\Money\MoneyHandle();
		$res = $this->money->takeMoney($account_identity, $money, $pwd);
		Render($res, '1', lang()->get('success'));
	}

	/**
	 * 投注
	 */
	public function Betting() {
		$account_identity = $this->verifyPar('account_identity', 'post'); //用户唯一id
		$money = $this->verifyPar('money', 'post'); //操作所需金额
		$money_type = $this->verifyPar('money_type', 'post'); //资金类型
		$identity = UUID();
		$orderId = OrderID();
		$game_type = $this->verifyPar('game_type', 'post'); //游戏id
		$data = [
			'money_type' => $money_type,
			'identity' => $identity,
			'order_id' => $orderId,
			'game_type' => $game_type,
		];
		//$moneyclass = new \Biz\Money\MoneyHandle();
		$res = $this->money->betting($account_identity, $money, $data);
		Render($res, '1', lang()->get('success'));
	}

	/***
		     * 中奖
	*/
	public function Prize() {
		$account_identity = $this->verifyPar('account_identity', 'post'); //用户唯一id
		$money = $this->verifyPar('money', 'post'); //操作所需金额
		$game_type = 'testGame';
		//$moneyclass = new \Biz\Money\MoneyHandle();
		$res = $this->money->prize($account_identity, $money, $game_type);
		Render($res, '1', lang()->get('success'));}

	/**
	 * 充值
	 */
	public function AddMoney() {
		$account_identity = $this->verifyPar('account_identity', 'post'); //用户唯一id
		$money = $this->verifyPar('money', 'post'); //操作所需金额
		//$moneyclass = new \Biz\Money\MoneyHandle();
		$res = $this->money->addMoney($account_identity, $money);
		Render($res, '1', lang()->get('success'));
	}

	/**
	 * 撤单
	 */
	public function Cancel() {
		$account_identity = $this->verifyPar('account_identity', 'post'); //用户唯一id
		$order_id = $this->verifyPar('order_id', 'post'); //订单id
		//$money = new \Biz\Money\MoneyHandle();
		//$money->setPayPwd();
		$abc = $this->money->cancel($account_identity, $order_id);
		Render($abc, '1', lang()->get('success'));
	}
	/**
	 * 验证参数是否传入
	 * @param  [type] $name 参数名
	 * @param  [type] $type 传入类型
	 * @return [type]       返回参数
	 */
	public function verifyPar($name, $type) {
		if ($type == 'get') {
			$value = isset($_GET[$name]) ? $_GET[$name] : '';
		} else if ($type == 'post') {
			$value = isset($_POST[$name]) ? $_POST[$name] : '';
		}
		return $value;
	}
}
