diff --git a/bweb/src/main/java/com/bweb/controller/TestController.java b/bweb/src/main/java/com/bweb/controller/TestController.java index f75a5e5..db96b0d 100644 --- a/bweb/src/main/java/com/bweb/controller/TestController.java +++ b/bweb/src/main/java/com/bweb/controller/TestController.java @@ -8,6 +8,7 @@ import com.hfkj.config.CommonSysConst; import com.hfkj.model.ResponseData; +import com.hfkj.service.pay.huift.TradeService; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; import org.apache.commons.lang3.StringUtils; @@ -17,6 +18,7 @@ import org.slf4j.LoggerFactory; import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.*; +import javax.annotation.Resource; import java.util.*; @@ -25,7 +27,24 @@ import java.util.*; @Api(value="测试") public class TestController { private static Logger log = LoggerFactory.getLogger(TestController.class); + @Resource + private TradeService huiftTradeService; + @RequestMapping(value="/thirdPayResult",method = RequestMethod.GET) + @ResponseBody + @ApiOperation(value = "查询V家园订单交易状态") + public ResponseData thirdPayResult(@RequestParam(value = "preOrderNo" , required = true) String preOrderNo, + @RequestParam(value = "shopCode" , required = true) String shopCode, + @RequestParam(value = "signSecret" , required = true) String signSecret) { + try { + + return ResponseMsgUtil.success(huiftTradeService.thirdPayResult(preOrderNo,shopCode,signSecret)); + + } catch (Exception e) { + log.error("error!",e); + return ResponseMsgUtil.exception(e); + } + } @RequestMapping(value="/haiOilLogin",method = RequestMethod.POST) @ResponseBody diff --git a/order/src/main/java/com/order/controller/business/BsOrderMeiTuanController.java b/order/src/main/java/com/order/controller/business/BsOrderMeiTuanController.java index 3f4cd6d..23cb2e4 100644 --- a/order/src/main/java/com/order/controller/business/BsOrderMeiTuanController.java +++ b/order/src/main/java/com/order/controller/business/BsOrderMeiTuanController.java @@ -39,7 +39,7 @@ public class BsOrderMeiTuanController { try { // 查询配置的平台服务费 SecConfig config = secConfigService.queryDetail(platformCode); - BigDecimal servicePrice = new BigDecimal(0); + BigDecimal servicePrice; if (config == null) { log.error("orderMeiTuan -> servicePrice() error!"); diff --git a/order/src/main/java/com/order/controller/notify/MeiTuanController.java b/order/src/main/java/com/order/controller/notify/MeiTuanController.java index 1bbc55f..bff3c1a 100644 --- a/order/src/main/java/com/order/controller/notify/MeiTuanController.java +++ b/order/src/main/java/com/order/controller/notify/MeiTuanController.java @@ -7,8 +7,11 @@ import com.hfkj.common.exception.SysCode; import com.hfkj.common.utils.OrderUtil; import com.hfkj.config.CommonSysConst; import com.hfkj.entity.BsOrderMeituan; +import com.hfkj.entity.BsOrderRefund; import com.hfkj.meituan.MeiTuanService; import com.hfkj.service.goods.BsOrderMeiTuanService; +import com.hfkj.service.order.BsOrderRefundService; +import com.hfkj.service.order.BsOrderService; import com.hfkj.sysenum.order.OrderChildStatusEnum; import com.meituan.sqt.utils.EncryptUtil; import io.swagger.annotations.Api; @@ -32,6 +35,10 @@ public class MeiTuanController { @Resource private BsOrderMeiTuanService bsOrderMeiTuanService; + @Resource + private BsOrderRefundService orderRefundService; + @Resource + private BsOrderService orderService; private static Logger log = LoggerFactory.getLogger(MeiTuanService.class); @@ -115,6 +122,55 @@ public class MeiTuanController { } // 退款 if (Objects.equals(jsonObject.getString("method"), "trade.third.refund")) { + + BsOrderRefund orderRefund = orderRefundService.meiTuanRefund( + jsonObject.getString("tradeRefundNo") , + jsonObject.getString("tradeNo") , + jsonObject.getBigDecimal("refundAmount") , + "美团退款" + ); + // 美团退款订单 + JSONObject object = new JSONObject(); + object.put("thirdRefundNo" , orderRefund.getRefundOrderNo()); + log.info("美团关闭订单-参数: {}", object); + JSONObject data = new JSONObject(); + data.put("status", 0); + data.put("msg", "成功"); + data.put("data", EncryptUtil.aesEncrypt(object.toJSONString() , CommonSysConst.getSysConfig().getMtSecretKey())); + log.info("============回调任务End============="); + return data; + + } + // 交易关单 + if (Objects.equals(jsonObject.getString("method"), "trade.third.pay.close")) { + BsOrderMeituan orderMeiTuan = bsOrderMeiTuanService.findOrderMeiTuanByTradeNo(jsonObject.getString("tradeNo")); + + if (orderMeiTuan != null) { + if (orderMeiTuan.getStatus() == OrderChildStatusEnum.status1.getCode() || orderMeiTuan.getStatus() == OrderChildStatusEnum.status5.getCode()) { + + if (orderMeiTuan.getOrderNo() == null) { + orderMeiTuan.setCancelTime(new Date()); + orderMeiTuan.setStatus(OrderChildStatusEnum.status5.getCode()); + bsOrderMeiTuanService.update(orderMeiTuan); + } else { + orderService.cancel(orderMeiTuan.getOrderNo(), false); + } + + + // 美团查询订单 + JSONObject object = new JSONObject(); + object.put("tradeNo" , orderMeiTuan.getTradeNo()); + object.put("thirdTradeNo" , orderMeiTuan.getThirdTradeNo()); + log.info("美团关闭订单-参数: {}", object); + JSONObject data = new JSONObject(); + data.put("status", 0); + data.put("msg", "成功"); + data.put("data", EncryptUtil.aesEncrypt(object.toJSONString() , CommonSysConst.getSysConfig().getMtSecretKey())); + log.info("============回调任务End============="); + return data; + } + } + return null; } if (Objects.equals(jsonObject.getString("method"), "trade.third.pay.query")) { @@ -128,7 +184,6 @@ public class MeiTuanController { object.put("tradeTime" , "1970-01-01 00:00:00"); } else { object.put("tradeTime" , orderMeiTuan.getPayTime()); - } object.put("tradeAmount" , orderMeiTuan.getTradeAmount()); object.put("payStatus" , MeiTuanService.payStatus(orderMeiTuan.getStatus())); diff --git a/service/src/main/java/com/hfkj/service/order/BsOrderRefundService.java b/service/src/main/java/com/hfkj/service/order/BsOrderRefundService.java index 79b2a2a..250d3c4 100644 --- a/service/src/main/java/com/hfkj/service/order/BsOrderRefundService.java +++ b/service/src/main/java/com/hfkj/service/order/BsOrderRefundService.java @@ -44,13 +44,14 @@ public interface BsOrderRefundService { /** * @MethodName meiTuanRefund * @Description: 美团退款 - * @param childOrderNo + * @param tradeRefundNo * @param remark + * @param refundPrice * @return: com.hfkj.entity.BsOrderRefund * @Author: Sum1Dream * @Date: 2024/9/18 下午4:33 */ - BsOrderRefund meiTuanRefund(String childOrderNo, String tradeNo , BigDecimal refundPrice, String remark); + BsOrderRefund meiTuanRefund(String tradeRefundNo, String tradeNo , BigDecimal refundPrice, String remark); /** * 查询退款 @@ -58,6 +59,15 @@ public interface BsOrderRefundService { * @return */ BsOrderRefund getRefund(String refundOrderNo); + /** + * @MethodName getRefundByTradeRefundNo + * @Description: + * @param tradeRefundNo + * @return: com.hfkj.entity.BsOrderRefund + * @Author: Sum1Dream + * @Date: 2024/9/23 上午11:16 + */ + BsOrderRefund getRefundByTradeRefundNo(String tradeRefundNo); /** * 查询退款列表 * @param param diff --git a/service/src/main/java/com/hfkj/service/order/OrderCancelService.java b/service/src/main/java/com/hfkj/service/order/OrderCancelService.java index 9f0b154..4fedc1c 100644 --- a/service/src/main/java/com/hfkj/service/order/OrderCancelService.java +++ b/service/src/main/java/com/hfkj/service/order/OrderCancelService.java @@ -3,10 +3,12 @@ package com.hfkj.service.order; import com.hfkj.common.utils.RedisUtil; import com.hfkj.entity.BsOrderChild; import com.hfkj.entity.BsOrderCoupon; +import com.hfkj.entity.BsOrderMeituan; import com.hfkj.entity.GoodsMsg; import com.hfkj.model.order.OrderChildModel; import com.hfkj.model.order.OrderModel; import com.hfkj.service.coupon.BsOrderCouponService; +import com.hfkj.service.goods.BsOrderMeiTuanService; import com.hfkj.service.goods.GoodsMsgService; import com.hfkj.service.goods.GoodsSpecsService; import com.hfkj.sysenum.order.OrderChildProductTypeEnum; @@ -44,6 +46,8 @@ public class OrderCancelService { private GoodsMsgService goodsMsgService; @Resource private GoodsSpecsService goodsSpecsService; + @Resource + private BsOrderMeiTuanService bsOrderMeiTuanService; /** * 订单业务处理 * @param order @@ -55,6 +59,9 @@ public class OrderCancelService { if (childOrder.getProductType().equals(OrderChildProductTypeEnum.type2.getCode())) { product(childOrder); } + if (childOrder.getProductType().equals(OrderChildProductTypeEnum.type5.getCode())) { + meituan(childOrder); + } } } @@ -79,5 +86,15 @@ public class OrderCancelService { } } + // 美团订单取消 + public void meituan(OrderChildModel orderChild) { + // 查询产品 + BsOrderMeituan orderMeiTuan = bsOrderMeiTuanService.findOrderMeiTuan(orderChild.getChildOrderNo()); + + orderMeiTuan.setCancelTime(new Date()); + orderMeiTuan.setStatus(OrderChildStatusEnum.status5.getCode()); + bsOrderMeiTuanService.update(orderMeiTuan); + } + } diff --git a/service/src/main/java/com/hfkj/service/order/OrderRefundSuccessService.java b/service/src/main/java/com/hfkj/service/order/OrderRefundSuccessService.java index ecae015..35271d0 100644 --- a/service/src/main/java/com/hfkj/service/order/OrderRefundSuccessService.java +++ b/service/src/main/java/com/hfkj/service/order/OrderRefundSuccessService.java @@ -7,6 +7,7 @@ import com.hfkj.service.coupon.BsOrderCouponService; import com.hfkj.service.goods.BsOrderCinemaService; import com.hfkj.service.goods.BsOrderStarbucksService; import com.hfkj.service.goods.impl.BsOrderGoodsServiceImpl; +import com.hfkj.service.goods.impl.BsOrderMeiTuanServiceImpl; import com.hfkj.sysenum.order.OrderChildProductTypeEnum; import com.hfkj.sysenum.order.OrderChildStatusEnum; import org.springframework.beans.factory.annotation.Autowired; @@ -35,6 +36,8 @@ public class OrderRefundSuccessService { private BsOrderCouponService orderCouponService; @Resource private BsOrderStarbucksService bsOrderStarbucksService; + @Autowired + private BsOrderMeiTuanServiceImpl bsOrderMeiTuanService; /** * 订单业务处理 @@ -52,6 +55,9 @@ public class OrderRefundSuccessService { } else if (orderChild.getProductType().equals(OrderChildProductTypeEnum.type3.getCode())) { // 电影票退款业务 cinema(orderChild); + } else if (orderChild.getProductType().equals(OrderChildProductTypeEnum.type5.getCode())) { + // 美团退款业务 + meiTuan(orderChild); } } catch (Exception e) { System.out.println("========================================="); @@ -114,6 +120,36 @@ public class OrderRefundSuccessService { } + /** + * @MethodName meiTuan + * @Description: 美团退款 + * @param childOrder + * @Author: Sum1Dream + * @Date: 2024/9/23 下午2:04 + */ + public void meiTuan(BsOrderChild childOrder) { + // 美团退款 + BsOrderMeituan orderMeiTuan = bsOrderMeiTuanService.findOrderMeiTuan(childOrder.getOrderNo()); + + try { + + if (orderMeiTuan != null) { + Map map = new HashMap<>(); + map.put("orderNo", childOrder.getOrderNo()); + CinemaService.refundMovieOrder(map); + orderMeiTuan.setStatus(OrderChildStatusEnum.status4.getCode()); + orderMeiTuan.setRefundTime(new Date()); + orderMeiTuan.setExceptionStatus(false); + bsOrderMeiTuanService.update(orderMeiTuan); + } + } catch (Exception e) { + orderMeiTuan.setExceptionStatus(true); + orderMeiTuan.setExceptionMsg(e.getMessage()); + bsOrderMeiTuanService.update(orderMeiTuan); + } + + } + public void starbucks(BsOrderChild childOrder) { // 查询星巴克订单 BsOrderStarbucks orderStarbucks = bsOrderStarbucksService.findGoodsOrder(childOrder.getOrderNo()); diff --git a/service/src/main/java/com/hfkj/service/order/impl/BsOrderRefundServiceImpl.java b/service/src/main/java/com/hfkj/service/order/impl/BsOrderRefundServiceImpl.java index fc51ee7..bb9237f 100644 --- a/service/src/main/java/com/hfkj/service/order/impl/BsOrderRefundServiceImpl.java +++ b/service/src/main/java/com/hfkj/service/order/impl/BsOrderRefundServiceImpl.java @@ -12,6 +12,7 @@ import com.hfkj.entity.*; import com.hfkj.mer.BsMerPayConfigService; import com.hfkj.model.order.OrderChildModel; import com.hfkj.model.order.OrderModel; +import com.hfkj.service.goods.BsOrderMeiTuanService; import com.hfkj.service.hlt.HltCardRefundService; import com.hfkj.service.hlt.HuiLianTongUnionCardService; import com.hfkj.service.order.BsOrderChildService; @@ -35,6 +36,7 @@ import org.springframework.transaction.annotation.Transactional; import javax.annotation.Resource; import java.math.BigDecimal; +import java.math.RoundingMode; import java.util.*; import java.util.stream.Collectors; @@ -60,6 +62,8 @@ public class BsOrderRefundServiceImpl implements BsOrderRefundService { private HltCardRefundService hltCardRefundService; @Resource private OrderRefundSuccessService orderRefundSuccessService; + @Resource + private BsOrderMeiTuanService orderMeiTuanService; @Override public void editData(BsOrderRefund data) { data.setUpdateTime(new Date()); @@ -215,6 +219,7 @@ public class BsOrderRefundServiceImpl implements BsOrderRefundService { // 资金退款 orderRefund.setRefundStatus(refundMoney(orderRefund)?OrderRefundStatusEnum.status2.getCode():OrderRefundStatusEnum.status3.getCode()); + orderRefund.setFinishTime(orderRefund.getRefundStatus().equals(OrderRefundStatusEnum.status2.getCode())?new Date():null); editData(orderRefund); // 退款成功 @@ -248,16 +253,31 @@ public class BsOrderRefundServiceImpl implements BsOrderRefundService { @Override @Transactional(propagation= Propagation.REQUIRES_NEW,rollbackFor= {RuntimeException.class}) - public BsOrderRefund meiTuanRefund(String childOrderNo, String tradeNo , BigDecimal refundPrice, String remark) { + public BsOrderRefund meiTuanRefund(String tradeRefundNo, String tradeNo , BigDecimal refundPrice, String remark) { + + // 查询退款订 + BsOrderRefund bsOrderRefund = getRefundByTradeRefundNo(tradeRefundNo); + + if (bsOrderRefund != null) { + return bsOrderRefund; + } + + // 查询业务订单 + BsOrderMeituan orderMeiTuan = orderMeiTuanService.findOrderMeiTuanByTradeNo(tradeNo); + if (orderMeiTuan == null) { + throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "未知的业务订单"); + } // 查询子订单 - OrderChildModel orderChild = orderChildService.getDetail(childOrderNo); + OrderChildModel orderChild = orderChildService.getDetail(orderMeiTuan.getChildOrderNo()); if (orderChild == null) { throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "未知的子订单"); } -// if (productCount > orderChild.getSurplusRefundCount()) { -// throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "退款失败!退货数量超过子订单可退数量"); -// } + + if (orderChild.getStatus() != OrderChildStatusEnum.status2.getCode()) { + throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "当前状态不支持退款!"); + } + // 查询交易订单 BsOrder order = orderService.getOrder(orderChild.getOrderNo()); if (order == null) { @@ -268,6 +288,7 @@ public class BsOrderRefundServiceImpl implements BsOrderRefundService { BsOrderRefund orderRefund = new BsOrderRefund(); orderRefund.setMerId(orderChild.getMerId()); orderRefund.setOrderNo(orderChild.getOrderNo()); + orderRefund.setTradeRefundNo(tradeRefundNo); orderRefund.setOrderChildNo(orderChild.getChildOrderNo()); orderRefund.setUserId(order.getUserId()); orderRefund.setUserPhone(order.getUserPhone()); @@ -276,20 +297,39 @@ public class BsOrderRefundServiceImpl implements BsOrderRefundService { orderRefund.setRefundPayChannel(order.getPayChannel()); orderRefund.setReufndPayType(order.getPayType()); -// if (orderChild.getSurplusRefundCount().equals(productCount)) { -// // 全部退款 -// orderRefund.setRefundPrice(orderChild.getSurplusRefundPrice()); -// orderRefund.setRefundIntegral(orderChild.getSurplusRefundIntegral()); -// } else { -// // 部分退款 -// // 计算单价 -// BigDecimal unitPrice = orderChild.getSurplusRefundPrice().divide(new BigDecimal(orderChild.getProductCount().toString()), 2, BigDecimal.ROUND_DOWN).setScale(2); -// BigDecimal unitPriceIntegral = new BigDecimal(orderChild.getSurplusRefundIntegral().toString()).divide(new BigDecimal("100")) -// .divide(new BigDecimal(orderChild.getProductCount().toString()), 2, BigDecimal.ROUND_DOWN).setScale(2); -// -// orderRefund.setRefundPrice(unitPrice.multiply(new BigDecimal(productCount.toString()))); -// orderRefund.setRefundIntegral(unitPriceIntegral.multiply(new BigDecimal("100")).longValue()); -// } + // 是否全额退款 + if (orderMeiTuan.getTradeAmount().equals(refundPrice)) { + // 全部退款 + orderRefund.setRefundPrice(orderChild.getSurplusRefundPrice()); + orderRefund.setRefundIntegral(orderChild.getSurplusRefundIntegral()); + } else { + // 部分退款 + // 计算部分退款比例 + BigDecimal proportion = refundPrice.divide(orderChild.getProductTotalPrice() , 2 , RoundingMode.HALF_UP); + // 退积分 + Long unitPriceIntegral = new BigDecimal(orderChild.getIntegralDiscountPrice()).multiply(proportion).longValue(); + // 退金额 + BigDecimal price = orderChild.getProductActualPrice().multiply(proportion); + + if (price.compareTo(new BigDecimal("0.01")) < 0) { + price = new BigDecimal(0); + } + + // 插入退款积分 + if (unitPriceIntegral > orderChild.getSurplusRefundIntegral()) { + orderRefund.setRefundIntegral(orderChild.getSurplusRefundIntegral()); + } else { + orderRefund.setRefundIntegral(unitPriceIntegral); + } + // 插入退款金额 + if (price.compareTo(orderChild.getSurplusRefundPrice()) > 0) { + orderRefund.setRefundPrice(orderChild.getSurplusRefundPrice()); + } else { + orderRefund.setRefundPrice(price); + } + + } + if (orderRefund.getRefundIntegral() > 0L) { @@ -314,8 +354,15 @@ public class BsOrderRefundServiceImpl implements BsOrderRefundService { orderRefund.setAccountMerchantKey(orderChild.getSettleAccountKey()); editData(orderRefund); - // 资金退款 - orderRefund.setRefundStatus(refundMoney(orderRefund)?OrderRefundStatusEnum.status2.getCode():OrderRefundStatusEnum.status3.getCode()); + + + if (orderRefund.getRefundPrice().compareTo(new BigDecimal(0)) > 0) { + // 资金退款 + orderRefund.setRefundStatus(refundMoney(orderRefund)?OrderRefundStatusEnum.status2.getCode():OrderRefundStatusEnum.status3.getCode()); + } else { + orderRefund.setRefundStatus(OrderRefundStatusEnum.status2.getCode()); + } + editData(orderRefund); // 退款成功 @@ -358,6 +405,17 @@ public class BsOrderRefundServiceImpl implements BsOrderRefundService { return null; } + @Override + public BsOrderRefund getRefundByTradeRefundNo(String tradeRefundNo) { + BsOrderRefundExample example = new BsOrderRefundExample(); + example.createCriteria().andTradeRefundNoEqualTo(tradeRefundNo); + List list = orderRefundMapper.selectByExample(example); + if (!list.isEmpty()){ + return list.get(0); + } + return null; + } + @Override public List getRefundList(Map param) { BsOrderRefundExample example = new BsOrderRefundExample(); diff --git a/service/src/main/java/com/hfkj/service/order/impl/BsOrderServiceImpl.java b/service/src/main/java/com/hfkj/service/order/impl/BsOrderServiceImpl.java index e180b77..9d9a78f 100644 --- a/service/src/main/java/com/hfkj/service/order/impl/BsOrderServiceImpl.java +++ b/service/src/main/java/com/hfkj/service/order/impl/BsOrderServiceImpl.java @@ -524,7 +524,7 @@ public class BsOrderServiceImpl implements BsOrderService { // 删除缓存 cacheDelete(order.getOrderNo()); // 处理业务 - //orderPaySuccessService.orderBusHandle(order); + orderPaySuccessService.orderBusHandle(order); } @Override