diff --git a/doc/api.md b/doc/api.md index a64f18a..7c1a20e 100644 --- a/doc/api.md +++ b/doc/api.md @@ -504,9 +504,6 @@ ```js { tocket_lottery: 10, //用户在当前店铺拥有的抽奖券数量 - share_rewards: [{ - - }], } ``` @@ -595,7 +592,7 @@ ### 16. 挑战详情 1. Method: POST -2. URI: /api/:accountid/shop +2. URI: /api/:accountid/exam_info | 字段 | 说明 | | -------- | -------------------------------------- | @@ -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: 已获得 } ] diff --git a/src/api/controllers/exam.controller.ts b/src/api/controllers/exam.controller.ts index 5ebb6b4..2d66c7f 100644 --- a/src/api/controllers/exam.controller.ts +++ b/src/api/controllers/exam.controller.ts @@ -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 = await UserReward.userGotSet(accountId, shop.id, eid) + let rewardList = [] + if (examData && examData.rewardInfo && examData.rewardInfo.length > 0) { + let couponMap: Map = 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 + } } diff --git a/src/api/controllers/game_user.controller.ts b/src/api/controllers/game_user.controller.ts index db13a23..aa86b70 100644 --- a/src/api/controllers/game_user.controller.ts +++ b/src/api/controllers/game_user.controller.ts @@ -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) + } } diff --git a/src/models/user/UserReward.ts b/src/models/user/UserReward.ts index 809d288..0beb0a8 100644 --- a/src/models/user/UserReward.ts +++ b/src/models/user/UserReward.ts @@ -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 = new Set() + for (const record of records) { + result.add(record.rewardId) + } + return result + } } export const UserReward = getModelForClass(UserRewardClass, { existingConnection: UserRewardClass.db })