|
@@ -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);
|