diff --git a/src/plugins/Mys/index.ts b/src/plugins/Mys/index.ts index 6ad7ccb8..b4241411 100644 --- a/src/plugins/Mys/index.ts +++ b/src/plugins/Mys/index.ts @@ -16,6 +16,7 @@ import { getNoticeList, getActivityList, getNewsList } from "./request/news"; import { getNoticeCard, getActivityCard, getNewsCard } from "./utils/news"; // Lottery import { getLotteryData } from "./request/lottery"; +import { getLotteryCard, getLotteryRewardCard } from "./utils/lottery"; const MysOper = { Post: { @@ -40,6 +41,10 @@ const MysOper = { }, Lottery: { get: getLotteryData, + card: { + lottery: getLotteryCard, + reward: getLotteryRewardCard, + } }, }; diff --git a/src/plugins/Mys/interface/lottery.ts b/src/plugins/Mys/interface/lottery.ts index b95f2fc4..6753416f 100644 --- a/src/plugins/Mys/interface/lottery.ts +++ b/src/plugins/Mys/interface/lottery.ts @@ -81,3 +81,40 @@ export interface LotteryReward { users: User[]; id: string; } + +/** + * @description 渲染用的抽奖信息 + * @since Alpha v0.1.1 + * @interface LotteryCard + * @property {string} id 抽奖 ID + * @property {string} participantWay 参与方式 + * @property {string} status 状态 + * @property {User} creator 创建者 + * @property {string} drawTime 开奖时间 + * @property {LotteryRewardCard[]} rewards 奖励列表 + * @return {LotteryCard} + */ +export interface LotteryCard { + id: string; + participantWay: string; + status: string; + creator: User; + drawTime: string; + rewards: LotteryRewardCard[]; +} + +/** + * @description 渲染用的奖励信息 + * @since Alpha v0.1.1 + * @interface LotteryRewardCard + * @property {string} rewardName 奖励名称 + * @property {number} winnerNumber 获奖人数 + * @property {number} scheduledWinnerNumber 预计获奖人数 + * @property {User[]} users 用户列表 + */ +export interface LotteryRewardCard { + rewardName: string; + winnerNumber: number; + scheduledWinnerNumber: number; + users: User[]; +} diff --git a/src/plugins/Mys/utils/lottery.ts b/src/plugins/Mys/utils/lottery.ts new file mode 100644 index 00000000..533e4039 --- /dev/null +++ b/src/plugins/Mys/utils/lottery.ts @@ -0,0 +1,42 @@ +/** + * @file plugins Mys utils lottery.ts + * @description 抽奖工具类 + * @author BTMuli + * @since Alpha v0.1.1 + */ + +import { LotteryData, LotteryCard, LotteryRewardCard, LotteryReward } from "../interface/lottery"; + +/** + * @description 根据抽奖信息转为渲染用的抽奖信息 + * @since Alpha v0.1.1 + * @param {LotteryData} lotteryData 抽奖信息 + * @return {LotteryCard} + */ +export function getLotteryCard(lotteryData: LotteryData): LotteryCard { + return { + id: lotteryData.id, + participantWay: lotteryData.participant_way, + status: lotteryData.status, + creator: lotteryData.creator, + drawTime: lotteryData.draw_time, + rewards: lotteryData.user_rewards.map(reward => { + return getLotteryRewardCard(reward); + }), + }; +} + +/** + * @description 根据抽奖奖励信息转为渲染用的抽奖奖励信息 + * @since Alpha v0.1.1 + * @param {LotteryReward} lotteryReward 抽奖奖励信息 + * @return {LotteryRewardCard} + */ +export function getLotteryRewardCard(lotteryReward: LotteryReward): LotteryRewardCard { + return { + rewardName: lotteryReward.reward_name, + winnerNumber: lotteryReward.winner_number, + scheduledWinnerNumber: lotteryReward.scheduled_winner_number, + users: lotteryReward.users, + }; +}