This commit is contained in:
liu
2026-09-04 22:10:28 +08:00
parent cf1d3a6229
commit 1e25459676
4 changed files with 65 additions and 1 deletions
@@ -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')