wallet.ts 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. import { CoolController, BaseController } from '@cool-midway/core';
  2. import { ALL, Body, Get, Inject, Post, Provide, Query } from '@midwayjs/decorator';
  3. import { BusinessEntity } from '../../payment/entity/business';
  4. import { WalletService } from "../../payment/service/wallet";
  5. /**
  6. * 钱包
  7. */
  8. @Provide()
  9. @CoolController('/api/v1/Fiat')
  10. export class WalletController extends BaseController {
  11. @Inject()
  12. walletService: WalletService;
  13. /**
  14. * 创建钱包
  15. * /api/v3/Fiat/Wallet
  16. */
  17. @Post('/Wallet', { summary: '创建钱包' })
  18. async createWallet(@Body(ALL) business: BusinessEntity) {
  19. // if (!this.allowKeys.includes(key)) {
  20. // return this.fail('非法操作');
  21. // }
  22. // 关键参数校验
  23. // 数据落库
  24. // 回调
  25. console.log(business);
  26. return this.ok(await this.walletService.add(business));
  27. }
  28. /**
  29. * TODO 创建钱包回调通知
  30. *
  31. */
  32. @Post('/wallet/callback', { summary: '创建钱包回调通知' })
  33. async createWalletCallback(@Body(ALL) business: BusinessEntity) {
  34. // if (!this.allowKeys.includes(key)) {
  35. // return this.fail('非法操作');
  36. // }
  37. // 关键参数校验
  38. // 数据落库
  39. // 回调
  40. console.log(business);
  41. return this.ok('hello, cool-admin!!!');
  42. }
  43. /**
  44. * 获取钱包信息
  45. *
  46. */
  47. @Get('/GetWalletAccounts', { summary: '获取钱包信息' })
  48. async GetWalletAccounts(@Query('customer_id') customer_id: string,) {
  49. // if (!this.allowKeys.includes(key)) {
  50. // return this.fail('非法操作');
  51. // }
  52. // 关键参数校验
  53. // 数据落库
  54. // 回调
  55. console.log('GetWalletAccounts', customer_id);
  56. return this.ok(await this.walletService.getWallet(customer_id));
  57. }
  58. /**
  59. * 获取账户币种余额
  60. */
  61. @Get('/AccountBalance', { summary: '获取账户币种余额' })
  62. async AccountBalance(
  63. @Query('customer_id') customer_id: string,
  64. @Query('currency') currency: string,) {
  65. // if (!this.allowKeys.includes(key)) {
  66. // return this.fail('非法操作');
  67. // }
  68. // 关键参数校验
  69. // 数据落库
  70. // 回调
  71. console.log(customer_id,currency);
  72. return this.ok(await this.walletService.getWalletBalance({
  73. customer_id: customer_id,
  74. currency: currency
  75. }));
  76. }
  77. }