PayStore.ts 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  1. import {
  2. APP_PAYMENT_ORDER,
  3. APP_PAY_ORDER_LIST,
  4. APP_RECHARGE_CONFIG,
  5. APP_WITHDRAW_BASE_INFO,
  6. APP_WITHDRAW_PAYOUT,
  7. APP_WITHDRAW_RECORD,
  8. APP_WITHDRAW_SET_INFO,
  9. success,
  10. } from '@scripts/api';
  11. import { ApiEnvelope, Http } from '@scripts/request';
  12. import {
  13. IGoodsConfig,
  14. IPaymentOrder,
  15. IPaymentOrderRequest,
  16. IPayOrderItem,
  17. IPayOrderPageData,
  18. IRechargeConfigData,
  19. IWithdrawBaseInfo,
  20. IWithdrawBaseInfoRequest,
  21. IWithdrawPayoutRequest,
  22. IWithdrawRecordItem,
  23. IWithdrawRecordPageData,
  24. IWithdrawRecordRequest,
  25. IWithdrawSetInfoRequest,
  26. } from './data';
  27. class PayStore {
  28. private _config: IGoodsConfig[] = [];
  29. private _payOrderList: IPayOrderItem[] = [];
  30. private _withdrawBaseInfo: IWithdrawBaseInfo = null;
  31. private _withdrawRecord: IWithdrawRecordItem[] = [];
  32. public get config() { return this._config; }
  33. public get payOrderList() { return this._payOrderList; }
  34. public get withdrawBaseInfo() { return this._withdrawBaseInfo; }
  35. public get withdrawRecord() { return this._withdrawRecord; }
  36. async reqRechargeConfig() {
  37. const res = await Http.call<IRechargeConfigData>(APP_RECHARGE_CONFIG);
  38. if (success(res) && res.data) {
  39. const goods_list = Array.isArray(res.data.list) ? res.data.list : [];
  40. this._config = goods_list.map(goods => {
  41. goods.gears = JSON.parse(goods.gear);
  42. return goods;
  43. });
  44. return true
  45. }
  46. return false;
  47. }
  48. async reqPaymentOrder(params: IPaymentOrderRequest): Promise<boolean> {
  49. const res = await Http.call<Record<string, unknown>>(APP_PAYMENT_ORDER, params as any);
  50. if (success(res) && res.data && !Array.isArray(res.data)) {
  51. return true;
  52. }
  53. return false;
  54. }
  55. async reqPayOrderList(page = 1, pageSize = 10) {
  56. const res = await Http.call<IPayOrderPageData>(APP_PAY_ORDER_LIST, { page, pageSize });
  57. if (success(res) && res.data) {
  58. this._payOrderList = Array.isArray(res.data.data) ? res.data.data : [];
  59. return true;
  60. }
  61. return false;
  62. }
  63. async reqWithdrawBaseInfo(arg: IWithdrawBaseInfoRequest = {}): Promise<boolean> {
  64. const res = await Http.call<IWithdrawBaseInfo>(APP_WITHDRAW_BASE_INFO, {
  65. paypass: arg.paypass || '',
  66. });
  67. if (success(res) && res.data) {
  68. this._withdrawBaseInfo = this.parseWithdrawBaseInfo(res.data);
  69. return true;
  70. }
  71. return false;
  72. }
  73. async reqWithdrawRecord(arg: IWithdrawRecordRequest = {}) {
  74. const params: Record<string, unknown> = {
  75. paypass: arg.paypass || '',
  76. };
  77. if (arg.score_type !== undefined) params.score_type = arg.score_type;
  78. if (arg.sort_by !== undefined) params.sort_by = arg.sort_by;
  79. if (arg.sort !== undefined) params.sort = arg.sort;
  80. const res = await Http.call<IWithdrawRecordPageData>(APP_WITHDRAW_RECORD, params);
  81. if (success(res) && res.data) {
  82. this._withdrawRecord = Array.isArray(res.data.data) ? res.data.data : [];
  83. return true;
  84. }
  85. return false;
  86. }
  87. async reqWithdrawSetInfo(arg: IWithdrawSetInfoRequest): Promise<boolean> {
  88. const params = {
  89. paypass: arg.paypass || '',
  90. cbPixType: arg.PixType,
  91. bank: arg.bank,
  92. account: arg.account,
  93. userName: arg.userName,
  94. phone: arg.phone,
  95. PAN: arg.PAN,
  96. email: arg.email,
  97. IFSC: arg.IFSC,
  98. adhaar: arg.adhaar,
  99. branceBank: arg.branceBank,
  100. PixNum: arg.PixNum,
  101. code: arg.code || '',
  102. };
  103. const res = await Http.call(APP_WITHDRAW_SET_INFO, params);
  104. if (success(res)) {
  105. await this.reqWithdrawBaseInfo({ paypass: arg.paypass });
  106. return true;
  107. }
  108. return false;
  109. }
  110. async reqWithdrawPayout(arg: IWithdrawPayoutRequest): Promise<boolean> {
  111. const res = await Http.call(APP_WITHDRAW_PAYOUT, {
  112. paypass: arg.paypass || '',
  113. score: arg.score,
  114. });
  115. if (success(res)) {
  116. await this.reqWithdrawBaseInfo({ paypass: arg.paypass });
  117. return true;
  118. }
  119. return false;
  120. }
  121. clear() {
  122. this._payOrderList = [];
  123. this._withdrawBaseInfo = null;
  124. this._withdrawRecord = [];
  125. }
  126. private parseWithdrawBaseInfo(data: IWithdrawBaseInfo): IWithdrawBaseInfo {
  127. const info = { ...data };
  128. if (Number(info.SumCanExchange) < 0) info.SumCanExchange = 0;
  129. const defaultCooldown = Number(info.withdraw_info_cooldown_seconds || 0);
  130. const cashappCooldown = Number(
  131. info.withdraw_info_precheck?.cashapp?.cooldown_seconds ?? defaultCooldown,
  132. );
  133. const paypalCooldown = Number(
  134. info.withdraw_info_precheck?.paypal?.cooldown_seconds ?? defaultCooldown,
  135. );
  136. info.cashapp_update_cd = cashappCooldown > 0 ? Date.now() + cashappCooldown * 1000 : 0;
  137. info.paypal_update_cd = paypalCooldown > 0 ? Date.now() + paypalCooldown * 1000 : 0;
  138. info.lastUpdateTs = Date.now() - Number(info.withdraw_info_update_time_pass || 0) * 1000;
  139. return info;
  140. }
  141. }
  142. export const payStore = new PayStore();