订单退款
This commit is contained in:
parent
691f12753e
commit
d6966b9b07
|
|
@ -1,14 +1,20 @@
|
|||
package com.czg.controller.admin;
|
||||
|
||||
import com.czg.order.dto.OrderInfoAddDTO;
|
||||
import com.czg.order.dto.OrderInfoQueryDTO;
|
||||
import com.czg.order.dto.OrderInfoRefundDTO;
|
||||
import com.czg.order.entity.OrderInfo;
|
||||
import com.czg.order.service.OrderInfoService;
|
||||
import com.czg.order.vo.HistoryOrderVo;
|
||||
import com.czg.order.vo.OrderInfoVo;
|
||||
import com.czg.resp.CzgResult;
|
||||
import com.czg.sa.StpKit;
|
||||
import com.czg.service.order.service.PayService;
|
||||
import com.czg.utils.ServletUtil;
|
||||
import com.mybatisflex.core.paginate.Page;
|
||||
import jakarta.annotation.Resource;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
|
||||
/**
|
||||
|
|
@ -23,29 +29,31 @@ public class AdminOrderController {
|
|||
|
||||
@Resource
|
||||
private OrderInfoService orderInfoService;
|
||||
@Resource
|
||||
private PayService payService;
|
||||
|
||||
/**
|
||||
* 订单列表
|
||||
*/
|
||||
// @PostMapping
|
||||
// public CzgResult<Page<OrderInfoVo>> getOrderPage(@RequestBody OrderInfoQueryDTO queryDTO) {
|
||||
// queryDTO.setShopId(StpKit.USER.getShopId());
|
||||
// return CzgResult.success(orderInfoService.getOrderByPage(queryDTO));
|
||||
// }
|
||||
//
|
||||
// @GetMapping("/historyOrder")
|
||||
// public CzgResult<HistoryOrderVo> historyOrder(Long orderId) {
|
||||
// return CzgResult.success(orderInfoService.historyOrder(orderId));
|
||||
// }
|
||||
//
|
||||
// @PostMapping("/createOrder")
|
||||
// public CzgResult<OrderInfo> createOrder(@Validated @RequestBody OrderInfoAddDTO addDto) {
|
||||
// addDto.setPlatformType(ServletUtil.getHeaderIgnoreCase(ServletUtil.getRequest(), "platformType"));
|
||||
// addDto.setStaffId(StpKit.USER.getLoginIdAsLong());
|
||||
// addDto.setShopId(StpKit.USER.getShopId());
|
||||
// addDto.setOrderType("cash");
|
||||
// return CzgResult.success(orderInfoService.createOrder(addDto));
|
||||
// }
|
||||
@PostMapping
|
||||
public CzgResult<Page<OrderInfoVo>> getOrderPage(@RequestBody OrderInfoQueryDTO queryDTO) {
|
||||
queryDTO.setShopId(StpKit.USER.getShopId());
|
||||
return CzgResult.success(orderInfoService.getOrderByPage(queryDTO));
|
||||
}
|
||||
|
||||
@GetMapping("/historyOrder")
|
||||
public CzgResult<HistoryOrderVo> historyOrder(Long orderId) {
|
||||
return CzgResult.success(orderInfoService.historyOrder(orderId));
|
||||
}
|
||||
|
||||
@PostMapping("/createOrder")
|
||||
public CzgResult<OrderInfo> createOrder(@Validated @RequestBody OrderInfoAddDTO addDto) {
|
||||
addDto.setPlatformType(ServletUtil.getHeaderIgnoreCase(ServletUtil.getRequest(), "platformType"));
|
||||
addDto.setStaffId(StpKit.USER.getLoginIdAsLong());
|
||||
addDto.setShopId(StpKit.USER.getShopId());
|
||||
addDto.setOrderType("cash");
|
||||
return CzgResult.success(orderInfoService.createOrder(addDto));
|
||||
}
|
||||
|
||||
/**
|
||||
* 订单全额退款 只传订单id
|
||||
|
|
@ -54,6 +62,6 @@ public class AdminOrderController {
|
|||
*/
|
||||
@PostMapping("/refundOrder")
|
||||
public CzgResult<Object> refundOrder(@Validated @RequestBody OrderInfoRefundDTO refundDTO) {
|
||||
return orderInfoService.refundOrder(refundDTO);
|
||||
return payService.refundOrderBefore(refundDTO);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,12 +1,13 @@
|
|||
package com.czg.order.service;
|
||||
|
||||
import com.alibaba.fastjson2.JSONObject;
|
||||
import com.czg.order.dto.*;
|
||||
import com.czg.order.dto.CheckOrderPay;
|
||||
import com.czg.order.dto.OrderInfoAddDTO;
|
||||
import com.czg.order.dto.OrderInfoQueryDTO;
|
||||
import com.czg.order.entity.OrderInfo;
|
||||
import com.czg.order.enums.PayEnums;
|
||||
import com.czg.order.vo.HistoryOrderVo;
|
||||
import com.czg.order.vo.OrderInfoVo;
|
||||
import com.czg.resp.CzgResult;
|
||||
import com.mybatisflex.core.paginate.Page;
|
||||
import com.mybatisflex.core.service.IService;
|
||||
import jakarta.validation.constraints.NotBlank;
|
||||
|
|
@ -29,8 +30,6 @@ public interface OrderInfoService extends IService<OrderInfo> {
|
|||
|
||||
OrderInfo checkOrderPay(CheckOrderPay param);
|
||||
|
||||
CzgResult<Object> refundOrder(OrderInfoRefundDTO param);
|
||||
|
||||
void payCallBackOrder(@NotBlank String orderNo, @NotNull JSONObject resultJson);
|
||||
|
||||
void refundCallBackOrder(@NotBlank String orderNo, @NotNull JSONObject resultJson);
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@ package com.czg.service.order.service;
|
|||
|
||||
import com.czg.entity.resp.CzgBaseResp;
|
||||
import com.czg.entity.resp.CzgRefundResp;
|
||||
import com.czg.order.dto.OrderInfoRefundDTO;
|
||||
import com.czg.resp.CzgResult;
|
||||
import com.czg.service.order.dto.OrderPayParamDTO;
|
||||
import com.czg.service.order.dto.VipPayParamDTO;
|
||||
|
|
@ -93,6 +94,7 @@ public interface PayService {
|
|||
*/
|
||||
CzgResult<Object> refundVip(VipRefundDTO payParam);
|
||||
|
||||
CzgResult<Object> refundOrderBefore(OrderInfoRefundDTO param);
|
||||
|
||||
/**
|
||||
* 订单退款
|
||||
|
|
|
|||
|
|
@ -15,7 +15,9 @@ import com.czg.config.RedisCst;
|
|||
import com.czg.entity.notify.CzgPayNotifyDTO;
|
||||
import com.czg.entity.notify.CzgRefundNotifyDTO;
|
||||
import com.czg.enums.ShopUserFlowBizEnum;
|
||||
import com.czg.order.dto.*;
|
||||
import com.czg.order.dto.CheckOrderPay;
|
||||
import com.czg.order.dto.OrderInfoAddDTO;
|
||||
import com.czg.order.dto.OrderInfoQueryDTO;
|
||||
import com.czg.order.entity.OrderDetail;
|
||||
import com.czg.order.entity.OrderInfo;
|
||||
import com.czg.order.entity.OrderPayment;
|
||||
|
|
@ -27,12 +29,10 @@ import com.czg.order.service.OrderPaymentService;
|
|||
import com.czg.order.vo.HistoryOrderVo;
|
||||
import com.czg.order.vo.OrderDetailSmallVO;
|
||||
import com.czg.order.vo.OrderInfoVo;
|
||||
import com.czg.resp.CzgResult;
|
||||
import com.czg.sa.StpKit;
|
||||
import com.czg.service.RedisService;
|
||||
import com.czg.service.order.enums.OrderStatusEnums;
|
||||
import com.czg.service.order.mapper.OrderInfoMapper;
|
||||
import com.czg.service.order.service.PayService;
|
||||
import com.czg.utils.AssertUtil;
|
||||
import com.czg.utils.CzgStrUtils;
|
||||
import com.czg.utils.PageUtil;
|
||||
|
|
@ -69,10 +69,6 @@ public class OrderInfoServiceImpl extends ServiceImpl<OrderInfoMapper, OrderInfo
|
|||
private OrderPaymentService paymentService;
|
||||
@Resource
|
||||
private CashierCartService cartService;
|
||||
@Resource
|
||||
private OrderDetailService detailService;
|
||||
@Resource
|
||||
private PayService payService;
|
||||
@DubboReference
|
||||
private ShopInfoService shopInfoService;
|
||||
@DubboReference
|
||||
|
|
@ -301,99 +297,6 @@ public class OrderInfoServiceImpl extends ServiceImpl<OrderInfoMapper, OrderInfo
|
|||
return orderInfo;
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional
|
||||
public CzgResult<Object> refundOrder(OrderInfoRefundDTO param) {
|
||||
OrderInfo orderInfo = getById(param.getOrderId());
|
||||
//退款总额
|
||||
BigDecimal refundAmountTotal = BigDecimal.ZERO;
|
||||
//退优惠券数量 <商品id,数量>
|
||||
Map<Long, Integer> returnCouponMap = new HashMap<>();
|
||||
boolean isPay = true;
|
||||
String refPayOrderNo = "REFO" + IdUtil.getSnowflakeNextId();
|
||||
if (orderInfo.getStatus().equals(OrderStatusEnums.UNPAID.getCode())) {
|
||||
isPay = false;
|
||||
refPayOrderNo = "";
|
||||
}
|
||||
if (CollUtil.isNotEmpty(param.getRefundDetails())) {
|
||||
for (OrderDetail refundDetail : param.getRefundDetails()) {
|
||||
AssertUtil.isNull(refundDetail.getNum(), "退单数量不能为空");
|
||||
//退款金额
|
||||
BigDecimal refundAmount = BigDecimal.ZERO;
|
||||
//退款数量
|
||||
BigDecimal refNum;
|
||||
OrderDetail orderDetail = detailService.getById(refundDetail.getId());
|
||||
//可退数量=订单数量-退单数量-退菜数量
|
||||
BigDecimal returnNum = orderDetail.getNum().subtract(orderDetail.getRefundNum()).subtract(orderDetail.getReturnNum());
|
||||
if (returnNum.compareTo(BigDecimal.ZERO) <= 0 || returnNum.compareTo(refundDetail.getNum()) < 0) {
|
||||
throw new ValidateException("退单失败," + orderDetail.getProductName() + "可退数量不足");
|
||||
}
|
||||
//可退数量 大于优惠券数量
|
||||
if (returnNum.compareTo(orderDetail.getCouponNum()) > 0) {
|
||||
//实际计算金额的数量
|
||||
refNum = returnNum.subtract(orderDetail.getCouponNum());
|
||||
//退单数量 大于 实际计算金额的数量
|
||||
if (refundDetail.getNum().compareTo(refNum) > 0) {
|
||||
refundAmount = refNum.multiply(orderDetail.getPrice());
|
||||
returnCouponMap.put(orderDetail.getProductId(), refundDetail.getNum().subtract(refNum).intValue());
|
||||
} else {
|
||||
refundAmount = refundDetail.getNum().multiply(orderDetail.getPrice());
|
||||
}
|
||||
}
|
||||
if (refundAmount.compareTo(refundDetail.getReturnAmount()) != 0) {
|
||||
throw new ValidateException("退单失败," + orderDetail.getProductName() + "退单金额不正确");
|
||||
}
|
||||
refNum = refundDetail.getNum();
|
||||
refundAmountTotal = refundAmountTotal.add(refundAmount);
|
||||
if (isPay) {
|
||||
orderDetail.setRefundNum(orderDetail.getRefundNum().add(refNum));
|
||||
orderDetail.setReturnAmount(orderDetail.getReturnAmount().add(refundDetail.getReturnAmount()));
|
||||
if (orderDetail.getReturnAmount().compareTo(orderDetail.getPayAmount()) > 0) {
|
||||
throw new ValidateException("退单失败," + orderDetail.getProductName() + "退单金额不正确");
|
||||
}
|
||||
} else {
|
||||
orderDetail.setReturnNum(orderDetail.getRefundNum().add(refNum));
|
||||
orderDetail.setPayAmount((orderDetail.getNum().subtract(orderDetail.getRefundNum()).subtract(orderDetail.getReturnNum())
|
||||
.subtract(orderDetail.getCouponNum())).multiply(orderDetail.getPrice()));
|
||||
}
|
||||
orderDetail.setRefundNo(refPayOrderNo);
|
||||
orderDetail.setRefundRemark(orderDetail.getRefundRemark() + param.getRefundReason());
|
||||
detailService.updateById(orderDetail);
|
||||
}
|
||||
} else {
|
||||
refundAmountTotal = param.getRefundAmount();
|
||||
}
|
||||
//总退款金额
|
||||
//TODO 退款 券 未处理
|
||||
if (isPay) {
|
||||
if (param.isModify()) {
|
||||
orderInfo.setRefundAmount(orderInfo.getRefundAmount().add(param.getRefundAmount()));
|
||||
if (orderInfo.getRefundAmount().compareTo(orderInfo.getPayAmount()) < 0) {
|
||||
throw new ValidateException("退单失败,可退金额不足");
|
||||
}
|
||||
//退款 param.getRefundAmount()
|
||||
payService.refundOrder(orderInfo.getShopId(), orderInfo.getId(), orderInfo.getPayOrderId(),
|
||||
refPayOrderNo, param.getRefundReason(), param.getRefundAmount());
|
||||
} else {
|
||||
if (refundAmountTotal.compareTo(param.getRefundAmount()) != 0) {
|
||||
throw new ValidateException("退单失败,退款金额不正确");
|
||||
}
|
||||
orderInfo.setRefundAmount(orderInfo.getRefundAmount().add(refundAmountTotal));
|
||||
if (orderInfo.getRefundAmount().compareTo(orderInfo.getPayAmount()) < 0) {
|
||||
throw new ValidateException("退单失败,可退金额不足");
|
||||
}
|
||||
//退款 refundAmountTotal
|
||||
payService.refundOrder(orderInfo.getShopId(), orderInfo.getId(), orderInfo.getPayOrderId(),
|
||||
refPayOrderNo, param.getRefundReason(), refundAmountTotal);
|
||||
}
|
||||
} else {
|
||||
orderInfo.setOrderAmount(orderInfo.getOrderAmount().subtract(refundAmountTotal));
|
||||
}
|
||||
orderInfo.setRefundRemark(orderInfo.getRefundRemark() + param.getRefundReason());
|
||||
updateById(orderInfo);
|
||||
return CzgResult.success();
|
||||
}
|
||||
|
||||
/**
|
||||
* 填充 优惠券使用数量 以及 付款金额
|
||||
*
|
||||
|
|
|
|||
|
|
@ -1,20 +1,23 @@
|
|||
package com.czg.service.order.service.impl;
|
||||
|
||||
import cn.hutool.core.collection.CollUtil;
|
||||
import cn.hutool.core.exceptions.ValidateException;
|
||||
import cn.hutool.core.util.IdUtil;
|
||||
import com.alibaba.fastjson2.JSONObject;
|
||||
import com.czg.account.dto.shopuser.ShopUserMoneyEditDTO;
|
||||
import com.czg.account.entity.*;
|
||||
import com.czg.account.service.*;
|
||||
import com.czg.config.RabbitPublisher;
|
||||
import com.czg.config.RedisCst;
|
||||
import com.czg.entity.req.*;
|
||||
import com.czg.entity.resp.*;
|
||||
import com.czg.enums.ShopUserFlowBizEnum;
|
||||
import com.czg.order.dto.CheckOrderPay;
|
||||
import com.czg.order.dto.OrderInfoRefundDTO;
|
||||
import com.czg.order.entity.OrderDetail;
|
||||
import com.czg.order.entity.OrderInfo;
|
||||
import com.czg.order.entity.OrderPayment;
|
||||
import com.czg.order.enums.PayEnums;
|
||||
import com.czg.order.service.OrderDetailService;
|
||||
import com.czg.order.service.OrderInfoService;
|
||||
import com.czg.order.service.OrderPaymentService;
|
||||
import com.czg.resp.CzgResult;
|
||||
|
|
@ -23,6 +26,7 @@ import com.czg.service.RedisService;
|
|||
import com.czg.service.order.dto.OrderPayParamDTO;
|
||||
import com.czg.service.order.dto.VipPayParamDTO;
|
||||
import com.czg.service.order.dto.VipRefundDTO;
|
||||
import com.czg.service.order.enums.OrderStatusEnums;
|
||||
import com.czg.service.order.service.PayService;
|
||||
import com.czg.system.enums.SysParamCodeEnum;
|
||||
import com.czg.system.service.SysParamsService;
|
||||
|
|
@ -67,12 +71,12 @@ public class PayServiceImpl implements PayService {
|
|||
@DubboReference
|
||||
private ShopCouponService couponService;
|
||||
@Resource
|
||||
private RabbitPublisher rabbitPublisher;
|
||||
@Resource
|
||||
private CzgPayService czgPayService;
|
||||
@Resource
|
||||
private OrderInfoService orderInfoService;
|
||||
@Resource
|
||||
private OrderDetailService orderDetailService;
|
||||
@Resource
|
||||
private OrderPaymentService paymentService;
|
||||
@Resource
|
||||
private RedisService redisService;
|
||||
|
|
@ -391,6 +395,99 @@ public class PayServiceImpl implements PayService {
|
|||
return CzgResult.success();
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional
|
||||
public CzgResult<Object> refundOrderBefore(OrderInfoRefundDTO param) {
|
||||
OrderInfo orderInfo = orderInfoService.getById(param.getOrderId());
|
||||
//退款总额
|
||||
BigDecimal refundAmountTotal = BigDecimal.ZERO;
|
||||
//退优惠券数量 <商品id,数量>
|
||||
Map<Long, Integer> returnCouponMap = new HashMap<>();
|
||||
boolean isPay = true;
|
||||
String refPayOrderNo = "REFO" + IdUtil.getSnowflakeNextId();
|
||||
if (orderInfo.getStatus().equals(OrderStatusEnums.UNPAID.getCode())) {
|
||||
isPay = false;
|
||||
refPayOrderNo = "";
|
||||
}
|
||||
if (CollUtil.isNotEmpty(param.getRefundDetails())) {
|
||||
for (OrderDetail refundDetail : param.getRefundDetails()) {
|
||||
AssertUtil.isNull(refundDetail.getNum(), "退单数量不能为空");
|
||||
//退款金额
|
||||
BigDecimal refundAmount = BigDecimal.ZERO;
|
||||
//退款数量
|
||||
BigDecimal refNum;
|
||||
OrderDetail orderDetail = orderDetailService.getById(refundDetail.getId());
|
||||
//可退数量=订单数量-退单数量-退菜数量
|
||||
BigDecimal returnNum = orderDetail.getNum().subtract(orderDetail.getRefundNum()).subtract(orderDetail.getReturnNum());
|
||||
if (returnNum.compareTo(BigDecimal.ZERO) <= 0 || returnNum.compareTo(refundDetail.getNum()) < 0) {
|
||||
throw new ValidateException("退单失败," + orderDetail.getProductName() + "可退数量不足");
|
||||
}
|
||||
//可退数量 大于优惠券数量
|
||||
if (returnNum.compareTo(orderDetail.getCouponNum()) > 0) {
|
||||
//实际计算金额的数量
|
||||
refNum = returnNum.subtract(orderDetail.getCouponNum());
|
||||
//退单数量 大于 实际计算金额的数量
|
||||
if (refundDetail.getNum().compareTo(refNum) > 0) {
|
||||
refundAmount = refNum.multiply(orderDetail.getPrice());
|
||||
returnCouponMap.put(orderDetail.getProductId(), refundDetail.getNum().subtract(refNum).intValue());
|
||||
} else {
|
||||
refundAmount = refundDetail.getNum().multiply(orderDetail.getPrice());
|
||||
}
|
||||
}
|
||||
if (refundAmount.compareTo(refundDetail.getReturnAmount()) != 0) {
|
||||
throw new ValidateException("退单失败," + orderDetail.getProductName() + "退单金额不正确");
|
||||
}
|
||||
refNum = refundDetail.getNum();
|
||||
refundAmountTotal = refundAmountTotal.add(refundAmount);
|
||||
if (isPay) {
|
||||
orderDetail.setRefundNum(orderDetail.getRefundNum().add(refNum));
|
||||
orderDetail.setReturnAmount(orderDetail.getReturnAmount().add(refundDetail.getReturnAmount()));
|
||||
if (orderDetail.getReturnAmount().compareTo(orderDetail.getPayAmount()) > 0) {
|
||||
throw new ValidateException("退单失败," + orderDetail.getProductName() + "退单金额不正确");
|
||||
}
|
||||
} else {
|
||||
orderDetail.setReturnNum(orderDetail.getRefundNum().add(refNum));
|
||||
orderDetail.setPayAmount((orderDetail.getNum().subtract(orderDetail.getRefundNum()).subtract(orderDetail.getReturnNum())
|
||||
.subtract(orderDetail.getCouponNum())).multiply(orderDetail.getPrice()));
|
||||
}
|
||||
orderDetail.setRefundNo(refPayOrderNo);
|
||||
orderDetail.setRefundRemark(orderDetail.getRefundRemark() + param.getRefundReason());
|
||||
orderDetailService.updateById(orderDetail);
|
||||
}
|
||||
} else {
|
||||
refundAmountTotal = param.getRefundAmount();
|
||||
}
|
||||
//总退款金额
|
||||
//TODO 退款 券 未处理
|
||||
if (isPay) {
|
||||
if (param.isModify()) {
|
||||
orderInfo.setRefundAmount(orderInfo.getRefundAmount().add(param.getRefundAmount()));
|
||||
if (orderInfo.getRefundAmount().compareTo(orderInfo.getPayAmount()) < 0) {
|
||||
throw new ValidateException("退单失败,可退金额不足");
|
||||
}
|
||||
//退款 param.getRefundAmount()
|
||||
refundOrder(orderInfo.getShopId(), orderInfo.getId(), orderInfo.getPayOrderId(),
|
||||
refPayOrderNo, param.getRefundReason(), param.getRefundAmount());
|
||||
} else {
|
||||
if (refundAmountTotal.compareTo(param.getRefundAmount()) != 0) {
|
||||
throw new ValidateException("退单失败,退款金额不正确");
|
||||
}
|
||||
orderInfo.setRefundAmount(orderInfo.getRefundAmount().add(refundAmountTotal));
|
||||
if (orderInfo.getRefundAmount().compareTo(orderInfo.getPayAmount()) < 0) {
|
||||
throw new ValidateException("退单失败,可退金额不足");
|
||||
}
|
||||
//退款 refundAmountTotal
|
||||
refundOrder(orderInfo.getShopId(), orderInfo.getId(), orderInfo.getPayOrderId(),
|
||||
refPayOrderNo, param.getRefundReason(), refundAmountTotal);
|
||||
}
|
||||
} else {
|
||||
orderInfo.setOrderAmount(orderInfo.getOrderAmount().subtract(refundAmountTotal));
|
||||
}
|
||||
orderInfo.setRefundRemark(orderInfo.getRefundRemark() + param.getRefundReason());
|
||||
orderInfoService.updateById(orderInfo);
|
||||
return CzgResult.success();
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional
|
||||
public CzgResult<Object> refundOrder(@NonNull Long shopId, @NonNull Long orderId, @NonNull Long payOrderId, @NonNull String refPayOrderNo,
|
||||
|
|
|
|||
Loading…
Reference in New Issue