<?php
/**
 * 会员账户
 * @Copyright (C) 2016 汉潮 All rights reserved.
 * @License http://www.hanchao9999.com
 * @Author zhaoh <1070309178@qq.com>
 */

namespace Member\Controller;
use Think\Controller;
class CapitalController extends BaseController {
	public function _initialize(){
		parent::_initialize ();
		$this->account_type=strtoarray(C('ACCOUNT_TYPE'));$this->assign('account_type',$this->account_type);
		$this->account_status=strtoarray(C('ACCOUNT_STATUS'));$this->assign('account_status',$this->account_status);
		$this->order_status=strtoarray(C('ORDER_STATUS'));$this->assign('order_status',$this->order_status);
		$this->pay_status=strtoarray(C('ORDER_PAY'));$this->assign('pay_status',$this->pay_status);
		
        $this->assign('menu_pid',4);
		$this->assign('menu_sid',1);
		$memberinfo=M('Member')->where('id='.MID)->field(true)->find();
		$this->assign('memberinfo',$memberinfo);
   	}
	//余额变更
    public function index(){
		$map['uid']=MID;
		$map['type']=array('in',array(1,2));
		$map['role']=0;
		$info=page_list('AccountLog',$map,'change_time desc,id desc',true,10,'',1);
		$this->assign('info',$info);
        $this->assign('tplseo_title','余额变更_会员中心_'.C('WEB_SITE_TITLE'));
        $this->display();
    }
	//充值明细
    public function recharge(){
		$postdata=I('param.');
		$map['uid']=MID;
		$map['type']=2;
		if(!empty($postdata['order_sn']))$map['order_sn']=$postdata['order_sn'];
		$info=page_list('OrderInfo',$map,'id desc,addtime desc',true,10,'',1);
		$this->assign('info',$info);$this->assign($postdata);
        $this->assign('tplseo_title','充值明细_会员中心_'.C('WEB_SITE_TITLE'));
        $this->display();
    }
	//继续支付
    public function go_pay(){
		$order_id=I('order_id');
		$map['is_delete'] = 0;
        $map['order_id'] = array("like", "%," . $order_id . ",%");
		$log_id = M("PayLog")->where($map)->getField('id');
		if($log_id){
			$return['status']=1;$return['url']=U('Home/Pay/go_buy','',false,true).'/?id='.$log_id;
		}else{
			$return['status']=0;$return['msg']='支付信息错误';
		}
		$this->ajaxReturn($return);
    }
	//提现明细
    public function withdraw(){
		$postdata=I('param.');
		$map['uid']=MID;
		if(!empty($postdata['status']))$map['status']=$postdata['status']-1;
        if(!empty($postdata['date_from']))$map['create_time'][]=array('EGT',strtotime($postdata['date_from']));
        if(!empty($postdata['date_to']))$map['create_time'][]=array('elt',strtotime($postdata['date_to']));
		$info=page_list('MemberWithdrawals',$map,'id desc,update_time asc',true,10,'',1);
		$this->assign('info',$info);$this->assign($postdata);
		//提现状态
		$this->get_status($postdata['status']);
        $this->assign('tplseo_title','提现明细_会员中心_'.C('WEB_SITE_TITLE'));
        $this->display();
    }
	private function get_status($id){
		$status_type=array(0=>'处理状态',1=>'未处理',2=>'已处理',3=>'已关闭');
		foreach($status_type as $k=>$v){
			if($id==$k){
				$status_selected.="<option selected='selected' value='$k'>$v</option>";
			}else{
				$status_selected.='<option value='.$k.'>'.$v.'</option>';
			}
		}
		$this->assign('status_type',$status_type);
		$this->assign('status_selected',$status_selected);
	}
}
?>