PayStore.ts 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200
  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 _showBonus: boolean | number = false;
  30. private _cpfFirst: boolean | number = false;
  31. private _currPayOrder: IPaymentOrder = null;
  32. private _currPayGiftID = -1;
  33. private _payOrderList: IPayOrderItem[] = [];
  34. private _withdrawBaseInfo: IWithdrawBaseInfo = null;
  35. private _withdrawRecord: IWithdrawRecordItem[] = [];
  36. public get config() { return this._config; }
  37. public get showBonus() { return this._showBonus; }
  38. public get cpfFirst() { return this._cpfFirst; }
  39. public get currPayOrder() { return this._currPayOrder; }
  40. public get currPayGiftID() { return this._currPayGiftID; }
  41. public get payOrderList() { return this._payOrderList; }
  42. public get withdrawBaseInfo() { return this._withdrawBaseInfo; }
  43. public get withdrawRecord() { return this._withdrawRecord; }
  44. async reqRechargeConfig() {
  45. const res = await Http.call<IRechargeConfigData>(APP_RECHARGE_CONFIG);
  46. if (success(res) && res.data) {
  47. this._config = Array.isArray(res.data.list) ? res.data.list : [];
  48. this._showBonus = res.data.bonus_show ?? false;
  49. this._cpfFirst = res.data.cpf_first ?? false;
  50. }
  51. return res;
  52. }
  53. async reqPaymentOrder(arg: IPaymentOrderRequest): Promise<boolean> {
  54. const user = arg.user;
  55. const price = arg.price ?? arg.prices;
  56. const params = {
  57. tranType: '0502',
  58. payAmt: price,
  59. goodsName: arg.goodsName,
  60. buyIp: '',
  61. pay_type: arg.payType,
  62. pay_method: arg.pay_method,
  63. GiftsID: arg.GiftsID,
  64. eventType: arg.eventType || 1,
  65. AdId: user?.GlobalUID,
  66. userName: user?.NickName,
  67. userEmail: user?.Email,
  68. userPhone: user?.Phone,
  69. rand_str: Date.now(),
  70. cpf_first: arg.cpf_first || 0,
  71. };
  72. const res = await Http.call<Record<string, unknown>>(APP_PAYMENT_ORDER, params);
  73. if (success(res) && res.data && !Array.isArray(res.data)) {
  74. const orderArg: Partial<IPaymentOrderRequest> = { ...arg };
  75. delete orderArg.user;
  76. this._currPayOrder = {
  77. ...res.data,
  78. createAt: Date.now(),
  79. deadline: Number(res.data.deadline ?? 15 * 60),
  80. status: 'pending',
  81. arg: orderArg,
  82. };
  83. this._currPayGiftID = Number(arg.GiftsID ?? -1);
  84. return true;
  85. }
  86. return false;
  87. }
  88. async reqPayOrderList(page = 1, pageSize = 10) {
  89. const res = await Http.call<IPayOrderPageData>(APP_PAY_ORDER_LIST, { page, pageSize });
  90. if (success(res) && res.data) {
  91. this._payOrderList = Array.isArray(res.data.data) ? res.data.data : [];
  92. return true;
  93. }
  94. return false;
  95. }
  96. async reqWithdrawBaseInfo(arg: IWithdrawBaseInfoRequest = {}): Promise<boolean> {
  97. const res = await Http.call<IWithdrawBaseInfo>(APP_WITHDRAW_BASE_INFO, {
  98. paypass: arg.paypass || '',
  99. });
  100. if (success(res) && res.data) {
  101. this._withdrawBaseInfo = this.parseWithdrawBaseInfo(res.data);
  102. return true;
  103. }
  104. return false;
  105. }
  106. async reqWithdrawRecord(arg: IWithdrawRecordRequest = {}) {
  107. const params: Record<string, unknown> = {
  108. paypass: arg.paypass || '',
  109. };
  110. if (arg.score_type !== undefined) params.score_type = arg.score_type;
  111. if (arg.sort_by !== undefined) params.sort_by = arg.sort_by;
  112. if (arg.sort !== undefined) params.sort = arg.sort;
  113. const res = await Http.call<IWithdrawRecordPageData>(APP_WITHDRAW_RECORD, params);
  114. if (success(res) && res.data) {
  115. this._withdrawRecord = Array.isArray(res.data.data) ? res.data.data : [];
  116. return true;
  117. }
  118. return false;
  119. }
  120. async reqWithdrawSetInfo(arg: IWithdrawSetInfoRequest): Promise<boolean> {
  121. const params = {
  122. paypass: arg.paypass || '',
  123. cbPixType: arg.PixType,
  124. bank: arg.bank,
  125. account: arg.account,
  126. userName: arg.userName,
  127. phone: arg.phone,
  128. PAN: arg.PAN,
  129. email: arg.email,
  130. IFSC: arg.IFSC,
  131. adhaar: arg.adhaar,
  132. branceBank: arg.branceBank,
  133. PixNum: arg.PixNum,
  134. code: arg.code || '',
  135. };
  136. const res = await Http.call(APP_WITHDRAW_SET_INFO, params);
  137. if (success(res)) {
  138. await this.reqWithdrawBaseInfo({ paypass: arg.paypass });
  139. return true;
  140. }
  141. return false;
  142. }
  143. async reqWithdrawPayout(arg: IWithdrawPayoutRequest): Promise<boolean> {
  144. const res = await Http.call(APP_WITHDRAW_PAYOUT, {
  145. paypass: arg.paypass || '',
  146. score: arg.score,
  147. });
  148. if (success(res)) {
  149. await this.reqWithdrawBaseInfo({ paypass: arg.paypass });
  150. return true;
  151. }
  152. return false;
  153. }
  154. clear() {
  155. this._currPayOrder = null;
  156. this._currPayGiftID = -1;
  157. this._payOrderList = [];
  158. this._withdrawBaseInfo = null;
  159. this._withdrawRecord = [];
  160. }
  161. private parseWithdrawBaseInfo(data: IWithdrawBaseInfo): IWithdrawBaseInfo {
  162. const info = { ...data };
  163. if (Number(info.SumCanExchange) < 0) info.SumCanExchange = 0;
  164. const defaultCooldown = Number(info.withdraw_info_cooldown_seconds || 0);
  165. const cashappCooldown = Number(
  166. info.withdraw_info_precheck?.cashapp?.cooldown_seconds ?? defaultCooldown,
  167. );
  168. const paypalCooldown = Number(
  169. info.withdraw_info_precheck?.paypal?.cooldown_seconds ?? defaultCooldown,
  170. );
  171. info.cashapp_update_cd = cashappCooldown > 0 ? Date.now() + cashappCooldown * 1000 : 0;
  172. info.paypal_update_cd = paypalCooldown > 0 ? Date.now() + paypalCooldown * 1000 : 0;
  173. info.lastUpdateTs = Date.now() - Number(info.withdraw_info_update_time_pass || 0) * 1000;
  174. return info;
  175. }
  176. }
  177. export const payStore = new PayStore();