From c24cdd854e258712408a7904bdb401c49e3f07c1 Mon Sep 17 00:00:00 2001
From: zhengyiming <540361168@qq.com>
Date: 星期四, 28 八月 2025 13:09:08 +0800
Subject: [PATCH] fix: 修改通道充值提示语
---
packages/core/src/lifeRecharge.ts | 116 ++++++++++++++++++++++++++++++++++++++++++++++++++++-----
1 files changed, 105 insertions(+), 11 deletions(-)
diff --git a/packages/core/src/lifeRecharge.ts b/packages/core/src/lifeRecharge.ts
index ca0de2e..7bd3191 100644
--- a/packages/core/src/lifeRecharge.ts
+++ b/packages/core/src/lifeRecharge.ts
@@ -2,36 +2,55 @@
BlLifeRechargeServices,
PhoneMesssageCodeLoginInput,
RequestConfig,
+ ChannelOutput,
} from './lifeRechargeServices';
-import { IRequest, BlLifeRechargeOptions } from './types';
+import { BlLifeRechargeOptions } from './types';
import { LifeRechargeConstants } from './lifeRechargeConstants';
import { BlLifeRechargeAccountModel } from './lifeRechargeAccountModel';
+import { LifeRechargeListener } from './listener';
-export class BlLifeRecharge<T extends IRequest = IRequest> {
- services: BlLifeRechargeServices<T>;
+export class BlLifeRecharge<TResponse = any, TRequestOptions = any> {
+ services: BlLifeRechargeServices<TResponse, TRequestOptions>;
accountModel: BlLifeRechargeAccountModel;
+ listener: LifeRechargeListener;
static constants = LifeRechargeConstants;
constants = LifeRechargeConstants;
- constructor(options: BlLifeRechargeOptions<T>) {
- this.services = new BlLifeRechargeServices(options);
- this.accountModel = new BlLifeRechargeAccountModel({
+ constructor(options: BlLifeRechargeOptions<TResponse, TRequestOptions>) {
+ this.listener = new LifeRechargeListener();
+ this.services = new BlLifeRechargeServices(this, options);
+ this.accountModel = new BlLifeRechargeAccountModel(this, {
userId: options.userId,
phoneNumber: options.phoneNumber,
+ channlesNum: options.channlesNum,
});
}
+ init() {
+ if (this.accountModel.userId) {
+ this.accountModel.getUserInfo();
+ }
+ }
+
async login(body: PhoneMesssageCodeLoginInput, options?: RequestConfig) {
- let res = await this.services.lifePayPhoneMesssageCodeLogin(body, options);
- this.accountModel.setUserId(res);
- this.accountModel.setPhoneNumber(body.phoneNumber);
- return res;
+ try {
+ let res = await this.services.lifePayPhoneMesssageCodeLogin(body, options);
+ this.accountModel.setUserId(res.userId);
+ this.accountModel.getUserInfo();
+ this.accountModel.setPhoneNumber(body.phoneNumber);
+ return res;
+ } catch (error) {
+ throw new Error(error);
+ }
}
loginout() {
this.accountModel.setUserId('');
this.accountModel.setPhoneNumber('');
+ this.accountModel.setUserChannles([]);
+ this.accountModel.isBackClientUser = false;
+ this.accountModel.setUserPromoterIdNumber('');
}
isLogin() {
@@ -39,6 +58,81 @@
}
getRechargeParValue(amount: number | string, rate: number) {
- return (Number(amount) * rate).toFixed(2);
+ if (rate > 0) {
+ return ((Number(amount) * rate) / 100).toFixed(2);
+ }
+ return Number(amount).toFixed(2);
+ }
+
+ MaxParValue = 300;
+
+ filterParValueList(parValueList: string[]) {
+ return parValueList.filter((x) => Number(x) <= this.MaxParValue);
+ }
+
+ getCarrierByPhoneNumber(phoneNumber: string): LifeRechargeConstants.IspCode {
+ // 瀹氫箟鍙锋鍜屽搴旂殑杩愯惀鍟�
+ const carrierSegments = {
+ [LifeRechargeConstants.IspCode.yidong]: [
+ '134',
+ '135',
+ '136',
+ '137',
+ '138',
+ '139',
+ '150',
+ '151',
+ '152',
+ '157',
+ '158',
+ '159',
+ '182',
+ '183',
+ '184',
+ '187',
+ '188',
+ '198',
+ '147',
+ '178',
+ '165',
+ ],
+ [LifeRechargeConstants.IspCode.liantong]: [
+ '130',
+ '131',
+ '132',
+ '155',
+ '156',
+ '185',
+ '186',
+ '145',
+ '176',
+ '166',
+ ],
+ [LifeRechargeConstants.IspCode.dianxin]: [
+ '133',
+ '153',
+ '180',
+ '181',
+ '189',
+ '177',
+ '199',
+ '191',
+ ],
+ };
+
+ // 妫�鏌ユ墜鏈哄彿鏄惁鏈夋晥锛堣繖閲屽彧绠�鍗曟鏌ラ暱搴︼級
+ if (!/^\d{11}$/.test(phoneNumber)) {
+ return '' as any;
+ }
+
+ let prefix = phoneNumber.substr(0, 3);
+ for (let carrier in carrierSegments) {
+ if (carrierSegments[carrier].includes(prefix)) {
+ return carrier as LifeRechargeConstants.IspCode;
+ }
+ }
+
+ // 濡傛灉娌℃湁鎵惧埌鍖归厤鐨勫彿娈碉紝鍒欒繑鍥炴湭鐭�
+ return '' as any;
}
}
--
Gitblit v1.9.1