使用方式
一、获取当前抽奖活动列表
通过 getLotteryList 获取当前所有可用的抽奖活动列表。
Api 方法: getLotteryList(): LotteryBasicData[]
返回值说明: 抽奖活动列表,LotteryBasicData[] 类型
示例:
const lotteryList = lotteryTarget.getLotteryList();
console.log('当前抽奖活动列表', lotteryList);
二、获取抽奖详情
通过 getLotteryDetail 获取指定抽奖活动的详细信息。
Api 方法: getLotteryDetail(options: LotteryBasicOptions): Promise<undefined | LotteryDetail>
参数说明:
- options:获取参数,包含抽奖ID和抽奖条件,
LotteryBasicOptions类型,必传,详细类型说明如下
| 参数名 | 说明 | 类型 | 必须 | 默认值 |
|---|---|---|---|---|
lotteryId |
- | string |
是 | - |
subLotteryId |
- | string |
否 | - |
lotteryCondition |
- | LotteryCondition |
否 | - |
返回值说明: 抽奖详情,Promise<undefined | LotteryDetail> 类型
示例:
const detail = await lotteryTarget.getLotteryDetail({ lotteryId: 'xxxx' });
console.log('抽奖详情', detail);
三、获取抽奖结果
在抽奖抽出了中奖结果之后,可调用该方法获取指定 lotteryId 的中奖结果。
Api 方法: getLotteryResult(options: LotteryBasicOptions): Promise<undefined | LotteryResult>
参数说明:
- options:获取参数,包含抽奖ID和抽奖条件,
LotteryBasicOptions类型,必传,详细类型说明如下
| 参数名 | 说明 | 类型 | 必须 | 默认值 |
|---|---|---|---|---|
lotteryId |
- | string |
是 | - |
subLotteryId |
- | string |
否 | - |
lotteryCondition |
- | LotteryCondition |
否 | - |
返回值说明: 抽奖结果,Promise<undefined | LotteryResult> 类型
示例:
const lotteryResult = await lotteryTarget.getLotteryResult({ lotteryId: 'xxxx' });
console.log('抽奖结果', lotteryResult);
console.log('是否中奖', lotteryResult.isWinner);
console.log('奖品信息', lotteryResult.prizeInfo);
四、发送评论抽奖的评论内容
通过 sendComment 发送评论抽奖的评论内容。
Api 方法: sendComment(): Promise<void>
示例:
await lotteryTarget.sendComment();
console.log('评论已发送');
五、检查评论的内容是否符合评论抽奖的条件
通过 checkComment 检查评论内容是否符合评论抽奖的条件。
Api 方法: checkComment(comment: string): Promise<void>
参数说明:
- comment:评论的内容,
string类型,必传
示例:
await lotteryTarget.checkComment('这是一条评论');
console.log('评论检查完成');
六、完成评论抽奖
通过 finishComment 完成评论抽奖流程。
Api 方法: finishComment(): Promise<void>
示例:
await lotteryTarget.finishComment();
console.log('评论抽奖已完成');
七、开始答题
通过 startAnswer 开始答题抽奖流程。
Api 方法: startAnswer(): Promise<StartLotteryAnswerResult>
返回值说明: 答题开始结果,Promise<StartLotteryAnswerResult> 类型
示例:
const result = await lotteryTarget.startAnswer();
console.log('答题开始,当前正在答题的题目 id', result.questionId);
八、获取最近一次的答题结果
通过 getLastAnswerResult 获取最近一次的答题结果。
Api 方法: getLastAnswerResult(): Promise<undefined | AnswerResultData>
返回值说明: 答题结果,Promise<undefined | AnswerResultData> 类型
示例:
const result = await lotteryTarget.getLastAnswerResult();
console.log('最近答题结果', result);
console.log('是否正确', result.result);
九、提交答题
通过 submitAnswer 提交答题抽奖的答案。
Api 方法: submitAnswer(params: SubmitAnswerParams): Promise<SubmitAnswerResult>
参数说明:
- params:提交答题参数,
SubmitAnswerParams类型,必传,详细类型说明如下
| 参数名 | 说明 | 类型 | 必须 | 默认值 |
|---|---|---|---|---|
questionId |
题目 id | string |
是 | - |
answer |
答案 | string |
是 | - |
返回值说明: 答题提交结果,Promise<SubmitAnswerResult> 类型
示例:
const result = await lotteryTarget.submitAnswer({
questionId: 'xxxx',
answer: 'ab'
});
console.log('答题提交结果', result);
console.log('是否正确', result.result);
十、获取个人中奖记录
通过 getPersonalWinning 获取当前观众的中奖列表,并显示到页面。
Api 方法: getPersonalWinning(options?: PageOptions): Promise<PageContent<LotteryRecordData>>
参数说明:
- options:分页选项,
PageOptions类型,选传,默认{},详细类型说明如下
| 参数名 | 说明 | 类型 | 必须 | 默认值 |
|---|---|---|---|---|
pageNumber |
页数 | number |
否 | - |
pageSize |
页码 | number |
否 | - |
返回值说明: 中奖记录列表,Promise<PageContent<LotteryRecordData>> 类型,详细类型说明如下
| 属性名 | 说明 | 类型 |
|---|---|---|
pageNumber |
当前页数 | number |
pageSize |
每页数量 | number |
totalItems |
总记录数 | number |
totalPages |
总页数 | number |
contents |
内容列表 | I[] |
示例:
const data = await lotteryTarget.getPersonalWinning({ pageNumber: 1 });
console.log('中奖记录列表', data.contents);
十一、获取中奖领取信息
通过 lotteryId 获取该次抽奖的中奖信息,用于显示信息填写、二维码、链接等交互。
Api 方法: getLotteryReceive(options: Object): Promise<LotteryReceiveData>
参数说明:
- options:获取参数,
Object类型,必传,详细类型说明如下
| 参数名 | 说明 | 类型 | 必须 | 默认值 |
|---|---|---|---|---|
lotteryId |
抽奖 id | string |
是 | - |
返回值说明: 中奖领取信息,Promise<LotteryReceiveData> 类型,详细类型说明如下
| 属性名 | 说明 | 类型 |
|---|---|---|
prizeInfo |
奖品信息 | LotteryPrizeInfo |
acceptType |
领奖方式 | PrizeAcceptType |
formList |
表单列表 | LotteryReceiveFormItem[] |
received |
是否已领取 | boolean |
lotteryId |
抽奖 id | string |
lotteryCondition |
抽奖条件 | LotteryCondition |
prizeUrl |
奖品领取地址 | null | string |
qrCode |
二维码地址 | string |
qrCodeTips |
二维码提示 | string |
winnerCode |
兑换码 | string |
showWinnerCode |
是否显示兑换码 | boolean |
overTime |
中奖信息提交截止时间 | null | number |
示例:
import { PrizeAcceptType } from '@polyv/iar-lottery-sdk';
const receiveData = await lotteryTarget.getLotteryReceive({ lotteryId: 'xxxx' });
console.log('领取方式:', receiveData.acceptType);
console.log('表单结构与中奖截止时间:', receiveData.formList, receiveData.overTime);
console.log('领取链接:', receiveData.prizeUrl);
console.log('二维码信息:', receiveData.qrCode, receiveData.qrCodeTips);
十二、提交领取信息
当中奖设置了需要采集中奖信息后,可通过 submitReceive 提交中奖者的领取信息。
Api 方法: submitReceive(options: SubmitReceiveOptions): Promise<void>
参数说明:
- options:提交参数,
SubmitReceiveOptions类型,必传,详细类型说明如下
| 参数名 | 说明 | 类型 | 必须 | 默认值 |
|---|---|---|---|---|
lotteryId |
抽奖 id | string |
是 | - |
winnerCode |
兑换码 | string |
是 | - |
receiveInfo |
领取信息 | LotteryReceiveFormItem[] |
是 | - |
示例:
const receiveInfo = [
{ field: '姓名', value: '张三' },
{ field: '手机', value: '18012345678' },
{ field: '地址', value: '广东省广州市番禺区xxxx' }
];
await lotteryTarget.submitReceive({
lotteryId: 'xxxx',
winnerCode: 'xxxx',
receiveInfo,
});
toast('提交成功');
十三、获取中奖者分组列表
通过 getLotteryWinnersGroup 获取中奖者分组列表,用于显示到页面。
Api 方法: getLotteryWinnersGroup(options: Object): Promise<LotteryWinnersGroup[]>
参数说明:
- options:获取参数,
Object类型,必传,详细类型说明如下
| 参数名 | 说明 | 类型 | 必须 | 默认值 |
|---|---|---|---|---|
lotteryId |
- | string |
是 | - |
返回值说明: 中奖者分组列表,Promise<LotteryWinnersGroup[]> 类型
示例:
const data = await lotteryTarget.getLotteryWinnersGroup({ lotteryId: 'xxxx' });
console.log('中奖者分组列表', data);
// 通过分组 id 获取中奖者列表
const winners = await lotteryTarget.getLotteryWinners({ lotteryId: 'xxxx', groupId: data[0].id });
console.log('中奖者列表', winners.contents);
十四、获取中奖者列表
通过 getLotteryWinners 获取指定抽奖活动的中奖者列表。
Api 方法: getLotteryWinners(options: GetLotteryWinnersOptions): Promise<PageContent<LotteryWinnersData>>
参数说明:
- options:获取参数,包含抽奖ID、分组ID、页码和每页数量,
GetLotteryWinnersOptions类型,必传,详细类型说明如下
| 参数名 | 说明 | 类型 | 必须 | 默认值 |
|---|---|---|---|---|
pageNumber |
页数 | number |
否 | - |
pageSize |
页码 | number |
否 | - |
lotteryId |
抽奖 id | string |
是 | - |
groupId |
分组 id | number |
否 | - |
返回值说明: 中奖者列表,Promise<PageContent<LotteryWinnersData>> 类型,详细类型说明如下
| 属性名 | 说明 | 类型 |
|---|---|---|
pageNumber |
当前页数 | number |
pageSize |
每页数量 | number |
totalItems |
总记录数 | number |
totalPages |
总页数 | number |
contents |
内容列表 | I[] |
示例:
const data = await lotteryTarget.getLotteryWinners({ lotteryId: 'xxxx' });
console.log('中奖者列表', data.contents);
