|
@@ -1,11 +1,13 @@
|
|
|
package com.fs.hisStore.service.impl;
|
|
|
|
|
|
+import java.text.SimpleDateFormat;
|
|
|
import java.util.*;
|
|
|
import java.util.function.Function;
|
|
|
import java.util.stream.Collectors;
|
|
|
import java.util.stream.Stream;
|
|
|
|
|
|
import cn.binarywang.wx.miniapp.api.WxMaService;
|
|
|
+import cn.hutool.core.date.DateTime;
|
|
|
import cn.hutool.core.date.DateUnit;
|
|
|
import cn.hutool.core.date.DateUtil;
|
|
|
import cn.hutool.core.util.ObjectUtil;
|
|
@@ -21,16 +23,16 @@ import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
import com.fs.common.utils.StringUtils;
|
|
|
import com.fs.company.domain.CompanyUser;
|
|
|
import com.fs.company.mapper.CompanyUserMapper;
|
|
|
+import com.fs.company.service.ICompanyService;
|
|
|
import com.fs.core.config.WxMaConfiguration;
|
|
|
+import com.fs.core.config.WxPayProperties;
|
|
|
import com.fs.course.mapper.FsUserCompanyUserMapper;
|
|
|
import com.fs.course.param.CollectionInfoConfirmParam;
|
|
|
import com.fs.course.vo.FsUserInfoCollectionUVO;
|
|
|
import com.fs.his.config.FsSysConfig;
|
|
|
import com.fs.his.domain.*;
|
|
|
-import com.fs.his.mapper.FsDoctorMapper;
|
|
|
-import com.fs.his.mapper.FsPackageMapper;
|
|
|
-import com.fs.his.mapper.FsPackageOrderMapper;
|
|
|
-import com.fs.his.mapper.FsPrescribeMapper;
|
|
|
+import com.fs.his.enums.FsStoreOrderStatusEnum;
|
|
|
+import com.fs.his.mapper.*;
|
|
|
import com.fs.his.param.FsPrescribeParam;
|
|
|
import com.fs.his.service.*;
|
|
|
import com.fs.his.utils.ConfigUtil;
|
|
@@ -40,10 +42,30 @@ import com.fs.hisStore.param.FsUserInformationCollectionListDParam;
|
|
|
import com.fs.hisStore.param.FsUserInformationCollectionParam;
|
|
|
import com.fs.hisStore.vo.FsUserInformationCollectionListDVO;
|
|
|
import com.fs.hisStore.vo.FsUserInformationCollectionVO;
|
|
|
+import com.fs.huifuPay.domain.HuiFuRefundResult;
|
|
|
+import com.fs.huifuPay.sdk.opps.core.request.V2TradePaymentScanpayRefundRequest;
|
|
|
+import com.fs.huifuPay.service.HuiFuService;
|
|
|
import com.fs.store.domain.FsDoctorConfirm;
|
|
|
import com.fs.store.service.IFsDoctorConfirmService;
|
|
|
+import com.fs.system.domain.SysConfig;
|
|
|
+import com.fs.system.mapper.SysConfigMapper;
|
|
|
import com.fs.system.oss.CloudStorageService;
|
|
|
import com.fs.system.oss.OSSFactory;
|
|
|
+import com.fs.system.service.ISysConfigService;
|
|
|
+import com.fs.tzBankPay.TzBankService.TzBankService;
|
|
|
+import com.fs.tzBankPay.doman.RefundParam;
|
|
|
+import com.fs.tzBankPay.doman.RefundResult;
|
|
|
+import com.fs.tzBankPay.doman.TzBankResult;
|
|
|
+import com.fs.ybPay.dto.RefundDTO;
|
|
|
+import com.fs.ybPay.service.IPayService;
|
|
|
+import com.github.binarywang.wxpay.bean.request.WxPayRefundRequest;
|
|
|
+import com.github.binarywang.wxpay.bean.request.WxPayUnifiedOrderRequest;
|
|
|
+import com.github.binarywang.wxpay.bean.result.WxPayRefundQueryResult;
|
|
|
+import com.github.binarywang.wxpay.bean.result.WxPayRefundResult;
|
|
|
+import com.github.binarywang.wxpay.config.WxPayConfig;
|
|
|
+import com.github.binarywang.wxpay.exception.WxPayException;
|
|
|
+import com.github.binarywang.wxpay.service.WxPayService;
|
|
|
+import com.google.gson.Gson;
|
|
|
import me.chanjar.weixin.common.error.WxErrorException;
|
|
|
import org.slf4j.Logger;
|
|
|
import org.slf4j.LoggerFactory;
|
|
@@ -64,6 +86,28 @@ import org.springframework.util.CollectionUtils;
|
|
|
@Service
|
|
|
public class FsUserInformationCollectionServiceImpl extends ServiceImpl<FsUserInformationCollectionMapper, FsUserInformationCollection> implements IFsUserInformationCollectionService {
|
|
|
Logger logger= LoggerFactory.getLogger(getClass());
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private ISysConfigService configService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ SysConfigMapper sysConfigMapper;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private WxPayProperties wxPayProperties;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private WxPayService wxPayService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ IPayService payService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private TzBankService tzBankService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private HuiFuService huiFuService;
|
|
|
+
|
|
|
@Autowired
|
|
|
private CompanyUserMapper companyUserMapper;
|
|
|
|
|
@@ -103,6 +147,14 @@ public class FsUserInformationCollectionServiceImpl extends ServiceImpl<FsUserIn
|
|
|
@Autowired
|
|
|
private IFsPrescribeService prescribeService;
|
|
|
|
|
|
+ @Autowired
|
|
|
+ private ICompanyService companyService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private FsStorePaymentMapper fsStorePaymentMapper;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private FsStoreOrderLogsMapper fsStoreOrderLogsMapper;
|
|
|
/**
|
|
|
* 查询用户信息采集
|
|
|
*
|
|
@@ -358,9 +410,10 @@ public class FsUserInformationCollectionServiceImpl extends ServiceImpl<FsUserIn
|
|
|
FsStoreOrder fsStoreOrder = storeOrderService.selectFsStoreOrderByOrderCode(fsUserInformationCollection.getPackageOrderCode());
|
|
|
if (fsStoreOrder != null && fsStoreOrder.getIsPay() == 1 ) {
|
|
|
if (fsStoreOrder.getPrescribeId() != null) {
|
|
|
- FsPrescribeParam fsPrescribeParam = new FsPrescribeParam();
|
|
|
- fsPrescribeParam.setPrescribeId(fsStoreOrder.getPrescribeId());
|
|
|
- prescribeService.confirmPrescribe(fsPrescribeParam);
|
|
|
+// FsPrescribeParam fsPrescribeParam = new FsPrescribeParam();
|
|
|
+// fsPrescribeParam.setPrescribeId(fsStoreOrder.getPrescribeId());
|
|
|
+// prescribeService.confirmPrescribe(fsPrescribeParam);
|
|
|
+ prescribeService.collectionPrescribe(fsStoreOrder.getPrescribeId());
|
|
|
}
|
|
|
} else {
|
|
|
throw new CustomException("生成处方信息中......");
|
|
@@ -448,6 +501,7 @@ public class FsUserInformationCollectionServiceImpl extends ServiceImpl<FsUserIn
|
|
|
vo.setDoctorConfirm(collection.getDoctorConfirm());
|
|
|
vo.setUserAdvice(collection.getUserAdvice());
|
|
|
vo.setDoctorAdvice(collection.getDoctorAdvice());
|
|
|
+ vo.setDoctor(doctorMapper.selectFsDoctorByDoctorId(collection.getDoctorId()));
|
|
|
}
|
|
|
return vo;
|
|
|
}
|
|
@@ -516,6 +570,179 @@ public class FsUserInformationCollectionServiceImpl extends ServiceImpl<FsUserIn
|
|
|
return R.error("用户确认失败");
|
|
|
}
|
|
|
|
|
|
+ @Override
|
|
|
+ @Transactional
|
|
|
+ public void autoRefund(FsUserInformationCollection collection) {
|
|
|
+
|
|
|
+ //清空订单号
|
|
|
+ fsUserInformationCollectionMapper.collectionOderCodeNULL(collection.getId());
|
|
|
+
|
|
|
+ //更新采集信息状态
|
|
|
+ FsUserInformationCollection map = new FsUserInformationCollection();
|
|
|
+ map.setId(collection.getId());
|
|
|
+ map.setUserConfirm2(0);
|
|
|
+ map.setStatus(1);
|
|
|
+ map.setUserConfirm(0);
|
|
|
+ map.setDoctorConfirm(0);
|
|
|
+ //更新用户信息采集状态
|
|
|
+ fsUserInformationCollectionMapper.updateFsUserInformationCollection(map);
|
|
|
+
|
|
|
+ //退款操作
|
|
|
+ FsStoreOrder fsStoreOrder = storeOrderService.selectFsStoreOrderByOrderCode(collection.getPackageOrderCode());
|
|
|
+ if (fsStoreOrder == null) {
|
|
|
+ throw new CustomException("没有处方订单");
|
|
|
+ }
|
|
|
+
|
|
|
+ //更新处方单信息
|
|
|
+ FsStoreOrder mapStoreOrder = new FsStoreOrder();
|
|
|
+ mapStoreOrder.setOrderId(fsStoreOrder.getOrderId());
|
|
|
+ mapStoreOrder.setStatus(-2);
|
|
|
+ mapStoreOrder.setRefundTime(DateUtils.getNowDate());
|
|
|
+ storeOrderService.updateFsStoreOrder(mapStoreOrder);
|
|
|
+
|
|
|
+ //订单日志
|
|
|
+ FsStoreOrderLogs Logs = new FsStoreOrderLogs();
|
|
|
+ Logs.setChangeMessage(FsStoreOrderStatusEnum.REFUND_STATUS_2.getDesc());
|
|
|
+ Logs.setOrderId(fsStoreOrder.getOrderId());
|
|
|
+ Logs.setChangeTime(new DateTime());
|
|
|
+ Logs.setChangeType(FsStoreOrderStatusEnum.REFUND_STATUS_2.getValue().toString());
|
|
|
+ fsStoreOrderLogsMapper.insertFsStoreOrderLogs(Logs);
|
|
|
+
|
|
|
+ String orderType = "store";
|
|
|
+ Long orderId = fsStoreOrder.getOrderId();
|
|
|
+ if (fsStoreOrder.getPackageOrderId() != null) {
|
|
|
+ orderType = "package";
|
|
|
+
|
|
|
+ FsPackageOrder fsPackageOrder = packageOrderMapper.selectByOderCode(collection.getPackageOrderCode());
|
|
|
+ if (fsPackageOrder == null) {
|
|
|
+ throw new CustomException("没有套餐订单");
|
|
|
+ }
|
|
|
+ orderId = fsStoreOrder.getPackageOrderId();
|
|
|
+
|
|
|
+ //更新套餐单信息
|
|
|
+ FsPackageOrder mapPackageOrder = new FsPackageOrder();
|
|
|
+ mapPackageOrder.setOrderId(fsPackageOrder.getOrderId());
|
|
|
+ mapPackageOrder.setStatus(-2);
|
|
|
+ mapPackageOrder.setRefundStatus(2);
|
|
|
+ packageOrderMapper.updateFsPackageOrder(fsPackageOrder);
|
|
|
+ }
|
|
|
+
|
|
|
+ if (fsStoreOrder.getCompanyId() != null) {
|
|
|
+ companyService.refundCompanyMoney(fsStoreOrder);
|
|
|
+ }
|
|
|
+
|
|
|
+ //获取支付明细
|
|
|
+ List<FsStorePayment> payments = fsStorePaymentMapper.selectFsStorePaymentByPay(2, fsStoreOrder.getOrderId());
|
|
|
+ if (fsStoreOrder.getPackageOrderId() != null) {
|
|
|
+
|
|
|
+ payments = fsStorePaymentMapper.selectFsStorePaymentByPay(3, fsStoreOrder.getPackageOrderId());
|
|
|
+ }
|
|
|
+
|
|
|
+ if (payments != null && !payments.isEmpty()) {
|
|
|
+ FsStorePayment payment = payments.get(0);
|
|
|
+ String json = configService.selectConfigByKey("his.pay");
|
|
|
+ if (payment.getPayMode().equals("wx")) {
|
|
|
+ WxPayConfig payConfig = new WxPayConfig();
|
|
|
+ SysConfig sysConfig = sysConfigMapper.selectConfigByConfigKey("his.pay");
|
|
|
+ FsPayConfig fsPayConfig = new Gson().fromJson(sysConfig.getConfigValue(), FsPayConfig.class);
|
|
|
+ payConfig.setAppId(fsPayConfig.getAppId());
|
|
|
+ payConfig.setMchId(fsPayConfig.getWxMchId());
|
|
|
+ payConfig.setMchKey(fsPayConfig.getWxMchKey());
|
|
|
+ payConfig.setKeyPath(wxPayProperties.getKeyPath());
|
|
|
+ payConfig.setSubAppId(org.apache.commons.lang3.StringUtils.trimToNull(null));
|
|
|
+ payConfig.setSubMchId(org.apache.commons.lang3.StringUtils.trimToNull(null));
|
|
|
+ wxPayService.setConfig(payConfig);
|
|
|
+ WxPayRefundRequest refundRequest = new WxPayRefundRequest();
|
|
|
+ refundRequest.setOutTradeNo(orderType + "-" + payment.getPayCode());
|
|
|
+ refundRequest.setOutRefundNo(orderType + "-" + 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")) {
|
|
|
+ FsStorePayment paymentMap = new FsStorePayment();
|
|
|
+ paymentMap.setPaymentId(payment.getPaymentId());
|
|
|
+ paymentMap.setStatus(-1);
|
|
|
+ paymentMap.setRefundTime(DateUtils.getNowDate());
|
|
|
+ paymentMap.setRefundMoney(payment.getPayMoney());
|
|
|
+ fsStorePaymentMapper.updateFsStorePayment(paymentMap);
|
|
|
+ } else {
|
|
|
+ throw new CustomException("退款请求失败" + refundQueryResult.getReturnMsg());
|
|
|
+ }
|
|
|
+ } catch (WxPayException e) {
|
|
|
+ throw new CustomException("退款请求失败" + e.getReturnMsg());
|
|
|
+ }
|
|
|
+ } else if (payment.getPayMode().equals("yb")) {
|
|
|
+ //易宝
|
|
|
+ RefundDTO refundDTO = new RefundDTO();
|
|
|
+ refundDTO.setRefundMoney(payment.getPayMoney().toString());
|
|
|
+ refundDTO.setLowRefundNo(orderType + "-" + payment.getPayCode());
|
|
|
+ refundDTO.setUpOrderId(payment.getTradeNo());
|
|
|
+ com.fs.ybPay.domain.RefundResult result = payService.refund(refundDTO);
|
|
|
+ logger.info("订单退款返回结果:退款订单id:" + orderId + result);
|
|
|
+ if (result.getState().equals("5")) {
|
|
|
+ FsStorePayment paymentMap = new FsStorePayment();
|
|
|
+ paymentMap.setPaymentId(payment.getPaymentId());
|
|
|
+ paymentMap.setStatus(-1);
|
|
|
+ paymentMap.setRefundTime(DateUtils.getNowDate());
|
|
|
+ paymentMap.setRefundMoney(payment.getPayMoney());
|
|
|
+ fsStorePaymentMapper.updateFsStorePayment(paymentMap);
|
|
|
+ } else {
|
|
|
+ throw new CustomException("退款请求失败" + result.getMessage());
|
|
|
+ }
|
|
|
+ } else if (payment.getPayMode().equals("tz")) {
|
|
|
+ RefundParam tzBankResult = new RefundParam();
|
|
|
+ // 使用set方法为对象的字段赋值
|
|
|
+ //商户原支付订单号
|
|
|
+ tzBankResult.setOldPayOutOrderNo(orderType + payment.getPayCode());
|
|
|
+ // 商户退款订单号 对接平台系统里自己生成的退款订单号
|
|
|
+ tzBankResult.setRefundOrderNo(orderType + payment.getPayCode());
|
|
|
+ // 交易发送时间 yyyyMMddHHmmss
|
|
|
+ SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMddHHmmss");
|
|
|
+ tzBankResult.setTrxSendTime(sdf.format(new Date()));
|
|
|
+ // 退款金额
|
|
|
+ tzBankResult.setRefundOrdTransAmt(payment.getPayMoney().doubleValue());
|
|
|
+ TzBankResult<RefundResult> result = tzBankService.refund(tzBankResult);
|
|
|
+ logger.info("订单退款返回结果:退款订单id:" + orderId + result);
|
|
|
+ if (result.getBody().getRefundOrdStatus().equals("90") || result.getBody().getRefundOrdStatus().equals("60")) {
|
|
|
+ FsStorePayment paymentMap = new FsStorePayment();
|
|
|
+ paymentMap.setPaymentId(payment.getPaymentId());
|
|
|
+ paymentMap.setStatus(-1);
|
|
|
+ paymentMap.setRefundTime(DateUtils.getNowDate());
|
|
|
+ paymentMap.setRefundMoney(payment.getPayMoney());
|
|
|
+ fsStorePaymentMapper.updateFsStorePayment(paymentMap);
|
|
|
+ } else {
|
|
|
+ throw new CustomException("退款请求失败" + result.getRetMsg());
|
|
|
+ }
|
|
|
+ } else if (payment.getPayMode().equals("hf")) {
|
|
|
+ V2TradePaymentScanpayRefundRequest request = new V2TradePaymentScanpayRefundRequest();
|
|
|
+ request.setOrdAmt(payment.getPayMoney().toString());
|
|
|
+ request.setOrgReqDate(new SimpleDateFormat("yyyyMMdd").format(payment.getCreateTime()));
|
|
|
+ request.setReqSeqId("refund-" + payment.getPayCode());
|
|
|
+ Map<String, Object> extendInfoMap = new HashMap<>();
|
|
|
+ extendInfoMap.put("org_req_seq_id", orderType + "-" + payment.getPayCode());
|
|
|
+ request.setExtendInfo(extendInfoMap);
|
|
|
+ HuiFuRefundResult refund = huiFuService.refund(request);
|
|
|
+ logger.info("订单退款返回结果:退款订单id:" + orderId + refund);
|
|
|
+ if ((refund.getResp_code().equals("00000000") || refund.getResp_code().equals("00000100")) && (refund.getTrans_stat().equals("S") || refund.getTrans_stat().equals("P"))) {
|
|
|
+ FsStorePayment paymentMap = new FsStorePayment();
|
|
|
+ paymentMap.setPaymentId(payment.getPaymentId());
|
|
|
+ paymentMap.setStatus(-1);
|
|
|
+ paymentMap.setRefundTime(DateUtils.getNowDate());
|
|
|
+ paymentMap.setRefundMoney(payment.getPayMoney());
|
|
|
+ fsStorePaymentMapper.updateFsStorePayment(paymentMap);
|
|
|
+ } else {
|
|
|
+ throw new CustomException("退款请求失败" + refund.getResp_desc());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ throw new CustomException("未找的支付明细");
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
private List<AnswerVO> getAnswerVOs(List<AnswerVO> target,List<AnswerVO> source) {
|
|
|
target.addAll(source);
|
|
|
return target.stream()
|