field( "o.*,p.store_name as pro_title,p.image as pro_img,m.mobile,m.avatar, (select count(*) from table_order_info where o_id = o.id) as order_count, (select count(*) from table_order_info where o_id = o.id and status = 2) as send_count, (SELECT title from table_express where id = o.express_id) as exp_name, (SELECT name from table_warehouse where id = o.warehouse_id) as ck_name" ) ->alias("o") //->join('platform pf',"pf.id=o.platform_id") ->leftJoin('member m','m.uid=o.uid') ->leftJoin('product p',"p.id = o.pro_id") ->where('o.type',1); }else{ $model = $this ->field("o.*,p.store_name as pro_title,a.image as pro_img,m.mobile,m.avatar,f.name,f.mobile,f.address,a.suk") ->alias("o") ->leftJoin('orderInfo f',"f.o_id=o.id") ->leftJoin('member m','m.uid=o.uid') ->leftJoin('product p',"p.id = o.pro_id") ->leftJoin('product_attr_value a',"a.product_id = o.pro_id and a.unique = o.unique") ->where('o.type',0); } $data = $model->when(!empty($where),function ($query) use($where){ //用户 if(!empty($where['uid'])) { $query->where('o.uid',$where['uid']); } //搜索订单 if(!empty($where['order_id'])) { $query->whereLike('o.order_id',"%{$where['order_id']}%"); } //搜索平台 if(!empty($where['platform_id'])) { $query->whereLike('o.platform_id',$where['platform_id']); } //仓库 if(!empty($where['warehouse_id'])) { $query->whereLike('o.warehouse_id',$where['warehouse_id']); } //搜索备注信息 if(!empty($where['mono'])) { $query->whereLike('o.order_id',"%{$where['mono']}%"); } //查询日期 if(!empty($where['data']) && !empty($where['data'][0]) && !empty($where['data'][1])) { $query->whereTime('o.time','between',$where['data']); } //订单类型 if(is_numeric($where['orderType'])) { $query->where('o.status',$where['orderType']); } else { $query->where('o.status','>',0); } //timeType[今日,昨日,最近7天,最近30天] if(!empty($where['timeType'])) { if($where['timeType'] == 'day') { $query->whereDay('o.time'); } if($where['timeType'] == 'yesterday') { $query->whereDay('o.time','yesterday'); } if($where['timeType'] == 'last7') { $query->whereTime('o.time','-7 day'); } if($where['timeType'] == 'last30') { $query->whereTime('o.time','-30 day'); } } }) ->order($desc) ->paginate(['list_rows'=>$pageCount,'page'=>$page]) ->toArray(); //echo $this->getLastSql();exit; return [$data['total'],$data['data']]; } /** * 获取推送数据 * @param $page * @param array $where * @param int $pageCount * @param string $filed * @param string $desc * @return array */ public function getPushList($page,$where = [],$pageCount = 20,$filed = '*',$desc = 'id desc'){ $data = $this ->field( "o.*,p.store_name as pro_title,p.image as pro_img,m.mobile,m.avatar, (select count(*) from table_order_info where o_id = o.id) as order_count, (select count(*) from table_order_info where o_id = o.id and is_push = 1) as push_count, (SELECT title from table_express where id = o.express_id) as exp_name, (SELECT name from table_warehouse where id = o.warehouse_id) as ck_name" ) ->alias("o") //->join('platform pf',"pf.id=o.platform_id") ->join('member m','m.uid=o.uid') ->leftJoin('product p',"p.id = o.pro_id") ->when(!empty($where),function ($query) use($where){ //用户 if(!empty($where['uid'])) { $query->where('o.uid',$where['uid']); } //搜索订单 if(!empty($where['order_id'])) { $query->whereLike('o.order_id',"%{$where['order_id']}%"); } //搜索平台 if(!empty($where['platform_id'])) { $query->whereLike('o.platform_id',$where['platform_id']); } //仓库 if(!empty($where['warehouse_id'])) { $query->whereLike('o.warehouse_id',$where['warehouse_id']); } //查询日期 if(!empty($where['data']) && !empty($where['data'][0]) && !empty($where['data'][1])) { $query->whereTime('o.time','between',$where['data']); } //订单类型 if(is_numeric($where['orderType'])) { $query->where('o.status',$where['orderType']); } else { $query->where('o.status','>',0); } }) ->order($desc) ->paginate(['list_rows'=>$pageCount,'page'=>$page]) ->toArray(); //echo $this->getLastSql();exit; return [$data['total'],$data['data']]; } }