From c2be91227ba5b49d7a5dae0ec83d7a6b1d1ee870 Mon Sep 17 00:00:00 2001 From: "autumn.g@foxmail.com" Date: Fri, 1 Sep 2023 17:01:05 +0800 Subject: [PATCH] =?UTF-8?q?update=20=E5=85=85=E5=80=BC=E4=BD=99=E9=A2=9D?= =?UTF-8?q?=20=E6=96=B0=E6=96=B9=E6=B3=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../orderlogic/AbstractOrderLogic.java | 18 +++- .../orderlogic/DelayMerchantOrderLogic.java | 83 ++++++++++++++++++- .../NotDelayMerchantOrderLogic.java | 83 ++++++++++++++++++- 3 files changed, 172 insertions(+), 12 deletions(-) diff --git a/jsowell-pile/src/main/java/com/jsowell/pile/service/orderlogic/AbstractOrderLogic.java b/jsowell-pile/src/main/java/com/jsowell/pile/service/orderlogic/AbstractOrderLogic.java index ed400d97d..c0c4bd25b 100644 --- a/jsowell-pile/src/main/java/com/jsowell/pile/service/orderlogic/AbstractOrderLogic.java +++ b/jsowell-pile/src/main/java/com/jsowell/pile/service/orderlogic/AbstractOrderLogic.java @@ -15,10 +15,7 @@ import com.jsowell.common.exception.BusinessException; import com.jsowell.common.util.DateUtils; import com.jsowell.common.util.StringUtils; import com.jsowell.pile.domain.*; -import com.jsowell.pile.dto.BasicPileDTO; -import com.jsowell.pile.dto.GenerateOrderDTO; -import com.jsowell.pile.dto.PayOrderDTO; -import com.jsowell.pile.dto.PayOrderSuccessCallbackDTO; +import com.jsowell.pile.dto.*; import com.jsowell.pile.service.*; import com.jsowell.pile.transaction.service.TransactionService; import com.jsowell.pile.vo.uniapp.PileConnectorDetailVO; @@ -31,6 +28,7 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.InitializingBean; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Value; import javax.annotation.Resource; import java.math.BigDecimal; @@ -45,6 +43,9 @@ import java.util.Map; public abstract class AbstractOrderLogic implements InitializingBean { protected Logger logger = LoggerFactory.getLogger(this.getClass()); + @Value("${adapay.callback}") + protected String ADAPAY_CALLBACK_URL; + @Resource protected IOrderBasicInfoService orderBasicInfoService; @@ -121,7 +122,16 @@ public abstract class AbstractOrderLogic implements InitializingBean { */ public abstract void refundOrder(OrderBasicInfo orderBasicInfo); + /** + * 余额充值 + */ + public abstract Map rechargeBalance(WeixinPayDTO dto); + /** + * 余额退款 + * @param dto + */ + public abstract void refundBalance(ApplyRefundDTO dto); /** * 订单支付成功 支付回调 diff --git a/jsowell-pile/src/main/java/com/jsowell/pile/service/orderlogic/DelayMerchantOrderLogic.java b/jsowell-pile/src/main/java/com/jsowell/pile/service/orderlogic/DelayMerchantOrderLogic.java index bd4fd0f4f..024dba769 100644 --- a/jsowell-pile/src/main/java/com/jsowell/pile/service/orderlogic/DelayMerchantOrderLogic.java +++ b/jsowell-pile/src/main/java/com/jsowell/pile/service/orderlogic/DelayMerchantOrderLogic.java @@ -3,8 +3,15 @@ package com.jsowell.pile.service.orderlogic; import com.alibaba.fastjson2.JSON; import com.alibaba.fastjson2.JSONArray; import com.alibaba.fastjson2.JSONObject; +import com.alibaba.fastjson2.TypeReference; +import com.google.common.collect.ImmutableMap; import com.google.common.collect.Lists; import com.google.common.collect.Maps; +import com.huifu.adapay.core.exception.BaseAdaPayException; +import com.huifu.adapay.model.Payment; +import com.jsowell.adapay.common.CreateAdaPaymentParam; +import com.jsowell.adapay.config.AbstractAdapayConfig; +import com.jsowell.adapay.factory.AdapayConfigFactory; import com.jsowell.adapay.operation.PaymentReverseOperation; import com.jsowell.adapay.response.PaymentReverseResponse; import com.jsowell.common.constant.Constants; @@ -15,14 +22,13 @@ import com.jsowell.common.enums.MemberWalletEnum; import com.jsowell.common.enums.adapay.MerchantDelayModeEnum; import com.jsowell.common.enums.ykc.*; import com.jsowell.common.exception.BusinessException; +import com.jsowell.common.util.AdapayUtil; import com.jsowell.common.util.DateUtils; import com.jsowell.common.util.StringUtils; import com.jsowell.common.util.id.IdUtils; +import com.jsowell.common.util.id.SnowflakeIdWorker; import com.jsowell.pile.domain.*; -import com.jsowell.pile.dto.ApplyRefundDTO; -import com.jsowell.pile.dto.GenerateOrderDTO; -import com.jsowell.pile.dto.PayOrderDTO; -import com.jsowell.pile.dto.PayOrderSuccessCallbackDTO; +import com.jsowell.pile.dto.*; import com.jsowell.pile.transaction.dto.OrderTransactionDTO; import com.jsowell.pile.vo.uniapp.MemberVO; import com.jsowell.pile.vo.web.BalanceDeductionAmountVO; @@ -30,6 +36,7 @@ import com.jsowell.pile.vo.web.BillingTemplateVO; import com.jsowell.pile.vo.web.UpdateMemberBalanceDTO; import com.jsowell.wxpay.dto.WechatSendMsgDTO; import org.apache.commons.collections4.CollectionUtils; +import org.springframework.cglib.beans.BeanMap; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; @@ -421,6 +428,74 @@ public class DelayMerchantOrderLogic extends AbstractOrderLogic { } } + /** + * 余额充值 + * + * @param dto + */ + @Override + public Map rechargeBalance(WeixinPayDTO dto) { + // 获取支付配置 + AbstractAdapayConfig config = AdapayConfigFactory.getConfig(dto.getWechatAppId()); + if (config == null) { + throw new BusinessException(ReturnCodeEnum.CODE_ADAPAY_CONFIG_IS_NULL_ERROR); + } + logger.info("使用汇付支付充值余额 支付配置参数:{}", JSON.toJSONString(config)); + + String goodsTitle = "充值余额"; + String goodsDesc = "会员充值余额"; + + // 查询延时支付模式,由一级运营商配置决定 + String delayMode = pileMerchantInfoService.getDelayModeByWechatAppId(dto.getWechatAppId()); + String payMode = MerchantDelayModeEnum.getAdapayPayMode(delayMode); + // 封装对象 + // String payMode = Constants.ADAPAY_PAY_MODE_DELAY; // 汇付延时分账 + CreateAdaPaymentParam createAdaPaymentParam = new CreateAdaPaymentParam(); + createAdaPaymentParam.setOrder_no(SnowflakeIdWorker.getSnowflakeId()); + createAdaPaymentParam.setPay_amt(AdapayUtil.formatAmount(dto.getAmount())); + // createAdaPaymentParam.setApp_id(ADAPAY_APP_ID); // 移动到配置文件中 + createAdaPaymentParam.setApp_id(config.getAdapayAppId()); // 移动到配置文件中 + createAdaPaymentParam.setPay_channel("wx_lite"); // todo 如果以后有支付宝等别的渠道,这里需要做修改,判断是什么渠道的请求 + createAdaPaymentParam.setGoods_title(goodsTitle); + createAdaPaymentParam.setGoods_desc(goodsDesc); + createAdaPaymentParam.setExpend(JSONObject.toJSONString(ImmutableMap.of("open_id", dto.getOpenId()))); + // 异步通知地址,url为http/https路径,服务器POST回调,URL 上请勿附带参数 + createAdaPaymentParam.setNotify_url(ADAPAY_CALLBACK_URL); + Map map = Maps.newHashMap(); + map.put("type", ScenarioEnum.BALANCE.getValue()); + map.put("payMode", payMode); + map.put("memberId", dto.getMemberId()); + createAdaPaymentParam.setDescription(JSON.toJSONString(map)); + // 延时分账 + if (StringUtils.isNotBlank(payMode)) { + createAdaPaymentParam.setPay_mode(payMode); + } + try { + logger.info("创建汇付支付参数:{}", JSONObject.toJSONString(createAdaPaymentParam)); + Map response = Payment.create(BeanMap.create(createAdaPaymentParam), config.getWechatAppId()); + logger.info("创建汇付支付参数反参:{}", JSONObject.toJSONString(response)); + if (response != null && !response.isEmpty()) { + JSONObject jsonObject = JSONObject.parseObject(response.get("expend").toString()); + JSONObject pay_info = jsonObject.getJSONObject("pay_info"); + return JSONObject.parseObject(pay_info.toJSONString(), new TypeReference>() { + }); + } + } catch (BaseAdaPayException e) { + logger.error("汇付-获取支付对象发生异常", e); + } + return null; + } + + /** + * 余额退款 + * + * @param dto + */ + @Override + public void refundBalance(ApplyRefundDTO dto) { + + } + /** * 余额支付订单退款 */ diff --git a/jsowell-pile/src/main/java/com/jsowell/pile/service/orderlogic/NotDelayMerchantOrderLogic.java b/jsowell-pile/src/main/java/com/jsowell/pile/service/orderlogic/NotDelayMerchantOrderLogic.java index 6a3c004d3..0e0c41dbb 100644 --- a/jsowell-pile/src/main/java/com/jsowell/pile/service/orderlogic/NotDelayMerchantOrderLogic.java +++ b/jsowell-pile/src/main/java/com/jsowell/pile/service/orderlogic/NotDelayMerchantOrderLogic.java @@ -2,8 +2,15 @@ package com.jsowell.pile.service.orderlogic; import com.alibaba.fastjson2.JSON; import com.alibaba.fastjson2.JSONObject; +import com.alibaba.fastjson2.TypeReference; +import com.google.common.collect.ImmutableMap; import com.google.common.collect.Lists; import com.google.common.collect.Maps; +import com.huifu.adapay.core.exception.BaseAdaPayException; +import com.huifu.adapay.model.Payment; +import com.jsowell.adapay.common.CreateAdaPaymentParam; +import com.jsowell.adapay.config.AbstractAdapayConfig; +import com.jsowell.adapay.factory.AdapayConfigFactory; import com.jsowell.adapay.response.RefundResponse; import com.jsowell.common.constant.Constants; import com.jsowell.common.core.domain.ykc.TransactionRecordsData; @@ -13,14 +20,13 @@ import com.jsowell.common.enums.MemberWalletEnum; import com.jsowell.common.enums.adapay.MerchantDelayModeEnum; import com.jsowell.common.enums.ykc.*; import com.jsowell.common.exception.BusinessException; +import com.jsowell.common.util.AdapayUtil; import com.jsowell.common.util.DateUtils; import com.jsowell.common.util.StringUtils; import com.jsowell.common.util.id.IdUtils; +import com.jsowell.common.util.id.SnowflakeIdWorker; import com.jsowell.pile.domain.*; -import com.jsowell.pile.dto.ApplyRefundDTO; -import com.jsowell.pile.dto.GenerateOrderDTO; -import com.jsowell.pile.dto.PayOrderDTO; -import com.jsowell.pile.dto.PayOrderSuccessCallbackDTO; +import com.jsowell.pile.dto.*; import com.jsowell.pile.transaction.dto.OrderTransactionDTO; import com.jsowell.pile.vo.uniapp.MemberVO; import com.jsowell.pile.vo.web.BalanceDeductionAmountVO; @@ -28,6 +34,7 @@ import com.jsowell.pile.vo.web.BillingTemplateVO; import com.jsowell.pile.vo.web.UpdateMemberBalanceDTO; import com.jsowell.wxpay.dto.WechatSendMsgDTO; import org.apache.commons.collections4.CollectionUtils; +import org.springframework.cglib.beans.BeanMap; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; @@ -393,6 +400,74 @@ public class NotDelayMerchantOrderLogic extends AbstractOrderLogic{ } } + /** + * 余额充值 + * + * @param dto + */ + @Override + public Map rechargeBalance(WeixinPayDTO dto) { + // 获取支付配置 + AbstractAdapayConfig config = AdapayConfigFactory.getConfig(dto.getWechatAppId()); + if (config == null) { + throw new BusinessException(ReturnCodeEnum.CODE_ADAPAY_CONFIG_IS_NULL_ERROR); + } + logger.info("使用汇付支付充值余额 支付配置参数:{}", JSON.toJSONString(config)); + + String goodsTitle = "充值余额"; + String goodsDesc = "会员充值余额"; + + // 查询延时支付模式,由一级运营商配置决定 + String delayMode = pileMerchantInfoService.getDelayModeByWechatAppId(dto.getWechatAppId()); + String payMode = MerchantDelayModeEnum.getAdapayPayMode(delayMode); + // 封装对象 + // String payMode = Constants.ADAPAY_PAY_MODE_DELAY; // 汇付延时分账 + CreateAdaPaymentParam createAdaPaymentParam = new CreateAdaPaymentParam(); + createAdaPaymentParam.setOrder_no(SnowflakeIdWorker.getSnowflakeId()); + createAdaPaymentParam.setPay_amt(AdapayUtil.formatAmount(dto.getAmount())); + // createAdaPaymentParam.setApp_id(ADAPAY_APP_ID); // 移动到配置文件中 + createAdaPaymentParam.setApp_id(config.getAdapayAppId()); // 移动到配置文件中 + createAdaPaymentParam.setPay_channel("wx_lite"); // todo 如果以后有支付宝等别的渠道,这里需要做修改,判断是什么渠道的请求 + createAdaPaymentParam.setGoods_title(goodsTitle); + createAdaPaymentParam.setGoods_desc(goodsDesc); + createAdaPaymentParam.setExpend(JSONObject.toJSONString(ImmutableMap.of("open_id", dto.getOpenId()))); + // 异步通知地址,url为http/https路径,服务器POST回调,URL 上请勿附带参数 + createAdaPaymentParam.setNotify_url(ADAPAY_CALLBACK_URL); + Map map = Maps.newHashMap(); + map.put("type", ScenarioEnum.BALANCE.getValue()); + map.put("payMode", payMode); + map.put("memberId", dto.getMemberId()); + createAdaPaymentParam.setDescription(JSON.toJSONString(map)); + // 延时分账 + if (StringUtils.isNotBlank(payMode)) { + createAdaPaymentParam.setPay_mode(payMode); + } + try { + logger.info("创建汇付支付参数:{}", JSONObject.toJSONString(createAdaPaymentParam)); + Map response = Payment.create(BeanMap.create(createAdaPaymentParam), config.getWechatAppId()); + logger.info("创建汇付支付参数反参:{}", JSONObject.toJSONString(response)); + if (response != null && !response.isEmpty()) { + JSONObject jsonObject = JSONObject.parseObject(response.get("expend").toString()); + JSONObject pay_info = jsonObject.getJSONObject("pay_info"); + return JSONObject.parseObject(pay_info.toJSONString(), new TypeReference>() { + }); + } + } catch (BaseAdaPayException e) { + logger.error("汇付-获取支付对象发生异常", e); + } + return null; + } + + /** + * 余额退款 + * + * @param dto + */ + @Override + public void refundBalance(ApplyRefundDTO dto) { + + } + // uniApp 发送停止充电订阅消息 private void sendMsg(OrderBasicInfo orderBasicInfo) { try {