🐞 fix(礼包码): 停止使用礼包码的record字段
This commit is contained in:
49
shared/db/UserGiftCodeDetail.ts
Normal file
49
shared/db/UserGiftCodeDetail.ts
Normal file
@@ -0,0 +1,49 @@
|
||||
import BaseModel from './BaseModel';
|
||||
import { index, getModelForClass, prop, DocumentType, modelOptions } from '@typegoose/typegoose';
|
||||
|
||||
/**
|
||||
* 领取记录
|
||||
**/
|
||||
@modelOptions({ schemaOptions: { id: false } })
|
||||
@index({ roleId: 1, giftId: 1 })
|
||||
@index({ orderId: 1, giftId: 1 })
|
||||
export default class UserGiftCodeDetail extends BaseModel {
|
||||
|
||||
@prop({ required: true, default: '' })
|
||||
roleId: string;
|
||||
|
||||
@prop({ required: true, default: '' })
|
||||
roleName: string;
|
||||
|
||||
@prop({ required: true, default: 0 })
|
||||
serverId: number;
|
||||
|
||||
@prop({ required: false, default: '' })
|
||||
orderId?: string;
|
||||
|
||||
@prop({ required: true, default: '' })
|
||||
giftId: number; // giftCode表的id
|
||||
|
||||
@prop({ required: true, default: '' })
|
||||
code: string; // 兑换码
|
||||
|
||||
public static async record(roleId: string, roleName: string, serverId: number, giftId: number, code: string, orderId?: string) {
|
||||
await UserGiftCodeDetailModel.insertMany([{ roleId, roleName, serverId, giftId, code, orderId }]);
|
||||
}
|
||||
|
||||
public static async checkHasUsed(roleId: string, id: number) {
|
||||
let result = await UserGiftCodeDetailModel.exists({ giftId: id, roleId });
|
||||
return result;
|
||||
}
|
||||
|
||||
public static async checkOrderHasUsed(id: number, orderId: string) {
|
||||
let result = await UserGiftCodeDetailModel.exists({ giftId: id, orderId });
|
||||
return result;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
export const UserGiftCodeDetailModel = getModelForClass(UserGiftCodeDetail);
|
||||
|
||||
export interface UserGiftCodeDetailType extends Pick<DocumentType<UserGiftCodeDetail>, keyof UserGiftCodeDetail> { }
|
||||
export type UserGiftCodeDetailParam = Partial<UserGiftCodeDetailType>;
|
||||
Reference in New Issue
Block a user