feat(用户): 添加已使用余额字段并实现订单和退款逻辑

在用户表中添加 use_balance 字段用于记录已使用余额
修改订单和退款审批服务,在扣款和退款时同步更新该字段
This commit is contained in:
dzq 2025-05-28 11:41:53 +08:00
parent 4f4c3f39cc
commit 66d1fcd026
5 changed files with 13 additions and 0 deletions

View File

@ -148,6 +148,10 @@ public class QyUserEntity extends BaseEntity<QyUserEntity> {
@TableField("balance")
private BigDecimal balance;
@ApiModelProperty("已使用用户余额")
@TableField("use_balance")
private BigDecimal useBalance;
@ApiModelProperty("系统角色id")
@TableField("sys_role_id")
private Long sysRoleId;

View File

@ -106,6 +106,9 @@ public class QyUserDTO {
@ExcelColumn(name = "用户余额")
private BigDecimal balance;
@ExcelColumn(name = "已使用用户余额")
private BigDecimal useBalance;
@ExcelColumn(name = "系统角色ID")
private Long sysRoleId;

View File

@ -192,6 +192,7 @@ public class ReturnApprovalApplicationService {
QyUserEntity qyUser = userService.getUserByUserId(userid, WeixinConstants.corpid);
if (null != qyUser) {
qyUser.setBalance(qyUser.getBalance().add(command.getReturnAmount()));
qyUser.setUseBalance(qyUser.getUseBalance().subtract(command.getReturnAmount()));
}
userService.updateById(qyUser);
} catch (Exception e) {

View File

@ -192,6 +192,7 @@ public class OrderApplicationService {
throw new ApiException(ErrorCode.Client.COMMON_REQUEST_PARAMETERS_INVALID, "余额不足");
} else {
qyUser.setBalance(qyUser.getBalance().subtract(orderModel.getTotalAmount()));
qyUser.setUseBalance(qyUser.getUseBalance().add(orderModel.getTotalAmount()));
userService.updateById(qyUser);
}
// 金额转换元转分并四舍五入

View File

@ -4,4 +4,8 @@ AFTER `goods_detail`;
ALTER TABLE `qy_user`
ADD COLUMN `sys_role_id` BIGINT DEFAULT NULL COMMENT '系统角色id'
AFTER `balance`;
ALTER TABLE `qy_user`
ADD COLUMN `use_balance` decimal(15,2) NOT NULL DEFAULT '0.00' COMMENT '已使用用户余额'
AFTER `balance`;