diff --git a/apps/character/ProfileDetail.js b/apps/character/ProfileDetail.js index e691bd67..5850d416 100644 --- a/apps/character/ProfileDetail.js +++ b/apps/character/ProfileDetail.js @@ -1,7 +1,7 @@ import lodash from 'lodash' import { autoRefresh } from './ProfileCommon.js' import { Common, Format, Profile } from '../../components/index.js' -import { MysApi, Avatar } from '../../models/index.js' +import { MysApi, Avatar, ProfileRank } from '../../models/index.js' export async function renderProfile (e, char, mode = 'profile', params = {}) { let selfUser = await MysApi.initUser(e) @@ -89,6 +89,11 @@ export async function renderProfile (e, char, mode = 'profile', params = {}) { basic.dmg = Format.comma(basic.dmg) basic.avg = Format.comma(basic.avg) } + let rank = false + if (e.group_id) { + rank = await ProfileRank.create({ group: e.group_id, uid, qq: e.user_id }) + await rank.getRank(profile, true) + } // 渲染图像 return await Common.render('character/profile-detail', { save_id: uid, diff --git a/apps/character/ProfileStat.js b/apps/character/ProfileStat.js index 8f276843..2ec4735f 100644 --- a/apps/character/ProfileStat.js +++ b/apps/character/ProfileStat.js @@ -1,6 +1,6 @@ import lodash from 'lodash' import { Common, Data } from '../../components/index.js' -import { AvatarList } from '../../models/index.js' +import { AvatarList, ProfileRank } from '../../models/index.js' export async function profileStat (e) { // 缓存时间,单位小时 @@ -16,6 +16,10 @@ export async function profileStat (e) { return true } let uid = avatars.uid + let rank = false + if (e.group_id) { + rank = await ProfileRank.create({ group: e.group_id, uid, qq: e.user_id }) + } let talentData = await avatars.getTalentData() // 天赋等级背景 let avatarRet = [] @@ -28,6 +32,9 @@ export async function profileStat (e) { if (profile.hasData) { let mark = profile.getArtisMark(false) avatar.artisMark = Data.getData(mark, 'mark,markClass,names') + if (rank) { + rank.getRank(profile) + } } } }) diff --git a/models/ProfileRank.js b/models/ProfileRank.js index bee5570a..63200a73 100644 --- a/models/ProfileRank.js +++ b/models/ProfileRank.js @@ -17,9 +17,12 @@ export default class ProfileRank { } async getRank (profile, force = false) { + if (!profile.hasData) { + return false + } const key = this.key(profile, 'mark') let rank = await redis.zRank(key, this.uid) - if (!rank || force) { + if (!lodash.isNumber(rank) || force) { let mark = profile.getArtisMark(false) if (mark) { await redis.zAdd(key, { score: mark._mark, value: this.uid })