chore: 忽略 tools/ 目录并从版本库移除历史脚本
这个提交包含在:
@@ -83,6 +83,7 @@ class Home extends V1
|
||||
'color' => (string)$row['color'],
|
||||
'kind' => isset($row['kind']) && $row['kind'] === 'farm' ? 'farm' : 'general',
|
||||
'count' => (int)$row['post_count'],
|
||||
'isHome' => isset($row['is_home']) ? (int)$row['is_home'] : 0,
|
||||
];
|
||||
|
||||
if ($pid === 0) {
|
||||
@@ -115,6 +116,67 @@ class Home extends V1
|
||||
$this->ok($list);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取首页金刚区推荐二级分类列表
|
||||
* GET /api/v1/home/nav-categories → [{id,pid,name,iconKey,icon,image,color,isHome}]
|
||||
* 规则:优先取后台设置 is_home=1 且 enabled=1 的二级分类,不足8个时智能补充热门果蔬二级分类,输出精准8宫格
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function navCategories()
|
||||
{
|
||||
// 1. 优先获取后台标记为推荐至首页金刚区的二级分类 (is_home=1, pid>0)
|
||||
$homeRows = \think\Db::name('fc_category')
|
||||
->where('enabled', 1)
|
||||
->where('pid', '>', 0)
|
||||
->where('is_home', 1)
|
||||
->order('sort asc, id asc')
|
||||
->limit(8)
|
||||
->select();
|
||||
|
||||
$selectedIds = array_column($homeRows, 'id');
|
||||
$list = $homeRows;
|
||||
|
||||
// 2. 若配置不足8个,则从高频果蔬二级分类中自动补齐至8个
|
||||
if (count($list) < 8) {
|
||||
$needed = 8 - count($list);
|
||||
$query = \think\Db::name('fc_category')
|
||||
->where('enabled', 1)
|
||||
->where('pid', 'in', [1, 2]); // 优先从蔬菜(1)和水果(2)中补充
|
||||
if (!empty($selectedIds)) {
|
||||
$query->whereNotIn('id', $selectedIds);
|
||||
}
|
||||
$moreRows = $query->order('sort asc, post_count desc, id asc')
|
||||
->limit($needed)
|
||||
->select();
|
||||
$list = array_merge($list, $moreRows);
|
||||
}
|
||||
|
||||
$res = [];
|
||||
foreach ($list as $row) {
|
||||
$id = (int)$row['id'];
|
||||
$pid = (int)$row['pid'];
|
||||
$iconKey = (string)$row['icon_key'];
|
||||
$rawImage = isset($row['image']) ? (string)$row['image'] : '';
|
||||
$iconPath = $this->resolveCategoryIconPath($id, $iconKey, $rawImage);
|
||||
$imagePath = $rawImage !== '' ? $rawImage : $iconPath;
|
||||
|
||||
$res[] = [
|
||||
'id' => $id,
|
||||
'pid' => $pid,
|
||||
'name' => (string)$row['name'],
|
||||
'iconKey' => $iconKey,
|
||||
'icon' => $iconPath,
|
||||
'image' => $imagePath,
|
||||
'color' => (string)$row['color'],
|
||||
'kind' => isset($row['kind']) && $row['kind'] === 'farm' ? 'farm' : 'general',
|
||||
'isHome' => isset($row['is_home']) ? (int)$row['is_home'] : 0,
|
||||
];
|
||||
}
|
||||
|
||||
$this->ok($res);
|
||||
}
|
||||
|
||||
/**
|
||||
* H3 热门搜索
|
||||
* GET /api/v1/home/search/hot → [string]
|
||||
|
||||
在新工单中引用
屏蔽一个用户