query(); foreach (['order_no', 'user_code', 'operator', 'remark'] as $field) { $value = trim((string) ($where['LIKE_' . $field] ?? '')); if ($value === '') { continue; } $query->where($field, 'like', '%' . $value . '%'); } if (($where['process_id'] ?? '') !== '') { $query->where('process_id', $where['process_id']); } if (($where['step_id'] ?? '') !== '') { $query->where('step_id', $where['step_id']); } if (($where['status_id'] ?? '') !== '') { $query->where('status_id', $where['status_id']); } if (($where['scan_result'] ?? '') !== '') { $query->where('scan_result', $where['scan_result']); } if (!empty($where['scan_time_range']) && is_array($where['scan_time_range']) && count($where['scan_time_range']) === 2) { $query->whereBetween('scan_time', [strtotime((string) $where['scan_time_range'][0]), strtotime((string) $where['scan_time_range'][1])]); } return $query; } }