|
@@ -2,6 +2,7 @@ package com.fs.live.service.impl;
|
|
|
|
|
|
|
|
import java.lang.reflect.Field;
|
|
import java.lang.reflect.Field;
|
|
|
import java.math.BigDecimal;
|
|
import java.math.BigDecimal;
|
|
|
|
|
+import java.math.RoundingMode;
|
|
|
import java.sql.Timestamp;
|
|
import java.sql.Timestamp;
|
|
|
import java.text.DecimalFormat;
|
|
import java.text.DecimalFormat;
|
|
|
import java.text.ParseException;
|
|
import java.text.ParseException;
|
|
@@ -61,6 +62,7 @@ import com.fs.erp.domain.*;
|
|
|
import com.fs.erp.dto.*;
|
|
import com.fs.erp.dto.*;
|
|
|
import com.fs.erp.mapper.FsErpFinishPushMapper;
|
|
import com.fs.erp.mapper.FsErpFinishPushMapper;
|
|
|
import com.fs.erp.service.IErpOrderService;
|
|
import com.fs.erp.service.IErpOrderService;
|
|
|
|
|
+import com.fs.his.config.AppConfig;
|
|
|
import com.fs.his.config.FsSysConfig;
|
|
import com.fs.his.config.FsSysConfig;
|
|
|
import com.fs.his.domain.*;
|
|
import com.fs.his.domain.*;
|
|
|
import com.fs.his.enums.FsStoreOrderLogEnum;
|
|
import com.fs.his.enums.FsStoreOrderLogEnum;
|
|
@@ -68,6 +70,7 @@ import com.fs.his.mapper.*;
|
|
|
import com.fs.his.utils.ConfigUtil;
|
|
import com.fs.his.utils.ConfigUtil;
|
|
|
import com.fs.hisStore.config.FsErpConfig;
|
|
import com.fs.hisStore.config.FsErpConfig;
|
|
|
import com.fs.hisStore.config.StoreConfig;
|
|
import com.fs.hisStore.config.StoreConfig;
|
|
|
|
|
+import com.fs.hisStore.constants.StoreConstants;
|
|
|
import com.fs.hisStore.domain.*;
|
|
import com.fs.hisStore.domain.*;
|
|
|
import com.fs.hisStore.dto.*;
|
|
import com.fs.hisStore.dto.*;
|
|
|
import com.fs.hisStore.enums.*;
|
|
import com.fs.hisStore.enums.*;
|
|
@@ -95,17 +98,23 @@ import com.fs.live.param.*;
|
|
|
import com.fs.live.service.*;
|
|
import com.fs.live.service.*;
|
|
|
import com.fs.live.vo.*;
|
|
import com.fs.live.vo.*;
|
|
|
import com.fs.store.domain.*;
|
|
import com.fs.store.domain.*;
|
|
|
|
|
+import com.fs.system.domain.SysConfig;
|
|
|
import com.fs.system.service.ISysConfigService;
|
|
import com.fs.system.service.ISysConfigService;
|
|
|
import com.fs.wx.order.domain.FsWxExpressTask;
|
|
import com.fs.wx.order.domain.FsWxExpressTask;
|
|
|
import com.fs.wx.order.mapper.FsWxExpressTaskMapper;
|
|
import com.fs.wx.order.mapper.FsWxExpressTaskMapper;
|
|
|
import com.github.binarywang.wxpay.bean.order.WxPayMpOrderResult;
|
|
import com.github.binarywang.wxpay.bean.order.WxPayMpOrderResult;
|
|
|
import com.github.binarywang.wxpay.bean.request.WxPayRefundRequest;
|
|
import com.github.binarywang.wxpay.bean.request.WxPayRefundRequest;
|
|
|
|
|
+import com.github.binarywang.wxpay.bean.request.WxPayRefundV3Request;
|
|
|
import com.github.binarywang.wxpay.bean.request.WxPayUnifiedOrderRequest;
|
|
import com.github.binarywang.wxpay.bean.request.WxPayUnifiedOrderRequest;
|
|
|
import com.github.binarywang.wxpay.bean.result.WxPayRefundQueryResult;
|
|
import com.github.binarywang.wxpay.bean.result.WxPayRefundQueryResult;
|
|
|
|
|
+import com.github.binarywang.wxpay.bean.result.WxPayRefundQueryV3Result;
|
|
|
import com.github.binarywang.wxpay.bean.result.WxPayRefundResult;
|
|
import com.github.binarywang.wxpay.bean.result.WxPayRefundResult;
|
|
|
|
|
+import com.github.binarywang.wxpay.bean.result.WxPayRefundV3Result;
|
|
|
import com.github.binarywang.wxpay.config.WxPayConfig;
|
|
import com.github.binarywang.wxpay.config.WxPayConfig;
|
|
|
import com.github.binarywang.wxpay.exception.WxPayException;
|
|
import com.github.binarywang.wxpay.exception.WxPayException;
|
|
|
import com.github.binarywang.wxpay.service.WxPayService;
|
|
import com.github.binarywang.wxpay.service.WxPayService;
|
|
|
|
|
+import com.github.binarywang.wxpay.service.impl.WxPayServiceImpl;
|
|
|
|
|
+import com.google.gson.Gson;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
import me.chanjar.weixin.common.error.WxErrorException;
|
|
import me.chanjar.weixin.common.error.WxErrorException;
|
|
|
import org.apache.commons.collections4.CollectionUtils;
|
|
import org.apache.commons.collections4.CollectionUtils;
|
|
@@ -146,6 +155,8 @@ public class LiveOrderServiceImpl implements ILiveOrderService {
|
|
|
private FsUserWxMapper fsUserWxMapper;
|
|
private FsUserWxMapper fsUserWxMapper;
|
|
|
@Autowired
|
|
@Autowired
|
|
|
private RocketMQTemplate rocketMQTemplate;
|
|
private RocketMQTemplate rocketMQTemplate;
|
|
|
|
|
+ @Autowired
|
|
|
|
|
+ private CloudHostProper cloudHostProper;
|
|
|
|
|
|
|
|
@Autowired
|
|
@Autowired
|
|
|
private FsCoursePlaySourceConfigMapper fsCoursePlaySourceConfigMapper;
|
|
private FsCoursePlaySourceConfigMapper fsCoursePlaySourceConfigMapper;
|
|
@@ -821,7 +832,7 @@ public class LiveOrderServiceImpl implements ILiveOrderService {
|
|
|
paymentMap.setTradeNo(tradeNo);
|
|
paymentMap.setTradeNo(tradeNo);
|
|
|
paymentMap.setBankSerialNo(bankSerialNo);
|
|
paymentMap.setBankSerialNo(bankSerialNo);
|
|
|
paymentMap.setBankTransactionId(bankTransactionId);
|
|
paymentMap.setBankTransactionId(bankTransactionId);
|
|
|
- paymentMap.setPayTypeCode("微信小程序支付");
|
|
|
|
|
|
|
+ paymentMap.setPayTypeCode("wx_app");
|
|
|
liveOrderPaymentMapper.updateLiveOrderPayment(paymentMap);
|
|
liveOrderPaymentMapper.updateLiveOrderPayment(paymentMap);
|
|
|
order = baseMapper.selectFsUserVipOrderByOrderCode(storePayment.getBusinessCode());
|
|
order = baseMapper.selectFsUserVipOrderByOrderCode(storePayment.getBusinessCode());
|
|
|
if (order == null || !order.getStatus().equals(OrderInfoEnum.STATUS_0.getValue())) {
|
|
if (order == null || !order.getStatus().equals(OrderInfoEnum.STATUS_0.getValue())) {
|
|
@@ -1406,24 +1417,27 @@ public class LiveOrderServiceImpl implements ILiveOrderService {
|
|
|
//货到付款
|
|
//货到付款
|
|
|
} else {
|
|
} else {
|
|
|
//将钱退还给用户
|
|
//将钱退还给用户
|
|
|
- List<LiveOrderPayment> payments = liveOrderPaymentMapper.selectLiveOrderPaymentByPay(5, order.getOrderId());
|
|
|
|
|
|
|
+ List<LiveOrderPayment> payments = liveOrderPaymentMapper.selectLiveOrderPaymentByPay(9, order.getOrderId());
|
|
|
if (payments != null && !payments.isEmpty()) {
|
|
if (payments != null && !payments.isEmpty()) {
|
|
|
// String json = configService.selectConfigByKey("his.pay");
|
|
// String json = configService.selectConfigByKey("his.pay");
|
|
|
// FsPayConfigScrm fsPayConfig = JSON.parseObject(json, FsPayConfigScrm.class);
|
|
// FsPayConfigScrm fsPayConfig = JSON.parseObject(json, FsPayConfigScrm.class);
|
|
|
-
|
|
|
|
|
|
|
+ SysConfig sysConfig = configService.selectConfigByConfigKey("app.config");
|
|
|
|
|
+ AppConfig config = new Gson().fromJson(sysConfig.getConfigValue(), AppConfig.class);
|
|
|
for (LiveOrderPayment payment : payments) {
|
|
for (LiveOrderPayment payment : payments) {
|
|
|
- FsCoursePlaySourceConfig fsCoursePlaySourceConfig = fsCoursePlaySourceConfigMapper.selectCoursePlaySourceConfigByAppId(payment.getAppId());
|
|
|
|
|
- if (fsCoursePlaySourceConfig == null) {
|
|
|
|
|
- throw new CustomException("未找到appId对应的小程序配置: " + payment.getAppId());
|
|
|
|
|
|
|
+ if (order.getPayType().equals("99")||order.getPayType().equals("5")){
|
|
|
|
|
+ payment.setAppId(config.getAppId());
|
|
|
}
|
|
}
|
|
|
- Long merchantConfigId = fsCoursePlaySourceConfig.getMerchantConfigId();
|
|
|
|
|
- if (merchantConfigId == null || merchantConfigId <= 0) {
|
|
|
|
|
- throw new CustomException("小程序没有配置商户信息");
|
|
|
|
|
|
|
+// payment.setAppId(config.getAppId());
|
|
|
|
|
+
|
|
|
|
|
+ String payType = payment.getPayMode();
|
|
|
|
|
+ if ("wxApp".equals(payment.getPayMode())){
|
|
|
|
|
+ payType = "wx";
|
|
|
}
|
|
}
|
|
|
- MerchantAppConfig merchantAppConfig = merchantAppConfigMapper.selectMerchantAppConfigById(fsCoursePlaySourceConfig.getMerchantConfigId());
|
|
|
|
|
- FsPayConfig fsPayConfig = JSON.parseObject(merchantAppConfig.getDataJson(), FsPayConfig.class);
|
|
|
|
|
|
|
|
|
|
if (payment.getPayMode() == null || "wx".equals(payment.getPayMode())) {
|
|
if (payment.getPayMode() == null || "wx".equals(payment.getPayMode())) {
|
|
|
|
|
+ MerchantAppConfig merchantAppConfig = merchantAppConfigMapper.selectMerchantAppConfigByAppId(payment.getAppId(),payType);
|
|
|
|
|
+ FsPayConfig fsPayConfig = JSON.parseObject(merchantAppConfig.getDataJson(), FsPayConfig.class);
|
|
|
|
|
+
|
|
|
WxPayConfig payConfig = new WxPayConfig();
|
|
WxPayConfig payConfig = new WxPayConfig();
|
|
|
payConfig.setAppId(fsPayConfig.getAppId());
|
|
payConfig.setAppId(fsPayConfig.getAppId());
|
|
|
payConfig.setMchId(fsPayConfig.getWxMchId());
|
|
payConfig.setMchId(fsPayConfig.getWxMchId());
|
|
@@ -1456,19 +1470,19 @@ public class LiveOrderServiceImpl implements ILiveOrderService {
|
|
|
return R.error("退款请求失败" + e.getErrCodeDes());
|
|
return R.error("退款请求失败" + e.getErrCodeDes());
|
|
|
}
|
|
}
|
|
|
} else if (payment.getPayMode() != null && "hf".equals(payment.getPayMode())) {
|
|
} else if (payment.getPayMode() != null && "hf".equals(payment.getPayMode())) {
|
|
|
|
|
+ MerchantAppConfig merchantAppConfig = merchantAppConfigMapper.selectMerchantAppConfigByAppId(payment.getAppId(),payType);
|
|
|
|
|
+ FsPayConfig fsPayConfig = JSON.parseObject(merchantAppConfig.getDataJson(), FsPayConfig.class);
|
|
|
|
|
+
|
|
|
String huifuId = "";
|
|
String huifuId = "";
|
|
|
- FsHfpayConfigMapper fsHfpayConfigMapper = SpringUtils.getBean(FsHfpayConfigMapper.class);
|
|
|
|
|
if (payment.getAppId() != null) {
|
|
if (payment.getAppId() != null) {
|
|
|
- FsHfpayConfig fsHfpayConfig = fsHfpayConfigMapper.selectByAppId(payment.getAppId());
|
|
|
|
|
- if (fsHfpayConfig != null) {
|
|
|
|
|
- huifuId = fsHfpayConfig.getHuifuId();
|
|
|
|
|
|
|
+ if (merchantAppConfig != null) {
|
|
|
|
|
+ huifuId = merchantAppConfig.getMerchantId();
|
|
|
}
|
|
}
|
|
|
} else {
|
|
} else {
|
|
|
CloudHostProper cloudHostProper = SpringUtils.getBean(CloudHostProper.class);
|
|
CloudHostProper cloudHostProper = SpringUtils.getBean(CloudHostProper.class);
|
|
|
if ("益善缘".equals(cloudHostProper.getCompanyName())) {
|
|
if ("益善缘".equals(cloudHostProper.getCompanyName())) {
|
|
|
- FsHfpayConfig fsPayConfig2 = fsHfpayConfigMapper.selectByAppId("wx0d1a3dd485268521");
|
|
|
|
|
- if (fsPayConfig2 != null) {
|
|
|
|
|
- huifuId = fsPayConfig2.getHuifuId();
|
|
|
|
|
|
|
+ if (merchantAppConfig != null) {
|
|
|
|
|
+ huifuId = merchantAppConfig.getMerchantId();
|
|
|
}
|
|
}
|
|
|
} else {
|
|
} else {
|
|
|
huifuId = fsPayConfig.getHuifuId();
|
|
huifuId = fsPayConfig.getHuifuId();
|
|
@@ -1482,9 +1496,16 @@ public class LiveOrderServiceImpl implements ILiveOrderService {
|
|
|
request.setOrgReqDate(new SimpleDateFormat("yyyyMMdd").format(payment.getCreateTime()));
|
|
request.setOrgReqDate(new SimpleDateFormat("yyyyMMdd").format(payment.getCreateTime()));
|
|
|
request.setReqSeqId("refund-" + payment.getPayCode());
|
|
request.setReqSeqId("refund-" + payment.getPayCode());
|
|
|
Map<String, Object> extendInfoMap = new HashMap<>();
|
|
Map<String, Object> extendInfoMap = new HashMap<>();
|
|
|
- extendInfoMap.put("org_party_order_id", payment.getBankSerialNo());
|
|
|
|
|
|
|
+
|
|
|
|
|
+ if (order.getPayType().equals("99")){
|
|
|
|
|
+ request.setOrdAmt(payment.getPayMoney().setScale(2, RoundingMode.DOWN).toString());
|
|
|
|
|
+ extendInfoMap.put("org_req_seq_id", "live-"+payment.getPayCode());
|
|
|
|
|
+ }else {
|
|
|
|
|
+ request.setOrdAmt(payment.getPayMoney().toString());
|
|
|
|
|
+ extendInfoMap.put("org_party_order_id", payment.getBankSerialNo());
|
|
|
|
|
+ request.setAppId(payment.getAppId());
|
|
|
|
|
+ }
|
|
|
request.setExtendInfo(extendInfoMap);
|
|
request.setExtendInfo(extendInfoMap);
|
|
|
- request.setAppId(payment.getAppId());
|
|
|
|
|
HuiFuRefundResult refund = huiFuService.refund(request);
|
|
HuiFuRefundResult refund = huiFuService.refund(request);
|
|
|
log.info("退款:" + refund);
|
|
log.info("退款:" + refund);
|
|
|
if (refund != null && ("00000000".equals(refund.getResp_code()) || "00000100".equals(refund.getResp_code()))
|
|
if (refund != null && ("00000000".equals(refund.getResp_code()) || "00000100".equals(refund.getResp_code()))
|
|
@@ -1497,6 +1518,44 @@ public class LiveOrderServiceImpl implements ILiveOrderService {
|
|
|
TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
|
|
TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
|
|
|
return R.error(refund != null ? refund.getResp_desc() : "退款失败");
|
|
return R.error(refund != null ? refund.getResp_desc() : "退款失败");
|
|
|
}
|
|
}
|
|
|
|
|
+ } else if ("wxApp".equals(payment.getPayMode()) && "wx_app".equals(payment.getPayTypeCode())) {
|
|
|
|
|
+ // 微信 App 支付退款(APIv3)
|
|
|
|
|
+ WxPayService wxPayService = getWxPayService(payment.getAppId(), payType);
|
|
|
|
|
+ WxPayRefundV3Request refundRequest = new WxPayRefundV3Request();
|
|
|
|
|
+ refundRequest.setOutTradeNo("live-" + payment.getPayCode());
|
|
|
|
|
+ refundRequest.setOutRefundNo("live-" + payment.getPayCode());
|
|
|
|
|
+ WxPayRefundV3Request.Amount amount = new WxPayRefundV3Request.Amount();
|
|
|
|
|
+ Integer money = WxPayUnifiedOrderRequest.yuanToFen(payment.getPayMoney().toString());
|
|
|
|
|
+ amount.setRefund(money);
|
|
|
|
|
+ amount.setTotal(money);
|
|
|
|
|
+ amount.setCurrency("CNY");
|
|
|
|
|
+ refundRequest.setAmount(amount);
|
|
|
|
|
+ try {
|
|
|
|
|
+ WxPayRefundV3Result refundResult = wxPayService.refundV3(refundRequest);
|
|
|
|
|
+ WxPayRefundQueryV3Result refundQueryResult = wxPayService.refundQueryV3(refundResult.getOutRefundNo());
|
|
|
|
|
+ if (refundQueryResult != null && "SUCCESS".equals(refundQueryResult.getStatus())) {
|
|
|
|
|
+ LiveOrderPayment paymentMap = new LiveOrderPayment();
|
|
|
|
|
+ paymentMap.setPaymentId(payment.getPaymentId());
|
|
|
|
|
+ paymentMap.setStatus(-1);
|
|
|
|
|
+ paymentMap.setRefundTime(DateUtils.getNowDate());
|
|
|
|
|
+ paymentMap.setRefundMoney(payment.getPayMoney());
|
|
|
|
|
+ liveOrderPaymentMapper.updateLiveOrderPayment(paymentMap);
|
|
|
|
|
+ } else {
|
|
|
|
|
+ String errMsg = refundQueryResult == null ? "退款查询为空" : refundQueryResult.getStatus();
|
|
|
|
|
+ throw new CustomException("退款请求失败" + errMsg);
|
|
|
|
|
+ }
|
|
|
|
|
+ } catch (WxPayException e) {
|
|
|
|
|
+ throw new CustomException("退款请求失败" + e.getCustomErrorMsg());
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ }else if (payment.getPayMode()!=null&&payment.getPayMode().equals("cz")) {
|
|
|
|
|
+ LiveOrderPayment paymentMap = new LiveOrderPayment();
|
|
|
|
|
+ paymentMap.setPaymentId(payment.getPaymentId());
|
|
|
|
|
+ paymentMap.setStatus(-1);
|
|
|
|
|
+ paymentMap.setRefundTime(DateUtils.getNowDate());
|
|
|
|
|
+ paymentMap.setRefundMoney(payment.getPayMoney());
|
|
|
|
|
+ liveOrderPaymentMapper.updateLiveOrderPayment(paymentMap);
|
|
|
|
|
+ FsUserScrm fsUserScrm = userService.selectFsUserById(Long.valueOf(order.getUserId()));
|
|
|
} else {
|
|
} else {
|
|
|
TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
|
|
TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
|
|
|
return R.error("支付类型异常");
|
|
return R.error("支付类型异常");
|
|
@@ -1521,10 +1580,44 @@ public class LiveOrderServiceImpl implements ILiveOrderService {
|
|
|
userService.subTuiMoney(storeOrder);
|
|
userService.subTuiMoney(storeOrder);
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
-
|
|
|
|
|
return R.ok();
|
|
return R.ok();
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 封装微信参数
|
|
|
|
|
+ *
|
|
|
|
|
+ * @param appId 应用appId
|
|
|
|
|
+ * @param payType 支付类型
|
|
|
|
|
+ * @return
|
|
|
|
|
+ */
|
|
|
|
|
+ private WxPayService getWxPayService(String appId, String payType){
|
|
|
|
|
+ MerchantAppConfig merchantAppConfig = merchantAppConfigMapper.selectMerchantAppConfigByAppId(appId, payType);
|
|
|
|
|
+ if (merchantAppConfig == null) {
|
|
|
|
|
+ throw new CustomException("未找到appId对应的商户配置: " + appId);
|
|
|
|
|
+ }
|
|
|
|
|
+ FsPayConfig fsPayConfig = JSON.parseObject(merchantAppConfig.getDataJson(), FsPayConfig.class);
|
|
|
|
|
+
|
|
|
|
|
+ WxPayConfig payConfig = new WxPayConfig();
|
|
|
|
|
+ payConfig.setAppId(appId);
|
|
|
|
|
+ payConfig.setMchId(fsPayConfig.getWxMchId());
|
|
|
|
|
+ payConfig.setMchKey(fsPayConfig.getWxMchKey());
|
|
|
|
|
+ payConfig.setSubAppId(StringUtils.trimToNull(null));
|
|
|
|
|
+ payConfig.setSubMchId(StringUtils.trimToNull(null));
|
|
|
|
|
+ payConfig.setKeyPath(fsPayConfig.getKeyPath());
|
|
|
|
|
+ if (StringUtils.isNotBlank(fsPayConfig.getPublicKeyId())
|
|
|
|
|
+ && StringUtils.isNotBlank(fsPayConfig.getPublicKeyPath())) {
|
|
|
|
|
+ payConfig.setPublicKeyId(fsPayConfig.getPublicKeyId());
|
|
|
|
|
+ payConfig.setPublicKeyPath(fsPayConfig.getPublicKeyPath());
|
|
|
|
|
+ }
|
|
|
|
|
+ payConfig.setApiV3Key(fsPayConfig.getWxApiV3Key());
|
|
|
|
|
+ payConfig.setPrivateKeyPath(fsPayConfig.getPrivateKeyPath());
|
|
|
|
|
+ payConfig.setPrivateCertPath(fsPayConfig.getPrivateCertPath());
|
|
|
|
|
+ payConfig.setNotifyUrl(fsPayConfig.getNotifyUrlScrm());
|
|
|
|
|
+ WxPayServiceImpl payService = new WxPayServiceImpl();
|
|
|
|
|
+ payService.setConfig(payConfig);
|
|
|
|
|
+ return payService;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
@Override
|
|
@Override
|
|
|
@Transactional(rollbackFor = Exception.class)
|
|
@Transactional(rollbackFor = Exception.class)
|
|
|
public R refundOrderMoney(Long orderId, LiveAfterSales liveAfterSales) {
|
|
public R refundOrderMoney(Long orderId, LiveAfterSales liveAfterSales) {
|
|
@@ -1626,26 +1719,26 @@ public class LiveOrderServiceImpl implements ILiveOrderService {
|
|
|
if (payments != null && !payments.isEmpty()) {
|
|
if (payments != null && !payments.isEmpty()) {
|
|
|
// String json = configService.selectConfigByKey("his.pay");
|
|
// String json = configService.selectConfigByKey("his.pay");
|
|
|
// FsPayConfigScrm fsPayConfig = JSON.parseObject(json, FsPayConfigScrm.class);
|
|
// FsPayConfigScrm fsPayConfig = JSON.parseObject(json, FsPayConfigScrm.class);
|
|
|
|
|
+ SysConfig sysConfig = configService.selectConfigByConfigKey("app.config");
|
|
|
|
|
+ AppConfig config = new Gson().fromJson(sysConfig.getConfigValue(), AppConfig.class);
|
|
|
|
|
|
|
|
for (LiveOrderPayment payment : payments) {
|
|
for (LiveOrderPayment payment : payments) {
|
|
|
- FsCoursePlaySourceConfig fsCoursePlaySourceConfig = fsCoursePlaySourceConfigMapper.selectCoursePlaySourceConfigByAppId(payment.getAppId());
|
|
|
|
|
- if (fsCoursePlaySourceConfig == null) {
|
|
|
|
|
- throw new CustomException("未找到appId对应的小程序配置: " + payment.getAppId());
|
|
|
|
|
|
|
+ if (order.getPayType().equals("99")||order.getPayType().equals("5")){
|
|
|
|
|
+ payment.setAppId(config.getAppId());
|
|
|
}
|
|
}
|
|
|
- Long merchantConfigId = fsCoursePlaySourceConfig.getMerchantConfigId();
|
|
|
|
|
- if (merchantConfigId == null || merchantConfigId <= 0) {
|
|
|
|
|
- throw new CustomException("小程序没有配置商户信息");
|
|
|
|
|
|
|
+ if (StringUtils.isBlank(payment.getAppId())) {
|
|
|
|
|
+ throw new IllegalArgumentException("appId不能为空");
|
|
|
}
|
|
}
|
|
|
- Long merConfigId = fsCoursePlaySourceConfig.getMerchantConfigId();
|
|
|
|
|
- if (payment.getMerConfigId() != null) {
|
|
|
|
|
- merConfigId = payment.getMerConfigId();
|
|
|
|
|
|
|
+ String payType = payment.getPayMode();
|
|
|
|
|
+ if ("wxApp".equals(payment.getPayMode())){
|
|
|
|
|
+ payType = "wx";
|
|
|
}
|
|
}
|
|
|
- MerchantAppConfig merchantAppConfig = merchantAppConfigMapper.selectMerchantAppConfigById(merConfigId);
|
|
|
|
|
- FsPayConfig fsPayConfig = JSON.parseObject(merchantAppConfig.getDataJson(), FsPayConfig.class);
|
|
|
|
|
|
|
|
|
|
if (payment.getPayMode() == null || "wx".equals(payment.getPayMode())) {
|
|
if (payment.getPayMode() == null || "wx".equals(payment.getPayMode())) {
|
|
|
|
|
+ MerchantAppConfig merchantAppConfig = merchantAppConfigMapper.selectMerchantAppConfigByAppId(payment.getAppId(),payType);
|
|
|
|
|
+ FsPayConfig fsPayConfig = JSON.parseObject(merchantAppConfig.getDataJson(), FsPayConfig.class);
|
|
|
WxPayConfig payConfig = new WxPayConfig();
|
|
WxPayConfig payConfig = new WxPayConfig();
|
|
|
- payConfig.setAppId(fsPayConfig.getAppId());
|
|
|
|
|
|
|
+ payConfig.setAppId(payment.getAppId());
|
|
|
payConfig.setMchId(fsPayConfig.getWxMchId());
|
|
payConfig.setMchId(fsPayConfig.getWxMchId());
|
|
|
payConfig.setMchKey(fsPayConfig.getWxMchKey());
|
|
payConfig.setMchKey(fsPayConfig.getWxMchKey());
|
|
|
payConfig.setKeyPath(fsPayConfig.getKeyPath());
|
|
payConfig.setKeyPath(fsPayConfig.getKeyPath());
|
|
@@ -1674,36 +1767,41 @@ public class LiveOrderServiceImpl implements ILiveOrderService {
|
|
|
return R.error("退款请求失败" + e.getErrCodeDes());
|
|
return R.error("退款请求失败" + e.getErrCodeDes());
|
|
|
}
|
|
}
|
|
|
} else if (payment.getPayMode() != null && "hf".equals(payment.getPayMode())) {
|
|
} else if (payment.getPayMode() != null && "hf".equals(payment.getPayMode())) {
|
|
|
|
|
+ MerchantAppConfig merchantAppConfig = merchantAppConfigMapper.selectMerchantAppConfigByAppId(payment.getAppId(),payType);
|
|
|
|
|
+ FsPayConfig fsPayConfig = JSON.parseObject(merchantAppConfig.getDataJson(), FsPayConfig.class);
|
|
|
String huifuId = "";
|
|
String huifuId = "";
|
|
|
- FsHfpayConfigMapper fsHfpayConfigMapper = SpringUtils.getBean(FsHfpayConfigMapper.class);
|
|
|
|
|
if (payment.getAppId() != null) {
|
|
if (payment.getAppId() != null) {
|
|
|
- FsHfpayConfig fsHfpayConfig = fsHfpayConfigMapper.selectByAppId(payment.getAppId());
|
|
|
|
|
- if (fsHfpayConfig == null) {
|
|
|
|
|
|
|
+ if (merchantAppConfig == null){
|
|
|
huifuId = fsPayConfig.getHuifuId();
|
|
huifuId = fsPayConfig.getHuifuId();
|
|
|
- } else {
|
|
|
|
|
- huifuId = fsHfpayConfig.getHuifuId();
|
|
|
|
|
|
|
+ }else {
|
|
|
|
|
+ huifuId = merchantAppConfig.getMerchantId();
|
|
|
}
|
|
}
|
|
|
} else {
|
|
} else {
|
|
|
- CloudHostProper cloudHostProper = SpringUtils.getBean(CloudHostProper.class);
|
|
|
|
|
- if ("益善缘".equals(cloudHostProper.getCompanyName())) {
|
|
|
|
|
- FsHfpayConfig fsPayConfig2 = fsHfpayConfigMapper.selectByAppId("wx0d1a3dd485268521");
|
|
|
|
|
- huifuId = fsPayConfig2.getHuifuId();
|
|
|
|
|
- } else {
|
|
|
|
|
- huifuId = fsPayConfig.getHuifuId();
|
|
|
|
|
|
|
+ if (("益善缘".equals(cloudHostProper.getCompanyName()))) {
|
|
|
|
|
+
|
|
|
|
|
+ huifuId = merchantAppConfig.getMerchantId();
|
|
|
|
|
+ }else {
|
|
|
|
|
+ huifuId=fsPayConfig.getHuifuId();
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
V2TradePaymentScanpayRefundRequest request = new V2TradePaymentScanpayRefundRequest();
|
|
V2TradePaymentScanpayRefundRequest request = new V2TradePaymentScanpayRefundRequest();
|
|
|
- DecimalFormat df = new DecimalFormat("0.00");
|
|
|
|
|
request.setOrgHfSeqId(payment.getTradeNo());
|
|
request.setOrgHfSeqId(payment.getTradeNo());
|
|
|
request.setHuifuId(huifuId);
|
|
request.setHuifuId(huifuId);
|
|
|
- request.setOrdAmt(df.format(refundAmount));
|
|
|
|
|
|
|
+
|
|
|
|
|
+ Map<String, Object> extendInfoMap = new HashMap<>();
|
|
|
|
|
+ if (order.getPayType().equals("99")){
|
|
|
|
|
+ request.setOrdAmt(payment.getPayMoney().setScale(2, RoundingMode.DOWN).toString());
|
|
|
|
|
+ extendInfoMap.put("org_req_seq_id", "live-"+payment.getPayCode());
|
|
|
|
|
+ }else {
|
|
|
|
|
+ request.setOrdAmt(payment.getPayMoney().toString());
|
|
|
|
|
+ extendInfoMap.put("org_party_order_id", payment.getBankSerialNo());
|
|
|
|
|
+ request.setAppId(payment.getAppId());
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
request.setOrgReqDate(new SimpleDateFormat("yyyyMMdd").format(payment.getCreateTime()));
|
|
request.setOrgReqDate(new SimpleDateFormat("yyyyMMdd").format(payment.getCreateTime()));
|
|
|
request.setReqSeqId("refund-" + payment.getPayCode());
|
|
request.setReqSeqId("refund-" + payment.getPayCode());
|
|
|
- Map<String, Object> extendInfoMap = new HashMap<>();
|
|
|
|
|
- extendInfoMap.put("org_party_order_id", payment.getBankSerialNo());
|
|
|
|
|
request.setExtendInfo(extendInfoMap);
|
|
request.setExtendInfo(extendInfoMap);
|
|
|
- request.setAppId(payment.getAppId());
|
|
|
|
|
HuiFuRefundResult refund = huiFuService.refund(request);
|
|
HuiFuRefundResult refund = huiFuService.refund(request);
|
|
|
log.info("退款:" + refund);
|
|
log.info("退款:" + refund);
|
|
|
if (refund != null && ("00000000".equals(refund.getResp_code()) || "00000100".equals(refund.getResp_code()))
|
|
if (refund != null && ("00000000".equals(refund.getResp_code()) || "00000100".equals(refund.getResp_code()))
|
|
@@ -1716,6 +1814,45 @@ public class LiveOrderServiceImpl implements ILiveOrderService {
|
|
|
TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
|
|
TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
|
|
|
return R.error(refund != null ? refund.getResp_desc() : "退款失败");
|
|
return R.error(refund != null ? refund.getResp_desc() : "退款失败");
|
|
|
}
|
|
}
|
|
|
|
|
+ }else if (payment.getPayMode() != null &&"wxApp".equals(payment.getPayMode())) {
|
|
|
|
|
+ // 微信 App 支付退款(APIv3)
|
|
|
|
|
+ WxPayService wxPayService = getWxPayService(payment.getAppId(), payType);
|
|
|
|
|
+ WxPayRefundV3Request refundRequest = new WxPayRefundV3Request();
|
|
|
|
|
+ refundRequest.setOutTradeNo("live-" + payment.getPayCode());
|
|
|
|
|
+ refundRequest.setOutRefundNo("live-" + payment.getPayCode());
|
|
|
|
|
+ WxPayRefundV3Request.Amount amount = new WxPayRefundV3Request.Amount();
|
|
|
|
|
+ Integer totalFen = WxPayUnifiedOrderRequest.yuanToFen(payment.getPayMoney().toString());
|
|
|
|
|
+ Integer refundFen = WxPayUnifiedOrderRequest.yuanToFen(refundAmount.toString());
|
|
|
|
|
+ amount.setRefund(refundFen);
|
|
|
|
|
+ amount.setTotal(totalFen);
|
|
|
|
|
+ amount.setCurrency("CNY");
|
|
|
|
|
+ refundRequest.setAmount(amount);
|
|
|
|
|
+ try {
|
|
|
|
|
+ WxPayRefundV3Result refundResult = wxPayService.refundV3(refundRequest);
|
|
|
|
|
+ WxPayRefundQueryV3Result refundQueryResult = wxPayService.refundQueryV3(refundResult.getOutRefundNo());
|
|
|
|
|
+ if (refundQueryResult != null && "SUCCESS".equals(refundQueryResult.getStatus())) {
|
|
|
|
|
+ LiveOrderPayment paymentMap = new LiveOrderPayment();
|
|
|
|
|
+ paymentMap.setPaymentId(payment.getPaymentId());
|
|
|
|
|
+ paymentMap.setStatus(-1);
|
|
|
|
|
+ paymentMap.setRefundTime(DateUtils.getNowDate());
|
|
|
|
|
+ paymentMap.setRefundMoney(refundAmount);
|
|
|
|
|
+ liveOrderPaymentMapper.updateLiveOrderPayment(paymentMap);
|
|
|
|
|
+ } else {
|
|
|
|
|
+ String errMsg = refundQueryResult == null ? "退款查询为空" : refundQueryResult.getStatus();
|
|
|
|
|
+ throw new CustomException("退款请求失败" + errMsg);
|
|
|
|
|
+ }
|
|
|
|
|
+ } catch (WxPayException e) {
|
|
|
|
|
+ throw new CustomException("退款请求失败" + e.getCustomErrorMsg());
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ }else if (payment.getPayMode()!=null&&payment.getPayMode().equals("cz")) {
|
|
|
|
|
+// TODO 储值退款
|
|
|
|
|
+ LiveOrderPayment paymentMap = new LiveOrderPayment();
|
|
|
|
|
+ paymentMap.setPaymentId(payment.getPaymentId());
|
|
|
|
|
+ paymentMap.setStatus(-1);
|
|
|
|
|
+ paymentMap.setRefundTime(DateUtils.getNowDate());
|
|
|
|
|
+ paymentMap.setRefundMoney(payment.getPayMoney());
|
|
|
|
|
+ liveOrderPaymentMapper.updateLiveOrderPayment(paymentMap);
|
|
|
} else {
|
|
} else {
|
|
|
TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
|
|
TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
|
|
|
return R.error("支付类型异常");
|
|
return R.error("支付类型异常");
|
|
@@ -1741,7 +1878,7 @@ public class LiveOrderServiceImpl implements ILiveOrderService {
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
//优惠券返回
|
|
//优惠券返回
|
|
|
- if (order.getUserCouponId() != null) {
|
|
|
|
|
|
|
+ if(order.getUserCouponId()!=null){
|
|
|
// 退券
|
|
// 退券
|
|
|
order.setCouponUserId(Long.parseLong(order.getUserId()));
|
|
order.setCouponUserId(Long.parseLong(order.getUserId()));
|
|
|
this.refundCoupon(order);
|
|
this.refundCoupon(order);
|