|
@@ -42,8 +42,20 @@ class ProductController extends Controller
|
|
|
->where('dist_id', getDistId())
|
|
|
->firstOrFail();
|
|
|
|
|
|
+ if (!$category) {
|
|
|
+ abort('404');
|
|
|
+ }
|
|
|
+ $categoryIds = [$category->id];
|
|
|
+ if ($category) {
|
|
|
+ //找下一级分类
|
|
|
+ $subCategories = DistProductCategory::where('parent_id', $category->id)->get();
|
|
|
+ foreach ($subCategories as $subCategory) {
|
|
|
+ $categoryIds[] = $subCategory->id;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
// 获取分类下的所有产品,排序,然后进行分页
|
|
|
- $products = DistProduct::where('category_id', $category->id)
|
|
|
+ $products = DistProduct::whereIn('category_id', $categoryIds)
|
|
|
->where('dist_id', getDistId())
|
|
|
->where('enabled', 1)
|
|
|
->where('status', 2)
|