装备:任务

This commit is contained in:
luying
2022-02-22 10:56:31 +08:00
parent 56f2c23929
commit 3f5371df79
11 changed files with 598 additions and 262 deletions

View File

@@ -33,6 +33,9 @@ export default class UserTaskRec extends BaseModel {
@prop({ required: true, type: Number, default: [] })
received: number[]; // 是否已领取
@prop({ required: true, type: String, default: [] })
records: string[]; // 历史记录
private static getRefreshCondition(type: number) {
let today = getZeroPointD();
@@ -55,6 +58,8 @@ export default class UserTaskRec extends BaseModel {
return rec;
}
public static async checkHistoryAndSetTaskRec(roleId: string, type: number, taskType: number, group: string, count: number) {
let rec: UserTaskRecType = await UserTaskRecModel.findByRoleAndGroup(roleId, type, taskType, group);
if(rec) {
@@ -67,6 +72,15 @@ export default class UserTaskRec extends BaseModel {
return rec;
}
public static async checkRecordAndIncTaskRec(roleId: string, type: number, taskType: number, group: string, count: number, record: string) {
let rec: UserTaskRecType = await UserTaskRecModel.findByRoleAndGroup(roleId, type, taskType, group);
if(!rec || rec.records.indexOf(record) == -1) {
let condition = this.getRefreshCondition(type);
rec = await UserTaskRecModel.findOneAndUpdate({ roleId, group, taskType, ...condition }, { $setOnInsert: { code: genCode(8), received: [] }, $inc: { count }, $push: { records: record } }, { new: true, upsert: true }).lean();
}
return rec;
}
public static async findByRoleAndType(roleId: string, type: number) {
let condition = this.getRefreshCondition(type);
let rec: UserTaskRecType[] = await UserTaskRecModel.find({ roleId, ...condition }).lean();