order('weigh asc,id asc')->select(); $tree->init(collection($list)->toArray(), 'pid'); return self::transformTree($tree->getTreeArray(0)); } public static function getOptions($type = 'goods', $pid = 0) { $list = self::$Model::where('type', $type)->where('status', 'normal')->order('weigh asc,id asc')->column('name', 'id'); return $list; } /** * 首页轮播:分类类型 banner,仅正常状态,按权重从高到低 * @return array */ public static function getBannerList() { $list = self::getList(['type' => 'banner', 'status' => 'normal'], 0, 'weigh desc,id desc'); $rows = []; foreach ($list as $item) { $image = (string)($item['image'] ?? ''); if ($image === '') { continue; } $rows[] = [ 'name' => (string)($item['name'] ?? ''), 'image' => cdnurl($image, true), 'description' => (string)($item['description'] ?? ''), ]; } return $rows; } public static function transformTree($data) { return array_map(function ($item) { $transformedItem = [ 'groupId' => (string)$item['id'], 'thumbnail' => $item['image'] ?: 'https://cdn-we-retail.ym.tencent.com/miniapp/category/category-default.png', 'name' => $item['name'] ]; if (isset($item['childlist']) && is_array($item['childlist']) && count($item['childlist']) > 0) { $transformedItem['children'] = self::transformTree($item['childlist']); } return $transformedItem; }, $data); } }