<?php
/**
 * 会员中心
 * @Copyright (C) 2016 汉潮 All rights reserved.
 * @License http://www.hanchao9999.com
 * @Author lss <lss@qq.com>
 */
namespace Member\Controller;
use Think\Controller;
class UserinfoController extends BaseController
{
    public function _initialize()
    {
        parent::_initialize();
        $this->assign($this->member_info);
    }

    public function user_infor()
    {
        $map['id'] = $this->member_info['id'];
        $memberinfo = M('Member')->where($map)->field(true)->find();
        $this->assign('memberinfos', $memberinfo);
		//第三方登录信息
		$maps['lock_to_id']=MID;
		$info=M('OauthMember')->where($maps)->field('id,_from')->find();
		$this->assign('info', $info);
        $this->assign('tplseo_title', '会员信息_会员中心_' . C('WEB_SITE_TITLE'));
        $this->display();
    }

    /**
     *修改会员信息，登录密码，支付密码
     */
    public function updateinfo()
    {
        if (IS_POST) {
            $postdata = I('param.');
            $data = D('Common/Member')->user_infor($postdata);
            $this->ajaxReturn($data);
        }
    }
    /**
     *获取会员的地址
     */
    public function address()
    {
        $address_list = D('Common/Member')->get_address_list();
        $this->assign($address_list);
        $this->assign('address_num', C('MEMBER_RECRIVE_ADDRESS_NUM'));
        $this->assign('tplseo_title', '收货地址_会员中心_' . C('WEB_SITE_TITLE'));
        $this->display();
    }

    /**
     *地址弹出框
     */
    public function pop_address()
    {
        $id = I(id);
        if ($id > 0) {
            $address = D('Common/Member')->address_cont($id);
            $this->assign('address', $address);
        }
        $this->display();
    }

    /**
     *添加或修改地址
     */
    public function update_address()
    {
        $postdata = I('post.');
        $result = D('Common/Member')->modify_address($postdata);
        $this->ajaxReturn($result);
    }

    /**
     *删除收货地址
     */
    public function del_address($id)
    {
        $data = D('Common/Member')->delete_address($id);
        $this->ajaxReturn($data);
    }
    /**
      *修改交易密码
      */
    public function securitys(){
        $memberinfo=M('Member')->where('id='.MID)->field('paypassword,salt')->find();
        $this->assign('memberinfo',$memberinfo);
        $this->display();
    }
	/**
      *修改卡交易密码
      */
    public function card_securitys(){
        $memberinfo=M('Member')->where('id='.MID)->field('card_paypass,salt')->find();
        $this->assign('memberinfo',$memberinfo);
        $this->display();
    }
    //推广
    public function extension()
    {
        $data = D('Common/Member')->extension();
        $this->assign($data);
        $this->assign('extensionname', '推广');
        $this->assign('tplseo_title', '我要推广_会员中心_' . C('WEB_SITE_TITLE'));
        $this->display();
    }

    //推广分成
    public function my_extension()
    {
        $postdata = I('post.');
        $data = D('Common/Member')->my_extension($postdata);
        $this->assign($data);
        $this->assign($postdata);
        $this->assign('tplseo_title', '推广分成_会员中心_' . C('WEB_SITE_TITLE'));
        $this->display();
    }
    //推广列表
    public function extension_list(){
        $postdata = I('param.');
        $data = D('Common/Member')->extension_list($postdata);
        $this->assign($data);
        $this->assign('tplseo_title', '推广列表_会员中心_' . C('WEB_SITE_TITLE'));
        $this->display();
    }
	/* *
	 * 解除第三方绑定信息
	 */
    public function del_other(){
		$return=array('status'=>0,'info'=>'');
        $id = I('param.id');
		$map['id']=$id;
		$map['lock_to_id']=MID;
		$result=M('OauthMember')->where($map)->delete();
		if($result){
			$return['status']=1;
			$return['info']='解除成功';
		}else{
			$return['info']='解除失败';
		}
        $this->ajaxReturn($return);
    }
	public function user_card(){
		$card_status = idtoname($this->member_info['id'],'Member','status','id',false);
		if ($card_status != 1) {$this->error('您还未开通会员卡，请到就近店铺开通！');}
		$data = D('Common/Member')->member_card($this->member_info);
		$this->assign($data);
		$this->display();
	}
}
?>