<?php
// +----------------------------------------------------------------------
// | yershop网店管理系统
// +----------------------------------------------------------------------
// | Copyright (c) 2017 http://www.yershop.com All rights reserved.
// +----------------------------------------------------------------------
// | 版权申明：yershop网店管理系统不是一个自由软件，是贝云网络官方推出的商业源码，严禁在未经许可的情况下
// | 拷贝、复制、传播、使用yershop网店管理系统的任意代码，如有违反，请立即删除，否则您将面临承担相应
// | 法律责任的风险。如果需要取得官方授权，请联系官方http://www.yershop.com
// +----------------------------------------------------------------------
namespace app\index\controller;
use think\Controller;
use think\Db;
/*购物车*/
class Team extends Home{
	
	public function index($type=0) {
		if(!session_uid()) {
		    $this->redirect( "User/login");
		} 
		$uid=session_uid();	
		if(is_null($type)){
			
		     $ids=getChilds($uid);	
		     if($ids){
		       $map[]=['id','in',$ids];
			   $map[]=['status','=',1];
		    }  
		   
	}
       if(!is_null($type)&&$type==0){
       	
       		$map[]=['pid','=',$uid];
	      	$map[]=['status','=',1];
	
       }
	   if($type==1){
	   		$map[]=['pid','=',$uid];
	      	$map[]=['status','=',1];
	      	$list=db('user')->where($map)->select();
	      	unset($map);
	      	$arr=array();
	      	foreach ($list as $k=>$v){
	      		
	      	   array_push($arr,$v['id']);	
	      	}
			if($arr){
			    $map[]=['pid','in',$arr];
	      	    $map[]=['status','=',1];	
			}
	      	
	
	   	//dump($map);
	   }
	   if($type==2){
	   	
	   	
	   		$map[]=['pid','=',$uid];
	      	$map[]=['status','=',1];
	      	$list=db('user')->where($map)->select();
	      	unset($map);
	      	$arr=array();
	      	foreach ($list as $k=>$v){
	      		
	      	   array_push($arr,$v['id']);	
	      	}
	         	unset($list);
				if($arr){
	      		$map[]=['pid','in',$arr];
	      	    $map[]=['status','=',1];
	      	     	$list=db('user')->where($map)->select();
	      	    	unset($map);
	      	$types=array();
	      	foreach ($list as $k=>$v){
	      		
	      	   array_push($types,$v['id']);	
	      	}
			if($types){
				$map[]=['pid','in',$types];
	      	    $map[]=['status','=',1];
			}
				}
	   }
        if(isset($map)){
    
	        $res=getLists('user',$map,"10",'status desc,id desc');       
        }else{
			$res['list']='';
			$res['page']='';
		}	 	
        $this->assign('res', $res);
		return $this->fetch();

	}
      // 生成支付订单号
   public function ordersn(){
       $yCode = array('A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'input', 'J');
		$orderSn ='2018'. $yCode[intval(date('Y')) - 2011] . strtoupper(dechex(date('m'))) . date('d') . substr(time(), -5) . substr(microtime(), 2, 5) . sprintf('%04d%02d', rand(1000, 9999),rand(0,99));
		return $orderSn;
		
    }

	/**
     * 解析状态
     */
	 public function parse2($status){   
	       switch ($status)
				{
				case 0:
				  return "未确认";
				  break;
				case 1:
				  return "已转账";
				  break;
				case 2:
				  return "已拒绝";
				  break;
				default:
				  return  "未确认";
				}
	}

}
