zhengyiming
2025-03-28 381c97332e567a1b95a9a5220275461d0ae3f74e
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
import { BlLifeRechargeAccountModelOptions } from './types';
import { ChannelOutput } from './lifeRechargeServices';
import { BlLifeRecharge } from './lifeRecharge';
 
export class BlLifeRechargeAccountModel<TResponse = any, TRequestOptions = any> {
  ctx: BlLifeRecharge<TResponse, TRequestOptions>;
 
  userId = '';
  phoneNumber = '';
  channlesNum = '';
 
  /**用户所有的渠道 */
  userChannles = [] as ChannelOutput[];
  isBackClientUser: boolean;
 
  constructor(
    ctx: BlLifeRecharge<TResponse, TRequestOptions>,
    options: BlLifeRechargeAccountModelOptions = {}
  ) {
    const { userId = '', phoneNumber = '', channlesNum } = options;
    this.ctx = ctx;
    this.setUserId(userId);
    this.setPhoneNumber(phoneNumber);
    this.setChannlesNum(channlesNum);
  }
 
  setUserId(userId: string) {
    this.userId = userId;
    this.ctx.listener.fireEvent('update', this.ctx);
    // if (userId) {
    //   this.getUserInfo(userId);
    // }
  }
 
  async getUserInfo(userId?: string) {
    try {
      let res = await this.ctx.services.lifePayUserMesssageByIduser(
        {
          id: userId || this.userId,
        },
        {
          showLoading: false,
        }
      );
      this.isBackClientUser = res.isBackClientUser;
      if (res && res.isBackClientUser) {
        this.setUserChannles(res.channlesNum ?? []);
      }
      return res;
    } catch (error) {
      console.log('error: ', error);
    }
  }
 
  setPhoneNumber(phoneNumber: string) {
    this.phoneNumber = phoneNumber;
    this.ctx.listener.fireEvent('update', this.ctx);
  }
  setChannlesNum(channlesNum: string) {
    this.channlesNum = channlesNum;
    this.ctx.listener.fireEvent('update', this.ctx);
  }
  setUserChannles(userChannles: ChannelOutput[]) {
    this.userChannles = userChannles;
    this.ctx.listener.fireEvent('update', this.ctx);
  }
}