订单完善以及退款相关

This commit is contained in:
SjS 2025-05-06 19:50:21 +08:00
parent 36327b09ee
commit ee42441178
4 changed files with 50 additions and 22 deletions

View File

@ -11,10 +11,19 @@ public class OrderVO extends Order{
// 支付
@ApiModelProperty("支付单号")
private String payNo;
@ApiModelProperty("已支付金额")
private BigDecimal payedAmount;
@ApiModelProperty("支付已退款金额")
private BigDecimal payRefunded;
@ApiModelProperty("支付退款中金额")
private BigDecimal payRefunding;
// 用户
@ApiModelProperty("用户名称")
private String userName;
@ApiModelProperty("用户手机号")
private String userPhone;
}

View File

@ -22,7 +22,7 @@ public class OrderRefundDTO implements LogBizParam {
private BigDecimal amount;
@ApiModelProperty("退款次数")
@NotNull(message = "退款次数")
@NotNull(message = "退款次数不能为空")
@Min(value = 0, message = "退款次数不允许小于0")
private Integer number;

View File

@ -20,6 +20,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<result property="suitAmount" column="suit_amount" />
<result property="cancelRemark" column="cancel_remark" />
<result property="payExpireTime" column="pay_expire_time" />
<result property="refundNum" column="refund_num" />
</resultMap>
<sql id="selectOrderVo">
@ -33,14 +34,19 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
bo.pay_amount,
bo.mark,
bo.status,
bo.refund_num,
bo.create_time,
bo.suit_id,
bo.suit_num,
bo.suit_amount,
bo.cancel_remark,
bo.pay_expire_time,
bp.refunded,
bp.refunding
bp.refunded as pay_refunded,
bp.refunding as pay_refunding,
bp.no as pay_no,
bp.amount as payed_amount,
su.nick_name as user_name,
su.user_name as user_phone
from <include refid="searchTables"></include>
</sql>
@ -52,20 +58,21 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
</sql>
<sql id="searchCondition">
<if test="query.orderNo != null and query.orderNo != ''"> and order_no = #{query.orderNo}</if>
<if test="query.id != null and query.id != ''"> and id = #{query.id}</if>
<if test="query.storeId != null "> and store_id = #{query.storeId}</if>
<if test="query.storeName != null and query.storeName != ''"> and store_name like concat('%', #{query.storeName}, '%')</if>
<if test="query.userId != null "> and user_id = #{query.userId}</if>
<if test="query.payId != null "> and pay_id = #{query.payId}</if>
<if test="query.payAmount != null "> and pay_amount = #{query.payAmount}</if>
<if test="query.mark != null and query.mark != ''"> and mark = #{query.mark}</if>
<if test="query.status != null and query.status != ''"> and status = #{query.status}</if>
<if test="query.suitId != null "> and suit_id = #{query.suitId}</if>
<if test="query.suitNum != null "> and suit_num = #{query.suitNum}</if>
<if test="query.suitAmount != null "> and suit_amount = #{query.suitAmount}</if>
<if test="query.cancelRemark != null and query.cancelRemark != ''"> and cancel_remark = #{query.cancelRemark}</if>
<if test="query.payExpireTime != null "> and pay_expire_time = #{query.payExpireTime}</if> ${@com.ruoyi.framework.util.DataScopeUtil@create(query.scope)
<if test="query.orderNo != null and query.orderNo != ''"> and bo.order_no = #{query.orderNo}</if>
<if test="query.id != null and query.id != ''"> and bo.id = #{query.id}</if>
<if test="query.storeId != null "> and bo.store_id = #{query.storeId}</if>
<if test="query.storeName != null and query.storeName != ''"> and bo.store_name like concat('%', #{query.storeName}, '%')</if>
<if test="query.userId != null "> and bo.user_id = #{query.userId}</if>
<if test="query.payId != null "> and bo.pay_id = #{query.payId}</if>
<if test="query.payNo != null and query.payNo != ''"> and bp.no like concat('%', #{query.payNo}, '%')</if>
<if test="query.payAmount != null "> and bo.pay_amount = #{query.payAmount}</if>
<if test="query.mark != null and query.mark != ''"> and bo.mark = #{query.mark}</if>
<if test="query.status != null and query.status != ''"> and bo.status = #{query.status}</if>
<if test="query.suitId != null "> and bo.suit_id = #{query.suitId}</if>
<if test="query.suitNum != null "> and bo.suit_num = #{query.suitNum}</if>
<if test="query.suitAmount != null "> and bo.suit_amount = #{query.suitAmount}</if>
<if test="query.cancelRemark != null and query.cancelRemark != ''"> and bo.cancel_remark = #{query.cancelRemark}</if>
<if test="query.payExpireTime != null "> and bo.pay_expire_time = #{query.payExpireTime}</if> ${@com.ruoyi.framework.util.DataScopeUtil@create(query.scope)
.userSetAlias("bs.user_id")
.build()
}
@ -99,6 +106,12 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
</where>
</select>
<!-- addRefundNum -->
<insert id="addRefundNum">
update bst_order
set refund_num = refund_num + #{number}
where pay_id = #{id} and suit_num >= refund_num + #{number}
</insert>
<insert id="insertOrder" parameterType="Order" useGeneratedKeys="true" keyProperty="id">
insert into bst_order

View File

@ -9,6 +9,7 @@ import java.util.concurrent.TimeUnit;
import com.github.pagehelper.PageHelper;
import com.ruoyi.bst.changeRecord.domain.ChangeRecord;
import com.ruoyi.bst.changeRecord.domain.enums.ChangeRecordBstType;
import com.ruoyi.bst.changeRecord.service.ChangeRecordService;
import com.ruoyi.bst.lightingNum.domain.LightingNum;
import com.ruoyi.bst.lightingNum.domain.LightingNumQuery;
@ -279,6 +280,11 @@ public class OrderServiceImpl implements OrderService
return this.refund(order, dto.getAmount(), dto.getNumber(),dto.getReason(), dto.getUserId(), dto.getUserName());
}
@Override
public int addRefundNum(Long id, Integer number) {
return orderMapper.addRefundNum(id,number);
}
/**
* 退款
@ -293,15 +299,15 @@ public class OrderServiceImpl implements OrderService
private int refund(OrderVO order, BigDecimal amount,Integer number, String reason, Long userId, String userName) {
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");
ServiceUtil.assertion(number == null || number <= 0, "参数错误,退款次数不允许为空且必须大于0");
ServiceUtil.assertion(amount == null || amount.compareTo(BigDecimal.ZERO) < 0, "参数错误,退款金额不允许为空且");
ServiceUtil.assertion(number == null || number < 0, "参数错误,退款次数不允许为空且不允许小于0");
BigDecimal canRefundAmount = OrderUtil.calcCanRefundAmount(order);
ServiceUtil.assertion(canRefundAmount.compareTo(amount) < 0, "ID为%s的订单可退款金额不足当前可退款金额为%s元", order.getId(), canRefundAmount);
// 退款原因
String refundReason = null;
refundReason = String.format("%s:订单%s退款%s元 %s次", userName, order.getOrderNo(), amount ,number);
refundReason = String.format("%s:订单%s退款", userName, order.getOrderNo());
if (StringUtils.isNotBlank(reason)) {
refundReason += "" + reason;
}
@ -322,7 +328,7 @@ public class OrderServiceImpl implements OrderService
lightingNumService.reduceLightingNumByQuery(data,query);
// 生成次数变化记录表
ChangeRecord changeRecord = new ChangeRecord();
changeRecord.setBstType(PayBstType.ORDER.getType());
changeRecord.setBstType(ChangeRecordBstType.REFUND.getCode());
changeRecord.setBstId(order.getId());
changeRecord.setUserId(order.getUserId());
changeRecord.setStoreId(order.getStoreId());