diff --git a/cweb/src/main/java/com/cweb/controller/BsStoreDiscountActivityPartakeUserController.java b/cweb/src/main/java/com/cweb/controller/BsStoreDiscountActivityPartakeUserController.java index 404c989..d00c253 100644 --- a/cweb/src/main/java/com/cweb/controller/BsStoreDiscountActivityPartakeUserController.java +++ b/cweb/src/main/java/com/cweb/controller/BsStoreDiscountActivityPartakeUserController.java @@ -65,16 +65,18 @@ public class BsStoreDiscountActivityPartakeUserController { @RequestParam(value = "type" , required = true) Integer type, @RequestParam(value = "systemType" , required = true) Integer systemType) { try { - System.out.println("outTradeNo="+outTradeNo+"&qrCodeSn="+"&type="+type+"&systemType="+systemType); + + BsTradeOrder tradeNo = tradeOrderService.getOrderByOutTradeNoOrPlatformTradeNo(outTradeNo); + if (tradeNo == null) { + throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "未知的订单"); + } + System.out.println("outTradeNo="+tradeNo.getOutTradeNo()+"&qrCodeSn="+"&type="+type+"&systemType="+systemType); JSONObject response = HttpsUtils.doGet(CommonSysConst.getSysConfig().getHsg_domain_name() + "/v1/wxMsg/getWxToken"); if (StringUtils.isBlank(response.getString("return_data"))) { throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "获取token失败"); } - BsTradeOrder tradeNo = tradeOrderService.getOrderByOutTradeNo(outTradeNo); - if (tradeNo == null) { - throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "未知的订单"); - } + String param = outTradeNo; String fileUrl = "/share/" + System.currentTimeMillis() + ".png"; // type 生成类型 diff --git a/cweb/src/main/java/com/cweb/controller/TestController.java b/cweb/src/main/java/com/cweb/controller/TestController.java index a2a509c..b6093b7 100644 --- a/cweb/src/main/java/com/cweb/controller/TestController.java +++ b/cweb/src/main/java/com/cweb/controller/TestController.java @@ -156,8 +156,8 @@ public class TestController { // soundService.sendPayMsg("898604A2192181729951", new BigDecimal("12.99")); - soundService.geSoundInfo("898604A2192181729951"); - return ResponseMsgUtil.success(""); + // soundService.geSoundInfo("898604A2192181729951"); + return ResponseMsgUtil.success(tradeOrderService.getOrderByOutTradeNoOrPlatformTradeNo("ZF1130202304261716539211335407")); // soundService.geSoundDetail("898604A2192181729951"); // return ResponseMsgUtil.success(AlipayRequest.imageUpload("C:/Users/hurui/Desktop/default_oil_station.jpg")); @@ -270,15 +270,13 @@ public class TestController { Map mapPost = new HashMap<>(); mapPost.put("apiKey" , "0C7897EA3BD96156A5881618FF2FF645"); mapPost.put("merchId" , "20230258302"); - mapPost.put("productType" , 102); + mapPost.put("productType" , 102); // 101 普通支付 102 商家活动差价返利 mapPost.put("orderNo" , orderNo); - mapPost.put("userId" , 366); + mapPost.put("phone" , 366); mapPost.put("orderId" , orderId); mapPost.put("price" , price); mapPost.put("title" , "南充大饭店"); mapPost.put("createTime" , new Date()); - - mapPost.put("sign" , WxUtils.generateSignApi(mapPost, MapUtils.getString(mapPost, "apiKey"), WXPayConstants.SignType.MD5)); return ResponseMsgUtil.success(HttpsUtils.doPost("http://localhost:9902/v1/orderRebate/rebate" , mapPost , new HashMap<>())); } catch (Exception e) { diff --git a/service/src/main/java/com/hfkj/channel/hsg/HsgIntegralService.java b/service/src/main/java/com/hfkj/channel/hsg/HsgIntegralService.java new file mode 100644 index 0000000..0611866 --- /dev/null +++ b/service/src/main/java/com/hfkj/channel/hsg/HsgIntegralService.java @@ -0,0 +1,78 @@ +package com.hfkj.channel.hsg; + +import com.alibaba.fastjson.JSONObject; +import com.hfkj.channel.hsg.config.HsgConfig; +import com.hfkj.channel.hsg.type.RebateProductTypeEnum; +import com.hfkj.channel.weixin.utils.WxUtils; +import com.hfkj.channel.weixin.utils.sdk.WXPayConstants; +import com.hfkj.common.exception.ErrorCode; +import com.hfkj.common.exception.ErrorHelp; +import com.hfkj.common.exception.SysCode; +import com.hfkj.common.utils.HttpsUtils; +import com.hfkj.common.utils.ResponseMsgUtil; +import org.apache.commons.collections4.MapUtils; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.math.BigDecimal; +import java.util.Date; +import java.util.HashMap; +import java.util.Map; + +/** + * @className: HsgService + * @author: HuRui + * @date: 2023/4/27 + **/ +public class HsgIntegralService { + + private static Logger log = LoggerFactory.getLogger(HsgIntegralService.class); + + /** + * 返利 + * @param productType + * @param phone + * @param orderNo + * @param orderId + * @param price + * @param storeName + * @param createTime + * @return + * @throws Exception + */ + public static Boolean rebate(RebateProductTypeEnum productType, + String phone, + String orderNo, + Long orderId, + BigDecimal price, + String storeName, + Date createTime) { + + try { + Map mapPost = new HashMap<>(); + mapPost.put("apiKey" , HsgConfig.apiKey); + mapPost.put("merchId" , HsgConfig.merchId); + mapPost.put("productType" , productType.getNumber()); // 101 普通支付 102 商家活动差价返利 + mapPost.put("orderNo" , orderNo); + mapPost.put("phone" , phone); + mapPost.put("orderId" , orderId); + mapPost.put("price" , price); + mapPost.put("title" , storeName); + mapPost.put("createTime" , createTime); + mapPost.put("sign" , WxUtils.generateSignApi(mapPost, MapUtils.getString(mapPost, "apiKey"), WXPayConstants.SignType.MD5)); + JSONObject response = HttpsUtils.doPost(HsgConfig.hsgDomainName+"v1/orderRebate/rebate", mapPost, new HashMap<>()); + System.out.println(response); + if (response == null) { + throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "请求超时"); + } + if (!response.getString("return_code").equals("000000")) { + throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, response.getString("return_msg")); + } + return true; + } catch (Exception e) { + return false; + } + } + + +} diff --git a/service/src/main/java/com/hfkj/channel/hsg/config/HsgConfig.java b/service/src/main/java/com/hfkj/channel/hsg/config/HsgConfig.java new file mode 100644 index 0000000..b15317c --- /dev/null +++ b/service/src/main/java/com/hfkj/channel/hsg/config/HsgConfig.java @@ -0,0 +1,17 @@ +package com.hfkj.channel.hsg.config; + +import com.hfkj.config.CommonSysConst; + +/** + * @className: HsgConfig + * @author: HuRui + * @date: 2023/4/27 + **/ +public class HsgConfig { + + public final static String apiKey = "0C7897EA3BD96156A5881618FF2FF645"; + + public final static String merchId = "20230258302"; + public final static String hsgDomainName = CommonSysConst.getSysConfig().getHsg_domain_name(); + +} diff --git a/service/src/main/java/com/hfkj/channel/hsg/type/RebateProductTypeEnum.java b/service/src/main/java/com/hfkj/channel/hsg/type/RebateProductTypeEnum.java new file mode 100644 index 0000000..1e41e57 --- /dev/null +++ b/service/src/main/java/com/hfkj/channel/hsg/type/RebateProductTypeEnum.java @@ -0,0 +1,35 @@ +package com.hfkj.channel.hsg.type; + +/** + * + */ +public enum RebateProductTypeEnum { + type1(101, "普通支付"), + type2(102, "商家活动差价返利"), + ; + + private Integer number; + + private String name; + + RebateProductTypeEnum(int number, String name) { + this.number = number; + this.name = name; + } + + public Integer getNumber() { + return number; + } + + public void setNumber(Integer number) { + this.number = number; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } +} diff --git a/service/src/main/java/com/hfkj/channel/lakala/LaKaLaTradeService.java b/service/src/main/java/com/hfkj/channel/lakala/LaKaLaTradeService.java index f52771f..3194b26 100644 --- a/service/src/main/java/com/hfkj/channel/lakala/LaKaLaTradeService.java +++ b/service/src/main/java/com/hfkj/channel/lakala/LaKaLaTradeService.java @@ -46,6 +46,13 @@ public class LaKaLaTradeService { @Resource private BsMerPlatformNoRateService merPlatformNoRateService; + @Resource + private LaKaLaTradeSeparateService laKaLaTradeSeparateService; + + @Resource + private BsTradeOrderProfitSharingService tradeOrderProfitSharingService; + + /** * 交易【被扫】 * @param tradeNo 订单号 @@ -317,7 +324,16 @@ public class LaKaLaTradeService { orderMsg.setRequestContent(JSONObject.toJSONString(requestMap)); tradeOrderMsgService.editTradeOrderMsg(orderMsg); - // 请求拉卡拉接口 + // 是否分账 + if (order.getProfitSharingStatus().equals(true)) { + // 查询分账记录 + BsTradeOrderProfitSharing tradeOrderProfitSharing = tradeOrderProfitSharingService.getProfitSharingByTradeOrderId(ProfitSharingCmdTypeEnum.CMD_TYPE_1, order.getId()); + if (tradeOrderProfitSharing != null) { + laKaLaTradeSeparateService.cancel(tradeOrderProfitSharing.getProfitSharingOrderNo()); + } + } + + // 请求拉卡拉退款接口 JSONObject responseBody = HttpsUtils.doPost(CommonSysConst.getSysConfig().getLkl_request_url() + "/api/v3/labs/relation/refund", commonParam, heard); orderMsg.setResponseContent(responseBody.toJSONString()); tradeOrderMsgService.editTradeOrderMsg(orderMsg); diff --git a/service/src/main/java/com/hfkj/service/BsTradeOrderProfitSharingService.java b/service/src/main/java/com/hfkj/service/BsTradeOrderProfitSharingService.java index 4c9ab6a..f7f77e3 100644 --- a/service/src/main/java/com/hfkj/service/BsTradeOrderProfitSharingService.java +++ b/service/src/main/java/com/hfkj/service/BsTradeOrderProfitSharingService.java @@ -2,6 +2,7 @@ package com.hfkj.service; import com.hfkj.entity.BsTradeOrder; import com.hfkj.entity.BsTradeOrderProfitSharing; +import com.hfkj.sysenum.ProfitSharingCmdTypeEnum; import java.util.List; @@ -25,6 +26,8 @@ public interface BsTradeOrderProfitSharingService { */ void createProfitSharing(BsTradeOrder tradeOrder); + BsTradeOrderProfitSharing getProfitSharingByTradeOrderId(ProfitSharingCmdTypeEnum profitSharingCmdType,Long tradeOrderId); + /** * 根据分账单号 查询详情 * @param profitSharingOrderNo diff --git a/service/src/main/java/com/hfkj/service/BsTradeOrderService.java b/service/src/main/java/com/hfkj/service/BsTradeOrderService.java index 43c171b..3d3e241 100644 --- a/service/src/main/java/com/hfkj/service/BsTradeOrderService.java +++ b/service/src/main/java/com/hfkj/service/BsTradeOrderService.java @@ -48,6 +48,8 @@ public interface BsTradeOrderService { */ BsTradeOrder getOrderByOutTradeNo(String tradeNo); + BsTradeOrder getOrderByOutTradeNoOrPlatformTradeNo(String tradeNo); + /** * 根据交易订单id,查询 * @param tradeOrderId diff --git a/service/src/main/java/com/hfkj/service/impl/BsTradeOrderProfitSharingServiceImpl.java b/service/src/main/java/com/hfkj/service/impl/BsTradeOrderProfitSharingServiceImpl.java index 4ca88f8..8027388 100644 --- a/service/src/main/java/com/hfkj/service/impl/BsTradeOrderProfitSharingServiceImpl.java +++ b/service/src/main/java/com/hfkj/service/impl/BsTradeOrderProfitSharingServiceImpl.java @@ -388,6 +388,20 @@ public class BsTradeOrderProfitSharingServiceImpl implements BsTradeOrderProfitS } } + @Override + public BsTradeOrderProfitSharing getProfitSharingByTradeOrderId(ProfitSharingCmdTypeEnum profitSharingCmdType, Long tradeOrderId) { + BsTradeOrderProfitSharingExample example = new BsTradeOrderProfitSharingExample(); + BsTradeOrderProfitSharingExample.Criteria criteria = example.createCriteria() + .andCmdTypeEqualTo(profitSharingCmdType.getNumber()) + .andTradeOrderIdEqualTo(tradeOrderId); + + List list = tradeOrderProfitSharingMapper.selectByExample(example); + if (list.size() > 0) { + return list.get(0); + } + return null; + } + @Override public BsTradeOrderProfitSharing getDetailByProfitSharingOrderNo(String profitSharingOrderNo) { BsTradeOrderProfitSharingExample example = new BsTradeOrderProfitSharingExample(); diff --git a/service/src/main/java/com/hfkj/service/impl/BsTradeOrderServiceImpl.java b/service/src/main/java/com/hfkj/service/impl/BsTradeOrderServiceImpl.java index 9d723cc..d17da18 100644 --- a/service/src/main/java/com/hfkj/service/impl/BsTradeOrderServiceImpl.java +++ b/service/src/main/java/com/hfkj/service/impl/BsTradeOrderServiceImpl.java @@ -1,6 +1,8 @@ package com.hfkj.service.impl; import com.alibaba.fastjson.JSONObject; +import com.hfkj.channel.hsg.HsgIntegralService; +import com.hfkj.channel.hsg.type.RebateProductTypeEnum; import com.hfkj.common.exception.ErrorCode; import com.hfkj.common.exception.ErrorHelp; import com.hfkj.common.exception.SysCode; @@ -232,6 +234,15 @@ public class BsTradeOrderServiceImpl implements BsTradeOrderService { } if (tradeOrder.getStoreDiscountId() != null && StringUtils.isNotBlank(tradeOrder.getUserPhone())) { + // 支付返积分 + HsgIntegralService.rebate(RebateProductTypeEnum.type2, + tradeOrder.getUserPhone(), + tradeOrder.getOutTradeNo(), + tradeOrder.getId(), + tradeOrder.getStoreDiscountActualPrice(), + tradeOrder.getStoreName(), + tradeOrder.getCreateTime()); + BsStoreDiscountActivityPartakeUser partakeUser = discountActivityPartakeUserService.getPartakeUser(tradeOrder.getUserPhone(), tradeOrder.getStoreDiscountId()); if (partakeUser != null) { partakeUser.setPartakeSurplusNum(partakeUser.getPartakeSurplusNum() - 1); @@ -262,6 +273,18 @@ public class BsTradeOrderServiceImpl implements BsTradeOrderService { return null; } + @Override + public BsTradeOrder getOrderByOutTradeNoOrPlatformTradeNo(String tradeNo) { + BsTradeOrderExample example = new BsTradeOrderExample(); + example.createCriteria().andOutTradeNoEqualTo(tradeNo); + example.or().andPlatformTradeNoEqualTo(tradeNo); + List list = tradeOrderMapper.selectByExample(example); + if (list.size() > 0) { + return list.get(0); + } + return null; + } + @Override public BsTradeOrder getOrderByTradeNoId(Long tradeOrderId) { return tradeOrderMapper.selectByPrimaryKey(tradeOrderId);