diff --git a/cweb/src/main/java/com/cweb/controller/TestController.java b/cweb/src/main/java/com/cweb/controller/TestController.java index e725e4c..a2a509c 100644 --- a/cweb/src/main/java/com/cweb/controller/TestController.java +++ b/cweb/src/main/java/com/cweb/controller/TestController.java @@ -9,6 +9,8 @@ import com.alipay.api.response.AlipaySystemOauthTokenResponse; import com.hfkj.channel.alipay.utils.AlipayRequest; import com.hfkj.channel.alipay.utils.AlipayUtils; import com.hfkj.channel.lakala.LaKaLaLedgerService; +import com.hfkj.channel.lakala.LaKaLaMerService; +import com.hfkj.channel.lakala.LaKaLaTradeSeparateService; import com.hfkj.channel.lakala.LaKaLaTradeService; import com.hfkj.channel.lakala.config.LaKaLaConfig; import com.hfkj.channel.saas.SaasMerService; @@ -73,6 +75,9 @@ public class TestController { @Resource private LaKaLaTradeService laKaLaTradeService; + @Resource + private LaKaLaTradeSeparateService laKaLaTradeSeparateService; + @Resource private CommonService commonService; @@ -80,7 +85,8 @@ public class TestController { private BsLklMccService lklMccService; @Resource private LaKaLaLedgerService laKaLaLedgerService; - + @Resource + private LaKaLaMerService laKaLaMerService; @Resource private BsTradeOrderService tradeOrderService; @Resource @@ -93,7 +99,7 @@ public class TestController { try { // return ResponseMsgUtil.success(LaKaLaConfig.queryCardBin("3100020709200056842")); - return ResponseMsgUtil.success(saasCommon.getToken()); + return ResponseMsgUtil.success(LaKaLaConfig.uploadFile("", "", "")); } catch (Exception e) { log.error(e.getMessage(), e); @@ -111,8 +117,11 @@ public class TestController { // return ResponseMsgUtil.success(saasCommon.getArea("1")); // return ResponseMsgUtil.success(saasCommon.getBank("6530", "大坪支行")); - tradeOrderProfitSharingService.createProfitSharing(tradeOrderService.getOrderByOutTradeNo("")); - return ResponseMsgUtil.success(""); + // tradeOrderProfitSharingService.createProfitSharing(tradeOrderService.getOrderByOutTradeNo("ZF1130202304261043149211335400")); + // laKaLaLedgerService.queryLedgerMer("8226900481608NL"); + //laKaLaTradeSeparateService.separate("1530202304261049572195600000"); + // tradeOrderProfitSharingService.createProfitSharing(tradeOrderService.getOrderByOutTradeNo("ZF1130202304261734049211335408")); + return ResponseMsgUtil.success(laKaLaTradeSeparateService.fallback("153020230426173509288272000001")); // return ResponseMsgUtil.success(""); // 1200 // return ResponseMsgUtil.success(saasCommon.fileUpload(new HashMap<>())); diff --git a/cweb/src/main/java/com/cweb/notify/LaKaLaController.java b/cweb/src/main/java/com/cweb/notify/LaKaLaController.java index e24789b..537b9b2 100644 --- a/cweb/src/main/java/com/cweb/notify/LaKaLaController.java +++ b/cweb/src/main/java/com/cweb/notify/LaKaLaController.java @@ -19,6 +19,8 @@ import javax.annotation.Resource; import javax.servlet.http.HttpServletResponse; import java.io.BufferedOutputStream; import java.math.BigDecimal; +import java.util.HashMap; +import java.util.Map; /** @@ -67,13 +69,19 @@ public class LaKaLaController { // 查询订单 BsTradeOrder order = tradeOrderService.getOrderByOutTradeNo(body.getString("out_trade_no")); if (order != null) { + Map other = new HashMap<>(); + other.put("log_no", body.getString("log_no")); + other.put("acc_trade_no", body.getString("acc_trade_no")); + other.put("card_type", body.getString("card_type")); + tradeOrderService.paySuccess( body.getString("out_trade_no"), body.getString("trade_no"), PlatformTypeEnum.type1, TradeOrderPayModeEnum.getNameByCode(body.getString("account_type")), body.getBigDecimal("payer_amount").divide(new BigDecimal("100")), - body.getString("settle_merchant_no") + body.getString("merchant_no"), + other ); /* order.setPayMode(body.getString("account_type")); @@ -94,17 +102,22 @@ public class LaKaLaController { tradeOrderService.editOrder(order);*/ } - BufferedOutputStream out = new BufferedOutputStream(response.getOutputStream()); - JSONObject result = new JSONObject(); - result.put("code", "SUCCESS"); - result.put("message", "执行成功"); - out.write(result.toJSONString().getBytes()); - out.flush(); - out.close(); } catch (Exception e) { log.error("login error!",e); - } + } finally { + try { + BufferedOutputStream out = new BufferedOutputStream(response.getOutputStream()); + JSONObject result = new JSONObject(); + result.put("code", "SUCCESS"); + result.put("message", "执行成功"); + out.write(result.toJSONString().getBytes()); + out.flush(); + out.close(); + } catch (Exception e) { + } + + } } @RequestMapping(value="/applyLedgerMer",method = RequestMethod.POST) diff --git a/cweb/src/main/java/com/cweb/notify/WeiXinController.java b/cweb/src/main/java/com/cweb/notify/WeiXinController.java index 15f23c2..598d949 100644 --- a/cweb/src/main/java/com/cweb/notify/WeiXinController.java +++ b/cweb/src/main/java/com/cweb/notify/WeiXinController.java @@ -84,7 +84,8 @@ public class WeiXinController { PlatformTypeEnum.type4, TradeOrderPayModeEnum.WECHAT, new BigDecimal(map.get("total_fee")).divide(new BigDecimal("100")), - map.get("sub_mch_id")); + map.get("sub_mch_id"), + new HashMap<>()); } BufferedOutputStream out = new BufferedOutputStream(response.getOutputStream()); out.write(resXml.getBytes()); diff --git a/service/src/main/java/com/hfkj/channel/lakala/LaKaLaLedgerService.java b/service/src/main/java/com/hfkj/channel/lakala/LaKaLaLedgerService.java index 7694654..dbb3fdd 100644 --- a/service/src/main/java/com/hfkj/channel/lakala/LaKaLaLedgerService.java +++ b/service/src/main/java/com/hfkj/channel/lakala/LaKaLaLedgerService.java @@ -112,6 +112,65 @@ public class LaKaLaLedgerService { return responseBody; } + public JSONObject updateLedger(Long merLedgerId) { + BsMerLedger merLedger = merLedgerService.getMerLedgerById(merLedgerId); + if (merLedger == null || !merLedger.getPlatformType().equals(PlatformTypeEnum.type1.getNumber())) { + throw ErrorHelp.genException(SysCode.System, ErrorCode.REQ_PARAMS_ERROR, ""); + } + // 商户 + MerBasisModel merDetail = merService.getMerDetail(merLedger.getMerId()); + if (merDetail == null) { + throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "未找到商户"); + } + + Map commonParam = new HashMap<>(); + commonParam.put("reqTime", DateUtil.format(new Date(), "yyyyMMddHHmmss")); + commonParam.put("version", "1.0.0"); + commonParam.put("reqId", UnionUtils.createNonceStr()); + + String orderNo = System.currentTimeMillis()+""; + Map map = new HashMap<>(); + map.put("version", "1.0"); + map.put("orderNo", orderNo); + map.put("orgCode", "1"); + map.put("receiverNo", merLedger.getReceiverNo()); + map.put("merCupNo", merLedger.getCupNo()); + map.put("contactMobile", merDetail.getRegPhone()); + map.put("splitLowestRatio", merLedger.getSplitLowestRatio()); + map.put("splitEntrustFileName", merLedger.getSplitEntrustFileName()); + // 转换成bas64 + String base64ImgUrl = ImageUtils.getBase64ByImgUrl(CommonSysConst.getSysConfig().getObs_url()+merLedger.getSplitEntrustFilePath()); + String fileType = merLedger.getSplitEntrustFilePath().substring(merLedger.getSplitEntrustFilePath().lastIndexOf(".") + 1); + map.put("splitEntrustFilePath", LaKaLaConfig.uploadFile("COOPERATION_QUALIFICATION_PROOF", fileType, base64ImgUrl).getString("attFileId")); + map.put("splitRange", "MARK"); + map.put("retUrl", CommonSysConst.getSysConfig().getDomainName() + "/crest/laKaLaNotify/applyLedgerMer"); + commonParam.put("reqData", map); + + Map reqParam = LaKaLaConfig.generateSignParamsV2(JSONObject.parseObject(JSONObject.toJSONString(commonParam))); + // 头部参数 + Map heard = new HashMap<>(); + heard.put("Authorization", reqParam.get("Authorization")); + + // 请求记录 + Map requestMap = new HashMap<>(); + requestMap.put("Authorization", reqParam.get("Authorization")); + requestMap.put("req_data", JSONObject.toJSONString(commonParam)); + + BsMerLedgerApply merLedgerApply = new BsMerLedgerApply(); + merLedgerApply.setMerLedgerId(merLedger.getId()); + merLedgerApply.setMerId(merLedger.getId()); + merLedgerApply.setOrderNo(orderNo); + merLedgerApply.setRequestBody(JSONObject.toJSONString(requestMap)); + + JSONObject responseBody = HttpsUtils.doPost(CommonSysConst.getSysConfig().getLkl_request_url() + "/api/v2/mms/openApi/ledger/modifyLedgerReceiver", commonParam, heard); + System.out.println("body:" + JSONObject.toJSONString(commonParam)); + System.out.println("response:" + responseBody.toJSONString()); + if (!responseBody.getString("retCode").equals("000000")) { + throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, responseBody.getString("retMsg")); + } + return responseBody; + } + /** * 商户分账信息变更申请 * @param merLedgerId @@ -234,16 +293,16 @@ public class LaKaLaLedgerService { map.put("orgCode", "1"); map.put("receiverName", merDetail.getMerName()); map.put("contactMobile", merDetail.getRegPhone()); - map.put("acctTypeCode", merDetail.getMerType().equals(MerSettleType.status1.getNumber())?57:58);// 57:对公 58:对私 + map.put("acctTypeCode", merDetail.getMerSettleAcct().getSettleType().equals(MerSettleType.status1.getNumber())?57:58);// 57:对公 58:对私 map.put("acctNo", merDetail.getMerSettleAcct().getBankCardNo()); - map.put("acctName", merDetail.getMerSettleAcct().getBankCardHolder()); + map.put("acctName", merDetail.getMerSettleAcct().getSettleType().equals(MerSettleType.status1.getNumber())?merDetail.getBlisName():merDetail.getMerSettleAcct().getBankCardHolder()); map.put("acctCertificateType", "17"); map.put("acctCertificateNo", merDetail.getMerSettleAcct().getSettleIdCardNo()); map.put("acctOpenBankCode", merDetail.getMerSettleAcct().getOpenningBankCode()); map.put("acctOpenBankName", merDetail.getMerSettleAcct().getOpenningBankName()); map.put("acctClearBankCode", merDetail.getMerSettleAcct().getClearingBankCode()); - if (merDetail.getMerType().equals(MerSettleType.status1.getNumber()) == true) { + if (merDetail.getMerSettleAcct().getSettleType().equals(MerSettleType.status1.getNumber()) == true) { map.put("licenseNo", merDetail.getBlisNo()); map.put("licenseName", merDetail.getBlisName()); map.put("legalPersonName", merDetail.getLarName()); @@ -271,7 +330,7 @@ public class LaKaLaLedgerService { } } } - map.put("attachList", attachMapList); + map.put("attachList", attachMapList); commonParam.put("reqData", map); Map reqParam = LaKaLaConfig.generateSignParamsV2(JSONObject.parseObject(JSONObject.toJSONString(commonParam))); @@ -294,6 +353,76 @@ public class LaKaLaLedgerService { } } + /** + * 创建分账接收方 + */ + public void updateLedgerReceiver(Long merId) { + // 商户 + MerBasisModel merDetail = merService.getMerDetail(merId); + if (merDetail == null) { + throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "未找到商户"); + } + Map commonParam = new HashMap<>(); + commonParam.put("reqTime", DateUtil.format(new Date(), "yyyyMMddHHmmss")); + commonParam.put("version", "1.0.0"); + commonParam.put("reqId", UnionUtils.createNonceStr()); + + Map map = new HashMap<>(); + map.put("version", "1.0"); + map.put("orderNo", System.currentTimeMillis()+""); + map.put("orgCode", "1"); + map.put("receiverNo", "1"); + map.put("receiverName", merDetail.getMerName()); + map.put("contactMobile", merDetail.getRegPhone()); + map.put("acctNo", merDetail.getMerSettleAcct().getBankCardNo()); + map.put("acctTypeCode", merDetail.getMerSettleAcct().getSettleType().equals(MerSettleType.status1.getNumber())?57:58);// 57:对公 58:对私 + map.put("acctOpenBankCode", merDetail.getMerSettleAcct().getOpenningBankCode()); + map.put("acctOpenBankName", merDetail.getMerSettleAcct().getOpenningBankName()); + map.put("acctClearBankCode", merDetail.getMerSettleAcct().getClearingBankCode()); + + List> attachMapList = new ArrayList<>(); + Map attachMap; + + List attachList = merAttachService.getAttachListByMer(merId, PlatformTypeEnum.type0, null); + for (BsMerAttach attach : attachList) { + if (StringUtils.isNotBlank(attach.getFileUrl())) { + MerAttachType attachType = MerAttachType.getDataByNumber(attach.getType()); + if (attachType != null && StringUtils.isNotBlank(attachType.getLklCode())) { + attachMap = new HashMap<>(); + + // 转换成bas64 + String base64ImgUrl = ImageUtils.getBase64ByImgUrl(CommonSysConst.getSysConfig().getObs_url()+"/"+attach.getFileUrl()); + String fileType = attach.getFileUrl().substring(attach.getFileUrl().lastIndexOf(".") + 1); + attachMap.put("attachType", attachType.getLklCode()); + attachMap.put("attachName", attachType.getName()); + attachMap.put("attachStorePath", LaKaLaConfig.uploadFile(attachType.getLklSaasCode(), fileType, base64ImgUrl).getString("attFileId")); + attachMapList.add(attachMap); + } + } + } + map.put("attachList", attachMapList); + commonParam.put("reqData", map); + + Map reqParam = LaKaLaConfig.generateSignParamsV2(JSONObject.parseObject(JSONObject.toJSONString(commonParam))); + // 头部参数 + Map heard = new HashMap<>(); + heard.put("Authorization", reqParam.get("Authorization")); + + JSONObject responseBody = HttpsUtils.doPost(CommonSysConst.getSysConfig().getLkl_request_url() + "/api/v2/mms/openApi/ledger/modifyLedgerReceiver", commonParam, heard); + System.out.println("body:" + JSONObject.toJSONString(commonParam)); + System.out.println("response:" + responseBody.toJSONString()); + if (!responseBody.getString("retCode").equals("000000")) { + throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, responseBody.getString("retMsg")); + } + + // 查询分账信息 + BsMerLedger merLedger = merLedgerService.getMerLedger(merId, PlatformTypeEnum.type1); + if (merLedger != null) { + merLedger.setReceiverNo(responseBody.getJSONObject("respData").getString("receiverNo")); + merLedgerService.editMerLedger(merLedger); + } + } + /** * 绑定分账关系 */ 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 b644e05..1382725 100644 --- a/service/src/main/java/com/hfkj/channel/lakala/LaKaLaTradeSeparateService.java +++ b/service/src/main/java/com/hfkj/channel/lakala/LaKaLaTradeSeparateService.java @@ -18,6 +18,7 @@ import org.apache.commons.lang3.StringUtils; import org.springframework.stereotype.Service; import javax.annotation.Resource; +import java.math.BigDecimal; import java.util.*; /** @@ -45,7 +46,7 @@ public class LaKaLaTradeSeparateService { if (null == tradeOrderProfitSharing) { throw ErrorHelp.genException(SysCode.System, ErrorCode.REQ_PARAMS_ERROR, "未找到交易分账记录"); } - if (tradeOrderProfitSharing.getStatus().equals(ProfitSharingStatusEnum.status0.getNumber())) { + if (!tradeOrderProfitSharing.getStatus().equals(ProfitSharingStatusEnum.status0.getNumber())) { throw ErrorHelp.genException(SysCode.System, ErrorCode.REQ_PARAMS_ERROR, "业务不处于待处理状态"); } // 查询交易详情 @@ -61,9 +62,9 @@ public class LaKaLaTradeSeparateService { Map map = new HashMap<>(); map.put("merchant_no", tradeOrder.getPlatformMerNo()); map.put("log_no", tradeOrder.getPlatformLogNo()); - map.put("log_date", DateUtil.date2String(tradeOrder.getPayTime(), "yyyy-MM-dd")); + map.put("log_date", DateUtil.date2String(tradeOrder.getPayTime(), "yyyyMMdd")); map.put("out_separate_no", tradeOrderProfitSharing.getProfitSharingOrderNo()); - map.put("total_amt", tradeOrderProfitSharing.getProfitSharingAmoun()); + map.put("total_amt", tradeOrderProfitSharing.getProfitSharingAmoun().multiply(new BigDecimal("100")).longValue()); map.put("lkl_org_no", "1"); map.put("cal_type", "0"); @@ -72,14 +73,14 @@ public class LaKaLaTradeSeparateService { for (BsTradeOrderProfitSharingReceiver receiver : profitSharingReceiverList) { recvDatasMap = new HashMap<>(); - recvDatasMap.put("recv_merchant_no", receiver.getReceiverAccount()); - recvDatasMap.put("separate_value", receiver.getProfitSharingAmount()); + recvDatasMap.put("recv_no", receiver.getReceiverAccount()); + recvDatasMap.put("separate_value", receiver.getReceiverAmount().multiply(new BigDecimal("100")).longValue()); recvDatasMapList.add(recvDatasMap); } - commonParam.put("recv_datas", recvDatasMapList); - commonParam.put("reqData", map); + map.put("recv_datas", recvDatasMapList); + commonParam.put("req_data", map); - Map reqParam = LaKaLaConfig.generateSignParamsV2(JSONObject.parseObject(JSONObject.toJSONString(commonParam))); + Map reqParam = LaKaLaConfig.generateSignParamsV3(JSONObject.parseObject(JSONObject.toJSONString(commonParam))); // 头部参数 Map heard = new HashMap<>(); heard.put("Authorization", reqParam.get("Authorization")); @@ -88,7 +89,7 @@ public class LaKaLaTradeSeparateService { System.out.println("body:" + JSONObject.toJSONString(commonParam)); System.out.println("response:" + responseBody.toJSONString()); - if (!responseBody.getString("retCode").equals("000000")) { + if (!responseBody.getString("code").equals("SACS0000")) { throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, responseBody.getString("retMsg")); } @@ -121,6 +122,41 @@ public class LaKaLaTradeSeparateService { return responseBody; } + public JSONObject queryAmt(String profitSharingOrderNo) { + // 交易订单分账 + BsTradeOrderProfitSharing tradeOrderProfitSharing = tradeOrderProfitSharingService.getDetailByProfitSharingOrderNo(profitSharingOrderNo); + if (null == tradeOrderProfitSharing) { + throw ErrorHelp.genException(SysCode.System, ErrorCode.REQ_PARAMS_ERROR, "未找到交易分账记录"); + } + // 查询交易详情 + BsTradeOrder tradeOrder = tradeOrderService.getOrderByTradeNoId(tradeOrderProfitSharing.getTradeOrderId()); + + Map commonParam = new HashMap<>(); + commonParam.put("req_time", DateUtil.format(new Date(), "yyyyMMddHHmmss")); + commonParam.put("version", "3.0"); + + Map map = new HashMap<>(); + map.put("merchant_no", tradeOrderProfitSharing.getPlatformMerNo()); + map.put("log_no", tradeOrder.getPlatformLogNo()); + map.put("log_date", DateUtil.date2String(tradeOrder.getPayTime(), "yyyyMMdd")); + commonParam.put("req_data", map); + + Map reqParam = LaKaLaConfig.generateSignParamsV3(JSONObject.parseObject(JSONObject.toJSONString(commonParam))); + // 头部参数 + Map heard = new HashMap<>(); + heard.put("Authorization", reqParam.get("Authorization")); + + JSONObject responseBody = HttpsUtils.doPost(CommonSysConst.getSysConfig().getLkl_request_url() + "/api/v3/sacs/queryAmt", commonParam, heard); + System.out.println("body:" + JSONObject.toJSONString(commonParam)); + System.out.println("response:" + responseBody.toJSONString()); + if (!responseBody.getString("code").equals("SACS0000")) { + throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, responseBody.getString("msg")); + } + tradeOrderProfitSharing.setStatus(ProfitSharingStatusEnum.status2.getNumber()); + tradeOrderProfitSharingService.editData(tradeOrderProfitSharing); + return responseBody; + } + /** * 分账撤销 * @param profitSharingOrderNo @@ -132,22 +168,18 @@ public class LaKaLaTradeSeparateService { if (null == tradeOrderProfitSharing) { throw ErrorHelp.genException(SysCode.System, ErrorCode.REQ_PARAMS_ERROR, "未找到交易分账记录"); } - if (tradeOrderProfitSharing.getStatus().equals(ProfitSharingStatusEnum.status0.getNumber())) { - throw ErrorHelp.genException(SysCode.System, ErrorCode.REQ_PARAMS_ERROR, "业务不处于待处理状态"); - } - Map commonParam = new HashMap<>(); commonParam.put("req_time", DateUtil.format(new Date(), "yyyyMMddHHmmss")); commonParam.put("version", "3.0"); Map map = new HashMap<>(); map.put("merchant_no", tradeOrderProfitSharing.getPlatformMerNo()); - map.put("origin_separate_no", tradeOrderProfitSharing.getOriginProfitSharingOrderNo()); - map.put("out_separate_no", tradeOrderProfitSharing.getProfitSharingOrderNo()); - map.put("total_amt", tradeOrderProfitSharing.getProfitSharingAmoun()); - commonParam.put("reqData", map); + map.put("origin_out_separate_no", tradeOrderProfitSharing.getProfitSharingOrderNo()); + map.put("out_separate_no", tradeOrderProfitSharing.getProfitSharingOrderNo()+"1"); + map.put("total_amt", tradeOrderProfitSharing.getProfitSharingAmoun().multiply(new BigDecimal("100")).longValue()); + commonParam.put("req_data", map); - Map reqParam = LaKaLaConfig.generateSignParamsV2(JSONObject.parseObject(JSONObject.toJSONString(commonParam))); + Map reqParam = LaKaLaConfig.generateSignParamsV3(JSONObject.parseObject(JSONObject.toJSONString(commonParam))); // 头部参数 Map heard = new HashMap<>(); heard.put("Authorization", reqParam.get("Authorization")); @@ -155,8 +187,8 @@ public class LaKaLaTradeSeparateService { JSONObject responseBody = HttpsUtils.doPost(CommonSysConst.getSysConfig().getLkl_request_url() + "/api/v3/sacs/cancel", commonParam, heard); System.out.println("body:" + JSONObject.toJSONString(commonParam)); System.out.println("response:" + responseBody.toJSONString()); - if (!responseBody.getString("retCode").equals("000000")) { - throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, responseBody.getString("retMsg")); + if (!responseBody.getString("code").equals("SACS0000")) { + throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, responseBody.getString("msg")); } tradeOrderProfitSharing.setStatus(ProfitSharingStatusEnum.status2.getNumber()); tradeOrderProfitSharingService.editData(tradeOrderProfitSharing); @@ -164,6 +196,7 @@ public class LaKaLaTradeSeparateService { } /** + * todo 目前未开发,目前的场景用不到 * 分账回退 * @param profitSharingOrderNo 交易订单号 * @return @@ -174,9 +207,6 @@ public class LaKaLaTradeSeparateService { if (null == tradeOrderProfitSharing) { throw ErrorHelp.genException(SysCode.System, ErrorCode.REQ_PARAMS_ERROR, "未找到交易分账记录"); } - if (tradeOrderProfitSharing.getStatus().equals(ProfitSharingStatusEnum.status0.getNumber())) { - throw ErrorHelp.genException(SysCode.System, ErrorCode.REQ_PARAMS_ERROR, "业务不处于待处理状态"); - } Map commonParam = new HashMap<>(); commonParam.put("req_time", DateUtil.format(new Date(), "yyyyMMddHHmmss")); @@ -184,12 +214,20 @@ public class LaKaLaTradeSeparateService { Map map = new HashMap<>(); map.put("merchant_no", tradeOrderProfitSharing.getPlatformMerNo()); - map.put("origin_separate_no", tradeOrderProfitSharing.getOriginProfitSharingOrderNo()); - map.put("out_separate_no", tradeOrderProfitSharing.getProfitSharingOrderNo()); - map.put("total_amt", tradeOrderProfitSharing.getProfitSharingAmoun()); - commonParam.put("reqData", map); - - Map reqParam = LaKaLaConfig.generateSignParamsV2(JSONObject.parseObject(JSONObject.toJSONString(commonParam))); + map.put("origin_out_separate_no", tradeOrderProfitSharing.getProfitSharingOrderNo()); + map.put("out_separate_no", tradeOrderProfitSharing.getProfitSharingOrderNo()+"1"); + map.put("total_amt", "24"); + + // 回退分账金额,只能回退一个商户 + List> originRecvDatas = new ArrayList<>(); + Map originRecv = new HashMap<>(); + originRecv.put("recv_no", "SR2023042415050"); + originRecv.put("amt", "24"); + originRecvDatas.add(originRecv); + map.put("origin_recv_datas", originRecvDatas); + commonParam.put("req_data", map); + + Map reqParam = LaKaLaConfig.generateSignParamsV3(JSONObject.parseObject(JSONObject.toJSONString(commonParam))); // 头部参数 Map heard = new HashMap<>(); heard.put("Authorization", reqParam.get("Authorization")); @@ -197,8 +235,8 @@ public class LaKaLaTradeSeparateService { JSONObject responseBody = HttpsUtils.doPost(CommonSysConst.getSysConfig().getLkl_request_url() + "/api/v3/sacs/fallback", commonParam, heard); System.out.println("body:" + JSONObject.toJSONString(commonParam)); System.out.println("response:" + responseBody.toJSONString()); - if (!responseBody.getString("retCode").equals("000000")) { - throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, responseBody.getString("retMsg")); + if (!responseBody.getString("code").equals("SACS0000")) { + throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, responseBody.getString("msg")); } tradeOrderProfitSharing.setStatus(ProfitSharingStatusEnum.status2.getNumber()); tradeOrderProfitSharingService.editData(tradeOrderProfitSharing); @@ -223,10 +261,10 @@ public class LaKaLaTradeSeparateService { Map map = new HashMap<>(); map.put("merchant_no", tradeOrderProfitSharing.getPlatformMerNo()); - map.put("separate_no", tradeOrderProfitSharing.getProfitSharingOrderNo()); - commonParam.put("reqData", map); + map.put("out_separate_no", tradeOrderProfitSharing.getProfitSharingOrderNo()); + commonParam.put("req_data", map); - Map reqParam = LaKaLaConfig.generateSignParamsV2(JSONObject.parseObject(JSONObject.toJSONString(commonParam))); + Map reqParam = LaKaLaConfig.generateSignParamsV3(JSONObject.parseObject(JSONObject.toJSONString(commonParam))); // 头部参数 Map heard = new HashMap<>(); heard.put("Authorization", reqParam.get("Authorization")); @@ -234,8 +272,8 @@ public class LaKaLaTradeSeparateService { JSONObject responseBody = HttpsUtils.doPost(CommonSysConst.getSysConfig().getLkl_request_url() + "/api/v3/sacs/query", commonParam, heard); System.out.println("body:" + JSONObject.toJSONString(commonParam)); System.out.println("response:" + responseBody.toJSONString()); - if (!responseBody.getString("retCode").equals("000000")) { - throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, responseBody.getString("retMsg")); + if (!responseBody.getString("code").equals("SACS0000")) { + throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, responseBody.getString("msg")); } return responseBody.getJSONObject("resp_data"); } 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 5c87648..f52771f 100644 --- a/service/src/main/java/com/hfkj/channel/lakala/LaKaLaTradeService.java +++ b/service/src/main/java/com/hfkj/channel/lakala/LaKaLaTradeService.java @@ -43,6 +43,9 @@ public class LaKaLaTradeService { @Resource private BsMerService merService; + @Resource + private BsMerPlatformNoRateService merPlatformNoRateService; + /** * 交易【被扫】 * @param tradeNo 订单号 @@ -68,6 +71,14 @@ public class LaKaLaTradeService { throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "未找到商户终端号"); } + // 比例 + BsMerPlatformNoRate rate = merPlatformNoRateService.getDetail(order.getMerId(), PlatformTypeEnum.type1.getNumber(), null); + if (rate != null) { + order.setProfitSharingStatus(true); + } else { + order.setProfitSharingStatus(false); + } + Map commonParam = new HashMap<>(); commonParam.put("req_time", DateUtil.format(new Date(), "yyyyMMddHHmmss")); commonParam.put("version", "3.0"); @@ -80,6 +91,7 @@ public class LaKaLaTradeService { map.put("auth_code", authCode); map.put("total_amount", order.getTradeAmount().multiply(new BigDecimal("100")).intValue()); map.put("notify_url", CommonSysConst.getSysConfig().getLkl_micro_pay_ret_url()); + map.put("settle_type", order.getProfitSharingStatus().equals(true)?"1":"0"); Map locationInfo = new HashMap<>(); locationInfo.put("request_ip", "10.176.1.192"); diff --git a/service/src/main/java/com/hfkj/channel/lakala/config/LaKaLaConfig.java b/service/src/main/java/com/hfkj/channel/lakala/config/LaKaLaConfig.java index 007994a..4ea9daa 100644 --- a/service/src/main/java/com/hfkj/channel/lakala/config/LaKaLaConfig.java +++ b/service/src/main/java/com/hfkj/channel/lakala/config/LaKaLaConfig.java @@ -174,6 +174,7 @@ public class LaKaLaConfig { heard.put("Authorization", reqParam.get("Authorization")); JSONObject responseBody = HttpsUtils.doPost(CommonSysConst.getSysConfig().getLkl_request_url() + "/api/v2/mms/openApi/uploadFile", param, heard); + System.out.println("body:"); if (!responseBody.getString("retCode").equals("000000")) { throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, responseBody.getString("retMsg")); } diff --git a/service/src/main/java/com/hfkj/channel/saas/SaasMerService.java b/service/src/main/java/com/hfkj/channel/saas/SaasMerService.java index 06b507f..9e6eed4 100644 --- a/service/src/main/java/com/hfkj/channel/saas/SaasMerService.java +++ b/service/src/main/java/com/hfkj/channel/saas/SaasMerService.java @@ -71,6 +71,11 @@ public class SaasMerService { @Resource private SaasMerRequest saasMerRequest; + /** + * 商户进件 + * @param merId + * @throws Exception + */ public void addMer(Long merId) throws Exception { MerBasisModel basisModel = merService.getMerDetail(merId); @@ -267,6 +272,34 @@ public class SaasMerService { merContractRecordMsgService.insertRecordMsg(recordMsg); } + /** + * 修改结算信息 + * @param customerNo + * @return + */ + public JSONObject updateSettle(String customerNo) { + try { + Map param = new HashMap<>(); + param.put("customerNo", customerNo); + + Map header = new HashMap<>(); + header.put("Authorization", "bearer " + saasCommon.getToken()); + + JSONObject obj = new JSONObject(); + obj.put("data", Base64.encodeBase64String(RSAUtil.encryptByPrivateKey(JSONObject.toJSONString(param).getBytes(), Base64.decodeBase64(RSAUtil.PRIVATE_KEY)))); + + JSONObject responseObj = HttpsUtils.doPost(SaasConfig.requestMerUrl + "open/merchant/info", obj, header); + System.out.println(responseObj.toJSONString()); + if (responseObj == null || !responseObj.getString("code").equals("000000")) { + throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, responseObj.getString("message")); + } + return JSONObject.parseObject(new String(RSAUtil.decryptByPublicKey(Base64.decodeBase64(responseObj.getString("data")), Base64.decodeBase64(RSAUtil.PUBLIC_KEY)))); + + } catch (Exception e) { + System.out.println(e); + return null; + } + } /** * 查询银行地区编码 diff --git a/service/src/main/java/com/hfkj/common/utils/HttpsUtils.java b/service/src/main/java/com/hfkj/common/utils/HttpsUtils.java index 1a48606..a6e4956 100644 --- a/service/src/main/java/com/hfkj/common/utils/HttpsUtils.java +++ b/service/src/main/java/com/hfkj/common/utils/HttpsUtils.java @@ -53,13 +53,13 @@ public class HttpsUtils { private static PoolingHttpClientConnectionManager connMgr; private static RequestConfig requestConfig; - private static final int MAX_TIMEOUT = 15000; + private static final int MAX_TIMEOUT = 25000; static { // 设置连接池 connMgr = new PoolingHttpClientConnectionManager(); // 设置连接池大小 - connMgr.setMaxTotal(100); + connMgr.setMaxTotal(1000); connMgr.setDefaultMaxPerRoute(connMgr.getMaxTotal()); // Validate connections after 1 sec of inactivity connMgr.setValidateAfterInactivity(1000); diff --git a/service/src/main/java/com/hfkj/dao/BsTradeOrderProfitSharingMapperExt.java b/service/src/main/java/com/hfkj/dao/BsTradeOrderProfitSharingMapperExt.java index 9af571c..9bf8514 100644 --- a/service/src/main/java/com/hfkj/dao/BsTradeOrderProfitSharingMapperExt.java +++ b/service/src/main/java/com/hfkj/dao/BsTradeOrderProfitSharingMapperExt.java @@ -15,10 +15,11 @@ public interface BsTradeOrderProfitSharingMapperExt { @Select({" SELECT a.* FROM bs_trade_order_profit_sharing a " + " LEFT JOIN bs_trade_order b on b.id = a.trade_order_id " + - " where b.`status` = 3 and a.`status` = 0 " + + " where b.`status` = 3 and a.`status` in (0,2,3) " + " and a.create_time <= DATE_SUB(NOW(), INTERVAL 5 MINUTE) "}) @Results({ @Result(column="id", property="id", jdbcType=JdbcType.BIGINT, id=true), + @Result(column="cmd_type", property="cmdType", jdbcType=JdbcType.BIGINT), @Result(column="trade_order_id", property="tradeOrderId", jdbcType=JdbcType.BIGINT), @Result(column="trade_order_no", property="tradeOrderNo", jdbcType=JdbcType.VARCHAR), @Result(column="profit_sharing_order_no", property="profitSharingOrderNo", jdbcType=JdbcType.VARCHAR), diff --git a/service/src/main/java/com/hfkj/service/BsTradeOrderService.java b/service/src/main/java/com/hfkj/service/BsTradeOrderService.java index 02929c1..43c171b 100644 --- a/service/src/main/java/com/hfkj/service/BsTradeOrderService.java +++ b/service/src/main/java/com/hfkj/service/BsTradeOrderService.java @@ -40,7 +40,7 @@ public interface BsTradeOrderService { * @param tradeActualAmount * @param subMchId */ - void paySuccess(String outTradeNo, String transactionId, PlatformTypeEnum platformType, TradeOrderPayModeEnum tradeOrderPayMode, BigDecimal tradeActualAmount, String subMchId); + void paySuccess(String outTradeNo, String transactionId, PlatformTypeEnum platformType, TradeOrderPayModeEnum tradeOrderPayMode, BigDecimal tradeActualAmount, String subMchId, Map other); /** * 根据交易流水 查询 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 ff7ea03..9d723cc 100644 --- a/service/src/main/java/com/hfkj/service/impl/BsTradeOrderServiceImpl.java +++ b/service/src/main/java/com/hfkj/service/impl/BsTradeOrderServiceImpl.java @@ -54,6 +54,8 @@ public class BsTradeOrderServiceImpl implements BsTradeOrderService { @Resource private UserDiscountService userDiscountService; + @Resource + private BsMerPlatformNoRateService merPlatformNoRateService; @Override public void editOrder(BsTradeOrder tradeOrder) { @@ -188,7 +190,7 @@ public class BsTradeOrderServiceImpl implements BsTradeOrderService { tradeOrder.setQrCodeId(MapUtils.getLong(param, "qrCodeId")); } - tradeOrder.setProfitSharingStatus(true); + tradeOrder.setProfitSharingStatus(false); editOrder(tradeOrder); Map returnParam = new HashMap<>(); @@ -197,7 +199,7 @@ public class BsTradeOrderServiceImpl implements BsTradeOrderService { } @Override - public void paySuccess(String outTradeNo, String transactionId, PlatformTypeEnum platformType, TradeOrderPayModeEnum tradeOrderPayMode, BigDecimal tradeActualAmount, String subMchId) { + public void paySuccess(String outTradeNo, String transactionId, PlatformTypeEnum platformType, TradeOrderPayModeEnum tradeOrderPayMode, BigDecimal tradeActualAmount, String subMchId, Map other) { // 查询订单 BsTradeOrder tradeOrder = getOrderByOutTradeNo(outTradeNo); if (tradeOrder != null && tradeOrder.getStatus().equals(TradeOrderStatusEnum.status1.getNumber())) { @@ -208,6 +210,16 @@ public class BsTradeOrderServiceImpl implements BsTradeOrderService { tradeOrder.setTradeActualAmount(tradeActualAmount); tradeOrder.setStatus(TradeOrderStatusEnum.status3.getNumber()); tradeOrder.setPayTime(new Date()); + + if (StringUtils.isNotBlank(MapUtils.getString(other, "log_no"))) { + tradeOrder.setPlatformLogNo(MapUtils.getString(other, "log_no")); + } + if (StringUtils.isNotBlank(MapUtils.getString(other, "acc_trade_no"))) { + tradeOrder.setAccTradeNo(MapUtils.getString(other, "acc_trade_no")); + } + if (StringUtils.isNotBlank(MapUtils.getString(other, "card_type"))) { + tradeOrder.setCardType(MapUtils.getString(other, "card_type")); + } editOrder(tradeOrder); Map param = new HashMap<>(); @@ -216,7 +228,7 @@ public class BsTradeOrderServiceImpl implements BsTradeOrderService { param.put("status", DeviceStatusEnum.status1.getNumber()); List deviceList = deviceService.getDeviceList(param); for (BsDevice device : deviceList) { - soundService.sendPayMsg(device.getDeviceNo(), tradeOrder.getTradeAmount()); + soundService.sendPayMsg(device.getDeviceNo(), tradeOrder.getTradeAmount()); } if (tradeOrder.getStoreDiscountId() != null && StringUtils.isNotBlank(tradeOrder.getUserPhone())) { @@ -234,9 +246,7 @@ public class BsTradeOrderServiceImpl implements BsTradeOrderService { // 创建分账 if (tradeOrder.getProfitSharingStatus().equals(true)) { - new Thread(() -> { - tradeOrderProfitSharingService.createProfitSharing(tradeOrder); - }); + tradeOrderProfitSharingService.createProfitSharing(tradeOrder); } } } diff --git a/service/src/main/resources/prod/commonConfig.properties b/service/src/main/resources/prod/commonConfig.properties index e249998..df077d6 100644 --- a/service/src/main/resources/prod/commonConfig.properties +++ b/service/src/main/resources/prod/commonConfig.properties @@ -6,13 +6,13 @@ qr_code_data_url=https://pay.dctpay.com/scanPay qr_code_url=https://pay.dctpay.com/filesystem/payQrCode/ lkl_request_url=https://s2.lakala.com -lkl_org_code=950386 +lkl_org_code=965644 lkl_v3_appid=OP00000622 lkl_v3_serial_no=01752b7386f8 lkl_v3_private_key=/home/project/gratia-pay/cert/lakala/v3/prod_private.text -lkl_v2_appid=OP00000066 -lkl_v2_serial_no=017f2990c583 +lkl_v2_appid=OP00000622 +lkl_v2_serial_no=01752b7386f8 lkl_v2_private_key=/home/project/gratia-pay/cert/lakala/v2/prod_private.text lkl_mer_contract_ret_url=https://pay.dctpay.com/brest/laKaLaNotify/merContract lkl_micro_pay_ret_url=https://pay.dctpay.com/crest/laKaLaNotify/microPay