增加挑战累计积分的排行和奖励

This commit is contained in:
zhl 2021-06-02 20:46:44 +08:00
parent 3ffbcb44e0
commit 08c3e422c9
4 changed files with 32 additions and 6 deletions

View File

@ -172,7 +172,7 @@ class ExamController extends BaseController {
session: history.id,
}
await history.save()
await updateExamRank(rankObj)
const { total } = await updateExamRank(rankObj)
let { rankList, userRank, rankTotal } = await getRank({
shop: history.shop,
level: history.activityId,
@ -187,7 +187,8 @@ class ExamController extends BaseController {
let examData = await ShopExam.findById(history.activityId)
let rewardList = []
if (examData && examData.rewardInfo && examData.rewardInfo.length > 0) {
let rewards = examData.getReward(statMap.score)
let rewards = examData.getReward(statMap.score, 0)
rewards = rewards.concat(examData.getReward(total, 1))
for (let reward of rewards) {
let geted = await UserReward.examRewardGeted(history, accountid, reward.id)
if (geted) {

View File

@ -60,6 +60,13 @@ export class ExamRewardClass extends Base {
@prop({ default: 0 })
public count: number
/**
*
* @type {number} 0: 单局, 1: 累积
*/
@prop({ default: 0 })
public type: number
}
@dbconn()
@ -211,7 +218,7 @@ export class ShopExamClass extends BaseModule {
})
}
public getReward(score: number) {
public getReward(score: number, type: number) {
if (!this.rewardInfo || this.rewardInfo.length === 0) {
return []
}

View File

@ -7,7 +7,7 @@ import { GameEnv } from '../config/GameEnv'
import { Shop } from '../models/shop/Shop'
import { mission_vo } from '../config/parsers/mission_vo'
import { ShopActivity } from '../models/shop/ShopActivity'
import { getAccountRank, getRankCount, getRankList, updateRank } from './Rank'
import { getAccountRank, getRankCount, getRankList, updateRank, updateTotalRank } from './Rank'
import { PuzzleRank } from '../models/match/PuzzleRank'
import { UserReward } from '../models/UserReward'
import { GameUser } from '../models/GameUser'
@ -197,8 +197,11 @@ export async function updateExamRank({
mode: number
session: string
}) {
const totalKey = rankKey(shop, level, mode)
await updateRank(accountId, score, totalKey)
const singleKey = rankKey(shop, level, mode)
let single = await updateRank(accountId, score, singleKey)
const totalKey = rankKey(shop, level + '_total', mode)
let total = await updateTotalRank(accountId, score, totalKey)
return { single, total }
}
export async function getRank({

View File

@ -26,6 +26,21 @@ export async function updateRank(accountId: string, score: number, subKey?: stri
return Math.max(score, scoreOld)
}
/**
*
* @param {string} accountId
* @param {number} score
* @param {string} subKey
* @return {Promise<number>}
*/
export async function updateTotalRank(accountId: string, score: number, subKey?: string) {
let scoreOld = await getAccountScore(accountId, subKey)
score += scoreOld
let scoreL = parseFloat(`${score | 0}.${MAX_TIME - Date.now()}`)
await new RedisClient().zadd(generateRankKey(subKey), scoreL, accountId)
return score
}
/**
*
* @param {number} min