cqp 4 nedēļas atpakaļ
vecāks
revīzija
684f28cb18
1 mainītis faili ar 31 papildinājumiem un 9 dzēšanām
  1. 31 9
      app/Service/ProductService.php

+ 31 - 9
app/Service/ProductService.php

@@ -620,9 +620,11 @@ class ProductService extends Service
             // 清理用户输入,去除前后空白并替换多个连续空格为单个空格
             $cleanTitle = preg_replace('/\s+/', ' ', trim($data['title_t']));
             // 构建查询时使用 TRIM 和 REPLACE 来清理数据库字段中的空白字符
-            $model->whereRaw("TRIM(REPLACE(title, ' ', '')) LIKE ?", ['%' . str_replace(' ', '', $cleanTitle) . '%'])
-                ->orWhere('code', 'LIKE', '%'.$data['title_t'].'%')
-                ->orWhere('size', 'LIKE', '%'.$data['title_t'].'%');
+            $model->where(function ($query) use ($cleanTitle, $data) {
+                $query->whereRaw("TRIM(REPLACE(title, ' ', '')) LIKE ?", ['%' . str_replace(' ', '', $cleanTitle) . '%'])
+                    ->orWhere('code', 'LIKE', '%' . $data['title_t'] . '%')
+                    ->orWhere('size', 'LIKE', '%' . $data['title_t'] . '%');
+            });
         }
         if(! empty($data['title'])) {
             // 清理用户输入,去除前后空白并替换多个连续空格为单个空格
@@ -694,9 +696,11 @@ class ProductService extends Service
             // 清理用户输入,去除前后空白并替换多个连续空格为单个空格
             $cleanTitle = preg_replace('/\s+/', ' ', trim($data['title_t']));
             // 构建查询时使用 TRIM 和 REPLACE 来清理数据库字段中的空白字符
-            $model->whereRaw("TRIM(REPLACE(title, ' ', '')) LIKE ?", ['%' . str_replace(' ', '', $cleanTitle) . '%'])
-                ->orWhere('code', 'LIKE', '%'.$data['title_t'].'%')
-                ->orWhere('size', 'LIKE', '%'.$data['title_t'].'%');
+            $model->where(function ($query) use ($cleanTitle, $data) {
+                $query->whereRaw("TRIM(REPLACE(title, ' ', '')) LIKE ?", ['%' . str_replace(' ', '', $cleanTitle) . '%'])
+                    ->orWhere('code', 'LIKE', '%' . $data['title_t'] . '%')
+                    ->orWhere('size', 'LIKE', '%' . $data['title_t'] . '%');
+            });
         }
         if(! empty($data['title'])){
             // 清理用户输入,去除前后空白并替换多个连续空格为单个空格
@@ -1227,9 +1231,11 @@ class ProductService extends Service
             // 清理用户输入,去除前后空白并替换多个连续空格为单个空格
             $cleanTitle = preg_replace('/\s+/', ' ', trim($data['title_t']));
             // 构建查询时使用 TRIM 和 REPLACE 来清理数据库字段中的空白字符
-            $model->whereRaw("TRIM(REPLACE(title, ' ', '')) LIKE ?", ['%' . str_replace(' ', '', $cleanTitle) . '%'])
-                ->orWhere('code', 'LIKE', '%'.$data['title_t'].'%')
-                ->orWhere('size', 'LIKE', '%'.$data['title_t'].'%');
+            $model->where(function ($query) use ($cleanTitle, $data) {
+                $query->whereRaw("TRIM(REPLACE(title, ' ', '')) LIKE ?", ['%' . str_replace(' ', '', $cleanTitle) . '%'])
+                    ->orWhere('code', 'LIKE', '%' . $data['title_t'] . '%')
+                    ->orWhere('size', 'LIKE', '%' . $data['title_t'] . '%');
+            });
         }
         if(! empty($data['title'])){
             // 清理用户输入,去除前后空白并替换多个连续空格为单个空格
@@ -1309,8 +1315,10 @@ class ProductService extends Service
             $arr = array_flip($arr);
             if (isset($arr[112])) {
                 $data['data'][$key]['is_roll'] = true;
+                $is_roll = true;
             }else{
                 $data['data'][$key]['is_roll'] = false;
+                $is_roll = false;
             }
 
             $tmp = $img[$value['id']] ?? [];
@@ -1327,6 +1335,20 @@ class ProductService extends Service
             $title = $value['title'];
             if(! empty($item_code_map[$value['item_code']])) $title = $item_code_map[$value['item_code']];
             $data['data'][$key]['title'] = $title;
+
+            //通用名称
+            $common_title = $item_code_map[$value['item_code']] ?? "";
+            //is_roll false 展示title  true product_category_name
+            if($is_roll){
+                $category_tmp = $category[$value['product_category_id']] ?? [];
+                $category_title = $category_tmp['title'] ?? '';
+                if(! empty($common_title)) $category_title = $common_title;
+                $data['data'][$key]['product_category_name'] = $category_title;
+            }else{
+                $title = $value['title'];
+                if(! empty($common_title)) $title = $common_title;
+                $data['data'][$key]['title'] = $title;
+            }
         }
 
         return $data;