orderService.ts 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  1. // src/lib/services/orderService.ts
  2. import api from '@/lib/api';
  3. export interface OrderListParams {
  4. page?: number;
  5. page_size?: number;
  6. size?: number;
  7. keyword?: string;
  8. status?: string;
  9. channel_type?: 'direct' | 'agency' | 'website' | string;
  10. handler_id?: string;
  11. settlement_status?: 'unsettled' | 'risk_period' | 'eligible' | 'settled' | string;
  12. [key: string]: any;
  13. }
  14. export const orderService = {
  15. /**
  16. * 分页查询订单列表
  17. */
  18. async listAll(params?: OrderListParams) {
  19. const res = await api.get('/api/vas/order/list_all', { params });
  20. return res.data;
  21. },
  22. /**
  23. * 分页查询当前用户的订单列表 (前台用户)
  24. */
  25. async listByUser(params?: OrderListParams) {
  26. const res = await api.get('/api/vas/order/list_by_user', { params });
  27. return res.data;
  28. },
  29. /**
  30. * 获取订单详情
  31. */
  32. async getDetail(orderId: string | number) {
  33. const res = await api.get('/api/vas/order/detail', {
  34. params: { order_id: orderId },
  35. });
  36. return res.data;
  37. },
  38. /**
  39. * 前台用户创建订单
  40. */
  41. async create(payload: Record<string, any>) {
  42. const res = await api.post('/api/vas/order/create', payload);
  43. return res.data;
  44. },
  45. /**
  46. * 管理员后台直接创建订单 (支持渠道/中介/对接人/自定义价格)
  47. */
  48. async createByAdmin(payload: {
  49. product_id: number;
  50. user_inputs: Record<string, any>;
  51. channel_type?: 'direct' | 'agency' | 'website' | string;
  52. agency_id?: string | null;
  53. handler_id?: string | null;
  54. final_amount?: number | null;
  55. }) {
  56. const res = await api.post('/api/vas/order/create_by_admin', payload);
  57. return res.data;
  58. },
  59. /**
  60. * 标记订单履约出签完成,开启退款风险期(如T+7)
  61. */
  62. async markCompleted(orderId: string | number, riskDays: number = 7) {
  63. const res = await api.post('/api/vas/order/mark_completed', null, {
  64. params: { order_id: orderId, risk_days: riskDays },
  65. });
  66. return res.data;
  67. },
  68. /**
  69. * 取消订单
  70. */
  71. async cancel(orderId: string | number) {
  72. const res = await api.post('/api/vas/order/cancel', null, {
  73. params: { order_id: orderId },
  74. });
  75. return res.data;
  76. },
  77. /**
  78. * 管理员更新订单状态
  79. */
  80. async updateStatus(orderId: string | number, payload: { status: string; [key: string]: any }) {
  81. const res = await api.post('/api/vas/order/admin_update_status', payload, {
  82. params: { order_id: orderId },
  83. });
  84. return res.data;
  85. },
  86. /**
  87. * 修改订单用户输入数据 (JSON Patch)
  88. */
  89. async patchUserInputs(orderId: string | number, payload: Record<string, any>) {
  90. const res = await api.post('/api/vas/order/patch_user_inputs', payload, {
  91. params: { order_id: orderId },
  92. });
  93. return res.data;
  94. },
  95. /**
  96. * 管理员配置与更新订单属性 (渠道/对接人/中介/申报参数/状态)
  97. */
  98. async updateOrder(
  99. orderId: string | number,
  100. payload: {
  101. channel_type?: 'direct' | 'agency' | 'website';
  102. agency_id?: string | null;
  103. handler_id?: string | null;
  104. status?: string;
  105. user_inputs?: Record<string, any>;
  106. }
  107. ) {
  108. const res = await api.post('/api/vas/order/update', payload, {
  109. params: { order_id: orderId },
  110. });
  111. return res.data;
  112. },
  113. /**
  114. * 后台调整订单价格 (优惠 / 减免 / 附加费)
  115. */
  116. async adjustPrice(orderId: string | number, payload: Record<string, any>) {
  117. const res = await api.post('/api/vas/order/adjust-price', payload, {
  118. params: { order_id: orderId },
  119. });
  120. return res.data;
  121. },
  122. /**
  123. * 获取订单生命周期事件日志
  124. */
  125. async getEvents(orderId: string | number) {
  126. try {
  127. const res = await api.get('/api/vas/order-event/list', {
  128. params: { order_id: orderId },
  129. });
  130. return res.data;
  131. } catch {
  132. const res = await api.get('/api/order/events', {
  133. params: { order_id: orderId },
  134. });
  135. return res.data;
  136. }
  137. },
  138. /**
  139. * AI 智能解析表单数据 (LLM Data Parsing)
  140. */
  141. async parseDataWithLlm(payload: { raw_text?: string; input_raw_str?: string; schema_id?: string | number;[key: string]: any }) {
  142. const res = await api.post('/api/vas/llm/data_parsing', payload);
  143. return res.data;
  144. },
  145. };