New file |
| | |
| | | import createAxios from '@/utils/axios' |
| | | |
| | | // 购物车管理 API |
| | | const baseUrl = '/admin/api/cart' |
| | | |
| | | const cartApi = { |
| | | // 添加商品到购物车 |
| | | addToCart(data: any, userId: number, unitId: number): ApiPromise { |
| | | return createAxios({ |
| | | url: `${baseUrl}/add`, |
| | | method: 'post', |
| | | data, |
| | | params: { userId, unitId } |
| | | }) as ApiPromise |
| | | }, |
| | | |
| | | // 从购物车移除商品 |
| | | removeFromCart(userId: number, unitId: number, pricingId: number): ApiPromise { |
| | | return createAxios({ |
| | | url: `${baseUrl}/remove`, |
| | | method: 'delete', |
| | | params: { userId, unitId, pricingId } |
| | | }) as ApiPromise |
| | | }, |
| | | |
| | | // 更新购物车商品数量 |
| | | updateCartItem(userId: number, unitId: number, pricingId: number, quantity: number): ApiPromise { |
| | | return createAxios({ |
| | | url: `${baseUrl}/update`, |
| | | method: 'put', |
| | | params: { userId, unitId, pricingId, quantity } |
| | | }) as ApiPromise |
| | | }, |
| | | |
| | | // 获取购物车信息 |
| | | getCartInfo(userId: number, unitId: number): ApiPromise { |
| | | return createAxios({ |
| | | url: `${baseUrl}/info`, |
| | | method: 'get', |
| | | params: { userId, unitId } |
| | | }) as ApiPromise |
| | | }, |
| | | |
| | | // 获取购物车商品列表 |
| | | getCartItems(userId: number, unitId: number): ApiPromise { |
| | | return createAxios({ |
| | | url: `${baseUrl}/items`, |
| | | method: 'get', |
| | | params: { userId, unitId } |
| | | }) as ApiPromise |
| | | }, |
| | | |
| | | // 清空购物车 |
| | | clearCart(userId: number, unitId: number): ApiPromise { |
| | | return createAxios({ |
| | | url: `${baseUrl}/clear`, |
| | | method: 'delete', |
| | | params: { userId, unitId } |
| | | }) as ApiPromise |
| | | } |
| | | } |
| | | |
| | | export default cartApi |
New file |
| | |
| | | import createAxios from '@/utils/axios' |
| | | |
| | | const baseUrl = '/admin/api/order' |
| | | |
| | | const orderApi = { |
| | | // 获取一次性防重复提交 Token |
| | | getIdempotencyToken(userId?: number): ApiPromise { |
| | | return createAxios({ |
| | | url: `${baseUrl}/idempotency/token`, |
| | | method: 'get', |
| | | params: userId ? { userId } : {} |
| | | }) as ApiPromise |
| | | }, |
| | | |
| | | // 创建订单(在 headers 中携带 Idempotency-Token) |
| | | createOrder(data: any, token: string): ApiPromise { |
| | | return createAxios({ |
| | | url: `${baseUrl}/create`, |
| | | method: 'post', |
| | | data, |
| | | headers: { 'Idempotency-Token': token } |
| | | }) as ApiPromise |
| | | } |
| | | } |
| | | |
| | | export default orderApi |