222 lines
7.3 KiB
TypeScript
222 lines
7.3 KiB
TypeScript
/**
|
|
* 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.
|
|
*/
|
|
import request from './index'
|
|
import type { IdType } from '@/utils/id'
|
|
|
|
/**
|
|
* 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.
|
|
*/
|
|
export interface Coupon {
|
|
id: IdType
|
|
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
|
|
shopId?: IdType
|
|
couponScene?: string
|
|
requiredVipLevel?: string
|
|
autoMatch?: number
|
|
availableTags: Tag[]
|
|
unavailableTags: Tag[]
|
|
}
|
|
|
|
/**
|
|
* 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.
|
|
*/
|
|
export interface Tag {
|
|
id: IdType
|
|
tagName?: string
|
|
}
|
|
|
|
/**
|
|
* 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.
|
|
*/
|
|
export interface UserCoupon {
|
|
id: IdType
|
|
couponId: IdType
|
|
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
|
|
}
|
|
|
|
/**
|
|
* 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.
|
|
*/
|
|
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
|
|
availableTagIds: IdType[]
|
|
unavailableTagIds: IdType[]
|
|
}
|
|
|
|
/**
|
|
* 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.
|
|
*/
|
|
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.
|
|
*/
|
|
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`
|
|
*/
|
|
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`
|
|
*/
|
|
updateCoupon: (id: IdType, data: CreateCouponRequest) => {
|
|
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`
|
|
*/
|
|
deleteCoupon: (id: IdType) => {
|
|
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`
|
|
*/
|
|
getCouponById: (id: IdType) => {
|
|
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 }`
|
|
*/
|
|
listCoupons: (params: { page: number; size: number; shopId?: IdType }) => {
|
|
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`
|
|
*/
|
|
assignCouponToUser: (userId: IdType, couponId: IdType) => {
|
|
return request({
|
|
url: '/coupon/assign',
|
|
method: 'post',
|
|
params: { userId, couponId }
|
|
})
|
|
},
|
|
|
|
// 获取用户优惠券列表
|
|
listUserCoupons: async (status?: number): Promise<UserCoupon[]> => {
|
|
return await request({
|
|
url: '/coupon/user/list',
|
|
method: 'get',
|
|
params: { status }
|
|
}) as UserCoupon[]
|
|
},
|
|
|
|
// 使用优惠券
|
|
/**
|
|
* `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`
|
|
*/
|
|
useCoupon: (userCouponId: IdType) => {
|
|
return request({
|
|
url: '/coupon/use',
|
|
method: 'post',
|
|
params: { userCouponId }
|
|
})
|
|
},
|
|
|
|
// 获取作品可用的优惠券
|
|
getAvailableCoupons: async (productTags: string, productPrice: number, shopId?: IdType): Promise<UserCoupon[]> => {
|
|
return await request({
|
|
url: '/coupon/available',
|
|
method: 'get',
|
|
params: { productTags, productPrice, shopId }
|
|
}) as UserCoupon[]
|
|
}
|
|
}
|