|
@@ -1,13 +1,5 @@
|
|
|
package com.fs.store.service.impl;
|
|
|
|
|
|
-import java.lang.reflect.Field;
|
|
|
-import java.math.BigDecimal;
|
|
|
-import java.sql.Timestamp;
|
|
|
-import java.text.ParseException;
|
|
|
-import java.text.SimpleDateFormat;
|
|
|
-import java.time.LocalDateTime;
|
|
|
-import java.util.*;
|
|
|
-
|
|
|
import cn.hutool.core.bean.BeanUtil;
|
|
|
import cn.hutool.core.util.IdUtil;
|
|
|
import cn.hutool.json.JSONUtil;
|
|
@@ -26,26 +18,21 @@ import com.fs.erp.service.IErpOrderService;
|
|
|
import com.fs.huifuPay.domain.HuiFuRefundResult;
|
|
|
import com.fs.huifuPay.sdk.opps.core.request.V2TradePaymentScanpayRefundRequest;
|
|
|
import com.fs.huifuPay.service.HuiFuService;
|
|
|
-import com.fs.pay.pay.domain.QueryRefundResult;
|
|
|
-import com.fs.pay.pay.domain.RefundResult;
|
|
|
-import com.fs.pay.pay.dto.RefundOrderDTO;
|
|
|
import com.fs.pay.pay.service.PayService;
|
|
|
-import com.fs.pay.pay.service.impl.PayApiServiceImpl;
|
|
|
-import com.fs.pay.service.impl.PayServiceImpl;
|
|
|
+import com.fs.pay.service.IPayService;
|
|
|
import com.fs.store.config.StoreConfig;
|
|
|
import com.fs.store.domain.*;
|
|
|
import com.fs.store.dto.StoreOrderProductDTO;
|
|
|
import com.fs.store.enums.AfterSalesStatusEnum;
|
|
|
import com.fs.store.enums.AfterStatusEnum;
|
|
|
import com.fs.store.enums.OrderInfoEnum;
|
|
|
+import com.fs.store.mapper.FsStoreAfterSalesMapper;
|
|
|
import com.fs.store.mapper.FsStoreOrderItemMapper;
|
|
|
import com.fs.store.param.*;
|
|
|
import com.fs.store.service.*;
|
|
|
import com.fs.store.vo.FsStoreAfterSalesQueryVO;
|
|
|
import com.fs.store.vo.FsStoreAfterSalesVO;
|
|
|
import com.fs.store.vo.FsStoreOrderItemVO;
|
|
|
-import com.fs.pay.service.IPayService;
|
|
|
-import com.fs.pay.service.dto.RefundDTO;
|
|
|
import com.fs.system.service.ISysConfigService;
|
|
|
import com.fs.wx.pay.config.WxPayProperties;
|
|
|
import com.github.binarywang.wxpay.bean.request.WxPayRefundRequest;
|
|
@@ -55,16 +42,22 @@ 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.hc.openapi.tool.util.Ids;
|
|
|
import lombok.Synchronized;
|
|
|
import org.slf4j.Logger;
|
|
|
import org.slf4j.LoggerFactory;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
-import com.fs.store.mapper.FsStoreAfterSalesMapper;
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
import org.springframework.transaction.interceptor.TransactionAspectSupport;
|
|
|
|
|
|
+import java.lang.reflect.Field;
|
|
|
+import java.math.BigDecimal;
|
|
|
+import java.sql.Timestamp;
|
|
|
+import java.text.ParseException;
|
|
|
+import java.text.SimpleDateFormat;
|
|
|
+import java.time.LocalDateTime;
|
|
|
+import java.util.*;
|
|
|
+
|
|
|
/**
|
|
|
* 售后记录Service业务层处理
|
|
|
*
|
|
@@ -282,6 +275,7 @@ public class FsStoreAfterSalesServiceImpl implements IFsStoreAfterSalesService
|
|
|
FsStoreAfterSalesItem storeAfterSalesItem = new FsStoreAfterSalesItem();
|
|
|
storeAfterSalesItem.setStoreAfterSalesId(storeAfterSales.getId());
|
|
|
storeAfterSalesItem.setProductId(item.getProductId());
|
|
|
+ storeAfterSalesItem.setNum(productParam.getNum());
|
|
|
storeAfterSalesItem.setJsonInfo(item.getJsonInfo());
|
|
|
storeAfterSalesItem.setIsDel(0);
|
|
|
afterSalesItemService.insertFsStoreAfterSalesItem(storeAfterSalesItem);
|
|
@@ -529,13 +523,9 @@ public class FsStoreAfterSalesServiceImpl implements IFsStoreAfterSalesService
|
|
|
//
|
|
|
// return R.ok("操作成功");
|
|
|
// }
|
|
|
-
|
|
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
@Override
|
|
|
- public synchronized R refundMoney(FsStoreAfterSalesRefundParam param) {
|
|
|
- return refundStoreMoney(param);
|
|
|
- }
|
|
|
- @Transactional
|
|
|
- R refundStoreMoney(FsStoreAfterSalesRefundParam param){
|
|
|
+ public R refundMoney(FsStoreAfterSalesRefundParam param) {
|
|
|
FsStoreAfterSales storeAfterSales = fsStoreAfterSalesMapper.selectFsStoreAfterSalesById(param.getSalesId());
|
|
|
if (storeAfterSales == null) {
|
|
|
throw new CustomException("未查询到售后订单信息");
|
|
@@ -555,6 +545,14 @@ public class FsStoreAfterSalesServiceImpl implements IFsStoreAfterSalesService
|
|
|
order.setRefundStatus(OrderInfoEnum.REFUND_STATUS_2.getValue());
|
|
|
orderService.updateFsStoreOrder(order);
|
|
|
|
|
|
+ BigDecimal refundAmount = param.getRefundAmount();
|
|
|
+ if (Objects.isNull(refundAmount)) {
|
|
|
+ throw new CustomException("退款金额不能为空");
|
|
|
+ }
|
|
|
+ if (order.getPayMoney().compareTo(refundAmount) < 0) {
|
|
|
+ throw new CustomException("退款金额不能大于支付金额");
|
|
|
+ }
|
|
|
+
|
|
|
FsStoreAfterSalesStatus storeAfterSalesStatus = new FsStoreAfterSalesStatus();
|
|
|
storeAfterSalesStatus.setStoreAfterSalesId(storeAfterSales.getId());
|
|
|
storeAfterSalesStatus.setChangeType(4);
|
|
@@ -565,12 +563,20 @@ public class FsStoreAfterSalesServiceImpl implements IFsStoreAfterSalesService
|
|
|
//退库存
|
|
|
//获取订单下的商品
|
|
|
List<FsStoreOrderItemVO> orderItemVOS=fsStoreOrderItemMapper.selectFsStoreOrderItemListByOrderId(order.getId());
|
|
|
- for(FsStoreOrderItemVO vo:orderItemVOS){
|
|
|
- if(vo.getIsAfterSales()==1){
|
|
|
- productService.incProductStock(vo.getNum(), vo.getProductId()
|
|
|
- , vo.getProductAttrValueId());
|
|
|
+
|
|
|
+ // 获取售后商品
|
|
|
+ FsStoreAfterSalesItem params = new FsStoreAfterSalesItem();
|
|
|
+ params.setStoreAfterSalesId(storeAfterSales.getId());
|
|
|
+ List<FsStoreAfterSalesItem> fsStoreAfterSalesItems = afterSalesItemService.selectFsStoreAfterSalesItemList(params);
|
|
|
+
|
|
|
+ // 退库存
|
|
|
+ for (FsStoreAfterSalesItem item : fsStoreAfterSalesItems) {
|
|
|
+ FsStoreOrderItemVO itemVO = orderItemVOS.stream().filter(i -> i.getProductId().equals(item.getProductId())).findFirst().orElse(null);
|
|
|
+ if(Objects.nonNull(itemVO) && itemVO.getIsAfterSales() == 1 && Objects.nonNull(item.getNum())){
|
|
|
+ productService.incProductStock(item.getNum().longValue(), item.getProductId(), null);
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
//将钱退还给用户
|
|
|
if(order.getPayMoney().compareTo(BigDecimal.ZERO)==1){
|
|
|
List<FsStorePayment> payments=paymentService.selectFsStorePaymentByOrderId(order.getId());
|
|
@@ -591,7 +597,7 @@ public class FsStoreAfterSalesServiceImpl implements IFsStoreAfterSalesService
|
|
|
refundRequest.setOutTradeNo("store-"+payment.getPayCode());
|
|
|
refundRequest.setOutRefundNo("store-"+payment.getPayCode());
|
|
|
refundRequest.setTotalFee(WxPayUnifiedOrderRequest.yuanToFen(payment.getPayMoney().toString()));
|
|
|
- refundRequest.setRefundFee(WxPayUnifiedOrderRequest.yuanToFen(payment.getPayMoney().toString()));
|
|
|
+ refundRequest.setRefundFee(WxPayUnifiedOrderRequest.yuanToFen(refundAmount.toString()));
|
|
|
try {
|
|
|
WxPayRefundResult refundResult = wxPayService.refund(refundRequest);
|
|
|
WxPayRefundQueryResult refundQueryResult = wxPayService.refundQuery("", refundResult.getOutTradeNo(), refundResult.getOutRefundNo(), refundResult.getRefundId());
|
|
@@ -611,7 +617,7 @@ public class FsStoreAfterSalesServiceImpl implements IFsStoreAfterSalesService
|
|
|
}
|
|
|
}else if (payment.getPayMode()!=null&&payment.getPayMode().equals("hf")){
|
|
|
V2TradePaymentScanpayRefundRequest request = new V2TradePaymentScanpayRefundRequest();
|
|
|
- request.setOrdAmt(payment.getPayMoney().toString());
|
|
|
+ request.setOrdAmt(refundAmount.toString());
|
|
|
request.setOrgReqDate(new SimpleDateFormat("yyyyMMdd").format(payment.getCreateTime()));
|
|
|
request.setReqSeqId("refund-"+payment.getPayCode());
|
|
|
Map<String, Object> extendInfoMap = new HashMap<>();
|