update 充值余额 新方法

This commit is contained in:
2023-09-01 17:01:05 +08:00
parent 74e97e2671
commit c2be91227b
3 changed files with 172 additions and 12 deletions

View File

@@ -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<String, Object> rechargeBalance(WeixinPayDTO dto);
/**
* 余额退款
* @param dto
*/
public abstract void refundBalance(ApplyRefundDTO dto);
/**
* 订单支付成功 支付回调

View File

@@ -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<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) {
}
/**
* 余额支付订单退款
*/

View File

@@ -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<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) {
}
// uniApp 发送停止充电订阅消息
private void sendMsg(OrderBasicInfo orderBasicInfo) {
try {