条件抽奖
一、功能概述
本模块提供直播间抽奖相关功能,包括初始化抽奖、获取抽奖信息、参与抽奖等功能。
二、Api 方法
2.1 初始化福利抽奖
说明: 初始化抽奖功能,获取抽奖详情并设置相关状态
Api 方法: initLottery(lotteryId: string): Promise<WelfareLotteryDetail>
参数说明:
- lotteryId:抽奖ID,
string类型,必传
返回值说明: 抽奖详情,Promise<WelfareLotteryDetail> 类型,详细类型说明如下
| 属性名 | 说明 | 类型 |
|---|---|---|
lotteryId |
抽奖 id | string |
prizeName |
奖品名称 | string |
realPrice |
优惠价 | number |
price |
原价 | number |
thumbnail |
奖品缩略图 | string |
amount |
中奖人数 | number |
lotteryCondition |
参与条件 | WelfareLotteryCondition |
lotteryRange |
抽奖用户范围 | WelfareLotteryRange |
customGroupLotteryType |
分组抽奖类型 | WelfareLotteryCustomGroupType |
endTime |
开奖时间,单位:时间戳 | number |
status |
抽奖状态 | WelfareLotteryStatus |
winnerIds |
中奖用户id列表 | string[] |
inviteNum |
邀请人数 | number |
inviteType |
邀请类型 | WelfareLotteryInviteType |
comment |
评论抽奖关键字 | string |
duration |
观看时长 | number |
hiddenWinnerAmount |
隐藏奖品数量 | YN |
viewerSize |
参与人数 | number |
hiddenAttendeeNumber |
隐藏参与人数 | YN |
示例:
// 初始化抽奖
const lotteryDetail = await watchCore.welfareLottery.initLottery('123456');
console.log('抽奖详情', lotteryDetail);
2.2 获取抽奖详情
说明: 获取指定抽奖活动的详细信息
Api 方法: getLotteryDetail(lotteryId: string): Promise<WelfareLotteryDetail>
参数说明:
- lotteryId:抽奖ID,
string类型,必传
返回值说明: 抽奖详情,Promise<WelfareLotteryDetail> 类型,详细类型说明如下
| 属性名 | 说明 | 类型 |
|---|---|---|
lotteryId |
抽奖 id | string |
prizeName |
奖品名称 | string |
realPrice |
优惠价 | number |
price |
原价 | number |
thumbnail |
奖品缩略图 | string |
amount |
中奖人数 | number |
lotteryCondition |
参与条件 | WelfareLotteryCondition |
lotteryRange |
抽奖用户范围 | WelfareLotteryRange |
customGroupLotteryType |
分组抽奖类型 | WelfareLotteryCustomGroupType |
endTime |
开奖时间,单位:时间戳 | number |
status |
抽奖状态 | WelfareLotteryStatus |
winnerIds |
中奖用户id列表 | string[] |
inviteNum |
邀请人数 | number |
inviteType |
邀请类型 | WelfareLotteryInviteType |
comment |
评论抽奖关键字 | string |
duration |
观看时长 | number |
hiddenWinnerAmount |
隐藏奖品数量 | YN |
viewerSize |
参与人数 | number |
hiddenAttendeeNumber |
隐藏参与人数 | YN |
示例:
// 获取抽奖详情
const detail = await watchCore.welfareLottery.getLotteryDetail('123456');
console.log('抽奖详情', detail);
2.3 获取抽奖完成情况
说明: 获取用户参与抽奖的完成情况,如观看时长、是否评论等
Api 方法: getLotteryFinishData(lotteryId?: string): Promise<WelfareLotteryFinishData>
参数说明:
- lotteryId:undefined,
string类型,选传
返回值说明: 抽奖完成情况,Promise<WelfareLotteryFinishData> 类型,详细类型说明如下
| 属性名 | 说明 | 类型 |
|---|---|---|
lotteryId |
抽奖 id | string |
viewerSize |
参与人数 | number |
condition |
参与条件 | WelfareLotteryCondition |
hasComment |
是否已参与评论 | YN |
duration |
已观看时长 | number |
inviteType |
邀请类型 | WelfareLotteryInviteType |
inviteCount |
邀请人数 | number |
示例:
// 获取抽奖完成情况
const finishData = await watchCore.welfareLottery.getLotteryFinishData();
console.log('抽奖完成情况', finishData);
2.4 获取中奖列表
说明: 获取抽奖活动的中奖用户列表
Api 方法: getLotteryWinners(options: Object): Promise<LotteryWinnersData>
参数说明:
- options:查询参数,
Object类型,必传,详细类型说明如下
| 参数名 | 说明 | 类型 | 必须 | 默认值 |
|---|---|---|---|---|
pageNumber |
- | number |
否 | - |
lotteryId |
抽奖ID | string |
是 | - |
返回值说明: 中奖名单数据,Promise<LotteryWinnersData> 类型,详细类型说明如下
| 属性名 | 说明 | 类型 |
|---|---|---|
contents |
获奖列表 | LotteryWinnerItem[] |
pageNumber |
当前页码 | number |
pageSize |
每页条数 | number |
totalItems |
总条数 | number |
totalPages |
总页数 | number |
示例:
// 获取中奖名单
const winners = await watchCore.welfareLottery.getLotteryWinners({
lotteryId: '123456'
});
console.log('中奖名单', winners);
2.5 完成评论抽奖
说明: 提交评论完成评论类型的抽奖参与条件
Api 方法: finishCommentLottery(options: Object): Promise<void>
参数说明:
- options:参数,
Object类型,必传,详细类型说明如下
| 参数名 | 说明 | 类型 | 必须 | 默认值 |
|---|---|---|---|---|
comment |
评论内容 | string |
是 | - |
示例:
// 提交评论参与抽奖
await watchCore.welfareLottery.finishCommentLottery({
comment: '我要参与抽奖'
});
说明: 获取抽奖活动的奖品详细信息
Api 方法: getLotteryPrize(lotteryId: string): Promise<WelfareLotteryPrize>
参数说明:
- lotteryId:抽奖ID,
string类型,必传
返回值说明: 抽奖奖品信息,Promise<WelfareLotteryPrize> 类型,详细类型说明如下
| 属性名 | 说明 | 类型 |
|---|---|---|
acceptType |
领奖方式 | PrizeAcceptType |
channelId |
频道ID | string |
formList |
领奖表单 | PrizeFromItem[] |
hasObtain |
是否已领奖,当acceptType为form时有效 | boolean |
lotteryId |
抽奖ID | string |
prizeUrl |
领奖url | string |
recordId |
中奖ID | string |
qrCode |
领奖二维码 | string |
qrCodeTips |
领奖二维码提示语 | string |
winnerCode |
中奖码 | string |
示例:
// 获取抽奖奖品信息
const prizeInfo = await watchCore.welfareLottery.getLotteryPrize('123456');
console.log('抽奖奖品信息', prizeInfo);
2.6 获取抽奖记录
说明: 获取用户参与的抽奖活动记录
Api 方法: getLotteryRecord(options: Object): Promise<LotteryRecordData>
参数说明:
- options:查询参数,
Object类型,必传,详细类型说明如下
| 参数名 | 说明 | 类型 | 必须 | 默认值 |
|---|---|---|---|---|
pageNumber |
- | number |
否 | - |
pageSize |
- | number |
否 | - |
返回值说明: 抽奖记录数据,Promise<LotteryRecordData> 类型,详细类型说明如下
| 属性名 | 说明 | 类型 |
|---|---|---|
contents |
获奖列表 | LotteryRecordItem[] |
pageNumber |
当前页码 | number |
pageSize |
每页条数 | number |
totalItems |
总条数 | number |
totalPages |
总页数 | number |
示例:
// 获取抽奖记录
const records = await watchCore.welfareLottery.getLotteryRecord({
pageNumber: 1,
pageSize: 20
});
console.log('抽奖记录', records);
2.7 获取领奖信息表单配置
说明: 获取抽奖活动的领奖信息表单配置,用于中奖后填写领奖信息
Api 方法: getLotteryReceive(options: Object): Promise<LotteryReceiveData>
参数说明:
- options:查询参数,
Object类型,必传,详细类型说明如下
| 参数名 | 说明 | 类型 | 必须 | 默认值 |
|---|---|---|---|---|
lotteryId |
抽奖ID | string |
是 | - |
返回值说明: 领奖信息表单配置,Promise<LotteryReceiveData> 类型,详细类型说明如下
| 属性名 | 说明 | 类型 |
|---|---|---|
acceptType |
领奖方式 | LotteryAcceptType |
formList |
表单列表 | LotteryReceiveFormItem[] |
hasObtain |
是否已领取 | boolean |
lotteryId |
抽奖 id | string |
prizeUrl |
奖品领取地址 | null | string |
qrCode |
二维码地址 | string |
qrCodeTips |
二维码提示 | string |
recordId |
纪录 id | string |
winnerCode |
兑换码 | string |
示例:
// 获取领奖信息表单
const receiveForm = await watchCore.welfareLottery.getLotteryReceive({
lotteryId: '123456'
});
console.log('领奖表单', receiveForm);
2.8 提交领奖人信息
说明: 提交中奖者的领奖信息,包括姓名、联系方式等
Api 方法: submitReceive(options: Object): Promise<void>
参数说明:
- options:提交参数,
Object类型,必传,详细类型说明如下
| 参数名 | 说明 | 类型 | 必须 | 默认值 |
|---|---|---|---|---|
lotteryId |
抽奖ID | string |
是 | - |
winnerCode |
中奖码 | string |
是 | - |
receiveInfo |
领奖人信息表单数据 | LotteryReceiveFormItem[] |
是 | - |
示例:
// 提交领奖信息
await watchCore.welfareLottery.submitReceive({
lotteryId: '123456',
winnerCode: '123456',
receiveInfo: [{
key: 'name',
value: '张三'
}]
});
2.9 获取抽奖隐私协议内容
说明: 获取抽奖活动的隐私协议内容
Api 方法: getLotteryPrivacy(): LotteryPrivacyDetail
返回值说明: 抽奖隐私协议内容,LotteryPrivacyDetail 类型,详细类型说明如下
| 属性名 | 说明 | 类型 |
|---|---|---|
privacyContent |
抽奖隐私协议内容 | undefined | string |
lotteryActivityPrivacyEnabled |
抽奖活动隐私协议开关 | YN |
示例:
// 获取抽奖隐私协议内容
const privacy = await watchCore.welfareLottery.getLotteryPrivacy();
console.log('抽奖隐私协议内容', privacy);
2.10 获取抽奖分组信息
说明: 获取抽奖活动的分组信息
Api 方法: getLotteryWinnersGroup(options: Object): Promise<LotteryWinnerGroupItem[]>
参数说明:
- options:查询参数,
Object类型,必传,详细类型说明如下
| 参数名 | 说明 | 类型 | 必须 | 默认值 |
|---|---|---|---|---|
lotteryId |
抽奖ID | string |
是 | - |
返回值说明: 抽奖分组信息列表,Promise<LotteryWinnerGroupItem[]> 类型
示例:
// 获取抽奖分组信息
const groupInfo = await watchCore.welfareLottery.getLotteryWinnersGroup({
lotteryId: '123456'
});
console.log('抽奖分组信息', groupInfo);
2.11 获取抽奖分组中的中奖名单
说明: 获取抽奖活动特定分组中的中奖用户列表
Api 方法: getLotteryWinnersByGroup(options: Object): Promise<LotteryWinnersData>
参数说明:
- options:查询参数,
Object类型,必传,详细类型说明如下
| 参数名 | 说明 | 类型 | 必须 | 默认值 |
|---|---|---|---|---|
pageNumber |
- | number |
否 | - |
lotteryId |
抽奖ID | string |
是 | - |
groupId |
分组ID | number |
是 | - |
返回值说明: 分组中的中奖名单数据,Promise<LotteryWinnersData> 类型,详细类型说明如下
| 属性名 | 说明 | 类型 |
|---|---|---|
contents |
获奖列表 | LotteryWinnerItem[] |
pageNumber |
当前页码 | number |
pageSize |
每页条数 | number |
totalItems |
总条数 | number |
totalPages |
总页数 | number |
示例:
// 获取特定分组的中奖名单
const groupWinners = await watchCore.welfareLottery.getLotteryWinnersByGroup({
lotteryId: '123456',
groupId: 1
});
console.log('分组中奖名单', groupWinners);
2.12 获取当前观看时间
说明: 获取当前观看时间
Api 方法: getLotteryWatchTime(): number
返回值说明: 当前观看时间
示例:
const watchTime = watchCore.welfareLottery.getLotteryWatchTime();
console.log('当前观看时间', watchTime);
三、模块事件
3.1 开始抽奖事件
说明: 当福利抽奖活动开始时触发
Event 事件: WelfareLotteryEvents.StartLottery
回调参数: Object 对象,详细类型说明如下
| 属性名 | 说明 | 类型 |
|---|---|---|
lotteryId |
抽奖 id | string |
lotteryDetail |
抽奖详情 | WelfareLotteryDetail |
示例:
watchCore.welfareLottery.eventEmitter.on(WelfareLotteryEvents.StartLottery, (data) => {
console.log('抽奖活动开始', data.lotteryId, data.lotteryDetail);
});
3.2 结束抽奖事件
说明: 当福利抽奖活动结束时触发
Event 事件: WelfareLotteryEvents.EndLottery
回调参数: Object 对象,详细类型说明如下
| 属性名 | 说明 | 类型 |
|---|---|---|
lotteryId |
抽奖 id | string |
lotteryDetail |
抽奖详情 | WelfareLotteryDetail |
示例:
watchCore.welfareLottery.eventEmitter.on(WelfareLotteryEvents.EndLottery, (data) => {
console.log('抽奖活动结束', data.lotteryId, data.lotteryDetail);
});
3.3 观看时长更改事件
说明: 当用户观看时长发生变化时触发
Event 事件: WelfareLotteryEvents.WatchTimeChange
回调参数: Object 对象,详细类型说明如下
| 属性名 | 说明 | 类型 |
|---|---|---|
watchTime |
观看时长(单位:秒) | number |
示例:
watchCore.welfareLottery.eventEmitter.on(WelfareLotteryEvents.WatchTimeChange, (data) => {
console.log('观看时长更新', data.watchTime);
});
