|
@@ -78,9 +78,11 @@ 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.common.reflect.TypeToken;
|
|
import com.google.common.reflect.TypeToken;
|
|
|
import com.google.gson.Gson;
|
|
import com.google.gson.Gson;
|
|
|
import lombok.Synchronized;
|
|
import lombok.Synchronized;
|
|
|
|
|
+import lombok.extern.slf4j.Slf4j;
|
|
|
import me.chanjar.weixin.common.error.WxErrorException;
|
|
import me.chanjar.weixin.common.error.WxErrorException;
|
|
|
import org.apache.rocketmq.spring.core.RocketMQTemplate;
|
|
import org.apache.rocketmq.spring.core.RocketMQTemplate;
|
|
|
import org.slf4j.Logger;
|
|
import org.slf4j.Logger;
|
|
@@ -109,6 +111,7 @@ import static com.fs.his.utils.PhoneUtil.encryptPhone;
|
|
|
* @author fs
|
|
* @author fs
|
|
|
* @date 2023-06-12
|
|
* @date 2023-06-12
|
|
|
*/
|
|
*/
|
|
|
|
|
+@Slf4j
|
|
|
@Service
|
|
@Service
|
|
|
public class FsInquiryOrderServiceImpl implements IFsInquiryOrderService
|
|
public class FsInquiryOrderServiceImpl implements IFsInquiryOrderService
|
|
|
{
|
|
{
|
|
@@ -512,6 +515,39 @@ public class FsInquiryOrderServiceImpl implements IFsInquiryOrderService
|
|
|
.build();
|
|
.build();
|
|
|
publisher.publishEvent(new TemplateEvent(this, templateBean));
|
|
publisher.publishEvent(new TemplateEvent(this, templateBean));
|
|
|
}
|
|
}
|
|
|
|
|
+ } else if ("appPay".equals(payment.getPayMode()) && "wx".equals(payment.getPayTypeCode())) {
|
|
|
|
|
+ MerchantAppConfig merchantAppConfig = merchantAppConfigMapper.selectMerchantAppConfigById(payment.getMerConfigId());
|
|
|
|
|
+ FsPayConfig fsPayConfig = com.alibaba.fastjson.JSON.parseObject(merchantAppConfig.getDataJson(), FsPayConfig.class);
|
|
|
|
|
+
|
|
|
|
|
+ // 处理微信退款
|
|
|
|
|
+ WxPayService wxPayService = getWxPayService(fsPayConfig);
|
|
|
|
|
+ WxPayRefundRequest refundRequest = new WxPayRefundRequest();
|
|
|
|
|
+ refundRequest.setOutTradeNo("inquiry"+"-"+payment.getPayCode());
|
|
|
|
|
+ refundRequest.setOutRefundNo("inquiry"+"-"+payment.getPayCode());
|
|
|
|
|
+ refundRequest.setTotalFee(WxPayUnifiedOrderRequest.yuanToFen(payment.getPayMoney().toString()));
|
|
|
|
|
+ refundRequest.setRefundFee(WxPayUnifiedOrderRequest.yuanToFen(payment.getPayMoney().toString()));
|
|
|
|
|
+ log.info("微信退款入参:{}",refundRequest);
|
|
|
|
|
+ try {
|
|
|
|
|
+ WxPayRefundResult refundResult = wxPayService.refund(refundRequest);
|
|
|
|
|
+ WxPayRefundQueryResult refundQueryResult = wxPayService.refundQuery("", refundResult.getOutTradeNo(), refundResult.getOutRefundNo(), refundResult.getRefundId());
|
|
|
|
|
+ log.info("微信退款出参:{}",refundQueryResult);
|
|
|
|
|
+ if (refundQueryResult != null && refundQueryResult.getResultCode().equals("SUCCESS")) {
|
|
|
|
|
+ FsStorePayment paymentMap = new FsStorePayment();
|
|
|
|
|
+ paymentMap.setPaymentId(payment.getPaymentId());
|
|
|
|
|
+ paymentMap.setStatus(-1);
|
|
|
|
|
+ paymentMap.setRefundTime(DateUtils.getNowDate());
|
|
|
|
|
+ paymentMap.setRefundMoney(payment.getPayMoney());
|
|
|
|
|
+ fsStorePaymentMapper.updateFsStorePayment(paymentMap);
|
|
|
|
|
+
|
|
|
|
|
+ updateStatus(payment);
|
|
|
|
|
+ } else {
|
|
|
|
|
+ throw new CustomException("退款请求失败" + refundQueryResult.getReturnMsg());
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ } catch (WxPayException e) {
|
|
|
|
|
+ throw new CustomException("退款请求失败" + e);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -574,6 +610,31 @@ public class FsInquiryOrderServiceImpl implements IFsInquiryOrderService
|
|
|
fsInquiryOrderLogsService.insertFsInquiryOrderLogs(log);
|
|
fsInquiryOrderLogsService.insertFsInquiryOrderLogs(log);
|
|
|
return R.ok("操作成功");
|
|
return R.ok("操作成功");
|
|
|
}
|
|
}
|
|
|
|
|
+
|
|
|
|
|
+ private void updateStatus(FsStorePayment fsStorePayment){
|
|
|
|
|
+ switch (fsStorePayment.getBusinessType()){
|
|
|
|
|
+ case 1:
|
|
|
|
|
+ FsInquiryOrder fsInquiryOrder = new FsInquiryOrder();
|
|
|
|
|
+ fsInquiryOrder.setOrderId(Long.valueOf(fsStorePayment.getBusinessId()));
|
|
|
|
|
+ fsInquiryOrder.setStatus(-2);
|
|
|
|
|
+ fsInquiryOrderMapper.updateFsInquiryOrder(fsInquiryOrder);
|
|
|
|
|
+ break;
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ private WxPayService getWxPayService(FsPayConfig fsPayConfig){
|
|
|
|
|
+
|
|
|
|
|
+ WxPayConfig payConfig = new WxPayConfig();
|
|
|
|
|
+ payConfig.setAppId(fsPayConfig.getWxAppAppId());
|
|
|
|
|
+ payConfig.setMchId(fsPayConfig.getWxAppMchId());
|
|
|
|
|
+ payConfig.setMchKey(fsPayConfig.getWxAppMchKey());
|
|
|
|
|
+ payConfig.setKeyPath(fsPayConfig.getWxAppKeyPath());
|
|
|
|
|
+ payConfig.setNotifyUrl(fsPayConfig.getWxAppNotifyUrl());
|
|
|
|
|
+ WxPayServiceImpl payService = new WxPayServiceImpl();
|
|
|
|
|
+ payService.setConfig(payConfig);
|
|
|
|
|
+ return payService;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
@Override
|
|
@Override
|
|
|
@Transactional
|
|
@Transactional
|
|
|
public R createOrder(FsInquiryOrderCreateParam param) {
|
|
public R createOrder(FsInquiryOrderCreateParam param) {
|