增加抽奖券的入库

This commit is contained in:
zhl 2021-06-07 12:47:39 +08:00
parent acd6b01439
commit bf5e12d75f
3 changed files with 12 additions and 2 deletions

View File

@ -11,7 +11,7 @@ import { BaseModule } from '../Base'
})
class ItemRecordClass extends BaseModule {
@prop()
public item: number
public item: string
@prop()
public accountId: string
@prop()
@ -39,7 +39,7 @@ class ItemRecordClass extends BaseModule {
public static async log(
accountId: string,
shop: string,
itemId: number,
itemId: string,
count: number,
reason?: string,
moreparam?: any,

View File

@ -1,6 +1,7 @@
import { dbconn } from '../../decorators/dbconn'
import { getModelForClass, index, modelOptions, prop } from '@typegoose/typegoose'
import { BaseModule } from '../Base'
import { ItemRecord } from './ItemRecord'
@dbconn()
@index({ accountId: 1, shop: 1 }, { unique: false })
@ -36,17 +37,22 @@ class UserItemClass extends BaseModule {
shop,
item,
count,
reason,
params,
}: {
accountId: string
shop: string
item: string
count: number
reason: string
params: any
}) {
let record = await UserItem.findOneAndUpdate(
{ accountId, shop, item },
{ $inc: { count: count } },
{ upsert: true, new: true },
)
await ItemRecord.log(accountId, shop, item, count, reason, params)
return record
}
}

View File

@ -8,6 +8,7 @@ import { Coupon } from '../shop/Coupon'
import { getCouponUrl } from '../../services/File'
import { PuzzleSessionClass } from '../match/PuzzleSession'
import { LOTTERY_TICKET } from '../../constants/BaseConst'
import { UserItem } from './UserItem'
const nanoid = customAlphabet('2345678abcdefghjkmnpqrstwxy', 10)
@ -173,6 +174,9 @@ class UserRewardClass extends BaseModule {
if (coupon === LOTTERY_TICKET) {
rewardType = 1
await saveRecord(1, count)
let reason = history.type === 1 ? '活动奖励' : '挑战奖励'
let params = { activity: history.activityId, rewardId }
await UserItem.addItem({ accountId, shop: history.shop, item: coupon, count, reason, params })
name = '抽奖券'
} else {
rewardType = 0