batch.ts 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220
  1. import request from "@/utils/request";
  2. const API_PATH = "/payment/batch";
  3. /** 制单授权记录(后端 BatchAuthorizeEntity,全局 SNAKE_CASE 序列化) */
  4. export interface BatchAuthorizeVO {
  5. /** 雪花ID序列化为字符串(后端 @JsonSerialize(ToStringSerializer)),防止 JS 精度丢失 */
  6. id?: string;
  7. out_biz_no: string;
  8. status: string;
  9. agreement_no?: string;
  10. authorize_link?: string;
  11. participant_id: string;
  12. participant_id_type?: string;
  13. /**
  14. * 个人账号(ALIPAY_LOGON_ID)主体扫码授权获取的支付宝账号ID(2088 开头)— 制单时付款方 identity 用(ALIPAY_USER_ID)。
  15. * 注: 本应用未开通支付宝 open_id 能力(user.info.share 响应实证),故不用 open_id 体系
  16. */
  17. alipay_user_id?: string;
  18. /** 主体名称(表单录入,同时作为授权申请 principal_info.name) */
  19. participant_name?: string;
  20. /** 服务商(表单下拉选择,授权申请 client 解析依据) */
  21. service_provider_id?: number;
  22. authorize_expire_time?: string;
  23. created_time?: string;
  24. }
  25. /**
  26. * 分页结果类型 — 后端 PageResult 全局 SNAKE_CASE 序列化后 JSON key 为 `list`
  27. * (全局 PageResult<T> 类型声明为 items,与后端契约不符,本模块以后端实际契约为准,
  28. * 保留 items 兼容字段以支持 `?.items ?? ?.list ?? []` 双保险解包,与存量 index.vue 一致)
  29. */
  30. export interface BatchPageResult<T> {
  31. items?: T;
  32. list: T;
  33. total: number;
  34. page_no: number;
  35. page_size: number;
  36. }
  37. /** 批次(后端 BatchOrderEntity) */
  38. export interface BatchOrderVO {
  39. out_batch_no: string;
  40. batch_trans_id?: string;
  41. total_amount: string;
  42. total_count: number;
  43. order_title?: string;
  44. /** INIT=受理中 / WAIT_PAY=等待支付 / SUCCESS=成功 / DISUSE=已关闭 / FAIL=失败 / INVALID=无效 */
  45. status: string;
  46. created_time?: string;
  47. pay_url?: string;
  48. payer_uid?: string;
  49. agreement_no?: string;
  50. transfer_scene_name?: string;
  51. time_expire?: string;
  52. remark?: string;
  53. error_code?: string;
  54. error_msg?: string;
  55. }
  56. /** 批次明细(后端 BatchDetailEntity) */
  57. export interface BatchDetailItem {
  58. out_biz_no: string;
  59. amount: string;
  60. remark?: string;
  61. payee_identity: string;
  62. /** ALIPAY_LOGON_ID / ALIPAY_USER_ID / ALIPAY_OPEN_ID(默认 LOGON_ID) */
  63. payee_identity_type?: string;
  64. payee_name?: string;
  65. status?: string;
  66. error_code?: string;
  67. error_msg?: string;
  68. }
  69. /** 创建批次请求体(BatchCreateDTO,snake_case;付款方恒为已授权主体、协议号自动带出,均不接受客户端指定) */
  70. export interface BatchCreateParams {
  71. /** 付款主体(授权主体支付宝账号/uid/openid,制单时从已授权主体选择;后端按主体类型映射制单 identity) */
  72. participant_id: string;
  73. order_title: string;
  74. transfer_scene_name?: string;
  75. transfer_scene_report_infos?: Array<{ info_type: string; info_content: string }>;
  76. time_expire?: string;
  77. remark?: string;
  78. details: BatchDetailItem[];
  79. }
  80. export const BatchPayAPI = {
  81. /** 生成制单授权链接(账号级: 主体信息来自表单,服务商下拉选择) */
  82. authorizeApply(data: {
  83. participant_name: string;
  84. participant_id: string;
  85. /** 主体类型: ALIPAY_USER_ID 支付宝账号ID(默认) / ALIPAY_LOGON_ID 登录号 / ALIPAY_OPEN_ID OpenID */
  86. participant_id_type?: string;
  87. service_provider_id: number;
  88. }) {
  89. return request<ApiResponse<{ authorize_link: string; out_biz_no: string; status: string }>>({
  90. url: `${API_PATH}/authorize/apply`,
  91. method: "post",
  92. data,
  93. });
  94. },
  95. /** 制单授权重新生成:作废当前 AUTHING 申请(旧链接失效),换新 out_biz_no 重新申请 */
  96. authorizeRebind(id: string) {
  97. return request<ApiResponse<{ authorize_link: string; out_biz_no: string; status: string }>>({
  98. url: `${API_PATH}/authorize/rebind`,
  99. method: "post",
  100. data: { id },
  101. });
  102. },
  103. /** 查询制单授权状态(AUTHED 时回写协议号) */
  104. queryAuthorize(outBizNo: string) {
  105. return request<ApiResponse<{ agreement_no: string; status: string }>>({
  106. url: `${API_PATH}/authorize/query`,
  107. method: "get",
  108. params: { out_biz_no: outBizNo },
  109. });
  110. },
  111. /** 生成 user.info.share OAuth 授权链接(LOGON_ID 主体扫码获取支付宝ID 制单用)— 前端新窗口打开 */
  112. openidAuthorizeUrl(id: string) {
  113. return request<ApiResponse<string>>({
  114. url: `${API_PATH}/authorize/openid/url`,
  115. method: "get",
  116. params: { id },
  117. });
  118. },
  119. /** 制单授权记录(分页,可按主体筛选) */
  120. authorizeList(params: { participant_id?: string; page_no?: number; page_size?: number }) {
  121. return request<ApiResponse<BatchPageResult<BatchAuthorizeVO[]>>>({
  122. url: `${API_PATH}/authorize/list`,
  123. method: "get",
  124. params,
  125. });
  126. },
  127. /** 创建批次(幂等键 out_batch_no 由后端生成) */
  128. batchCreate(data: BatchCreateParams) {
  129. return request<ApiResponse<{ out_batch_no: string; batch_trans_id: string; status: string }>>({
  130. url: `${API_PATH}/create`,
  131. method: "post",
  132. data,
  133. });
  134. },
  135. /** 生成 PC 支付页面 — pageExecute 返回 HTML 表单(与充值/签约同款处理) */
  136. renderPay(outBatchNo: string) {
  137. return request<ApiResponse<{ pay_url: string }>>({
  138. url: `${API_PATH}/pay`,
  139. method: "post",
  140. data: { out_batch_no: outBatchNo },
  141. });
  142. },
  143. /** 查询批次状态(同步支付宝并回写 DB) */
  144. batchQuery(outBatchNo: string) {
  145. return request<ApiResponse<{ out_batch_no: string; status: string }>>({
  146. url: `${API_PATH}/query`,
  147. method: "get",
  148. params: { out_batch_no: outBatchNo },
  149. });
  150. },
  151. /** 关闭未支付批次 */
  152. batchClose(outBatchNo: string) {
  153. return request<ApiResponse<{ status: string }>>({
  154. url: `${API_PATH}/close`,
  155. method: "post",
  156. data: { out_batch_no: outBatchNo },
  157. });
  158. },
  159. /** 批次列表(分页,主体/状态/时间筛选) */
  160. batchList(params: {
  161. participant_id?: string;
  162. status?: string;
  163. start_time?: string;
  164. end_time?: string;
  165. page_no?: number;
  166. page_size?: number;
  167. }) {
  168. return request<ApiResponse<BatchPageResult<BatchOrderVO[]>>>({
  169. url: `${API_PATH}/list`,
  170. method: "get",
  171. params,
  172. });
  173. },
  174. /** 批次详情 + 明细分页(租户隔离由后端拦截器自动追加) */
  175. batchDetail(outBatchNo: string, pageNo = 1, pageSize = 20) {
  176. return request<ApiResponse<{ order: BatchOrderVO; details: BatchPageResult<BatchDetailItem[]> }>>({
  177. url: `${API_PATH}/detail`,
  178. method: "get",
  179. params: {
  180. out_batch_no: outBatchNo,
  181. page_no: pageNo,
  182. page_size: pageSize,
  183. },
  184. });
  185. },
  186. /** 批次报表导出(xlsx 下载,接口直出字节流非 Result 包装) */
  187. batchExport(params: {
  188. participant_id?: string;
  189. status?: string;
  190. start_time?: string;
  191. end_time?: string;
  192. }) {
  193. return request({
  194. url: `${API_PATH}/export`,
  195. method: "get",
  196. params,
  197. responseType: "blob",
  198. });
  199. },
  200. };
  201. export default BatchPayAPI;