<?php
namespace app\admin\logic;
use think\Db;
use app\common\server\UrlServer;
use think\helper\Time;
use app\common\server\ConfigServer;

class SuborderLogic{
    
     /**
     * Notes: 列表查询条件
     * @param $get
     * @return array
     */
    public static function whereDate($get)
    {
        $where = [];
        $where[] = ['o.admin','=',session('admin_info.id')];
        if(isset($get['type'])&& $get['type']!=''){
           $where[] = ['o.status','=',$get['type']];
        }
        if(isset($get['satff']) && $get['satff']!=''){
            $where[] = ['o.staff_id','=',$get['satff']];
        }

        if(isset($get['order_sn']) && $get['order_sn']!=''){
            $where[] = ['o.order_sn','=',$get['order_sn']];
        }
        if(isset($get['id']) && $get['id']!=''){
            $where[] = ['o.id','=',$get['id']];
        }
        if(isset($get['staf_stuts']) && $get['staf_stuts']!=''){
            if($get['staf_stuts']==0){
            $where[] = ['o.staff_id','=',0]; 
            }
        }
        if(isset($get['phone']) && $get['phone']!=''){
            $where[] = ['o.phone','=',$get['phone']];
         }
       if(isset($get['admin']) && $get['admin']!=''){
            $where[] = ['o.admin','=',$get['admin']];
         }  
        if(isset($get['name']) && $get['name']!=''){
             $where[] = ['o.name', 'like', '%' . $get['name'] . '%'];
         } 
        //下单时间检索
        if(isset($get['start_time']) && $get['start_time']!=''){
            $where[] = ['o.autotime','>=',strtotime($get['start_time'])];
        }
        if(isset($get['end_time']) && $get['end_time']!=''){
            $where[] = ['o.autotime','<=',strtotime($get['end_time'])];
        }
        if(isset($get['channel']) && $get['channel']!=''){
         $where[] = ['o.channel_id','=',$get['channel']];
         }
         return $where;
    }
    
    public static  function cleaning($get){
        $where = self::whereDate($get);
        $count = Db::name('order_exe')
            ->alias('o')
            ->join('goods g', 'o.goods_id = g.id')
            ->where('g.brand_id', 1)
            ->where($where)
            ->count();
         $lists = Db::name('order_exe')
        ->alias('o')
        ->join('goods g', 'o.goods_id = g.id')
        ->where($where)
        ->where('g.brand_id', 1)
         ->field('o.*')
        ->page($get['page'], $get['limit'])
        ->order('o.id desc')
        ->select();
         foreach ($lists as &$item){
            $item['autotime'] = date("Y-m-d",$item['autotime']);
            
            $cumst=Db::name('order')->where('order_sn',$item['order_sn'])->find();       //获取订单的基本信息
         
            if($cumst){
            $item['consignee']= $cumst['consignee'];
            $item['phone']= $cumst['mobile'];
            $item['address']= $cumst['address'];
            $item['typeorder']= $cumst['type'];  
            $item['order_remarks']= $cumst['order_remarks'];
            $cumsts=Db::name('user_address')->where('telephone',$cumst['mobile'])->find();   //获取到客户的基本信息
            if($cumsts){
                $item['pet']= $cumsts['pet'];
                $item['hbl']= $cumsts['hbl'];
                $item['user_remarks']= $cumsts['user_remarks'];
                $item['square']= $cumsts['areas'];
                $item['admin_remarks']= $cumsts['admin_remarks'];
                $item['staff_remarks']= $cumsts['staff_remarks']; 
            }

            }
            $admin=Db::name('admin')->where('id',$item['admin'])->find();            //获取管理员信息
            if($admin){
                 $item['admin']=$admin['name'];
            }else{
                 $item['admin']='-';
            }
           
            $staff=Db::name('staff')->where('id',$item['staff_id'])->find();           //获取到订单的保洁师人员
            if($staff){
                $item['staff_name']=$staff['name'];
                $item['staff_id']= $staff['id'];
                $item['staff_mobile']= $staff['mobile'];
                $item['staff_addr']= $staff['addr'];     
              }

            
            $goods=Db::name('goods')->where('id',$item['goods_id'])->find();            //获取商品到信息
            
            $channel=Db::name('orderchannel')->where('id',$cumst['channel_id'])->find();
            if($channel){
                $item['channel_name']= $channel['name'];
            }else{
                 $item['channel_name']='客户自助下单';
            }
            
            if($goods){
                $item['goods_name']=$goods['name'];
            }else{
                 $item['goods_name']='-';
            }
            
            //保洁师服务时间
            if($item['start_time']){
                $item['start_time']=date("Y-m-d H:i:s",$item['start_time']);
            }else{
                $item['start_time']='-';
            }
            
            if($item['timeout']){
                  $item['timeout']=date("Y-m-d H:i:s",$item['timeout']);
             }else{
                 $item['timeout']='-';
            }
             
            //售后订单回访控制 
            $track=Db::name('order_trace')->where('order_id',$item['id'])->find();
            if($track){
                $item['is_show']=-1;
            }else{
                 $item['is_show']=1;
            }
            
            //控制异常订单显示
            
            $abnormal=Db::name('order_sale')->where('order_id',$item['id'])->find();
            if($abnormal){
                $item['sale_show']=-1;
            }else{
                 $item['sale_show']=1;
            }
        
            if($item['admin']==0){
              $coustdd=Db::name('user_address')->where('telephone',$cumst['mobile'])->find();
              if($coustdd){
                $date=Db::name('order_exe')->where('id',$item['id'])->update(['name'=>$cumst['consignee'],'phone'=>$cumst['mobile'],'admin'=>$coustdd['admin_id']]);
              }
         
            }
            //自动更新套餐
            if($item['goods_id']==0){
               $date=Db::name('order_exe')->where('id',$item['id'])->update(['goods_id'=>$cumst['goods_id']]);
             }
             if($item['channel_id']==0){
                $date=Db::name('order_exe')->where('id',$item['id'])->update(['channel_id'=>$cumst['channel_id']]);
             }
         
             if(strtotime($item['autotime'])!=strtotime($item['date'])){
                $date=Db::name('order_exe')->where('id',$item['id'])->update(['date'=>$item['autotime']]);
             }
        
         }
       return ['count' => $count, 'lists' => $lists];
    }

    public static function depth($get){
        $where = self::whereDate($get);
        $count = Db::name('order_exe')
            ->alias('o')
            ->join('goods g', 'o.goods_id = g.id')
            ->where('g.brand_id', 4)
            ->where($where)
            ->count();
         $lists = Db::name('order_exe')
        ->alias('o')
        ->join('goods g', 'o.goods_id = g.id')
        ->where($where)
        ->where('g.brand_id', 4)
         ->field('o.*')
        ->page($get['page'], $get['limit'])
        ->order('o.id desc')
        ->select();
         foreach ($lists as &$item){
            $item['autotime'] = date("Y-m-d",$item['autotime']);
            
            $cumst=Db::name('order')->where('order_sn',$item['order_sn'])->find();       //获取订单的基本信息
         
            if($cumst){
            $item['consignee']= $cumst['consignee'];
            $item['phone']= $cumst['mobile'];
            $item['address']= $cumst['address'];
            $item['typeorder']= $cumst['type'];  
            $item['order_remarks']= $cumst['order_remarks'];
            $cumsts=Db::name('user_address')->where('telephone',$cumst['mobile'])->find();   //获取到客户的基本信息
            if($cumsts){
                $item['pet']= $cumsts['pet'];
                $item['hbl']= $cumsts['hbl'];
                $item['user_remarks']= $cumsts['user_remarks'];
                $item['square']= $cumsts['areas'];
                $item['admin_remarks']= $cumsts['admin_remarks'];
                $item['staff_remarks']= $cumsts['staff_remarks']; 
            }

            }
            $admin=Db::name('admin')->where('id',$item['admin'])->find();            //获取管理员信息
            if($admin){
                 $item['admin']=$admin['name'];
            }else{
                 $item['admin']='-';
            }
           
            $staff=Db::name('staff')->where('id',$item['staff_id'])->find();           //获取到订单的保洁师人员
            if($staff){
                $item['staff_name']=$staff['name'];
                $item['staff_id']= $staff['id'];
                $item['staff_mobile']= $staff['mobile'];
                $item['staff_addr']= $staff['addr'];     
              }

            
            $goods=Db::name('goods')->where('id',$item['goods_id'])->find();            //获取商品到信息
            
            $channel=Db::name('orderchannel')->where('id',$cumst['channel_id'])->find();
            if($channel){
                $item['channel_name']= $channel['name'];
            }else{
                 $item['channel_name']='客户自助下单';
            }
            
            if($goods){
                $item['goods_name']=$goods['name'];
            }else{
                 $item['goods_name']='-';
            }
            
            //保洁师服务时间
            if($item['start_time']){
                $item['start_time']=date("Y-m-d H:i:s",$item['start_time']);
            }else{
                $item['start_time']='-';
            }
            
            if($item['timeout']){
                  $item['timeout']=date("Y-m-d H:i:s",$item['timeout']);
             }else{
                 $item['timeout']='-';
            }
             
            //售后订单回访控制 
            $track=Db::name('order_trace')->where('order_id',$item['id'])->find();
            if($track){
                $item['is_show']=-1;
            }else{
                 $item['is_show']=1;
            }
            
            //控制异常订单显示
            
            $abnormal=Db::name('order_sale')->where('order_id',$item['id'])->find();
            if($abnormal){
                $item['sale_show']=-1;
            }else{
                 $item['sale_show']=1;
            }
        
            if($item['admin']==0){
              $coustdd=Db::name('user_address')->where('telephone',$cumst['mobile'])->find();
              if($coustdd){
                $date=Db::name('order_exe')->where('id',$item['id'])->update(['name'=>$cumst['consignee'],'phone'=>$cumst['mobile'],'admin'=>$coustdd['admin_id']]);
              }
         
            }
            //自动更新套餐
            if($item['goods_id']==0){
               $date=Db::name('order_exe')->where('id',$item['id'])->update(['goods_id'=>$cumst['goods_id']]);
             }
             if($item['channel_id']==0){
                $date=Db::name('order_exe')->where('id',$item['id'])->update(['channel_id'=>$cumst['channel_id']]);
             }
         
             if(strtotime($item['autotime'])!=strtotime($item['date'])){
                $date=Db::name('order_exe')->where('id',$item['id'])->update(['date'=>$item['autotime']]);
             }
        
            }
       return ['count' => $count, 'lists' => $lists];
    }


    public static function storage($get){
        $where = self::whereDate($get);
        $count = Db::name('order_exe')
            ->alias('o')
            ->join('goods g', 'o.goods_id = g.id')
            ->where('g.brand_id', 2)
            ->where($where)
            ->count();
         $lists = Db::name('order_exe')
        ->alias('o')
        ->join('goods g', 'o.goods_id = g.id')
        ->where($where)
        ->where('g.brand_id', 2)
         ->field('o.*')
        ->page($get['page'], $get['limit'])
        ->order('o.id desc')
        ->select();
         foreach ($lists as &$item){
            $item['autotime'] = date("Y-m-d",$item['autotime']);
            
            $cumst=Db::name('order')->where('order_sn',$item['order_sn'])->find();       //获取订单的基本信息
         
            if($cumst){
            $item['consignee']= $cumst['consignee'];
            $item['phone']= $cumst['mobile'];
            $item['address']= $cumst['address'];
            $item['typeorder']= $cumst['type'];  
            $item['order_remarks']= $cumst['order_remarks'];
            $cumsts=Db::name('user_address')->where('telephone',$cumst['mobile'])->find();   //获取到客户的基本信息
            if($cumsts){
                $item['pet']= $cumsts['pet'];
                $item['hbl']= $cumsts['hbl'];
                $item['user_remarks']= $cumsts['user_remarks'];
                $item['square']= $cumsts['areas'];
                $item['admin_remarks']= $cumsts['admin_remarks'];
                $item['staff_remarks']= $cumsts['staff_remarks']; 
            }

            }
            $admin=Db::name('admin')->where('id',$item['admin'])->find();            //获取管理员信息
            if($admin){
                 $item['admin']=$admin['name'];
            }else{
                 $item['admin']='-';
            }
           
            $staff=Db::name('staff')->where('id',$item['staff_id'])->find();           //获取到订单的保洁师人员
            if($staff){
                $item['staff_name']=$staff['name'];
                $item['staff_id']= $staff['id'];
                $item['staff_mobile']= $staff['mobile'];
                $item['staff_addr']= $staff['addr'];     
              }

            
            $goods=Db::name('goods')->where('id',$item['goods_id'])->find();            //获取商品到信息
            
            $channel=Db::name('orderchannel')->where('id',$cumst['channel_id'])->find();
            if($channel){
                $item['channel_name']= $channel['name'];
            }else{
                 $item['channel_name']='客户自助下单';
            }
            
            if($goods){
                $item['goods_name']=$goods['name'];
            }else{
                 $item['goods_name']='-';
            }
            
            //保洁师服务时间
            if($item['start_time']){
                $item['start_time']=date("Y-m-d H:i:s",$item['start_time']);
            }else{
                $item['start_time']='-';
            }
            
            if($item['timeout']){
                  $item['timeout']=date("Y-m-d H:i:s",$item['timeout']);
             }else{
                 $item['timeout']='-';
            }
             
            //售后订单回访控制 
            $track=Db::name('order_trace')->where('order_id',$item['id'])->find();
            if($track){
                $item['is_show']=-1;
            }else{
                 $item['is_show']=1;
            }
            
            //控制异常订单显示
            
            $abnormal=Db::name('order_sale')->where('order_id',$item['id'])->find();
            if($abnormal){
                $item['sale_show']=-1;
            }else{
                 $item['sale_show']=1;
            }
        
            if($item['admin']==0){
              $coustdd=Db::name('user_address')->where('telephone',$cumst['mobile'])->find();
              if($coustdd){
                $date=Db::name('order_exe')->where('id',$item['id'])->update(['name'=>$cumst['consignee'],'phone'=>$cumst['mobile'],'admin'=>$coustdd['admin_id']]);
              }
         
            }
            //自动更新套餐
            if($item['goods_id']==0){
               $date=Db::name('order_exe')->where('id',$item['id'])->update(['goods_id'=>$cumst['goods_id']]);
             }
             if($item['channel_id']==0){
                $date=Db::name('order_exe')->where('id',$item['id'])->update(['channel_id'=>$cumst['channel_id']]);
             }
         
             if(strtotime($item['autotime'])!=strtotime($item['date'])){
                $date=Db::name('order_exe')->where('id',$item['id'])->update(['date'=>$item['autotime']]);
             }
        
            }
            return ['count' => $count, 'lists' => $lists];
    }


    public static function pets($get){
        $where = self::whereDate($get);
        $count = Db::name('order_exe')
            ->alias('o')
            ->join('goods g', 'o.goods_id = g.id')
            ->where('g.brand_id', 14)
            ->where($where)
            ->count();
         $lists = Db::name('order_exe')
        ->alias('o')
        ->join('goods g', 'o.goods_id = g.id')
        ->where($where)
        ->where('g.brand_id', 14)
         ->field('o.*')
        ->page($get['page'], $get['limit'])
        ->order('o.id desc')
        ->select();
         foreach ($lists as &$item){
            $item['autotime'] = date("Y-m-d",$item['autotime']);
            
            $cumst=Db::name('order')->where('order_sn',$item['order_sn'])->find();       //获取订单的基本信息
         
            if($cumst){
            $item['consignee']= $cumst['consignee'];
            $item['phone']= $cumst['mobile'];
            $item['address']= $cumst['address'];
            $item['typeorder']= $cumst['type'];  
            $item['order_remarks']= $cumst['order_remarks'];
            $cumsts=Db::name('user_address')->where('telephone',$cumst['mobile'])->find();   //获取到客户的基本信息
            if($cumsts){
                $item['pet']= $cumsts['pet'];
                $item['hbl']= $cumsts['hbl'];
                $item['user_remarks']= $cumsts['user_remarks'];
                $item['square']= $cumsts['areas'];
                $item['admin_remarks']= $cumsts['admin_remarks'];
                $item['staff_remarks']= $cumsts['staff_remarks']; 
            }

            }
            $admin=Db::name('admin')->where('id',$item['admin'])->find();            //获取管理员信息
            if($admin){
                 $item['admin']=$admin['name'];
            }else{
                 $item['admin']='-';
            }
           
            $staff=Db::name('staff')->where('id',$item['staff_id'])->find();           //获取到订单的保洁师人员
            if($staff){
                $item['staff_name']=$staff['name'];
                $item['staff_id']= $staff['id'];
                $item['staff_mobile']= $staff['mobile'];
                $item['staff_addr']= $staff['addr'];     
              }

            
            $goods=Db::name('goods')->where('id',$item['goods_id'])->find();            //获取商品到信息
            
            $channel=Db::name('orderchannel')->where('id',$cumst['channel_id'])->find();
            if($channel){
                $item['channel_name']= $channel['name'];
            }else{
                 $item['channel_name']='客户自助下单';
            }
            
            if($goods){
                $item['goods_name']=$goods['name'];
            }else{
                 $item['goods_name']='-';
            }
            
            //保洁师服务时间
            if($item['start_time']){
                $item['start_time']=date("Y-m-d H:i:s",$item['start_time']);
            }else{
                $item['start_time']='-';
            }
            
            if($item['timeout']){
                  $item['timeout']=date("Y-m-d H:i:s",$item['timeout']);
             }else{
                 $item['timeout']='-';
            }
             
            //售后订单回访控制 
            $track=Db::name('order_trace')->where('order_id',$item['id'])->find();
            if($track){
                $item['is_show']=-1;
            }else{
                 $item['is_show']=1;
            }
            
            //控制异常订单显示
            
            $abnormal=Db::name('order_sale')->where('order_id',$item['id'])->find();
            if($abnormal){
                $item['sale_show']=-1;
            }else{
                 $item['sale_show']=1;
            }
        
            if($item['admin']==0){
              $coustdd=Db::name('user_address')->where('telephone',$cumst['mobile'])->find();
              if($coustdd){
                $date=Db::name('order_exe')->where('id',$item['id'])->update(['name'=>$cumst['consignee'],'phone'=>$cumst['mobile'],'admin'=>$coustdd['admin_id']]);
              }
         
            }
            //自动更新套餐
            if($item['goods_id']==0){
               $date=Db::name('order_exe')->where('id',$item['id'])->update(['goods_id'=>$cumst['goods_id']]);
             }
             if($item['channel_id']==0){
                $date=Db::name('order_exe')->where('id',$item['id'])->update(['channel_id'=>$cumst['channel_id']]);
             }
         
             if(strtotime($item['autotime'])!=strtotime($item['date'])){
                $date=Db::name('order_exe')->where('id',$item['id'])->update(['date'=>$item['autotime']]);
             }
        
            }
            return ['count' => $count, 'lists' => $lists];
    }

    public static function thick($get){
        $where = self::whereDate($get);
        $count = Db::name('order_exe')
            ->alias('o')
            ->join('goods g', 'o.goods_id = g.id')
            ->where('g.brand_id', 13)
            ->where($where)
            ->count();
         $lists = Db::name('order_exe')
        ->alias('o')
        ->join('goods g', 'o.goods_id = g.id')
        ->where($where)
        ->where('g.brand_id', 13)
         ->field('o.*')
        ->page($get['page'], $get['limit'])
        ->order('o.id desc')
        ->select();
         foreach ($lists as &$item){
            $item['autotime'] = date("Y-m-d",$item['autotime']);
            
            $cumst=Db::name('order')->where('order_sn',$item['order_sn'])->find();       //获取订单的基本信息
         
            if($cumst){
            $item['consignee']= $cumst['consignee'];
            $item['phone']= $cumst['mobile'];
            $item['address']= $cumst['address'];
            $item['typeorder']= $cumst['type'];  
            $item['order_remarks']= $cumst['order_remarks'];
            $cumsts=Db::name('user_address')->where('telephone',$cumst['mobile'])->find();   //获取到客户的基本信息
            if($cumsts){
                $item['pet']= $cumsts['pet'];
                $item['hbl']= $cumsts['hbl'];
                $item['user_remarks']= $cumsts['user_remarks'];
                $item['square']= $cumsts['areas'];
                $item['admin_remarks']= $cumsts['admin_remarks'];
                $item['staff_remarks']= $cumsts['staff_remarks']; 
            }

            }
            $admin=Db::name('admin')->where('id',$item['admin'])->find();            //获取管理员信息
            if($admin){
                 $item['admin']=$admin['name'];
            }else{
                 $item['admin']='-';
            }
           
            $staff=Db::name('staff')->where('id',$item['staff_id'])->find();           //获取到订单的保洁师人员
            if($staff){
                $item['staff_name']=$staff['name'];
                $item['staff_id']= $staff['id'];
                $item['staff_mobile']= $staff['mobile'];
                $item['staff_addr']= $staff['addr'];     
              }

            
            $goods=Db::name('goods')->where('id',$item['goods_id'])->find();            //获取商品到信息
            
            $channel=Db::name('orderchannel')->where('id',$cumst['channel_id'])->find();
            if($channel){
                $item['channel_name']= $channel['name'];
            }else{
                 $item['channel_name']='客户自助下单';
            }
            
            if($goods){
                $item['goods_name']=$goods['name'];
            }else{
                 $item['goods_name']='-';
            }
            
            //保洁师服务时间
            if($item['start_time']){
                $item['start_time']=date("Y-m-d H:i:s",$item['start_time']);
            }else{
                $item['start_time']='-';
            }
            
            if($item['timeout']){
                  $item['timeout']=date("Y-m-d H:i:s",$item['timeout']);
             }else{
                 $item['timeout']='-';
            }
             
            //售后订单回访控制 
            $track=Db::name('order_trace')->where('order_id',$item['id'])->find();
            if($track){
                $item['is_show']=-1;
            }else{
                 $item['is_show']=1;
            }
            
            //控制异常订单显示
            
            $abnormal=Db::name('order_sale')->where('order_id',$item['id'])->find();
            if($abnormal){
                $item['sale_show']=-1;
            }else{
                 $item['sale_show']=1;
            }
        
            if($item['admin']==0){
              $coustdd=Db::name('user_address')->where('telephone',$cumst['mobile'])->find();
              if($coustdd){
                $date=Db::name('order_exe')->where('id',$item['id'])->update(['name'=>$cumst['consignee'],'phone'=>$cumst['mobile'],'admin'=>$coustdd['admin_id']]);
              }
         
            }
            //自动更新套餐
            if($item['goods_id']==0){
               $date=Db::name('order_exe')->where('id',$item['id'])->update(['goods_id'=>$cumst['goods_id']]);
             }
             if($item['channel_id']==0){
                $date=Db::name('order_exe')->where('id',$item['id'])->update(['channel_id'=>$cumst['channel_id']]);
             }
         
             if(strtotime($item['autotime'])!=strtotime($item['date'])){
                $date=Db::name('order_exe')->where('id',$item['id'])->update(['date'=>$item['autotime']]);
             }
        
            }
            return ['count' => $count, 'lists' => $lists];
    }
    
     public static function fine($get){
        $where = self::whereDate($get);
        $count = Db::name('order_exe')
            ->alias('o')
            ->join('goods g', 'o.goods_id = g.id')
            ->where('g.brand_id', 12)
            ->where($where)
            ->count();
         $lists = Db::name('order_exe')
        ->alias('o')
        ->join('goods g', 'o.goods_id = g.id')
        ->where($where)
        ->where('g.brand_id', 12)
         ->field('o.*')
        ->page($get['page'], $get['limit'])
        ->order('o.id desc')
        ->select();
         foreach ($lists as &$item){
            $item['autotime'] = date("Y-m-d",$item['autotime']);
            
            $cumst=Db::name('order')->where('order_sn',$item['order_sn'])->find();       //获取订单的基本信息
         
            if($cumst){
            $item['consignee']= $cumst['consignee'];
            $item['phone']= $cumst['mobile'];
            $item['address']= $cumst['address'];
            $item['typeorder']= $cumst['type'];  
            $item['order_remarks']= $cumst['order_remarks'];
            $cumsts=Db::name('user_address')->where('telephone',$cumst['mobile'])->find();   //获取到客户的基本信息
            if($cumsts){
                $item['pet']= $cumsts['pet'];
                $item['hbl']= $cumsts['hbl'];
                $item['user_remarks']= $cumsts['user_remarks'];
                $item['square']= $cumsts['areas'];
                $item['admin_remarks']= $cumsts['admin_remarks'];
                $item['staff_remarks']= $cumsts['staff_remarks']; 
            }

            }
            $admin=Db::name('admin')->where('id',$item['admin'])->find();            //获取管理员信息
            if($admin){
                 $item['admin']=$admin['name'];
            }else{
                 $item['admin']='-';
            }
           
            $staff=Db::name('staff')->where('id',$item['staff_id'])->find();           //获取到订单的保洁师人员
            if($staff){
                $item['staff_name']=$staff['name'];
                $item['staff_id']= $staff['id'];
                $item['staff_mobile']= $staff['mobile'];
                $item['staff_addr']= $staff['addr'];     
              }

            
            $goods=Db::name('goods')->where('id',$item['goods_id'])->find();            //获取商品到信息
            
            $channel=Db::name('orderchannel')->where('id',$cumst['channel_id'])->find();
            if($channel){
                $item['channel_name']= $channel['name'];
            }else{
                 $item['channel_name']='客户自助下单';
            }
            
            if($goods){
                $item['goods_name']=$goods['name'];
            }else{
                 $item['goods_name']='-';
            }
            
            //保洁师服务时间
            if($item['start_time']){
                $item['start_time']=date("Y-m-d H:i:s",$item['start_time']);
            }else{
                $item['start_time']='-';
            }
            
            if($item['timeout']){
                  $item['timeout']=date("Y-m-d H:i:s",$item['timeout']);
             }else{
                 $item['timeout']='-';
            }
             
            //售后订单回访控制 
            $track=Db::name('order_trace')->where('order_id',$item['id'])->find();
            if($track){
                $item['is_show']=-1;
            }else{
                 $item['is_show']=1;
            }
            
            //控制异常订单显示
            
            $abnormal=Db::name('order_sale')->where('order_id',$item['id'])->find();
            if($abnormal){
                $item['sale_show']=-1;
            }else{
                 $item['sale_show']=1;
            }
        
            if($item['admin']==0){
              $coustdd=Db::name('user_address')->where('telephone',$cumst['mobile'])->find();
              if($coustdd){
                $date=Db::name('order_exe')->where('id',$item['id'])->update(['name'=>$cumst['consignee'],'phone'=>$cumst['mobile'],'admin'=>$coustdd['admin_id']]);
              }
         
            }
            //自动更新套餐
            if($item['goods_id']==0){
               $date=Db::name('order_exe')->where('id',$item['id'])->update(['goods_id'=>$cumst['goods_id']]);
             }
             if($item['channel_id']==0){
                $date=Db::name('order_exe')->where('id',$item['id'])->update(['channel_id'=>$cumst['channel_id']]);
             }
         
             if(strtotime($item['autotime'])!=strtotime($item['date'])){
                $date=Db::name('order_exe')->where('id',$item['id'])->update(['date'=>$item['autotime']]);
             }
        
            }
            return ['count' => $count, 'lists' => $lists];
    }   
    




     public static function move($get){
        $where = self::whereDate($get);
        $count = Db::name('order_exe')
            ->alias('o')
            ->join('goods g', 'o.goods_id = g.id')
            ->where('g.brand_id', 11)
            ->where($where)
            ->count();
         $lists = Db::name('order_exe')
        ->alias('o')
        ->join('goods g', 'o.goods_id = g.id')
        ->where($where)
        ->where('g.brand_id', 11)
         ->field('o.*')
        ->page($get['page'], $get['limit'])
        ->order('o.id desc')
        ->select();
         foreach ($lists as &$item){
            $item['autotime'] = date("Y-m-d",$item['autotime']);
            
            $cumst=Db::name('order')->where('order_sn',$item['order_sn'])->find();       //获取订单的基本信息
         
            if($cumst){
            $item['consignee']= $cumst['consignee'];
            $item['phone']= $cumst['mobile'];
            $item['address']= $cumst['address'];
            $item['typeorder']= $cumst['type'];  
            $item['order_remarks']= $cumst['order_remarks'];
            $cumsts=Db::name('user_address')->where('telephone',$cumst['mobile'])->find();   //获取到客户的基本信息
            if($cumsts){
                $item['pet']= $cumsts['pet'];
                $item['hbl']= $cumsts['hbl'];
                $item['user_remarks']= $cumsts['user_remarks'];
                $item['square']= $cumsts['areas'];
                $item['admin_remarks']= $cumsts['admin_remarks'];
                $item['staff_remarks']= $cumsts['staff_remarks']; 
            }

            }
            $admin=Db::name('admin')->where('id',$item['admin'])->find();            //获取管理员信息
            if($admin){
                 $item['admin']=$admin['name'];
            }else{
                 $item['admin']='-';
            }
           
            $staff=Db::name('staff')->where('id',$item['staff_id'])->find();           //获取到订单的保洁师人员
            if($staff){
                $item['staff_name']=$staff['name'];
                $item['staff_id']= $staff['id'];
                $item['staff_mobile']= $staff['mobile'];
                $item['staff_addr']= $staff['addr'];     
              }

            
            $goods=Db::name('goods')->where('id',$item['goods_id'])->find();            //获取商品到信息
            
            $channel=Db::name('orderchannel')->where('id',$cumst['channel_id'])->find();
            if($channel){
                $item['channel_name']= $channel['name'];
            }else{
                 $item['channel_name']='客户自助下单';
            }
            
            if($goods){
                $item['goods_name']=$goods['name'];
            }else{
                 $item['goods_name']='-';
            }
            
            //保洁师服务时间
            if($item['start_time']){
                $item['start_time']=date("Y-m-d H:i:s",$item['start_time']);
            }else{
                $item['start_time']='-';
            }
            
            if($item['timeout']){
                  $item['timeout']=date("Y-m-d H:i:s",$item['timeout']);
             }else{
                 $item['timeout']='-';
            }
             
            //售后订单回访控制 
            $track=Db::name('order_trace')->where('order_id',$item['id'])->find();
            if($track){
                $item['is_show']=-1;
            }else{
                 $item['is_show']=1;
            }
            
            //控制异常订单显示
            
            $abnormal=Db::name('order_sale')->where('order_id',$item['id'])->find();
            if($abnormal){
                $item['sale_show']=-1;
            }else{
                 $item['sale_show']=1;
            }
        
            if($item['admin']==0){
              $coustdd=Db::name('user_address')->where('telephone',$cumst['mobile'])->find();
              if($coustdd){
                $date=Db::name('order_exe')->where('id',$item['id'])->update(['name'=>$cumst['consignee'],'phone'=>$cumst['mobile'],'admin'=>$coustdd['admin_id']]);
              }
         
            }
            //自动更新套餐
            if($item['goods_id']==0){
               $date=Db::name('order_exe')->where('id',$item['id'])->update(['goods_id'=>$cumst['goods_id']]);
             }
             if($item['channel_id']==0){
                $date=Db::name('order_exe')->where('id',$item['id'])->update(['channel_id'=>$cumst['channel_id']]);
             }
         
             if(strtotime($item['autotime'])!=strtotime($item['date'])){
                $date=Db::name('order_exe')->where('id',$item['id'])->update(['date'=>$item['autotime']]);
             }
        
            }
            return ['count' => $count, 'lists' => $lists];
    }   
    
    
    
    
     public static function detection($get){
        $where = self::whereDate($get);
        $count = Db::name('order_exe')
            ->alias('o')
            ->join('goods g', 'o.goods_id = g.id')
            ->where('g.brand_id', 10)
            ->where($where)
            ->count();
         $lists = Db::name('order_exe')
        ->alias('o')
        ->join('goods g', 'o.goods_id = g.id')
        ->where($where)
        ->where('g.brand_id', 10)
         ->field('o.*')
        ->page($get['page'], $get['limit'])
        ->order('o.id desc')
        ->select();
         foreach ($lists as &$item){
            $item['autotime'] = date("Y-m-d",$item['autotime']);
            
            $cumst=Db::name('order')->where('order_sn',$item['order_sn'])->find();       //获取订单的基本信息
         
            if($cumst){
            $item['consignee']= $cumst['consignee'];
            $item['phone']= $cumst['mobile'];
            $item['address']= $cumst['address'];
            $item['typeorder']= $cumst['type'];  
            $item['order_remarks']= $cumst['order_remarks'];
            $cumsts=Db::name('user_address')->where('telephone',$cumst['mobile'])->find();   //获取到客户的基本信息
            if($cumsts){
                $item['pet']= $cumsts['pet'];
                $item['hbl']= $cumsts['hbl'];
                $item['user_remarks']= $cumsts['user_remarks'];
                $item['square']= $cumsts['areas'];
                $item['admin_remarks']= $cumsts['admin_remarks'];
                $item['staff_remarks']= $cumsts['staff_remarks']; 
            }

            }
            $admin=Db::name('admin')->where('id',$item['admin'])->find();            //获取管理员信息
            if($admin){
                 $item['admin']=$admin['name'];
            }else{
                 $item['admin']='-';
            }
           
            $staff=Db::name('staff')->where('id',$item['staff_id'])->find();           //获取到订单的保洁师人员
            if($staff){
                $item['staff_name']=$staff['name'];
                $item['staff_id']= $staff['id'];
                $item['staff_mobile']= $staff['mobile'];
                $item['staff_addr']= $staff['addr'];     
              }

            
            $goods=Db::name('goods')->where('id',$item['goods_id'])->find();            //获取商品到信息
            
            $channel=Db::name('orderchannel')->where('id',$cumst['channel_id'])->find();
            if($channel){
                $item['channel_name']= $channel['name'];
            }else{
                 $item['channel_name']='客户自助下单';
            }
            
            if($goods){
                $item['goods_name']=$goods['name'];
            }else{
                 $item['goods_name']='-';
            }
            
            //保洁师服务时间
            if($item['start_time']){
                $item['start_time']=date("Y-m-d H:i:s",$item['start_time']);
            }else{
                $item['start_time']='-';
            }
            
            if($item['timeout']){
                  $item['timeout']=date("Y-m-d H:i:s",$item['timeout']);
             }else{
                 $item['timeout']='-';
            }
             
            //售后订单回访控制 
            $track=Db::name('order_trace')->where('order_id',$item['id'])->find();
            if($track){
                $item['is_show']=-1;
            }else{
                 $item['is_show']=1;
            }
            
            //控制异常订单显示
            
            $abnormal=Db::name('order_sale')->where('order_id',$item['id'])->find();
            if($abnormal){
                $item['sale_show']=-1;
            }else{
                 $item['sale_show']=1;
            }
        
            if($item['admin']==0){
              $coustdd=Db::name('user_address')->where('telephone',$cumst['mobile'])->find();
              if($coustdd){
                $date=Db::name('order_exe')->where('id',$item['id'])->update(['name'=>$cumst['consignee'],'phone'=>$cumst['mobile'],'admin'=>$coustdd['admin_id']]);
              }
         
            }
            //自动更新套餐
            if($item['goods_id']==0){
               $date=Db::name('order_exe')->where('id',$item['id'])->update(['goods_id'=>$cumst['goods_id']]);
             }
             if($item['channel_id']==0){
                $date=Db::name('order_exe')->where('id',$item['id'])->update(['channel_id'=>$cumst['channel_id']]);
             }
         
             if(strtotime($item['autotime'])!=strtotime($item['date'])){
                $date=Db::name('order_exe')->where('id',$item['id'])->update(['date'=>$item['autotime']]);
             }
        
            }
            return ['count' => $count, 'lists' => $lists];
    }   



//

     public static function governance($get){
        $where = self::whereDate($get);
        $count = Db::name('order_exe')
            ->alias('o')
            ->join('goods g', 'o.goods_id = g.id')
            ->where('g.brand_id', 9)
            ->where($where)
            ->count();
         $lists = Db::name('order_exe')
        ->alias('o')
        ->join('goods g', 'o.goods_id = g.id')
        ->where($where)
        ->where('g.brand_id', 9)
         ->field('o.*')
        ->page($get['page'], $get['limit'])
        ->order('o.id desc')
        ->select();
         foreach ($lists as &$item){
            $item['autotime'] = date("Y-m-d",$item['autotime']);
            
            $cumst=Db::name('order')->where('order_sn',$item['order_sn'])->find();       //获取订单的基本信息
         
            if($cumst){
            $item['consignee']= $cumst['consignee'];
            $item['phone']= $cumst['mobile'];
            $item['address']= $cumst['address'];
            $item['typeorder']= $cumst['type'];  
            $item['order_remarks']= $cumst['order_remarks'];
            $cumsts=Db::name('user_address')->where('telephone',$cumst['mobile'])->find();   //获取到客户的基本信息
            if($cumsts){
                $item['pet']= $cumsts['pet'];
                $item['hbl']= $cumsts['hbl'];
                $item['user_remarks']= $cumsts['user_remarks'];
                $item['square']= $cumsts['areas'];
                $item['admin_remarks']= $cumsts['admin_remarks'];
                $item['staff_remarks']= $cumsts['staff_remarks']; 
            }

            }
            $admin=Db::name('admin')->where('id',$item['admin'])->find();            //获取管理员信息
            if($admin){
                 $item['admin']=$admin['name'];
            }else{
                 $item['admin']='-';
            }
           
            $staff=Db::name('staff')->where('id',$item['staff_id'])->find();           //获取到订单的保洁师人员
            if($staff){
                $item['staff_name']=$staff['name'];
                $item['staff_id']= $staff['id'];
                $item['staff_mobile']= $staff['mobile'];
                $item['staff_addr']= $staff['addr'];     
              }

            
            $goods=Db::name('goods')->where('id',$item['goods_id'])->find();            //获取商品到信息
            
            $channel=Db::name('orderchannel')->where('id',$cumst['channel_id'])->find();
            if($channel){
                $item['channel_name']= $channel['name'];
            }else{
                 $item['channel_name']='客户自助下单';
            }
            
            if($goods){
                $item['goods_name']=$goods['name'];
            }else{
                 $item['goods_name']='-';
            }
            
            //保洁师服务时间
            if($item['start_time']){
                $item['start_time']=date("Y-m-d H:i:s",$item['start_time']);
            }else{
                $item['start_time']='-';
            }
            
            if($item['timeout']){
                  $item['timeout']=date("Y-m-d H:i:s",$item['timeout']);
             }else{
                 $item['timeout']='-';
            }
             
            //售后订单回访控制 
            $track=Db::name('order_trace')->where('order_id',$item['id'])->find();
            if($track){
                $item['is_show']=-1;
            }else{
                 $item['is_show']=1;
            }
            
            //控制异常订单显示
            
            $abnormal=Db::name('order_sale')->where('order_id',$item['id'])->find();
            if($abnormal){
                $item['sale_show']=-1;
            }else{
                 $item['sale_show']=1;
            }
        
            if($item['admin']==0){
              $coustdd=Db::name('user_address')->where('telephone',$cumst['mobile'])->find();
              if($coustdd){
                $date=Db::name('order_exe')->where('id',$item['id'])->update(['name'=>$cumst['consignee'],'phone'=>$cumst['mobile'],'admin'=>$coustdd['admin_id']]);
              }
         
            }
            //自动更新套餐
            if($item['goods_id']==0){
               $date=Db::name('order_exe')->where('id',$item['id'])->update(['goods_id'=>$cumst['goods_id']]);
             }
             if($item['channel_id']==0){
                $date=Db::name('order_exe')->where('id',$item['id'])->update(['channel_id'=>$cumst['channel_id']]);
             }
         
             if(strtotime($item['autotime'])!=strtotime($item['date'])){
                $date=Db::name('order_exe')->where('id',$item['id'])->update(['date'=>$item['autotime']]);
             }
        
            }
            return ['count' => $count, 'lists' => $lists];
    }   
    

    
     
     public static function wash($get){
        $where = self::whereDate($get);
        $count = Db::name('order_exe')
            ->alias('o')
            ->join('goods g', 'o.goods_id = g.id')
            ->where('g.brand_id', 7)
            ->where($where)
            ->count();
         $lists = Db::name('order_exe')
        ->alias('o')
        ->join('goods g', 'o.goods_id = g.id')
        ->where($where)
        ->where('g.brand_id', 7)
         ->field('o.*')
        ->page($get['page'], $get['limit'])
        ->order('o.id desc')
        ->select();
         foreach ($lists as &$item){
            $item['autotime'] = date("Y-m-d",$item['autotime']);
            
            $cumst=Db::name('order')->where('order_sn',$item['order_sn'])->find();       //获取订单的基本信息
         
            if($cumst){
            $item['consignee']= $cumst['consignee'];
            $item['phone']= $cumst['mobile'];
            $item['address']= $cumst['address'];
            $item['typeorder']= $cumst['type'];  
            $item['order_remarks']= $cumst['order_remarks'];
            $cumsts=Db::name('user_address')->where('telephone',$cumst['mobile'])->find();   //获取到客户的基本信息
            if($cumsts){
                $item['pet']= $cumsts['pet'];
                $item['hbl']= $cumsts['hbl'];
                $item['user_remarks']= $cumsts['user_remarks'];
                $item['square']= $cumsts['areas'];
                $item['admin_remarks']= $cumsts['admin_remarks'];
                $item['staff_remarks']= $cumsts['staff_remarks']; 
            }

            }
            $admin=Db::name('admin')->where('id',$item['admin'])->find();            //获取管理员信息
            if($admin){
                 $item['admin']=$admin['name'];
            }else{
                 $item['admin']='-';
            }
           
            $staff=Db::name('staff')->where('id',$item['staff_id'])->find();           //获取到订单的保洁师人员
            if($staff){
                $item['staff_name']=$staff['name'];
                $item['staff_id']= $staff['id'];
                $item['staff_mobile']= $staff['mobile'];
                $item['staff_addr']= $staff['addr'];     
              }

            
            $goods=Db::name('goods')->where('id',$item['goods_id'])->find();            //获取商品到信息
            
            $channel=Db::name('orderchannel')->where('id',$cumst['channel_id'])->find();
            if($channel){
                $item['channel_name']= $channel['name'];
            }else{
                 $item['channel_name']='客户自助下单';
            }
            
            if($goods){
                $item['goods_name']=$goods['name'];
            }else{
                 $item['goods_name']='-';
            }
            
            //保洁师服务时间
            if($item['start_time']){
                $item['start_time']=date("Y-m-d H:i:s",$item['start_time']);
            }else{
                $item['start_time']='-';
            }
            
            if($item['timeout']){
                  $item['timeout']=date("Y-m-d H:i:s",$item['timeout']);
             }else{
                 $item['timeout']='-';
            }
             
            //售后订单回访控制 
            $track=Db::name('order_trace')->where('order_id',$item['id'])->find();
            if($track){
                $item['is_show']=-1;
            }else{
                 $item['is_show']=1;
            }
            
            //控制异常订单显示
            
            $abnormal=Db::name('order_sale')->where('order_id',$item['id'])->find();
            if($abnormal){
                $item['sale_show']=-1;
            }else{
                 $item['sale_show']=1;
            }
        
            if($item['admin']==0){
              $coustdd=Db::name('user_address')->where('telephone',$cumst['mobile'])->find();
              if($coustdd){
                $date=Db::name('order_exe')->where('id',$item['id'])->update(['name'=>$cumst['consignee'],'phone'=>$cumst['mobile'],'admin'=>$coustdd['admin_id']]);
              }
         
            }
            //自动更新套餐
            if($item['goods_id']==0){
               $date=Db::name('order_exe')->where('id',$item['id'])->update(['goods_id'=>$cumst['goods_id']]);
             }
             if($item['channel_id']==0){
                $date=Db::name('order_exe')->where('id',$item['id'])->update(['channel_id'=>$cumst['channel_id']]);
             }
         
             if(strtotime($item['autotime'])!=strtotime($item['date'])){
                $date=Db::name('order_exe')->where('id',$item['id'])->update(['date'=>$item['autotime']]);
             }
        
            }
            return ['count' => $count, 'lists' => $lists];
    }  


     public static function linen($get){
         
        $where = self::whereDate($get);
        $count = Db::name('order_exe')
            ->alias('o')
            ->join('goods g', 'o.goods_id = g.id')
            ->where('g.brand_id', 8)
            ->where($where)
            ->count();
         $lists = Db::name('order_exe')
        ->alias('o')
        ->join('goods g', 'o.goods_id = g.id')
        ->where($where)
        ->where('g.brand_id', 8)
         ->field('o.*')
        ->page($get['page'], $get['limit'])
        ->order('o.id desc')
        ->select();
         foreach ($lists as &$item){
            $item['autotime'] = date("Y-m-d",$item['autotime']);
            
            $cumst=Db::name('order')->where('order_sn',$item['order_sn'])->find();       //获取订单的基本信息
         
            if($cumst){
            $item['consignee']= $cumst['consignee'];
            $item['phone']= $cumst['mobile'];
            $item['address']= $cumst['address'];
            $item['typeorder']= $cumst['type'];  
            $item['order_remarks']= $cumst['order_remarks'];
            $cumsts=Db::name('user_address')->where('telephone',$cumst['mobile'])->find();   //获取到客户的基本信息
            if($cumsts){
                $item['pet']= $cumsts['pet'];
                $item['hbl']= $cumsts['hbl'];
                $item['user_remarks']= $cumsts['user_remarks'];
                $item['square']= $cumsts['areas'];
                $item['admin_remarks']= $cumsts['admin_remarks'];
                $item['staff_remarks']= $cumsts['staff_remarks']; 
            }

            }
            $admin=Db::name('admin')->where('id',$item['admin'])->find();            //获取管理员信息
            if($admin){
                 $item['admin']=$admin['name'];
            }else{
                 $item['admin']='-';
            }
           
            $staff=Db::name('staff')->where('id',$item['staff_id'])->find();           //获取到订单的保洁师人员
            if($staff){
                $item['staff_name']=$staff['name'];
                $item['staff_id']= $staff['id'];
                $item['staff_mobile']= $staff['mobile'];
                $item['staff_addr']= $staff['addr'];     
              }

            
            $goods=Db::name('goods')->where('id',$item['goods_id'])->find();            //获取商品到信息
            
            $channel=Db::name('orderchannel')->where('id',$cumst['channel_id'])->find();
            if($channel){
                $item['channel_name']= $channel['name'];
            }else{
                 $item['channel_name']='客户自助下单';
            }
            
            if($goods){
                $item['goods_name']=$goods['name'];
            }else{
                 $item['goods_name']='-';
            }
            
            //保洁师服务时间
            if($item['start_time']){
                $item['start_time']=date("Y-m-d H:i:s",$item['start_time']);
            }else{
                $item['start_time']='-';
            }
            
            if($item['timeout']){
                  $item['timeout']=date("Y-m-d H:i:s",$item['timeout']);
             }else{
                 $item['timeout']='-';
            }
             
            //售后订单回访控制 
            $track=Db::name('order_trace')->where('order_id',$item['id'])->find();
            if($track){
                $item['is_show']=-1;
            }else{
                 $item['is_show']=1;
            }
            
            //控制异常订单显示
            
            $abnormal=Db::name('order_sale')->where('order_id',$item['id'])->find();
            if($abnormal){
                $item['sale_show']=-1;
            }else{
                 $item['sale_show']=1;
            }
        
            if($item['admin']==0){
              $coustdd=Db::name('user_address')->where('telephone',$cumst['mobile'])->find();
              if($coustdd){
                $date=Db::name('order_exe')->where('id',$item['id'])->update(['name'=>$cumst['consignee'],'phone'=>$cumst['mobile'],'admin'=>$coustdd['admin_id']]);
              }
         
            }
            //自动更新套餐
            if($item['goods_id']==0){
               $date=Db::name('order_exe')->where('id',$item['id'])->update(['goods_id'=>$cumst['goods_id']]);
             }
             if($item['channel_id']==0){
                $date=Db::name('order_exe')->where('id',$item['id'])->update(['channel_id'=>$cumst['channel_id']]);
             }
         
             if(strtotime($item['autotime'])!=strtotime($item['date'])){
                $date=Db::name('order_exe')->where('id',$item['id'])->update(['date'=>$item['autotime']]);
             }
        
            }
            return ['count' => $count, 'lists' => $lists];
    }  


     public static function cooking($get){
         
        $where = self::whereDate($get);
        $count = Db::name('order_exe')
            ->alias('o')
            ->join('goods g', 'o.goods_id = g.id')
            ->where('g.brand_id', 3)
            ->where($where)
            ->count();
         $lists = Db::name('order_exe')
        ->alias('o')
        ->join('goods g', 'o.goods_id = g.id')
        ->where($where)
        ->where('g.brand_id', 3)
         ->field('o.*')
        ->page($get['page'], $get['limit'])
        ->order('o.id desc')
        ->select();
         foreach ($lists as &$item){
            $item['autotime'] = date("Y-m-d",$item['autotime']);
            
            $cumst=Db::name('order')->where('order_sn',$item['order_sn'])->find();       //获取订单的基本信息
         
            if($cumst){
            $item['consignee']= $cumst['consignee'];
            $item['phone']= $cumst['mobile'];
            $item['address']= $cumst['address'];
            $item['typeorder']= $cumst['type'];  
            $item['order_remarks']= $cumst['order_remarks'];
            $cumsts=Db::name('user_address')->where('telephone',$cumst['mobile'])->find();   //获取到客户的基本信息
            if($cumsts){
                $item['pet']= $cumsts['pet'];
                $item['hbl']= $cumsts['hbl'];
                $item['user_remarks']= $cumsts['user_remarks'];
                $item['square']= $cumsts['areas'];
                $item['admin_remarks']= $cumsts['admin_remarks'];
                $item['staff_remarks']= $cumsts['staff_remarks']; 
            }

            }
            $admin=Db::name('admin')->where('id',$item['admin'])->find();            //获取管理员信息
            if($admin){
                 $item['admin']=$admin['name'];
            }else{
                 $item['admin']='-';
            }
           
            $staff=Db::name('staff')->where('id',$item['staff_id'])->find();           //获取到订单的保洁师人员
            if($staff){
                $item['staff_name']=$staff['name'];
                $item['staff_id']= $staff['id'];
                $item['staff_mobile']= $staff['mobile'];
                $item['staff_addr']= $staff['addr'];     
              }

            
            $goods=Db::name('goods')->where('id',$item['goods_id'])->find();            //获取商品到信息
            
            $channel=Db::name('orderchannel')->where('id',$cumst['channel_id'])->find();
            if($channel){
                $item['channel_name']= $channel['name'];
            }else{
                 $item['channel_name']='客户自助下单';
            }
            
            if($goods){
                $item['goods_name']=$goods['name'];
            }else{
                 $item['goods_name']='-';
            }
            
            //保洁师服务时间
            if($item['start_time']){
                $item['start_time']=date("Y-m-d H:i:s",$item['start_time']);
            }else{
                $item['start_time']='-';
            }
            
            if($item['timeout']){
                  $item['timeout']=date("Y-m-d H:i:s",$item['timeout']);
             }else{
                 $item['timeout']='-';
            }
             
            //售后订单回访控制 
            $track=Db::name('order_trace')->where('order_id',$item['id'])->find();
            if($track){
                $item['is_show']=-1;
            }else{
                 $item['is_show']=1;
            }
            
            //控制异常订单显示
            
            $abnormal=Db::name('order_sale')->where('order_id',$item['id'])->find();
            if($abnormal){
                $item['sale_show']=-1;
            }else{
                 $item['sale_show']=1;
            }
        
            if($item['admin']==0){
              $coustdd=Db::name('user_address')->where('telephone',$cumst['mobile'])->find();
              if($coustdd){
                $date=Db::name('order_exe')->where('id',$item['id'])->update(['name'=>$cumst['consignee'],'phone'=>$cumst['mobile'],'admin'=>$coustdd['admin_id']]);
              }
         
            }
            //自动更新套餐
            if($item['goods_id']==0){
               $date=Db::name('order_exe')->where('id',$item['id'])->update(['goods_id'=>$cumst['goods_id']]);
             }
             if($item['channel_id']==0){
                $date=Db::name('order_exe')->where('id',$item['id'])->update(['channel_id'=>$cumst['channel_id']]);
             }
         
             if(strtotime($item['autotime'])!=strtotime($item['date'])){
                $date=Db::name('order_exe')->where('id',$item['id'])->update(['date'=>$item['autotime']]);
             }
        
            }
            return ['count' => $count, 'lists' => $lists];
    }  
     public static function lists($get){
         
        $where = self::whereDate($get);
        $count = Db::name('order_exe')
            ->alias('o')
            ->join('goods g', 'o.goods_id = g.id')
            ->where('g.brand_id', 3)
            ->where($where)
            ->count();
         $lists = Db::name('order_exe')
        ->alias('o')
        ->join('goods g', 'o.goods_id = g.id')
        ->where($where)
         ->field('o.*')
        ->page($get['page'], $get['limit'])
        ->order('o.id desc')
        ->select();
         foreach ($lists as &$item){
            $item['autotime'] = date("Y-m-d",$item['autotime']);
            
            $cumst=Db::name('order')->where('order_sn',$item['order_sn'])->find();       //获取订单的基本信息
         
            if($cumst){
            $item['consignee']= $cumst['consignee'];
            $item['phone']= $cumst['mobile'];
            $item['address']= $cumst['address'];
            $item['typeorder']= $cumst['type'];  
            $item['order_remarks']= $cumst['order_remarks'];
            $cumsts=Db::name('user_address')->where('telephone',$cumst['mobile'])->find();   //获取到客户的基本信息
            if($cumsts){
                $item['pet']= $cumsts['pet'];
                $item['hbl']= $cumsts['hbl'];
                $item['user_remarks']= $cumsts['user_remarks'];
                $item['square']= $cumsts['areas'];
                $item['admin_remarks']= $cumsts['admin_remarks'];
                $item['staff_remarks']= $cumsts['staff_remarks']; 
            }

            }
            $admin=Db::name('admin')->where('id',$item['admin'])->find();            //获取管理员信息
            if($admin){
                 $item['admin']=$admin['name'];
            }else{
                 $item['admin']='-';
            }
           
            $staff=Db::name('staff')->where('id',$item['staff_id'])->find();           //获取到订单的保洁师人员
            if($staff){
                $item['staff_name']=$staff['name'];
                $item['staff_id']= $staff['id'];
                $item['staff_mobile']= $staff['mobile'];
                $item['staff_addr']= $staff['addr'];     
              }

            
            $goods=Db::name('goods')->where('id',$item['goods_id'])->find();            //获取商品到信息
            
            $channel=Db::name('orderchannel')->where('id',$cumst['channel_id'])->find();
            if($channel){
                $item['channel_name']= $channel['name'];
            }else{
                 $item['channel_name']='客户自助下单';
            }
            
            if($goods){
                $item['goods_name']=$goods['name'];
            }else{
                 $item['goods_name']='-';
            }
            
            //保洁师服务时间
            if($item['start_time']){
                $item['start_time']=date("Y-m-d H:i:s",$item['start_time']);
            }else{
                $item['start_time']='-';
            }
            
            if($item['timeout']){
                  $item['timeout']=date("Y-m-d H:i:s",$item['timeout']);
             }else{
                 $item['timeout']='-';
            }
             
            //售后订单回访控制 
            $track=Db::name('order_trace')->where('order_id',$item['id'])->find();
            if($track){
                $item['is_show']=-1;
            }else{
                 $item['is_show']=1;
            }
            
            //控制异常订单显示
            
            $abnormal=Db::name('order_sale')->where('order_id',$item['id'])->find();
            if($abnormal){
                $item['sale_show']=-1;
            }else{
                 $item['sale_show']=1;
            }
        
            if($item['admin']==0){
              $coustdd=Db::name('user_address')->where('telephone',$cumst['mobile'])->find();
              if($coustdd){
                $date=Db::name('order_exe')->where('id',$item['id'])->update(['name'=>$cumst['consignee'],'phone'=>$cumst['mobile'],'admin'=>$coustdd['admin_id']]);
              }
         
            }
            //自动更新套餐
            if($item['goods_id']==0){
               $date=Db::name('order_exe')->where('id',$item['id'])->update(['goods_id'=>$cumst['goods_id']]);
             }
             if($item['channel_id']==0){
                $date=Db::name('order_exe')->where('id',$item['id'])->update(['channel_id'=>$cumst['channel_id']]);
             }
         
             if(strtotime($item['autotime'])!=strtotime($item['date'])){
                $date=Db::name('order_exe')->where('id',$item['id'])->update(['date'=>$item['autotime']]);
             }
        
            }
            return ['count' => $count, 'lists' => $lists];
    }  


}