applications.ts 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204
  1. import { CoolController, BaseController } from '@cool-midway/core';
  2. import { Context } from '@midwayjs/koa';
  3. import {Fields, Files, Get, Provide, Query} from '@midwayjs/core';
  4. import {ALL, Body, Inject, Post} from "@midwayjs/decorator";
  5. import {EasyPayAdapter} from "../../../payment/adapter/easypay.adapter";
  6. import {EasyOpenService} from "../../service/open";
  7. import {accountsService} from "../../service/admin/accounts";
  8. import {OpenApplicationsEntity} from "../../entity/open_applications";
  9. import { applicationsService } from '../../service/admin/applications';
  10. /**
  11. * 开发接口的流水订单
  12. */
  13. @Provide()
  14. @CoolController({
  15. api: ['add', 'delete', 'update', 'info', 'list', 'page'],
  16. entity: OpenApplicationsEntity,
  17. pageQueryOp: {
  18. where: async (ctx: Context) => {
  19. const { merchant, roleId } = ctx.admin;
  20. if ([1, 3].includes(roleId)) {
  21. return [['mchId=:mchId', { mchId: merchant.mchId }]];
  22. }
  23. return [];
  24. },
  25. },
  26. })
  27. export class ApplicationsController extends BaseController {
  28. @Inject()
  29. ctx: Context; // Inject the context
  30. @Inject()
  31. easyPayAdapter: EasyPayAdapter;
  32. @Inject()
  33. easyOpenService: EasyOpenService;
  34. @Inject()
  35. accountsService: accountsService;
  36. @Inject()
  37. applicationsService: applicationsService;
  38. /**
  39. * merchant_certification
  40. */
  41. @Post('/v1/upload', { summary: '上传文件' })
  42. async upload(@Files() files: any[], @Fields() fields) {
  43. const results = [];
  44. for (const file of files) {
  45. const result = await this.easyOpenService.upload(file);
  46. results.push(result);
  47. }
  48. return { success: true, data: results };
  49. }
  50. /**
  51. * 申请收款账户
  52. * {
  53. * "request_id": "fusion_0002",
  54. * "purpose": "ECOMM_PLATFORM",
  55. * "account_id": "2bd64372841a54bf8b41f879ff07884b",
  56. * "currency": "EUR",
  57. * "payment_type": "SWIFT",
  58. * "additional_info": {
  59. * "online_sales_method": "AMAZON",
  60. * "payer_party": "AMAZON",
  61. * "store_name": "redius",
  62. * "store_photos": ["2123321"],
  63. * "business_category": "纺织、服装及日化用品专门销售",
  64. * "store_address": {
  65. * "region": "HK",
  66. * "city": "HK",
  67. * "street": "HK"
  68. * }
  69. * }
  70. * }
  71. *
  72. *
  73. * {
  74. id: '48a39dc9aec5417b883fcd3d5f9f5a0a',
  75. request_id: 'fusionget_1740974452715',
  76. reference: null,
  77. account_id: '2bd64372841a54bf8b41f879ff07884b',
  78. order_no: '20250303120053717551',
  79. currency: 'EUR',
  80. payment_type: 'SWIFT',
  81. purpose: 'ECOMM_STANDALONE',
  82. additional_info: {
  83. store_name: '赚钱浜',
  84. offline_sales_method: null,
  85. online_sales_method: 'AMAZON,SHOPIFY',
  86. website_url: 'va.fusion.com',
  87. store_photos: [
  88. 'http://easypay-legal-entity-demo.oss-cn-hongkong.aliyuncs.com/fusion/uploads/1740973141012_9.png'
  89. ],
  90. business_category: '纺织、服装及日化用品专门销售',
  91. business_regions: null,
  92. monthly_transaction_count: 1000,
  93. monthly_transaction_amount: null,
  94. payer_party: 'AMAZON',
  95. payer_party_account: '1231231',
  96. funds_regions: null,
  97. funds_type: 'INVESTMENT',
  98. documents: null,
  99. store_address: {
  100. region: 'HK',
  101. state_or_province: '香港',
  102. city: '香港',
  103. street: '香港西贡区市场街124号',
  104. zip_code: '123123'
  105. },
  106. official_account: null,
  107. official_account_appid: null,
  108. mini_program: null,
  109. mini_program_appid: null,
  110. app_download_url: null,
  111. app_appid: null,
  112. abbreviated_company_name: null
  113. },
  114. status: 'PENDING',
  115. reason: null,
  116. create_time: '2025-03-03T12:00:53+08:00',
  117. update_time: '2025-03-03T12:00:53+08:00'
  118. }
  119. */
  120. @Post('/applications', { summary: '申请收款账户' })
  121. async createPayInOrder(@Body(ALL) params: any) {
  122. return await this.applicationsService.addApplications(params, {
  123. fail: this.fail,
  124. ok: this.ok,
  125. })
  126. // this.easyOpenService.save_user(res, params);
  127. // return res;
  128. }
  129. /**
  130. * 创建账户
  131. */
  132. @Post('/get_applications_list', { summary: '创建账户' })
  133. async getApplicationsList(@Body(ALL) params: any) {
  134. // 获取申请列表
  135. return await this.applicationsService.getApplicationsList(params);
  136. // this.easyOpenService.save_user(res, params);
  137. // return res;
  138. }
  139. /**
  140. * 获取用户的账户余额
  141. */
  142. @Post('/getApplicationsListByMchId', { summary: '获取用户的账户余额' })
  143. async getApplicationsListByMchId() {
  144. // 获取申请列表
  145. return await this.applicationsService.getApplicationsListByMchId();
  146. // this.easyOpenService.save_user(res, params);
  147. // return res;
  148. }
  149. /**
  150. * 获取用户的账户流水
  151. */
  152. @Get('/getTransactionsListByMchId', { summary: '获取用户的账户流水' })
  153. async getTransactionsListByMchId(@Query(ALL) params: any,) {
  154. return await this.applicationsService.getTransactionsListByMchId(params);
  155. }
  156. /**
  157. * 获取用户的收款账户
  158. */
  159. @Get('/getBankAccountsBy', { summary: '获取用户的收款账户' })
  160. async getBankAccountsBy(@Query(ALL) params: any,) {
  161. return await this.applicationsService.getBankAccountsBy(params);
  162. }
  163. /**
  164. * 查询汇率
  165. */
  166. @Get('/getExchangeCurrency', { summary: '获取用户的收款账户' })
  167. async getExchangeCurrency(@Query(ALL) params: any,) {
  168. return await this.applicationsService.getExchangeCurrency(params);
  169. }
  170. /**
  171. * 换汇
  172. */
  173. @Post('/exchanges', { summary: '获取用户的收款账户' })
  174. async exchanges(@Body(ALL) params: any,) {
  175. return await this.applicationsService.exchanges(params);
  176. }
  177. /**
  178. * 转账
  179. * 账户:b847628dec3e59509ac3d3f9d32ad533
  180. */
  181. @Post('/transfer', { summary: '获取用户的收款账户' })
  182. async transfer(@Body(ALL) params: any,) {
  183. return await this.applicationsService.transfer(params);
  184. }
  185. /**
  186. * 付款
  187. * 账户:b847628dec3e59509ac3d3f9d32ad533
  188. */
  189. @Post('/payments', { summary: '获取用户的收款账户' })
  190. async payments(@Body(ALL) params: any,) {
  191. return await this.applicationsService.payments(params);
  192. }
  193. }