活动:签到
This commit is contained in:
@@ -1,12 +1,18 @@
|
||||
import BaseModel from './BaseModel';
|
||||
import { index, getModelForClass, prop, DocumentType } from '@typegoose/typegoose';
|
||||
import { getZeroPoint } from '../pubUtils/timeUtil';
|
||||
|
||||
|
||||
export class Activity_Sign_In_Record extends BaseModel {
|
||||
export class Activity_Sign_In_Record {
|
||||
@prop({ required: true })
|
||||
dayIndex: number; // 第几天
|
||||
@prop({ required: true })
|
||||
time: Date; // 时间
|
||||
time: number; // 时间
|
||||
|
||||
constructor(dayIndex: number, time: number) {
|
||||
this.dayIndex = dayIndex;
|
||||
this.time = time;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -21,20 +27,13 @@ export default class Activity_Sign_In extends BaseModel {
|
||||
roleId: string; // 用户Id
|
||||
@prop({ required: true })
|
||||
roundIndex: number; // 周期数,从活动设置的开始时间计算
|
||||
@prop({ required: true })
|
||||
@prop({ required: true, type: Activity_Sign_In_Record, _id: false })
|
||||
records: Activity_Sign_In_Record[]; // 领取记录
|
||||
|
||||
//签到记录
|
||||
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)
|
||||
}
|
||||
public static async addSignInRecord(activityId: number, roleId: string, roundIndex: number, dayIndex: number) {
|
||||
let result: ActivitySignInModelType = await ActivitySignInModel.findOneAndUpdate({ roleId, activityId, roundIndex },
|
||||
{ $push: { records: { $each: records } } }, { upsert: true, new: true }).lean(true);
|
||||
{ $push: { records: new Activity_Sign_In_Record(dayIndex, Date.now()) } }, { upsert: true, new: true }).lean(true);
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user