From 838f19d8d21ed21e7bbbf7c434a1797ef6144d6b Mon Sep 17 00:00:00 2001 From: CounterFire2023 <136581895+CounterFire2023@users.noreply.github.com> Date: Tue, 26 Mar 2024 19:14:44 +0800 Subject: [PATCH] fix some bugs --- docs/uaw.md | 4 ++-- src/controllers/chain.controller.ts | 4 ++-- src/controllers/chest.controller.ts | 32 ++++++++++++++++++++--------- src/controllers/game.controller.ts | 16 ++++++++++++--- src/controllers/sign.controller.ts | 4 ++-- src/models/ActivityChest.ts | 3 ++- src/tasks/DailyCheckIn.ts | 2 +- 7 files changed, 44 insertions(+), 21 deletions(-) diff --git a/docs/uaw.md b/docs/uaw.md index 871805e..0174b8f 100644 --- a/docs/uaw.md +++ b/docs/uaw.md @@ -477,7 +477,7 @@ body: ```js [{ id: 1, // 箱子id - stat: 0, // 0: 锁定, 1: 正常 + stat: 0, // 0: 锁定, 1: 正常, 2: 已开启, 未领取, 9: 已领取 shareCode: '箱子的分享码', level: 1, // 箱子品级 maxBonus: 10, // 最大可助力数量 @@ -554,7 +554,7 @@ body: ```js { - chestid: '131aasd`1' // 宝箱id + chestId: '131aasd`1' // 宝箱id } ``` diff --git a/src/controllers/chain.controller.ts b/src/controllers/chain.controller.ts index ef8d3bd..ff1d02d 100644 --- a/src/controllers/chain.controller.ts +++ b/src/controllers/chain.controller.ts @@ -9,7 +9,7 @@ export default class ChainController extends BaseController { // @router('get /api/stake/list') async stakeList(req) { const user = req.user - const records = await queryStakeList(user.address) + const records = await queryStakeList(user.address.toLowerCase()) const result = records.map(r => r.toJson()) return result } @@ -33,7 +33,7 @@ export default class ChainController extends BaseController { const history = await TokenClaimHistory.addOne({ user: user.id, activity: user.activity, - address: user.address, + address: user.address.toLowerCase(), token, amount, }) diff --git a/src/controllers/chest.controller.ts b/src/controllers/chest.controller.ts index 06dd547..cad1aeb 100644 --- a/src/controllers/chest.controller.ts +++ b/src/controllers/chest.controller.ts @@ -1,7 +1,6 @@ import { ZError, SyncLocker, ZRedisClient, BaseController, ROLE_ANON, role, router } from 'zutils' import { ActivityChest, ChestStatusEnum } from 'models/ActivityChest' import { ActivityUser } from 'models/ActivityUser' -import { mongoose } from '@typegoose/typegoose' import { rankKey, rankLevel, updateRankScore } from 'services/rank.svr' import { formatDate } from 'zutils/utils/date.util' import { ScoreRecord } from 'models/ScoreRecord' @@ -18,10 +17,23 @@ class BoxController extends BaseController { @router('get /api/chest/list') async chestList(req) { const user = req.user - const chests = await ActivityChest.find({ activity: user.activity, user: user.id, status: { $in: [0, 1] } }).sort({ + const openRecord = await ChestRecord.find({ from: user.address.toLowerCase() }) + const chestIds = openRecord.map(record => record.chestId) + const chestSet = new Set(chestIds) + const chests = await ActivityChest.find({ + activity: user.activity, + user: user.id, + status: { $in: [0, 1, 2] }, + }).sort({ level: -1, }) - return chests.map(chest => chest.toJson()) + const results = chests.map(chest => chest.toJson()) + for (let result of results) { + if (chestSet.has(result.id)) { + result.stat = 2 + } + } + return results } /** * 宝箱助力列表 @@ -119,25 +131,25 @@ class BoxController extends BaseController { async openChest(req) { new SyncLocker().checkLock(req) const user = req.user - const { chestid } = req.query - if (!chestid) { - throw new ZError(11, 'chestid is required') + const { chestId } = req.params + if (!chestId) { + throw new ZError(11, 'chestId is required') } - const openRecord = await ChestRecord.findOne({ from: user.address, chestId: chestid }) + const openRecord = await ChestRecord.findOne({ from: user.address.toLowerCase(), chestId }) if (!openRecord) { throw new ZError(12, 'onchain open record not found') } - const chest = await ActivityChest.findById(chestid) + const chest = await ActivityChest.findById(chestId) if (!chest) { throw new ZError(12, 'chest not found') } if (chest.user !== user.id) { throw new ZError(13, 'chest not belong to user') } - if (chest.status === 1) { + if (chest.status === ChestStatusEnum.OPENED) { throw new ZError(14, 'chest already opened') } - chest.status = 1 + chest.status = ChestStatusEnum.OPENED const score = chest.scoreInit + chest.scoreBonus const dateTag = formatDate(new Date()) await updateRankScore({ diff --git a/src/controllers/game.controller.ts b/src/controllers/game.controller.ts index 489e1db..5230b9b 100644 --- a/src/controllers/game.controller.ts +++ b/src/controllers/game.controller.ts @@ -8,6 +8,7 @@ import { formatDate } from 'zutils/utils/date.util' import { mongoose } from '@typegoose/typegoose' import { generateChestLevel, generateNewChest, generateStepReward } from 'services/game.svr' import { ChestStatusEnum } from 'models/ActivityChest' +import { updateRankScore } from 'services/rank.svr' /** * 探索游戏相关接口 @@ -61,7 +62,7 @@ class GameController extends BaseController { } else if (tag === 'last') { days = '1' } - const res = await queryCheckInList(user.address, days, 0) + const res = await queryCheckInList(user.address.toLowerCase(), days, 0) return res } /** @@ -78,7 +79,7 @@ class GameController extends BaseController { } days = parseInt(days) const dateTag = formatDate(new Date()) - const checkRecord = await checkInToday(user.address, dateTag) + const checkRecord = await checkInToday(user.address.toLowerCase(), dateTag) if (!checkRecord) { throw new ZError(12, 'not signed in') } @@ -141,7 +142,7 @@ class GameController extends BaseController { } const signCfg = seqSignCfg const dateTag = formatDate(new Date()) - const checkRecord = await checkInToday(user.address, dateTag) + const checkRecord = await checkInToday(user.address.toLowerCase(), dateTag) let todayStat = 0 if (checkRecord) { // 有签到的链上记录, 说明已签到 @@ -226,6 +227,15 @@ class GameController extends BaseController { chests.push(generateNewChest(user.id, user.activity, level, ChestStatusEnum.NORMAL)) } } + await updateRankScore({ + user: user.id, + score: score, + activity: user.activity, + scoreType: 'game_step', + scoreParams: { + step: step, + }, + }) for (let chest of chests) { await chest.save() } diff --git a/src/controllers/sign.controller.ts b/src/controllers/sign.controller.ts index 344cc43..cf495a4 100644 --- a/src/controllers/sign.controller.ts +++ b/src/controllers/sign.controller.ts @@ -109,7 +109,7 @@ class SignController extends BaseController { if (user.inviteUser) { const inviteUser = await ActivityUser.findById(user.inviteUser) if (inviteUser) { - invite = inviteUser.address + invite = inviteUser.address.toLowerCase() } } const records = await ScoreRecord.find({ user: user.id, activity: user.activity, scoreType: 'invite' }) @@ -119,7 +119,7 @@ class SignController extends BaseController { score += record.score } let result = { - address: user.address, + address: user.address.toLowerCase(), boost: user.boost || 1, boostExpire: user.boostExpire, twitterId: user.twitterId, diff --git a/src/models/ActivityChest.ts b/src/models/ActivityChest.ts index 16f0075..6a6ebab 100644 --- a/src/models/ActivityChest.ts +++ b/src/models/ActivityChest.ts @@ -8,6 +8,7 @@ const alphabet = '3fBCM8j17XNA9xYun4wmLWep2oHFlhPcgyEJskqOz6GK0UtV5ZRaDSvrTbidQI export enum ChestStatusEnum { LOCKED = 0, NORMAL = 1, + NOT_CLAIMED = 2, OPENED = 9, } /** @@ -68,7 +69,7 @@ class ActivityChestClass extends BaseModule { public toJson() { return { // @ts-ignore - id: this._id, + id: this.id, stat: this.status, shareCode: this.shareCode, level: this.level, diff --git a/src/tasks/DailyCheckIn.ts b/src/tasks/DailyCheckIn.ts index 0c93380..ba7e08b 100644 --- a/src/tasks/DailyCheckIn.ts +++ b/src/tasks/DailyCheckIn.ts @@ -57,7 +57,7 @@ export default class DailyCheckIn extends ITask { // 请求前7天的签到记录, 往前查找连续签到的记录, let cfg = this.activity.tasks.find((t: TaskCfg) => t.id === task.id) if (cfg.type === TaskTypeEnum.DAILY) { - const res = await queryCheckInList(this.user.address, 1, 0) + const res = await queryCheckInList(this.user.address.toLowerCase(), 1, 0) const [taskId, dateTag] = task.id.split(':') let list: { day: string; time: number; count: number }[] = res