排序
This commit is contained in:
@@ -47,6 +47,18 @@ class ProductController extends BaseMiniController
|
||||
});
|
||||
}
|
||||
|
||||
// 先按分类树展示顺序(与小程序分类栏一致;不在启用分类树中的商品排最后),再按商品排序
|
||||
$categoryIds = ProductCategoryModel::getTreeOrderedIds(true);
|
||||
if ($categoryIds !== []) {
|
||||
$cases = [];
|
||||
foreach ($categoryIds as $position => $categoryId) {
|
||||
$cases[] = "WHEN {$categoryId} THEN {$position}";
|
||||
}
|
||||
$query->orderByRaw(
|
||||
'CASE category_id ' . implode(' ', $cases) . ' ELSE ' . count($categoryIds) . ' END'
|
||||
);
|
||||
}
|
||||
|
||||
$pageSize = (int) $request->input('pageSize', 10);
|
||||
$paginator = $query->orderBy('sort', 'desc')
|
||||
->orderBy('id')
|
||||
|
||||
Reference in New Issue
Block a user