fix(server): 拆约推荐等级徽章三级(undefined)修复 — getMergedProfile 补选 level1/2/3 列 + memberLevelLabel 空值兜底;参与者排序改为组织者置顶、其余按 matchScore 降序、无分沉底
This commit is contained in:
@@ -586,7 +586,7 @@ function getUserWithCompanies(userId) {
|
||||
function memberLevelLabel(member) {
|
||||
const lvl = Number(member && member.level) || 1;
|
||||
const name = lvl === 4 ? '三级' : lvl === 3 ? '二级' : lvl === 2 ? '一级' : '学员';
|
||||
const no = lvl === 4 ? member.level3 : lvl === 3 ? member.level2 : lvl === 2 ? member.level1 : '';
|
||||
const no = lvl === 4 ? (member.level3 || '') : lvl === 3 ? (member.level2 || '') : lvl === 2 ? (member.level1 || '') : '';
|
||||
return lvl >= 2 ? `${name}(${no})`.replace(/\(\)$/, '') : name;
|
||||
}
|
||||
// 拆搭子推荐辅助:收集用户兴趣标签(会员 tags 优先,expertise 逐词补充;v8 单表直读本行)
|
||||
@@ -1838,7 +1838,7 @@ app.get('/tags/recommended', (req, res) => {
|
||||
function getMergedProfile(userId) {
|
||||
const user = db.prepare(`
|
||||
SELECT u.id, u.uid, u.nickname, u.avatar_url, u.position, u.industry, u.hometown, u.expertise,
|
||||
u.name AS member_name, u.city, u.branch, u.level, u.tags AS member_tags, u.description AS member_description,
|
||||
u.name AS member_name, u.city, u.branch, u.level, u.level1, u.level2, u.level3, u.tags AS member_tags, u.description AS member_description,
|
||||
(SELECT company_name FROM user_companies WHERE user_id = u.id ORDER BY sort_order LIMIT 1) as company
|
||||
FROM users u WHERE u.id = ? AND u.has_account = 1
|
||||
`).get(userId);
|
||||
@@ -1958,9 +1958,6 @@ app.get('/ai/recommendations/:activityId', async (req, res) => {
|
||||
`).all(activityId);
|
||||
const profiles = rows.map(r => getMergedProfile(r.user_id)).filter(Boolean);
|
||||
|
||||
// 组织者排最前
|
||||
profiles.sort((a, b) => (b.userId === activity.creator_id ? 1 : 0) - (a.userId === activity.creator_id ? 1 : 0));
|
||||
|
||||
const viewer = viewerId ? getMergedProfile(viewerId) : null;
|
||||
const viewerKnown = !!(viewer && profiles.some(p => p.userId === viewerId));
|
||||
const scored = profiles.map(p => {
|
||||
@@ -1981,6 +1978,15 @@ app.get('/ai/recommendations/:activityId', async (req, res) => {
|
||||
};
|
||||
});
|
||||
|
||||
// 排序:组织者置顶,其余按匹配度降序,无分数(自己/未登录)沉底
|
||||
scored.sort((a, b) => {
|
||||
const aOrg = a.isOrganizer ? 1 : 0, bOrg = b.isOrganizer ? 1 : 0;
|
||||
if (aOrg !== bOrg) return bOrg - aOrg;
|
||||
const aScore = a.matchScore == null ? -1 : a.matchScore;
|
||||
const bScore = b.matchScore == null ? -1 : b.matchScore;
|
||||
return bScore - aScore;
|
||||
});
|
||||
|
||||
// 总体建议
|
||||
let suggestions;
|
||||
const others = scored.filter(p => !p.isSelf && p.matchScore !== null).sort((a, b) => b.matchScore - a.matchScore);
|
||||
|
||||
Reference in New Issue
Block a user