<?php
/**
 * 会员统计
 * @Copyright (C) 2016 汉潮 All rights reserved.
 * @License http://www.hanchao9999.com
 * @Author xiaogg <xiaogg@sina.cn>
 */
namespace Admin\Controller;
class MemberStatisticsController extends BaseController{
    public function index($is_return=false){//会员FRM
        $shop_list=D('Shops')->shop_list();
        $this->assign('shop_list',$shop_list);
        $list=$map=$map_oi=array();
        $postdata=I('param.');
        if($postdata['shopid'])$map['a.user_shop']= $postdata['shopid'];
        $now_time=strtotime(date('Y-m-d',NOW_TIME));
        if($postdata['reg_from'] || $postdata['reg_to']){
	  $date_from = strtotime($postdata['reg_from']);
	  if($date_from){$map['oi.addtime'][] = array('egt',$date_from);$map_oi['addtime'][] = array('egt',$date_from);}
	  $date_to = strtotime($postdata['reg_to']);
	  if($date_to){$date_to = $date_to+86399;$map['oi.addtime'][] = array('lt',$date_to);$map_oi['addtime'][] = array('lt',$date_to);}
	  $postdata['dates']=0;
        }else{
	  if(in_array($postdata['dates'],array(7,14,30,60))){
	      $between=quick_time($postdata['dates']);
	      $map['oi.addtime']=$map_oi['addtime']=array('between',array($between[0],$between[1]));
	  }else{
	      $postdata['dates']=99;
	  }
        }
        $having='';
        if($postdata['num_from'] || $postdata['num_to']){
	  if(is_numeric($postdata['num_from']) && $postdata['num_from']>0){
	      $having.= 'count(oi.id) >= '.$postdata['num_from'].' and ';
	  }else{
	      $this->error('消费次数必须为正数');exit;
	  }
	  if(is_numeric($postdata['num_to']) && $postdata['num_to']>0){
	      $having.= 'count(oi.id) <= '.$postdata['num_to'];
	  }else{
	      $this->error('消费次数必须为正数');exit;
	  }
	  if($postdata['num_from']>$postdata['num_to']){
	      $this->error('消费次数输入范围异常');exit;
	  }
	  $postdata['nums']=0;
        }else{
	  switch($postdata['nums']){
	      case 3:
		$having.='2 < count(oi.id) and count(oi.id) <6';
		break;
	      case 6:
		$having.='5 < count(oi.id) and count(oi.id) <11';
		break;
	      case 11:
		$having.='11 < count(oi.id) and count(oi.id) <21';
		break;
	      default:
		$postdata['nums']=99;
		break;
	  }
        }
        if($postdata['price_from'] || $postdata['price_to']){
	  if(is_numeric($postdata['price_from']) && $postdata['price_from']>0){
	      if(strlen($having) > 0){
		$having.= ' and ';
	      }
	      $having.= 'sum(oi.order_amount)/count(oi.id) >= '.$postdata['price_from'].' and ';
	  }else{
	      $this->error('订单均价必须为正数');exit;
	  }
	  if($postdata['price_to']){
	      $having.= 'sum(oi.order_amount)/count(oi.id) <= '.$postdata['price_to'];
	  }else{
	      $this->error('订单均价必须为正数');exit;
	  }
	  if($postdata['price_from']>$postdata['price_to']){
	      $this->error('订单均价输入范围异常');exit;
	  }
	  $postdata['price']=0;
        }else{
	  switch($postdata['price']){
	      case 3:
		if(strlen($having) > 0){
		    $having.= ' and ';
		}
		$having.='3 <= (sum(oi.order_amount)/count(oi.id)) and (sum(oi.order_amount)/count(oi.id)) <=15';
	      break;
	      case 16:
		if(strlen($having) > 0){
		    $having.= ' and ';
		}
		$having.='16 <= (sum(oi.order_amount)/count(oi.id)) and (sum(oi.order_amount)/count(oi.id)) <=25';
		break;
	      case 26:
		if(strlen($having) > 0){
		    $having.= ' and ';
		}
		$having.='26 <= (sum(oi.order_amount)/count(oi.id)) and (sum(oi.order_amount)/count(oi.id)) <=45';
		break;
	      default:
		$postdata['price']=99;
		break;
	  }
        }
        $map['oi.type']=$map_oi['type']=array('in','1,6,11,13,14');
        $map['oi.pay_status']=$map_oi['pay_status']=3;
        $map['oi.is_delete']=$map_oi['is_delete']=0;
        $map['oi.status']=$map_oi['status']=array('in','1,2,3,6,8');
        $field='a.id,a.card_sn,a.mobile,a.rank_id,a.usepoints,a.money,sum(oi.order_amount) as order_amount,sum(oi.order_amount)/count(oi.id) as avg_money,count(oi.id) as num';
        $list_e=M('Member')->alias('a')->where($map)->join('__ORDER_INFO__ oi ON a.id=oi.uid')->group('oi.uid')->field($field)->having($having)->select();
        $join='JOIN __ORDER_INFO__ oi ON a.id=oi.uid';
        $map['group']='oi.uid';
        $list=$this->page_lists('Member',$map,'',$field,20,$join,1,$having);
        foreach($list['list'] as $k=>$v){
	  $map_oi['uid']=$v['id'];
	  $addtime=M('OrderInfo')->where($map_oi)->order('addtime desc')->field('addtime')->find();
	  $list['list'][$k]['addtime']=$addtime['addtime'];
	  $list['list'][$k]['day']=intval((NOW_TIME-$addtime['addtime'])/24/3600);
        }unset($k,$v);
        if($is_return){
	  $list_new=array();
	  if($list_e){
	      $i=0;
	      foreach($list_e as $k=>$v){
		$i++;
		$list_new[$i]['n']=$i;
		$list_new[$i]['card_sn']=$v['card_sn'];
		$list_new[$i]['name']=show_user_name($v['id']);
		$list_new[$i]['mobile']=$v['mobile'];
		$list_new[$i]['rank_name']=idtoname($v['rank_id'],'MemberRank');
		$list_new[$i]['usepoints']=$v['usepoints'];
		$list_new[$i]['money']=$v['money'];
		$list_new[$i]['order_amount']=$v['order_amount'];
		$list_new[$i]['avg_money']=format_decimal($v['avg_money']);
		$list_new[$i]['num']=$v['num'];
		$map_oi['uid']=$v['id'];
		$addtime=M('OrderInfo')->where($map_oi)->order('addtime desc')->field('addtime')->find();
		$list_new[$i]['addtime']=time_format($addtime['addtime']);
		$list_new[$i]['day']=intval((NOW_TIME-$addtime['addtime'])/24/3600);
	      }
	  }

	  $return['list']=$list_new;
	  return $return;
        }else{
	  $this->assign($postdata);
	  $this->assign($list);
	  $this->display();
        }
    }

    public function export(){
        $rest=$this->index(true);
        $data=array();
        $data=$rest['list'];
        $title=array('序号','会员卡号','会员姓名','会员等级','手机号','积分','余额','订单总价','订单均价','消费次数','最后消费日期','距今天日期(天)');
        export_csv('会员FRM分析.csv',$title,$data);
        exit;
    }
    private function page_lists($module,$map=array(),$order='',$field=true,$pagesize=0,$join='',$REQUEST=1,$having=''){
        if(empty($module))return false;if(empty($pagesize))$pagesize=C('LIST_ROWS') > 0 ? C('LIST_ROWS') : 10;
        if($REQUEST>=1)$REQUEST = (array)I('request.');
        if(!isset($REQUEST['p'])&&isset($REQUEST['page']))$REQUEST['p']=$REQUEST['page'];
        if(intval($REQUEST['p'])<=0)$REQUEST['p']=1;
        $group = '';
        if(isset($map['group'])&&!empty($map['group'])){$group = $map['group'];unset($map['group']);}
        $model = M($module);
        $preve = (intval($REQUEST['p'])-1)*$pagesize;
        $limit = "$preve,$pagesize";
        if ( isset($REQUEST['_order']) && isset($REQUEST['_field']) && in_array(strtolower($REQUEST['_order']),array('desc','asc')) ) {
	  $order = '`'.$REQUEST['_field'].'` '.$REQUEST['_order'];
        }
        $return = array();
        if($group){
	  $distinct='distinct '.$group;
	  $return['count'] = $model->alias('a')->where($map)->join($join)->having($having)->count($distinct);
	  if(is_array($return['count'])){
	      $count_key=array_keys($return['count']);$return['count'] =$count_key[0];
	  }
        }else{
	  $return['count'] = $model->alias('a')->where($map)->join($join)->having($having)->count();
        }
        $Page = new \Common\Vendor\Page($return['count'],$pagesize,$REQUEST);
        $return['page'] = $Page->show();
        $return['firstRow'] = $Page->firstRow;
        $return['listRows'] = $Page->listRows;
        $return['totalPages'] = $Page->totalPages;
        $return['list'] = $model->alias('a')->where($map)->order('create_time')->join($join)->field($field)->group($group)->having($having)->order($order)->limit($limit)->select();
        return $return;
    }
//沉睡会员
    public function dead_sleep($is_return=false){
        $sou_type=strtoarray(array('1'=>'日','2'=>'月','3'=>'年'));
        $this->assign('sou_type',$sou_type);
        $map=array();
        $postdata=I('param.');
        if($postdata['day'] && $postdata['sou_value']){
	  if(intval($postdata['day'])<=0){
	      $this->error('请输入大于0的整数');exit;
	  }
	  $start_time=strtotime(date('Y-m-d',NOW_TIME));
	  if($postdata['sou_value']==1){
	      $date_from=$start_time-$postdata['day']*86400;
	      $date_to =$start_time+86399;
	      $map['oi.addtime']=array('between',array($date_from,$date_to));
	  }
	  if($postdata['sou_value']==2){
	      $date_from=$start_time-$postdata['day']*86400*30;
	      $date_to =$start_time+86399;
	      $map['oi.addtime']=array('between',array($date_from,$date_to));
	  }
	  if($postdata['sou_value']==3){
	      $date_from=$start_time-$postdata['day']*86400*365;
	      $date_to =$start_time+86399;
	      $map['oi.addtime']=array('between',array($date_from,$date_to));
	  }
        }
        $map['oi.type']=$map_oi['type']=array('in','1,6,11,13,14');
        $map['oi.pay_status']=$map_oi['pay_status']=3;
        $map['oi.is_delete']=$map_oi['is_delete']=0;
        $map['oi.status']=$map_oi['status']=array('in','1,2,3,6,8');
        $list=M('Member')->alias('a')->where($map)->join('__ORDER_INFO__ oi ON a.id=oi.uid')->group('oi.uid')->field('a.id')->select();
        $ids=array_map('array_shift', $list);
        $map=array();
        if($ids){
	  $map['id']=array('not in',$ids);
        }else{
	  $map['id']=0;
        }

        $map['status']=1;
        $map['is_tmp']=0;
        $field='id,card_sn,mobile,rank_id,usepoints,money';
        $uids=page_list('Member',$map,'','',20);
        foreach($uids['list'] as $k=>$v){
	  $map_oi['uid']=$v['id'];
	  $orderinfo=M('OrderInfo')->where($map_oi)->order('addtime desc')->field('addtime,order_amount,shop_id,in_online')->find();
	  if($orderinfo){
	      $uids['list'][$k]['addtime']=time_format($orderinfo['addtime']);
	      $uids['list'][$k]['order_amount']=$orderinfo['order_amount'];
	      $uids['list'][$k]['shopname']=idtoname($orderinfo['shop_id'],'Shops');
	      $uids['list'][$k]['in_online']=$orderinfo['in_online']==1?'线下':'线上';
	  }else{
	      $uids['list'][$k]['addtime']='没有购买记录';
	      $uids['list'][$k]['in_online']='';
	  }
        }unset($k,$v);
        $list_e=M('Member')->where($map)->field($field)->select();
        if($is_return){
	  $return=$list_new=array();
	  if($list_e){
	      $i=0;
	      foreach($list_e as $k=>$v){
		$i++;
		$list_new[$i]['n']=$i;
		$list_new[$i]['card_sn']=$v['card_sn'];
		$list_new[$i]['name']=show_user_name($v['id']);
		$list_new[$i]['mobile']=$v['mobile'];
		$list_new[$i]['rank_name']=idtoname($v['rank_id'],'MemberRank');
		$list_new[$i]['usepoints']=$v['usepoints'];
		$list_new[$i]['money']=$v['money'];
		$map_oi['uid']=$v['id'];
		$orderinfo=M('OrderInfo')->where($map_oi)->order('addtime desc')->field('addtime,order_amount,shop_id,in_online')->find();
		if($orderinfo){
		    $list_new[$i]['addtime']=time_format($orderinfo['addtime']);
		    $list_new[$i]['order_amount']=$orderinfo['order_amount'];
		    $list_new[$i]['shopname']=idtoname($orderinfo['shop_id'],'Shops');
		    $list_new[$i]['in_online']=$orderinfo['in_online']==1?'线下':'线上';
		}else{
		    $list_new[$i]['addtime']='没有购买记录';
		    $list_new[$i]['order_amount']='';
		    $list_new[$i]['shopname']='';
		    $list_new[$i]['in_online']='';
		}
	      }
	  }
	  $return['list']=$list_new;
	  return $return;
        }else{

	  $this->assign($postdata);
	  $this->assign($uids);
	  $this->display();
        }
    }
    public function sleep_explode(){
        $rest=$this->dead_sleep(true);
        $data=array();
        $data=$rest['list'];
        $title=array('序号','会员卡号','会员姓名','手机号','会员等级','积分','余额','上次消费时间','消费金额','消费仓库','消费类型');
        export_csv('沉睡会员.csv',$title,$data);
        exit;
    }
    public function increase($is_return=false){
        //$sou_type=strtoarray(array('1'=>'按仓库','2'=>'按小时','3'=>'按日','4'=>'按月'));
        $sou_type=strtoarray(array('2'=>'按小时','3'=>'按日','4'=>'按月'));
        $this->assign('sou_type',$sou_type);
        $shop_list=D('Shops')->shop_list();
        $this->assign('shop_list',$shop_list);
        $postdata=I('param.');
        $now_time=strtotime(date('Y-m-d',NOW_TIME));
        $map=$map_oi=array();
        if($postdata['reg_from'] || $postdata['reg_to']){
	  $date_from = strtotime($postdata['reg_from']);
	  if($date_from){$map['reg_time'][]=array('egt',$date_from);$map_oi['addtime'][] = array('egt',$date_from);}
	  $date_to = strtotime($postdata['reg_to']);
	  if($date_to){$date_to = $date_to+86399;$map['reg_time'][]=array('egt',$date_from);$map_oi['addtime'][] = array('lt',$date_to);}
	  $postdata['dates']=0;
        }else{
	  if(in_array($postdata['dates'],array(1,2,7,30))){
	      $between=quick_time($postdata['dates']);
	      $map['reg_time']=$map_oi['addtime']=array('between',array($between[0],$between[1]));
	  }else{
	      $postdata['dates']=99;
	  }
        }
        $map['is_tmp']=0;
        $map['status']=1;
        $map_oi['type']=array('in','1,6,11,13,14');
        $map_oi['pay_status']=3;
        $map_oi['is_delete']=0;
        $map_oi['status']=array('in','1,2,3,6,8');
        $field='count(id) as num,reg_time';
        $all=$list=array();
        $all['m_numb']=$all['o_numb']=$all['precent']=$m_num=$o_num=0;
        if(empty($postdata['sou_value'])) $postdata['sou_value']=2;
        switch($postdata['sou_value']){
	  case 2://按小时
	      for($i=0;$i<24;$i++){
			$day_arr[$i] = $i; //处理时间数组
	      }
	      $member=M('Member')->where($map)->field('id,reg_time')->select();
	      if($member){
		$uids=array();
		foreach($member as $k=>$v){
		    $new_m[date('G',$v['reg_time'])][]= $v['id'];
		    $uids[]=$v['id'];
		}unset($k,$v);
		$list_t=M('Member')->where($map)->group("DATE_FORMAT(FROM_UNIXTIME(reg_time),'%k')")->field($field)->select();
		$new_list=$o_list=array();
		foreach($list_t as $k=>$v){
		    $new_list[date('G',$v['reg_time'])]=$v['num'];
		}unset($k,$v);
		$list_time=array();
		foreach ($new_m as $k => $v) {
		    $list[$k]['reg_time']=$k.'点';
		    $list[$k]['m_num']=$new_list[$k];
		    $map_oi['uid']=array('in',$v);
		    $num=M('OrderInfo')->where($map_oi)->group("DATE_FORMAT(FROM_UNIXTIME(addtime),'%k')")->having("DATE_FORMAT(FROM_UNIXTIME(addtime),'%k') = $k")->field('uid,addtime')->select();
		    if(count($num)>0){
		        $list[$k]['o_num']=count($num);//获取新增会员下单的会员数
		    }else{
		        $list[$k]['o_num']=0;
		    }
		    $list[$k]['percent']=format_decimal($list[$k]['o_num']*100/$new_list[$k]).'%';
		    $m_num+=$new_list[$k];
		    $o_num+=$list[$k]['o_num'];
		    $list_time[]=$k;
		}unset($k,$v);
		$new_day=array_diff($day_arr,$list_time);
		foreach($new_day as $vt){
		    $list[$vt]['reg_time']=$vt.'点';
		    $list[$vt]['m_num']=0;
		    $list[$vt]['o_num']=0;
		    $list[$vt]['percent']='0.00%';
		}
		ksort($list);
		$all['m_numb']=$m_num;
		$all['o_numb']=$o_num;
		$all['percent']=format_decimal($all['o_numb']*100/$all['m_numb']).'%';
	      }
	      break;
	  case 3://按日
	      for($i=1;$i<32;$i++){
		$day_arr[$i] = $i; //处理时间数组
	      }

	      $member=M('Member')->where($map)->field('id,reg_time')->select();
	      if($member){
		$uids=array();
		foreach($member as $k=>$v){
		    $new_m[date('j',$v['reg_time'])][]= $v['id'];
		    $uids[]=$v['id'];
		}unset($k,$v);
		$list_t=M('Member')->where($map)->group("DATE_FORMAT(FROM_UNIXTIME(reg_time),'%e')")->field($field)->select();
		$new_list=$o_list=array();
		foreach($list_t as $k=>$v){
		    $new_list[date('j',$v['reg_time'])]=$v['num'];
		}unset($k,$v);
		$list_time=array();
		foreach ($new_m as $k => $v) {
		    $list[$k]['reg_time']=$k.'日';
		    $list[$k]['m_num']=$new_list[$k];
		    $map_oi['uid']=array('in',$v);
		    $num=M('OrderInfo')->where($map_oi)->group("DATE_FORMAT(FROM_UNIXTIME(addtime),'%e')")->having("DATE_FORMAT(FROM_UNIXTIME(addtime),'%e') = $k")->field('uid,addtime')->select();

		    if(count($num)>0){
		        $list[$k]['o_num']=count($num);//获取新增会员下单的会员数
		    }else{
		        $list[$k]['o_num']=0;
		    }
		    $list[$k]['percent']=format_decimal($list[$k]['o_num']*100/$new_list[$k]).'%';
		    $m_num+=$new_list[$k];
		    $o_num+=$list[$k]['o_num'];
		    $list_time[]=$k;
		}unset($k,$v);
		$new_day=array_diff($day_arr,$list_time);
		foreach($new_day as $vt){
		    $list[$vt]['reg_time']=$vt.'日';
		    $list[$vt]['m_num']=0;
		    $list[$vt]['o_num']=0;
		    $list[$vt]['percent']='0.00%';
		}
		ksort($list);
		$all['m_numb']=$m_num;
		$all['o_numb']=$o_num;
		$all['percent']=format_decimal($all['o_numb']*100/$all['m_numb']).'%';
	      }
	      break;
	  case 4://月
	      for($i=1;$i<13;$i++){
		$day_arr[$i] = $i; //处理时间数组
	      }
	      $member=M('Member')->where($map)->field('id,reg_time')->select();
	      if($member){
		$uids=array();
		foreach($member as $k=>$v){
		    $new_m[date('n',$v['reg_time'])][]= $v['id'];
		    $uids[]=$v['id'];
		}unset($k,$v);
		$list_t=M('Member')->where($map)->group("DATE_FORMAT(FROM_UNIXTIME(reg_time),'%c')")->field($field)->select();
		$new_list=$o_list=array();
		foreach($list_t as $k=>$v){
		    $new_list[date('n',$v['reg_time'])]=$v['num'];
		}unset($k,$v);
		$list_time=array();
		foreach ($new_m as $k => $v) {
		    $list[$k]['reg_time']=$k.'月';
		    $list[$k]['m_num']=$new_list[$k];
		    $map_oi['uid']=array('in',$v);
		    $num=M('OrderInfo')->where($map_oi)->group("DATE_FORMAT(FROM_UNIXTIME(addtime),'%c')")->having("DATE_FORMAT(FROM_UNIXTIME(addtime),'%c') = $k")->field('uid,addtime')->select();

		    if(count($num)>0){
		        $list[$k]['o_num']=count($num);//获取新增会员下单的会员数
		    }else{
		        $list[$k]['o_num']=0;
		    }
		    $list[$k]['percent']=format_decimal($list[$k]['o_num']*100/$new_list[$k]).'%';
		    $m_num+=$new_list[$k];
		    $o_num+=$list[$k]['o_num'];
		    $list_time[]=$k;
		}unset($k,$v);
		$new_day=array_diff($day_arr,$list_time);
		foreach($new_day as $vt){
		    $list[$vt]['reg_time']=$vt.'月';
		    $list[$vt]['m_num']=0;
		    $list[$vt]['o_num']=0;
		    $list[$vt]['percent']='0.00%';
		}
		ksort($list);
		$all['m_numb']=$m_num;
		$all['o_numb']=$o_num;
		$all['percent']=format_decimal($all['o_numb']*100/$all['m_numb']).'%';
	      }
	      break;
	  default://按店
	      $postdata['sou_value']=1;
	      $shoplist=$shop_list;
//	      if($postdata['shopid']){
//		$map_s=array();
//		$map_s['id']=$postdata['shopid'];
//		$shoplist=M('Shops')->where($map_s)->getField('id,name');
//	      }
	      $shop_ids=array_keys($shoplist);
	      if($shop_ids){
		$map['user_shop']=array('in',$shop_ids);
		$new_m=$new_list=array();
		$member=M('Member')->where($map)->field('id,user_shop')->select();
		if($member){
		    $uids=array();
		    foreach($member as $k=>$v){
		        $new_m[$v['user_shop']][]= $v['id'];
		        $uids[]=$v['id'];
		    }unset($k,$v);
		    $list_s=M('Member')->where($map)->group("user_shop")->field('count(id) as num,id,user_shop')->select();
		    foreach($list_s as $k=>$v){
		        $new_list[$v['user_shop']]=$v['num'];
		    }unset($k,$v);
		    foreach ($new_m as $k => $v) {
		        $list[$k]['shop_name']=$shop_list[$k];
		        $list[$k]['m_num']=$new_list[$k];
		        $map_oi['uid']=array('in',$v);
		        $map_oi['shop_id']=$k;
		        $num=M('OrderInfo')->where($map_oi)->group('uid')->field('count(id) as onum')->select();
		        if(count($num)>0){
			  $list[$k]['o_num']=count($num);//获取新增会员下单的会员数
		        }else{
			  $list[$k]['o_num']=0;
		        }
		        $list[$k]['percent']=format_decimal($list[$k]['o_num']*100/$new_list[$k]).'%';
		        $m_num+=$new_list[$k];
		        $o_num+=$list[$k]['o_num'];
		        $list_time[]=$k;
		    }unset($k,$v);
		}
		$new_day=array_diff($shop_ids,$list_time);
		foreach($new_day as $vt){
		    $list[$vt]['shop_name']=$shop_list[$vt];
		    $list[$vt]['m_num']=0;
		    $list[$vt]['o_num']=0;
		    $list[$vt]['percent']='0.00%';
		}
		ksort($list);
		$keys=array_keys($list);
		$xz_key=array_pop($keys);
		$xz_key=$xz_key+1;
		//网上新增
		unset($map['user_shop']);
		$map['user_shop']=0;
		$xz_member=M('Member')->where($map)->getField('id',true);
		$list[$xz_key]['shop_name']='网上';
		$list[$xz_key]['m_num']=$list[$xz_key]['o_num']=0;
		$list[$xz_key]['percent']='0.00%';
		unset($map_oi['shop_id']);unset($map_oi['uid']);
		if($xz_member){
		    $map_oi['uid']=array('in',$xz_member);
		    $xz_order=count(M('OrderInfo')->where($map_oi)->group('uid')->field('count(id) as onum')->select());
		    $list[$xz_key]['m_num']=count($xz_member);
		    $list[$xz_key]['o_num']=$xz_order;
		    $list[$xz_key]['percent']=format_decimal($xz_order*100/count($xz_member)).'%';
		}
		$all['m_numb']=$m_num+$list[$xz_key]['m_num'];
		$all['o_numb']=$o_num+$list[$xz_key]['o_num'];
		$all['percent']=format_decimal($all['o_numb']*100/$all['m_numb']).'%';
	      }
	      break;
        }
        if($is_return){
	  $return['list']=$list;
	  $return['info']=$all;
	  if($postdata['sou_value']==1){
	      $return['title'] = array('仓库','新增会员数','下单人数','会员转化率');
	  }else{
	      $return['title'] = array('时间','新增会员数','下单人数','会员转化率');
	  }
	  return $return;
        }else{
	  $this->assign($postdata);
	  $this->assign($all);
	  $this->assign('list',$list);
	  $this->display();
        }
    }
    public function increase_explode(){
        $rest=$this->increase(true);
        $data=array();
        $data=$rest['list'];
        $data[]=array('总计',$rest['info']['m_numb'],$rest['info']['o_numb'],$rest['info']['percent']);
        export_csv('会员增长率.csv',$rest['title'],$data);
        exit;
    }
}