|
@@ -597,7 +597,14 @@ class ProductService extends Service
|
|
|
->orderby('product_attribute', 'desc')
|
|
|
->orderby('id', 'desc');
|
|
|
|
|
|
- if(! empty($data['title'])) $model->where('title', 'LIKE', '%'.$data['title'].'%');
|
|
|
+ if(! empty($data['title'])) {
|
|
|
+ // 清理用户输入,去除前后空白并替换多个连续空格为单个空格
|
|
|
+ $cleanTitle = preg_replace('/\s+/', ' ', trim($data['title']));
|
|
|
+ // 构建查询时使用 TRIM 和 REPLACE 来清理数据库字段中的空白字符
|
|
|
+ $model->whereRaw("TRIM(REPLACE(title, ' ', '')) LIKE ?", ['%' . str_replace(' ', '', $cleanTitle) . '%']);
|
|
|
+
|
|
|
+// $model->where('title', 'LIKE', '%'.$data['title'].'%');
|
|
|
+ }
|
|
|
if(isset($data['state'])) $model->where('state', $data['state']);
|
|
|
if(isset($data['is_use'])) $model->where('is_use', $data['is_use']);
|
|
|
if(isset($data['product_attribute'])) $model->where('product_attribute', $data['product_attribute']);
|
|
@@ -648,7 +655,13 @@ class ProductService extends Service
|
|
|
->orWhere('code', 'LIKE', '%'.$data['title_t'].'%')
|
|
|
->orWhere('size', 'LIKE', '%'.$data['title_t'].'%');
|
|
|
}
|
|
|
- if(! empty($data['title'])) $model->where('title', 'LIKE', '%'.$data['title'].'%');
|
|
|
+ if(! empty($data['title'])){
|
|
|
+ // 清理用户输入,去除前后空白并替换多个连续空格为单个空格
|
|
|
+ $cleanTitle = preg_replace('/\s+/', ' ', trim($data['title']));
|
|
|
+ // 构建查询时使用 TRIM 和 REPLACE 来清理数据库字段中的空白字符
|
|
|
+ $model->whereRaw("TRIM(REPLACE(title, ' ', '')) LIKE ?", ['%' . str_replace(' ', '', $cleanTitle) . '%']);
|
|
|
+// $model->where('title', 'LIKE', '%'.$data['title'].'%');
|
|
|
+ }
|
|
|
if(isset($data['state'])) $model->where('state', $data['state']);
|
|
|
if(isset($data['product_attribute'])) $model->where('product_attribute', $data['product_attribute']);
|
|
|
if(! empty($data['product_category_id'])) $model->where('product_category_id', $data['product_category_id']);
|