package com.stylefeng.guns.modular.system.model.vo;
|
|
import com.stylefeng.guns.modular.system.model.UserInfo;
|
import lombok.Data;
|
|
import java.math.BigDecimal;
|
import java.util.Date;
|
import java.util.Random;
|
|
/**
|
* 余额修改记录
|
*
|
* @author Lux
|
* @version 1.0.0
|
* @since 2026/6/23 15:06
|
*/
|
@Data
|
public class BalanceModifyRecordVo {
|
|
private Integer id;
|
|
/**
|
* 流水ID
|
*/
|
private String recordID;
|
|
/**
|
* 用户名称
|
*/
|
private String userName;
|
|
/**
|
* 用户手机号
|
*/
|
private String phone;
|
|
/**
|
* 用户id
|
*/
|
private Integer userId;
|
|
/**
|
* 1=增加,2=减少
|
*/
|
private Integer type;
|
|
/**
|
* '添加时间'
|
*/
|
private Date createTime;
|
|
/**
|
* '金额'
|
*/
|
private BigDecimal money;
|
|
public static BalanceModifyRecordVo convert(UserInfo oldUser, UserInfo newUser) {
|
Random random = new Random();
|
StringBuilder result = new StringBuilder();
|
for (int i = 0; i < 8; i++) {
|
result.append(random.nextInt(10));
|
}
|
BalanceModifyRecordVo recordVo = new BalanceModifyRecordVo();
|
recordVo.setRecordID(result.toString());
|
recordVo.setUserName(newUser.getNickName());
|
recordVo.setPhone(newUser.getPhone());
|
recordVo.setUserId(newUser.getId());
|
recordVo.setCreateTime(new Date());
|
BigDecimal newBalance = newUser.getBalance() != null ? BigDecimal.valueOf(newUser.getBalance()) : BigDecimal.ZERO;
|
BigDecimal oldBalance = oldUser.getBalance() != null ? BigDecimal.valueOf(oldUser.getBalance()) : BigDecimal.ZERO;
|
BigDecimal amount = newBalance.subtract(oldBalance);
|
// 判断方向
|
if (amount.compareTo(BigDecimal.ZERO) > 0) {
|
recordVo.setType(1); // 增加金额(充值)
|
recordVo.setMoney(amount);
|
} else {
|
recordVo.setType(2); // 减少金额,转为正数(消费)
|
recordVo.setMoney(amount.abs());
|
}
|
return recordVo;
|
}
|
}
|