| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200 |
- import {
- APP_PAYMENT_ORDER,
- APP_PAY_ORDER_LIST,
- APP_RECHARGE_CONFIG,
- APP_WITHDRAW_BASE_INFO,
- APP_WITHDRAW_PAYOUT,
- APP_WITHDRAW_RECORD,
- APP_WITHDRAW_SET_INFO,
- success,
- } from '@scripts/api';
- import { ApiEnvelope, Http } from '@scripts/request';
- import {
- IGoodsConfig,
- IPaymentOrder,
- IPaymentOrderRequest,
- IPayOrderItem,
- IPayOrderPageData,
- IRechargeConfigData,
- IWithdrawBaseInfo,
- IWithdrawBaseInfoRequest,
- IWithdrawPayoutRequest,
- IWithdrawRecordItem,
- IWithdrawRecordPageData,
- IWithdrawRecordRequest,
- IWithdrawSetInfoRequest,
- } from './data';
- class PayStore {
- private _config: IGoodsConfig[] = [];
- private _showBonus: boolean | number = false;
- private _cpfFirst: boolean | number = false;
- private _currPayOrder: IPaymentOrder = null;
- private _currPayGiftID = -1;
- private _payOrderList: IPayOrderItem[] = [];
- private _withdrawBaseInfo: IWithdrawBaseInfo = null;
- private _withdrawRecord: IWithdrawRecordItem[] = [];
- public get config() { return this._config; }
- public get showBonus() { return this._showBonus; }
- public get cpfFirst() { return this._cpfFirst; }
- public get currPayOrder() { return this._currPayOrder; }
- public get currPayGiftID() { return this._currPayGiftID; }
- public get payOrderList() { return this._payOrderList; }
- public get withdrawBaseInfo() { return this._withdrawBaseInfo; }
- public get withdrawRecord() { return this._withdrawRecord; }
- async reqRechargeConfig() {
- const res = await Http.call<IRechargeConfigData>(APP_RECHARGE_CONFIG);
- if (success(res) && res.data) {
- this._config = Array.isArray(res.data.list) ? res.data.list : [];
- this._showBonus = res.data.bonus_show ?? false;
- this._cpfFirst = res.data.cpf_first ?? false;
- }
- return res;
- }
- async reqPaymentOrder(arg: IPaymentOrderRequest): Promise<boolean> {
- const user = arg.user;
- const price = arg.price ?? arg.prices;
- const params = {
- tranType: '0502',
- payAmt: price,
- goodsName: arg.goodsName,
- buyIp: '',
- pay_type: arg.payType,
- pay_method: arg.pay_method,
- GiftsID: arg.GiftsID,
- eventType: arg.eventType || 1,
- AdId: user?.GlobalUID,
- userName: user?.NickName,
- userEmail: user?.Email,
- userPhone: user?.Phone,
- rand_str: Date.now(),
- cpf_first: arg.cpf_first || 0,
- };
- const res = await Http.call<Record<string, unknown>>(APP_PAYMENT_ORDER, params);
- if (success(res) && res.data && !Array.isArray(res.data)) {
- const orderArg: Partial<IPaymentOrderRequest> = { ...arg };
- delete orderArg.user;
- this._currPayOrder = {
- ...res.data,
- createAt: Date.now(),
- deadline: Number(res.data.deadline ?? 15 * 60),
- status: 'pending',
- arg: orderArg,
- };
- this._currPayGiftID = Number(arg.GiftsID ?? -1);
- return true;
- }
- return false;
- }
- async reqPayOrderList(page = 1, pageSize = 10) {
- const res = await Http.call<IPayOrderPageData>(APP_PAY_ORDER_LIST, { page, pageSize });
- if (success(res) && res.data) {
- this._payOrderList = Array.isArray(res.data.data) ? res.data.data : [];
- return true;
- }
- return false;
- }
- async reqWithdrawBaseInfo(arg: IWithdrawBaseInfoRequest = {}): Promise<boolean> {
- const res = await Http.call<IWithdrawBaseInfo>(APP_WITHDRAW_BASE_INFO, {
- paypass: arg.paypass || '',
- });
- if (success(res) && res.data) {
- this._withdrawBaseInfo = this.parseWithdrawBaseInfo(res.data);
- return true;
- }
- return false;
- }
- async reqWithdrawRecord(arg: IWithdrawRecordRequest = {}) {
- const params: Record<string, unknown> = {
- paypass: arg.paypass || '',
- };
- if (arg.score_type !== undefined) params.score_type = arg.score_type;
- if (arg.sort_by !== undefined) params.sort_by = arg.sort_by;
- if (arg.sort !== undefined) params.sort = arg.sort;
- const res = await Http.call<IWithdrawRecordPageData>(APP_WITHDRAW_RECORD, params);
- if (success(res) && res.data) {
- this._withdrawRecord = Array.isArray(res.data.data) ? res.data.data : [];
- return true;
- }
- return false;
- }
- async reqWithdrawSetInfo(arg: IWithdrawSetInfoRequest): Promise<boolean> {
- const params = {
- paypass: arg.paypass || '',
- cbPixType: arg.PixType,
- bank: arg.bank,
- account: arg.account,
- userName: arg.userName,
- phone: arg.phone,
- PAN: arg.PAN,
- email: arg.email,
- IFSC: arg.IFSC,
- adhaar: arg.adhaar,
- branceBank: arg.branceBank,
- PixNum: arg.PixNum,
- code: arg.code || '',
- };
- const res = await Http.call(APP_WITHDRAW_SET_INFO, params);
- if (success(res)) {
- await this.reqWithdrawBaseInfo({ paypass: arg.paypass });
- return true;
- }
- return false;
- }
- async reqWithdrawPayout(arg: IWithdrawPayoutRequest): Promise<boolean> {
- const res = await Http.call(APP_WITHDRAW_PAYOUT, {
- paypass: arg.paypass || '',
- score: arg.score,
- });
- if (success(res)) {
- await this.reqWithdrawBaseInfo({ paypass: arg.paypass });
- return true;
- }
- return false;
- }
- clear() {
- this._currPayOrder = null;
- this._currPayGiftID = -1;
- this._payOrderList = [];
- this._withdrawBaseInfo = null;
- this._withdrawRecord = [];
- }
- private parseWithdrawBaseInfo(data: IWithdrawBaseInfo): IWithdrawBaseInfo {
- const info = { ...data };
- if (Number(info.SumCanExchange) < 0) info.SumCanExchange = 0;
- const defaultCooldown = Number(info.withdraw_info_cooldown_seconds || 0);
- const cashappCooldown = Number(
- info.withdraw_info_precheck?.cashapp?.cooldown_seconds ?? defaultCooldown,
- );
- const paypalCooldown = Number(
- info.withdraw_info_precheck?.paypal?.cooldown_seconds ?? defaultCooldown,
- );
- info.cashapp_update_cd = cashappCooldown > 0 ? Date.now() + cashappCooldown * 1000 : 0;
- info.paypal_update_cd = paypalCooldown > 0 ? Date.now() + paypalCooldown * 1000 : 0;
- info.lastUpdateTs = Date.now() - Number(info.withdraw_info_update_time_pass || 0) * 1000;
- return info;
- }
- }
- export const payStore = new PayStore();
|