<?php
namespace App\Models;
/**
 *
 */
class Account_bank extends BaseModel {
	protected $table = 'account_bank';
	public $timestamps = false;

	function account_bank($list, $page, $where = '') {
		$data = $this->join('account', 'account.identity', '=', 'account_bank.account_identity')
			->join('account_detailed', 'account.identity', '=', 'account_detailed.account_identity')
			->select('account_bank.id', 'account', 'account.identity', 'bank_name', 'bank_number', 'bank_address', 'band_time','account_detailed.name', 'account_name', 'account_bank.status')
			->orderBy('band_time', 'desc')
		// ->where('account_bank.status', '1')
			->paginate($list);
		if (!empty($where) && is_array($where)) {
			$data = $this->join('account', 'account.identity', '=', 'account_bank.account_identity')
				->join('account_detailed', 'account.identity', '=', 'account_detailed.account_identity')
				->select('account_bank.id', 'account', 'account.identity', 'bank_name', 'bank_number', 'bank_address', 'band_time', 'account_name', 'account_detailed.name','account_bank.status')
				->orderBy('band_time', 'desc')
				->where($where)
				->paginate($list);
		}
		if (!$data) {
			return -2020042003; //没有银行卡添加
		}
		return $data->toArray();
	}

	//开关
	function closeGame($data, $game) {
		$res = $this->where('bank_number', $game)->update($data);
		if (!$res) {
			return -5040000122;
		}
		return $res;
	}
	//通过uid获取信息
	function getInfoByUid($uid) {
		$data = $this->join('account_detailed', 'account_detailed.account_identity', '=', 'account_bank.account_identity')
					 ->where('account_bank.account_identity', $uid)->first();
		if (!$data) {
			return array(); //没有银行卡信息
		}
		return $data->toArray();
	}

	function updateOne($data, $id) {
		$res = $this->where('account_identity', $id)->update($data);
		if (!$res) {
			return -5040001101; //失败
		}
		return 1;
	}
	
	//检测用户是否有银行卡信息
	function checkHasBank($id) {
		$data = $this->where('account_identity', $id)->first();
		if (!$data) {
			return -5040000102; //无相关信息
		}
		return $data->toArray();
	}

	/**
	 * 检测银行卡是否相同
	 * [checkBank description]
	 * @param  [type] $fild  [description]
	 * @param  [type] $value [description]
	 * @return [type]        [description]
	 */
	function checkBank($fild, $value) {
		$res = $this->where($fild, $value)->first();
		if ($res) {
			return false;
		}
		return true;
	}

}

?>