抽卡:添加抽卡接口

This commit is contained in:
luying
2021-04-23 15:46:04 +08:00
parent 1f6839cafb
commit beadccf778
23 changed files with 591 additions and 85 deletions

42
shared/db/UserGachaRec.ts Normal file
View File

@@ -0,0 +1,42 @@
import BaseModel from './BaseModel';
import { index, getModelForClass, prop, DocumentType, modelOptions } from '@typegoose/typegoose';
import { GachaResult } from '../domain/activityField/gachaField';
import { genCode } from '../pubUtils/util';
/**
* 玩家抽卡表
**/
@modelOptions({ schemaOptions: { id: false } })
@index({ code: 1 })
export default class UserGachaRec extends BaseModel {
@prop({ required: true })
code: string; // 玩家id
@prop({ required: true })
roleId: string; // 玩家id
@prop({ required: true })
gachaId: number; // 抽卡id 1-元宝 2-友情 3-指定 4-限时
@prop({ required: true, default: 0 })
activityId: number; // 限时抽卡对应活动id
@prop({ required: true, default: 0 })
count: number; // 抽卡次数
@prop({ required: true, type: GachaResult, default: [], _id: false })
result: GachaResult[]; // 结果
public static async createRec(roleId: string, gachaId: number, activityId: number, count: number, result: GachaResult[]) {
let code = genCode(8);
const rec = await UserGachaRecModel.findOneAndUpdate({ code }, { $set: { roleId, gachaId, activityId, count, result } }, { new: true, upsert: true });
return rec;
}
}
export const UserGachaRecModel = getModelForClass(UserGachaRec);
export interface UserGachaRecType extends Pick<DocumentType<UserGachaRec>, keyof UserGachaRec> { }
export type UserGachaRecParam = Partial<UserGachaRecType>;