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();