Эх сурвалжийг харах

[智价云] 移动端规格商品名称重复剔除更新

tangyuanwang 6 цаг өмнө
parent
commit
d16a7e6fea

+ 11 - 4
app/Http/Controllers/Api/WashConfig/LowPriceGoods.php

@@ -5,6 +5,7 @@ namespace App\Http\Controllers\Api\WashConfig;
 use App\Http\Controllers\Api\Api;
 use App\Http\Controllers\Api\Api;
 use App\Http\Requests\Manager\WashConfig\LowPriceGoods as Request;
 use App\Http\Requests\Manager\WashConfig\LowPriceGoods as Request;
 use App\Models\Manager\WashConfig\LowPriceGoods as LowPriceGoodsModel;
 use App\Models\Manager\WashConfig\LowPriceGoods as LowPriceGoodsModel;
+use Illuminate\Support\Facades\DB;
 
 
 
 
 /**
 /**
@@ -50,8 +51,11 @@ class LowPriceGoods extends Api
         $result = $LowPriceGoodsModel->query()
         $result = $LowPriceGoodsModel->query()
             ->where($map)
             ->where($map)
             ->orderByDesc('id')
             ->orderByDesc('id')
-            ->select(['id','product_name'])
-            ->distinct('product_name')
+            ->select([
+                DB::raw('MAX(id) as id'),  // 使用 MAX 聚合函数获取最新的 id
+                'product_name'
+            ])
+            ->groupBy('product_name')
             ->paginate($limit);
             ->paginate($limit);
         // 分配数据
         // 分配数据
         if (!$result)  return json_send(['code' => 'error', 'msg' => '暂无数据']);
         if (!$result)  return json_send(['code' => 'error', 'msg' => '暂无数据']);
@@ -94,8 +98,11 @@ class LowPriceGoods extends Api
         $result = $LowPriceGoodsModel->query()
         $result = $LowPriceGoodsModel->query()
             ->where($map)
             ->where($map)
             ->orderByDesc('id')
             ->orderByDesc('id')
-            ->select(['id','product_specs'])
-            ->distinct('product_specs')
+            ->select([
+                DB::raw('MAX(id) as id'),  // 使用 MAX 聚合函数获取最新的 id
+                'product_specs'
+            ])
+            ->groupBy('product_specs')
             ->paginate($limit);
             ->paginate($limit);
         // 分配数据
         // 分配数据
         if (!$result)  return json_send(['code' => 'error', 'msg' => '暂无数据']);
         if (!$result)  return json_send(['code' => 'error', 'msg' => '暂无数据']);