From 8bb9173a95a87e3ceab4f48b5b34041af38b7c70 Mon Sep 17 00:00:00 2001
From: zhengyiming <540361168@qq.com>
Date: 星期五, 28 三月 2025 15:23:14 +0800
Subject: [PATCH] fix: 四期需求

---
 packages/core/src/lifeRecharge.ts |   82 +++++++++++++++++++++++++++++++++++++++-
 1 files changed, 79 insertions(+), 3 deletions(-)

diff --git a/packages/core/src/lifeRecharge.ts b/packages/core/src/lifeRecharge.ts
index aa8c8e6..409801a 100644
--- a/packages/core/src/lifeRecharge.ts
+++ b/packages/core/src/lifeRecharge.ts
@@ -2,30 +2,39 @@
   BlLifeRechargeServices,
   PhoneMesssageCodeLoginInput,
   RequestConfig,
+  ChannelOutput,
 } from './lifeRechargeServices';
 import { BlLifeRechargeOptions } from './types';
 import { LifeRechargeConstants } from './lifeRechargeConstants';
 import { BlLifeRechargeAccountModel } from './lifeRechargeAccountModel';
+import { LifeRechargeListener } from './listener';
 
 export class BlLifeRecharge<TResponse = any, TRequestOptions = any> {
   services: BlLifeRechargeServices<TResponse, TRequestOptions>;
   accountModel: BlLifeRechargeAccountModel;
+  listener: LifeRechargeListener;
 
   static constants = LifeRechargeConstants;
   constants = LifeRechargeConstants;
 
+  /**鐢ㄦ埛鎵�鏈夌殑娓犻亾 */
+  userChannles = [] as ChannelOutput[];
+  isBackClientUser: boolean;
+
   constructor(options: BlLifeRechargeOptions<TResponse, TRequestOptions>) {
-    this.services = new BlLifeRechargeServices(options);
-    this.accountModel = new BlLifeRechargeAccountModel({
+    this.listener = new LifeRechargeListener();
+    this.services = new BlLifeRechargeServices(this, options);
+    this.accountModel = new BlLifeRechargeAccountModel(this, {
       userId: options.userId,
       phoneNumber: options.phoneNumber,
+      channlesNum: options.channlesNum,
     });
   }
 
   async login(body: PhoneMesssageCodeLoginInput, options?: RequestConfig) {
     try {
       let res = await this.services.lifePayPhoneMesssageCodeLogin(body, options);
-      this.accountModel.setUserId(res);
+      this.accountModel.setUserId(res.userId);
       this.accountModel.setPhoneNumber(body.phoneNumber);
       return res;
     } catch (error) {
@@ -36,6 +45,7 @@
   loginout() {
     this.accountModel.setUserId('');
     this.accountModel.setPhoneNumber('');
+    this.accountModel.setUserChannles([]);
   }
 
   isLogin() {
@@ -51,4 +61,70 @@
   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