| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196 |
- import {
- APP_FIRST_PACK,
- APP_FIRST_PACK_VISIBLE,
- 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 {
- IFirstPack,
- IFirstPackVisible,
- IGoodsConfig,
- IPaymentOrder,
- IPaymentOrderRequest,
- IPayOrderItem,
- IPayOrderPageData,
- IRechargeConfigData,
- IWithdrawBaseInfo,
- IWithdrawBaseInfoRequest,
- IWithdrawPayoutRequest,
- IWithdrawRecordItem,
- IWithdrawRecordPageData,
- IWithdrawRecordRequest,
- IWithdrawSetInfoRequest,
- } from './data';
- class PayStore {
- private _config: IGoodsConfig[] = [];
- private _payOrderList: IPayOrderItem[] = [];
- private _withdrawBaseInfo: IWithdrawBaseInfo = null;
- private _withdrawRecord: IWithdrawRecordItem[] = [];
- private _firstPackVisible = false;
- public get config() { return this._config; }
- public get payOrderList() { return this._payOrderList; }
- public get withdrawBaseInfo() { return this._withdrawBaseInfo; }
- public get withdrawRecord() { return this._withdrawRecord; }
- public get firstPackVisible() { return this._firstPackVisible; }
- async reqRechargeConfig() {
- const res = await Http.call<IRechargeConfigData>(APP_RECHARGE_CONFIG);
- if (success(res) && res.data) {
- let icon_id = 1;
- const goods_list = Array.isArray(res.data.list) ? res.data.list : [];
- this._config = [...goods_list, ...goods_list].map(goods => {
- goods.gears = JSON.parse(goods.gear);
- goods.cp = Number(goods.cp);
- goods.cp_reward = Number(goods.cp_reward);
- goods.cp_reward_display_percent = Number(goods.cp_reward_display_percent);
- goods.gc = Number(goods.gc);
- goods.gc_reward = Number(goods.gc_reward);
- goods.gc_reward_display_percent = Number(goods.gc_reward_display_percent);
- goods.sc = Number(goods.sc);
- goods.sc_reward = Number(goods.sc_reward);
- goods.sc_reward_display_percent = Number(goods.sc_reward_display_percent);
- goods.icon_id = icon_id;
- icon_id++;
- return goods;
- });
- return true
- }
- return false;
- }
- async reqPaymentOrder(params: IPaymentOrderRequest): Promise<boolean> {
- const res = await Http.call<Record<string, unknown>>(APP_PAYMENT_ORDER, params as any);
- if (success(res) && res.data && !Array.isArray(res.data)) {
- 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 reqFirstPackVisible() {
- const res = await Http.call<IFirstPackVisible>(APP_FIRST_PACK_VISIBLE);
- if (success(res)) {
- this._firstPackVisible = res.data.show;
- return res.data.show;
- }
- return false;
- }
- async reqFirstPackInfo() {
- const res = await Http.call<IFirstPack>(APP_FIRST_PACK);
- if (success(res)) {
- return res.data;
- }
- }
- 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._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();
|