coupon.ts 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. /**
  2. * 优惠券相关API
  3. */
  4. import { get, post } from '../utils/request';
  5. /**
  6. * 用户优惠券信息
  7. */
  8. export interface UserCouponInfo {
  9. id: string;
  10. couponCode: string;
  11. templateId: string;
  12. userId: string;
  13. orderId: string | null;
  14. status: number; // 0-未使用, 1-已使用, 2-已过期
  15. receiveTime: string;
  16. useTime: string | null;
  17. validStartTime: string;
  18. validEndTime: string;
  19. discountAmount: number | null;
  20. discountValue: number | null;
  21. couponName: string;
  22. couponType: number; // 1-满减券, 2-折扣券, 3-抵扣券, 4-兑换券
  23. minAmount: number;
  24. couponDesc: string;
  25. applyScope: number;
  26. statusLabel: string;
  27. statusColor: string;
  28. }
  29. /**
  30. * 可领取优惠券模板
  31. */
  32. export interface CouponTemplateInfo {
  33. id: string;
  34. couponName: string;
  35. couponType: number;
  36. couponDesc: string;
  37. discountValue: number;
  38. minAmount: number;
  39. maxDiscount: number;
  40. totalCount: number;
  41. remainCount: number;
  42. receiveLimit: number;
  43. validType: number;
  44. validStartTime: string;
  45. validEndTime: string;
  46. validDays: number;
  47. applyScope: number;
  48. receiveType: string;
  49. status: number;
  50. }
  51. /**
  52. * 分页结果
  53. */
  54. export interface PageResult<T> {
  55. list: T[];
  56. total: number;
  57. pageSize: number;
  58. currentPage: number;
  59. totalPages: number;
  60. }
  61. /**
  62. * 优惠券数量统计
  63. */
  64. export interface CouponCountInfo {
  65. availableCount: number;
  66. }
  67. /**
  68. * 获取我的优惠券列表
  69. * @param status 0-未使用, 1-已使用, 2-已过期
  70. * @param page 页码
  71. * @param pageSize 每页数量
  72. */
  73. export const getMyCoupons = (status: number = 0, page: number = 1, pageSize: number = 10): Promise<PageResult<UserCouponInfo>> => {
  74. return get<PageResult<UserCouponInfo>>('/coupon/my', { status, page, pageSize });
  75. };
  76. /**
  77. * 获取优惠券详情
  78. * @param id 优惠券ID
  79. */
  80. export const getCouponDetail = (id: string): Promise<UserCouponInfo> => {
  81. return get<UserCouponInfo>(`/coupon/${id}`);
  82. };
  83. /**
  84. * 领取优惠券
  85. * @param templateId 优惠券模板ID
  86. */
  87. export const receiveCoupon = (templateId: string): Promise<UserCouponInfo> => {
  88. return post<UserCouponInfo>(`/coupon/receive/${templateId}`);
  89. };
  90. /**
  91. * 获取可用优惠券数量
  92. */
  93. export const getCouponCount = (): Promise<CouponCountInfo> => {
  94. return get<CouponCountInfo>('/coupon/count');
  95. };
  96. /**
  97. * 获取可领取优惠券列表(领券中心)
  98. */
  99. export const getAvailableCoupons = (): Promise<CouponTemplateInfo[]> => {
  100. return get<CouponTemplateInfo[]>('/coupon/available');
  101. };
  102. /**
  103. * 获取可用优惠券列表(下单时使用)
  104. */
  105. export const getUsableCoupons = (): Promise<UserCouponInfo[]> => {
  106. return get<UserCouponInfo[]>('/coupon/usable');
  107. };