🐞 fix(礼包码): 停止使用礼包码的record字段
This commit is contained in:
@@ -2,7 +2,6 @@ import BaseModel from './BaseModel';
|
||||
import { index, getModelForClass, prop, DocumentType, modelOptions } from '@typegoose/typegoose';
|
||||
import { GIFT_GENERATE_TYPE } from '../consts';
|
||||
import { GiftCodeModel, GiftCodeType } from './GiftCode';
|
||||
import { nowSeconds } from '../pubUtils/timeUtil';
|
||||
import { genCode } from '../pubUtils/util';
|
||||
import { SearchGiftCodeDetailParam } from '../domain/backEndField/search';
|
||||
|
||||
@@ -55,7 +54,7 @@ export default class GiftCodeDetail extends BaseModel {
|
||||
|
||||
// 根据code
|
||||
public static async findByCode(code: string) {
|
||||
let result: GiftCodeDetailType = await GiftCodeDetailModel.findOne({ code }).lean(true);
|
||||
let result: GiftCodeDetailType = await GiftCodeDetailModel.findOne({ code }).select('-record').lean(true);
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -78,11 +77,10 @@ export default class GiftCodeDetail extends BaseModel {
|
||||
return result;
|
||||
}
|
||||
|
||||
public static async increaseUsedNum(code: string, roleId: string, roleName: string, serverId: number, orderId?: string) {
|
||||
let result: GiftCodeDetailType = await GiftCodeDetailModel.findOneAndUpdate({ code }, {
|
||||
$inc: { usedNum: 1 }, $push: { roleIds: roleId, record: { roleId, roleName, serverId, time: nowSeconds(), orderId } }
|
||||
public static async increaseUsedNum(code: string) {
|
||||
await GiftCodeDetailModel.updateOne({ code }, {
|
||||
$inc: { usedNum: 1 }
|
||||
}, { new: true }).lean();
|
||||
return result;
|
||||
}
|
||||
|
||||
public static async generateMany(giftCode: GiftCodeType, count = 1, uid = 1) {
|
||||
|
||||
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