<?php
/**
 * 会员中心
 * @Copyright (C) 2016 汉潮 All rights reserved.
 * @License http://www.hanchao9999.com
 * @Author zhaoh <1070309178@qq.com>
 */
namespace Mobile\Controller;
use Think\Controller;
class MemberController extends BaseController {
	public function _initialize(){
		parent::_initialize ();
		if(!MID){
			cookie('forward',U('Mobile/'.CONTROLLER_NAME.'/'.ACTION_NAME));
			$this->redirect('Mobile/Login/index');
		}
	}
	public function index(){
		session('jump',NULL);
        $u_map['id']=MID;
		$info=M('Member')->where($u_map)->field(true)->find();
		$this->assign('info',$info);
		$map = $c_map = $xs_map = array();
		$map['uid']=MID;
		$no_pay=D('Common/OrderInfo')->all_order($map,2,1);$this->assign('no_pay',$no_pay);
		$takeout=D('Common/OrderInfo')->all_order($map,4,1,5,true,14);$this->assign('takeout',$takeout);
		$no_group=D('Common/OrderInfo')->all_order($map,6,1);$this->assign('no_group',$no_group);//待成团
		$no_ship=D('Common/OrderInfo')->all_order($map,3,1);$this->assign('no_ship',$no_ship);
		$yes_ship=D('Common/OrderInfo')->all_order($map,4,1);$this->assign('yes_ship',$yes_ship);
		$no_comment=D('Common/OrderInfo')->all_order($map,5,1);$this->assign('no_comment',$no_comment);
		$service_order=D('Common/OrderInfo')->all_order($map,7,1,'','',7);$this->assign('service_order',$service_order);//服务订单

		$tui_kuan=D('Common/OrderInfo')->all_order($map,9,1);$this->assign('tui_kuan',$tui_kuan);
		// 收藏商品
		// $goods_count=M('GoodsCollect')->where($map)->field('id')->count();
		// $shops_count=M('ShopsCollect')->where($map)->field('id')->count();
		$xs_map['user_id'] = MID;
		$xs_bonu=M('MemberBonus')->where($xs_map)->field('id')->count();
		$c_map = $map;
		$c_map['coupons_type'] = 1;
		$get_coupons=M('CouponsGet')->where($c_map)->field('id')->count();
        $color = unserialize(C('WX_CARD'))['color'];
		
        $this->assign('color',$color);
		// $this->assign('goods_count',$goods_count);
		$this->assign('get_coupons',$get_coupons);
		$this->assign('xs_bonu',$xs_bonu);
        $this->assign('tplseo_title','会员中心'.'_'.C('WEB_SITE_TITLE'));
        $this->assign('page_title','会员中心');
        
        if($info['header_img'] && str_exists($info['header_img'],'http')){
            $header_type=getwebimageinfo($info['header_img']);
            $w_img= ROOT_PATH."/uploads/image/qrcode/cache/header_".MID.".".$header_type;//微信临时头像
        }else{
            $w_img=$info['header_img'];
        }
        $header_cache=$w_img?file_exists($w_img):1;
        $this->assign('header_cache',$header_cache);
        
		$this->display();
	}
    public function cacheheader(){
        $u_map['id']=MID;
		$info=M('Member')->where($u_map)->field('header_img')->find();
         if($info['header_img'] && str_exists($info['header_img'],'http')){
            $header_type=getwebimageinfo($info['header_img']);
            $w_img= ROOT_PATH."/uploads/image/qrcode/cache/header_".MID.".".$header_type;//微信临时头像
            if(!file_exists($w_img)){
                file_put_contents($w_img,file_get_contents($info['header_img']));
                echo $w_img;
            }
        }
    }
	public function views_list($type = 0){
        $this->assign('tplseo_title','我的足迹'.'_'.C('WEB_SITE_TITLE'));
        $this->assign('page_title','我的足迹');
		$goods_ids=session(MID+'_footer_history');
		if(!empty($goods_ids)){
			$page=I('param.page');
			$page=$page?$page:1;
			$map['id']=array('in',$goods_ids);
			$info=page_list('Goods',$map,$order,'id,goods_name,img,shop_price,market_price',10,'',$page);
			if ($type == 1) return $info;
			$this->assign($info);
		}
		$this->display();
	}
	public function get_views_list(){
        $return['status'] = 0;
        $data = $this->views_list(1);
        if (empty($data['list'])) $this->ajaxReturn($return);

        $return['status'] = 1;
        $this->assign($data);
        $list_html = $this->fetch('views_page_list');
        $return['data'] = $list_html;
        $this->ajaxReturn($return);
    }
	public function member_card(){
		$card_status = idtoname($this->member_info['id'],'Member','card_status','id',false);
		if ($card_status != 1) {$this->error('您还未开通会员卡，请到就近店铺开通！');}
		$data = D('Common/Member')->member_card($this->member_info);
		$this->assign('page_title', '我的会员卡');
		$this->assign($data);
		$this->display();
	}
	public function my_package(){
		if($this->m_info['is_tmp']==1&&!$this->m_info['mobile']){
			$this->redirect('Mobile/Login/perfect');
		}elseif($this->m_info['is_tmp']==1&&$this->m_info['mobile']){
			$this->error('您已经领取过会员卡了！');exit;
		}
		$map['uid'] = MID;
		$map['package_id'] = array('neq',0);
		$my_order = M('MemberPackage')->where($map)->field('order_id')->group('order_id')->select();
		foreach($my_order as $k=>$v){
			$true = 0;
			$where['uid'] = MID;
			$where['order_id'] = $v['order_id'];
			$where['package_id'] = array('neq',0);
			$order_package = M('MemberPackage')->where($where)->select();
			foreach($order_package as $ke=>$ve){
				if($ve['service_num'] != $ve['use_num']){
					$true = 1;
				}
			}
			if($true == 1){
				$arr[]=$k;
			}
			$my_order[$k]['data'] = $order_package;
			$my_order[$k]['package_id'] = $order_package[0]['package_id'];
		}unset($k,$v);
		foreach($my_order as $k=>$v){
			if(!in_array($k,$arr)){
				unset($my_order[$k]);
			}
		}
		$this->assign('data',$my_order);
		$this->display();
	}
	/**
     * 我的累计签到页面
     */
	public function sign(){
		$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/Member/sign'));
			$this->assign('is_mobile',1);
			$this->redirect('Mobile/Login/perfect');
			// $this->assign('url',U('Mobile/Login/perfect'));
		}else{
			$sign_type = C('SIGN_TYPE');
			// 连续签到天数;今天是否签到过;显示签到天数
			$sum_day = 0;$f_qd = 0;$xs_day = 0;
			
			$map = array();$map['id']=MID;
			$map['sign_time']=array('gt',strtotime(date('Y-m-d',NOW_TIME)));
			$is_count=M('Member')->where($map)->count();
			
			$u_map = array();$u_map['id'] = MID;
			$m_info = M('Member')->where($u_map)->field('sign_day_num,sign_time,usepoints')->find();
			$sign_info = json_decode(C('SIGN_INFO'),true);
			$today = strtotime(date('Y-m-d',NOW_TIME));
			if($is_count){
				$f_qd = 1;
				$sum_day = $m_info['sign_day_num'];
			}else{
				$f_qd = 0;
				$ys_day_start = strtotime(date('Y-m-d',strtotime('-1 day')));
				$ys_day_end = $ys_day_start+86400-1;
				if($m_info['sign_time']>$ys_day_start && $m_info['sign_time']<$ys_day_end){
					$sum_day = $m_info['sign_day_num'];
				}else{
					$sum_day = 0;
					$m_info['sign_day_num'] = 0;
				}
			}
			
			$now = empty($sum_day)?0:intval($sum_day);
			$sign_info_day = getmiddlenum($now);
			
			$this->assign('sign_info_day',$sign_info_day);
			$this->assign($m_info);
			$this->assign('f_qd',$f_qd);
			$this->assign('is_mobile',0);
		}
		$this->assign('page_title','会员签到');
		$this->display();
    }
	public function sign_goods_list(){
		$return = array('status'=>0,'data'=>'');
		
		$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/Member/sign'));
			$return['status'] = 2;
			$return['url'] = U('Mobile/Login/perfect');
			$this->ajaxReturn($return);
		}else{
			$map = array();$map['is_internet'] = 1;
			$map['status'] = 1;$map['is_delete'] = 0;$map['is_delete'] = 0;
			$map['is_offline']=1;//线上
			$pagesize = 20;
			$page = I('page');
			$p = empty($page) ? 1 : $page;
			$order = 'is_best desc,sort desc,id desc';
			$data=page_list("Goods",$map,$order,true,$pagesize,'',$p);
			
			$goods_list = array();
			if($data['list']){
				$goods_list = $data['list'];
				if($goods_list){
					$goods_list=D('Wxsmall/Takeout')->format_data($goods_list,2);
					$page = intval($p)+1;
					$this->assign('goods_data',$goods_list);
					$return['status'] = 1;
					$return['page'] = $page;
					$return['sum_page'] = $data['totalPages'];
				}
			}
			
			$list_html=$this->fetch('goods_lists');
			$return['data'] = $list_html;
			$this->ajaxReturn($return);
		}
	}
	/**
     * 累计签到
     */
	public function sub_sign(){
		$return = array();$sum_day = 0;
		
		$map = array();$map['id']=MID;
		$map['sign_time']=array('gt',strtotime(date('Y-m-d',NOW_TIME)));
		$count=M('Member')->where($map)->count();
			
		$u_map = array();$u_map['id'] = MID;
		$m_info = M('Member')->where($u_map)->field('sign_day_num,sign_time,usepoints')->find();
		if($count){
			$return['status'] = 2;
			$return['is_day'] = $m_info['sign_day_num'];
			$return['all_points'] = $m_info['usepoints'];
			$this->ajaxReturn($return);
		}else{
			if($m_info['sign_day_num'] > 0){
				$ys_day_start = strtotime(date('Y-m-d',strtotime('-1 day')));
				$ys_day_end = $ys_day_start+86400-1;
				if($m_info['sign_time']>$ys_day_start && $m_info['sign_time']<$ys_day_end){
					$sum_day = $m_info['sign_day_num']+1;
				}else{
					$sum_day = 1;
				}
			}else{
				$sum_day = 1;
			}
			$return = save_sign($sum_day,MID);
			$this->ajaxReturn($return);
		}
	}
	/**
     * 签到规则
     */
	public function sign_rule(){
		$sign_rule = C('SIGN_RULE');
		$this->assign('content',$sign_rule);
		$this->assign('page_title','签到规则');
		$this->display();
	}
	/**获取签到记录列表
     * @param array $map
     * @param string $join
     * @param string $order
     * @param int $p
     * @param int $pagesize
     */
    public function get_sign_record_list($map=array(),$p=1,$pagesize=0){
        $pagesize=empty($pagesize)?C('WEB_GOODS_PAGE'):$pagesize;
        $p=empty($p)?1:$p;
		$order = 'id desc';
        $gift_list=page_list('WinGift',$map,$order,true,$pagesize,'',$p);
		if($gift_list['count'] > $pagesize*$p){
            $gift_list['show'] = 1;
        }else{
            $gift_list['show'] = 0;
        }
        return $gift_list;
    }
    /**
     * 我的签到记录
     */
    public function sign_record($is_ajax = 0){
        $postdata=I('param.');
        $map['user_id'] = MID;$map['win_type'] = 5;
        $sign_list = $this->get_sign_record_list($map,$postdata['page']);
        if ($is_ajax == 1) return $sign_list;
        $this->assign($sign_list);
        $this->assign($postdata);
        $this->assign('page_title','签到记录');
        $this->display();
    }
    public function sign_record_list(){
        $return['status'] = 0;
        $data = $this->sign_record(1);
        if (empty($data['list'])) $this->ajaxReturn($return);
        $return['status'] = 1;
        $this->assign($data);
        $list_html = $this->fetch('sign_record_list');
        $return['data'] = $list_html;
		$return['show'] = $data['show'];
        $this->ajaxReturn($return);
    }
	public function sign_record_cont(){
		$id=I('id');
        if(!$id){
            $this->error('参数错误！');exit;
        }
		$map = array();
		$map['id'] = $id;
		$map['win_type'] = 5;
        $gift_info=M('WinGift')->where($map)->field(true)->find();
		
        $this->assign('gift_info',$gift_info);
        $this->assign('page_title','签到礼品');
        $this->display();
	}
	// 微信卡券
    public function kaquan(){
        $member_info = session('member_info');
        $uid = $member_info['id'];
        $where['uid'] = $uid;
        $where['coupons_type'] = 2;
        $coupons_list = M('CouponsGet')->where($where)->field(true)->select();
        foreach ($coupons_list as $k => $v) {
            $list[$k] =  M('Coupons')->where('id='.$v['coupons_id'])->find();
            $list[$k]['status'] = $v['status'];
        }
        $this->assign('coupons_list',$coupons_list);
        $this->display();
    }
	//核销记录
	public function hx_jl(){
		$postdata = I('param.');
		$hx_list=D('Common/Member')->package_hxlist($postdata);
		// echo "<pre>";
		// print_r($hx_list);exit;
		$this->assign($hx_list);
		$this->assign('tplseo_title','核销记录'.'_'.C('WEB_SITE_TITLE'));
        $this->assign('page_title','核销记录');
		$this->display();
	}
    public function member_privilege(){
        $this->assign('tplseo_title','会员特权'.'_'.C('WEB_SITE_TITLE'));
        $this->assign('page_title','会员特权');
        $this->display();
    }
    public function privilege_explain(){
        $type = I('param.type');
        if($type == 1){
            $html = C('CARD_INTEGRAL_EXPLAIN');
            $this->assign('tplseo_title','积分说明'.'_'.C('WEB_SITE_TITLE'));
            $this->assign('page_title','积分说明'); 
        }
        if($type == 2){
            $html = C('CARD_EXPLAIN');
            $this->assign('tplseo_title','会员卡说明'.'_'.C('WEB_SITE_TITLE'));
            $this->assign('page_title','会员卡说明');
        }
        if($type == 3){
            $rank_id = M('Member')->where('id='.MID)->getField('rank_id');
            $map = array();
            $rankids = "0,".$rank_id;
            $map['rank_limit'] = array('IN',$rankids);
			$map['status'] = 1;
            $map['begin_time'] = array('LT',NOW_TIME);
	        $map['_string'] = 'end_time >'.NOW_TIME.' or end_time = 0';
			$list = M('ManypointsRule')->where($map)->field(true)->select();
            foreach($list as $k=>$v){
                if($v['consumption_type']!=3){
                    $give_num = $v['give_num'];
                    $list[$k]['give_num'] = $give_num;
                }
				if($v['give_type'] == 1){
					$list[$k]['give_type']='现金';
				}elseif($v['give_type'] == 2){
					$list[$k]['give_type']='倍积分';
				}
			}unset($k,$v);
            $this->assign('list',$list);
			// echo "<pre>";
			// print_r($list);exit;
            //$html = C('CARD_EXPLAIN');
            $this->assign('tplseo_title','会员等级特权'.'_'.C('WEB_SITE_TITLE'));
            $this->assign('page_title','会员等级特权');
        }
        $this->assign('html',$html);
        $this->assign('type',$type);
        $this->display();
    }
	public function receipt_draw(){
		$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/Member/receipt_draw'));
			$this->redirect('Mobile/Login/perfect');
			// $this->error('请先完善资料',U('Mobile/Login/perfect'));exit;
		}else{
			$num = 1;
			
			//活动信息
			$map=array();
			$map['status'] = 1;
			$map['class'] = 0;
			$map['start_time'] = array('lt',NOW_TIME);
			$map['end_time'] = array('gt',NOW_TIME);
			$info = M('ReceiptDraw')->where($map)->field(true)->find();
			if($info){
				//lxl 2018.8.13 start
				// $ExtensionKey = 'cj662';
				$ExtensionKey = cookie('ExtensionKey');
				if($ExtensionKey){
					$order_id = str_replace('cj','',$ExtensionKey);//订单id
				}
				//lxl 2018.8.13 end
				
				if(!$order_id){
					$this->error('抽奖二维码错误',U('Mobile/Index/index'));exit;
				}
				$o_map = array();$o_map['id'] = $order_id;
				$o_count = M('OrderInfo')->where($o_map)->count();
				if($o_count != 1){
					$this->error('该订单不存在',U('Mobile/Index/index'));exit;
				}
				$error = '';
				$where=array();
				$where['order_id'] = $order_id;
				$where['win_type'] = 2;
				$res = M('WinGift')->where($where)->getField('id');
				if($res){
					$error = '您的抽奖机会已用完啦';
				}
			
				//奖品 奖项
				$p_map['act_id'] = $info['id'];
				$list = M('Prize')->where($p_map)->field(true)->select();
				foreach($list as $key=>$value){
					$w_map['gift_id'] = $value['id'];
					$w_map['win_type'] = 2;
					$w_count = M('WinGift')->where($w_map)->count();
					if($w_count == $value['goods_num']){
						unset($list[$key]);
					}
				}
				$this->assign('list',$list);
				$this->assign($info);
				//中奖算法
				foreach($list as $k=>$v){
					$count = M('WinGift')->where('gift_id='.$v['id'])->count();
					if($count == $v['goods_num'])unset($list[$k]);
				}
				$prize = $this->getPrize($list);
				$this->assign('prize',$prize);
			}else{
				$error = '暂无活动';
				$this->error('当前没有抽奖活动',U('Mobile/Index/index'));exit;
			}
			if(!empty($error)) $num = 0;
			$this->assign('num',$num);
			$this->assign('order_id',$order_id);
			$this->assign('error',$error);
		}
		$this->display();
	}
	/* 
	 * 经典的概率算法， 
	 * $proArr是一个预先设置的数组， 
	 * 假设数组为：array(100,200,300，400)， 
	 * 开始是从1,1000 这个概率范围内筛选第一个数是否在他的出现概率范围之内，  
	 * 如果不在，则将概率空间，也就是k的值减去刚刚的那个数字的概率空间， 
	 * 在本例当中就是减去100，也就是说第二个数是在1，900这个范围内筛选的。 
	 * 这样 筛选到最终，总会有一个数满足要求。 
	 * 就相当于去一个箱子里摸东西， 
	 * 第一个不是，第二个不是，第三个还不是，那最后一个一定是。 
	 * 这个算法简单，而且效率非常 高， 
	 * 关键是这个算法已在我们以前的项目中有应用，尤其是大数据量的项目中效率非常棒。 
	 */ 
	public function get_rand($proArr) {   
		$result = '';    
		//概率数组的总概率精度   
		$proSum = array_sum($proArr);    
		//概率数组循环   
		foreach ($proArr as $key => $proCur) {   
			$randNum = mt_rand(1, $proSum);   
			if ($randNum <= $proCur) {   
				$result = $key;   
				break;   
			} else {   
				$proSum -= $proCur;   
			}         
		}   
		unset ($proArr);    
		return $result;   
	}
	public function getPrize($prize_arr){
		$num = 0;
		$arr = $new_arr = array();
		foreach ($prize_arr as $key => $val) {   
			$arr[$val['id']] = $val['prize_probability'];
			$new_arr[$val['id']]['id'] = $val['id'];
			$new_arr[$val['id']]['prize_name'] = $val['prize_name'];
			$num = $num + $val['prize_probability'];			
		}
		// echo "<pre>"; print_r($prize_arr); print_r($arr);
		// print_r($new_arr);
		$arr[0] = 100-$num;
		$rid = $this->get_rand($arr); //根据概率获取奖项id
		if($rid == 0){
			$res['yes'] = '谢谢参与'; //中奖项
		}else{
			// $res['yes'] = $prize_arr[$rid-1]['prize_name']; //中奖项
			$res['yes'] = $new_arr[$rid]['prize_name']; //中奖项
		}
		
		// unset($prize_arr[$rid-1]); //将中奖项从数组中剔除，剩下未中奖项
		unset($new_arr[$rid]); //将中奖项从数组中剔除，剩下未中奖项
		shuffle($prize_arr); //打乱数组顺序
		$res['id'] = $rid;
		$res['no'] = $pr; 
// print_r($res);exit;
		return $res;
	}
	// 记录中奖数据到数据库
	public function set_sn_code() {
		$res = array();$res['status'] = 0;
		$param['order_id'] = I('order_id');
		$param['gift_id'] = I('prize_id');
		$param['uid'] = MID;
		
		if($param['gift_id'] == 0){
			$res['info'] = '谢谢参与，恭喜下次中奖！';
		}else{
			$where = array();$where['order_id'] = $param['order_id'];$where['win_type'] = 2;
			$ret = M('WinGift')->where($where)->count();
			if($ret){
				$res['status'] = 2;
				$res['info'] = '您已经抽过礼品了，不能再次抽奖，请在抽奖记录中查看！';
			}else{
				$res=D('Common/Member')->set_sn_code($param);
			}
		}
		$this->ajaxReturn($res);
	}
	
	// 微信会员卡激活
	public function wx_phone(){
		$member_info = session('member_info');
        $where=array();
		$where['id'] = $member_info['id'];
		$member = M('Member')->where($where)->field(true)->find();
		if($member['parent_id']){
			$member['ref_mobile'] = idtoname($member['parent_id'],'Member','mobile');
            if($member['ref_mobile']==$member['mobile'])$member['ref_mobile']='';
		}else{
			$member['ref_mobile'] = '';
		}
        if(empty($member['username']))$member['username']=$member['mobile'];
		$this->assign($member);


		$where = $map = $data = $con_where = $con_data = $c_data =  array();
        //基本属性
        $con_where['name'] = 'MEMBERATTRIBUTE';
        $con_have = M("Config")->where($con_where)->field("id,name,value")->find();
        if($con_have){
            $con_data = unserialize($con_have['value']);
            if(empty($con_data) || $con_data['real_name']['is_member']){
                $c_data[1] = $con_data['real_name'];
                $c_data[1]['name'] = "真实姓名";
                $c_data[1]['field'] = "real_name";
                $c_data[1]['type'] = "text";
            }
            if(empty($con_data) || $con_data['birthday']['is_member']){
                $c_data[2] = $con_data['birthday'];
                $c_data[2]['name'] = "生日";
                $c_data[2]['field'] = "birthday";
                $c_data[2]['type'] = "date";
            }
            if(empty($con_data) || $con_data['sex']['is_member']){
                $c_data[3] = $con_data['sex'];
                $c_data[3]['name'] = "性别";
                $c_data[3]['field'] = "sex";
                $c_data[3]['type'] = "radio";
            }
            if(empty($con_data) || $con_data['idcard']['is_member']){
                $c_data[4] = $con_data['idcard'];
                $c_data[4]['name'] = "身份证号";
                $c_data[4]['field'] = "idcard";
                $c_data[4]['type'] = "text";
            }
            if(empty($con_data) || $con_data['address']['is_member']){
                $c_data[5] = $con_data['address'];
                $c_data[5]['name'] = "地区";
                $c_data[5]['field'] = "address";
                $c_data[5]['type'] = "radio";
            }
            $this->assign("jiben_data",$c_data);
        }



        $where['name'] = 'ATTRIBUTE';
        $have = M("Config")->where($where)->field("id,name,value")->find();
        $attr_list = json_decode($have['value'],true);
        $map['uid'] = MID;
        foreach ($attr_list as $key => $value) {
            if($value['is_member']){
                $data[$key] = $value;
                $map['aid'] = $value['id'];
                $data[$key]['value'] = M("MemberAttribute")->where($map)->getField("content");
                if($value['type'] == 'date' && $data[$key]['value']){
                    $data[$key]['value'] = date("Y-m-d",$data[$key]['value']);
                }
                if(($value['type'] == 'radio') && $value['content']){
                    $data[$key]['data'] = explode(",",$value['content']);
                }
                if($value['type'] == 'checkbox' && $value['content']){  //多选
                    $con_data = array_filter(explode(",",$value['content']));   //多有的多选项
                    $vvv = array_filter(explode(",",trim($data[$key]['value'],',')));
                    foreach ($con_data as $cc => $vv) {
                        $data[$key]['data'][$cc]['name'] = $vv;
                        $ss = 0;
                        foreach ($vvv as $zz => $yy) {
                            if(in_array($yy,$con_data) && $yy == $vv){
                                $ss = 1;
                            }
                        }$data[$key]['data'][$cc]['is_have'] = $ss;
                    }
                    $data[$key]['value'] = trim($data[$key]['value'],',');
                }
            }
        }unset($key,$value);
        $this->assign('attr_list', $data);
        
		$this->display();
	}
	public function activation(){
		$post = I('post.');
		if($post['mobile'] && $post['username']){
		    $check=C('MEMBERATTRIBUTE');$con_data = unserialize($con_have['value']);
		    if((empty($con_data) || $con_data['address']['is_member']) && (empty($post['province']) || empty($post['city_id']))){
		      $return['status'] = 0;
			  $return['msg'] = '会员地址信息填写不完整';$this->ajaxReturn($return);
		    }
			$Weixin = new \Common\Vendor\WeixinCard();
	        $membercard = $Weixin->membercard($post,'初始积分同步');
			$return['msg'] = $membercard;
	        if($membercard['status'] == 1){
		    	$return['status'] = 1;
				$return['msg'] = $membercard['msg'];
		    }else{
		    	$return['status'] = 0;
				$return['msg'] = $membercard['msg'];
		    }
		}else{
			$return['status'] = 0;
			$return['msg'] = '会员信息填写不完整';
		}	
	    $this->ajaxReturn($return);
	}
}