|
@@ -29,6 +29,7 @@ import com.fs.erp.dto.ErpRefundUpdateRequest;
|
|
|
import com.fs.erp.mapper.FsJstAftersalePushMapper;
|
|
import com.fs.erp.mapper.FsJstAftersalePushMapper;
|
|
|
import com.fs.erp.mapper.FsJstAftersalePushScrmMapper;
|
|
import com.fs.erp.mapper.FsJstAftersalePushScrmMapper;
|
|
|
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.FsStoreAfterSalesStatusEnum;
|
|
import com.fs.his.enums.FsStoreAfterSalesStatusEnum;
|
|
@@ -68,6 +69,7 @@ import com.github.binarywang.wxpay.bean.result.WxPayRefundResult;
|
|
|
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 com.google.gson.Gson;
|
|
|
import lombok.Synchronized;
|
|
import lombok.Synchronized;
|
|
|
import org.apache.commons.beanutils.BeanUtils;
|
|
import org.apache.commons.beanutils.BeanUtils;
|
|
@@ -82,6 +84,7 @@ import org.springframework.transaction.interceptor.TransactionAspectSupport;
|
|
|
import java.lang.reflect.Field;
|
|
import java.lang.reflect.Field;
|
|
|
import java.lang.reflect.InvocationTargetException;
|
|
import java.lang.reflect.InvocationTargetException;
|
|
|
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;
|
|
@@ -858,25 +861,26 @@ public class FsStoreAfterSalesScrmServiceImpl implements IFsStoreAfterSalesScrmS
|
|
|
if(order.getPayMoney().compareTo(BigDecimal.ZERO)==1){
|
|
if(order.getPayMoney().compareTo(BigDecimal.ZERO)==1){
|
|
|
List<FsStorePaymentScrm> payments=paymentService.selectFsStorePaymentByOrderId(order.getId());
|
|
List<FsStorePaymentScrm> payments=paymentService.selectFsStorePaymentByOrderId(order.getId());
|
|
|
if(payments!=null){
|
|
if(payments!=null){
|
|
|
|
|
+ SysConfig sysConfig = configService.selectConfigByConfigKey("app.config");
|
|
|
|
|
+ AppConfig config = new Gson().fromJson(sysConfig.getConfigValue(), AppConfig.class);
|
|
|
|
|
|
|
|
for(FsStorePaymentScrm payment:payments){
|
|
for(FsStorePaymentScrm payment:payments){
|
|
|
|
|
+ if (order.getPayType().equals("99")){
|
|
|
|
|
+ payment.setAppId(config.getAppId());
|
|
|
|
|
+ }
|
|
|
if (StringUtils.isBlank(payment.getAppId())) {
|
|
if (StringUtils.isBlank(payment.getAppId())) {
|
|
|
throw new IllegalArgumentException("appId不能为空");
|
|
throw new IllegalArgumentException("appId不能为空");
|
|
|
}
|
|
}
|
|
|
- FsCoursePlaySourceConfig fsCoursePlaySourceConfig = fsCoursePlaySourceConfigMapper.selectCoursePlaySourceConfigByAppId(payment.getAppId());
|
|
|
|
|
- if (fsCoursePlaySourceConfig == null) {
|
|
|
|
|
- throw new CustomException("未找到appId对应的小程序配置: " + payment.getAppId());
|
|
|
|
|
- }
|
|
|
|
|
- Long merchantConfigId = fsCoursePlaySourceConfig.getMerchantConfigId();
|
|
|
|
|
- if (merchantConfigId == null || merchantConfigId <= 0) {
|
|
|
|
|
- throw new CustomException("小程序没有配置商户信息");
|
|
|
|
|
|
|
+ String payType = payment.getPayMode();
|
|
|
|
|
+ if ("wxApp".equals(payment.getPayMode())){
|
|
|
|
|
+ payType = "wx";
|
|
|
}
|
|
}
|
|
|
- MerchantAppConfig merchantAppConfig = merchantAppConfigMapper.selectMerchantAppConfigById(fsCoursePlaySourceConfig.getMerchantConfigId());
|
|
|
|
|
|
|
+ MerchantAppConfig merchantAppConfig = merchantAppConfigMapper.selectMerchantAppConfigByAppId(payment.getAppId(),payType);
|
|
|
FsPayConfig fsPayConfig = JSON.parseObject(merchantAppConfig.getDataJson(), FsPayConfig.class);
|
|
FsPayConfig fsPayConfig = JSON.parseObject(merchantAppConfig.getDataJson(), FsPayConfig.class);
|
|
|
|
|
|
|
|
if (payment.getPayMode()==null||payment.getPayMode().equals("wx")){
|
|
if (payment.getPayMode()==null||payment.getPayMode().equals("wx")){
|
|
|
WxPayConfig payConfig = new WxPayConfig();
|
|
WxPayConfig payConfig = new WxPayConfig();
|
|
|
- payConfig.setAppId(fsCoursePlaySourceConfig.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());
|
|
@@ -907,34 +911,36 @@ public class FsStoreAfterSalesScrmServiceImpl implements IFsStoreAfterSalesScrmS
|
|
|
}
|
|
}
|
|
|
}else if (payment.getPayMode()!=null&&payment.getPayMode().equals("hf")){
|
|
}else if (payment.getPayMode()!=null&&payment.getPayMode().equals("hf")){
|
|
|
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 {
|
|
}else {
|
|
|
- huifuId = fsHfpayConfig.getHuifuId();
|
|
|
|
|
|
|
+ huifuId = merchantAppConfig.getMerchantId();
|
|
|
}
|
|
}
|
|
|
} else {
|
|
} else {
|
|
|
if (("益善缘".equals(cloudHostProper.getCompanyName()))) {
|
|
if (("益善缘".equals(cloudHostProper.getCompanyName()))) {
|
|
|
|
|
|
|
|
- FsHfpayConfig fsPayConfig2 = fsHfpayConfigMapper.selectByAppId("wx0d1a3dd485268521");
|
|
|
|
|
- huifuId = fsPayConfig2.getHuifuId();
|
|
|
|
|
|
|
+ huifuId = merchantAppConfig.getMerchantId();
|
|
|
}else {
|
|
}else {
|
|
|
huifuId=fsPayConfig.getHuifuId();
|
|
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", "store-"+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);
|
|
|
logger.info("退款:"+refund);
|
|
logger.info("退款:"+refund);
|
|
|
if((refund.getResp_code().equals("00000000")||refund.getResp_code().equals("00000100"))&&(refund.getTrans_stat().equals("S")||refund.getTrans_stat().equals("P"))){
|
|
if((refund.getResp_code().equals("00000000")||refund.getResp_code().equals("00000100"))&&(refund.getTrans_stat().equals("S")||refund.getTrans_stat().equals("P"))){
|
|
@@ -947,7 +953,33 @@ public class FsStoreAfterSalesScrmServiceImpl implements IFsStoreAfterSalesScrmS
|
|
|
return R.error(refund.getResp_desc());
|
|
return R.error(refund.getResp_desc());
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- }else {
|
|
|
|
|
|
|
+ }else if ("wxApp".equals(payment.getPayMode()) && "wx_app".equals(payment.getPayTypeCode())) {
|
|
|
|
|
+ // 处理微信退款
|
|
|
|
|
+ WxPayService wxPayService = getWxPayService();
|
|
|
|
|
+ WxPayRefundRequest refundRequest = new WxPayRefundRequest();
|
|
|
|
|
+ refundRequest.setOutTradeNo("store-"+payment.getPayCode());
|
|
|
|
|
+ refundRequest.setOutRefundNo("store-"+payment.getPayCode());
|
|
|
|
|
+ refundRequest.setTotalFee(WxPayUnifiedOrderRequest.yuanToFen(payment.getPayMoney().toString()));
|
|
|
|
|
+ refundRequest.setRefundFee(WxPayUnifiedOrderRequest.yuanToFen(payment.getPayMoney().toString()));
|
|
|
|
|
+ try {
|
|
|
|
|
+ WxPayRefundResult refundResult = wxPayService.refund(refundRequest);
|
|
|
|
|
+ WxPayRefundQueryResult refundQueryResult = wxPayService.refundQuery("", refundResult.getOutTradeNo(), refundResult.getOutRefundNo(), refundResult.getRefundId());
|
|
|
|
|
+ if (refundQueryResult != null && refundQueryResult.getResultCode().equals("SUCCESS")) {
|
|
|
|
|
+ FsStorePaymentScrm paymentMap = new FsStorePaymentScrm();
|
|
|
|
|
+ paymentMap.setPaymentId(payment.getPaymentId());
|
|
|
|
|
+ paymentMap.setStatus(-1);
|
|
|
|
|
+ paymentMap.setRefundTime(DateUtils.getNowDate());
|
|
|
|
|
+ paymentMap.setRefundMoney(payment.getPayMoney());
|
|
|
|
|
+ paymentService.updateFsStorePayment(paymentMap);
|
|
|
|
|
+ } else {
|
|
|
|
|
+ throw new CustomException("退款请求失败" + refundQueryResult.getReturnMsg());
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ } catch (WxPayException e) {
|
|
|
|
|
+ throw new CustomException("退款请求失败" + e);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ } else {
|
|
|
TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
|
|
TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
|
|
|
return R.error("支付类型异常");
|
|
return R.error("支付类型异常");
|
|
|
}
|
|
}
|
|
@@ -968,7 +1000,33 @@ public class FsStoreAfterSalesScrmServiceImpl implements IFsStoreAfterSalesScrmS
|
|
|
this.deletePurchaseLimitRecordsForStoreOrder(order);
|
|
this.deletePurchaseLimitRecordsForStoreOrder(order);
|
|
|
return R.ok();
|
|
return R.ok();
|
|
|
}
|
|
}
|
|
|
-
|
|
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 封装微信参数
|
|
|
|
|
+ *
|
|
|
|
|
+ * @return
|
|
|
|
|
+ */
|
|
|
|
|
+ private WxPayService getWxPayService(){
|
|
|
|
|
+ SysConfig sysConfig = configService.selectConfigByConfigKey("app.config");
|
|
|
|
|
+ AppConfig config = new Gson().fromJson(sysConfig.getConfigValue(), AppConfig.class);
|
|
|
|
|
+ FsCoursePlaySourceConfig fsCoursePlaySourceConfig = fsCoursePlaySourceConfigMapper.selectCoursePlaySourceConfigByAppId(config.getAppId());
|
|
|
|
|
+ if (fsCoursePlaySourceConfig == null) {
|
|
|
|
|
+ throw new CustomException("未找到appId对应的小程序配置: " + config.getAppId());
|
|
|
|
|
+ }
|
|
|
|
|
+ MerchantAppConfig merchantAppConfig = merchantAppConfigMapper.selectMerchantAppConfigById(fsCoursePlaySourceConfig.getMerchantConfigId());
|
|
|
|
|
+ FsPayConfig payConfig1 = JSON.parseObject(merchantAppConfig.getDataJson(), FsPayConfig.class);
|
|
|
|
|
+
|
|
|
|
|
+ WxPayConfig payConfig = new WxPayConfig();
|
|
|
|
|
+ payConfig.setAppId(merchantAppConfig.getAppId());
|
|
|
|
|
+ payConfig.setMchId(payConfig1.getWxMchId());
|
|
|
|
|
+ payConfig.setMchKey(payConfig1.getWxMchKey());
|
|
|
|
|
+ payConfig.setSubAppId(StringUtils.trimToNull(null));
|
|
|
|
|
+ payConfig.setSubMchId(StringUtils.trimToNull(null));
|
|
|
|
|
+ payConfig.setKeyPath(payConfig1.getKeyPath());
|
|
|
|
|
+ payConfig.setNotifyUrl(payConfig1.getNotifyUrlScrm());
|
|
|
|
|
+ WxPayServiceImpl payService = new WxPayServiceImpl();
|
|
|
|
|
+ payService.setConfig(payConfig);
|
|
|
|
|
+ return payService;
|
|
|
|
|
+ }
|
|
|
@Autowired
|
|
@Autowired
|
|
|
private IFsStoreProductPurchaseLimitScrmService purchaseLimitService;
|
|
private IFsStoreProductPurchaseLimitScrmService purchaseLimitService;
|
|
|
|
|
|