fix: 退款支持比例退款

This commit is contained in:
张松 2024-11-21 11:24:01 +08:00
parent 97e2b91364
commit 2d36aa4d9b
3 changed files with 19 additions and 14 deletions

View File

@ -47,7 +47,7 @@ public interface MpOrderDetailService extends IService<TbOrderDetail> {
/** /**
* 根据订单id和状态获取订单详情 * 根据订单id和状态获取订单详情
*/ */
List<TbOrderDetail> selectByOrderIdAndState(Integer orderId, TableConstant.OrderInfo.Status state); List<TbOrderDetail> selectByOrderIdAndState(Integer orderId, TableConstant.OrderInfo.Status... states);
/** /**
* 根据购物车id和订单id查询订单详情 * 根据购物车id和订单id查询订单详情

View File

@ -1,5 +1,6 @@
package cn.ysk.cashier.mybatis.service.impl; package cn.ysk.cashier.mybatis.service.impl;
import cn.hutool.core.collection.CollUtil;
import cn.ysk.cashier.cons.TableConstant; import cn.ysk.cashier.cons.TableConstant;
import cn.ysk.cashier.dto.shoptable.ReturnOrderDTO; import cn.ysk.cashier.dto.shoptable.ReturnOrderDTO;
import cn.ysk.cashier.enums.OrderStatusEnums; import cn.ysk.cashier.enums.OrderStatusEnums;
@ -50,10 +51,13 @@ public class MpOrderDetailServiceImpl extends ServiceImpl<TbOrderDetailMapper, T
} }
@Override @Override
public List<TbOrderDetail> selectByOrderIdAndState(Integer orderId, TableConstant.OrderInfo.Status state) { public List<TbOrderDetail> selectByOrderIdAndState(Integer orderId, TableConstant.OrderInfo.Status... statuses) {
return list(new LambdaQueryWrapper<TbOrderDetail>() LambdaQueryWrapper<TbOrderDetail> query = new LambdaQueryWrapper<TbOrderDetail>()
.eq(TbOrderDetail::getStatus, state.getValue()) .eq(TbOrderDetail::getOrderId, orderId);
.eq(TbOrderDetail::getOrderId, orderId)); if (statuses.length != 0) {
query.in(TbOrderDetail::getStatus, CollUtil.newArrayList(statuses));
}
return list(query);
} }
@Override @Override

View File

@ -2795,12 +2795,10 @@ public class TbShopTableServiceImpl implements TbShopTableService {
}else if (oldOrderInfo.getFullCouponDiscountAmount().compareTo(BigDecimal.ZERO) > 0 || oldOrderInfo.getPointsDiscountAmount().compareTo(BigDecimal.ZERO) > 0){ }else if (oldOrderInfo.getFullCouponDiscountAmount().compareTo(BigDecimal.ZERO) > 0 || oldOrderInfo.getPointsDiscountAmount().compareTo(BigDecimal.ZERO) > 0){
hasNormalReturn = true; hasNormalReturn = true;
// 计算当前商品占比 // 计算当前商品占比
BigDecimal ratio = calcDetailRatio(orderDetail); BigDecimal ratio = calcDetailRatio(orderDetail, returnNum);
BigDecimal realAmount = orderDetail.getPriceAmount().multiply(ratio); currentDetailAMount = orderDetail.getPriceAmount().divide(orderDetail.getNum(), 8, RoundingMode.HALF_UP)
currentDetailAMount = realAmount
.divide(orderDetail.getNum(), 8, RoundingMode.HALF_UP)
.multiply(returnNum).setScale(2, RoundingMode.HALF_UP); .multiply(returnNum).setScale(2, RoundingMode.HALF_UP);
returnAmount = returnAmount.add(currentDetailAMount); returnAmount = returnAmount.add(oldOrderInfo.getPayAmount().multiply(ratio));
saleAmount = saleAmount.add(orderDetail.getPrice()); saleAmount = saleAmount.add(orderDetail.getPrice());
packAMount = packAMount.add(orderDetail.getPackAmount() packAMount = packAMount.add(orderDetail.getPackAmount()
.divide(orderDetail.getNum(), 8, RoundingMode.HALF_UP) .divide(orderDetail.getNum(), 8, RoundingMode.HALF_UP)
@ -2869,11 +2867,12 @@ public class TbShopTableServiceImpl implements TbShopTableService {
mpOrderDetailService.updateBatchById(detailList); mpOrderDetailService.updateBatchById(detailList);
data.put("returnOrder", returnOrder); data.put("returnOrder", returnOrder);
data.put("returnAmount", returnAmount); data.put("returnAmount", returnAmount);
data.put("hasNormalReturn", hasNormalReturn);
return data; return data;
} }
private BigDecimal calcDetailRatio(TbOrderDetail orderDetail) { private BigDecimal calcDetailRatio(TbOrderDetail orderDetail, BigDecimal returnNum) {
List<TbOrderDetail> detailList = mpOrderDetailService.selectByOrderIdAndState(orderDetail.getId(), TableConstant.OrderInfo.Status.CLOSED); List<TbOrderDetail> detailList = mpOrderDetailService.selectByOrderIdAndState(orderDetail.getOrderId(), TableConstant.OrderInfo.Status.CLOSED, TableConstant.OrderInfo.Status.REFUND);
BigDecimal totalAmount = BigDecimal.ZERO; BigDecimal totalAmount = BigDecimal.ZERO;
for (TbOrderDetail item : detailList) { for (TbOrderDetail item : detailList) {
if (item.getUserCouponId() == null) { if (item.getUserCouponId() == null) {
@ -2881,7 +2880,8 @@ public class TbShopTableServiceImpl implements TbShopTableService {
} }
} }
return orderDetail.getPriceAmount().divide(totalAmount, 2, RoundingMode.HALF_UP); return orderDetail.getPriceAmount().divide(totalAmount, 8, RoundingMode.HALF_UP)
.divide(orderDetail.getNum(), 8, RoundingMode.HALF_UP).multiply(returnNum).setScale(2, RoundingMode.HALF_UP);
} }
private void updateStockAndRecord(List<TbOrderDetail> orderDetailList) { private void updateStockAndRecord(List<TbOrderDetail> orderDetailList) {
@ -2944,12 +2944,13 @@ public class TbShopTableServiceImpl implements TbShopTableService {
HashMap<String, Object> returnInfoData = updateReturnOrderInfo(returnOrderDTO, orderInfo, "scanCode".equals(payType) || "wx_lite".equals(payType)); HashMap<String, Object> returnInfoData = updateReturnOrderInfo(returnOrderDTO, orderInfo, "scanCode".equals(payType) || "wx_lite".equals(payType));
TbOrderInfo returnOrderInfo = (TbOrderInfo) returnInfoData.get("returnOrder"); TbOrderInfo returnOrderInfo = (TbOrderInfo) returnInfoData.get("returnOrder");
BigDecimal returnAmount = (BigDecimal) returnInfoData.get("returnAmount"); BigDecimal returnAmount = (BigDecimal) returnInfoData.get("returnAmount");
boolean hasNormalReturn = (boolean) returnInfoData.get("hasNormalReturn");
String shopId = orderInfo.getShopId(); String shopId = orderInfo.getShopId();
// // 线上退款 // // 线上退款
orderInfo.setRefundAmount(orderInfo.getRefundAmount().add(returnOrderInfo.getRefundAmount())); orderInfo.setRefundAmount(orderInfo.getRefundAmount().add(returnOrderInfo.getRefundAmount()));
orderInfo.setRefundRemark(returnOrderDTO.getNote()); orderInfo.setRefundRemark(returnOrderDTO.getNote());
if ("scanCode".equals(payType) || "wx_lite".equals(payType)) { if (hasNormalReturn && ("scanCode".equals(payType) || "wx_lite".equals(payType))) {
payService.returnOrder(Integer.valueOf(shopId), orderInfo, returnOrderInfo); payService.returnOrder(Integer.valueOf(shopId), orderInfo, returnOrderInfo);
returnOrderInfo.setStatus("refund"); returnOrderInfo.setStatus("refund");
mpOrderInfoService.updateById(returnOrderInfo); mpOrderInfoService.updateById(returnOrderInfo);