实现邀请奖励接口

This commit is contained in:
zhl 2021-06-07 15:48:01 +08:00
parent 9104a63cbf
commit bb2d99742c
3 changed files with 94 additions and 15 deletions

View File

@ -581,12 +581,27 @@
3. Response: JSON 3. Response: JSON
```js ```js
[{ {
"name": '显示名', num: 10, // 已邀请人数
"reward_type": '奖励物品的id', newget: [ // 本次请求新获得的物品
"reward_count": 100, //奖励物品数量 coupon: '优惠券的id',
"icon": "item/item_0" // 奖励物品的图片地址, 可能是本地,远程, 如果该字段为空的话, 需要取本地的默认值 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. 挑战奖励详情 ### 16. 挑战奖励详情

View File

@ -9,6 +9,9 @@ import { LOTTERY_TICKET } from '../../constants/BaseConst'
import { getShopInviteeNum } from '../../services/JCFW' import { getShopInviteeNum } from '../../services/JCFW'
import { Shop } from '../../models/shop/Shop' import { Shop } from '../../models/shop/Shop'
import { UserCoupon } from '../../models/user/UserCoupon' 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 { class GameUserController extends BaseController {
// TODO:: 增加返回未使用的券 // TODO:: 增加返回未使用的券
@ -86,5 +89,55 @@ class GameUserController extends BaseController {
throw new ZError(11, '无法找到对应店铺') throw new ZError(11, '无法找到对应店铺')
} }
let numInvite = await getShopInviteeNum(accountId, sessionid, shop.numid) 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<string, any> = new Map()
const gotSet: Set<string> = 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,
}
} }
} }

View File

@ -10,16 +10,20 @@ export class ShareCfgClass extends Base {
* @type {number} * @type {number}
*/ */
@prop() @prop()
public need_count: number public rank: number
@prop() @prop()
public name: string public coupon: string
@prop() @prop({ default: 0 })
public reward_type: string public count: number
@prop() /**
public reward_count: number *
* @type {number} 0: 优惠券, 1: 抽奖券
*/
@prop({ default: 0 })
public rewardType: number
@prop() @prop()
public icon: string public icon: string
@ -30,10 +34,17 @@ export class LotteryCfgClass extends Base {
public name: string public name: string
@prop() @prop()
public reward_type: string public coupon: string
@prop() @prop({ default: 0 })
public reward_count: number public count: number
/**
*
* @type {number} 0: 优惠券, 1: 抽奖券
*/
@prop({ default: 0 })
public rewardType: number
@prop() @prop()
public icon: string public icon: string