<?php
/**
 * 账号中心
 * @Copyright (C) 2016 汉潮 All rights reserved.
 * @License http://www.hanchao9999.com
 * @Author zhaoh <zhao@qq.com>
 */

namespace Supplier\Controller;
use Think\Controller;
class AccountController extends BaseController {
	/**
	* 供货商日志
	*/
    public function index(){
		$post=I('param.');
		$tabid=$post['tabid'];
		if(empty($tabid)){
			$this->get_action_arr();
			$list=D('Account')->action_list($post);
			$this->assign($list);$this->assign($post);
		}
		$tabid=$tabid?$tabid:'index';
        $this->display($tabid);
    }
	/**
	 * 供货商日志
	 */
	public function actionlog(){
		$post=I('param.');
		$tabid=$post['tabid'];
		if(empty($tabid)){
			$this->get_action_arr();
			$list=D('Account')->action_list($post);
			$this->assign($list);$this->assign($post);
		}
		$tabid=$tabid?$tabid:'actionlog';
        $this->display($tabid);
    }
	/**
	 * 消费记录
	 */
	public function accountlog(){
		$post=I('param.');
		$tabid=$post['tabid'];
		if(empty($tabid)){
			//变更类型
			$type_status=array();
			$type_status[1]='余额';
			$type_status[2]='未结算';
			$type_status[3]='待结算';
			$type_status[4]='冻结资金';
			$type_status[5]='销售总额';
			$list=D('Account')->account_list($post);
			//供货商资金
			$map['id']=$this->supplier_info['id'];
			$supplierinfo=M('Suppliers')->where($map)->field('total_revenues,money,unbalance,onbalance')->find();
			$this->assign($list);$this->assign($post);
			$this->assign('type_status',$type_status);
			$this->assign('supplierinfo',$supplierinfo);
		}
		$tabid=$tabid?$tabid:'accountlog';
        $this->display($tabid);
    }
	public function get_action_arr(){
		$map['status']=1;
		$map['type']=4;
		$actionarr=M('Action')->where($map)->field('id,title')->select();
		foreach($actionarr as $k=>$v){
			$arr[$v['id']]=$v['title'];
		}
		$this->assign('actionarr',$arr);
	}
	/**
	 * 修改密码
	 */
	public function modify_psw(){
		$post=I('param.');
		$tabid=$post['tabid'];
		$tabid=$tabid?$tabid:'modify_psw';
        $this->display($tabid);
	}
	/**
	 * 充值提现
	 */
  //   public function recharge(){
		// $post=I('param.');
		// $tabid=$post['tabid'];
		// if(empty($tabid)){//充值
			
		// }elseif($tabid=='get_money'){//提现
		// 	$payfree = C('SHOP_TIXIAN_FREE');
		// 	if ($payfree < 1) {
		// 		$num = $payfree * 100;
		// 		$this->assign('num', $num);
		// 	}
		// 	$supplier_info=M('Suppliers')->where('id='.MID)->field(true)->find();
		// 	$this->assign('supplier_info', $supplier_info);
		// 	$this->getmemberbank();
		// }
  //       $tabid=$tabid?$tabid:'get_money';
  //       $this->display($tabid);
  //   }
    /**
	 * 充值提现
	 */
    public function get_money(){
		$post=I('param.');
		$payfree = C('SHOP_TIXIAN_FREE');
		if ($payfree < 1) {
			$num = $payfree * 100;
			$this->assign('num', $num);
		}
		$supplier_info=M('Suppliers')->where('id='.MID)->field(true)->find();
		$this->assign('supplier_info', $supplier_info);
		$this->getmemberbank();
        $tabid=$tabid?$tabid:'get_money';
        $this->assign('tplseo_title','申请提现_'.C('WEB_SITE_TITLE'));
        $this->display($tabid);
    }
	/**
	 * 充值操作
	 */
    public function go_recharge(){
        $postdata = I('post.');
        //if(!check_verify($postdata['verify'], 'Member')){$data['status']=0;$data['info']=L('verify_error');$this->ajaxReturn($data);exit;}
        $result = D('Common/Withdrawals')->recharge($postdata);
        if ($result['status']) {
            $result['url'] = U('Home/Pay/go_buy', array('id' => $result['log_id']));
        }
        $this->ajaxReturn($result);
    }
	/**
	 * 提现操作
	 */
    public function go_withdrawals(){
        $postdata = I('post.');
        $result = D('Common/Withdrawals')->suppliers_get_money($postdata);
        if ($result['status'] == 1) {$result['url'] = U('Supplier/Account/accountlog');}
        $this->ajaxReturn($result);
    }
	/**
	 * 添加提现银行
	 */
    public function add_bank(){
        $postdata = I('post.');
        $result = D('Common/Withdrawals')->add_bank($postdata);
        if ($result['status']) $result['url'] = U('Supplier/Account/get_money');
        $this->ajaxReturn($result);
    }
	/**
	 * 提现银行信息
	 */
    private function getmemberbank(){
        $map['uid'] = MID;
        $map['status'] = 1;
		$map['type'] = 2;
        $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);
    }
}
?>