|
@@ -2,6 +2,7 @@ package com.fs.live.service.impl;
|
|
|
|
|
|
|
|
import java.lang.reflect.InvocationTargetException;
|
|
import java.lang.reflect.InvocationTargetException;
|
|
|
import java.sql.Timestamp;
|
|
import java.sql.Timestamp;
|
|
|
|
|
+import java.text.SimpleDateFormat;
|
|
|
import java.time.LocalDateTime;
|
|
import java.time.LocalDateTime;
|
|
|
import java.util.*;
|
|
import java.util.*;
|
|
|
|
|
|
|
@@ -10,6 +11,7 @@ import cn.hutool.core.date.DateTime;
|
|
|
import cn.hutool.core.util.IdUtil;
|
|
import cn.hutool.core.util.IdUtil;
|
|
|
import cn.hutool.core.util.ObjectUtil;
|
|
import cn.hutool.core.util.ObjectUtil;
|
|
|
import cn.hutool.json.JSONUtil;
|
|
import cn.hutool.json.JSONUtil;
|
|
|
|
|
+import com.alibaba.fastjson.JSON;
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
import com.fs.common.core.domain.R;
|
|
import com.fs.common.core.domain.R;
|
|
|
import com.fs.common.exception.CustomException;
|
|
import com.fs.common.exception.CustomException;
|
|
@@ -17,6 +19,9 @@ import com.fs.common.utils.CloudHostUtils;
|
|
|
import com.fs.common.utils.DateUtils;
|
|
import com.fs.common.utils.DateUtils;
|
|
|
|
|
|
|
|
import com.fs.common.utils.StringUtils;
|
|
import com.fs.common.utils.StringUtils;
|
|
|
|
|
+import com.fs.common.utils.spring.SpringUtils;
|
|
|
|
|
+import com.fs.company.service.ICompanyService;
|
|
|
|
|
+import com.fs.config.cloud.CloudHostProper;
|
|
|
import com.fs.erp.constant.AfterSalesOrderStatusEnum;
|
|
import com.fs.erp.constant.AfterSalesOrderStatusEnum;
|
|
|
import com.fs.erp.domain.FsJstAftersalePush;
|
|
import com.fs.erp.domain.FsJstAftersalePush;
|
|
|
import com.fs.erp.dto.BaseResponse;
|
|
import com.fs.erp.dto.BaseResponse;
|
|
@@ -24,25 +29,30 @@ import com.fs.erp.dto.ErpRefundUpdateRequest;
|
|
|
import com.fs.erp.mapper.FsJstAftersalePushMapper;
|
|
import com.fs.erp.mapper.FsJstAftersalePushMapper;
|
|
|
import com.fs.erp.service.IErpOrderService;
|
|
import com.fs.erp.service.IErpOrderService;
|
|
|
import com.fs.his.config.FsSysConfig;
|
|
import com.fs.his.config.FsSysConfig;
|
|
|
|
|
+import com.fs.his.domain.FsHfpayConfig;
|
|
|
import com.fs.his.domain.FsUser;
|
|
import com.fs.his.domain.FsUser;
|
|
|
|
|
+import com.fs.his.mapper.FsHfpayConfigMapper;
|
|
|
import com.fs.his.service.IFsUserService;
|
|
import com.fs.his.service.IFsUserService;
|
|
|
import com.fs.his.utils.ConfigUtil;
|
|
import com.fs.his.utils.ConfigUtil;
|
|
|
|
|
+import com.fs.hisStore.config.FsErpConfig;
|
|
|
import com.fs.hisStore.domain.*;
|
|
import com.fs.hisStore.domain.*;
|
|
|
import com.fs.hisStore.dto.StoreOrderProductDTO;
|
|
import com.fs.hisStore.dto.StoreOrderProductDTO;
|
|
|
-import com.fs.hisStore.enums.AfterSalesStatusEnum;
|
|
|
|
|
-import com.fs.hisStore.enums.AfterStatusEnum;
|
|
|
|
|
-import com.fs.hisStore.enums.OrderInfoEnum;
|
|
|
|
|
-import com.fs.hisStore.enums.SysConfigEnum;
|
|
|
|
|
|
|
+import com.fs.hisStore.enums.*;
|
|
|
import com.fs.hisStore.param.FsStoreAfterSalesProductParam;
|
|
import com.fs.hisStore.param.FsStoreAfterSalesProductParam;
|
|
|
|
|
+import com.fs.hisStore.service.IFsStoreProductScrmService;
|
|
|
import com.fs.hisStore.service.IFsUserScrmService;
|
|
import com.fs.hisStore.service.IFsUserScrmService;
|
|
|
import com.fs.hisStore.vo.FsStoreAfterSalesQueryVO;
|
|
import com.fs.hisStore.vo.FsStoreAfterSalesQueryVO;
|
|
|
import com.fs.hisStore.vo.FsStoreOrderItemVO;
|
|
import com.fs.hisStore.vo.FsStoreOrderItemVO;
|
|
|
|
|
+import com.fs.huifuPay.domain.HuiFuRefundResult;
|
|
|
|
|
+import com.fs.huifuPay.sdk.opps.core.request.V2TradePaymentScanpayRefundRequest;
|
|
|
|
|
+import com.fs.huifuPay.service.HuiFuService;
|
|
|
import com.fs.live.domain.*;
|
|
import com.fs.live.domain.*;
|
|
|
import com.fs.live.dto.LiveAfterSalesProductDTO;
|
|
import com.fs.live.dto.LiveAfterSalesProductDTO;
|
|
|
import com.fs.live.enums.LiveAfterSalesStatusEnum;
|
|
import com.fs.live.enums.LiveAfterSalesStatusEnum;
|
|
|
import com.fs.live.mapper.*;
|
|
import com.fs.live.mapper.*;
|
|
|
import com.fs.live.param.*;
|
|
import com.fs.live.param.*;
|
|
|
import com.fs.live.service.ILiveOrderItemService;
|
|
import com.fs.live.service.ILiveOrderItemService;
|
|
|
|
|
+import com.fs.live.service.ILiveOrderLogsService;
|
|
|
import com.fs.live.service.ILiveOrderService;
|
|
import com.fs.live.service.ILiveOrderService;
|
|
|
import com.fs.live.vo.LiveAfterSalesListUVO;
|
|
import com.fs.live.vo.LiveAfterSalesListUVO;
|
|
|
import com.fs.live.vo.LiveAfterSalesQueryVO;
|
|
import com.fs.live.vo.LiveAfterSalesQueryVO;
|
|
@@ -52,9 +62,17 @@ import com.fs.store.config.StoreConfig;
|
|
|
import com.fs.store.domain.*;
|
|
import com.fs.store.domain.*;
|
|
|
import com.fs.store.service.cache.IFsUserCacheService;
|
|
import com.fs.store.service.cache.IFsUserCacheService;
|
|
|
import com.fs.system.service.ISysConfigService;
|
|
import com.fs.system.service.ISysConfigService;
|
|
|
|
|
+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 lombok.extern.slf4j.Slf4j;
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
import org.apache.commons.beanutils.BeanUtils;
|
|
import org.apache.commons.beanutils.BeanUtils;
|
|
|
import org.apache.commons.collections4.CollectionUtils;
|
|
import org.apache.commons.collections4.CollectionUtils;
|
|
|
|
|
+import org.apache.commons.lang.ObjectUtils;
|
|
|
import org.apache.http.util.Asserts;
|
|
import org.apache.http.util.Asserts;
|
|
|
import org.springframework.aop.framework.AopContext;
|
|
import org.springframework.aop.framework.AopContext;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
@@ -887,4 +905,202 @@ public class LiveAfterSalesServiceImpl implements ILiveAfterSalesService {
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
+ @Autowired
|
|
|
|
|
+ private LiveOrderItemMapper liveOrderItemMapper;
|
|
|
|
|
+ @Autowired
|
|
|
|
|
+ private LiveUserLotteryRecordMapper liveUserLotteryRecordMapper;
|
|
|
|
|
+ @Autowired
|
|
|
|
|
+ private IFsStoreProductScrmService fsStoreProductService;
|
|
|
|
|
+
|
|
|
|
|
+ @Autowired
|
|
|
|
|
+ private WxPayService wxPayService;
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+ @Autowired
|
|
|
|
|
+ private HuiFuService huiFuService;
|
|
|
|
|
+
|
|
|
|
|
+ @Autowired
|
|
|
|
|
+ private ILiveOrderLogsService liveOrderLogsService;
|
|
|
|
|
+ @Autowired
|
|
|
|
|
+ private ICompanyService companyService;
|
|
|
|
|
+
|
|
|
|
|
+ @Autowired
|
|
|
|
|
+ private LiveAfterSalesMapper liveAfterSalesMapper;
|
|
|
|
|
+
|
|
|
|
|
+ @Override
|
|
|
|
|
+ @Transactional(rollbackFor = Exception.class,propagation = Propagation.REQUIRED)
|
|
|
|
|
+ public R handleImmediatelyRefund(Long orderId) {
|
|
|
|
|
+ IErpOrderService erpOrderService = getErpService();
|
|
|
|
|
+ FsErpConfig erpConfig = configUtil.generateStructConfigByKey("his.config", FsErpConfig.class);
|
|
|
|
|
+ LiveOrder order = liveOrderService.selectLiveOrderByOrderId(String.valueOf(orderId));
|
|
|
|
|
+ if (order == null) {
|
|
|
|
|
+ return R.error("订单不存在");
|
|
|
|
|
+ }
|
|
|
|
|
+ if (order.getStatus() == -2) {
|
|
|
|
|
+ return R.error("已退款");
|
|
|
|
|
+ }
|
|
|
|
|
+ if (!Integer.valueOf(-1).equals(order.getStatus())) {
|
|
|
|
|
+ return R.error("非法操作");
|
|
|
|
|
+ }
|
|
|
|
|
+ if (erpConfig.getErpOpen() != null
|
|
|
|
|
+ && erpConfig.getErpOpen() == 1
|
|
|
|
|
+ && StringUtils.isEmpty(order.getExtendOrderId())
|
|
|
|
|
+ && !CloudHostUtils.hasCloudHostName("康年堂")) {
|
|
|
|
|
+ return R.error("暂未推送至erp,请稍后再试!");
|
|
|
|
|
+ }
|
|
|
|
|
+// if (StringUtils.isNotEmpty(order.getExtendOrderId())) {
|
|
|
|
|
+// ErpRefundUpdateRequest request = new ErpRefundUpdateRequest();
|
|
|
|
|
+// request.setTid(order.getOrderCode());
|
|
|
|
|
+// request.setOid(order.getOrderCode());
|
|
|
|
|
+// request.setRefund_state(1);
|
|
|
|
|
+//
|
|
|
|
|
+// if (ObjectUtils.equals(order.getStatus(), 2)) {
|
|
|
|
|
+// LiveAfterSalesParam param = new LiveAfterSalesParam();
|
|
|
|
|
+// param.setOrderCode(order.getOrderCode());
|
|
|
|
|
+// param.setRefundAmount(order.getPayMoney());
|
|
|
|
|
+// param.setServiceType(1);
|
|
|
|
|
+// param.setReasons("后台手动退款流程");
|
|
|
|
|
+// param.setExplainImg(null);
|
|
|
|
|
+// List<FsStoreAfterSalesProductParam> productParams = new ArrayList<>();
|
|
|
|
|
+// List <LiveOrderItem> items = liveOrderItemMapper.selectLiveOrderItemByOrderId(order.getOrderId());
|
|
|
|
|
+// for (LiveOrderItem item : items){
|
|
|
|
|
+// FsStoreAfterSalesProductParam param1 = new FsStoreAfterSalesProductParam();
|
|
|
|
|
+// param1.setProductId(item.getProductId());
|
|
|
|
|
+// param1.setNum(Math.toIntExact(item.getNum()));
|
|
|
|
|
+// productParams.add(param1);
|
|
|
|
|
+// }
|
|
|
|
|
+// return liveAfterSalesService.applyForAfterSales(order.getUserId(), param);
|
|
|
|
|
+// } else {
|
|
|
|
|
+// jSTOrderService.refundUpdateLive(request);
|
|
|
|
|
+// }
|
|
|
|
|
+// }
|
|
|
|
|
+ order.setStatus(OrderInfoEnum.STATUS_NE2.getValue());
|
|
|
|
|
+ order.setRefundMoney(order.getPayMoney());
|
|
|
|
|
+ order.setRefundStatus(String.valueOf(OrderInfoEnum.REFUND_STATUS_2.getValue()));
|
|
|
|
|
+ liveUserLotteryRecordMapper.updateOrderStatusByOrderId(order.getOrderId(), -2);
|
|
|
|
|
+ liveOrderService.updateLiveOrder(order);
|
|
|
|
|
+
|
|
|
|
|
+ //退库存
|
|
|
|
|
+ //获取订单下的商品
|
|
|
|
|
+ List<LiveOrderItem> orderItemVOS = liveOrderItemMapper.selectLiveOrderItemByOrderId(order.getOrderId());
|
|
|
|
|
+ for (LiveOrderItem vo : orderItemVOS) {
|
|
|
|
|
+ if (vo.getIsAfterSales() == 1) {
|
|
|
|
|
+ fsStoreProductService.incProductStock(vo.getNum(), vo.getProductId(), vo.getProductAttrValueId());
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ if ("3".equals(order.getPayType())) {
|
|
|
|
|
+ //货到付款
|
|
|
|
|
+ } else {
|
|
|
|
|
+ //将钱退还给用户
|
|
|
|
|
+ List<LiveOrderPayment> payments = liveOrderPaymentMapper.selectLiveOrderPaymentByPay(5, order.getOrderId());
|
|
|
|
|
+ if (payments != null && !payments.isEmpty()) {
|
|
|
|
|
+ String json = configService.selectConfigByKey("his.pay");
|
|
|
|
|
+ FsPayConfigScrm fsPayConfig = JSON.parseObject(json, FsPayConfigScrm.class);
|
|
|
|
|
+ for (LiveOrderPayment payment : payments) {
|
|
|
|
|
+ if (payment.getPayMode() == null || "wx".equals(payment.getPayMode())) {
|
|
|
|
|
+ WxPayConfig payConfig = new WxPayConfig();
|
|
|
|
|
+ payConfig.setAppId(fsPayConfig.getAppId());
|
|
|
|
|
+ payConfig.setMchId(fsPayConfig.getWxMchId());
|
|
|
|
|
+ payConfig.setMchKey(fsPayConfig.getWxMchKey());
|
|
|
|
|
+ payConfig.setKeyPath(fsPayConfig.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("live-" + payment.getPayCode());
|
|
|
|
|
+ refundRequest.setOutRefundNo("live-" + 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 && "SUCCESS".equals(refundQueryResult.getResultCode())) {
|
|
|
|
|
+ LiveOrderPayment paymentMap = new LiveOrderPayment();
|
|
|
|
|
+ paymentMap.setPaymentId(payment.getPaymentId());
|
|
|
|
|
+ paymentMap.setStatus(-1);
|
|
|
|
|
+ paymentMap.setRefundTime(DateUtils.getNowDate());
|
|
|
|
|
+ paymentMap.setRefundMoney(payment.getPayMoney());
|
|
|
|
|
+ liveOrderPaymentMapper.updateLiveOrderPayment(paymentMap);
|
|
|
|
|
+ } else {
|
|
|
|
|
+ TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
|
|
|
|
|
+ return R.error("退款请求失败" + (refundQueryResult != null ? refundQueryResult.getErrCodeDes() : ""));
|
|
|
|
|
+ }
|
|
|
|
|
+ } catch (WxPayException e) {
|
|
|
|
|
+ TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
|
|
|
|
|
+ return R.error("退款请求失败" + e.getErrCodeDes());
|
|
|
|
|
+ }
|
|
|
|
|
+ } else if (payment.getPayMode() != null && "hf".equals(payment.getPayMode())) {
|
|
|
|
|
+ String huifuId = "";
|
|
|
|
|
+ FsHfpayConfigMapper fsHfpayConfigMapper = SpringUtils.getBean(FsHfpayConfigMapper.class);
|
|
|
|
|
+ if (payment.getAppId() != null) {
|
|
|
|
|
+ FsHfpayConfig fsHfpayConfig = fsHfpayConfigMapper.selectByAppId(payment.getAppId());
|
|
|
|
|
+ if (fsHfpayConfig != null) {
|
|
|
|
|
+ huifuId = fsHfpayConfig.getHuifuId();
|
|
|
|
|
+ }
|
|
|
|
|
+ } else {
|
|
|
|
|
+ CloudHostProper cloudHostProper = SpringUtils.getBean(CloudHostProper.class);
|
|
|
|
|
+ if ("益善缘".equals(cloudHostProper.getCompanyName())) {
|
|
|
|
|
+ FsHfpayConfig fsPayConfig2 = fsHfpayConfigMapper.selectByAppId("wx0d1a3dd485268521");
|
|
|
|
|
+ if (fsPayConfig2 != null) {
|
|
|
|
|
+ huifuId = fsPayConfig2.getHuifuId();
|
|
|
|
|
+ }
|
|
|
|
|
+ } else {
|
|
|
|
|
+ huifuId = fsPayConfig.getHuifuId();
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ V2TradePaymentScanpayRefundRequest request = new V2TradePaymentScanpayRefundRequest();
|
|
|
|
|
+ request.setOrgHfSeqId(payment.getTradeNo());
|
|
|
|
|
+ request.setHuifuId(huifuId);
|
|
|
|
|
+ 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_party_order_id", payment.getBankSerialNo());
|
|
|
|
|
+ request.setExtendInfo(extendInfoMap);
|
|
|
|
|
+ HuiFuRefundResult refund = huiFuService.refund(request);
|
|
|
|
|
+ log.info("退款:" + refund);
|
|
|
|
|
+ if (refund != null && ("00000000".equals(refund.getResp_code()) || "00000100".equals(refund.getResp_code()))
|
|
|
|
|
+ && ("S".equals(refund.getTrans_stat()) || "P".equals(refund.getTrans_stat()))) {
|
|
|
|
|
+ payment.setRefundMoney(payment.getPayMoney());
|
|
|
|
|
+ payment.setStatus(-1);
|
|
|
|
|
+ payment.setRefundTime(new Date());
|
|
|
|
|
+ liveOrderPaymentMapper.updateLiveOrderPayment(payment);
|
|
|
|
|
+ } else {
|
|
|
|
|
+ TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
|
|
|
|
|
+ return R.error(refund != null ? refund.getResp_desc() : "退款失败");
|
|
|
|
|
+ }
|
|
|
|
|
+ } else {
|
|
|
|
|
+ TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
|
|
|
|
|
+ return R.error("支付类型异常");
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ liveOrderLogsService.create(order.getOrderId(), OrderLogEnum.REFUND_ORDER_SUCCESS.getValue(),
|
|
|
|
|
+ OrderLogEnum.REFUND_ORDER_SUCCESS.getDesc());
|
|
|
|
|
+ //减去公司收入
|
|
|
|
|
+ if (order.getCompanyId() != null && order.getCompanyId() > 0 && order.getTuiMoneyStatus() != null && order.getTuiMoneyStatus() == 1) {
|
|
|
|
|
+ companyService.subLiveCompanyMoney(order);
|
|
|
|
|
+ }
|
|
|
|
|
+ // 减去用户佣金
|
|
|
|
|
+ if (order.getTuiUserId() != null && order.getTuiUserId() > 0) {
|
|
|
|
|
+ IFsUserScrmService userService = SpringUtils.getBean(IFsUserScrmService.class);
|
|
|
|
|
+ if (userService != null) {
|
|
|
|
|
+ // 需要将LiveOrder转换为FsStoreOrderScrm用于subTuiMoney方法
|
|
|
|
|
+ FsStoreOrderScrm storeOrder = new FsStoreOrderScrm();
|
|
|
|
|
+ storeOrder.setId(order.getOrderId());
|
|
|
|
|
+ storeOrder.setTuiUserId(order.getTuiUserId());
|
|
|
|
|
+ userService.subTuiMoney(storeOrder);
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ LiveAfterSales liveAfterSales = liveAfterSalesMapper.getLiveAfterSalesByOrderId(orderId);
|
|
|
|
|
+ LiveAfterSales liveMp = new LiveAfterSales();
|
|
|
|
|
+ liveMp.setId(liveAfterSales.getId());
|
|
|
|
|
+ liveMp.setStatus(LiveAfterSalesStatusEnum.STATUS_4.getValue());
|
|
|
|
|
+ liveMp.setSalesStatus(3);
|
|
|
|
|
+ liveAfterSalesMapper.updateLiveAfterSales(liveMp);
|
|
|
|
|
+
|
|
|
|
|
+ return R.ok();
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|