mirror of
https://codeup.aliyun.com/67c68d4e484ca2f0a13ac3c1/ydc/jsowell-charger-web.git
synced 2026-04-24 04:55:08 +08:00
update 实时分账
This commit is contained in:
@@ -95,7 +95,7 @@ public interface PileMerchantInfoMapper {
|
||||
* @param appId
|
||||
* @return
|
||||
*/
|
||||
String getFirstLevelMerchantIdByAppId(String appId);
|
||||
PileMerchantInfo getFirstLevelMerchantByAppId(String appId);
|
||||
|
||||
/**
|
||||
* 通过appid查询运营商部门id
|
||||
|
||||
@@ -66,7 +66,9 @@ public interface IPileMerchantInfoService {
|
||||
*/
|
||||
public int deletePileMerchantInfoById(Long id);
|
||||
|
||||
/**
|
||||
PileMerchantInfo getFirstLevelMerchantByAppId(String appId);
|
||||
|
||||
/**
|
||||
* 通过微信小程序appId查询一级运营商merchantId
|
||||
* @param appId 微信小程序appId
|
||||
* @return 一级运营商merchantId
|
||||
@@ -105,4 +107,6 @@ public interface IPileMerchantInfoService {
|
||||
* @return
|
||||
*/
|
||||
List<String> getDeptIdsByAppId(String appId);
|
||||
|
||||
String getDelayModeByWechatAppId(String wechatAppId);
|
||||
}
|
||||
|
||||
@@ -12,6 +12,7 @@ import com.jsowell.adapay.dto.QueryPaymentConfirmDTO;
|
||||
import com.jsowell.adapay.response.PaymentConfirmResponse;
|
||||
import com.jsowell.adapay.response.PaymentReverseResponse;
|
||||
import com.jsowell.adapay.response.QueryPaymentConfirmDetailResponse;
|
||||
import com.jsowell.adapay.response.RefundResponse;
|
||||
import com.jsowell.adapay.service.AdapayService;
|
||||
import com.jsowell.adapay.vo.OrderSettleResult;
|
||||
import com.jsowell.common.constant.CacheConstants;
|
||||
@@ -2338,23 +2339,21 @@ public class OrderBasicInfoServiceImpl implements IOrderBasicInfoService {
|
||||
BigDecimal refundAmount = dto.getRefundAmount();
|
||||
BigDecimal payAmt = callbackRecord.getPayAmt();
|
||||
if (refundAmount.compareTo(payAmt) > 0) {
|
||||
logger.error("汇付支付订单号:{}, 退款金额:{}(元),大于可退金额{}(元), 抛出异常", dto.getOrderCode(), refundAmount, payAmt);
|
||||
logger.error("汇付支付订单号:{}, 退款金额:{}(元),大于付款金额{}(元), 抛出异常", dto.getOrderCode(), refundAmount, payAmt);
|
||||
throw new BusinessException(ReturnCodeEnum.CODE_REFUND_ORDER_AMOUNT_ERROR);
|
||||
}
|
||||
|
||||
// 创建汇付退款对象 在完成初始化设置情况下,调用方法,获取 Refund对象
|
||||
|
||||
// TODO 拿orderCode查询清分状态
|
||||
String payMode = "delay";
|
||||
if (StringUtils.equals("", payMode)) {
|
||||
// 延迟分账确认的调退款接口
|
||||
adapayService.createRefundRequest(paymentId, refundAmount);
|
||||
} else {
|
||||
// 拿orderCode查询延时分账模式 延时分账的使用撤销方法退款,实时分账的使用退款方法
|
||||
String expend = callbackRecord.getExpend();
|
||||
JSONObject expendJsonObject = JSON.parseObject(expend);
|
||||
String payMode = expendJsonObject.getString("payMode");
|
||||
// String payMode = "delay";
|
||||
if (StringUtils.equalsIgnoreCase(payMode, Constants.ADAPAY_PAY_MODE_DELAY)) {
|
||||
// 延迟分账未确认调撤销调撤销接口退款
|
||||
PaymentReverseResponse response = adapayService.createPaymentReverseRequest(
|
||||
paymentId, refundAmount, dto.getWechatAppId(), dto.getMemberId(), ScenarioEnum.ORDER.getValue(),
|
||||
dto.getOrderCode());
|
||||
if (response != null && response.isFailed()) {
|
||||
if (response != null && response.isNotFailed()) {
|
||||
MemberAdapayRecord record = memberAdapayRecordService.selectByPaymentId(paymentId);
|
||||
BigDecimal reverseAmt = new BigDecimal(response.getReverse_amt());
|
||||
// 更新此笔交易单的消费金额 = 支付金额 - 撤销金额
|
||||
@@ -2370,7 +2369,52 @@ public class OrderBasicInfoServiceImpl implements IOrderBasicInfoService {
|
||||
}
|
||||
memberAdapayRecordService.updateByPrimaryKeySelective(record);
|
||||
}
|
||||
} else {
|
||||
// 实时分账的调退款接口
|
||||
RefundResponse refundRequest = adapayService.createRefundRequest(paymentId, refundAmount, dto.getWechatAppId(), dto.getMemberId(), ScenarioEnum.ORDER.getValue(),
|
||||
dto.getOrderCode());
|
||||
if (refundRequest != null && refundRequest.isNotFailed()) {
|
||||
MemberAdapayRecord record = memberAdapayRecordService.selectByPaymentId(paymentId);
|
||||
BigDecimal refundAmt = new BigDecimal(refundRequest.getRefund_amt());
|
||||
// 更新此笔交易单的消费金额 = 支付金额 - 撤销金额
|
||||
BigDecimal spendAmt = callbackRecord.getPayAmt().subtract(refundAmt);
|
||||
record.setSpendAmt(spendAmt);
|
||||
// 退款金额
|
||||
record.setRefundAmt(refundAmt);
|
||||
// 更新此笔交易单的剩余金额 = 支付金额 - 累计退款金额 - 累计消费金额
|
||||
record.setBalanceAmt(record.getPayAmt().subtract(record.getRefundAmt()).subtract(record.getSpendAmt()));
|
||||
if (BigDecimal.ZERO.compareTo(record.getBalanceAmt()) != 0) {
|
||||
logger.error("订单分账结束后账不平,paymentId:{}, orderCode:{}, 支付金额:{}, 消费金额:{}, 退款金额:{}",
|
||||
paymentId, dto.getOrderCode(), payAmt, spendAmt, refundAmt);
|
||||
}
|
||||
memberAdapayRecordService.updateByPrimaryKeySelective(record);
|
||||
}
|
||||
}
|
||||
// if (StringUtils.equals("", payMode)) {
|
||||
// // 延迟分账确认的调退款接口
|
||||
// adapayService.createRefundRequest(paymentId, refundAmount);
|
||||
// } else {
|
||||
// // 延迟分账未确认调撤销调撤销接口退款
|
||||
// PaymentReverseResponse response = adapayService.createPaymentReverseRequest(
|
||||
// paymentId, refundAmount, dto.getWechatAppId(), dto.getMemberId(), ScenarioEnum.ORDER.getValue(),
|
||||
// dto.getOrderCode());
|
||||
// if (response != null && response.isFailed()) {
|
||||
// MemberAdapayRecord record = memberAdapayRecordService.selectByPaymentId(paymentId);
|
||||
// BigDecimal reverseAmt = new BigDecimal(response.getReverse_amt());
|
||||
// // 更新此笔交易单的消费金额 = 支付金额 - 撤销金额
|
||||
// BigDecimal spendAmt = callbackRecord.getPayAmt().subtract(reverseAmt);
|
||||
// record.setSpendAmt(spendAmt);
|
||||
// // 退款金额
|
||||
// record.setRefundAmt(reverseAmt);
|
||||
// // 更新此笔交易单的剩余金额 = 支付金额 - 累计退款金额 - 累计消费金额
|
||||
// record.setBalanceAmt(record.getPayAmt().subtract(record.getRefundAmt()).subtract(record.getSpendAmt()));
|
||||
// if (BigDecimal.ZERO.compareTo(record.getBalanceAmt()) != 0) {
|
||||
// logger.error("订单分账结束后账不平,paymentId:{}, orderCode:{}, 支付金额:{}, 消费金额:{}, 退款金额:{}",
|
||||
// paymentId, dto.getOrderCode(), payAmt, spendAmt, reverseAmt);
|
||||
// }
|
||||
// memberAdapayRecordService.updateByPrimaryKeySelective(record);
|
||||
// }
|
||||
// }
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -260,7 +260,19 @@ public class PileMerchantInfoServiceImpl implements IPileMerchantInfoService {
|
||||
// 逻辑删除部门
|
||||
sysDeptService.deleteDeptById(Long.parseLong(deptId));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 通过微信小程序appId查询一级运营商merchant对象
|
||||
* @param appId 微信小程序appId
|
||||
* @return 一级运营商merchant对象
|
||||
*/
|
||||
@Override
|
||||
public PileMerchantInfo getFirstLevelMerchantByAppId(String appId) {
|
||||
if (StringUtils.isBlank(appId)) {
|
||||
return null;
|
||||
}
|
||||
return pileMerchantInfoMapper.getFirstLevelMerchantByAppId(appId);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -270,18 +282,12 @@ public class PileMerchantInfoServiceImpl implements IPileMerchantInfoService {
|
||||
*/
|
||||
@Override
|
||||
public String getFirstLevelMerchantIdByAppId(String appId) {
|
||||
if (StringUtils.isBlank(appId)) {
|
||||
return null;
|
||||
String merchantId = null;
|
||||
PileMerchantInfo merchant = getFirstLevelMerchantByAppId(appId);
|
||||
if (Objects.nonNull(merchant)) {
|
||||
merchantId = String.valueOf(merchant.getId());
|
||||
}
|
||||
try {
|
||||
String merchantId = pileMerchantInfoMapper.getFirstLevelMerchantIdByAppId(appId);
|
||||
if (StringUtils.isNotBlank(merchantId)) {
|
||||
return merchantId;
|
||||
}
|
||||
} catch (Exception e) {
|
||||
log.error("通过appid获取运营商id error", e);
|
||||
}
|
||||
return null;
|
||||
return merchantId;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -327,10 +333,6 @@ public class PileMerchantInfoServiceImpl implements IPileMerchantInfoService {
|
||||
return pileMerchantInfoMapper.queryInfoListByIds(deptIds);
|
||||
}
|
||||
|
||||
public List<String> getLoginUserMerchantIds() {
|
||||
AuthorizedDeptVO authorizedMap = SecurityUtils.getAuthorizedMap();
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询一级运营商列表
|
||||
@@ -388,5 +390,21 @@ public class PileMerchantInfoServiceImpl implements IPileMerchantInfoService {
|
||||
return pileMerchantInfoMapper.getDeptIdsByAppId(appId);
|
||||
}
|
||||
|
||||
/**
|
||||
* 通过wechatAppId查询一级运营商的延时支付模式配置
|
||||
* @param wechatAppId 微信小程序id
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public String getDelayModeByWechatAppId(String wechatAppId) {
|
||||
PileMerchantInfo merchant = getFirstLevelMerchantByAppId(wechatAppId);
|
||||
if (merchant != null) {
|
||||
String delayMode = merchant.getDelayMode();
|
||||
if (StringUtils.equals(delayMode, Constants.ONE)) {
|
||||
return Constants.ADAPAY_PAY_MODE_DELAY;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user