初步增加排名功能

This commit is contained in:
Kokomi 2022-11-08 04:16:30 +08:00
parent 9ba9781701
commit ea28dcc542
3 changed files with 18 additions and 3 deletions

View File

@ -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,

View File

@ -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)
}
}
}
})

View File

@ -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 })