瀏覽代碼

feat:需求调整后的自提商品相关接口

caoliqin 3 周之前
父節點
當前提交
be7544c171

+ 0 - 1
fs-company/src/main/java/com/fs/hisStore/controller/FsStoreOrderScrmController.java

@@ -177,7 +177,6 @@ public class FsStoreOrderScrmController extends BaseController
         if(!StringUtils.isEmpty(param.getDeliveryImportTimeRange())){
             param.setDeliveryImportTimeList(param.getDeliveryImportTimeRange().split("--"));
         }
-        param.setIsPickup(1);
         List<FsStoreOrderVO> list = fsStoreOrderService.selectFsStoreOrderAllListVO(param);
         return getDataTable(list);
     }

+ 147 - 0
fs-company/src/main/java/com/fs/hisStore/controller/FsStorePaymentScrmController.java

@@ -1,19 +1,61 @@
 package com.fs.hisStore.controller;
 
+import java.math.BigDecimal;
+import java.math.RoundingMode;
+import java.text.SimpleDateFormat;
+import java.util.Date;
+import java.util.HashMap;
 import java.util.List;
+import java.util.Map;
 
+import cn.hutool.core.util.ObjectUtil;
+import cn.hutool.json.JSONUtil;
+import com.alibaba.fastjson.JSON;
+import com.alipay.api.AlipayApiException;
+import com.alipay.api.domain.AlipayTradeRefundModel;
 import com.fs.common.core.domain.R;
+import com.fs.common.utils.DateUtils;
 import com.fs.common.utils.ParseUtils;
 import com.fs.common.utils.ServletUtils;
+import com.fs.common.utils.StringUtils;
 import com.fs.common.utils.poi.ExcelUtil;
+import com.fs.common.utils.spring.SpringUtils;
+import com.fs.company.service.ICompanyService;
+import com.fs.course.domain.FsCoursePlaySourceConfig;
+import com.fs.course.service.IFsCoursePlaySourceConfigService;
 import com.fs.framework.security.LoginUser;
 import com.fs.framework.service.TokenService;
+import com.fs.his.domain.FsHfpayConfig;
+import com.fs.his.domain.FsPayConfig;
+import com.fs.his.domain.MerchantAppConfig;
+import com.fs.his.mapper.FsHfpayConfigMapper;
+import com.fs.his.service.IMerchantAppConfigService;
 import com.fs.hisStore.domain.FsStorePaymentScrm;
+import com.fs.hisStore.domain.FsStoreOrderItemScrm;
+import com.fs.hisStore.domain.FsStoreProductScrm;
 import com.fs.hisStore.param.FsStorePaymentParam;
+import com.fs.hisStore.service.IFsStoreOrderItemScrmService;
+import com.fs.hisStore.service.IFsStoreProductScrmService;
 import com.fs.hisStore.service.IFsStorePaymentScrmService;
 import com.fs.hisStore.vo.FsStorePaymentVO;
+import com.fs.huifuPay.domain.HuiFuRefundResult;
+import com.fs.huifuPay.sdk.opps.core.request.V2TradePaymentScanpayRefundRequest;
+import com.fs.huifuPay.service.HuiFuService;
+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.ijpay.alipay.AliPayApi;
+import com.ijpay.alipay.AliPayApiConfig;
+import com.ijpay.alipay.AliPayApiConfigKit;
+import lombok.extern.slf4j.Slf4j;
 import org.springframework.security.access.prepost.PreAuthorize;
 import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.transaction.annotation.Transactional;
+import org.springframework.transaction.interceptor.TransactionAspectSupport;
 import org.springframework.web.bind.annotation.GetMapping;
 import org.springframework.web.bind.annotation.PostMapping;
 import org.springframework.web.bind.annotation.PutMapping;
@@ -34,6 +76,7 @@ import com.fs.common.core.page.TableDataInfo;
  * @author fs
  * @date 2022-06-20
  */
+@Slf4j
 @RestController
 @RequestMapping("/store/store/storePayment")
 public class FsStorePaymentScrmController extends BaseController
@@ -42,6 +85,20 @@ public class FsStorePaymentScrmController extends BaseController
     private IFsStorePaymentScrmService fsStorePaymentService;
     @Autowired
     private TokenService tokenService;
+    @Autowired
+    private IFsCoursePlaySourceConfigService fsCoursePlaySourceConfigService;
+    @Autowired
+    private IMerchantAppConfigService merchantAppConfigService;
+    @Autowired
+    HuiFuService huiFuService;
+    @Autowired
+    private WxPayService wxPayService;
+    @Autowired
+    private ICompanyService companyService;
+    @Autowired
+    private IFsStoreOrderItemScrmService fsStoreOrderItemService;
+    @Autowired
+    private IFsStoreProductScrmService fsStoreProductService;
     /**
      * 查询支付明细列表
      */
@@ -141,4 +198,94 @@ public class FsStorePaymentScrmController extends BaseController
         List<FsStorePaymentVO> list = fsStorePaymentService.selectFsMyStorePaymentListQueryVO(fsStorePayment);
         return getDataTable(list);
     }
+
+    /**
+     * 销售端直接退款
+     * @param fsStorePayment
+     * @return
+     */
+    @PreAuthorize("@ss.hasPermi('store:storePaymentScrm:refund')")
+    @PostMapping("/refundStorePayment")
+    @Transactional
+    public R refundStorePayment(@RequestBody FsStorePaymentScrm fsStorePayment)
+    {
+        FsStorePaymentScrm payment=fsStorePaymentService.selectFsStorePaymentById(fsStorePayment.getPaymentId());
+        String businessOrderId = fsStorePayment.getBusinessOrderId();
+        if (StringUtils.isEmpty(businessOrderId)) {
+            return R.error("没有关联的订单");
+        }
+        FsStoreOrderItemScrm orderItemQuery = new FsStoreOrderItemScrm();
+        orderItemQuery.setOrderId(Long.parseLong(businessOrderId));
+        List<FsStoreOrderItemScrm> orderItemList = fsStoreOrderItemService.selectFsStoreOrderItemList(orderItemQuery);
+        if (orderItemList == null || orderItemList.isEmpty()) {
+            return R.error("没有关联的订单");
+        }
+        for (FsStoreOrderItemScrm orderItem : orderItemList) {
+            FsStoreProductScrm product = fsStoreProductService.selectFsStoreProductById(orderItem.getProductId());
+            if (product == null || !Integer.valueOf(1).equals(product.getIsAllowSalesRefund())) {
+                return R.error("未允许销售直接退款,请联系管理员");
+            }
+        }
+        if(payment.getStatus()!=1){
+            return R.error("非法操作");
+        }
+        if(fsStorePayment.getRefundMoney().compareTo(new BigDecimal(0))<1){
+            return R.error("退款金额必须大于0");
+        }
+        if(payment.getPayMoney().compareTo(fsStorePayment.getRefundMoney())==-1){
+            return R.error("退款金额必须小于等于付款金额");
+        }
+
+        if(payment.getPayTypeCode().equals("weixin")){
+            FsCoursePlaySourceConfig fsCoursePlaySourceConfig = fsCoursePlaySourceConfigService.selectCoursePlaySourceConfigByAppId(payment.getAppId());
+            MerchantAppConfig merchantAppConfig = merchantAppConfigService.selectMerchantAppConfigById(fsCoursePlaySourceConfig.getMerchantConfigId());
+
+            if (ObjectUtil.isEmpty(merchantAppConfig)) {
+                return R.error("缺少支付相关配置");
+            }
+            FsPayConfig fsPayConfig = JSON.parseObject(merchantAppConfig.getDataJson(), FsPayConfig.class);
+
+            if (payment.getPayMode()!=null&&payment.getPayMode().equals("hf")){
+                String huifuId = "";
+                FsHfpayConfigMapper fsHfpayConfigMapper = SpringUtils.getBean(FsHfpayConfigMapper.class);
+                if (payment.getAppId() != null) {
+                    FsHfpayConfig fsHfpayConfig = fsHfpayConfigMapper.selectByAppId(payment.getAppId());
+                    huifuId = fsHfpayConfig.getHuifuId();
+                } else {
+                        huifuId=fsPayConfig.getHuifuId();
+                }
+                V2TradePaymentScanpayRefundRequest request = new V2TradePaymentScanpayRefundRequest();
+                request.setHuifuId(huifuId);
+
+                request.setOrdAmt(payment.getPayMoney().toString());
+                request.setOrgReqDate(new SimpleDateFormat("yyyyMMdd").format(payment.getCreateTime()));
+                request.setReqSeqId("refund-"+payment.getPayCode());
+                request.setAppId(payment.getAppId());
+                Map<String, Object> extendInfoMap = new HashMap<>();
+                extendInfoMap.put("org_party_order_id", payment.getBankSerialNo());
+                request.setExtendInfo(extendInfoMap);
+                log.info("请求参数:{}", request);
+                request.setAppId(payment.getAppId());
+                HuiFuRefundResult refund = huiFuService.refund(request);
+                log.info("退款:{}", refund);
+                if((refund.getResp_code().equals("00000000")||refund.getResp_code().equals("00000100"))&&(refund.getTrans_stat().equals("S")||refund.getTrans_stat().equals("P"))){
+                    payment.setRefundMoney(fsStorePayment.getRefundMoney());
+                    payment.setStatus(-1);
+                    payment.setRefundTime(new Date());
+                    fsStorePaymentService.updateFsStorePayment(payment);
+                    //收款 减去所有
+                    if(payment.getCompanyId()!=null&&payment.getCompanyId()>0){
+                        companyService.subCompanyPaymentMoney(payment);
+                    }
+                    return R.ok();
+                }else {
+                    TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
+                    return R.error(refund.getResp_desc());
+                }
+            }
+        }
+
+        return R.error("非法操作");
+    }
+
 }

+ 3 - 0
fs-service/src/main/java/com/fs/hisStore/mapper/FsStoreOrderScrmMapper.java

@@ -293,6 +293,9 @@ public interface FsStoreOrderScrmMapper
             "<if test = 'maps.deptId != null    '> " +
             "  AND (o.dept_id = #{maps.deptId} OR o.dept_id IN ( SELECT t.dept_id FROM company_dept t WHERE find_in_set(#{maps.deptId}, ancestors) )) " +
             "</if>" +
+            "<if test = 'maps.isPickup != null'> " +
+            "and o.is_pickup =#{maps.isPickup} " +
+            "</if>" +
             " ${maps.params.dataScope} "+
             "<if test = 'maps.productName != null and  maps.productName !=  \"\" '> " +
             " group by o.id "+