用户退款和自动退款区分
This commit is contained in:
parent
16477eefe3
commit
da4647aceb
|
@ -59,5 +59,10 @@ public class OrderVO extends Order {
|
|||
private LocalDateTime payTime;
|
||||
@ApiModelProperty("支付渠道名称")
|
||||
private String payChannelName;
|
||||
@ApiModelProperty("自动退款金额")
|
||||
private BigDecimal payAutoRefund;
|
||||
@ApiModelProperty("管理员退款金额")
|
||||
private BigDecimal payAdminRefund;
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -33,6 +33,9 @@ public class OrderRefundDTO implements LogBizParam {
|
|||
@ApiModelProperty("操作人名称")
|
||||
private String userName;
|
||||
|
||||
@ApiModelProperty("退款方式(1-自动退款,2-管理员退款)")
|
||||
private String type;
|
||||
|
||||
@Override
|
||||
public Object logBizId() {
|
||||
return orderId;
|
||||
|
|
|
@ -61,6 +61,8 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
|||
bp.refunding as pay_refunding,
|
||||
bp.pay_time as pay_time,
|
||||
bp.channel_name as pay_channel_name,
|
||||
bp.auto_refund as pay_auto_refund,
|
||||
bp.admin_refund as pay_admin_refund,
|
||||
bod.device_id,
|
||||
bod.device_mac,
|
||||
bod.device_sn,
|
||||
|
|
|
@ -66,6 +66,7 @@ import com.ruoyi.bst.pay.domain.enums.PayBstType;
|
|||
import com.ruoyi.bst.pay.domain.vo.DoPayVO;
|
||||
import com.ruoyi.bst.pay.service.PayConverter;
|
||||
import com.ruoyi.bst.pay.service.PayService;
|
||||
import com.ruoyi.bst.refund.domain.enums.RefundType;
|
||||
import com.ruoyi.bst.sms.service.SmsService;
|
||||
import com.ruoyi.common.core.domain.vo.UserVO;
|
||||
import com.ruoyi.common.core.redis.RedisLock;
|
||||
|
@ -497,8 +498,7 @@ public class OrderServiceImpl implements OrderService
|
|||
// 订单剩余金额退款
|
||||
BigDecimal refund = MathUtils.subtractDecimal(order.getPayAmount(), order.getTotalFee());
|
||||
if (refund != null && refund.compareTo(BigDecimal.ZERO) > 0) {
|
||||
String reason = "【自动退款】订单剩余金额退款" + order.getNo();
|
||||
return this.refund(order, refund, reason, null, "系统");
|
||||
return this.refund(order, refund, null, null, "系统", RefundType.AUTO.getCode());
|
||||
}
|
||||
|
||||
return 1;
|
||||
|
@ -513,7 +513,7 @@ public class OrderServiceImpl implements OrderService
|
|||
* @param userName 操作人名称
|
||||
* @return 结果
|
||||
*/
|
||||
private int refund(OrderVO order, BigDecimal amount, String reason, Long userId, String userName) {
|
||||
private int refund(OrderVO order, BigDecimal amount, String reason, Long userId, String userName, String type) {
|
||||
ServiceUtil.assertion(order == null, "参数错误,order不允许为空");
|
||||
ServiceUtil.assertion(!OrderStatus.canRefund().contains(order.getStatus()), "ID为%s的订单当前状态不允许退款", order.getId());
|
||||
ServiceUtil.assertion(amount == null || amount.compareTo(BigDecimal.ZERO) <= 0, "参数错误,退款金额不允许为空且必须大于0");
|
||||
|
@ -521,18 +521,32 @@ public class OrderServiceImpl implements OrderService
|
|||
BigDecimal canRefundAmount = OrderUtil.calcCanRefundAmount(order);
|
||||
ServiceUtil.assertion(canRefundAmount.compareTo(amount) < 0, "ID为%s的订单可退款金额不足,当前可退款金额为%s元", order.getId(), canRefundAmount);
|
||||
|
||||
|
||||
// 退款原因
|
||||
if (RefundType.ADMIN.getCode().equals(type)) {
|
||||
reason = String.format("【管理员退款】%s订单%s退款 %s 元", userName, order.getNo(), amount);
|
||||
} else {
|
||||
reason = String.format("【自动退款】%s订单%s退款 %s 元", userName, order.getNo(), amount);
|
||||
}
|
||||
if (StringUtils.isNotBlank(reason)) {
|
||||
reason += ":" + reason;
|
||||
}
|
||||
String refundReason = reason;
|
||||
|
||||
Integer result = transactionTemplate.execute(status -> {
|
||||
|
||||
// 分成退款
|
||||
boolean bonusRefund = bonusService.refundByBst(BonusBstType.ORDER, order.getId(), amount, order.getPayAmount(), reason);
|
||||
boolean bonusRefund = bonusService.refundByBst(BonusBstType.ORDER, order.getId(), amount, order.getPayAmount(), refundReason);
|
||||
ServiceUtil.assertion(!bonusRefund, "ID为%s的订单分成退款失败", order.getId());
|
||||
|
||||
// 支付退款
|
||||
PayRefundDTO dto = new PayRefundDTO();
|
||||
dto.setId(order.getPayId());
|
||||
dto.setRefundAmount(amount);
|
||||
dto.setRefundReason(reason);
|
||||
dto.setRefundReason(refundReason);
|
||||
dto.setUserId(userId);
|
||||
dto.setUserName(userName);
|
||||
dto.setType(type);
|
||||
return payService.refund(dto);
|
||||
});
|
||||
|
||||
|
@ -588,8 +602,7 @@ public class OrderServiceImpl implements OrderService
|
|||
public int refund(OrderRefundDTO dto) {
|
||||
OrderVO order = this.selectOrderById(dto.getOrderId());
|
||||
|
||||
// 退款
|
||||
return this.refund(order, dto.getAmount(), dto.getReason(), dto.getUserId(), dto.getUserName());
|
||||
return this.refund(order, dto.getAmount(), dto.getReason(), dto.getUserId(), dto.getUserName(), dto.getType());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -100,6 +100,14 @@ public class Pay extends BaseEntity implements Payable
|
|||
@ApiModelProperty("运营区ID")
|
||||
private Long areaId;
|
||||
|
||||
@Excel(name = "自动退款金额", readConverterExp = "元=")
|
||||
@ApiModelProperty("自动退款金额")
|
||||
private BigDecimal autoRefund;
|
||||
|
||||
@Excel(name = "管理员退款金额", readConverterExp = "元=")
|
||||
@ApiModelProperty("管理员退款金额")
|
||||
private BigDecimal adminRefund;
|
||||
|
||||
/**
|
||||
* 获取价格(分)
|
||||
*/
|
||||
|
|
|
@ -27,4 +27,7 @@ public class PayRefundDTO {
|
|||
@ApiModelProperty("退款操作人名称")
|
||||
private String userName;
|
||||
|
||||
@ApiModelProperty("退款方式(1-自动退款,2-管理员退款)")
|
||||
private String type;
|
||||
|
||||
}
|
||||
|
|
|
@ -83,7 +83,7 @@ public interface PayMapper
|
|||
* @param amount 退款金额
|
||||
* @return 结果
|
||||
*/
|
||||
int addRefundingAmount(@Param("id") Long id, @Param("amount") BigDecimal amount);
|
||||
int addRefundingAmount(@Param("id") Long id, @Param("amount") BigDecimal amount, @Param("type") String type);
|
||||
|
||||
/**
|
||||
* 记录退款金额
|
||||
|
|
|
@ -28,7 +28,9 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
|||
bp.expire_time,
|
||||
bp.app_name,
|
||||
bp.channel_name,
|
||||
bp.area_id
|
||||
bp.area_id,
|
||||
bp.auto_refund,
|
||||
bp.admin_refund
|
||||
from bst_pay bp
|
||||
</sql>
|
||||
|
||||
|
@ -95,6 +97,8 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
|||
<if test="appName != null and appName != ''">app_name,</if>
|
||||
<if test="channelName != null and channelName != ''">channel_name,</if>
|
||||
<if test="areaId != null">area_id,</if>
|
||||
<if test="autoRefund != null">auto_refund,</if>
|
||||
<if test="adminRefund != null">admin_refund,</if>
|
||||
</trim>
|
||||
<trim prefix="values (" suffix=")" suffixOverrides=",">
|
||||
<if test="no != null and no != ''">#{no},</if>
|
||||
|
@ -117,6 +121,8 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
|||
<if test="appName != null and appName != ''">#{appName},</if>
|
||||
<if test="channelName != null and channelName != ''">#{channelName},</if>
|
||||
<if test="areaId != null">#{areaId},</if>
|
||||
<if test="autoRefund != null">#{autoRefund},</if>
|
||||
<if test="adminRefund != null">#{adminRefund},</if>
|
||||
</trim>
|
||||
</insert>
|
||||
|
||||
|
@ -160,6 +166,8 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
|||
<if test="data.appName != null and data.appName != ''">app_name = #{data.appName},</if>
|
||||
<if test="data.channelName != null and data.channelName != ''">channel_name = #{data.channelName},</if>
|
||||
<if test="data.areaId != null">area_id = #{data.areaId},</if>
|
||||
<if test="data.autoRefund != null">auto_refund = #{data.autoRefund},</if>
|
||||
<if test="data.adminRefund != null">admin_refund = #{data.adminRefund},</if>
|
||||
</sql>
|
||||
|
||||
<delete id="deletePayById" parameterType="Long">
|
||||
|
@ -176,7 +184,15 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
|||
<!-- addRefundingAmount -->
|
||||
<insert id="addRefundingAmount">
|
||||
update bst_pay
|
||||
set refunding = refunding + #{amount}
|
||||
<trim prefix="SET" suffixOverrides=",">
|
||||
refunding = refunding + #{amount},
|
||||
<if test="type != null and type == '1'">
|
||||
auto_refund = auto_refund + #{amount},
|
||||
</if>
|
||||
<if test="type != null and type == '2'">
|
||||
admin_refund = admin_refund + #{amount},
|
||||
</if>
|
||||
</trim>
|
||||
where id = #{id} and amount >= refunded + refunding + #{amount}
|
||||
</insert>
|
||||
|
||||
|
|
|
@ -489,7 +489,7 @@ public class PayServiceImpl implements PayService {
|
|||
}
|
||||
|
||||
// 增加退款中金额
|
||||
int addRefunding = payMapper.addRefundingAmount(dto.getId(), dto.getRefundAmount());
|
||||
int addRefunding = payMapper.addRefundingAmount(dto.getId(), dto.getRefundAmount(), dto.getType());
|
||||
ServiceUtil.assertion(addRefunding != 1, "记录退款中的金额失败");
|
||||
|
||||
// 创建退款订单
|
||||
|
|
|
@ -49,4 +49,7 @@ public class Refund extends BaseEntity
|
|||
@ApiModelProperty("退款操作人名称")
|
||||
private String userName;
|
||||
|
||||
@Excel(name = "退款方式", readConverterExp = "1=自动退款,2=管理员退款")
|
||||
@ApiModelProperty("退款方式(1-自动退款 2-管理员退款)")
|
||||
private String type;
|
||||
}
|
||||
|
|
|
@ -0,0 +1,15 @@
|
|||
package com.ruoyi.bst.refund.domain.enums;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Getter;
|
||||
|
||||
@Getter
|
||||
@AllArgsConstructor
|
||||
public enum RefundType {
|
||||
AUTO("1", "自动退款"),
|
||||
ADMIN("2", "管理员退款");
|
||||
|
||||
private final String code;
|
||||
private final String name;
|
||||
|
||||
}
|
|
@ -17,6 +17,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
|||
br.reason,
|
||||
br.user_id,
|
||||
br.user_name,
|
||||
br.type,
|
||||
bp.channel_id,
|
||||
bp.app_id,
|
||||
bp.no as pay_no,
|
||||
|
@ -45,6 +46,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
|||
<if test="query.payBstType != null and query.payBstType != ''"> and bp.bst_type = #{query.payBstType}</if>
|
||||
<if test="query.payAreaId != null "> and bp.area_id = #{query.payAreaId}</if>
|
||||
<if test="query.channelId != null "> and bp.channel_id = #{query.channelId}</if>
|
||||
<if test="query.type != null and query.type != ''"> and br.type = #{query.type}</if>
|
||||
<if test="query.createDateRange != null and query.createDateRange.size() > 1">
|
||||
and date(br.create_time) >= #{query.createDateRange[0]}
|
||||
and date(br.create_time) <= #{query.createDateRange[1]}
|
||||
|
@ -82,6 +84,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
|||
<if test="reason != null">reason,</if>
|
||||
<if test="userId != null">user_id,</if>
|
||||
<if test="userName != null">user_name,</if>
|
||||
<if test="type != null and type != ''">type,</if>
|
||||
</trim>
|
||||
<trim prefix="values (" suffix=")" suffixOverrides=",">
|
||||
<if test="no != null and no != ''">#{no},</if>
|
||||
|
@ -92,6 +95,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
|||
<if test="reason != null">#{reason},</if>
|
||||
<if test="userId != null">#{userId},</if>
|
||||
<if test="userName != null">#{userName},</if>
|
||||
<if test="type != null and type != ''">#{type},</if>
|
||||
</trim>
|
||||
</insert>
|
||||
|
||||
|
@ -112,6 +116,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
|||
<if test="data.reason != null">reason = #{data.reason},</if>
|
||||
<if test="data.userId != null">user_id = #{data.userId},</if>
|
||||
<if test="data.userName != null">user_name = #{data.userName},</if>
|
||||
<if test="data.type != null and data.type != ''">type = #{data.type},</if>
|
||||
</sql>
|
||||
|
||||
<delete id="deleteRefundById" parameterType="Long">
|
||||
|
|
|
@ -17,7 +17,6 @@ import org.springframework.web.bind.annotation.RequestMapping;
|
|||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import com.aliyun.core.utils.StringUtils;
|
||||
import com.ruoyi.bst.areaJoin.domain.enums.AreaJoinPermission;
|
||||
import com.ruoyi.bst.order.domain.OrderQuery;
|
||||
import com.ruoyi.bst.order.domain.OrderVO;
|
||||
|
@ -29,6 +28,7 @@ import com.ruoyi.bst.order.domain.vo.OrderEndVO;
|
|||
import com.ruoyi.bst.order.service.OrderAssembler;
|
||||
import com.ruoyi.bst.order.service.OrderService;
|
||||
import com.ruoyi.bst.order.service.OrderValidator;
|
||||
import com.ruoyi.bst.refund.domain.enums.RefundType;
|
||||
import com.ruoyi.common.annotation.Log;
|
||||
import com.ruoyi.common.core.controller.BaseController;
|
||||
import com.ruoyi.common.core.domain.AjaxResult;
|
||||
|
@ -131,12 +131,9 @@ public class OrderController extends BaseController
|
|||
if (!orderValidator.canOperate(dto.getOrderId())) {
|
||||
return error("您无权退款ID为" + dto.getOrderId() + "的订单");
|
||||
}
|
||||
String userName = getNickName();
|
||||
dto.setUserId(getUserId());
|
||||
dto.setUserName(userName);
|
||||
if (StringUtils.isBlank(dto.getReason())) {
|
||||
dto.setReason("管理员【" + userName + "】退款");
|
||||
}
|
||||
dto.setUserName(getNickName());
|
||||
dto.setType(RefundType.ADMIN.getCode());
|
||||
return toAjax(orderService.refund(dto));
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user