<?php
/**
 * 充值提现
 * @Copyright (C) 2016 汉潮 All rights reserved.
 * @License http://www.hanchao9999.com
 * @Author zhaoh <1070309178@qq.com>
 */

namespace Mobile\Controller;
use Think\Controller;
class WithdrawalsController extends BaseController {
	public function _initialize(){
		parent::_initialize ();
		if(!MID){
			cookie('forward',U('Mobile/'.CONTROLLER_NAME.'/'.ACTION_NAME));
			$this->redirect('Mobile/Login/index');
		}
		if($this->m_info['is_tmp']==1&&!$this->m_info['mobile']){
			session('format_url',U('Mobile/Withdrawals/index'));
			$this->error('请先完善资料!',U('Mobile/Login/perfect'));exit;
			// $this->redirect('Mobile/Login/perfect');
		}elseif($this->m_info['is_tmp']==1&&$this->m_info['mobile']){
			$this->error('您已经领取过会员卡了！');exit;
		}
		$user_info=M('Member')->where('id='.MID)->field(true)->find();
		$this->assign('user_info',$user_info);
   	}
	//充值
    public function index(){
		$member_info=session('member_info');
		$m_map = array();$m_map['id'] = $member_info['id'];$m_map['mobile'] = array('neq','');
		$is_m = M('Member')->where($m_map)->count();
		if(empty($is_m)){
			session('format_url',U('Mobile/Withdrawals/index'));
			$this->error('请先完善资料',U('Mobile/Login/perfect'));exit;
		}
		
        $this->assign('tplseo_title', '我要充值' . '_' . C('WEB_SITE_TITLE'));
		$recharge_info = C('FIXED_RECHARGE');
		if($recharge_info){
			$recharge_arr = explode(',',$recharge_info);
			$this->assign('recharge_arr',$recharge_arr);
		}

		$map=array();
		$map['consumption_type'] = array('in','1,3');
		$list = $this->lists('ManypointsRule',$map);
		$this->assign('list',$list);
		$this->assign('fixed',$recharge_info);
        $this->assign('page_title', '我要充值');
        $this->display();
    }
	//充值操作
	public function go_recharge(){
		$postdata=I('post.');
		//if(!check_verify($postdata['verify'], 'Mobile')){$data['status']=0;$data['info']=L('verify_error');$this->ajaxReturn($data);exit;}
		unset($postdata['money_val']);unset($postdata['money_r']);
		$result=D('Common/Withdrawals')->recharge($postdata);
		//echo "<pre>";
		//print_r($result);//exit;
		if($result['status']){$result['url']=U('Home/Pay/go_buy','',false,true).'/?id='.$result['log_id'];}
		$this->ajaxReturn($result);
    }
	//提现
    public function withdrawals(){
		$payfree=C('TIXIAN_FREE');	//提现手续费
		if($payfree<1)$num=$payfree*100;
		$this->assign('num',$num);
		$tx_min_money=C('USER_MIN_GET_MONEY');	//最低提现金额
		$MEMBER_BANK=idtoname('MEMBER_BANK','Config','value,extra','name');
		$banks_arr=array_values(strtoarray($MEMBER_BANK['extra']));
		$banks_value=array_unique(explode(',',$MEMBER_BANK['value']));
		foreach($banks_arr as $key=>$v){if(in_array($v,$banks_value))$banksarr[$key+1]=$v;}
		$this->assign('banks',$banksarr);
		$this->assign('real_name',$this->user_info['real_name']);
        $this->assign('tplseo_title', '我要提现' . '_' . C('WEB_SITE_TITLE'));
        $this->assign('page_title', '我要提现');
        $this->display();
    }
	//提现操作
	public function go_withdrawals(){
		$postdata=I('post.');
		$result=D('Common/Withdrawals')->get_money($postdata);
		if($result['status']==1){
			$result['url']=U('Capital/index');
		}elseif($result['status']==2){
			$result['url']=U("UserInfo/security");
		}
		$this->ajaxReturn($result);
    }
	//添加提现银行
	public function add_bank(){
		$postdata=I('post.');
		$result=D('Common/Withdrawals')->add_bank($postdata);
		if($result['status'])$result['url']=U('Withdrawals/withdrawals');
		$this->ajaxReturn($result);
    }
	//获取验证码
    public function verify(){
        $config = array(
            'imageW' => '170',
            'imageH' => '50',
            'seKey' => 'chanchao' . C('HANCHAO_KEY'),
            'length' => 4,
        );
        $verify = new \Common\Vendor\Verify($config);
        $verify->entry('Mobile');
    }
	//提现银行信息
	private function getmemberbank(){
		$map['uid']=MID;$map['status']=1;
		$bank_info=M('MemberBank')->where($map)->field('name,bankname,bankcode')->find();
		
		if($bank_info['bankcode']){
			$length=strlen($bank_info['bankcode']);
			if(str_exists('@',$bank_info['bankcode'])){
				$bankcodearr=explode('@',$bank_info['bankcode']);
				$bank_info['bankcode']=substr($bankcodearr[0],0,(strlen($bankcodearr[0])-4)).'****@'.$bankcodearr[1];
			}else{
				$bank_info['bankcode']=substr($bank_info['bankcode'],0,($length-4)).'****';
			}
		}
		$this->assign('bank_info',$bank_info);
		$banks=array_unique(explode(',',C('MEMBER_BANK')));
		foreach($banks as $v){$banksarr[$v]=$v;}
		$this->assign('banks',$banksarr);

	}
}
?>