From ed0fde9d9976b3ff723b17c7cff3b340b4bb6602 Mon Sep 17 00:00:00 2001 From: hurui <177768073@qq.com> Date: Mon, 31 Oct 2022 10:53:28 +0800 Subject: [PATCH] =?UTF-8?q?=E6=8F=90=E4=BA=A4=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/web/controller/OrderController.java | 72 ---------- .../web/controller/OrderRefundController.java | 2 +- .../consumer/OrderRefundSuccessConsumer.java | 57 ++++++++ .../com/hai/order/model/RefundPriceModel.java | 23 ++++ .../service/OrderRefundHandleService.java | 9 +- .../hai/order/service/OrderRefundService.java | 26 +++- .../impl/OrderRefundHandleServiceImpl.java | 9 +- .../service/impl/OrderRefundServiceImpl.java | 125 +++++++++++++++--- .../order/service/impl/OrderServiceImpl.java | 41 +++++- .../java/com/hai/order/topic/OrderTopic.java | 1 + 10 files changed, 255 insertions(+), 110 deletions(-) create mode 100644 hai-order/src/main/java/com/web/rocketmq/consumer/OrderRefundSuccessConsumer.java create mode 100644 hai-service/src/main/java/com/hai/order/model/RefundPriceModel.java diff --git a/hai-order/src/main/java/com/web/controller/OrderController.java b/hai-order/src/main/java/com/web/controller/OrderController.java index 7d97dbc6..b27a712a 100644 --- a/hai-order/src/main/java/com/web/controller/OrderController.java +++ b/hai-order/src/main/java/com/web/controller/OrderController.java @@ -140,55 +140,6 @@ public class OrderController { } } - @RequestMapping(value="/refundOrder",method = RequestMethod.POST) - @ResponseBody - @ApiOperation(value = "交易订单退款") - public ResponseData refundOrder(@RequestBody JSONObject body) { - try { - if (body == null || StringUtils.isBlank(body.getString("orderNo"))) { - throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "未找到订单"); - } - orderService.refundOrder(body.getString("orderNo"), body.getString("remarks")); - - return ResponseMsgUtil.success("退款成功"); - - } catch (Exception e) { - log.error("OrderController -> refundOrder() error!",e); - return ResponseMsgUtil.exception(e); - } - } - - @RequestMapping(value="/refundOrderChild",method = RequestMethod.POST) - @ResponseBody - @ApiOperation(value = "子订单退款") - public ResponseData refundOrderChild(@RequestBody JSONObject body) { - try { - if (body == null - || StringUtils.isBlank(body.getString("childOrderNo")) - || body.getInteger("refundGoodsNum") == null - ) { - throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "未找到订单"); - } - - // 查询订单编号 - HighChildOrder orderChild = orderService.getChildOrderByNo(body.getString("childOrderNo")); - if (orderChild == null) { - throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "未找到订单编号"); - } - if (orderChild.getChildOrderStatus().equals(OrderChildStatus.STATUS2.getNumber()) - || orderChild.getChildOrderStatus().equals(OrderChildStatus.STATUS3.getNumber())){ - throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "子订单状态错误"); - } - orderService.refundChildOrder(orderChild.getOrderNo(), body.getString("childOrderNo"), body.getInteger("refundGoodsNum"), body.getString("remarks")); - - return ResponseMsgUtil.success("退款成功"); - - } catch (Exception e) { - log.error("OrderController -> refundOrderChild() error!",e); - return ResponseMsgUtil.exception(e); - } - } - @RequestMapping(value="/getDetailByOrderNo",method = RequestMethod.GET) @ResponseBody @ApiOperation(value = "根据订单号查询详情") @@ -236,29 +187,6 @@ public class OrderController { } } - @RequestMapping(value="/paySuccess",method = RequestMethod.POST) - @ResponseBody - @ApiOperation(value = "支付成功") - public ResponseData paySuccess(@RequestBody JSONObject body) { - try { - if (body == null || StringUtils.isBlank(body.getString("orderNo"))) { - throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "未找到订单"); - } - - HighOrder order = orderService.getOrderDetailByNo(body.getString("orderNo")); - - return ResponseMsgUtil.success(orderPaySuccessService.orderPaySuccessHandle(order.getOrderNo(), - OrderPayType.PAY_TYPE5, - "", - new BigDecimal("0"), - null)); - - } catch (Exception e) { - log.error("OrderController -> paySuccess() error!",e); - return ResponseMsgUtil.exception(e); - } - } - @RequestMapping(value = "/orderCheck", method = RequestMethod.GET) @ResponseBody @ApiOperation(value = "根据订单id查看订单") diff --git a/hai-order/src/main/java/com/web/controller/OrderRefundController.java b/hai-order/src/main/java/com/web/controller/OrderRefundController.java index cf53a0d2..fd48b246 100644 --- a/hai-order/src/main/java/com/web/controller/OrderRefundController.java +++ b/hai-order/src/main/java/com/web/controller/OrderRefundController.java @@ -85,7 +85,7 @@ public class OrderRefundController { @RequestMapping(value="/refundChild",method = RequestMethod.POST) @ResponseBody @ApiOperation(value = "子订单退款") - public ResponseData refundOrderChild(@RequestBody JSONObject body) { + public ResponseData refundChild(@RequestBody JSONObject body) { try { if (body == null || StringUtils.isBlank(body.getString("childOrderNo")) diff --git a/hai-order/src/main/java/com/web/rocketmq/consumer/OrderRefundSuccessConsumer.java b/hai-order/src/main/java/com/web/rocketmq/consumer/OrderRefundSuccessConsumer.java new file mode 100644 index 00000000..ac8d6eeb --- /dev/null +++ b/hai-order/src/main/java/com/web/rocketmq/consumer/OrderRefundSuccessConsumer.java @@ -0,0 +1,57 @@ +package com.web.rocketmq.consumer; + +import com.hai.entity.HighOrder; +import com.hai.entity.HighOrderRefund; +import com.hai.order.service.OrderRefundHandleService; +import com.hai.order.service.OrderRefundService; +import com.hai.order.service.OrderService; +import com.hai.order.type.OrderChildGoodsType; +import com.hai.order.type.OrderStatus; +import lombok.extern.slf4j.Slf4j; +import org.apache.rocketmq.spring.annotation.RocketMQMessageListener; +import org.apache.rocketmq.spring.core.RocketMQListener; +import org.springframework.stereotype.Component; + +import javax.annotation.Resource; + +@Component +@Slf4j +@RocketMQMessageListener(consumerGroup = "order-refund-success-group", topic = "order-topic",selectorExpression = "refund-success") +public class OrderRefundSuccessConsumer implements RocketMQListener { + + @Resource + private OrderService orderService; + + @Resource + private OrderRefundService orderRefundService; + + @Resource + private OrderRefundHandleService refundHandleService; + + @Override + public void onMessage(HighOrderRefund orderRefund) { + if (orderRefund.getGoodsType().equals(OrderChildGoodsType.TYPE1.getNumber())) { + refundHandleService.couponHandle(orderRefund); + + } else if (orderRefund.getGoodsType().equals(OrderChildGoodsType.TYPE2.getNumber())) { + + } else if (orderRefund.getGoodsType().equals(OrderChildGoodsType.TYPE3.getNumber())) { + refundHandleService.oilHandle(orderRefund); + + } else if (orderRefund.getGoodsType().equals(OrderChildGoodsType.TYPE4.getNumber())) { + + } else if (orderRefund.getGoodsType().equals(OrderChildGoodsType.TYPE5.getNumber())) { + + } else if (orderRefund.getGoodsType().equals(OrderChildGoodsType.TYPE6.getNumber())) { + + } else if (orderRefund.getGoodsType().equals(OrderChildGoodsType.TYPE7.getNumber())) { + + } else if (orderRefund.getGoodsType().equals(OrderChildGoodsType.TYPE8.getNumber())) { + + } else if (orderRefund.getGoodsType().equals(OrderChildGoodsType.TYPE9.getNumber())) { + + } else if (orderRefund.getGoodsType().equals(OrderChildGoodsType.TYPE10.getNumber())) { + + } + } +} diff --git a/hai-service/src/main/java/com/hai/order/model/RefundPriceModel.java b/hai-service/src/main/java/com/hai/order/model/RefundPriceModel.java new file mode 100644 index 00000000..ce60d3e6 --- /dev/null +++ b/hai-service/src/main/java/com/hai/order/model/RefundPriceModel.java @@ -0,0 +1,23 @@ +package com.hai.order.model; + +import lombok.Data; + +/** + * 退款模型 + * @className: RefundPriceModel + * @author: HuRui + * @date: 2022/10/28 + **/ +@Data +public class RefundPriceModel { + + // 退款成功 + private Boolean refundSuccess; + + // 退款订单号 + private String refundOrderNo; + + // 第三方退款订单号 + private String thirdPartyRefundOrderNo; + +} diff --git a/hai-service/src/main/java/com/hai/order/service/OrderRefundHandleService.java b/hai-service/src/main/java/com/hai/order/service/OrderRefundHandleService.java index 262a751c..d4a0c8f0 100644 --- a/hai-service/src/main/java/com/hai/order/service/OrderRefundHandleService.java +++ b/hai-service/src/main/java/com/hai/order/service/OrderRefundHandleService.java @@ -1,6 +1,7 @@ package com.hai.order.service; import com.hai.entity.HighChildOrder; +import com.hai.entity.HighOrderRefund; /** * 退款订单-业务处理 @@ -12,16 +13,16 @@ public interface OrderRefundHandleService { /** * 卡券业务 - * @param childOrder 子订单 + * @param orderRefund * @return * @throws Exception */ - void couponHandle(HighChildOrder childOrder) ; + void couponHandle(HighOrderRefund orderRefund) ; /** * 加油业务 - * @param childOrder + * @param orderRefund */ - void oilHandle(HighChildOrder childOrder) ; + void oilHandle(HighOrderRefund orderRefund) ; } diff --git a/hai-service/src/main/java/com/hai/order/service/OrderRefundService.java b/hai-service/src/main/java/com/hai/order/service/OrderRefundService.java index 1224482e..14666292 100644 --- a/hai-service/src/main/java/com/hai/order/service/OrderRefundService.java +++ b/hai-service/src/main/java/com/hai/order/service/OrderRefundService.java @@ -3,7 +3,10 @@ package com.hai.order.service; import com.hai.entity.HighChildOrder; import com.hai.entity.HighOrder; import com.hai.entity.HighOrderRefund; +import com.hai.order.model.RefundPriceModel; +import com.hai.order.type.OrderPayType; +import java.math.BigDecimal; import java.util.List; import java.util.Map; @@ -15,20 +18,37 @@ import java.util.Map; **/ public interface OrderRefundService { + /** + * 修改 + * @param orderRefund + */ + void update(HighOrderRefund orderRefund); + /** * 交易订单退款 * @param order 交易订单 * @param remarks 退款备注 */ - HighOrder createOrderRefund(HighOrder order, String remarks) throws Exception; + HighOrder createOrderRefund(String refundOrderNo,HighOrder order, String remarks) throws Exception; /** * 子订单退款 * @param orderChild 子订单 + * @param refundOrderNo 退款单号 * @param refundGoodsCount 退款商品数量 * @param remarks 退款备注 */ - HighOrderRefund createOrderChildRefund(HighChildOrder orderChild, String refundNo, Integer refundGoodsCount, String remarks) throws Exception; + HighOrderRefund createOrderChildRefund(HighChildOrder orderChild, String refundOrderNo, Integer refundGoodsCount, String remarks) throws Exception; + + /** + * 交易退钱 + * @param order + * @param orderPayType + * @param refundPrice + * @param refundIntegral + * @return + */ + RefundPriceModel refundPrice(String refundOrderNo, HighOrder order, OrderPayType orderPayType, BigDecimal refundPrice, Integer refundIntegral) throws Exception; /** * 获取退款订单列表 @@ -42,7 +62,7 @@ public interface OrderRefundService { * @param refundOrderNo * @return */ - HighOrderRefund getRefundByRefundNo(String refundOrderNo); + List getRefundByRefundNo(String refundOrderNo); } diff --git a/hai-service/src/main/java/com/hai/order/service/impl/OrderRefundHandleServiceImpl.java b/hai-service/src/main/java/com/hai/order/service/impl/OrderRefundHandleServiceImpl.java index d8475c51..6c4930a7 100644 --- a/hai-service/src/main/java/com/hai/order/service/impl/OrderRefundHandleServiceImpl.java +++ b/hai-service/src/main/java/com/hai/order/service/impl/OrderRefundHandleServiceImpl.java @@ -5,6 +5,7 @@ import com.hai.common.exception.ErrorHelp; import com.hai.common.exception.SysCode; import com.hai.entity.HighChildOrder; import com.hai.entity.HighGasOrder; +import com.hai.entity.HighOrderRefund; import com.hai.order.service.OrderRefundHandleService; import com.hai.order.type.OrderOilStatus; import com.hai.service.HighGasOrderService; @@ -25,21 +26,21 @@ public class OrderRefundHandleServiceImpl implements OrderRefundHandleService { private HighGasOrderService gasOrderService; @Override - public void couponHandle(HighChildOrder childOrder) { + public void couponHandle(HighOrderRefund orderRefund) { } @Override - public void oilHandle(HighChildOrder childOrder) { + public void oilHandle(HighOrderRefund orderRefund) { // 查询加油订单 - HighGasOrder gasOrder = gasOrderService.getDetailByChildOrderNo(childOrder.getChildOrderNo()); + HighGasOrder gasOrder = gasOrderService.getDetailByChildOrderNo(orderRefund.getOrderChildNo()); if (gasOrder == null) { throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "未找到加油订单"); } if (!gasOrder.getStatus().equals(OrderOilStatus.STATUS2.getNumber())) { throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "加油订单不处于已支付状态"); } - gasOrder.setRefundTime(childOrder.getRefundTime()); + gasOrder.setRefundTime(orderRefund.getRefundTime()); gasOrder.setStatus(OrderOilStatus.STATUS4.getNumber()); gasOrderService.updateGasOrder(gasOrder); } diff --git a/hai-service/src/main/java/com/hai/order/service/impl/OrderRefundServiceImpl.java b/hai-service/src/main/java/com/hai/order/service/impl/OrderRefundServiceImpl.java index 5e3bb0ba..05c97414 100644 --- a/hai-service/src/main/java/com/hai/order/service/impl/OrderRefundServiceImpl.java +++ b/hai-service/src/main/java/com/hai/order/service/impl/OrderRefundServiceImpl.java @@ -1,13 +1,20 @@ package com.hai.order.service.impl; +import com.alibaba.fastjson.JSONObject; import com.hai.common.exception.ErrorCode; import com.hai.common.exception.ErrorHelp; import com.hai.common.exception.SysCode; +import com.hai.common.utils.DateUtil; +import com.hai.config.HuiLianTongUnionCardConfig; +import com.hai.config.UnionPayConfig; +import com.hai.config.WxOrderConfig; import com.hai.dao.HighOrderRefundMapper; import com.hai.entity.HighChildOrder; import com.hai.entity.HighOrder; import com.hai.entity.HighOrderRefund; import com.hai.entity.HighOrderRefundExample; +import com.hai.model.OrderRefundModel; +import com.hai.order.model.RefundPriceModel; import com.hai.order.service.OrderRefundService; import com.hai.order.service.OrderService; import com.hai.order.type.OrderChildStatus; @@ -15,6 +22,7 @@ import com.hai.order.type.OrderPayType; import com.hai.order.type.OrderRefundStatus; import com.hai.order.type.OrderStatus; import com.hai.order.utils.OrderUtil; +import com.hai.service.HighOilCardService; import com.hai.service.HighUserService; import org.apache.commons.collections4.MapUtils; import org.apache.commons.lang3.StringUtils; @@ -22,6 +30,7 @@ import org.springframework.stereotype.Service; import javax.annotation.Resource; import java.math.BigDecimal; +import java.util.Calendar; import java.util.Date; import java.util.List; import java.util.Map; @@ -44,11 +53,19 @@ public class OrderRefundServiceImpl implements OrderRefundService { @Resource private OrderService orderService; + @Resource + private HighUserService highUserService; + + @Resource + private HighOilCardService oilCardService; + @Override - public HighOrder createOrderRefund(HighOrder order, String remarks) throws Exception { - // 退款订单号 - String refundOrderNo = OrderUtil.generateRefundOrderNo(); + public void update(HighOrderRefund orderRefund) { + orderRefundMapper.updateByPrimaryKey(orderRefund); + } + @Override + public HighOrder createOrderRefund(String refundOrderNo,HighOrder order, String remarks) throws Exception { for (HighChildOrder orderChild : order.getHighChildOrderList()) { // 创建退款记录 HighOrderRefund orderRefund = createOrderChildRefund(orderChild, refundOrderNo, orderChild.getSaleCount(), remarks); @@ -63,7 +80,7 @@ public class OrderRefundServiceImpl implements OrderRefundService { } @Override - public HighOrderRefund createOrderChildRefund(HighChildOrder orderChild,String refundNo,Integer refundGoodsCount, String remarks) throws Exception { + public HighOrderRefund createOrderChildRefund(HighChildOrder orderChild,String refundOrderNo,Integer refundGoodsCount, String remarks) throws Exception { if (!orderChild.getChildOrderStatus().equals(OrderChildStatus.STATUS2.getNumber()) && !orderChild.getChildOrderStatus().equals(OrderChildStatus.STATUS3.getNumber())){ throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "子订单状态错误"); @@ -92,7 +109,7 @@ public class OrderRefundServiceImpl implements OrderRefundService { orderRefund.setOrderChildId(orderChild.getId()); orderRefund.setOrderChildNo(orderChild.getChildOrderNo()); orderRefund.setMemId(orderChild.getMemId()); - orderRefund.setMemName(orderChild.getMemPhone()); + orderRefund.setMemName(orderChild.getMemName()); orderRefund.setMemPhone(orderChild.getMemPhone()); orderRefund.setGoodsType(orderChild.getGoodsType()); orderRefund.setGoodsId(orderChild.getGoodsId()); @@ -101,7 +118,7 @@ public class OrderRefundServiceImpl implements OrderRefundService { orderRefund.setGoodsImg(orderChild.getGoodsImg()); orderRefund.setGoodsSpecName(orderChild.getGoodsSpecName()); orderRefund.setGoodsCount(orderChild.getSaleCount()); - orderRefund.setRefundOrderNo(refundNo==null?OrderUtil.generateRefundOrderNo():refundNo); + orderRefund.setRefundOrderNo(refundOrderNo==null?OrderUtil.generateRefundOrderNo():refundOrderNo); orderRefund.setRefundGoodsNum(refundGoodsCount); orderRefund.setReturnTotalPrice(refundPrice.add(new BigDecimal(refundIntegral).divide(new BigDecimal("100")))); orderRefund.setRefundPrice(refundPrice); @@ -114,6 +131,85 @@ public class OrderRefundServiceImpl implements OrderRefundService { return orderRefund; } + @Override + public RefundPriceModel refundPrice(String refundOrderNo, HighOrder order, OrderPayType orderPayType, BigDecimal refundPrice, Integer refundIntegral) { + RefundPriceModel refundPriceModel = new RefundPriceModel(); + refundPriceModel.setRefundSuccess(false); + refundPriceModel.setRefundOrderNo(refundOrderNo); + try { + // 积分退款 + if (refundIntegral != null && refundIntegral > 0) { + String remark = "订单" + order.getOrderNo() + "退款,退还积分:" + refundIntegral; + // 积分退款 + highUserService.goldHandle(order.getMemId(), order.getPayGold(),1, 3, order.getId() , remark); + } + + // 第三方退款 + if (orderPayType.getNumber().equals(OrderPayType.PAY_TYPE2.getNumber())) { + // 微信退款 + OrderRefundModel orderRefundModel = WxOrderConfig.orderToRefund(order.getPaySerialNo(),order.getPayRealPrice(), order.getAccountMerchantNum(), refundPrice); + if(orderRefundModel.getResult_code().equals("SUCCESS")) { + refundPriceModel.setRefundSuccess(true); + refundPriceModel.setThirdPartyRefundOrderNo(orderRefundModel.getRefund_id()); + } + + } else if (orderPayType.getNumber().equals(OrderPayType.PAY_TYPE4.getNumber())) { + + JSONObject refund = HuiLianTongUnionCardConfig.refund(refundOrderNo, order.getPaySerialNo()); + if (!refund.getString("respCode").equals("0000")) { + throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR,refund.getString("respMessage")); + } + JSONObject consumptionResult = HuiLianTongUnionCardConfig.resolveResponse(refund.getString("data")); + if (consumptionResult.getBoolean("success") != true) { + throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "交易失败!"+consumptionResult.getString("message")); + } + refundPriceModel.setRefundSuccess(true); + refundPriceModel.setThirdPartyRefundOrderNo(consumptionResult.getString("orderId")); + + } else if (orderPayType.getNumber().equals(OrderPayType.PAY_TYPE5.getNumber())) { + Calendar startTime = Calendar.getInstance(); + startTime.set(Calendar.HOUR_OF_DAY, 00); + startTime.set(Calendar.MINUTE, 00); + startTime.set(Calendar.SECOND, 00); + + Calendar endTime = Calendar.getInstance(); + startTime.set(Calendar.HOUR_OF_DAY, 23); + startTime.set(Calendar.MINUTE, 59); + startTime.set(Calendar.SECOND, 59); + + // 订单是否处于当日的订单 + if (DateUtil.isEffectiveDate(order.getPayTime(), startTime.getTime(), endTime.getTime())) { + // 订单撤销 + JSONObject refund = UnionPayConfig.cancel(UnionPayConfig.MER_ID3, UnionPayConfig.TERM_ID3, order.getOrderNo(), order.getPaySerialNo()); + System.out.println(refund.toJSONString()); + if (!refund.getString("resultcode").equals("00") || !refund.getString("resultcode").equals("W6")) { + throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, refund.getString("returnmsg")); + } + refundPriceModel.setRefundSuccess(true); + } else { + // 订单退款 + JSONObject refund = UnionPayConfig.zwrefund(UnionPayConfig.MER_ID3, UnionPayConfig.TERM_ID3, order.getOrderNo(), order.getPaySerialNo(), order.getPayRealPrice().multiply(new BigDecimal("100")).longValue()); + System.out.println(refund.toJSONString()); + if (!refund.getString("resultcode").equals("00") || !refund.getString("resultcode").equals("W6")) { + JSONObject refund2 = UnionPayConfig.zwrefund(UnionPayConfig.MER_ID1, UnionPayConfig.TERM_ID1, order.getOrderNo(), order.getPaySerialNo(), order.getPayRealPrice().multiply(new BigDecimal("100")).longValue()); + if (!refund2.getString("resultcode").equals("00") || !refund.getString("resultcode").equals("W6")) { + throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, refund2.getString("returnmsg")); + } + } + refundPriceModel.setRefundSuccess(true); + } + } else if (orderPayType.getNumber().equals(OrderPayType.PAY_TYPE7.getNumber())) { + // 油卡退款 + oilCardService.refund(order.getOrderNo()); + refundPriceModel.setRefundSuccess(true); + } + + } catch (Exception e) { + refundPriceModel.setRefundSuccess(false); + } + return refundPriceModel; + } + @Override public List getRefundOrderList(Map param) { HighOrderRefundExample example = new HighOrderRefundExample(); @@ -171,23 +267,10 @@ public class OrderRefundServiceImpl implements OrderRefundService { } @Override - public HighOrderRefund getRefundByRefundNo(String refundOrderNo) { + public List getRefundByRefundNo(String refundOrderNo) { HighOrderRefundExample example = new HighOrderRefundExample(); example.createCriteria().andRefundOrderNoEqualTo(refundOrderNo); - List list = orderRefundMapper.selectByExample(example); - if (list.size() > 0) { - return list.get(0); - } - return null; + return orderRefundMapper.selectByExample(example); } - /** - * 金额退回用户 - * @param orderNo 订单号 - * @param refundPrice 退款金额 - * @param refundIntegral 退款积分 - */ - public void refundPrice(String orderNo,BigDecimal refundPrice,Integer refundIntegral) throws Exception { - - } } diff --git a/hai-service/src/main/java/com/hai/order/service/impl/OrderServiceImpl.java b/hai-service/src/main/java/com/hai/order/service/impl/OrderServiceImpl.java index d72fd392..f706a2ae 100644 --- a/hai-service/src/main/java/com/hai/order/service/impl/OrderServiceImpl.java +++ b/hai-service/src/main/java/com/hai/order/service/impl/OrderServiceImpl.java @@ -15,6 +15,7 @@ import com.hai.enum_type.DiscountUseScope; import com.hai.enum_type.OrderStatusEnum; import com.hai.order.model.CreateOrderChildModel; import com.hai.order.model.CreateOrderModel; +import com.hai.order.model.RefundPriceModel; import com.hai.order.service.*; import com.hai.order.topic.OrderTopic; import com.hai.order.type.*; @@ -511,18 +512,17 @@ public class OrderServiceImpl implements OrderService { throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "订单无法退款!"); } + // 退款订单号 + String refundOrderNo = OrderUtil.generateRefundOrderNo(); + // 创建退款 - order = orderRefundService.createOrderRefund(order, remarks); + order = orderRefundService.createOrderRefund(refundOrderNo, order, remarks); for (HighChildOrder childOrder : order.getHighChildOrderList()) { if (childOrder.getGiveawayType() == false) { childOrder.setRefundRemarks(remarks); childOrder.setRefundTime(new Date()); childOrder.setChildOrderStatus(OrderChildStatus.STATUS4.getNumber()); - - if (childOrder.getGoodsType().equals(OrderChildGoodsType.TYPE3.getNumber())) { - orderRefundHandleService.oilHandle(childOrder); - } } } @@ -532,8 +532,23 @@ public class OrderServiceImpl implements OrderService { order.setOrderStatus(OrderStatus.STATUS4.getNumber()); // todo 退款金额,原路返回 + RefundPriceModel refundPrice = orderRefundService.refundPrice(refundOrderNo + , order + , OrderPayType.getDataByType(order.getPayType()) + , order.getPayRealPrice() + , order.getPayGold()); + if (refundPrice.getRefundSuccess() == true) { + throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "退款失败,请稍后重试"); + } + List refundList = orderRefundService.getRefundByRefundNo(refundOrderNo); + for (HighOrderRefund orderRefund : refundList) { + orderRefund.setRefundStatus(OrderRefundStatus.STATUS2.getNumber()); + orderRefund.setRefundTime(new Date()); + orderRefundService.update(orderRefund); + rocketMQTemplate.syncSend(OrderTopic.ORDER_TOPIC_REFUND_SUCCESS.getTopic(), orderRefund); + } return updateOrderData(order); } @@ -565,6 +580,20 @@ public class OrderServiceImpl implements OrderService { } // todo 退款金额,原路返回 + RefundPriceModel refundPrice = orderRefundService.refundPrice(orderRefund.getRefundOrderNo() + , order + , OrderPayType.getDataByType(order.getPayType()) + , orderRefund.getRefundPrice() + , orderRefund.getRefundIntegral()); + if (!refundPrice.getRefundSuccess() == true) { + throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "退款失败,请稍后重试"); + } + + childOrderMapper.updateByPrimaryKey(orderChild); + + orderRefund.setRefundTime(new Date()); + orderRefund.setRefundStatus(OrderRefundStatus.STATUS2.getNumber()); + orderRefundService.update(orderRefund); // 购买的订单列表 @@ -591,6 +620,7 @@ public class OrderServiceImpl implements OrderService { order.setRefundTime(new Date()); order.setOrderStatus(OrderStatus.STATUS4.getNumber()); } + rocketMQTemplate.syncSend(OrderTopic.ORDER_TOPIC_REFUND_SUCCESS.getTopic(), orderRefund); return updateOrderData(order); } @@ -666,4 +696,5 @@ public class OrderServiceImpl implements OrderService { orderMapper.updateByPrimaryKey(highOrder); } } + } diff --git a/hai-service/src/main/java/com/hai/order/topic/OrderTopic.java b/hai-service/src/main/java/com/hai/order/topic/OrderTopic.java index a60635bd..93558014 100644 --- a/hai-service/src/main/java/com/hai/order/topic/OrderTopic.java +++ b/hai-service/src/main/java/com/hai/order/topic/OrderTopic.java @@ -9,6 +9,7 @@ package com.hai.order.topic; public enum OrderTopic { ORDER_TOPIC("order-topic", "订单主题"), ORDER_TOPIC_CANCEL(ORDER_TOPIC.getTopic() + ":cancel", "订单取消"), + ORDER_TOPIC_REFUND_SUCCESS(ORDER_TOPIC.getTopic() + ":refund-success", "订单退款成功业务"), ORDER_TOPIC_PROFIT_SHARING(ORDER_TOPIC.getTopic() + ":profit-sharing", "订单分账业务"), ;