fix: 退款支持比例退款
This commit is contained in:
parent
97e2b91364
commit
2d36aa4d9b
|
|
@ -47,7 +47,7 @@ public interface MpOrderDetailService extends IService<TbOrderDetail> {
|
|||
/**
|
||||
* 根据订单id和状态获取订单详情
|
||||
*/
|
||||
List<TbOrderDetail> selectByOrderIdAndState(Integer orderId, TableConstant.OrderInfo.Status state);
|
||||
List<TbOrderDetail> selectByOrderIdAndState(Integer orderId, TableConstant.OrderInfo.Status... states);
|
||||
|
||||
/**
|
||||
* 根据购物车id和订单id查询订单详情
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
package cn.ysk.cashier.mybatis.service.impl;
|
||||
|
||||
import cn.hutool.core.collection.CollUtil;
|
||||
import cn.ysk.cashier.cons.TableConstant;
|
||||
import cn.ysk.cashier.dto.shoptable.ReturnOrderDTO;
|
||||
import cn.ysk.cashier.enums.OrderStatusEnums;
|
||||
|
|
@ -50,10 +51,13 @@ public class MpOrderDetailServiceImpl extends ServiceImpl<TbOrderDetailMapper, T
|
|||
}
|
||||
|
||||
@Override
|
||||
public List<TbOrderDetail> selectByOrderIdAndState(Integer orderId, TableConstant.OrderInfo.Status state) {
|
||||
return list(new LambdaQueryWrapper<TbOrderDetail>()
|
||||
.eq(TbOrderDetail::getStatus, state.getValue())
|
||||
.eq(TbOrderDetail::getOrderId, orderId));
|
||||
public List<TbOrderDetail> selectByOrderIdAndState(Integer orderId, TableConstant.OrderInfo.Status... statuses) {
|
||||
LambdaQueryWrapper<TbOrderDetail> query = new LambdaQueryWrapper<TbOrderDetail>()
|
||||
.eq(TbOrderDetail::getOrderId, orderId);
|
||||
if (statuses.length != 0) {
|
||||
query.in(TbOrderDetail::getStatus, CollUtil.newArrayList(statuses));
|
||||
}
|
||||
return list(query);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
|||
|
|
@ -2795,12 +2795,10 @@ public class TbShopTableServiceImpl implements TbShopTableService {
|
|||
}else if (oldOrderInfo.getFullCouponDiscountAmount().compareTo(BigDecimal.ZERO) > 0 || oldOrderInfo.getPointsDiscountAmount().compareTo(BigDecimal.ZERO) > 0){
|
||||
hasNormalReturn = true;
|
||||
// 计算当前商品占比
|
||||
BigDecimal ratio = calcDetailRatio(orderDetail);
|
||||
BigDecimal realAmount = orderDetail.getPriceAmount().multiply(ratio);
|
||||
currentDetailAMount = realAmount
|
||||
.divide(orderDetail.getNum(), 8, RoundingMode.HALF_UP)
|
||||
BigDecimal ratio = calcDetailRatio(orderDetail, returnNum);
|
||||
currentDetailAMount = orderDetail.getPriceAmount().divide(orderDetail.getNum(), 8, 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());
|
||||
packAMount = packAMount.add(orderDetail.getPackAmount()
|
||||
.divide(orderDetail.getNum(), 8, RoundingMode.HALF_UP)
|
||||
|
|
@ -2869,11 +2867,12 @@ public class TbShopTableServiceImpl implements TbShopTableService {
|
|||
mpOrderDetailService.updateBatchById(detailList);
|
||||
data.put("returnOrder", returnOrder);
|
||||
data.put("returnAmount", returnAmount);
|
||||
data.put("hasNormalReturn", hasNormalReturn);
|
||||
return data;
|
||||
}
|
||||
|
||||
private BigDecimal calcDetailRatio(TbOrderDetail orderDetail) {
|
||||
List<TbOrderDetail> detailList = mpOrderDetailService.selectByOrderIdAndState(orderDetail.getId(), TableConstant.OrderInfo.Status.CLOSED);
|
||||
private BigDecimal calcDetailRatio(TbOrderDetail orderDetail, BigDecimal returnNum) {
|
||||
List<TbOrderDetail> detailList = mpOrderDetailService.selectByOrderIdAndState(orderDetail.getOrderId(), TableConstant.OrderInfo.Status.CLOSED, TableConstant.OrderInfo.Status.REFUND);
|
||||
BigDecimal totalAmount = BigDecimal.ZERO;
|
||||
for (TbOrderDetail item : detailList) {
|
||||
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) {
|
||||
|
|
@ -2944,12 +2944,13 @@ public class TbShopTableServiceImpl implements TbShopTableService {
|
|||
HashMap<String, Object> returnInfoData = updateReturnOrderInfo(returnOrderDTO, orderInfo, "scanCode".equals(payType) || "wx_lite".equals(payType));
|
||||
TbOrderInfo returnOrderInfo = (TbOrderInfo) returnInfoData.get("returnOrder");
|
||||
BigDecimal returnAmount = (BigDecimal) returnInfoData.get("returnAmount");
|
||||
boolean hasNormalReturn = (boolean) returnInfoData.get("hasNormalReturn");
|
||||
String shopId = orderInfo.getShopId();
|
||||
|
||||
// // 线上退款
|
||||
orderInfo.setRefundAmount(orderInfo.getRefundAmount().add(returnOrderInfo.getRefundAmount()));
|
||||
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);
|
||||
returnOrderInfo.setStatus("refund");
|
||||
mpOrderInfoService.updateById(returnOrderInfo);
|
||||
|
|
|
|||
Loading…
Reference in New Issue