wupengfei
2 天以前 ddddcf83e7deb9d0a674d2bbead300089530d87e
packages/core/src/lifeRechargeAccountModel.ts
@@ -1,20 +1,67 @@
import { BlLifeRechargeAccountModelOptions } from './types';
import { ChannelOutput } from './lifeRechargeServices';
import { BlLifeRecharge } from './lifeRecharge';
export class BlLifeRechargeAccountModel {
export class BlLifeRechargeAccountModel<TResponse = any, TRequestOptions = any> {
  ctx: BlLifeRecharge<TResponse, TRequestOptions>;
  userId = '';
  phoneNumber = '';
  channlesNum = '';
  constructor(options: BlLifeRechargeAccountModelOptions = {}) {
    const { userId = '', phoneNumber = '' } = options;
  /**用户所有的渠道 */
  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);
  }
}