增加挑战抽奖券的返回

This commit is contained in:
zhl 2021-06-07 12:39:19 +08:00
parent 8428f78731
commit acd6b01439
6 changed files with 101 additions and 11 deletions

View File

@ -6,6 +6,7 @@
1. [增加用户信息](#212), [抽奖转盘信息](#213), [抽奖](#214), [邀请奖励信息](#215), [挑战详情](#216) 接口
2. 所有接口增加post字段 version(当前版本固定取1.0.1)和sessionid(取自jcfw)
3. 获取店铺信息 增加返回店铺的数字编号
4. 上报测验题目答案接口的 奖励信息 增加返回rewardType, 0: 表明该奖励为优惠券, 1: 抽奖券
@ -306,7 +307,8 @@
name: '优惠券名',
count: 1, //数量
couponUrl: '优惠券详情图的url',
ids: ['获取记录的短id']
ids: ['获取记录的短id'],
rewardType: 0 //奖励类型 0: 优惠券 1: 抽奖券
}]
}
```

View File

@ -6,6 +6,8 @@ import { getRandom } from '../../utils/number.util'
import { UserReward } from '../../models/user/UserReward'
import { UserItem } from '../../models/user/UserItem'
import { LOTTERY_TICKET } from '../../constants/BaseConst'
import { getShopInviteeNum } from '../../services/JCFW'
import { Shop } from '../../models/shop/Shop'
class GameUserController extends BaseController {
// TODO:: 增加返回未使用的券
@ -58,9 +60,17 @@ class GameUserController extends BaseController {
@role('anon')
@router('post /api/:accountId/info')
async userInfo(req: any) {
const { accountId, sid } = req.params
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 result: any = {}
result.tocket_lottery = await UserItem.fetchCount({ accountId, shop: sid, item: LOTTERY_TICKET })
let numInvite = await getShopInviteeNum(accountId, sessionid, shop.numid)
return result
}

View File

@ -61,6 +61,13 @@ export class ExamRewardClass extends Base {
@prop({ default: 0 })
public count: number
/**
*
* @type {number} 0: 优惠券, 1: 抽奖券
*/
@prop({ default: 0 })
public rewardType: number
/**
*
* @type {number} 0: 单局, 1: 累积

View File

@ -1,4 +1,4 @@
import { getModelForClass, index, modelOptions, mongoose, prop, Severity } from '@typegoose/typegoose'
import { getModelForClass, index, modelOptions, mongoose, post, prop, Severity } from '@typegoose/typegoose'
import { dbconn } from '../../decorators/dbconn'
import { BaseModule } from '../Base'
@ -25,6 +25,14 @@ class ItemRecordClass extends BaseModule {
public count: number
@prop()
public reason: string
/**
*
* @type {number} 0: 抽奖券
*/
@prop()
public type: number
@prop({ type: mongoose.Schema.Types.Mixed })
public data: {}

View File

@ -7,9 +7,17 @@ import { Shop } from '../shop/Shop'
import { Coupon } from '../shop/Coupon'
import { getCouponUrl } from '../../services/File'
import { PuzzleSessionClass } from '../match/PuzzleSession'
import { LOTTERY_TICKET } from '../../constants/BaseConst'
const nanoid = customAlphabet('2345678abcdefghjkmnpqrstwxy', 10)
/**
*
* 1.
* 2.
* 3.
*/
@dbconn()
@index({ accountId: 1 }, { unique: false })
@index({ accountId: 1, shop: 1 }, { unique: false })
@ -47,7 +55,10 @@ class UserRewardClass extends BaseModule {
*/
@prop()
public activityId: string
/**
* PuzzleSession的id
* @type {string}
*/
@prop()
public sessionId: string
/**
@ -56,7 +67,10 @@ class UserRewardClass extends BaseModule {
*/
@prop()
public coupon: string
/**
* id
* @type {string}
*/
@prop()
public rewardId: string
@ -70,6 +84,16 @@ class UserRewardClass extends BaseModule {
@prop()
public status: number
/**
*
* @type {number} 0: 优惠券, 1: 抽奖券
*/
@prop({ default: 0 })
public rewardType: number
@prop({ default: 1 })
public count: number
public static async ticketList(accountId: string, shopId?: string) {
let params: any = { accountId }
let shopMap: Map<string, string> = new Map()
@ -124,8 +148,7 @@ class UserRewardClass extends BaseModule {
count: number,
) {
let ids: string[] = []
let cdata = await Coupon.findById(coupon)
for (let i = 0; i < count; i++) {
let saveRecord = async function (rewardType: number, cCount: number) {
let record = new UserReward({
accountId,
shop: history.shop,
@ -133,6 +156,8 @@ class UserRewardClass extends BaseModule {
status: 0,
rewardId,
coupon,
rewardType,
count: cCount,
})
if (history.type === 1) {
record.activityId = history.activityId
@ -142,12 +167,30 @@ class UserRewardClass extends BaseModule {
await record.save()
ids.push(record.sid)
}
let name = ''
let url = ''
let rewardType = 0
if (coupon === LOTTERY_TICKET) {
rewardType = 1
await saveRecord(1, count)
name = '抽奖券'
} else {
rewardType = 0
let cdata = await Coupon.findById(coupon)
for (let i = 0; i < count; i++) {
await saveRecord(0, 1)
}
name = cdata.name
url = getCouponUrl(history.shop, coupon)
}
return {
coupon,
name: cdata.name,
name,
count,
couponUrl: getCouponUrl(history.shop, coupon),
couponUrl: url,
ids,
rewardType,
}
}

View File

@ -2,8 +2,7 @@ import axios from 'axios'
import { ZError } from '../common/ZError'
/**
*
* @return {Promise<void>}
* ()
*/
export async function getInviteeNum(accountId: string, sessionId: string, shops: number[]) {
const url = 'https://service.kingsome.cn/webapp/index.php?c=AchievementShare&a=getInviteeNum'
@ -22,6 +21,27 @@ export async function getInviteeNum(accountId: string, sessionId: string, shops:
})
}
/**
* ()
*
* @param {string} accountId
* @param {string} sessionId
* @param {number} shop
*/
export async function getShopInviteeNum(accountId: string, sessionId: string, shop: number) {
let records = await getInviteeNum(accountId, sessionId, [shop])
let num = 0
if (records?.length > 0) {
for (let obj of records) {
if (obj.hasOwnProperty(shop)) {
num = obj[shop]
break
}
}
}
return num
}
/**
*
* @return {Promise<void>}