寻宝:情谊助战相关逻辑;更新物品表-加入情谊点
This commit is contained in:
@@ -96,7 +96,8 @@ export const CURRENCY_TYPE = {
|
||||
ACTION_POINT: "ap",
|
||||
TREASURE_POINT: "treasurePoint",
|
||||
EXPEDITION_POINT: "expeditionPoint",
|
||||
DUNGEON_POINT: "dungeonPoint"
|
||||
DUNGEON_POINT: "dungeonPoint",
|
||||
FRIEND_POINT: "friendPoint"
|
||||
}
|
||||
|
||||
const currencyArr = [
|
||||
@@ -105,7 +106,8 @@ const currencyArr = [
|
||||
{ "gid": 31003, "name": "体力", "type": CURRENCY_TYPE.ACTION_POINT },
|
||||
{ "gid": 40001, "name": "远征币", "type": CURRENCY_TYPE.EXPEDITION_POINT },
|
||||
{ "gid": 40002, "name": "寻宝币", "type": CURRENCY_TYPE.TREASURE_POINT },
|
||||
{ "gid": 40003, "name": "秘境币", "type": CURRENCY_TYPE.DUNGEON_POINT },
|
||||
{ "gid": 40003, "name": "情谊点", "type": CURRENCY_TYPE.FRIEND_POINT },
|
||||
{ "gid": 40004, "name": "秘境币", "type": CURRENCY_TYPE.DUNGEON_POINT },
|
||||
];
|
||||
export const CURRENCY = new Map<number, {gid: number, name: string, type: string}>();
|
||||
export const CURRENCY_BY_TYPE = new Map<string, number>();
|
||||
|
||||
41
shared/db/FriendPoint.ts
Normal file
41
shared/db/FriendPoint.ts
Normal file
@@ -0,0 +1,41 @@
|
||||
import BaseModel from './BaseModel';
|
||||
import { index, getModelForClass, prop } from '@typegoose/typegoose';
|
||||
|
||||
/**
|
||||
* 情谊点记录
|
||||
*/
|
||||
@index({ roleId: 1, createdAt: -1 })
|
||||
|
||||
export default class FriendPoint extends BaseModel {
|
||||
@prop({ required: true, default: '' })
|
||||
roleId: string; // 角色 id
|
||||
@prop({ required: true, default: '' })
|
||||
roleName: string; // 角色名称
|
||||
@prop({ required: true, default: 0 })
|
||||
cnt: number; // 当天获取的点数
|
||||
|
||||
/**
|
||||
* @description 更新每天的情谊点获取情况,cnt 有可能超过当日最大值,可根据返回值判断
|
||||
* @static
|
||||
* @param {string} roleId
|
||||
* @param {string} roleName
|
||||
* @param {number} cntInc
|
||||
* @param {number} maxPerDay
|
||||
* @param {boolean} [lean=true]
|
||||
* @memberof FriendPoint
|
||||
*/
|
||||
public static async updatePointToday(roleId: string, roleName: string, cntInc: number, maxPerDay: number, lean = true) {
|
||||
const curTime = new Date((new Date()).setHours(0, 0, 0, 0));
|
||||
// 当 oldCnt + cntInc > maxPerDay 时需计算实际可以获得的点数:cntInc - (newCnt - maxPerDay)
|
||||
const rec = await FriendPointModel.findOneAndUpdate({roleId, roleName, createdAt: {$gte: curTime}, cnt: {$lt: maxPerDay}}, {$inc: {cnt: cntInc}}, {upsert: true, new: true}).lean(lean);
|
||||
return rec;
|
||||
}
|
||||
|
||||
public static async getFrdPointRecToday(roleId: string, lean = true) {
|
||||
const curTime = new Date((new Date()).setHours(0, 0, 0, 0));
|
||||
const rec = await FriendPointModel.findOne({roleId, createdAt: {$gte: curTime}}).lean(lean);
|
||||
return rec;
|
||||
}
|
||||
}
|
||||
|
||||
export const FriendPointModel = getModelForClass(FriendPoint);
|
||||
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user