Tp5关联

 

        if(!empty($where['start'])){
            $where[] = [
                'equipment.createtime','>= TIME',$where['start']
            ];
            unset($where['start']);
        }
        //结束时间
        if(!empty($where['end'])){
            $where[] = [
                'equipment.createtime','<= TIME',$where['end']
            ];
            unset($where['end']);
        }
        //关键字
        $keywords = '';
        if(!empty($where['searchText'])){
            $keywords = $where['searchText'];
            unset($where['searchText']);
        }

        $query = EquipmentModel::where($where);
        $query->field('id,u_id,product_name,cover,model,brand,province,city,is_lease,weinintuijian,createtime,update_time');
        $query->withJoin(['owner'=>function($query){
            $query->withField('id,username,phone');
        }]);

        //关键字条件添加
        if(!empty($keywords)){
            $query ->where('u_id|brand|model|serial_number|owner.phone','like','%'.$keywords.'%');
        }

        $res_data = $query->paginate($size, false, ['page' => $page])->toArray();