From cc37b21349844a886013d4b99a6e13750cc1a0aa Mon Sep 17 00:00:00 2001 From: ztt <835303992@qq.com> Date: Sat, 16 Mar 2024 16:37:09 +0800 Subject: [PATCH] 1 --- addons/shopro/controller/Category.php | 20 +++++++++++++++++--- application/common.php | 4 ++++ 2 files changed, 21 insertions(+), 3 deletions(-) diff --git a/addons/shopro/controller/Category.php b/addons/shopro/controller/Category.php index 1509a0f..677d6e9 100755 --- a/addons/shopro/controller/Category.php +++ b/addons/shopro/controller/Category.php @@ -36,10 +36,24 @@ class Category extends Common */ public function goodsList() { $category = CategoryModel::where('parent_id', 0)->normal()->order('weigh', 'desc')->order('id', 'desc')->select(); - foreach ($category as &$item) { - $item['goods_list'] = Goods::where('category_ids', 'in', $item['id'])->show()->select(); + $category_ids = []; + foreach ($category as $item) { + $categories = CategoryModel::where('parent_id', $item['id'])->column('id'); + $category_ids = array_merge($category_ids, $categories); + } + $category = CategoryModel::where('id', 'in', $category_ids)->normal()->order('weigh', 'desc')->order('id', 'desc')->select(); + + foreach ($category as &$row) { + $row['image'] = formatImage($row['image']); + $row['goods_list'] = Goods::where('category_ids', 'in', $row['id'])->show()->select(); + foreach ($row['goods_list'] as $v) { + $v->image = formatImage($v->image); + $v->images = array_map('formatImage', $v->images); + } } - $this->success('商城分类', $category); } + + + } diff --git a/application/common.php b/application/common.php index 0259248..e1c5a84 100755 --- a/application/common.php +++ b/application/common.php @@ -560,3 +560,7 @@ EOT; return $icon; } } + + function formatImage($url) { + return request()->domain().$url; +}