64 lines
1.5 KiB
TypeScript
64 lines
1.5 KiB
TypeScript
/**
|
|
* @description 用户积分相关API
|
|
* @author yslg
|
|
* @since 2025-10-15
|
|
*/
|
|
|
|
import { api } from '@/apis/index';
|
|
import type { UserPoints, PointsRecord, ResultDomain } from '@/types';
|
|
|
|
/**
|
|
* 用户积分API服务
|
|
*/
|
|
export const userPointsApi = {
|
|
/**
|
|
* 获取用户积分信息
|
|
* @param userID 用户ID
|
|
* @returns Promise<ResultDomain<UserPoints>>
|
|
*/
|
|
async getUserPoints(userID: string): Promise<ResultDomain<UserPoints>> {
|
|
const response = await api.get<UserPoints>('/usercenter/points/info', { userID });
|
|
return response.data;
|
|
},
|
|
|
|
/**
|
|
* 获取用户积分记录
|
|
* @param userID 用户ID
|
|
* @param type 积分类型
|
|
* @returns Promise<ResultDomain<PointsRecord>>
|
|
*/
|
|
async getUserPointsRecords(userID: string, type?: number): Promise<ResultDomain<PointsRecord>> {
|
|
const response = await api.get<PointsRecord>('/usercenter/points/records', {
|
|
userID,
|
|
type
|
|
});
|
|
return response.data;
|
|
},
|
|
|
|
/**
|
|
* 消费积分
|
|
* @param userID 用户ID
|
|
* @param points 积分数量
|
|
* @param reason 消费原因
|
|
* @param relatedID 关联对象ID
|
|
* @param relatedType 关联对象类型
|
|
* @returns Promise<ResultDomain<boolean>>
|
|
*/
|
|
async consumePoints(
|
|
userID: string,
|
|
points: number,
|
|
reason: string,
|
|
relatedID?: string,
|
|
relatedType?: number
|
|
): Promise<ResultDomain<boolean>> {
|
|
const response = await api.post<boolean>('/usercenter/points/consume', {
|
|
userID,
|
|
points,
|
|
reason,
|
|
relatedID,
|
|
relatedType
|
|
});
|
|
return response.data;
|
|
}
|
|
};
|