增加挑战抽奖券的返回
This commit is contained in:
parent
8428f78731
commit
acd6b01439
@ -6,6 +6,7 @@
|
|||||||
1. [增加用户信息](#212), [抽奖转盘信息](#213), [抽奖](#214), [邀请奖励信息](#215), [挑战详情](#216) 接口
|
1. [增加用户信息](#212), [抽奖转盘信息](#213), [抽奖](#214), [邀请奖励信息](#215), [挑战详情](#216) 接口
|
||||||
2. 所有接口增加post字段 version(当前版本固定取1.0.1)和sessionid(取自jcfw)
|
2. 所有接口增加post字段 version(当前版本固定取1.0.1)和sessionid(取自jcfw)
|
||||||
3. 获取店铺信息 增加返回店铺的数字编号
|
3. 获取店铺信息 增加返回店铺的数字编号
|
||||||
|
4. 上报测验题目答案接口的 奖励信息 增加返回rewardType, 0: 表明该奖励为优惠券, 1: 抽奖券
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@ -306,7 +307,8 @@
|
|||||||
name: '优惠券名',
|
name: '优惠券名',
|
||||||
count: 1, //数量
|
count: 1, //数量
|
||||||
couponUrl: '优惠券详情图的url',
|
couponUrl: '优惠券详情图的url',
|
||||||
ids: ['获取记录的短id']
|
ids: ['获取记录的短id'],
|
||||||
|
rewardType: 0 //奖励类型 0: 优惠券 1: 抽奖券
|
||||||
}]
|
}]
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
@ -6,6 +6,8 @@ import { getRandom } from '../../utils/number.util'
|
|||||||
import { UserReward } from '../../models/user/UserReward'
|
import { UserReward } from '../../models/user/UserReward'
|
||||||
import { UserItem } from '../../models/user/UserItem'
|
import { UserItem } from '../../models/user/UserItem'
|
||||||
import { LOTTERY_TICKET } from '../../constants/BaseConst'
|
import { LOTTERY_TICKET } from '../../constants/BaseConst'
|
||||||
|
import { getShopInviteeNum } from '../../services/JCFW'
|
||||||
|
import { Shop } from '../../models/shop/Shop'
|
||||||
|
|
||||||
class GameUserController extends BaseController {
|
class GameUserController extends BaseController {
|
||||||
// TODO:: 增加返回未使用的券
|
// TODO:: 增加返回未使用的券
|
||||||
@ -58,9 +60,17 @@ class GameUserController extends BaseController {
|
|||||||
@role('anon')
|
@role('anon')
|
||||||
@router('post /api/:accountId/info')
|
@router('post /api/:accountId/info')
|
||||||
async userInfo(req: any) {
|
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 = {}
|
let result: any = {}
|
||||||
result.tocket_lottery = await UserItem.fetchCount({ accountId, shop: sid, item: LOTTERY_TICKET })
|
result.tocket_lottery = await UserItem.fetchCount({ accountId, shop: sid, item: LOTTERY_TICKET })
|
||||||
|
let numInvite = await getShopInviteeNum(accountId, sessionid, shop.numid)
|
||||||
|
|
||||||
return result
|
return result
|
||||||
}
|
}
|
||||||
|
@ -61,6 +61,13 @@ export class ExamRewardClass extends Base {
|
|||||||
@prop({ default: 0 })
|
@prop({ default: 0 })
|
||||||
public count: number
|
public count: number
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 奖励类型
|
||||||
|
* @type {number} 0: 优惠券, 1: 抽奖券
|
||||||
|
*/
|
||||||
|
@prop({ default: 0 })
|
||||||
|
public rewardType: number
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 奖励类型
|
* 奖励类型
|
||||||
* @type {number} 0: 单局, 1: 累积
|
* @type {number} 0: 单局, 1: 累积
|
||||||
|
@ -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 { dbconn } from '../../decorators/dbconn'
|
||||||
import { BaseModule } from '../Base'
|
import { BaseModule } from '../Base'
|
||||||
|
|
||||||
@ -25,6 +25,14 @@ class ItemRecordClass extends BaseModule {
|
|||||||
public count: number
|
public count: number
|
||||||
@prop()
|
@prop()
|
||||||
public reason: string
|
public reason: string
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 物品类型
|
||||||
|
* @type {number} 0: 抽奖券
|
||||||
|
*/
|
||||||
|
@prop()
|
||||||
|
public type: number
|
||||||
|
|
||||||
@prop({ type: mongoose.Schema.Types.Mixed })
|
@prop({ type: mongoose.Schema.Types.Mixed })
|
||||||
public data: {}
|
public data: {}
|
||||||
|
|
||||||
|
@ -7,9 +7,17 @@ import { Shop } from '../shop/Shop'
|
|||||||
import { Coupon } from '../shop/Coupon'
|
import { Coupon } from '../shop/Coupon'
|
||||||
import { getCouponUrl } from '../../services/File'
|
import { getCouponUrl } from '../../services/File'
|
||||||
import { PuzzleSessionClass } from '../match/PuzzleSession'
|
import { PuzzleSessionClass } from '../match/PuzzleSession'
|
||||||
|
import { LOTTERY_TICKET } from '../../constants/BaseConst'
|
||||||
|
|
||||||
const nanoid = customAlphabet('2345678abcdefghjkmnpqrstwxy', 10)
|
const nanoid = customAlphabet('2345678abcdefghjkmnpqrstwxy', 10)
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 用户挑战或活动获得的奖励记录
|
||||||
|
* 1. 用于判断某活动或挑战的奖励是否已经领取
|
||||||
|
* 2. 用于获取用户的优惠券列表
|
||||||
|
* 3. 用于抽奖券的部分获取记录
|
||||||
|
*/
|
||||||
|
|
||||||
@dbconn()
|
@dbconn()
|
||||||
@index({ accountId: 1 }, { unique: false })
|
@index({ accountId: 1 }, { unique: false })
|
||||||
@index({ accountId: 1, shop: 1 }, { unique: false })
|
@index({ accountId: 1, shop: 1 }, { unique: false })
|
||||||
@ -47,7 +55,10 @@ class UserRewardClass extends BaseModule {
|
|||||||
*/
|
*/
|
||||||
@prop()
|
@prop()
|
||||||
public activityId: string
|
public activityId: string
|
||||||
|
/**
|
||||||
|
* PuzzleSession的id
|
||||||
|
* @type {string}
|
||||||
|
*/
|
||||||
@prop()
|
@prop()
|
||||||
public sessionId: string
|
public sessionId: string
|
||||||
/**
|
/**
|
||||||
@ -56,7 +67,10 @@ class UserRewardClass extends BaseModule {
|
|||||||
*/
|
*/
|
||||||
@prop()
|
@prop()
|
||||||
public coupon: string
|
public coupon: string
|
||||||
|
/**
|
||||||
|
* 活动或挑战中奖励配置id
|
||||||
|
* @type {string}
|
||||||
|
*/
|
||||||
@prop()
|
@prop()
|
||||||
public rewardId: string
|
public rewardId: string
|
||||||
|
|
||||||
@ -70,6 +84,16 @@ class UserRewardClass extends BaseModule {
|
|||||||
@prop()
|
@prop()
|
||||||
public status: number
|
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) {
|
public static async ticketList(accountId: string, shopId?: string) {
|
||||||
let params: any = { accountId }
|
let params: any = { accountId }
|
||||||
let shopMap: Map<string, string> = new Map()
|
let shopMap: Map<string, string> = new Map()
|
||||||
@ -124,8 +148,7 @@ class UserRewardClass extends BaseModule {
|
|||||||
count: number,
|
count: number,
|
||||||
) {
|
) {
|
||||||
let ids: string[] = []
|
let ids: string[] = []
|
||||||
let cdata = await Coupon.findById(coupon)
|
let saveRecord = async function (rewardType: number, cCount: number) {
|
||||||
for (let i = 0; i < count; i++) {
|
|
||||||
let record = new UserReward({
|
let record = new UserReward({
|
||||||
accountId,
|
accountId,
|
||||||
shop: history.shop,
|
shop: history.shop,
|
||||||
@ -133,6 +156,8 @@ class UserRewardClass extends BaseModule {
|
|||||||
status: 0,
|
status: 0,
|
||||||
rewardId,
|
rewardId,
|
||||||
coupon,
|
coupon,
|
||||||
|
rewardType,
|
||||||
|
count: cCount,
|
||||||
})
|
})
|
||||||
if (history.type === 1) {
|
if (history.type === 1) {
|
||||||
record.activityId = history.activityId
|
record.activityId = history.activityId
|
||||||
@ -142,12 +167,30 @@ class UserRewardClass extends BaseModule {
|
|||||||
await record.save()
|
await record.save()
|
||||||
ids.push(record.sid)
|
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 {
|
return {
|
||||||
coupon,
|
coupon,
|
||||||
name: cdata.name,
|
name,
|
||||||
count,
|
count,
|
||||||
couponUrl: getCouponUrl(history.shop, coupon),
|
couponUrl: url,
|
||||||
ids,
|
ids,
|
||||||
|
rewardType,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2,8 +2,7 @@ import axios from 'axios'
|
|||||||
import { ZError } from '../common/ZError'
|
import { ZError } from '../common/ZError'
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 查询接受邀请的人数
|
* 查询接受邀请的人数(多店)
|
||||||
* @return {Promise<void>}
|
|
||||||
*/
|
*/
|
||||||
export async function getInviteeNum(accountId: string, sessionId: string, shops: number[]) {
|
export async function getInviteeNum(accountId: string, sessionId: string, shops: number[]) {
|
||||||
const url = 'https://service.kingsome.cn/webapp/index.php?c=AchievementShare&a=getInviteeNum'
|
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>}
|
* @return {Promise<void>}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user