增加抽奖券的入库

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 { class ItemRecordClass extends BaseModule {
@prop() @prop()
public item: number public item: string
@prop() @prop()
public accountId: string public accountId: string
@prop() @prop()
@ -39,7 +39,7 @@ class ItemRecordClass extends BaseModule {
public static async log( public static async log(
accountId: string, accountId: string,
shop: string, shop: string,
itemId: number, itemId: string,
count: number, count: number,
reason?: string, reason?: string,
moreparam?: any, moreparam?: any,

View File

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

View File

@ -8,6 +8,7 @@ import { Coupon } from '../shop/Coupon'
import { getCouponUrl } from '../../services/File' import { getCouponUrl } from '../../services/File'
import { PuzzleSessionClass } from '../match/PuzzleSession' import { PuzzleSessionClass } from '../match/PuzzleSession'
import { LOTTERY_TICKET } from '../../constants/BaseConst' import { LOTTERY_TICKET } from '../../constants/BaseConst'
import { UserItem } from './UserItem'
const nanoid = customAlphabet('2345678abcdefghjkmnpqrstwxy', 10) const nanoid = customAlphabet('2345678abcdefghjkmnpqrstwxy', 10)
@ -173,6 +174,9 @@ class UserRewardClass extends BaseModule {
if (coupon === LOTTERY_TICKET) { if (coupon === LOTTERY_TICKET) {
rewardType = 1 rewardType = 1
await saveRecord(1, count) 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 = '抽奖券' name = '抽奖券'
} else { } else {
rewardType = 0 rewardType = 0