Browse Source

fix:新品

super-yimizi 1 month ago
parent
commit
d8ea0d2959
1 changed files with 10 additions and 0 deletions
  1. 10 0
      application/api/controller/Goods.php

+ 10 - 0
application/api/controller/Goods.php

@@ -136,6 +136,15 @@ class Goods extends Base
         $orderby   = $param['orderby'] ?? 'weigh';
         $orderway  = $param['orderway'] ?? 'desc';
 
+        // 映射字段 $orderby  weigh,sales,price,views,comments,created_at
+        $orderbyMap = [
+            'weigh' => 'weigh',
+            'sales' => 'sales',
+            'views' => 'views',
+            'comments' => 'comments',
+            'created_at' => 'createtime',
+        ];
+
         $query = GoodsModel::where(function ($query) use ($param) {
             $query->where('status',GoodsEnum::STATUS_ON_SALE);
             //关键词
@@ -185,6 +194,7 @@ class Goods extends Base
             }
         });
         if (!empty($orderby) && !empty($orderway)) {
+            $orderby = $orderbyMap[$orderby] ?? 'weigh';
             $query = $query->order("{$orderby} {$orderway}");
         }
         $list = $query->paginate($pageSize);