From bb2d99742c21ce093984c95e3b5873e6f6be1117 Mon Sep 17 00:00:00 2001 From: zhl Date: Mon, 7 Jun 2021 15:48:01 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AE=9E=E7=8E=B0=E9=82=80=E8=AF=B7=E5=A5=96?= =?UTF-8?q?=E5=8A=B1=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- doc/api.md | 27 ++++++++--- src/api/controllers/game_user.controller.ts | 53 +++++++++++++++++++++ src/models/shop/ShopCfg.ts | 29 +++++++---- 3 files changed, 94 insertions(+), 15 deletions(-) diff --git a/doc/api.md b/doc/api.md index 813b795..1e232a6 100644 --- a/doc/api.md +++ b/doc/api.md @@ -581,12 +581,27 @@ 3. Response: JSON ```js -[{ - "name": '显示名', - "reward_type": '奖励物品的id', - "reward_count": 100, //奖励物品数量 - "icon": "item/item_0" // 奖励物品的图片地址, 可能是本地,远程, 如果该字段为空的话, 需要取本地的默认值 - }] +{ + num: 10, // 已邀请人数 + newget: [ // 本次请求新获得的物品 + coupon: '优惠券的id', + name: '优惠券名', + count: 1, //数量 + couponUrl: '优惠券详情图的url', + rewardType: 0, // 0: 优惠券, 1: 抽奖券 + ] + rewards: [ // 奖励列表 + { + coupon: '优惠券的id', + name: '优惠券名', + count: 1, //数量 + couponUrl: '优惠券详情图的url', + rewardType: 0, // 0: 优惠券, 1: 抽奖券 + score: 100, // 获得条件 + geted: 0, // 是否已获得, 0: 未获得, 1: 已获得 + } + ] +} ``` ### 16. 挑战奖励详情 diff --git a/src/api/controllers/game_user.controller.ts b/src/api/controllers/game_user.controller.ts index aa86b70..756c5e4 100644 --- a/src/api/controllers/game_user.controller.ts +++ b/src/api/controllers/game_user.controller.ts @@ -9,6 +9,9 @@ import { LOTTERY_TICKET } from '../../constants/BaseConst' import { getShopInviteeNum } from '../../services/JCFW' import { Shop } from '../../models/shop/Shop' import { UserCoupon } from '../../models/user/UserCoupon' +import { ShareCfgClass, ShopCfg } from '../../models/shop/ShopCfg' +import { Coupon } from '../../models/shop/Coupon' +import { getCouponUrl } from '../../services/File' class GameUserController extends BaseController { // TODO:: 增加返回未使用的券 @@ -86,5 +89,55 @@ class GameUserController extends BaseController { throw new ZError(11, '无法找到对应店铺') } let numInvite = await getShopInviteeNum(accountId, sessionid, shop.numid) + const cfg = await ShopCfg.findOne({ shop: shop.id }) + if (!cfg) { + throw new ZError(12, '当前店铺未配置相关信息') + } + if (!cfg.share_cfgs || cfg.share_cfgs.length === 0) { + throw new ZError(12, '当前店铺未配置相关信息') + } + let rewardList = [] + let newItems: any[] = [] + let couponMap: Map = new Map() + const gotSet: Set = await UserReward.userGotSet(accountId, shop.id, 'share') + for (let reward of cfg.share_cfgs) { + let name = '抽奖券' + let couponUrl = reward.icon + 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 = reward.icon || getCouponUrl(shop.id, reward.coupon) + } + if (!gotSet.has(reward._id + '') && numInvite >= reward.rank) { + let obj = await UserReward.saveOneRecord({ + accountId, + itemId: reward.coupon, + count: reward.count, + shop: shop.id, + rewardId: reward._id + '', + activityId: 'share', + source: 'share', + }) + gotSet.add(reward._id + '') + newItems.push(obj) + } + rewardList.push({ + coupon: reward.coupon, + name, + count: reward.count, + couponUrl, + score: reward.rank, + rewardType: reward.rewardType, + geted: gotSet.has(reward._id + '') ? 1 : 0, + }) + } + return { + num: numInvite, + newget: newItems, + rewards: rewardList, + } } } diff --git a/src/models/shop/ShopCfg.ts b/src/models/shop/ShopCfg.ts index e73272d..b0b3051 100644 --- a/src/models/shop/ShopCfg.ts +++ b/src/models/shop/ShopCfg.ts @@ -10,16 +10,20 @@ export class ShareCfgClass extends Base { * @type {number} */ @prop() - public need_count: number + public rank: number @prop() - public name: string + public coupon: string - @prop() - public reward_type: string + @prop({ default: 0 }) + public count: number - @prop() - public reward_count: number + /** + * 奖励类型 + * @type {number} 0: 优惠券, 1: 抽奖券 + */ + @prop({ default: 0 }) + public rewardType: number @prop() public icon: string @@ -30,10 +34,17 @@ export class LotteryCfgClass extends Base { public name: string @prop() - public reward_type: string + public coupon: string - @prop() - public reward_count: number + @prop({ default: 0 }) + public count: number + + /** + * 奖励类型 + * @type {number} 0: 优惠券, 1: 抽奖券 + */ + @prop({ default: 0 }) + public rewardType: number @prop() public icon: string