<?php

namespace app\admin\logic;

use app\common\logic\OrderRefundLogic;
use app\common\model\MessageScene_;
use app\common\model\NoticeSetting;
use app\common\model\Order;
use app\common\model\OrderGoods;
use app\common\model\OrderLog;
use app\common\logic\OrderLogLogic;
use app\common\model\Pay;
use app\common\model\UserLevel;
use app\common\server\ConfigServer;
use app\common\server\UrlServer;
use app\common\server\YlyPrinter;
use expressage\Kd100;
use expressage\Kdniao;
use think\Db;
use think\Exception;
use think\facade\Cache;
use think\facade\Env;
use think\facade\Hook;

class AdminorderLogic
{

    /**
     * Notes: 列表查询条件
     * @param $get
     * @author 段誉(2021/2/1 10:12)
     * @return array
     */
    public static function getListsCondition($get)
    {
        $where = [];
       
        $where[] = ['o.admin_id','=',session('admin_info.id')];
       
        //订单状态
        if ($get['type'] != '') {
            $where[] = ['o.pay_status', '=', $get['type']];
        }
        //订单编号查询
        if (isset($get['order_sn']) && $get['order_sn'] != '') {
            $where[] = ['o.order_sn', 'like', '%' . $get['order_sn'] . '%'];
        }
        //客户姓名查询
        if (isset($get['name']) && $get['name'] != '') {
            $where[] = ['o.consignee', 'like', '%' . $get['name'] . '%'];
        }
        //客户的电话查询
        if (isset($get['mobile']) && $get['mobile'] != '') {
            $where[] = ['o.mobile', 'like', '%' . $get['mobile'] . '%'];
        }
        //商品名称
        if (isset($get['goods_name']) && $get['goods_name'] != '') {
            $where[] = ['o.goods_name', 'like', '%' . $get['goods_name'] . '%'];
        }
        
                //商品名称
        if (isset($get['goods_id']) && $get['goods_id'] != '') {
            $where[] = ['o.goods_id', '=', $get['goods_id']];
        }
                //付款方式
        if (isset($get['order_ysck']) && $get['order_ysck'] != '') {
            $where[] = ['o.order_ysck', '=', $get['order_ysck']];
        }
        //付款方式
        if (isset($get['channel_id']) && $get['channel_id'] != '') {
            $where[] = ['o.channel_id', '=', $get['channel_id']];
        }
       
 
        //付款方式
        if (isset($get['pay_way']) && $get['pay_way'] != '') {
            $where[] = ['o.pay_way', '=', $get['pay_way']];
        }
        //付款方式
        if (isset($get['admin_id']) && $get['admin_id'] != '') {
            $where[] = ['o.admin_id', '=', $get['admin_id']];
        }



        //配送方式
        if (isset($get['delivery_type']) && $get['delivery_type'] != '') {
            $where[] = ['o.delivery_type', '=', $get['delivery_type']];
        }

        //订单类型
        if (isset($get['order_type']) && $get['order_type'] != '') {
            $where[] = ['o.admin_id', '=', NULL];
        }

        //订单来源
        if (isset($get['order_source']) && $get['order_source'] != '') {
            $where[] = ['o.order_source', '=', $get['order_source']];
        }

        //下单时间
        if (isset($get['start_time']) && $get['start_time'] != '') {
            $where[] = ['o.create_time', '>=', strtotime($get['start_time'])];
        }
        if (isset($get['end_time']) && $get['end_time'] != '') {
            $where[] = ['o.create_time', '<=', strtotime($get['end_time'])];
        }
        return $where;
    }
    
    
     /**
     * Notes: 日式保洁订单
     * @param $get
     * @author 段誉(2021/2/1 10:12)
     * @return array
     */
    public static function cleaning($get)
    {
        $order = new Order();
        $where = self::getListsCondition($get);
        $field = 'o.*,order_status as order_status_text,pay_way as pay_way_text';
        $brand = Db::name('goods_brand')->where(['del'=>0])->column('name','id');       //订单类型
        $admin=Db::name('admin')->column('name','id');
        
        
        $count = $order
            ->alias('o')
            ->join('goods g', 'o.goods_id = g.id')
            ->where('g.brand_id', 1)
            ->where($where)
            ->count();
            
        $lists = $order
        ->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();
       $channel = Db::name('orderchannel')->column('name','id');
       foreach ($lists as &$item){
            if(isset($channel[$item['channel_id']])){
                $item['channel'] = $channel[$item['channel_id']];
            }
            if(isset($brand[$item['type_id']])){
                $item['brand'] = $brand[$item['type_id']];
            }
           if(isset($admin[$item['admin_id']])){
                $item['admin_id'] = $admin[$item['admin_id']];
            }
            //获取订单的商品
            $goods=GoodsLogic::goodsinfo($item['goods_id']);
            if($goods){
                $item['goods_name']=$goods['name'];
                $item['goods_image']=UrlServer::getFileUrl($goods['image']);
                $item['code']=$goods['code'];
            }else{
                $item['goods_name']='';
                $item['goods_image']='';
                $item['code']=''; 
            }  

            $gord_id=Db::name('collection')->where('id',$item['gord_id'])->find();
            if($gord_id){
                  $item['gord_name']= $gord_id['cqname'];
            }else{
                  $item['gord_name']='-';
            }
        }
        
        return ['count' => $count, 'lists' => $lists];
    }

     /**
     * Notes: 收纳整理
     * @param $get
     * @author 段誉(2021/2/1 10:12)
     * @return array
     */
    public static function storage($get)
    {
        $order = new Order();
        $where = self::getListsCondition($get);
        $field = 'o.*,order_status as order_status_text,pay_way as pay_way_text';
        $brand = Db::name('goods_brand')->where(['del'=>0])->column('name','id');       //订单类型
        $admin=Db::name('admin')->column('name','id');
        
        
        $count = $order
            ->alias('o')
            ->join('goods g', 'o.goods_id = g.id')
            ->where('g.brand_id', 2)
            ->where($where)
            ->count();
            
        $lists = $order
        ->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();
       $channel = Db::name('orderchannel')->column('name','id');
       foreach ($lists as &$item){
            if(isset($channel[$item['channel_id']])){
                $item['channel'] = $channel[$item['channel_id']];
            }
            if(isset($brand[$item['type_id']])){
                $item['brand'] = $brand[$item['type_id']];
            }
           if(isset($admin[$item['admin_id']])){
                $item['admin_id'] = $admin[$item['admin_id']];
            }
            //获取订单的商品
            $goods=GoodsLogic::goodsinfo($item['goods_id']);
            if($goods){
                $item['goods_name']=$goods['name'];
                $item['goods_image']=UrlServer::getFileUrl($goods['image']);
                $item['code']=$goods['code'];
            }else{
                $item['goods_name']='';
                $item['goods_image']='';
                $item['code']=''; 
            }  

            $gord_id=Db::name('collection')->where('id',$item['gord_id'])->find();
            if($gord_id){
                  $item['gord_name']= $gord_id['cqname'];
            }else{
                  $item['gord_name']='-';
            }
        }
        
        return ['count' => $count, 'lists' => $lists];
    }
     /**
     * Notes: 深度清洗
     * @param $get
     * @author 段誉(2021/2/1 10:12)
     * @return array
     */
    public static function depth($get)
    {
        $order = new Order();
        $where = self::getListsCondition($get);
        $field = 'o.*,order_status as order_status_text,pay_way as pay_way_text';
        $brand = Db::name('goods_brand')->where(['del'=>0])->column('name','id');       //订单类型
        $admin=Db::name('admin')->column('name','id');
        
        
        $count = $order
            ->alias('o')
            ->join('goods g', 'o.goods_id = g.id')
            ->where('g.brand_id', 4)
            ->where($where)
            ->count();
            
        $lists = $order
        ->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();
       $channel = Db::name('orderchannel')->column('name','id');
       foreach ($lists as &$item){
            if(isset($channel[$item['channel_id']])){
                $item['channel'] = $channel[$item['channel_id']];
            }
            if(isset($brand[$item['type_id']])){
                $item['brand'] = $brand[$item['type_id']];
            }
           if(isset($admin[$item['admin_id']])){
                $item['admin_id'] = $admin[$item['admin_id']];
            }
            //获取订单的商品
            $goods=GoodsLogic::goodsinfo($item['goods_id']);
            if($goods){
                $item['goods_name']=$goods['name'];
                $item['goods_image']=UrlServer::getFileUrl($goods['image']);
                $item['code']=$goods['code'];
            }else{
                $item['goods_name']='';
                $item['goods_image']='';
                $item['code']=''; 
            }  

            $gord_id=Db::name('collection')->where('id',$item['gord_id'])->find();
            if($gord_id){
                  $item['gord_name']= $gord_id['cqname'];
            }else{
                  $item['gord_name']='-';
            }
        }
        
        return ['count' => $count, 'lists' => $lists];
    }

   /**
     * Notes: 宠物保洁
     * @param $get
     * @author 段誉(2021/2/1 10:12)
     * @return array
     */
    public static function pet($get)
    {
        $order = new Order();
        $where = self::getListsCondition($get);
        $field = 'o.*,order_status as order_status_text,pay_way as pay_way_text';
        $brand = Db::name('goods_brand')->where(['del'=>0])->column('name','id');       //订单类型
        $admin=Db::name('admin')->column('name','id');
        
        
        $count = $order
            ->alias('o')
            ->join('goods g', 'o.goods_id = g.id')
            ->where('g.brand_id', 5)
            ->where($where)
            ->count();
            
        $lists = $order
        ->alias('o')
        ->join('goods g', 'o.goods_id = g.id')
        ->where($where)
        ->where('g.brand_id', 5)
         ->field('o.*')
        ->page($get['page'], $get['limit'])
        ->order('o.id desc')
        ->select();
       $channel = Db::name('orderchannel')->column('name','id');
       foreach ($lists as &$item){
            if(isset($channel[$item['channel_id']])){
                $item['channel'] = $channel[$item['channel_id']];
            }
            if(isset($brand[$item['type_id']])){
                $item['brand'] = $brand[$item['type_id']];
            }
           if(isset($admin[$item['admin_id']])){
                $item['admin_id'] = $admin[$item['admin_id']];
            }
            //获取订单的商品
            $goods=GoodsLogic::goodsinfo($item['goods_id']);
            if($goods){
                $item['goods_name']=$goods['name'];
                $item['goods_image']=UrlServer::getFileUrl($goods['image']);
                $item['code']=$goods['code'];
            }else{
                $item['goods_name']='';
                $item['goods_image']='';
                $item['code']=''; 
            }  

            $gord_id=Db::name('collection')->where('id',$item['gord_id'])->find();
            if($gord_id){
                  $item['gord_name']= $gord_id['cqname'];
            }else{
                  $item['gord_name']='-';
            }
        }
        
        return ['count' => $count, 'lists' => $lists];
    }
    
       /**
     * Notes: 宠物保洁
     * @param $get
     * @author 段誉(2021/2/1 10:12)
     * @return array
     */
    public static function cooking($get)
    {
        $order = new Order();
        $where = self::getListsCondition($get);
        $field = 'o.*,order_status as order_status_text,pay_way as pay_way_text';
        $brand = Db::name('goods_brand')->where(['del'=>0])->column('name','id');       //订单类型
        $admin=Db::name('admin')->column('name','id');
        
        
        $count = $order
            ->alias('o')
            ->join('goods g', 'o.goods_id = g.id')
            ->where('g.brand_id', 3)
            ->where($where)
            ->count();
            
        $lists = $order
        ->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();
       $channel = Db::name('orderchannel')->column('name','id');
       foreach ($lists as &$item){
            if(isset($channel[$item['channel_id']])){
                $item['channel'] = $channel[$item['channel_id']];
            }
            if(isset($brand[$item['type_id']])){
                $item['brand'] = $brand[$item['type_id']];
            }
           if(isset($admin[$item['admin_id']])){
                $item['admin_id'] = $admin[$item['admin_id']];
            }
            //获取订单的商品
            $goods=GoodsLogic::goodsinfo($item['goods_id']);
            if($goods){
                $item['goods_name']=$goods['name'];
                $item['goods_image']=UrlServer::getFileUrl($goods['image']);
                $item['code']=$goods['code'];
            }else{
                $item['goods_name']='';
                $item['goods_image']='';
                $item['code']=''; 
            }  

            $gord_id=Db::name('collection')->where('id',$item['gord_id'])->find();
            if($gord_id){
                  $item['gord_name']= $gord_id['cqname'];
            }else{
                  $item['gord_name']='-';
            }
        }
        
        return ['count' => $count, 'lists' => $lists];
    }
         /**
     * Notes: 粗开荒保洁
     * @param $get
     * @author 段誉(2021/2/1 10:12)
     * @return array
     */
    public static function thick($get)
    {
        $order = new Order();
        $where = self::getListsCondition($get);
        $field = 'o.*,order_status as order_status_text,pay_way as pay_way_text';
        $brand = Db::name('goods_brand')->where(['del'=>0])->column('name','id');       //订单类型
        $admin=Db::name('admin')->column('name','id');
        
        
        $count = $order
            ->alias('o')
            ->join('goods g', 'o.goods_id = g.id')
            ->where('g.brand_id', 6)
            ->where($where)
            ->count();
            
        $lists = $order
        ->alias('o')
        ->join('goods g', 'o.goods_id = g.id')
        ->where($where)
        ->where('g.brand_id', 6)
         ->field('o.*')
        ->page($get['page'], $get['limit'])
        ->order('o.id desc')
        ->select();
       $channel = Db::name('orderchannel')->column('name','id');
       foreach ($lists as &$item){
            if(isset($channel[$item['channel_id']])){
                $item['channel'] = $channel[$item['channel_id']];
            }
            if(isset($brand[$item['type_id']])){
                $item['brand'] = $brand[$item['type_id']];
            }
           if(isset($admin[$item['admin_id']])){
                $item['admin_id'] = $admin[$item['admin_id']];
            }
            //获取订单的商品
            $goods=GoodsLogic::goodsinfo($item['goods_id']);
            if($goods){
                $item['goods_name']=$goods['name'];
                $item['goods_image']=UrlServer::getFileUrl($goods['image']);
                $item['code']=$goods['code'];
            }else{
                $item['goods_name']='';
                $item['goods_image']='';
                $item['code']=''; 
            }  

            $gord_id=Db::name('collection')->where('id',$item['gord_id'])->find();
            if($gord_id){
                  $item['gord_name']= $gord_id['cqname'];
            }else{
                  $item['gord_name']='-';
            }
        }
        
        return ['count' => $count, 'lists' => $lists];
    }  
    /**
     * Notes: 细开荒保洁
     * @param $get
     * @author 段誉(2021/2/1 10:12)
     * @return array
     */
    public static function fine($get)
    {
        $order = new Order();
        $where = self::getListsCondition($get);
        $field = 'o.*,order_status as order_status_text,pay_way as pay_way_text';
        $brand = Db::name('goods_brand')->where(['del'=>0])->column('name','id');       //订单类型
        $admin=Db::name('admin')->column('name','id');
        
        
        $count = $order
            ->alias('o')
            ->join('goods g', 'o.goods_id = g.id')
            ->where('g.brand_id', 7)
            ->where($where)
            ->count();
            
        $lists = $order
        ->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();
       $channel = Db::name('orderchannel')->column('name','id');
       foreach ($lists as &$item){
            if(isset($channel[$item['channel_id']])){
                $item['channel'] = $channel[$item['channel_id']];
            }
            if(isset($brand[$item['type_id']])){
                $item['brand'] = $brand[$item['type_id']];
            }
           if(isset($admin[$item['admin_id']])){
                $item['admin_id'] = $admin[$item['admin_id']];
            }
            //获取订单的商品
            $goods=GoodsLogic::goodsinfo($item['goods_id']);
            if($goods){
                $item['goods_name']=$goods['name'];
                $item['goods_image']=UrlServer::getFileUrl($goods['image']);
                $item['code']=$goods['code'];
            }else{
                $item['goods_name']='';
                $item['goods_image']='';
                $item['code']=''; 
            }  

            $gord_id=Db::name('collection')->where('id',$item['gord_id'])->find();
            if($gord_id){
                  $item['gord_name']= $gord_id['cqname'];
            }else{
                  $item['gord_name']='-';
            }
        }
        
        return ['count' => $count, 'lists' => $lists];
    }  
    /**
     * Notes: 搬家货运
     * @param $get
     * @author 段誉(2021/2/1 10:12)
     * @return array
     */
    public static function move($get)
    {
        $order = new Order();
        $where = self::getListsCondition($get);
        $field = 'o.*,order_status as order_status_text,pay_way as pay_way_text';
        $brand = Db::name('goods_brand')->where(['del'=>0])->column('name','id');       //订单类型
        $admin=Db::name('admin')->column('name','id');
        
        
        $count = $order
            ->alias('o')
            ->join('goods g', 'o.goods_id = g.id')
            ->where('g.brand_id', 8)
            ->where($where)
            ->count();
            
        $lists = $order
        ->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();
       $channel = Db::name('orderchannel')->column('name','id');
       foreach ($lists as &$item){
            if(isset($channel[$item['channel_id']])){
                $item['channel'] = $channel[$item['channel_id']];
            }
            if(isset($brand[$item['type_id']])){
                $item['brand'] = $brand[$item['type_id']];
            }
           if(isset($admin[$item['admin_id']])){
                $item['admin_id'] = $admin[$item['admin_id']];
            }
            //获取订单的商品
            $goods=GoodsLogic::goodsinfo($item['goods_id']);
            if($goods){
                $item['goods_name']=$goods['name'];
                $item['goods_image']=UrlServer::getFileUrl($goods['image']);
                $item['code']=$goods['code'];
            }else{
                $item['goods_name']='';
                $item['goods_image']='';
                $item['code']=''; 
            }  

            $gord_id=Db::name('collection')->where('id',$item['gord_id'])->find();
            if($gord_id){
                  $item['gord_name']= $gord_id['cqname'];
            }else{
                  $item['gord_name']='-';
            }
        }
        
        return ['count' => $count, 'lists' => $lists];
    }  
        /**
     * Notes: 搬家货运
     * @param $get
     * @author 段誉(2021/2/1 10:12)
     * @return array
     */
    public static function detection($get)
    {
        $order = new Order();
        $where = self::getListsCondition($get);
        $field = 'o.*,order_status as order_status_text,pay_way as pay_way_text';
        $brand = Db::name('goods_brand')->where(['del'=>0])->column('name','id');       //订单类型
        $admin=Db::name('admin')->column('name','id');
        
        
        $count = $order
            ->alias('o')
            ->join('goods g', 'o.goods_id = g.id')
            ->where('g.brand_id', 9)
            ->where($where)
            ->count();
            
        $lists = $order
        ->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();
       $channel = Db::name('orderchannel')->column('name','id');
       foreach ($lists as &$item){
            if(isset($channel[$item['channel_id']])){
                $item['channel'] = $channel[$item['channel_id']];
            }
            if(isset($brand[$item['type_id']])){
                $item['brand'] = $brand[$item['type_id']];
            }
           if(isset($admin[$item['admin_id']])){
                $item['admin_id'] = $admin[$item['admin_id']];
            }
            //获取订单的商品
            $goods=GoodsLogic::goodsinfo($item['goods_id']);
            if($goods){
                $item['goods_name']=$goods['name'];
                $item['goods_image']=UrlServer::getFileUrl($goods['image']);
                $item['code']=$goods['code'];
            }else{
                $item['goods_name']='';
                $item['goods_image']='';
                $item['code']=''; 
            }  

            $gord_id=Db::name('collection')->where('id',$item['gord_id'])->find();
            if($gord_id){
                  $item['gord_name']= $gord_id['cqname'];
            }else{
                  $item['gord_name']='-';
            }
        }
        return ['count' => $count, 'lists' => $lists];
    }  
    
    /**
     * Notes: 空气治理
     * @param $get
     * @author 段誉(2021/2/1 10:12)
     * @return array
     */
    public static function governance($get)
    {
        $order = new Order();
        $where = self::getListsCondition($get);
        $field = 'o.*,order_status as order_status_text,pay_way as pay_way_text';
        $brand = Db::name('goods_brand')->where(['del'=>0])->column('name','id');       //订单类型
        $admin=Db::name('admin')->column('name','id');
        
        
        $count = $order
            ->alias('o')
            ->join('goods g', 'o.goods_id = g.id')
            ->where('g.brand_id', 10)
            ->where($where)
            ->count();
            
        $lists = $order
        ->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();
       $channel = Db::name('orderchannel')->column('name','id');
       foreach ($lists as &$item){
            if(isset($channel[$item['channel_id']])){
                $item['channel'] = $channel[$item['channel_id']];
            }
            if(isset($brand[$item['type_id']])){
                $item['brand'] = $brand[$item['type_id']];
            }
           if(isset($admin[$item['admin_id']])){
                $item['admin_id'] = $admin[$item['admin_id']];
            }
            //获取订单的商品
            $goods=GoodsLogic::goodsinfo($item['goods_id']);
            if($goods){
                $item['goods_name']=$goods['name'];
                $item['goods_image']=UrlServer::getFileUrl($goods['image']);
                $item['code']=$goods['code'];
            }else{
                $item['goods_name']='';
                $item['goods_image']='';
                $item['code']=''; 
            }  

            $gord_id=Db::name('collection')->where('id',$item['gord_id'])->find();
            if($gord_id){
                  $item['gord_name']= $gord_id['cqname'];
            }else{
                  $item['gord_name']='-';
            }
        }
        return ['count' => $count, 'lists' => $lists];
    }  
    
        /**
     * Notes: 空气治理
     * @param $get
     * @author 段誉(2021/2/1 10:12)
     * @return array
     */
    public static function wash($get)
    {
        $order = new Order();
        $where = self::getListsCondition($get);
        $field = 'o.*,order_status as order_status_text,pay_way as pay_way_text';
        $brand = Db::name('goods_brand')->where(['del'=>0])->column('name','id');       //订单类型
        $admin=Db::name('admin')->column('name','id');
        
        
        $count = $order
            ->alias('o')
            ->join('goods g', 'o.goods_id = g.id')
            ->where('g.brand_id', 11)
            ->where($where)
            ->count();
            
        $lists = $order
        ->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();
       $channel = Db::name('orderchannel')->column('name','id');
       foreach ($lists as &$item){
            if(isset($channel[$item['channel_id']])){
                $item['channel'] = $channel[$item['channel_id']];
            }
            if(isset($brand[$item['type_id']])){
                $item['brand'] = $brand[$item['type_id']];
            }
           if(isset($admin[$item['admin_id']])){
                $item['admin_id'] = $admin[$item['admin_id']];
            }
            //获取订单的商品
            $goods=GoodsLogic::goodsinfo($item['goods_id']);
            if($goods){
                $item['goods_name']=$goods['name'];
                $item['goods_image']=UrlServer::getFileUrl($goods['image']);
                $item['code']=$goods['code'];
            }else{
                $item['goods_name']='';
                $item['goods_image']='';
                $item['code']=''; 
            }  

            $gord_id=Db::name('collection')->where('id',$item['gord_id'])->find();
            if($gord_id){
                  $item['gord_name']= $gord_id['cqname'];
            }else{
                  $item['gord_name']='-';
            }
        }
        return ['count' => $count, 'lists' => $lists];
    }  
    
    /**
     * Notes: 清洗
     * @param $get
     * @author 段誉(2021/2/1 10:12)
     * @return array
     */
    public static function linen($get)
    {
        $order = new Order();
        $where = self::getListsCondition($get);
        $field = 'o.*,order_status as order_status_text,pay_way as pay_way_text';
        $brand = Db::name('goods_brand')->where(['del'=>0])->column('name','id');       //订单类型
        $admin=Db::name('admin')->column('name','id');
        
        
        $count = $order
            ->alias('o')
            ->join('goods g', 'o.goods_id = g.id')
            ->where('g.brand_id', 13)
            ->where($where)
            ->count();
            
        $lists = $order
        ->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();
       $channel = Db::name('orderchannel')->column('name','id');
       foreach ($lists as &$item){
            if(isset($channel[$item['channel_id']])){
                $item['channel'] = $channel[$item['channel_id']];
            }
            if(isset($brand[$item['type_id']])){
                $item['brand'] = $brand[$item['type_id']];
            }
           if(isset($admin[$item['admin_id']])){
                $item['admin_id'] = $admin[$item['admin_id']];
            }
            //获取订单的商品
            $goods=GoodsLogic::goodsinfo($item['goods_id']);
            if($goods){
                $item['goods_name']=$goods['name'];
                $item['goods_image']=UrlServer::getFileUrl($goods['image']);
                $item['code']=$goods['code'];
            }else{
                $item['goods_name']='';
                $item['goods_image']='';
                $item['code']=''; 
            }  

            $gord_id=Db::name('collection')->where('id',$item['gord_id'])->find();
            if($gord_id){
                  $item['gord_name']= $gord_id['cqname'];
            }else{
                  $item['gord_name']='-';
            }
        }
        return ['count' => $count, 'lists' => $lists];
    }  
        /**
     * Notes: 宠物保洁订单
     * @param $get
     * @author 段誉(2021/2/1 10:12)
     * @return array
     */
    public static function pets($get)
    {
        $order = new Order();
        $where = self::getListsCondition($get);
        $field = 'o.*,order_status as order_status_text,pay_way as pay_way_text';
        $brand = Db::name('goods_brand')->where(['del'=>0])->column('name','id');       //订单类型
        $admin=Db::name('admin')->column('name','id');
        
        
        $count = $order
            ->alias('o')
            ->join('goods g', 'o.goods_id = g.id')
            ->where('g.brand_id', 14)
            ->where($where)
            ->count();
            
        $lists = $order
        ->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();
       $channel = Db::name('orderchannel')->column('name','id');
       foreach ($lists as &$item){
            if(isset($channel[$item['channel_id']])){
                $item['channel'] = $channel[$item['channel_id']];
            }
            if(isset($brand[$item['type_id']])){
                $item['brand'] = $brand[$item['type_id']];
            }
           if(isset($admin[$item['admin_id']])){
                $item['admin_id'] = $admin[$item['admin_id']];
            }
            //获取订单的商品
            $goods=GoodsLogic::goodsinfo($item['goods_id']);
            if($goods){
                $item['goods_name']=$goods['name'];
                $item['goods_image']=UrlServer::getFileUrl($goods['image']);
                $item['code']=$goods['code'];
            }else{
                $item['goods_name']='';
                $item['goods_image']='';
                $item['code']=''; 
            }  

            $gord_id=Db::name('collection')->where('id',$item['gord_id'])->find();
            if($gord_id){
                  $item['gord_name']= $gord_id['cqname'];
            }else{
                  $item['gord_name']='-';
            }
        }
        return ['count' => $count, 'lists' => $lists];
    }  
}