mirror of
https://codeup.aliyun.com/67c68d4e484ca2f0a13ac3c1/ydc/jsowell-charger-web.git
synced 2026-04-21 11:35:12 +08:00
Merge branch 'adapay' into merge_adapay
This commit is contained in:
@@ -0,0 +1,19 @@
|
||||
package com.jsowell.adapay.operation;
|
||||
|
||||
import lombok.*;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
@Builder
|
||||
public class PaymentRefundOperation extends AdapayOperationInfo{
|
||||
private String paymentId;
|
||||
private BigDecimal refundAmt;
|
||||
private String wechatAppId;
|
||||
private String memberId;
|
||||
private String scenarioType;
|
||||
private String orderCode;
|
||||
}
|
||||
@@ -110,7 +110,9 @@ public interface IPileMerchantInfoService {
|
||||
|
||||
String getDelayModeByWechatAppId(String wechatAppId);
|
||||
|
||||
/**
|
||||
String getDelayModeByMerchantId(String merchantId);
|
||||
|
||||
/**
|
||||
* 通过merchantId获取一级运营商信息
|
||||
*/
|
||||
PileMerchantInfo getFirstLevelMerchantByMerchantId(String merchantId);
|
||||
|
||||
@@ -38,6 +38,8 @@ import com.jsowell.pile.domain.*;
|
||||
import com.jsowell.pile.dto.*;
|
||||
import com.jsowell.pile.mapper.OrderBasicInfoMapper;
|
||||
import com.jsowell.pile.service.*;
|
||||
import com.jsowell.pile.service.orderlogic.AbstractOrderLogic;
|
||||
import com.jsowell.pile.service.orderlogic.OrderLogicFactory;
|
||||
import com.jsowell.pile.transaction.dto.ClearingBillTransactionDTO;
|
||||
import com.jsowell.pile.transaction.dto.OrderTransactionDTO;
|
||||
import com.jsowell.pile.transaction.service.TransactionService;
|
||||
@@ -445,7 +447,12 @@ public class OrderBasicInfoServiceImpl implements IOrderBasicInfoService {
|
||||
.flatUsedElectricity(Constants.ZERO)
|
||||
.valleyUsedElectricity(Constants.ZERO)
|
||||
.build();
|
||||
settleOrder(data, orderInfo);
|
||||
// settleOrder(data, orderInfo);
|
||||
|
||||
// 新逻辑
|
||||
String mode = pileMerchantInfoService.getDelayModeByMerchantId(orderInfo.getMerchantId());
|
||||
AbstractOrderLogic orderLogic = OrderLogicFactory.getOrderLogic(mode);
|
||||
orderLogic.settleOrder(data, orderInfo);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -422,6 +422,20 @@ public class PileMerchantInfoServiceImpl implements IPileMerchantInfoService {
|
||||
return merchant.getDelayMode();
|
||||
}
|
||||
|
||||
/**
|
||||
* 通过运营商id查询一级运营商配置的delayMode
|
||||
* @param merchantId
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public String getDelayModeByMerchantId(String merchantId) {
|
||||
PileMerchantInfo merchant = getFirstLevelMerchantByMerchantId(merchantId);
|
||||
if (merchant == null) {
|
||||
return null;
|
||||
}
|
||||
return merchant.getAppId();
|
||||
}
|
||||
|
||||
@Override
|
||||
public PileMerchantInfo getFirstLevelMerchantByMerchantId(String merchantId) {
|
||||
if (StringUtils.isBlank(merchantId)) {
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -116,7 +117,21 @@ public abstract class AbstractOrderLogic implements InitializingBean {
|
||||
*/
|
||||
public abstract void settleOrder(TransactionRecordsData data, OrderBasicInfo orderBasicInfo);
|
||||
|
||||
/**
|
||||
* 订单退款
|
||||
*/
|
||||
public abstract void refundOrder(OrderBasicInfo orderBasicInfo);
|
||||
|
||||
/**
|
||||
* 余额充值
|
||||
*/
|
||||
public abstract Map<String, Object> rechargeBalance(WeixinPayDTO dto);
|
||||
|
||||
/**
|
||||
* 余额退款
|
||||
* @param dto
|
||||
*/
|
||||
public abstract void refundBalance(ApplyRefundDTO dto);
|
||||
|
||||
/**
|
||||
* 订单支付成功 支付回调
|
||||
|
||||
@@ -3,10 +3,18 @@ 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.CacheConstants;
|
||||
import com.jsowell.common.constant.Constants;
|
||||
import com.jsowell.common.core.domain.ykc.TransactionRecordsData;
|
||||
import com.jsowell.common.enums.AcquirerEnum;
|
||||
@@ -15,14 +23,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 +37,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;
|
||||
|
||||
@@ -367,21 +375,7 @@ public class DelayMerchantOrderLogic extends AbstractOrderLogic {
|
||||
transactionService.doUpdateOrder(dto);
|
||||
|
||||
// 订单退款
|
||||
try {
|
||||
String payMode = orderBasicInfo.getPayMode();
|
||||
if (StringUtils.equals(payMode, OrderPayModeEnum.PAYMENT_OF_BALANCE.getValue())) {
|
||||
// 余额支付
|
||||
balancePaymentOrderRefund(orderBasicInfo);
|
||||
} else if (StringUtils.equals(payMode, OrderPayModeEnum.PAYMENT_OF_WECHATPAY.getValue())) {
|
||||
// 微信支付
|
||||
onlinePaymentOrderRefund(orderBasicInfo);
|
||||
} else {
|
||||
// 白名单支付
|
||||
logger.info("订单:{}使用白名单支付,不进行退款处理", orderBasicInfo.getOrderCode());
|
||||
}
|
||||
} catch (Exception e) {
|
||||
logger.error("{}-订单退款逻辑异常orderCode:{}", this.getClass().getSimpleName(), orderBasicInfo.getOrderCode(), e);
|
||||
}
|
||||
refundOrder(orderBasicInfo);
|
||||
|
||||
// 将卡/vin状态解锁
|
||||
if (!StringUtils.equals("0000000000000000", data.getLogicCard())) {
|
||||
@@ -416,10 +410,134 @@ public class DelayMerchantOrderLogic extends AbstractOrderLogic {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void refundOrder(OrderBasicInfo orderBasicInfo) {
|
||||
try {
|
||||
String payMode = orderBasicInfo.getPayMode();
|
||||
if (StringUtils.equals(payMode, OrderPayModeEnum.PAYMENT_OF_BALANCE.getValue())) {
|
||||
// 余额支付
|
||||
balancePaymentOrderRefund(orderBasicInfo);
|
||||
} else if (StringUtils.equals(payMode, OrderPayModeEnum.PAYMENT_OF_WECHATPAY.getValue())) {
|
||||
// 微信支付
|
||||
onlinePaymentOrderRefund(orderBasicInfo);
|
||||
} else {
|
||||
// 白名单支付
|
||||
logger.info("订单:{}使用白名单支付,不进行退款处理", orderBasicInfo.getOrderCode());
|
||||
}
|
||||
} catch (Exception e) {
|
||||
logger.error("{}-订单退款逻辑异常orderCode:{}", this.getClass().getSimpleName(), orderBasicInfo.getOrderCode(), e);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 余额充值
|
||||
*
|
||||
* @param dto
|
||||
*/
|
||||
@Override
|
||||
public Map<String, Object> 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<String, String> 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<String, Object> 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<Map<String, Object>>() {
|
||||
});
|
||||
}
|
||||
} catch (BaseAdaPayException e) {
|
||||
logger.error("汇付-获取支付对象发生异常", e);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* 余额退款
|
||||
*
|
||||
* @param dto
|
||||
*/
|
||||
@Override
|
||||
public void refundBalance(ApplyRefundDTO dto) {
|
||||
// 做个拦截,如果前一笔退款没有完成,就抛异常
|
||||
String redisKey = CacheConstants.MEMBER_BALANCE_REFUNDS_ARE_IN_PROGRESS + dto.getMemberId();
|
||||
PaymentReverseResponse redisResult = redisCache.getCacheObject(redisKey);
|
||||
if (Objects.nonNull(redisResult)) {
|
||||
throw new BusinessException(ReturnCodeEnum.CODE_BALANCE_REFUNDS_ARE_IN_PROGRESS_ERROR);
|
||||
}
|
||||
|
||||
// 查会员余额
|
||||
MemberVO memberVO = memberBasicInfoService.queryMemberInfoByMemberId(dto.getMemberId());
|
||||
if (memberVO == null) {
|
||||
throw new BusinessException(ReturnCodeEnum.CODE_MEMBER_NOT_FOUND_ERROR);
|
||||
}
|
||||
|
||||
// 校验退款金额
|
||||
BigDecimal principalBalance = memberVO.getPrincipalBalance();
|
||||
BigDecimal refundAmount = dto.getRefundAmount();
|
||||
if (refundAmount.compareTo(principalBalance) > 0) {
|
||||
throw new BusinessException(ReturnCodeEnum.CODE_REFUND_MEMBER_BALANCE_ERROR);
|
||||
}
|
||||
|
||||
// 查询用户充值余额订单 过滤掉已经退款的充值订单
|
||||
List<BalanceDeductionAmountVO> list = calculateTheBalanceDeductionAmount(dto.getMemberId(), refundAmount);
|
||||
for (BalanceDeductionAmountVO vo : list) {
|
||||
String paymentId = vo.getPaymentId();
|
||||
BigDecimal deductionAmount = vo.getDeductionAmount();
|
||||
|
||||
// 调汇付的交易撤销接口
|
||||
PaymentReverseResponse request = adapayService.createPaymentReverseRequest(paymentId, deductionAmount,
|
||||
dto.getWechatAppId(), dto.getMemberId(), ScenarioEnum.BALANCE.getValue(), null);
|
||||
|
||||
if (request != null && request.isNotFailed()) {
|
||||
memberAdapayRecordService.updateRefundAmount(paymentId, deductionAmount);
|
||||
|
||||
// 放缓存
|
||||
redisCache.setCacheObject(redisKey, request, CacheConstants.cache_expire_time_30m);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 余额支付订单退款
|
||||
*/
|
||||
private void balancePaymentOrderRefund(OrderBasicInfo orderBasicInfo) {
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void balancePaymentOrderRefund(OrderBasicInfo orderBasicInfo) {
|
||||
logger.info("{}-余额支付订单退款start orderBasicInfo:{}", this.getClass().getSimpleName(), JSON.toJSONString(orderBasicInfo));
|
||||
// 订单编号
|
||||
String orderCode = orderBasicInfo.getOrderCode();
|
||||
|
||||
@@ -2,9 +2,17 @@ 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.CacheConstants;
|
||||
import com.jsowell.common.constant.Constants;
|
||||
import com.jsowell.common.core.domain.ykc.TransactionRecordsData;
|
||||
import com.jsowell.common.enums.AcquirerEnum;
|
||||
@@ -13,14 +21,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,7 +35,9 @@ 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;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.text.ParseException;
|
||||
@@ -350,21 +359,7 @@ public class NotDelayMerchantOrderLogic extends AbstractOrderLogic{
|
||||
transactionService.doUpdateOrder(dto);
|
||||
|
||||
// 订单退款
|
||||
try {
|
||||
String payMode = orderBasicInfo.getPayMode();
|
||||
if (StringUtils.equals(payMode, OrderPayModeEnum.PAYMENT_OF_BALANCE.getValue())) {
|
||||
// 余额支付
|
||||
balancePaymentOrderRefund(orderBasicInfo);
|
||||
} else if (StringUtils.equals(payMode, OrderPayModeEnum.PAYMENT_OF_WECHATPAY.getValue())) {
|
||||
// 微信支付
|
||||
onlinePaymentOrderRefund(orderBasicInfo);
|
||||
} else {
|
||||
// 白名单支付
|
||||
logger.info("订单:{}使用白名单支付,不进行退款处理", orderBasicInfo.getOrderCode());
|
||||
}
|
||||
} catch (Exception e) {
|
||||
logger.error("{}-订单退款逻辑异常orderCode:{}", this.getClass().getSimpleName(), orderBasicInfo.getOrderCode(), e);
|
||||
}
|
||||
refundOrder(orderBasicInfo);
|
||||
|
||||
// 将卡/vin状态解锁
|
||||
if (!StringUtils.equals("0000000000000000", data.getLogicCard())) {
|
||||
@@ -387,6 +382,129 @@ public class NotDelayMerchantOrderLogic extends AbstractOrderLogic{
|
||||
logger.info("结算订单end:{} OrderTransactionDTO:{}", orderBasicInfo.getOrderCode(), JSONObject.toJSONString(dto));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void refundOrder(OrderBasicInfo orderBasicInfo) {
|
||||
try {
|
||||
String payMode = orderBasicInfo.getPayMode();
|
||||
if (StringUtils.equals(payMode, OrderPayModeEnum.PAYMENT_OF_BALANCE.getValue())) {
|
||||
// 余额支付
|
||||
balancePaymentOrderRefund(orderBasicInfo);
|
||||
} else if (StringUtils.equals(payMode, OrderPayModeEnum.PAYMENT_OF_WECHATPAY.getValue())) {
|
||||
// 微信支付
|
||||
onlinePaymentOrderRefund(orderBasicInfo);
|
||||
} else {
|
||||
// 白名单支付
|
||||
logger.info("订单:{}使用白名单支付,不进行退款处理", orderBasicInfo.getOrderCode());
|
||||
}
|
||||
} catch (Exception e) {
|
||||
logger.error("{}-订单退款逻辑异常orderCode:{}", this.getClass().getSimpleName(), orderBasicInfo.getOrderCode(), e);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 余额充值
|
||||
*
|
||||
* @param dto
|
||||
*/
|
||||
@Override
|
||||
public Map<String, Object> 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<String, String> 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<String, Object> 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<Map<String, Object>>() {
|
||||
});
|
||||
}
|
||||
} catch (BaseAdaPayException e) {
|
||||
logger.error("汇付-获取支付对象发生异常", e);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* 余额退款
|
||||
*
|
||||
* @param dto
|
||||
*/
|
||||
@Override
|
||||
public void refundBalance(ApplyRefundDTO dto) {
|
||||
// 做个拦截,如果前一笔退款没有完成,就抛异常
|
||||
String redisKey = CacheConstants.MEMBER_BALANCE_REFUNDS_ARE_IN_PROGRESS + dto.getMemberId();
|
||||
RefundResponse redisResult = redisCache.getCacheObject(redisKey);
|
||||
if (Objects.nonNull(redisResult)) {
|
||||
throw new BusinessException(ReturnCodeEnum.CODE_BALANCE_REFUNDS_ARE_IN_PROGRESS_ERROR);
|
||||
}
|
||||
|
||||
// 查会员余额
|
||||
MemberVO memberVO = memberBasicInfoService.queryMemberInfoByMemberId(dto.getMemberId());
|
||||
if (memberVO == null) {
|
||||
throw new BusinessException(ReturnCodeEnum.CODE_MEMBER_NOT_FOUND_ERROR);
|
||||
}
|
||||
|
||||
// 校验退款金额
|
||||
BigDecimal principalBalance = memberVO.getPrincipalBalance();
|
||||
BigDecimal refundAmount = dto.getRefundAmount();
|
||||
if (refundAmount.compareTo(principalBalance) > 0) {
|
||||
throw new BusinessException(ReturnCodeEnum.CODE_REFUND_MEMBER_BALANCE_ERROR);
|
||||
}
|
||||
|
||||
// 查询用户充值余额订单 过滤掉已经退款的充值订单
|
||||
List<BalanceDeductionAmountVO> list = calculateTheBalanceDeductionAmount(dto.getMemberId(), refundAmount);
|
||||
for (BalanceDeductionAmountVO vo : list) {
|
||||
String paymentId = vo.getPaymentId();
|
||||
BigDecimal deductionAmount = vo.getDeductionAmount();
|
||||
|
||||
// 调汇付的交易退款接口
|
||||
RefundResponse response = adapayService.createRefundRequest(paymentId, refundAmount,
|
||||
dto.getWechatAppId(), dto.getMemberId(), ScenarioEnum.ORDER.getValue(), dto.getOrderCode());
|
||||
|
||||
if (response != null && response.isNotFailed()) {
|
||||
memberAdapayRecordService.updateRefundAmount(paymentId, deductionAmount);
|
||||
|
||||
// 放缓存
|
||||
redisCache.setCacheObject(redisKey, response, CacheConstants.cache_expire_time_30m);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// uniApp 发送停止充电订阅消息
|
||||
private void sendMsg(OrderBasicInfo orderBasicInfo) {
|
||||
try {
|
||||
@@ -404,7 +522,8 @@ public class NotDelayMerchantOrderLogic extends AbstractOrderLogic{
|
||||
*
|
||||
* @param orderBasicInfo
|
||||
*/
|
||||
private void balancePaymentOrderRefund(OrderBasicInfo orderBasicInfo) {
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void balancePaymentOrderRefund(OrderBasicInfo orderBasicInfo) {
|
||||
logger.info("{}-余额支付订单退款start orderBasicInfo:{}", this.getClass().getSimpleName(), JSON.toJSONString(orderBasicInfo));
|
||||
// 订单编号
|
||||
String orderCode = orderBasicInfo.getOrderCode();
|
||||
|
||||
@@ -5,11 +5,9 @@ import com.jsowell.wxpay.common.WeChatPayParameter;
|
||||
import com.jsowell.wxpay.utils.WechatPayUtils;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.boot.CommandLineRunner;
|
||||
import org.springframework.core.annotation.Order;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
@Order(value = 2)
|
||||
@Component
|
||||
// @Order(value = 2)
|
||||
// @Component
|
||||
public class WechatPayConfig implements CommandLineRunner {
|
||||
/**
|
||||
* 公众号appid
|
||||
|
||||
@@ -2,9 +2,8 @@ package com.jsowell.wxpay.config;
|
||||
|
||||
import org.springframework.beans.factory.InitializingBean;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
@Component
|
||||
// @Component
|
||||
public class WeixinLoginProperties implements InitializingBean {
|
||||
|
||||
@Value("${weixin.login.gateway}")
|
||||
|
||||
Reference in New Issue
Block a user