实现挑战详情接口
This commit is contained in:
parent
fbcf600eea
commit
5a6bfcd68d
@ -504,9 +504,6 @@
|
||||
```js
|
||||
{
|
||||
tocket_lottery: 10, //用户在当前店铺拥有的抽奖券数量
|
||||
share_rewards: [{
|
||||
|
||||
}],
|
||||
}
|
||||
```
|
||||
|
||||
@ -595,7 +592,7 @@
|
||||
### 16. 挑战详情
|
||||
|
||||
1. Method: POST
|
||||
2. <span id="216">URI: /api/:accountid/shop</span>
|
||||
2. <span id="216">URI: /api/:accountid/exam_info</span>
|
||||
|
||||
| 字段 | 说明 |
|
||||
| -------- | -------------------------------------- |
|
||||
@ -625,7 +622,9 @@
|
||||
count: 1, //数量
|
||||
couponUrl: '优惠券详情图的url',
|
||||
type: 0, //类型 0: 单局能获得的奖励 1: 累计榜积分奖励, 2: 累计榜排名奖励
|
||||
score: '100', // 获得条件
|
||||
rewardType: 0, // 0: 优惠券, 1: 抽奖券
|
||||
score: 100, // 获得条件,type=2的类型, score是排名, 其他类型为积分
|
||||
scoreEnd: 150, // 只有type=2的时候才需要考虑该值, 表示从第几名到第几名能获得奖励
|
||||
geted: 0, // 是否已获得, 0: 未获得, 1: 已获得
|
||||
}
|
||||
]
|
||||
|
@ -8,6 +8,8 @@ import { calcExamScore, getRank, transformRecord, updateExamRank } from '../../s
|
||||
import { Shop, validShopId } from '../../models/shop/Shop'
|
||||
import { UserReward } from '../../models/user/UserReward'
|
||||
import { ShopPuzzle } from '../../models/shop/ShopPuzzle'
|
||||
import { Coupon } from '../../models/shop/Coupon'
|
||||
import { getCouponUrl } from '../../services/File'
|
||||
|
||||
class ExamController extends BaseController {
|
||||
@role('anon')
|
||||
@ -203,4 +205,50 @@ class ExamController extends BaseController {
|
||||
rspData.gameResult = gameResult
|
||||
return rspData
|
||||
}
|
||||
|
||||
@role('anon')
|
||||
@router('post /api/:accountId/exam_info')
|
||||
async examInfo(req: any) {
|
||||
const { accountId, sid, eid } = req.params
|
||||
if (!sid || !eid) {
|
||||
throw new ZError(10, '缺少必要参数: sid或eid')
|
||||
}
|
||||
const shop = await Shop.fetchByID(sid)
|
||||
if (!shop) {
|
||||
throw new ZError(11, '无法找到对应店铺')
|
||||
}
|
||||
let examData = await ShopExam.findById(eid)
|
||||
if (!examData) {
|
||||
throw new ZError(12, '无法找到对应挑战记录')
|
||||
}
|
||||
const gotSet: Set<string> = await UserReward.userGotSet(accountId, shop.id, eid)
|
||||
let rewardList = []
|
||||
if (examData && examData.rewardInfo && examData.rewardInfo.length > 0) {
|
||||
let couponMap: Map<string, any> = new Map()
|
||||
for (let reward of examData.rewardInfo) {
|
||||
let name = '抽奖券'
|
||||
let couponUrl = ''
|
||||
if (reward.rewardType === 0) {
|
||||
if (!couponMap.has(reward.coupon)) {
|
||||
let coupon = await Coupon.findById(reward.coupon)
|
||||
couponMap.set(coupon.id, coupon)
|
||||
}
|
||||
name = couponMap.get(reward.coupon).name
|
||||
couponUrl = getCouponUrl(shop.id, reward.coupon)
|
||||
}
|
||||
rewardList.push({
|
||||
coupon: reward.coupon,
|
||||
name,
|
||||
count: reward.count,
|
||||
couponUrl,
|
||||
type: reward.type,
|
||||
score: reward.rank,
|
||||
scoreEnd: reward.rankEnd,
|
||||
rewardType: reward.rewardType,
|
||||
geted: gotSet.has(reward._id + '') ? 1 : 0,
|
||||
})
|
||||
}
|
||||
}
|
||||
return rewardList
|
||||
}
|
||||
}
|
||||
|
@ -71,8 +71,20 @@ class GameUserController extends BaseController {
|
||||
}
|
||||
let result: any = {}
|
||||
result.tocket_lottery = await UserItem.fetchCount({ accountId, shop: sid, item: LOTTERY_TICKET })
|
||||
let numInvite = await getShopInviteeNum(accountId, sessionid, shop.numid)
|
||||
|
||||
return result
|
||||
}
|
||||
|
||||
@role('anon')
|
||||
@router('post /api/:accountId/share_rewards')
|
||||
async shareRewards(req: any) {
|
||||
const { accountId, sid, sessionid } = req.params
|
||||
if (!sid) {
|
||||
throw new ZError(10, '缺少必要参数: sid')
|
||||
}
|
||||
const shop = await Shop.fetchByID(sid)
|
||||
if (!shop) {
|
||||
throw new ZError(11, '无法找到对应店铺')
|
||||
}
|
||||
let numInvite = await getShopInviteeNum(accountId, sessionid, shop.numid)
|
||||
}
|
||||
}
|
||||
|
@ -16,6 +16,7 @@ import { UserCoupon } from './UserCoupon'
|
||||
@dbconn()
|
||||
@index({ accountId: 1 }, { unique: false })
|
||||
@index({ accountId: 1, shop: 1 }, { unique: false })
|
||||
@index({ accountId: 1, shop: 1, activityId: 1 }, { unique: false })
|
||||
@index({ accountId: 1, shop: 1, rewardId: 1, source: 1, activityId: 1 }, { unique: false })
|
||||
@modelOptions({ schemaOptions: { collection: 'game_user_reward', timestamps: true } })
|
||||
class UserRewardClass extends BaseModule {
|
||||
@ -182,6 +183,15 @@ class UserRewardClass extends BaseModule {
|
||||
).limit(1)
|
||||
return records.length > 0
|
||||
}
|
||||
|
||||
public static async userGotSet(accountId: string, shop: string, activityId: string) {
|
||||
let records = await UserReward.find({ accountId, shop, activityId })
|
||||
let result: Set<string> = new Set()
|
||||
for (const record of records) {
|
||||
result.add(record.rewardId)
|
||||
}
|
||||
return result
|
||||
}
|
||||
}
|
||||
|
||||
export const UserReward = getModelForClass(UserRewardClass, { existingConnection: UserRewardClass.db })
|
||||
|
Loading…
x
Reference in New Issue
Block a user