活动:添加rmb活动类型判断
This commit is contained in:
@@ -1,6 +1,14 @@
|
||||
import BaseModel from './BaseModel';
|
||||
import { index, getModelForClass, prop, DocumentType } from '@typegoose/typegoose';
|
||||
|
||||
|
||||
export class Activity_Sign_In_Record extends BaseModel {
|
||||
@prop({ required: true })
|
||||
dayIndex: number; // 第几天
|
||||
@prop({ required: true })
|
||||
time: Date; // 时间
|
||||
}
|
||||
|
||||
/**
|
||||
* 签到
|
||||
*/
|
||||
@@ -14,45 +22,38 @@ export default class Activity_Sign_In extends BaseModel {
|
||||
@prop({ required: true })
|
||||
roundIndex: number; // 周期数,从活动设置的开始时间计算
|
||||
@prop({ required: true })
|
||||
dayIndex: number; // 第几天 从1开始
|
||||
@prop({ required: true })
|
||||
isReceive: boolean; // 是否领取
|
||||
records: Activity_Sign_In_Record[]; // 领取记录
|
||||
|
||||
//签到记录
|
||||
public static async addSignInRecord(activityId: number, roleId: string, roundIndex: number, dayIndex: number, lean = true) {
|
||||
let result: ActivitySignInModelType = await ActivitySignInModel.findOneAndUpdate({ roleId, activityId, roundIndex, dayIndex },
|
||||
{ $set: { isReceive: true } }, { upsert: true, new: true }).lean(lean);
|
||||
public static async addSignInRecord(activityId: number, roleId: string, roundIndex: number, dayIndexs: number[]) {
|
||||
let records = [];
|
||||
for (let dayIndex of dayIndexs) {
|
||||
let record = new Activity_Sign_In_Record();
|
||||
record.dayIndex = dayIndex;
|
||||
record.time = new Date();
|
||||
records.push(record)
|
||||
}
|
||||
let result: ActivitySignInModelType = await ActivitySignInModel.findOneAndUpdate({ roleId, activityId, roundIndex },
|
||||
{ $push: { records: { $each: records } } }, { new: true }).lean(true);
|
||||
return result;
|
||||
}
|
||||
|
||||
//根据活动id查询活动数据
|
||||
public static async findData(activityId: number, roleId: string, roundIndex: number, lean = true) {
|
||||
let result: ActivitySignInModelType[] = await ActivitySignInModel.find({ roleId, activityId, roundIndex }).lean(lean);
|
||||
return result;
|
||||
}
|
||||
|
||||
//查询第几天的活动数据
|
||||
public static async findDataByDayIndex(activityId: number, roleId: string, roundIndex: number, dayIndex: number, lean = true) {
|
||||
let result: ActivitySignInModelType[] = await ActivitySignInModel.find({ roleId, activityId, roundIndex, dayIndex }).lean(lean);
|
||||
return result;
|
||||
}
|
||||
|
||||
//查询第几天的活动数据
|
||||
public static async isBuyVip(activityId: number, roleId: string, roundIndex: number) {
|
||||
let result: ActivitySignInModelType = await ActivitySignInModel.findOne({ roleId, activityId, roundIndex, dayIndex: 0 }).lean(true);
|
||||
public static async findData(activityId: number, roleId: string, roundIndex: number) {
|
||||
let result: ActivitySignInModelType = await ActivitySignInModel.findOne({ roleId, activityId, roundIndex }).lean(true);
|
||||
return result;
|
||||
}
|
||||
|
||||
//购买vip记录
|
||||
public static async buyVIP(activityId: number, roleId: string, roundIndex: number) {
|
||||
let result: ActivitySignInModelType = await ActivitySignInModel.findOneAndUpdate({ roleId, activityId, roundIndex },
|
||||
{ $set: { dayIndex: 0 } }, { upsert: true, new: true }).lean(true);
|
||||
{}, { upsert: true, new: true }).lean(true);
|
||||
return result;
|
||||
}
|
||||
|
||||
//删除签到记录
|
||||
public static async deleteActivity(activityId: number, roleId: string, roundIndex: number, dayIndex: number) {
|
||||
await ActivitySignInModel.deleteMany({ roleId, activityId, roundIndex, dayIndex });
|
||||
public static async deleteActivity(activityId: number, roleId: string, roundIndex: number) {
|
||||
await ActivitySignInModel.deleteMany({ roleId, activityId, roundIndex });
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user