mirror of
https://github.com/Rain-kl/OpenFlare.git
synced 2026-10-11 09:46:37 +08:00
压缩历史至 95081aff
This commit is contained in:
@@ -0,0 +1,14 @@
|
||||
export { RedEnvelopeService } from './redenvelope.service';
|
||||
export type {
|
||||
RedEnvelopeType,
|
||||
RedEnvelopeStatus,
|
||||
RedEnvelope,
|
||||
RedEnvelopeClaim,
|
||||
CreateRedEnvelopeRequest,
|
||||
CreateRedEnvelopeResponse,
|
||||
ClaimRedEnvelopeRequest,
|
||||
ClaimRedEnvelopeResponse,
|
||||
RedEnvelopeDetailResponse,
|
||||
RedEnvelopeListParams,
|
||||
RedEnvelopeListResponse,
|
||||
} from './types';
|
||||
@@ -0,0 +1,108 @@
|
||||
import { BaseService } from '../core/base.service';
|
||||
import type { UploadImageResponse } from '../upload/types';
|
||||
import type {
|
||||
CreateRedEnvelopeRequest,
|
||||
CreateRedEnvelopeResponse,
|
||||
ClaimRedEnvelopeRequest,
|
||||
ClaimRedEnvelopeResponse,
|
||||
RedEnvelopeDetailResponse,
|
||||
RedEnvelopeListParams,
|
||||
RedEnvelopeListResponse,
|
||||
} from './types';
|
||||
|
||||
/**
|
||||
* 红包服务
|
||||
* 处理红包创建、领取、查询相关的 API 请求
|
||||
*/
|
||||
export class RedEnvelopeService extends BaseService {
|
||||
protected static readonly basePath = '/api/v1/redenvelope';
|
||||
|
||||
/**
|
||||
* 创建红包
|
||||
* @param data - 创建红包请求参数
|
||||
* @returns 红包信息(包含分享链接)
|
||||
* @throws {UnauthorizedError} 当未登录时
|
||||
* @throws {ValidationError} 当参数验证失败时
|
||||
* @throws {ApiErrorBase} 当余额不足或支付密码错误时
|
||||
*
|
||||
* @example
|
||||
* ```typescript
|
||||
* const result = await RedEnvelopeService.create({
|
||||
* type: 'random',
|
||||
* total_amount: 100,
|
||||
* total_count: 10,
|
||||
* greeting: '恭喜发财',
|
||||
* pay_key: '123456'
|
||||
* });
|
||||
* console.log('分享链接:', result.link);
|
||||
* ```
|
||||
*/
|
||||
static async create(data: CreateRedEnvelopeRequest): Promise<CreateRedEnvelopeResponse> {
|
||||
return this.post<CreateRedEnvelopeResponse>('/create', data);
|
||||
}
|
||||
|
||||
/**
|
||||
* 领取红包
|
||||
* @param data - 领取红包请求参数
|
||||
* @returns 领取结果(包含领取金额)
|
||||
* @throws {UnauthorizedError} 当未登录时
|
||||
* @throws {NotFoundError} 当红包不存在时
|
||||
* @throws {ApiErrorBase} 当红包已领完、已过期或已领取过时
|
||||
*
|
||||
* @example
|
||||
* ```typescript
|
||||
* const result = await RedEnvelopeService.claim({ id: '123456' });
|
||||
* console.log('领取金额:', result.amount);
|
||||
* ```
|
||||
*/
|
||||
static async claim(data: ClaimRedEnvelopeRequest): Promise<ClaimRedEnvelopeResponse> {
|
||||
return this.post<ClaimRedEnvelopeResponse>('/claim', data);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取红包详情
|
||||
* @param id - 红包ID
|
||||
* @returns 红包详情(包含领取记录)
|
||||
* @throws {NotFoundError} 当红包不存在时
|
||||
*
|
||||
* @example
|
||||
* ```typescript
|
||||
* const detail = await RedEnvelopeService.getDetail('123456');
|
||||
* console.log('红包状态:', detail.red_envelope.status);
|
||||
* console.log('已领取人数:', detail.claims.length);
|
||||
* ```
|
||||
*/
|
||||
static async getDetail(id: string): Promise<RedEnvelopeDetailResponse> {
|
||||
return this.get<RedEnvelopeDetailResponse>(`/${ id }`);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取红包列表
|
||||
* @param params - 查询参数
|
||||
* @returns 红包列表
|
||||
* @throws {UnauthorizedError} 当未登录时
|
||||
*
|
||||
* @example
|
||||
* ```typescript
|
||||
* const result = await RedEnvelopeService.getList({
|
||||
* page: 1,
|
||||
* page_size: 20,
|
||||
* type: 'sent'
|
||||
* });
|
||||
* ```
|
||||
*/
|
||||
static async getList(params: RedEnvelopeListParams): Promise<RedEnvelopeListResponse> {
|
||||
return this.post<RedEnvelopeListResponse>('/list', params);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取用户历史红包封面
|
||||
* @param type - 封面类型 (cover: 背景封面, heterotypic: 异形装饰)
|
||||
* @returns 历史封面列表
|
||||
*/
|
||||
static async listCovers(
|
||||
type: 'cover' | 'heterotypic'
|
||||
): Promise<UploadImageResponse[]> {
|
||||
return this.get<UploadImageResponse[]>('/covers', { type });
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,154 @@
|
||||
/**
|
||||
* 红包类型
|
||||
* - fixed: 固定金额,每个红包金额相同
|
||||
* - random: 拼手气,随机分配金额
|
||||
*/
|
||||
export type RedEnvelopeType = 'fixed' | 'random';
|
||||
|
||||
/**
|
||||
* 红包状态
|
||||
* - active: 进行中,可领取
|
||||
* - finished: 已领完
|
||||
* - expired: 已过期
|
||||
*/
|
||||
export type RedEnvelopeStatus = 'active' | 'finished' | 'expired';
|
||||
|
||||
/**
|
||||
* 红包信息
|
||||
*/
|
||||
export interface RedEnvelope {
|
||||
/** 红包 ID */
|
||||
id: string;
|
||||
/** 创建者用户 ID */
|
||||
creator_id: string;
|
||||
/** 创建者用户名 */
|
||||
creator_username: string;
|
||||
/** 创建者头像 URL */
|
||||
creator_avatar_url?: string;
|
||||
/** 红包类型 */
|
||||
type: RedEnvelopeType;
|
||||
/** 总金额 */
|
||||
total_amount: string;
|
||||
/** 剩余金额 */
|
||||
remaining_amount: string;
|
||||
/** 红包总个数 */
|
||||
total_count: number;
|
||||
/** 剩余个数 */
|
||||
remaining_count: number;
|
||||
/** 祝福语 */
|
||||
greeting: string;
|
||||
/** 红包状态 */
|
||||
status: RedEnvelopeStatus;
|
||||
/** 封面上传记录 ID */
|
||||
cover_upload_id?: string;
|
||||
/** 装饰上传记录 ID */
|
||||
heterotypic_upload_id?: string;
|
||||
/** 过期时间 */
|
||||
expires_at: string;
|
||||
/** 创建时间 */
|
||||
created_at: string;
|
||||
}
|
||||
|
||||
/**
|
||||
* 红包领取记录
|
||||
*/
|
||||
export interface RedEnvelopeClaim {
|
||||
/** 记录 ID (作为字符串以避免 JS 精度问题) */
|
||||
id: string;
|
||||
/** 红包 ID (作为字符串以避免 JS 精度问题) */
|
||||
red_envelope_id: string;
|
||||
/** 领取者用户 ID (作为字符串以避免 JS 精度问题) */
|
||||
user_id: string;
|
||||
/** 领取者用户名 */
|
||||
username: string;
|
||||
/** 领取者头像 URL */
|
||||
avatar_url?: string;
|
||||
/** 领取金额 */
|
||||
amount: string;
|
||||
/** 领取时间 */
|
||||
claimed_at: string;
|
||||
}
|
||||
|
||||
/**
|
||||
* 创建红包请求参数
|
||||
*/
|
||||
export interface CreateRedEnvelopeRequest {
|
||||
/** 红包类型(fixed: 固定金额, random: 拼手气) */
|
||||
type: RedEnvelopeType;
|
||||
/** 总金额(必须大于0,最多2位小数) */
|
||||
total_amount: number;
|
||||
/** 红包个数(必须大于0) */
|
||||
total_count: number;
|
||||
/** 祝福语(可选,最大100字符) */
|
||||
greeting?: string;
|
||||
/** 支付密码(6-10位) */
|
||||
pay_key: string;
|
||||
/** 封面上传记录 ID */
|
||||
cover_upload_id?: string;
|
||||
/** 异形装饰上传记录 ID */
|
||||
heterotypic_upload_id?: string;
|
||||
}
|
||||
|
||||
/**
|
||||
* 创建红包响应
|
||||
*/
|
||||
export interface CreateRedEnvelopeResponse {
|
||||
/** 红包 ID (作为字符串以避免 JS 精度问题) */
|
||||
id: string;
|
||||
}
|
||||
|
||||
/**
|
||||
* 领取红包请求参数
|
||||
*/
|
||||
export interface ClaimRedEnvelopeRequest {
|
||||
/** 红包 ID */
|
||||
id: string;
|
||||
}
|
||||
|
||||
/**
|
||||
* 领取红包响应
|
||||
*/
|
||||
export interface ClaimRedEnvelopeResponse {
|
||||
/** 领取到的金额 */
|
||||
amount: string;
|
||||
/** 红包信息 */
|
||||
red_envelope: RedEnvelope;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取红包详情响应
|
||||
*/
|
||||
export interface RedEnvelopeDetailResponse {
|
||||
/** 红包信息 */
|
||||
red_envelope: RedEnvelope;
|
||||
/** 领取记录列表 */
|
||||
claims: RedEnvelopeClaim[];
|
||||
/** 当前用户的领取记录(如果已领取) */
|
||||
user_claimed?: RedEnvelopeClaim;
|
||||
}
|
||||
|
||||
/**
|
||||
* 红包列表查询参数
|
||||
*/
|
||||
export interface RedEnvelopeListParams {
|
||||
/** 页码,从 1 开始 */
|
||||
page: number;
|
||||
/** 每页数量,1-100 */
|
||||
page_size: number;
|
||||
/** 查询类型(sent: 发出的, received: 收到的) */
|
||||
type?: 'sent' | 'received';
|
||||
}
|
||||
|
||||
/**
|
||||
* 红包列表响应
|
||||
*/
|
||||
export interface RedEnvelopeListResponse {
|
||||
/** 总记录数 */
|
||||
total: number;
|
||||
/** 当前页码 */
|
||||
page: number;
|
||||
/** 每页数量 */
|
||||
page_size: number;
|
||||
/** 红包列表 */
|
||||
red_envelopes: RedEnvelope[];
|
||||
}
|
||||
Reference in New Issue
Block a user