zhengyiming
2025-02-24 3ee683d6b002f098e5b7fed11b54615126d82a3c
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
import {
  BlLifeRechargeServices,
  PhoneMesssageCodeLoginInput,
  RequestConfig,
} from './lifeRechargeServices';
import { IRequest, BlLifeRechargeOptions } from './types';
import { LifeRechargeConstants } from './lifeRechargeConstants';
import { BlLifeRechargeAccountModel } from './lifeRechargeAccountModel';
 
export class BlLifeRecharge<T extends IRequest = IRequest> {
  services: BlLifeRechargeServices<T>;
  accountModel: BlLifeRechargeAccountModel;
 
  static constants = LifeRechargeConstants;
  constants = LifeRechargeConstants;
 
  constructor(options: BlLifeRechargeOptions<T>) {
    this.services = new BlLifeRechargeServices(options);
    this.accountModel = new BlLifeRechargeAccountModel({
      userId: options.userId,
      phoneNumber: options.phoneNumber,
    });
  }
 
  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;
  }
 
  loginout() {
    this.accountModel.setUserId('');
    this.accountModel.setPhoneNumber('');
  }
 
  isLogin() {
    return !!this.accountModel.userId;
  }
 
  getRechargeParValue(amount: number | string, rate: number) {
    return (Number(amount) * rate).toFixed(2);
  }
}