fix(lottery):完善方法

This commit is contained in:
BTMuli
2023-03-30 23:18:27 +08:00
parent 53a66750d5
commit 54ef831adc
3 changed files with 84 additions and 0 deletions

View File

@@ -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,
}
},
};

View File

@@ -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[];
}

View File

@@ -0,0 +1,42 @@
/**
* @file plugins Mys utils lottery.ts
* @description 抽奖工具类
* @author BTMuli<bt-muli@outlook.com>
* @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,
};
}