order.ts 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. /**
  2. * 订单管理相关API
  3. */
  4. import { get, post } from '@/utils/request';
  5. export interface OrderQueryParams {
  6. page?: number;
  7. pageSize?: number;
  8. orderNo?: string;
  9. deviceId?: string;
  10. payStatus?: string;
  11. status?: number;
  12. statusList?: number[];
  13. startDate?: string;
  14. endDate?: string;
  15. }
  16. export interface OrderListResponse {
  17. list: any[];
  18. total: number;
  19. page: number;
  20. pageSize: number;
  21. }
  22. /**
  23. * 获取订单列表
  24. */
  25. export async function getOrderList(params: OrderQueryParams = {}): Promise<OrderListResponse> {
  26. const query = { ...params };
  27. if (query.status === -1) {
  28. delete (query as any).status;
  29. }
  30. return get('/order/list', query);
  31. }
  32. /**
  33. * 获取订单详情
  34. */
  35. export async function getOrderDetail(orderId: string): Promise<any> {
  36. return get(`/order/${orderId}`);
  37. }
  38. /**
  39. * 获取订单统计
  40. */
  41. export async function getOrderStats(params?: { startDate?: string; endDate?: string }): Promise<any> {
  42. return get('/order/statistics', params || {});
  43. }
  44. /**
  45. * 处理退款(支持部分退款、自定义金额、全额退款)
  46. */
  47. export async function handleRefund(
  48. orderId: string,
  49. reason: string,
  50. data?: { products?: { productId: string; productName: string; quantity: number; price: number }[]; refundAmount?: number }
  51. ): Promise<any> {
  52. const body: any = { reason };
  53. if (data?.products?.length) body.products = data.products;
  54. if (data?.refundAmount) body.refundAmount = data.refundAmount;
  55. return post(`/order/${orderId}/refund`, body);
  56. }