Files
JayuCloud/JY-Artist-Frontend/src/api/coupon.ts
T

222 lines
7.3 KiB
TypeScript
Raw Normal View History

/**
* Front-end API wrapper for this module.
* Call guide: import the named API object, then call the matching method from a Vue page or composable.
*/
2026-02-27 11:05:15 +08:00
import request from './index'
2026-03-27 14:55:41 +08:00
import type { IdType } from '@/utils/id'
2026-02-27 11:05:15 +08:00
2026-05-23 18:44:57 +08:00
/**
* Purpose: Coupon supports coupon.ts by holding or executing the coupon page or API role.
* Usage: import, call, read, or update this interface from the owning page/module while preserving the surrounding loading and permission flow.
*/
2026-02-27 11:05:15 +08:00
export interface Coupon {
2026-03-27 14:55:41 +08:00
id: IdType
2026-02-27 11:05:15 +08:00
couponCode: string
couponName: string
couponType: number
couponTypeName: string
discountValue?: number
minAmount?: number
reduceAmount?: number
totalCount: number
usedCount: number
remainingCount: number
startTime: string
endTime: string
status: number
statusName: string
2026-03-27 14:55:41 +08:00
shopId?: IdType
couponScene?: string
requiredVipLevel?: string
autoMatch?: number
2026-02-27 11:05:15 +08:00
availableTags: Tag[]
unavailableTags: Tag[]
}
2026-05-23 18:44:57 +08:00
/**
* Purpose: Tag supports coupon.ts by holding or executing the tag page or API role.
* Usage: import, call, read, or update this interface from the owning page/module while preserving the surrounding loading and permission flow.
*/
2026-02-27 11:05:15 +08:00
export interface Tag {
2026-03-27 14:55:41 +08:00
id: IdType
2026-02-27 11:05:15 +08:00
tagName?: string
}
2026-05-23 18:44:57 +08:00
/**
* Purpose: UserCoupon supports coupon.ts by holding or executing the user coupon page or API role.
* Usage: import, call, read, or update this interface from the owning page/module while preserving the surrounding loading and permission flow.
*/
2026-02-27 11:05:15 +08:00
export interface UserCoupon {
2026-03-27 14:55:41 +08:00
id: IdType
couponId: IdType
2026-02-27 11:05:15 +08:00
couponName: string
couponType: number
couponTypeName: string
discountValue: string
minAmount: string
reduceAmount: string
startTime: string
endTime: string
status: number
statusName: string
obtainTime: string
useTime: string
sourceType?: string
requiredVipLevel?: string
autoMatched?: boolean
2026-02-27 11:05:15 +08:00
}
2026-05-23 18:44:57 +08:00
/**
* Purpose: CreateCouponRequest supports coupon.ts by holding or executing the create coupon request page or API role.
* Usage: import, call, read, or update this interface from the owning page/module while preserving the surrounding loading and permission flow.
*/
2026-02-27 11:05:15 +08:00
export interface CreateCouponRequest {
couponCode: string
couponName: string
couponType: number
discountValue?: number
minAmount?: number
reduceAmount?: number
totalCount: number
startTime: string
endTime: string
couponScene?: string
requiredVipLevel?: string
autoMatch?: number
2026-03-27 14:55:41 +08:00
availableTagIds: IdType[]
unavailableTagIds: IdType[]
2026-02-27 11:05:15 +08:00
}
2026-05-23 18:44:57 +08:00
/**
* Purpose: CouponListResponse supports coupon.ts by holding or executing the coupon list response page or API role.
* Usage: import, call, read, or update this interface from the owning page/module while preserving the surrounding loading and permission flow.
*/
2026-02-27 11:05:15 +08:00
export interface CouponListResponse {
list: Coupon[]
total: number
page: number
size: number
}
/**
* couponApi groups all API calls for this page domain.
* Call guide: pass the typed payload or identifier into the method below, and use the returned Promise in the page script.
*/
2026-02-27 11:05:15 +08:00
export const couponApi = {
// 创建优惠券
/**
* `createCoupon` API call. Use this method from the page script to invoke the backend endpoint tied to this feature.
* Call guide: supply the parameters below, await the returned Promise, and handle loading / error UI in the caller.
* @param data: CreateCouponRequest caller-supplied value for `data: CreateCouponRequest`
*/
2026-02-27 11:05:15 +08:00
createCoupon: (data: CreateCouponRequest) => {
return request({
url: '/coupon/create',
method: 'post',
data
})
},
// 更新优惠券
/**
* `updateCoupon` API call. Use this method from the page script to invoke the backend endpoint tied to this feature.
* Call guide: supply the parameters below, await the returned Promise, and handle loading / error UI in the caller.
* @param id: IdType caller-supplied value for `id: IdType`
* @param data: CreateCouponRequest caller-supplied value for `data: CreateCouponRequest`
*/
2026-03-27 14:55:41 +08:00
updateCoupon: (id: IdType, data: CreateCouponRequest) => {
2026-02-27 11:05:15 +08:00
return request({
url: `/coupon/update/${id}`,
method: 'put',
data
})
},
// 删除优惠券
/**
* `deleteCoupon` API call. Use this method from the page script to invoke the backend endpoint tied to this feature.
* Call guide: supply the parameters below, await the returned Promise, and handle loading / error UI in the caller.
* @param id: IdType caller-supplied value for `id: IdType`
*/
2026-03-27 14:55:41 +08:00
deleteCoupon: (id: IdType) => {
2026-02-27 11:05:15 +08:00
return request({
url: `/coupon/delete/${id}`,
method: 'delete'
})
},
// 获取优惠券详情
/**
* `getCouponById` API call. Use this method from the page script to invoke the backend endpoint tied to this feature.
* Call guide: supply the parameters below, await the returned Promise, and handle loading / error UI in the caller.
* @param id: IdType caller-supplied value for `id: IdType`
*/
2026-03-27 14:55:41 +08:00
getCouponById: (id: IdType) => {
2026-02-27 11:05:15 +08:00
return request({
url: `/coupon/detail/${id}`,
method: 'get'
})
},
// 获取优惠券列表
/**
* `listCoupons` API call. Use this method from the page script to invoke the backend endpoint tied to this feature.
* Call guide: supply the parameters below, await the returned Promise, and handle loading / error UI in the caller.
* @param params: { page: number; size: number; shopId?: IdType } caller-supplied value for `params: { page: number; size: number; shopId?: IdType }`
*/
2026-03-27 14:55:41 +08:00
listCoupons: (params: { page: number; size: number; shopId?: IdType }) => {
2026-02-27 11:05:15 +08:00
return request({
url: '/coupon/list',
method: 'get',
params
})
},
// 为用户分配优惠券
/**
* `assignCouponToUser` API call. Use this method from the page script to invoke the backend endpoint tied to this feature.
* Call guide: supply the parameters below, await the returned Promise, and handle loading / error UI in the caller.
* @param userId: IdType caller-supplied value for `userId: IdType`
* @param couponId: IdType caller-supplied value for `couponId: IdType`
*/
2026-03-27 14:55:41 +08:00
assignCouponToUser: (userId: IdType, couponId: IdType) => {
2026-02-27 11:05:15 +08:00
return request({
url: '/coupon/assign',
method: 'post',
params: { userId, couponId }
})
},
// 获取用户优惠券列表
listUserCoupons: async (status?: number): Promise<UserCoupon[]> => {
return await request({
2026-02-27 11:05:15 +08:00
url: '/coupon/user/list',
method: 'get',
params: { status }
}) as UserCoupon[]
2026-02-27 11:05:15 +08:00
},
// 使用优惠券
/**
* `useCoupon` API call. Use this method from the page script to invoke the backend endpoint tied to this feature.
* Call guide: supply the parameters below, await the returned Promise, and handle loading / error UI in the caller.
* @param userCouponId: IdType caller-supplied value for `userCouponId: IdType`
*/
2026-03-27 14:55:41 +08:00
useCoupon: (userCouponId: IdType) => {
2026-02-27 11:05:15 +08:00
return request({
url: '/coupon/use',
method: 'post',
params: { userCouponId }
})
},
2026-03-05 16:08:27 +08:00
// 获取作品可用的优惠券
2026-03-27 14:55:41 +08:00
getAvailableCoupons: async (productTags: string, productPrice: number, shopId?: IdType): Promise<UserCoupon[]> => {
return await request({
2026-02-27 11:05:15 +08:00
url: '/coupon/available',
method: 'get',
params: { productTags, productPrice, shopId }
}) as UserCoupon[]
2026-02-27 11:05:15 +08:00
}
}