diff --git a/cweb/src/main/java/com/cweb/controller/TestController.java b/cweb/src/main/java/com/cweb/controller/TestController.java index 65c82ed..12c2a56 100644 --- a/cweb/src/main/java/com/cweb/controller/TestController.java +++ b/cweb/src/main/java/com/cweb/controller/TestController.java @@ -494,14 +494,14 @@ public class TestController { // externalCustomerNos.add("8226900899900DB"); // externalCustomerNos.add("822690053310F6C"); - // return ResponseMsgUtil.success(saasActivityService.customerRegisterActivity("73", "315653022016", "110274",externalCustomerNos)); - // return ResponseMsgUtil.success(saasActivityService.referee("8226900445800HS")); + // return ResponseMsgUtil.success(saasActivityService.customerRegisterActivity("73", "315653011018", "110274",externalCustomerNos)); + // return ResponseMsgUtil.success(saasActivityService.referee(code)); /******* 配置活动费率 *******/ String activityId = "73"; String externalCustomerNo = code; JSONArray jsonArray = saasActivityService.queryCustomerRates(activityId, externalCustomerNo); return ResponseMsgUtil.success(jsonArray); - /*Map rate; +/* Map rate; List> rates = new ArrayList<>(); for (Object obj : jsonArray) { diff --git a/open-api/src/main/java/com/api/controller/v1/TradeProfitSharingController.java b/open-api/src/main/java/com/api/controller/v1/TradeProfitSharingController.java index 2624aed..cc30949 100644 --- a/open-api/src/main/java/com/api/controller/v1/TradeProfitSharingController.java +++ b/open-api/src/main/java/com/api/controller/v1/TradeProfitSharingController.java @@ -43,7 +43,7 @@ import java.util.Map; @Controller @Api(value = "交易订单") -@RequestMapping(value = "/v1/tradeProfitSharing") +@RequestMapping(value = "/v1/profitSharing") public class TradeProfitSharingController { private static Logger log = LoggerFactory.getLogger(TradeProfitSharingController.class); @@ -68,9 +68,9 @@ public class TradeProfitSharingController { log.info("请求参数:" + JSONObject.toJSONString(body)); try { // 验证签名 -/* if (!SignatureUtil.checkSign(body.getSign(), body, merKeyService.getKeyByMerNo(body.getMerchantNo()))) { + if (!SignatureUtil.checkSign(body.getSign(), body, merKeyService.getKeyByMerNo(body.getMerchantNo()))) { throw ErrorHelp.genException(SysCode.OpenApi, ErrorCode.OPEN_API_SIGN_ERR, ""); - }*/ + } if (body.getRecvDatas() == null || body.getRecvDatas().size() == 0) { throw ErrorHelp.genException(SysCode.OpenApi, ErrorCode.OPEN_API_COMMON, "未填写分账接收方"); } @@ -140,11 +140,9 @@ public class TradeProfitSharingController { log.info("请求参数:" + JSONObject.toJSONString(body)); try { // 验证签名 -/* if (!SignatureUtil.checkSign(body.getSign(), body, merKeyService.getKeyByMerNo(body.getMerchantNo()))) { throw ErrorHelp.genException(SysCode.OpenApi, ErrorCode.OPEN_API_SIGN_ERR, ""); } -*/ ResponseSeparateCancelModel responseSeparateCancelModel = openApiTradeOrderProfitSharingService.cancel(body); log.info("返回参数:" + JSONObject.toJSONString(responseSeparateCancelModel)); return ResponseMsgUtil.success(responseSeparateCancelModel); @@ -164,10 +162,10 @@ public class TradeProfitSharingController { log.info("========= Start 分账结果查询接口 Start ==========="); log.info("请求参数:" + JSONObject.toJSONString(body)); try { -/* // 验证签名 + // 验证签名 if (!SignatureUtil.checkSign(body.getSign(), body, merKeyService.getKeyByMerNo(body.getMerchantNo()))) { throw ErrorHelp.genException(SysCode.OpenApi, ErrorCode.OPEN_API_SIGN_ERR, ""); - }*/ + } ResponseSeparateQueryModel query = openApiTradeOrderProfitSharingService.query(body); log.info("返回参数:" + JSONObject.toJSONString(query)); @@ -189,11 +187,9 @@ public class TradeProfitSharingController { log.info("请求参数:" + JSONObject.toJSONString(body)); try { // 验证签名 -/* if (!SignatureUtil.checkSign(body.getSign(), body, merKeyService.getKeyByMerNo(body.getMerchantNo()))) { throw ErrorHelp.genException(SysCode.OpenApi, ErrorCode.OPEN_API_SIGN_ERR, ""); } -*/ ResponseSeparateQueryAmtModel responseSeparateQueryAmt = openApiTradeOrderProfitSharingService.queryAmt(body); log.info("返回参数:" + JSONObject.toJSONString(responseSeparateQueryAmt)); return ResponseMsgUtil.success(responseSeparateQueryAmt); diff --git a/service/src/main/java/com/hfkj/channel/lakala/LaKaLaTradeSeparateService.java b/service/src/main/java/com/hfkj/channel/lakala/LaKaLaTradeSeparateService.java index d50d674..103bc13 100644 --- a/service/src/main/java/com/hfkj/channel/lakala/LaKaLaTradeSeparateService.java +++ b/service/src/main/java/com/hfkj/channel/lakala/LaKaLaTradeSeparateService.java @@ -109,7 +109,7 @@ public class LaKaLaTradeSeparateService { } else if (statusCode.equals("FAIL")) { tradeOrderProfitSharing.setStatus(ProfitSharingStatusEnum.status4.getNumber()); } - tradeOrderProfitSharing.setProfitSharingOrderNo(respData.getString("separate_no")); + tradeOrderProfitSharing.setPlatformProfitSharingOrderNo(respData.getString("separate_no")); tradeOrderProfitSharingService.editData(tradeOrderProfitSharing); // 处理接收方数据 @@ -194,8 +194,9 @@ public class LaKaLaTradeSeparateService { throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, responseBody.getString("msg")); } tradeOrderProfitSharing.setStatus(ProfitSharingStatusEnum.status2.getNumber()); + tradeOrderProfitSharing.setPlatformProfitSharingOrderNo(responseBody.getJSONObject("resp_data").getString("separate_no")); tradeOrderProfitSharingService.editData(tradeOrderProfitSharing); - return responseBody; + return responseBody.getJSONObject("resp_data"); } /** diff --git a/service/src/main/java/com/hfkj/channel/saas/SaasActivityService.java b/service/src/main/java/com/hfkj/channel/saas/SaasActivityService.java index 80f1aaa..ad91a29 100644 --- a/service/src/main/java/com/hfkj/channel/saas/SaasActivityService.java +++ b/service/src/main/java/com/hfkj/channel/saas/SaasActivityService.java @@ -179,7 +179,7 @@ public class SaasActivityService { Map param = new HashMap<>(); param.put("externalCustomerNo", externalCustomerNo); param.put("nameOrJobNumber", 0); - param.put("page", 3); + param.put("page", 1); Map header = new HashMap<>(); header.put("Authorization", "Bearer " + saasCommon.getToken()); diff --git a/service/src/main/java/com/hfkj/openapi/v1/model/response/ResponseSeparateCancelModel.java b/service/src/main/java/com/hfkj/openapi/v1/model/response/ResponseSeparateCancelModel.java index 8393bec..b470a19 100644 --- a/service/src/main/java/com/hfkj/openapi/v1/model/response/ResponseSeparateCancelModel.java +++ b/service/src/main/java/com/hfkj/openapi/v1/model/response/ResponseSeparateCancelModel.java @@ -2,6 +2,8 @@ package com.hfkj.openapi.v1.model.response; import lombok.Data; +import java.math.BigDecimal; + /** * 请求分账 * @className: RequestSeparateModel @@ -11,11 +13,6 @@ import lombok.Data; @Data public class ResponseSeparateCancelModel { - /** - * 商户号 - */ - private String merchantNo; - /** * 分账流水号 */ @@ -26,10 +23,25 @@ public class ResponseSeparateCancelModel { */ private String separateNo; + /** + * 原商户分账指令流水号 + */ + private String originOutSeparateNo; + + /** + * 原分账指令流水 + */ + private String originSeparateNo; + + /** + * 状态 + */ + private Integer status; + /** * 撤销金额 */ - private String totalAmount; + private BigDecimal totalAmount; /** * 签名参数 diff --git a/service/src/main/java/com/hfkj/openapi/v1/model/response/ResponseSeparateQueryModel.java b/service/src/main/java/com/hfkj/openapi/v1/model/response/ResponseSeparateQueryModel.java index 4556813..e90c732 100644 --- a/service/src/main/java/com/hfkj/openapi/v1/model/response/ResponseSeparateQueryModel.java +++ b/service/src/main/java/com/hfkj/openapi/v1/model/response/ResponseSeparateQueryModel.java @@ -37,12 +37,12 @@ public class ResponseSeparateQueryModel { /** * 分账时间 */ - private Date separateDate; + private String createDate; /** * 完成时间 */ - private Date finishDate; + private String finishDate; /** * 金额 diff --git a/service/src/main/java/com/hfkj/openapi/v1/service/impl/OpenApiTradeOrderProfitSharingServiceImpl.java b/service/src/main/java/com/hfkj/openapi/v1/service/impl/OpenApiTradeOrderProfitSharingServiceImpl.java index 67bc9cc..2212f14 100644 --- a/service/src/main/java/com/hfkj/openapi/v1/service/impl/OpenApiTradeOrderProfitSharingServiceImpl.java +++ b/service/src/main/java/com/hfkj/openapi/v1/service/impl/OpenApiTradeOrderProfitSharingServiceImpl.java @@ -79,6 +79,7 @@ public class OpenApiTradeOrderProfitSharingServiceImpl implements OpenApiTradeOr tradeOrderProfitSharing.setPlatformTradeNo(tradeOrder.getPlatformTradeNo()); tradeOrderProfitSharing.setPlatformAppid(tradeOrder.getPlatformAppid()); tradeOrderProfitSharing.setProfitSharingAmoun(new BigDecimal(separateModel.getTotalAmount())); + tradeOrderProfitSharing.setProfitSharingTime(new Date()); tradeOrderProfitSharing.setStatus(ProfitSharingStatusEnum.status0.getNumber()); tradeOrderProfitSharing.setCreateType(TradeOrderProfitSharingCreateType.type2.getNumber()); tradeOrderProfitSharingService.editData(tradeOrderProfitSharing); @@ -93,6 +94,7 @@ public class OpenApiTradeOrderProfitSharingServiceImpl implements OpenApiTradeOr profitSharingReceiver.setProfitSharingAmount(tradeOrderProfitSharing.getProfitSharingAmoun()); profitSharingReceiver.setReceiverObjectType(ProfitSharingReceiverObjectType.mer.getType()); profitSharingReceiver.setReceiverObjectId(recvMer.getId().toString()); + profitSharingReceiver.setReceiverNo(recvMer.getMerNo()); profitSharingReceiver.setReceiverAccount(merLedger.getReceiverNo()); profitSharingReceiver.setReceiverName(recvMer.getMerName()); profitSharingReceiver.setReceiverAmount(new BigDecimal(recvData.getSeparateAmount())); @@ -116,29 +118,54 @@ public class OpenApiTradeOrderProfitSharingServiceImpl implements OpenApiTradeOr @Transactional(propagation= Propagation.REQUIRES_NEW, timeout = 20) public ResponseSeparateCancelModel cancel(RequestSeparateCancelModel separateCancelModel) throws Exception { // 查询分账流水号是否存在 - if (tradeOrderProfitSharingService.getDetailByProfitSharingOrderNo(separateCancelModel.getOriginOutSeparateNo()) != null) { - throw ErrorHelp.genException(SysCode.OpenApi, ErrorCode.OPEN_API_COMMON, "原分账指令流水号重复"); + BsTradeOrderProfitSharing originOutSeparate = tradeOrderProfitSharingService.getDetailByProfitSharingOrderNo(separateCancelModel.getOriginOutSeparateNo()); + if (originOutSeparate == null) { + throw ErrorHelp.genException(SysCode.OpenApi, ErrorCode.OPEN_API_COMMON, "原分账指令流水号不存在"); } - // 查询分账 - BsTradeOrderProfitSharing tradeOrderProfitSharing = tradeOrderProfitSharingService.getDetailByProfitSharingOrderNo(separateCancelModel.getOutSeparateNo()); - if (tradeOrderProfitSharing == null) { - throw ErrorHelp.genException(SysCode.OpenApi, ErrorCode.OPEN_API_COMMON, "未知的分商户分账指令"); + if (!originOutSeparate.getStatus().equals(ProfitSharingStatusEnum.status1.getNumber())) { + throw ErrorHelp.genException(SysCode.OpenApi, ErrorCode.OPEN_API_COMMON, "原分账状态错误"); + } + if (originOutSeparate.getProfitSharingAmoun().compareTo(new BigDecimal(separateCancelModel.getTotalAmount())) != 0) { + throw ErrorHelp.genException(SysCode.OpenApi, ErrorCode.OPEN_API_COMMON, "撤销金额与分账金额不一致"); + } + // 查询撤销分账指令流水号 + if (tradeOrderProfitSharingService.getDetailByProfitSharingOrderNo(separateCancelModel.getOutSeparateNo()) != null) { + throw ErrorHelp.genException(SysCode.OpenApi, ErrorCode.OPEN_API_COMMON, "商户分账指令流水号重复"); } - /*if (tradeOrderProfitSharing.getProfitSharingAmoun()) { - - }*/ // 交易订单 - BsTradeOrder tradeOrder = openApiTradeOrderService.getOrderByOutTradeNo(tradeOrderProfitSharing.getTradeOrderNo()); + BsTradeOrder tradeOrder = openApiTradeOrderService.getOrderByOutTradeNo(originOutSeparate.getTradeOrderNo()); if (tradeOrder == null) { - throw ErrorHelp.genException(SysCode.OpenApi, ErrorCode.OPEN_API_COMMON, "未知的商户分账指令"); + throw ErrorHelp.genException(SysCode.OpenApi, ErrorCode.OPEN_API_COMMON, "未知的商户指令"); } if (!separateCancelModel.getMerchantNo().equals(tradeOrder.getMerNo())) { - throw ErrorHelp.genException(SysCode.OpenApi, ErrorCode.OPEN_API_COMMON, "未知的商户分账指令"); + throw ErrorHelp.genException(SysCode.OpenApi, ErrorCode.OPEN_API_COMMON, "未知的商户指令"); } + BsTradeOrderProfitSharing profitSharingCmd = new BsTradeOrderProfitSharing(); + profitSharingCmd.setCmdType(ProfitSharingCmdTypeEnum.CMD_TYPE_2.getNumber()); + profitSharingCmd.setTradeOrderId(tradeOrder.getId()); + profitSharingCmd.setTradeOrderNo(tradeOrder.getOutTradeNo()); + profitSharingCmd.setOriginProfitSharingOrderNo(separateCancelModel.getOriginOutSeparateNo()); + profitSharingCmd.setProfitSharingOrderNo(separateCancelModel.getOutSeparateNo()); + profitSharingCmd.setPlatformType(tradeOrder.getPlatformType()); + profitSharingCmd.setPlatformMerNo(tradeOrder.getPlatformMerNo()); + profitSharingCmd.setPlatformTradeNo(tradeOrder.getPlatformTradeNo()); + profitSharingCmd.setPlatformAppid(tradeOrder.getPlatformAppid()); + profitSharingCmd.setProfitSharingAmoun(new BigDecimal(separateCancelModel.getTotalAmount())); + profitSharingCmd.setProfitSharingTime(new Date()); + profitSharingCmd.setStatus(ProfitSharingStatusEnum.status2.getNumber()); + profitSharingCmd.setCreateType(TradeOrderProfitSharingCreateType.type2.getNumber()); + tradeOrderProfitSharingService.editData(profitSharingCmd); - // laKaLaTradeSeparateService.cancel(); + // 调用第三方 + JSONObject responseCancel = laKaLaTradeSeparateService.cancel(separateCancelModel.getOutSeparateNo()); ResponseSeparateCancelModel responseSeparateCancel = new ResponseSeparateCancelModel(); + responseSeparateCancel.setSeparateNo(responseCancel.getString("separate_no")); + responseSeparateCancel.setOutSeparateNo(profitSharingCmd.getProfitSharingOrderNo()); + responseSeparateCancel.setOriginSeparateNo(originOutSeparate.getPlatformProfitSharingOrderNo()); + responseSeparateCancel.setOriginOutSeparateNo(originOutSeparate.getProfitSharingOrderNo()); + responseSeparateCancel.setStatus(profitSharingCmd.getStatus()); + responseSeparateCancel.setTotalAmount(profitSharingCmd.getProfitSharingAmoun()); responseSeparateCancel.setSign(SignatureUtil.createSign(separateCancelModel, merKeyService.getKeyByMerNo(separateCancelModel.getMerchantNo()))); return responseSeparateCancel; } @@ -157,27 +184,66 @@ public class OpenApiTradeOrderProfitSharingServiceImpl implements OpenApiTradeOr } if (!separateQueryModel.getMerchantNo().equals(tradeOrder.getMerNo())) { throw ErrorHelp.genException(SysCode.OpenApi, ErrorCode.OPEN_API_COMMON, "未知的分账流水号"); - }/* - // 第三方接口查询 - JSONObject queryProfitSharing = laKaLaTradeSeparateService.query(separateQueryModel.getOutSeparateNo());*/ + } + // 第三方接口查询,防止未及时更新 + if (!tradeOrderProfitSharing.getStatus().equals(ProfitSharingStatusEnum.status1.getNumber())) { + JSONObject queryProfitSharing = laKaLaTradeSeparateService.query(separateQueryModel.getOutSeparateNo()); + if (queryProfitSharing.getString("status").equals("SUCCESS")) { + tradeOrderProfitSharing.setFinishTime(new Date()); + tradeOrderProfitSharing.setStatus(ProfitSharingStatusEnum.status1.getNumber()); + tradeOrderProfitSharingService.editData(tradeOrderProfitSharing); + + // 修改接收方状态 + List receiverList = tradeOrderProfitSharingReceiverService.getReceiverListByProfitSharingId(tradeOrderProfitSharing.getId()); + for (BsTradeOrderProfitSharingReceiver receiver : receiverList) { + receiver.setStatus(ProfitSharingReceiverStatusEnum.status1.getNumber()); + tradeOrderProfitSharingReceiverService.editData(receiver); + } + } + } ResponseSeparateQueryModel responseSeparateQueryModel = new ResponseSeparateQueryModel(); responseSeparateQueryModel.setCmdType(tradeOrderProfitSharing.getCmdType()); responseSeparateQueryModel.setOutSeparateNo(tradeOrderProfitSharing.getProfitSharingOrderNo()); responseSeparateQueryModel.setSeparateNo(tradeOrderProfitSharing.getPlatformProfitSharingOrderNo()); - responseSeparateQueryModel.setSeparateDate(tradeOrderProfitSharing.getProfitSharingTime()); - responseSeparateQueryModel.setFinishDate(tradeOrderProfitSharing.getFinishTime()); + + responseSeparateQueryModel.setCreateDate( + tradeOrderProfitSharing.getProfitSharingTime()!=null? + DateUtil.date2String(tradeOrderProfitSharing.getProfitSharingTime(), "yyyyMMdd") + : null); + + responseSeparateQueryModel.setFinishDate( + tradeOrderProfitSharing.getFinishTime()!=null? + DateUtil.date2String(tradeOrderProfitSharing.getFinishTime(), "yyyyMMdd") + : null); + responseSeparateQueryModel.setTotalAmount(tradeOrderProfitSharing.getProfitSharingAmoun()); responseSeparateQueryModel.setStatus(tradeOrderProfitSharing.getStatus()); // 接收方 List recvDataList = new ArrayList<>(); - List receiverList = tradeOrderProfitSharingReceiverService.getReceiverListByProfitSharingId(tradeOrderProfitSharing.getId()); - for (BsTradeOrderProfitSharingReceiver receiver : receiverList) { - ResponseSeparateQueryModel.ResponseSeparateRecvDataModel recvData = new ResponseSeparateQueryModel.ResponseSeparateRecvDataModel(); - recvData.setRecvMerchantNo(receiver.getReceiverNo()); - recvData.setSeparateAmount(receiver.getReceiverAmount()); - recvDataList.add(recvData); + if (tradeOrderProfitSharing.getCmdType().equals(ProfitSharingCmdTypeEnum.CMD_TYPE_1.getNumber())) { + List receiverList = tradeOrderProfitSharingReceiverService.getReceiverListByProfitSharingId(tradeOrderProfitSharing.getId()); + for (BsTradeOrderProfitSharingReceiver receiver : receiverList) { + ResponseSeparateQueryModel.ResponseSeparateRecvDataModel recvData = new ResponseSeparateQueryModel.ResponseSeparateRecvDataModel(); + recvData.setRecvMerchantNo(receiver.getReceiverNo()); + recvData.setSeparateAmount(receiver.getReceiverAmount()); + recvDataList.add(recvData); + } + } else if (tradeOrderProfitSharing.getCmdType().equals(ProfitSharingCmdTypeEnum.CMD_TYPE_2.getNumber())) { + // 原分账流水 + BsTradeOrderProfitSharing originOutSeparate = tradeOrderProfitSharingService.getDetailByProfitSharingOrderNo(tradeOrderProfitSharing.getOriginProfitSharingOrderNo()); + if (originOutSeparate == null) { + throw ErrorHelp.genException(SysCode.OpenApi, ErrorCode.OPEN_API_COMMON, "未知的原分账指令流水号"); + } + List receiverList = tradeOrderProfitSharingReceiverService.getReceiverListByProfitSharingId(originOutSeparate.getId()); + for (BsTradeOrderProfitSharingReceiver receiver : receiverList) { + ResponseSeparateQueryModel.ResponseSeparateRecvDataModel recvData = new ResponseSeparateQueryModel.ResponseSeparateRecvDataModel(); + recvData.setRecvMerchantNo(receiver.getReceiverNo()); + recvData.setSeparateAmount(receiver.getReceiverAmount()); + recvDataList.add(recvData); + } } + responseSeparateQueryModel.setRecvDataList(recvDataList); responseSeparateQueryModel.setSign(SignatureUtil.createSign(responseSeparateQueryModel, merKeyService.getKeyByMerNo(separateQueryModel.getMerchantNo()))); return responseSeparateQueryModel; diff --git a/service/src/main/java/com/hfkj/openapi/v1/utils/SignatureUtil.java b/service/src/main/java/com/hfkj/openapi/v1/utils/SignatureUtil.java index bf3d5b2..f4d66ea 100644 --- a/service/src/main/java/com/hfkj/openapi/v1/utils/SignatureUtil.java +++ b/service/src/main/java/com/hfkj/openapi/v1/utils/SignatureUtil.java @@ -83,8 +83,7 @@ public class SignatureUtil { public static void main(String[] args) throws Exception { String paramStr = "{\n" + " \"merchantNo\": \"2023030909414450700\",\n" + - " \"billDateS\": 1684568344000,\n" + - " \"billDateE\": 1685008407667\n" + + " \"outSeparateNo\": \"1530202304261720503943170005\"" + "}"; String sign = createSign(JSONObject.parseObject(paramStr), "LRL9uflTQGeyp9yVWDD6orhBp2VhYDvP"); System.out.println(sign); diff --git a/service/src/main/java/com/hfkj/service/impl/BsTradeOrderRefundServiceImpl.java b/service/src/main/java/com/hfkj/service/impl/BsTradeOrderRefundServiceImpl.java index 409ad5c..cac529e 100644 --- a/service/src/main/java/com/hfkj/service/impl/BsTradeOrderRefundServiceImpl.java +++ b/service/src/main/java/com/hfkj/service/impl/BsTradeOrderRefundServiceImpl.java @@ -72,11 +72,11 @@ public class BsTradeOrderRefundServiceImpl implements BsTradeOrderRefundService if (tradeOrder == null) { throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "未知的交易订单"); } - if (StringUtils.isNotBlank(tradeOrder.getUserPhone())) { +/* if (StringUtils.isNotBlank(tradeOrder.getUserPhone())) { if (HsgIntegralService.recycleIntegral(tradeOrder.getId().toString(),tradeOrder.getOutTradeNo()).equals(false)) { throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "用户积分不足,暂时无法退款"); } - } + }*/ editOrderRefund(tradeOrderRefund);