退款优化
This commit is contained in:
parent
4f35209093
commit
18ca36f200
|
@ -249,4 +249,20 @@ public class Order extends BaseEntity {
|
|||
@Excel(name = "是否改过价")
|
||||
@ApiModelProperty("是否改过价")
|
||||
private Boolean priceChanged;
|
||||
|
||||
@Excel(name = "骑行费退款")
|
||||
@ApiModelProperty("骑行费退款")
|
||||
private BigDecimal ridingRefund;
|
||||
|
||||
@Excel(name = "调度费退款")
|
||||
@ApiModelProperty("调度费退款")
|
||||
private BigDecimal dispatchRefund;
|
||||
|
||||
@Excel(name = "管理费退款")
|
||||
@ApiModelProperty("管理费退款")
|
||||
private BigDecimal manageRefund;
|
||||
|
||||
@Excel(name = "车损费退款")
|
||||
@ApiModelProperty("车损费退款")
|
||||
private BigDecimal deductionRefund;
|
||||
}
|
||||
|
|
|
@ -4,7 +4,6 @@ import java.math.BigDecimal;
|
|||
import java.time.LocalDateTime;
|
||||
import java.util.List;
|
||||
|
||||
import com.ruoyi.bst.order.constants.OrderConstants;
|
||||
import com.ruoyi.bst.order.utils.OrderUtil;
|
||||
import com.ruoyi.bst.orderDevice.domain.OrderDeviceVO;
|
||||
import com.ruoyi.common.utils.MathUtils;
|
||||
|
@ -101,16 +100,26 @@ public class OrderVO extends Order implements IotDevice {
|
|||
return this.currentLat;
|
||||
}
|
||||
|
||||
// 允许押金退款金额
|
||||
public BigDecimal getCanDepositRefundAmount() {
|
||||
return OrderUtil.calcCanAdminRefundAmount(this, OrderConstants.REFUND_TYPE_DEPOSIT);
|
||||
// 实收骑行费(含退款)
|
||||
public BigDecimal getActualReceivedRidingFee() {
|
||||
return MathUtils.subtractDecimal(this.getActualRidingFee(), this.getRidingRefund());
|
||||
}
|
||||
|
||||
// 允许骑行费退款金额
|
||||
public BigDecimal getCanRideRefundAmount() {
|
||||
return OrderUtil.calcCanAdminRefundAmount(this, OrderConstants.REFUND_TYPE_RIDE);
|
||||
// 实收调度费(含退款)
|
||||
public BigDecimal getActualReceivedDispatchFee() {
|
||||
return MathUtils.subtractDecimal(this.getActualDispatchFee(), this.getDispatchRefund());
|
||||
}
|
||||
|
||||
// 实收管理费(含退款)
|
||||
public BigDecimal getActualReceivedManageFee() {
|
||||
return MathUtils.subtractDecimal(this.getActualManageFee(), this.getManageRefund());
|
||||
}
|
||||
|
||||
// 实收车损费(含退款)
|
||||
public BigDecimal getActualReceivedDeductionFee() {
|
||||
return MathUtils.subtractDecimal(this.getActualDeductionFee(), this.getDeductionRefund());
|
||||
}
|
||||
|
||||
// 允许自动退款金额
|
||||
public BigDecimal getCanAutoRefundAmount() {
|
||||
return OrderUtil.calcCanAutoRefundAmount(this);
|
||||
|
|
|
@ -41,6 +41,9 @@ public class OrderCreateBO {
|
|||
// 下单用户
|
||||
private UserVO user;
|
||||
|
||||
// 未支付的订单数量
|
||||
private Integer unpaidCount;
|
||||
|
||||
// 用户进行中的订单设备
|
||||
private OrderDeviceVO userOrderDevice;
|
||||
|
||||
|
|
|
@ -3,7 +3,6 @@ package com.ruoyi.bst.order.domain.dto;
|
|||
import java.math.BigDecimal;
|
||||
|
||||
import javax.validation.constraints.Min;
|
||||
import javax.validation.constraints.NotBlank;
|
||||
import javax.validation.constraints.NotNull;
|
||||
import javax.validation.constraints.Size;
|
||||
|
||||
|
@ -19,10 +18,21 @@ public class OrderRefundDTO implements LogBizParam {
|
|||
@NotNull(message = "订单ID不允许为空")
|
||||
private Long orderId;
|
||||
|
||||
@ApiModelProperty("退款金额")
|
||||
@NotNull(message = "退款金额不允许为空")
|
||||
@Min(value = 0, message = "退款金额不允许小于0")
|
||||
private BigDecimal amount;
|
||||
@ApiModelProperty("骑行费退款")
|
||||
@Min(value = 0, message = "骑行费退款不允许小于0")
|
||||
private BigDecimal ridingRefund;
|
||||
|
||||
@ApiModelProperty("调度费退款")
|
||||
@Min(value = 0, message = "调度费退款不允许小于0")
|
||||
private BigDecimal dispatchRefund;
|
||||
|
||||
@ApiModelProperty("管理费退款")
|
||||
@Min(value = 0, message = "管理费退款不允许小于0")
|
||||
private BigDecimal manageRefund;
|
||||
|
||||
@ApiModelProperty("车损费退款")
|
||||
@Min(value = 0, message = "车损费退款不允许小于0")
|
||||
private BigDecimal deductionRefund;
|
||||
|
||||
@ApiModelProperty("退款原因")
|
||||
@Size(max = 200, message = "退款原因不允许超过200个字符")
|
||||
|
@ -34,10 +44,6 @@ public class OrderRefundDTO implements LogBizParam {
|
|||
@ApiModelProperty("操作人名称")
|
||||
private String userName;
|
||||
|
||||
@ApiModelProperty("退款类型:1-押金退款,2-骑行费退款")
|
||||
@NotBlank(message = "退款类型不允许为空")
|
||||
private String refundType;
|
||||
|
||||
@Override
|
||||
public Object logBizId() {
|
||||
return orderId;
|
||||
|
|
|
@ -0,0 +1,27 @@
|
|||
package com.ruoyi.bst.order.domain.dto;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
|
||||
import com.ruoyi.common.utils.MathUtils;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
public class OrderRefundDetailDTO {
|
||||
|
||||
// 骑行费
|
||||
private BigDecimal ridingRefund;
|
||||
|
||||
// 调度费
|
||||
private BigDecimal dispatchRefund;
|
||||
|
||||
// 管理费
|
||||
private BigDecimal manageRefund;
|
||||
|
||||
// 车损费
|
||||
private BigDecimal deductionRefund;
|
||||
|
||||
public BigDecimal getTotalRefund() {
|
||||
return MathUtils.addDecimal(ridingRefund, dispatchRefund, manageRefund, deductionRefund);
|
||||
}
|
||||
}
|
|
@ -209,4 +209,12 @@ public interface OrderMapper {
|
|||
*/
|
||||
int deductDeposit(@Param("id") Long id, @Param("amount") BigDecimal amount);
|
||||
|
||||
/**
|
||||
* 更新退款信息
|
||||
* @param data
|
||||
* @param query
|
||||
* @return
|
||||
*/
|
||||
int updateRefund(@Param("data") Order data, @Param("query") OrderQuery query);
|
||||
|
||||
}
|
||||
|
|
|
@ -67,6 +67,10 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
|||
bo.admin_refund_amount,
|
||||
bo.ride_pay_time,
|
||||
bo.price_changed,
|
||||
bo.riding_refund,
|
||||
bo.dispatch_refund,
|
||||
bo.manage_refund,
|
||||
bo.deduction_refund,
|
||||
<include refid="depositCanDeductRemain"/> as deposit_deduct_remain,
|
||||
ba.name as area_name,
|
||||
su.nick_name as user_name,
|
||||
|
@ -283,6 +287,10 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
|||
<if test="adminRefundAmount != null">admin_refund_amount,</if>
|
||||
<if test="ridePayTime != null">ride_pay_time,</if>
|
||||
<if test="priceChanged != null">price_changed,</if>
|
||||
<if test="ridingRefund != null">riding_refund,</if>
|
||||
<if test="dispatchRefund != null">dispatch_refund,</if>
|
||||
<if test="manageRefund != null">manage_refund,</if>
|
||||
<if test="deductionRefund != null">deduction_refund,</if>
|
||||
</trim>
|
||||
<trim prefix="values (" suffix=")" suffixOverrides=",">
|
||||
<if test="no != null and no != ''">#{no},</if>
|
||||
|
@ -340,6 +348,10 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
|||
<if test="adminRefundAmount != null">#{adminRefundAmount},</if>
|
||||
<if test="ridePayTime != null">#{ridePayTime},</if>
|
||||
<if test="priceChanged != null">#{priceChanged},</if>
|
||||
<if test="ridingRefund != null">#{ridingRefund},</if>
|
||||
<if test="dispatchRefund != null">#{dispatchRefund},</if>
|
||||
<if test="manageRefund != null">#{manageRefund},</if>
|
||||
<if test="deductionRefund != null">#{deductionRefund},</if>
|
||||
</trim>
|
||||
</insert>
|
||||
|
||||
|
@ -407,6 +419,10 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
|||
<if test="data.adminRefundAmount != null">admin_refund_amount = #{data.adminRefundAmount},</if>
|
||||
<if test="data.ridePayTime != null">ride_pay_time = #{data.ridePayTime},</if>
|
||||
<if test="data.priceChanged != null">price_changed = #{data.priceChanged},</if>
|
||||
<if test="data.ridingRefund != null">riding_refund = #{data.ridingRefund},</if>
|
||||
<if test="data.dispatchRefund != null">dispatch_refund = #{data.dispatchRefund},</if>
|
||||
<if test="data.manageRefund != null">manage_refund = #{data.manageRefund},</if>
|
||||
<if test="data.deductionRefund != null">deduction_refund = #{data.deductionRefund},</if>
|
||||
</sql>
|
||||
|
||||
<delete id="deleteOrderById" parameterType="Long">
|
||||
|
@ -626,4 +642,43 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
|||
and <include refid="depositCanDeductRemain"/> >= #{deductionFee}
|
||||
</update>
|
||||
|
||||
<!-- updateRefund -->
|
||||
|
||||
<update id="updateRefund">
|
||||
update bst_order bo
|
||||
<trim prefix="SET" suffixOverrides=",">
|
||||
admin_refund_count = admin_refund_count + 1,
|
||||
admin_refund_amount = admin_refund_amount + #{data.adminRefundAmount},
|
||||
<if test="data.ridingRefund != null">
|
||||
riding_refund = riding_refund + #{data.ridingRefund},
|
||||
</if>
|
||||
<if test="data.dispatchRefund != null">
|
||||
dispatch_refund = dispatch_refund + #{data.dispatchRefund},
|
||||
</if>
|
||||
<if test="data.manageRefund != null">
|
||||
manage_refund = manage_refund + #{data.manageRefund},
|
||||
</if>
|
||||
<if test="data.deductionRefund != null">
|
||||
deduction_refund = deduction_refund + #{data.deductionRefund},
|
||||
</if>
|
||||
</trim>
|
||||
<where>
|
||||
<if test="data.ridingRefund != null">
|
||||
and actual_riding_fee >= (riding_refund + #{data.ridingRefund})
|
||||
</if>
|
||||
<if test="data.dispatchRefund != null">
|
||||
and actual_dispatch_fee >= (dispatch_refund + #{data.dispatchRefund})
|
||||
</if>
|
||||
<if test="data.manageRefund != null">
|
||||
and actual_manage_fee >= (manage_refund + #{data.manageRefund})
|
||||
</if>
|
||||
<if test="data.deductionRefund != null">
|
||||
and actual_deduction_fee >= (deduction_refund + #{data.deductionRefund})
|
||||
</if>
|
||||
<include refid="searchCondition"/>
|
||||
</where>
|
||||
|
||||
</update>
|
||||
|
||||
|
||||
</mapper>
|
||||
|
|
|
@ -114,5 +114,11 @@ public interface OrderDashboard {
|
|||
*/
|
||||
BigDecimal selectSumOfActualManageFee(OrderQuery query);
|
||||
|
||||
/**
|
||||
* 根据用户ID查询未支付订单数量
|
||||
* @param userId
|
||||
*/
|
||||
int selectUnpaidCountByUserId(Long userId);
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -45,6 +45,7 @@ import com.ruoyi.bst.order.domain.enums.OrderStatus;
|
|||
import com.ruoyi.bst.order.domain.vo.OrderInParkingVO;
|
||||
import com.ruoyi.bst.order.domain.vo.OrderPrePriceVO;
|
||||
import com.ruoyi.bst.order.service.OrderConverter;
|
||||
import com.ruoyi.bst.order.service.OrderDashboard;
|
||||
import com.ruoyi.bst.order.service.OrderService;
|
||||
import com.ruoyi.bst.order.service.OrderValidator;
|
||||
import com.ruoyi.bst.order.utils.OrderUtil;
|
||||
|
@ -118,6 +119,9 @@ public class OrderConverterImpl implements OrderConverter{
|
|||
@Autowired
|
||||
private DeviceAssembler deviceAssembler;
|
||||
|
||||
@Autowired
|
||||
private OrderDashboard orderDashboard;
|
||||
|
||||
@Override
|
||||
public OrderPrePriceVO toOrderPrePriceVO(OrderCalcPrePriceDTO dto) {
|
||||
if (dto == null) {
|
||||
|
@ -168,6 +172,11 @@ public class OrderConverterImpl implements OrderConverter{
|
|||
UserVO user = userService.selectUserById(dto.getUserId());
|
||||
bo.setUser(user);
|
||||
|
||||
// 未支付骑行费的订单
|
||||
if (user != null) {
|
||||
bo.setUnpaidCount(orderDashboard.selectUnpaidCountByUserId(user.getUserId()));
|
||||
}
|
||||
|
||||
// 用户进行中的订单设备
|
||||
OrderDeviceVO userOrderDevice = orderDeviceService.selectUsingByUserId(dto.getUserId());
|
||||
bo.setUserOrderDevice(userOrderDevice);
|
||||
|
|
|
@ -138,4 +138,15 @@ public class OrderDashboardImpl implements OrderDashboard {
|
|||
public BigDecimal selectSumOfActualManageFee(OrderQuery query) {
|
||||
return MathUtils.dv(orderMapper.selectSumOfActualManageFee(query));
|
||||
}
|
||||
|
||||
@Override
|
||||
public int selectUnpaidCountByUserId(Long userId) {
|
||||
if (userId == null) {
|
||||
return 0;
|
||||
}
|
||||
OrderQuery query = new OrderQuery();
|
||||
query.setUserId(userId);
|
||||
query.setStatus(OrderStatus.RIDE_WAIT_PAY.getCode());
|
||||
return this.selectCount(query);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -57,6 +57,7 @@ import com.ruoyi.bst.order.domain.dto.OrderEndDTO;
|
|||
import com.ruoyi.bst.order.domain.dto.OrderOpenDeviceDTO;
|
||||
import com.ruoyi.bst.order.domain.dto.OrderPayRideFeeDTO;
|
||||
import com.ruoyi.bst.order.domain.dto.OrderRefundDTO;
|
||||
import com.ruoyi.bst.order.domain.dto.OrderRefundDetailDTO;
|
||||
import com.ruoyi.bst.order.domain.dto.OrderSeatDTO;
|
||||
import com.ruoyi.bst.order.domain.dto.OrderUpdatePriceDTO;
|
||||
import com.ruoyi.bst.order.domain.dto.OrderVerifyDTO;
|
||||
|
@ -497,7 +498,7 @@ public class OrderServiceImpl implements OrderService {
|
|||
ServiceUtil.assertion(deduct != 1, "ID为%s的订单自动押金抵扣失败", order.getId());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 设置日志参数
|
||||
* @param device 设备信息
|
||||
|
@ -697,11 +698,9 @@ public class OrderServiceImpl implements OrderService {
|
|||
@Override
|
||||
public int refund(OrderRefundDTO dto) {
|
||||
OrderVO order = this.selectOrderById(dto.getOrderId());
|
||||
BigDecimal amount = dto.getAmount();
|
||||
|
||||
ServiceUtil.assertion(order == null, "参数错误,订单不存在");
|
||||
ServiceUtil.assertion(!OrderStatus.canRefund().contains(order.getStatus()), "ID为%s的订单当前状态不允许退款", order.getId());
|
||||
ServiceUtil.assertion(amount == null || amount.compareTo(BigDecimal.ZERO) <= 0, "参数错误,退款金额不允许为空且必须大于0");
|
||||
|
||||
// 退款加锁,短时间内不允许多次退款
|
||||
Long lockKey = order.getId();
|
||||
|
@ -709,52 +708,88 @@ public class OrderServiceImpl implements OrderService {
|
|||
ServiceUtil.assertion(!lock, "订单%s退款过于频繁,请稍后重试", order.getNo());
|
||||
|
||||
try {
|
||||
BigDecimal canRefundAmount = OrderUtil.calcCanAdminRefundAmount(order, dto.getRefundType());
|
||||
ServiceUtil.assertion(canRefundAmount.compareTo(amount) < 0, "ID为%s的订单可退款金额不足,当前可退款金额为%s元", order.getId(),
|
||||
canRefundAmount);
|
||||
String type = RefundType.ADMIN.getCode();
|
||||
// 校验退款金额
|
||||
ServiceUtil.assertion(MathUtils.biggerThan(dto.getRidingRefund(), order.getActualReceivedRidingFee()), "骑行费可退款金额不足,当前可退款金额为%s元", order.getActualReceivedRidingFee());
|
||||
ServiceUtil.assertion(MathUtils.biggerThan(dto.getDispatchRefund(), order.getActualReceivedDispatchFee()), "调度费可退款金额不足,当前可退款金额为%s元", order.getActualReceivedDispatchFee());
|
||||
ServiceUtil.assertion(MathUtils.biggerThan(dto.getManageRefund(), order.getActualReceivedManageFee()), "管理费可退款金额不足,当前可退款金额为%s元", order.getActualReceivedManageFee());
|
||||
ServiceUtil.assertion(MathUtils.biggerThan(dto.getDeductionRefund(), order.getActualReceivedDeductionFee()), "车损费可退款金额不足,当前可退款金额为%s元", order.getActualReceivedDeductionFee());
|
||||
|
||||
// 总退款金额不允许为0
|
||||
BigDecimal totalRefund = MathUtils.addDecimal(dto.getRidingRefund(), dto.getDispatchRefund(), dto.getManageRefund(), dto.getDeductionRefund());
|
||||
ServiceUtil.assertion(totalRefund.compareTo(BigDecimal.ZERO) <= 0, "退款总额不允许小于或等于0");
|
||||
|
||||
// 退款原因
|
||||
String refundReason = this.getRefundReason(dto.getReason(), type, dto.getUserName(), order.getNo(), amount);
|
||||
int rows = 0;
|
||||
try {
|
||||
// 执行退款(押金)
|
||||
rows = this.doRefund(order, dto, OrderConstants.REFUND_TYPE_DEPOSIT);
|
||||
|
||||
Integer result = transactionTemplate.execute(status -> {
|
||||
// 更新订单退款信息
|
||||
Order data = new Order();
|
||||
data.setAdminRefundCount(order.getAdminRefundCount() + 1);
|
||||
data.setAdminRefundAmount(MathUtils.addDecimal(order.getAdminRefundAmount(), amount));
|
||||
OrderQuery query = new OrderQuery();
|
||||
query.setId(order.getId());
|
||||
query.setAdminRefundCount(order.getAdminRefundCount());
|
||||
query.setPayType(order.getPayType());
|
||||
query.setAdminRefundAmount(order.getAdminRefundAmount());
|
||||
int rows = orderMapper.updateByQuery(data, query);
|
||||
ServiceUtil.assertion(rows != 1, "ID为%s订单当前状态已发生变化,请稍后重试", order.getId());
|
||||
// 执行退款(支付)
|
||||
rows += this.doRefund(order, dto, OrderConstants.REFUND_TYPE_RIDE);
|
||||
} catch (Exception e) {
|
||||
log.error("退款失败: {}, {}", order.getId(), e.getMessage());
|
||||
}
|
||||
|
||||
// 分成退款
|
||||
boolean bonusRefund = bonusService.refundByBst(BonusBstType.ORDER, order.getId(), amount, refundReason);
|
||||
ServiceUtil.assertion(!bonusRefund, "ID为%s的订单分成退款失败,请联系管理员处理", order.getId());
|
||||
|
||||
// 支付退款
|
||||
PayRefundDTO refundDto = new PayRefundDTO();
|
||||
if (OrderConstants.REFUND_TYPE_DEPOSIT.equals(dto.getRefundType())) {
|
||||
refundDto.setId(order.getPayId());
|
||||
} else if (OrderConstants.REFUND_TYPE_RIDE.equals(dto.getRefundType())) {
|
||||
refundDto.setId(order.getRidePayId());
|
||||
}
|
||||
refundDto.setRefundAmount(amount);
|
||||
refundDto.setRefundReason(refundReason);
|
||||
refundDto.setUserId(dto.getUserId());
|
||||
refundDto.setUserName(dto.getUserName());
|
||||
refundDto.setType(type);
|
||||
return payService.refund(refundDto);
|
||||
});
|
||||
|
||||
return result == null ? 0 : 1;
|
||||
return rows;
|
||||
} finally {
|
||||
redisLock.unlock(RedisLockKey.ORDER_ADMIN_REFUND, lockKey);
|
||||
}
|
||||
}
|
||||
|
||||
private int doRefund(OrderVO order, OrderRefundDTO dto, String refundType) {
|
||||
|
||||
// 计算需要退款的金额
|
||||
OrderRefundDetailDTO detail = OrderUtil.calcRefundDetail(order, dto, refundType);
|
||||
BigDecimal refundAmount = detail.getTotalRefund();
|
||||
|
||||
// 若需要退款的金额为0,则不进行退款
|
||||
if (refundAmount == null || BigDecimal.ZERO.compareTo(refundAmount) == 0) {
|
||||
return 1;
|
||||
}
|
||||
// 若退款金额小于0,则不进行退款,并返回0
|
||||
if (BigDecimal.ZERO.compareTo(refundAmount) > 0) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
// 退款原因
|
||||
String type = RefundType.ADMIN.getCode();
|
||||
String refundReason = this.getRefundReason(dto.getReason(), type, dto.getUserName(), order.getNo(), refundAmount);
|
||||
|
||||
Integer result = transactionTemplate.execute(status -> {
|
||||
// 更新订单退款信息
|
||||
Order data = new Order();
|
||||
data.setAdminRefundAmount(refundAmount);
|
||||
data.setRidingRefund(detail.getRidingRefund());
|
||||
data.setDispatchRefund(detail.getDispatchRefund());
|
||||
data.setManageRefund(detail.getManageRefund());
|
||||
data.setDeductionRefund(detail.getDeductionRefund());
|
||||
OrderQuery query = new OrderQuery();
|
||||
query.setId(order.getId());
|
||||
query.setPayType(order.getPayType());
|
||||
int rows = orderMapper.updateRefund(data, query);
|
||||
ServiceUtil.assertion(rows != 1, "ID为%s订单当前状态已发生变化,请稍后重试", order.getId());
|
||||
|
||||
// 分成退款
|
||||
boolean bonusRefund = bonusService.refundByBst(BonusBstType.ORDER, order.getId(), refundAmount, refundReason);
|
||||
ServiceUtil.assertion(!bonusRefund, "ID为%s的订单分成退款失败,请联系管理员处理", order.getId());
|
||||
|
||||
// 支付退款
|
||||
PayRefundDTO refundDto = new PayRefundDTO();
|
||||
if (OrderConstants.REFUND_TYPE_DEPOSIT.equals(refundType)) {
|
||||
refundDto.setId(order.getPayId());
|
||||
} else if (OrderConstants.REFUND_TYPE_RIDE.equals(refundType)) {
|
||||
refundDto.setId(order.getRidePayId());
|
||||
}
|
||||
refundDto.setRefundAmount(refundAmount);
|
||||
refundDto.setRefundReason(refundReason);
|
||||
refundDto.setUserId(dto.getUserId());
|
||||
refundDto.setUserName(dto.getUserName());
|
||||
refundDto.setType(type);
|
||||
return payService.refund(refundDto);
|
||||
});
|
||||
|
||||
return result == null ? 0 : result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public DeviceIotVO openDevice(OrderOpenDeviceDTO dto) {
|
||||
ServiceUtil.assertion(dto == null, "参数错误,dto不允许为空");
|
||||
|
@ -991,21 +1026,21 @@ public class OrderServiceImpl implements OrderService {
|
|||
ServiceUtil.assertion(!lock, "ID为%s的订单正在支付中,请稍后重试", order.getId());
|
||||
try {
|
||||
ServiceUtil.assertion(!OrderStatus.canDeduct().contains(order.getStatus()), "ID为%s的订单当前状态不允许抵扣", order.getId());
|
||||
|
||||
|
||||
// 获取实际抵扣金额
|
||||
BigDecimal max = OrderUtil.calcRemainCanDeductDeposit(order);
|
||||
BigDecimal deductAmount = MathUtils.min(MathUtils.dv(order.getTotalFee()), max);
|
||||
|
||||
|
||||
// 关闭订单的支付ID
|
||||
boolean closePay = payService.closeByBstId(PayBstType.ORDER_RIDE.getType(), order.getId());
|
||||
ServiceUtil.assertion(!closePay, "ID为%s的订单骑行费支付关闭失败", order.getId());
|
||||
|
||||
|
||||
// 更新订单数据
|
||||
Integer result = transactionTemplate.execute(status -> {
|
||||
// 押金抵扣
|
||||
int deduct = orderMapper.deductDeposit(order.getId(), deductAmount);
|
||||
ServiceUtil.assertion(deduct != 1, "ID为%s的订单押金抵扣失败,剩余可抵扣押金不足%s元", order.getId(), deductAmount);
|
||||
|
||||
|
||||
// 处理抵扣成功
|
||||
OrderRidePaySuccessBO bo = new OrderRidePaySuccessBO();
|
||||
bo.setOrder(order);
|
||||
|
@ -1016,7 +1051,7 @@ public class OrderServiceImpl implements OrderService {
|
|||
bo.setPayTime(LocalDateTime.now());
|
||||
return this.handleRidePaySuccess(bo);
|
||||
});
|
||||
|
||||
|
||||
return result == null ? 0 : result;
|
||||
} finally {
|
||||
redisLock.unlock(RedisLockKey.ORDER_PAY_RIDE_FEE, lockKey);
|
||||
|
@ -1096,7 +1131,7 @@ public class OrderServiceImpl implements OrderService {
|
|||
} finally {
|
||||
redisLock.unlock(RedisLockKey.ORDER_PAY_RIDE_FEE, lockKey);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -1115,7 +1150,7 @@ public class OrderServiceImpl implements OrderService {
|
|||
// 关闭支付订单
|
||||
boolean closePay = payService.closeByBstId(PayBstType.ORDER_RIDE.getType(), order.getId());
|
||||
ServiceUtil.assertion(!closePay, "ID为%s的订单骑行费支付关闭失败", dto.getId());
|
||||
|
||||
|
||||
Integer result = transactionTemplate.execute(status -> {
|
||||
// 修改订单数据
|
||||
Order data = new Order();
|
||||
|
|
|
@ -87,6 +87,9 @@ public class OrderValidatorImpl implements OrderValidator{
|
|||
boolean isReal = user.getIsReal() != null && user.getIsReal();
|
||||
ServiceUtil.assertion(needRealName && !isReal, "用户%s未实名认证", user.getNickName(), ServiceCode.USER_NOT_REAL_NAME);
|
||||
|
||||
// 用户未支付的订单数量
|
||||
ServiceUtil.assertion(bo.getUnpaidCount() != null && bo.getUnpaidCount() > 0, "您有未支付的骑行费,请支付后下单");
|
||||
|
||||
// 用户进行中的订单设备
|
||||
OrderDeviceVO userOrderDevice = bo.getUserOrderDevice();
|
||||
if (userOrderDevice != null) {
|
||||
|
|
|
@ -15,6 +15,9 @@ import com.ruoyi.bst.device.domain.enums.DeviceStatus;
|
|||
import com.ruoyi.bst.order.constants.OrderConstants;
|
||||
import com.ruoyi.bst.order.domain.Order;
|
||||
import com.ruoyi.bst.order.domain.OrderVO;
|
||||
import com.ruoyi.bst.order.domain.dto.OrderRefundDTO;
|
||||
import com.ruoyi.bst.order.domain.dto.OrderRefundDetailDTO;
|
||||
import com.ruoyi.bst.order.domain.enums.OrderPayType;
|
||||
import com.ruoyi.bst.order.domain.vo.OrderFeeVO;
|
||||
import com.ruoyi.bst.order.domain.vo.OrderInParkingVO;
|
||||
import com.ruoyi.bst.order.domain.vo.OrderPrePriceVO;
|
||||
|
@ -246,4 +249,38 @@ public class OrderUtil {
|
|||
data.getDeductionFee()
|
||||
);
|
||||
}
|
||||
|
||||
public static OrderRefundDetailDTO calcRefundDetail(OrderVO order, OrderRefundDTO dto, String refundType) {
|
||||
OrderRefundDetailDTO result = new OrderRefundDetailDTO();
|
||||
BigDecimal deductionRefund = null;
|
||||
BigDecimal ridingRefund = null;
|
||||
BigDecimal dispatchRefund = null;
|
||||
BigDecimal manageRefund = null;
|
||||
// 押金退款
|
||||
if (OrderConstants.REFUND_TYPE_DEPOSIT.equals(refundType)) {
|
||||
deductionRefund = dto.getDeductionRefund();
|
||||
if (OrderPayType.DEPOSIT_DEDUCTION.getCode().equals(order.getPayType())) {
|
||||
ridingRefund = dto.getRidingRefund();
|
||||
dispatchRefund = dto.getDispatchRefund();
|
||||
manageRefund = dto.getManageRefund();
|
||||
}
|
||||
}
|
||||
// 支付退款
|
||||
else if (OrderConstants.REFUND_TYPE_RIDE.equals(refundType)) {
|
||||
ridingRefund = dto.getRidingRefund();
|
||||
dispatchRefund = dto.getDispatchRefund();
|
||||
manageRefund = dto.getManageRefund();
|
||||
if (OrderPayType.DEPOSIT_DEDUCTION.getCode().equals(order.getPayType())) {
|
||||
ridingRefund = BigDecimal.ZERO;
|
||||
dispatchRefund = BigDecimal.ZERO;
|
||||
manageRefund = BigDecimal.ZERO;
|
||||
}
|
||||
}
|
||||
|
||||
result.setRidingRefund(MathUtils.dv(ridingRefund));
|
||||
result.setDispatchRefund(MathUtils.dv(dispatchRefund));
|
||||
result.setManageRefund(MathUtils.dv(manageRefund));
|
||||
result.setDeductionRefund(MathUtils.dv(deductionRefund));
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -135,7 +135,11 @@ public class OrderController extends BaseController
|
|||
}
|
||||
dto.setUserId(getUserId());
|
||||
dto.setUserName(getNickName());
|
||||
return toAjax(orderService.refund(dto));
|
||||
int count = orderService.refund(dto);
|
||||
if (count == 0) {
|
||||
return error("退款失败");
|
||||
}
|
||||
return success(count);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -161,7 +165,7 @@ public class OrderController extends BaseController
|
|||
if (!orderValidator.canOperate(dto.getId())) {
|
||||
return error("您无权押金抵扣ID为" + dto.getId() + "的订单");
|
||||
}
|
||||
dto.setIgnoreVerify(true);
|
||||
dto.setIgnoreVerify(false);
|
||||
return toAjax(orderService.deduct(dto));
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user