ztt 10 months ago
parent 46b52e6ae5
commit cc37b21349
  1. 20
      addons/shopro/controller/Category.php
  2. 4
      application/common.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);
}
}

@ -560,3 +560,7 @@ EOT;
return $icon;
}
}
function formatImage($url) {
return request()->domain().$url;
}

Loading…
Cancel
Save