xuhaifeng 9 months ago
parent
commit
ae4385ac9b
20 changed files with 897 additions and 374 deletions
  1. 2 0
      yiqi-common/src/main/java/com/yiqi/core/domain/SettlementManageStore.java
  2. 7 4
      yiqi-common/src/main/java/com/yiqi/order/domain/OrderPayInfo.java
  3. 108 0
      yiqi-common/src/main/java/com/yiqi/order/domain/OrderRefundInfo.java
  4. 10 3
      yiqi-common/src/main/java/com/yiqi/order/domain/dto/PayRefundDTO.java
  5. 2 2
      yiqi-common/src/main/java/com/yiqi/order/service/IOrderPayInfoService.java
  6. 81 0
      yiqi-common/src/main/java/com/yiqi/order/service/IOrderRefundInfoService.java
  7. 0 11
      yiqi-common/src/main/java/com/yiqi/order/service/IPayService.java
  8. 9 0
      yiqi-common/src/main/java/com/yiqi/settlement/service/ISettlementStoreRateService.java
  9. 254 266
      yiqi-core/src/main/java/com/yiqi/core/service/impl/SettlementManageBillServiceImpl.java
  10. 4 5
      yiqi-core/src/main/java/com/yiqi/delay/impl/DelayTaskRunService.java
  11. 67 0
      yiqi-core/src/main/java/com/yiqi/order/mapper/OrderRefundInfoMapper.java
  12. 6 5
      yiqi-core/src/main/java/com/yiqi/order/service/impl/OrderClothServiceImpl.java
  13. 4 6
      yiqi-core/src/main/java/com/yiqi/order/service/impl/OrderGoodsServiceImpl.java
  14. 5 9
      yiqi-core/src/main/java/com/yiqi/order/service/impl/OrderPayInfoServiceImpl.java
  15. 6 6
      yiqi-core/src/main/java/com/yiqi/order/service/impl/OrderRechargeServiceImpl.java
  16. 118 0
      yiqi-core/src/main/java/com/yiqi/order/service/impl/OrderRefundInfoServiceImpl.java
  17. 23 55
      yiqi-core/src/main/java/com/yiqi/order/service/impl/PayServiceImpl.java
  18. 15 0
      yiqi-core/src/main/java/com/yiqi/settlement/service/impl/SettlementStoreRateServiceImpl.java
  19. 1 2
      yiqi-core/src/main/resources/mapper/order/OrderPayInfoMapper.xml
  20. 175 0
      yiqi-core/src/main/resources/mapper/order/OrderRefundInfoMapper.xml

+ 2 - 0
yiqi-common/src/main/java/com/yiqi/core/domain/SettlementManageStore.java

@@ -350,4 +350,6 @@ public class SettlementManageStore
     @ApiModelProperty("支付宝微信费率")
     private BigDecimal aliWxPayRate;
 
+
+    private String remark;
 }

+ 7 - 4
yiqi-common/src/main/java/com/yiqi/order/domain/OrderPayInfo.java

@@ -11,7 +11,6 @@ import com.fasterxml.jackson.annotation.JsonFormat;
 import com.yiqi.common.annotation.Excel;
 import io.swagger.annotations.ApiModel;
 import io.swagger.annotations.ApiModelProperty;
-import com.yiqi.common.core.domain.BaseEntity;
 import lombok.Data;
 import com.fasterxml.jackson.databind.annotation.JsonSerialize;
 import com.fasterxml.jackson.databind.ser.std.ToStringSerializer;
@@ -36,6 +35,10 @@ public class OrderPayInfo implements Serializable {
     @JsonSerialize(using = ToStringSerializer.class)
     private Long id;
 
+    @ApiModelProperty("门店ID")
+    @JsonSerialize(using = ToStringSerializer.class)
+    private Long storeId;
+
     /**
      * 订单编号
      */
@@ -46,9 +49,9 @@ public class OrderPayInfo implements Serializable {
     /**
      * 支付订单编号
      */
-    @Excel(name = "支付订单编号")
-    @ApiModelProperty("支付订单编号")
-    private String payOrderNo;
+    @Excel(name = "支付请求编号")
+    @ApiModelProperty("支付请求编号")
+    private String requestNo;
 
     /**
      * 支付金额

+ 108 - 0
yiqi-common/src/main/java/com/yiqi/order/domain/OrderRefundInfo.java

@@ -0,0 +1,108 @@
+package com.yiqi.order.domain;
+
+import java.math.BigDecimal;
+
+import com.baomidou.mybatisplus.annotation.IdType;
+import com.baomidou.mybatisplus.annotation.TableId;
+import com.baomidou.mybatisplus.annotation.TableName;
+import com.yiqi.common.annotation.Excel;
+import io.swagger.annotations.ApiModel;
+import io.swagger.annotations.ApiModelProperty;
+import com.yiqi.common.core.domain.BaseEntity;
+import lombok.Data;
+import com.fasterxml.jackson.databind.annotation.JsonSerialize;
+import com.fasterxml.jackson.databind.ser.std.ToStringSerializer;
+
+/**
+ * 第三方退款记录对象 order_refund_info
+ *
+ * @author douya
+ * @date 2024-09-16
+ */
+@ApiModel("第三方退款记录")
+@TableName("order_refund_info")
+@Data
+public class OrderRefundInfo extends BaseEntity {
+    private static final long serialVersionUID = 1L;
+
+    /**
+     * 主键ID
+     */
+    @ApiModelProperty("主键ID")
+    @TableId(type = IdType.AUTO)
+    @JsonSerialize(using = ToStringSerializer.class)
+    private Long id;
+
+    /**
+     * 门店ID
+     */
+    @Excel(name = "门店ID")
+    @ApiModelProperty("门店ID")
+    @JsonSerialize(using = ToStringSerializer.class)
+    private Long storeId;
+
+    /**
+     * 原订单编号
+     */
+    @Excel(name = "原订单编号")
+    @ApiModelProperty("原订单编号")
+    private String originOrderNo;
+
+    /**
+     * 退款订单编号
+     */
+    @Excel(name = "退款订单编号")
+    @ApiModelProperty("退款订单编号")
+    private String refundOrderNo;
+
+    /**
+     * 请求编号
+     */
+    @Excel(name = "请求编号")
+    @ApiModelProperty("请求编号")
+    private String requestNo;
+
+    /**
+     * 原支付金额
+     */
+    @Excel(name = "原支付金额")
+    @ApiModelProperty("原支付金额")
+    private BigDecimal payAmount;
+
+    /**
+     * 退款金额
+     */
+    @Excel(name = "退款金额")
+    @ApiModelProperty("退款金额")
+    private BigDecimal refundAmount;
+
+    /**
+     * 支付商户号
+     */
+    @Excel(name = "支付商户号")
+    @ApiModelProperty("支付商户号")
+    private String payMno;
+
+    /**
+     * 支付方式(0=微信,1=支付宝)
+     */
+    @Excel(name = "支付方式", readConverterExp = "0==微信,1=支付宝")
+    @ApiModelProperty("支付方式(0=微信,1=支付宝)")
+    private String payType;
+
+    /**
+     * 退款状态(0=待退款,1=已退款,-1:退款失败)
+     */
+    @Excel(name = "退款状态", readConverterExp = "0==待退款,1=已退款,-1:退款失败")
+    @ApiModelProperty("退款状态(0=待退款,1=已退款,-1:退款失败)")
+    private String refundStatus;
+
+    /**
+     * 返回消息
+     */
+    @Excel(name = "返回消息")
+    @ApiModelProperty("返回消息")
+    private String msg;
+
+
+}

+ 10 - 3
yiqi-common/src/main/java/com/yiqi/order/domain/dto/PayRefundDTO.java

@@ -17,18 +17,20 @@ public class PayRefundDTO {
      * @param payType      支付方式
      * @param outTradeNo   订单号
      * @param refundAmount 退款金额
-     * @param outRequestNo 退款单号(可选)
+     * @param refundNo     退款单号(可选)
      * @param refundReason 退款原因(可选)
      */
-    public PayRefundDTO(String payType, String orderNo, BigDecimal refundAmount, String outRequestNo, String outTradeNo, String refundReason) {
+    public PayRefundDTO(String payType, String orderNo, BigDecimal refundAmount, String refundNo, String outTradeNo, String refundReason) {
         this.payType = payType;
         this.outTradeNo = outTradeNo;
         this.orderNo = orderNo;
         this.refundAmount = refundAmount;
-        this.outRequestNo = outRequestNo;
+        this.refundNo = refundNo;
         this.refundReason = refundReason;
     }
 
+    private Long storeId;
+
     @ApiModelProperty("支付方式")
     private String payType;
 
@@ -53,6 +55,11 @@ public class PayRefundDTO {
             "必选条件部分退款时必选")
     private String outRequestNo;
 
+    /**
+     * 退款单号
+     */
+    private String refundNo;
+
     @ApiModelProperty("退款原因说明。 商家自定义,将在会在商户和用户的pc退款账单详情中展示")
     private String refundReason;
 }

+ 2 - 2
yiqi-common/src/main/java/com/yiqi/order/service/IOrderPayInfoService.java

@@ -75,10 +75,10 @@ public interface IOrderPayInfoService extends IService<OrderPayInfo> {
 
     /**
      * 根据支付订单号查询第三方支付记录
-     * @param payOrderNo
+     * @param requestNo
      * @return
      */
-    OrderPayInfo getOrderPayInfoByPayOrderNo(String payOrderNo);
+    OrderPayInfo getOrderPayInfoByRequestNo(String requestNo);
 
     //</editor-folder>
 }

+ 81 - 0
yiqi-common/src/main/java/com/yiqi/order/service/IOrderRefundInfoService.java

@@ -0,0 +1,81 @@
+package com.yiqi.order.service;
+
+import java.math.BigDecimal;
+import java.util.List;
+import com.baomidou.mybatisplus.extension.service.IService;
+import com.yiqi.order.domain.OrderPayInfo;
+import com.yiqi.order.domain.OrderRefundInfo;
+import com.yiqi.order.domain.dto.PayRefundDTO;
+
+/**
+ * 第三方退款记录Service接口
+ *
+ * @author douya
+ * @date 2024-09-16
+ */
+public interface IOrderRefundInfoService extends IService<OrderRefundInfo> {
+
+    //<editor-folder desc="基础函数">
+    /**
+     * 查询第三方退款记录
+     *
+     * @param id 第三方退款记录主键
+     * @return 第三方退款记录
+     */
+    public OrderRefundInfo selectOrderRefundInfoById(Long id);
+
+    /**
+     * 查询第三方退款记录列表
+     *
+     * @param orderRefundInfo 第三方退款记录
+     * @return 第三方退款记录集合
+     */
+    public List<OrderRefundInfo> selectOrderRefundInfoList(OrderRefundInfo orderRefundInfo);
+
+    /**
+     * 新增第三方退款记录
+     *
+     * @param orderRefundInfo 第三方退款记录
+     * @return 结果
+     */
+    public int insertOrderRefundInfo(OrderRefundInfo orderRefundInfo);
+
+    /**
+     * 修改第三方退款记录
+     *
+     * @param orderRefundInfo 第三方退款记录
+     * @return 结果
+     */
+    public int updateOrderRefundInfo(OrderRefundInfo orderRefundInfo);
+
+    /**
+     * 批量删除第三方退款记录
+     *
+     * @param ids 需要删除的第三方退款记录主键集合
+     * @return 结果
+     */
+    public int deleteOrderRefundInfoByIds(Long[] ids);
+
+    /**
+     * 删除第三方退款记录信息
+     *
+     * @param id 第三方退款记录主键
+     * @return 结果
+     */
+    public int deleteOrderRefundInfoById(Long id);
+
+
+    /**
+     *  创建第三方退款记录
+     * @param payRefundDTO
+     * @return
+     */
+    OrderRefundInfo createOrderRefundInfo(PayRefundDTO payRefundDTO);
+
+    /**
+     * 根据支付订单号查询第三方支付记录
+     * @param requestNo
+     * @return
+     */
+    OrderRefundInfo getOrderRefundInfoByRequestNo(String requestNo);
+}

+ 0 - 11
yiqi-common/src/main/java/com/yiqi/order/service/IPayService.java

@@ -83,15 +83,4 @@ public interface IPayService {
      */
     public R unifieRefundSuccessNotify(String refundNo, String orderNo, String outTradeNo);
 
-    /**
-     * 支付宝监测订单被取消或超时回调
-     *
-     * @param orderNo
-     */
-    public R alipayPayExpireOrCancelNotify(String orderNo);
-    //</editor-folder>
-
-    //<editor-folder desc="微信支付相关接口">
-
-    //</editor-folder>
 }

+ 9 - 0
yiqi-common/src/main/java/com/yiqi/settlement/service/ISettlementStoreRateService.java

@@ -1,7 +1,9 @@
 package com.yiqi.settlement.service;
 
+import java.util.Date;
 import java.util.List;
 import com.baomidou.mybatisplus.extension.service.IService;
+import com.yiqi.settlement.domain.SettlementFactoryRate;
 import com.yiqi.settlement.domain.SettlementStoreRate;
 import com.yiqi.settlement.domain.dto.SettlementStoreRateQueryDTO;
 import com.yiqi.settlement.domain.vo.SettlementStoreRateListVO;
@@ -22,4 +24,11 @@ public interface ISettlementStoreRateService extends IService<SettlementStoreRat
      */
     List<SettlementStoreRateListVO> queryList(SettlementStoreRateQueryDTO queryDTO);
 
+
+    /**
+     * 查询门店结算费率配置
+     * @param storeId
+     * @return
+     */
+    SettlementStoreRate getByStoreId(Long storeId, Date date);
 }

+ 254 - 266
yiqi-core/src/main/java/com/yiqi/core/service/impl/SettlementManageBillServiceImpl.java

@@ -25,7 +25,9 @@ import com.yiqi.order.service.IOrderGoodsService;
 import com.yiqi.recharge.domain.RechargePasswordCard;
 import com.yiqi.recharge.service.IRechargePasswordCardService;
 import com.yiqi.settlement.domain.SettlementFactoryRate;
+import com.yiqi.settlement.domain.SettlementStoreRate;
 import com.yiqi.settlement.service.ISettlementFactoryRateService;
+import com.yiqi.settlement.service.ISettlementStoreRateService;
 import com.yiqi.system.domain.ManageFactory;
 import com.yiqi.system.domain.SysSettlementRate;
 import com.yiqi.system.domain.SysStore;
@@ -58,6 +60,8 @@ public class SettlementManageBillServiceImpl extends ServiceImpl<SettlementManag
     @Autowired
     private ThreadPoolTaskExecutor threadPoolTaskExecutor;
     @Autowired
+    private ISettlementStoreRateService settlementStoreRateService;
+    @Autowired
     private IManageFactoryService factoryService;
     @Autowired
     private ISysStoreService storeService;
@@ -124,8 +128,6 @@ public class SettlementManageBillServiceImpl extends ServiceImpl<SettlementManag
                     .lt(OrderClothItem::getInFactoryTime, DateUtils.addDays(settlementManageBill.getEndTime(), 1)));
             this.buildFactorySettlement(settlementManageBill, factory, orderClothItemList);
         }
-        // 计算工厂结算明细
-//        threadPoolTaskExecutor.execute(() -> this.buildFactorySettlement(settlementManageBill, factoryList, orderClothItemList));
     }
 
     /**
@@ -140,8 +142,13 @@ public class SettlementManageBillServiceImpl extends ServiceImpl<SettlementManag
         if (CollUtil.isEmpty(storeList)) {
             return;
         }
+        for (SysStore store : storeList) {
+            this.buildStoreSettlement(settlementManageBill, store);
+        }
+
+
         // 计算门店结算明细
-        threadPoolTaskExecutor.execute(() -> this.buildStoreSettlement(settlementManageBill, storeList));
+//        threadPoolTaskExecutor.execute(() -> this.buildStoreSettlement(settlementManageBill, storeList));
     }
 
     /**
@@ -150,250 +157,256 @@ public class SettlementManageBillServiceImpl extends ServiceImpl<SettlementManag
      * @param settlementManageBill
      * @return
      */
-    private void buildStoreSettlement(SettlementManageBill settlementManageBill, List<SysStore> storeList) {
+    private void buildStoreSettlement(SettlementManageBill settlementManageBill, SysStore sysStore) {
         //查询全部门店费率
         List<SysSettlementRate> storeRateList = sysSettlementRateService.list(new QueryWrapper<SysSettlementRate>().lambda());
         Map<Long, List<SysSettlementRate>> storeRateMap = storeRateList.stream().collect(Collectors.groupingBy(SysSettlementRate::getOrgId));
         List<SettlementManageStore> settlementManageStoreList = new ArrayList<>();
-        for (SysStore sysStore : storeList) {
+
+        SettlementStoreRate settlementStoreRate =  settlementStoreRateService.getByStoreId(sysStore.getId(), settlementManageBill.getBeginTime());
+        if (settlementStoreRate == null) {
             SettlementManageStore settlementManageStore = new SettlementManageStore();
             this.buildStoreSettlementInfo(settlementManageStore, settlementManageBill, sysStore);
-            // 查询门店有效充值会员卡
-            List<RechargePasswordCard> rechargePasswordCardList = rechargePasswordCardService.list(new QueryWrapper<RechargePasswordCard>().lambda()
-
-                    .and(wrapper -> wrapper.gt(RechargePasswordCard::getRechargeBalance, BigDecimal.ZERO)
-                            .or()
-                            .gt(RechargePasswordCard::getGiveBalance, BigDecimal.ZERO))
-                    .and(wrapper -> wrapper.ge(RechargePasswordCard::getExpireTime, DateUtils.getNowDate(DateUtils.YYYY_MM_DD))
-                            .or().isNull(RechargePasswordCard::getExpireTime)));
-
-            // 查询门店未开卡
-            List<RechargePasswordCard> noOpenCardList = rechargePasswordCardService.list(new QueryWrapper<RechargePasswordCard>().lambda()
-                    .ne(RechargePasswordCard::getRechargeStatus, RechargeStatusType.NOT_UES.getCode()));
-
-            // 查询门店微信消费记录
-            List<AppUserBillMstr> wechatBillMstrList = appUserBillMstrService.list(new QueryWrapper<AppUserBillMstr>().lambda()
-                    .ne(AppUserBillMstr::getIsRefund, SysBoolType.YES.getCode())
-                    .eq(AppUserBillMstr::getSourceType, SourceType.STORE.getCode())
-                    .eq(AppUserBillMstr::getOrgId, sysStore.getId())
-                    .eq(AppUserBillMstr::getPayType, PayType.WECHAT.getCode())
-                    .ge(AppUserBillMstr::getCreateTime, settlementManageBill.getBeginTime())
-                    .lt(AppUserBillMstr::getCreateTime, DateUtils.addDays(settlementManageBill.getEndTime(), 1)));
-            // 查询门店支付宝消费记录
-            List<AppUserBillMstr> alipayBillMstrList = appUserBillMstrService.list(new QueryWrapper<AppUserBillMstr>().lambda()
-                    .ne(AppUserBillMstr::getIsRefund, SysBoolType.YES.getCode())
-                    .eq(AppUserBillMstr::getSourceType, SourceType.STORE.getCode())
-                    .eq(AppUserBillMstr::getOrgId, sysStore.getId())
-                    .eq(AppUserBillMstr::getPayType, PayType.ALIPAY.getCode())
-                    .ge(AppUserBillMstr::getCreateTime, settlementManageBill.getBeginTime())
-                    .lt(AppUserBillMstr::getCreateTime, DateUtils.addDays(settlementManageBill.getEndTime(), 1)));
-            // 查询衣服单项订单
-            ArrayList<String> statusList = new ArrayList<>();
-            statusList.add(ClothOrderFlowStatus.inFactory.getCode());
-            statusList.add(ClothOrderFlowStatus.checkCloth.getCode());
-            statusList.add(ClothOrderFlowStatus.outFactory.getCode());
-            statusList.add(ClothOrderFlowStatus.hangering.getCode());
-            statusList.add(ClothOrderFlowStatus.hasTake.getCode());
-            statusList.add(ClothOrderFlowStatus.reWash.getCode());
+            settlementManageStore.setStatus(SettlementStatusType.FAIL.getCode());
+            settlementManageStore.setRemark("结算费率无效,结算失败");
+            settlementManageStoreService.save(settlementManageStore);
+        }
 
-            List<OrderClothItem> orderClothItemList = orderClothItemService.list(new QueryWrapper<OrderClothItem>().lambda()
-                    .in(OrderClothItem::getFlowStatus, statusList)
-                    .eq(OrderClothItem::getSourceType, SourceType.STORE.getCode())
-                    .eq(OrderClothItem::getOrgId, sysStore.getId())
-                    .ge(OrderClothItem::getCreateTime, settlementManageBill.getBeginTime())
-                    .lt(OrderClothItem::getCreateTime, DateUtils.addDays(settlementManageBill.getEndTime(), 1)));
-            // 查询衣服订单
-            List<OrderCloth> orderClothList = orderClothService.list(new QueryWrapper<OrderCloth>().lambda()
-                    .ne(OrderCloth::getRefundStatus, OrderRefundStatus.REFUND_SUCCESS.getCode())
-                    .eq(OrderCloth::getSourceType, SourceType.STORE.getCode())
-                    .eq(OrderCloth::getOrgId, sysStore.getId())
-                    .ge(OrderCloth::getCreateTime, settlementManageBill.getBeginTime())
-                    .lt(OrderCloth::getCreateTime, DateUtils.addDays(settlementManageBill.getEndTime(), 1)));
-            // 查询商品订单
-            List<OrderGoods> orderGoodsList = orderGoodsService.list(new QueryWrapper<OrderGoods>().lambda()
-                    .ne(OrderGoods::getRefundStatus, OrderRefundStatus.REFUND_SUCCESS.getCode())
-                    .eq(OrderGoods::getSourceType, SourceType.STORE.getCode())
-                    .eq(OrderGoods::getOrgId, sysStore.getId())
-                    .ge(OrderGoods::getCreateTime, settlementManageBill.getBeginTime())
-                    .lt(OrderGoods::getCreateTime, DateUtils.addDays(settlementManageBill.getEndTime(), 1)));
-
-            // 查询门店跨店结算  收记录
-            List<AppUserBillMstr> crossReceiveBillMstrList = appUserBillMstrService.list(new QueryWrapper<AppUserBillMstr>().lambda()
-                    .eq(AppUserBillMstr::getSourceType, SourceType.STORE.getCode())
-                    .eq(AppUserBillMstr::getOrgId, sysStore.getId())
-                    .eq(AppUserBillMstr::getIsOtherStore, SysBoolType.YES.getCode())
-                    .eq(AppUserBillMstr::getPayType, PayType.BALANCE.getCode())
-                    .ge(AppUserBillMstr::getCreateTime, settlementManageBill.getBeginTime())
-                    .lt(AppUserBillMstr::getCreateTime, DateUtils.addDays(settlementManageBill.getEndTime(), 1)));
-            // 查询门店跨店结算  分红 (给出去)记录
-            List<AppUserBillMstr> crossSendBillMstrList = appUserBillMstrService.list(new QueryWrapper<AppUserBillMstr>().lambda()
-                    .eq(AppUserBillMstr::getSourceType, SourceType.STORE.getCode())
-                    .eq(AppUserBillMstr::getOtherStoreOrgId, sysStore.getId())
-                    .eq(AppUserBillMstr::getIsOtherStore, SysBoolType.YES.getCode())
-                    .eq(AppUserBillMstr::getPayType, PayType.BALANCE.getCode())
-                    .ge(AppUserBillMstr::getCreateTime, settlementManageBill.getBeginTime())
-                    .lt(AppUserBillMstr::getCreateTime, DateUtils.addDays(settlementManageBill.getEndTime(), 1)));
-            // 充值余额总和
-            BigDecimal totalRechargeBalance = rechargePasswordCardList.stream().map(RechargePasswordCard::getRechargeBalance).filter(Objects::nonNull).reduce(BigDecimal.ZERO, BigDecimal::add);
-            // 福利金余额总和
-//            BigDecimal totalWelfareBalance = rechargePasswordCardList.stream().map(RechargePasswordCard::getWelfareBalance).filter(Objects::nonNull).reduce(BigDecimal.ZERO, BigDecimal::add);
-            BigDecimal totalWelfareBalance = BigDecimal.ZERO;
-            // 赠送余额总和
-            BigDecimal totalGiveBalance = rechargePasswordCardList.stream().map(RechargePasswordCard::getGiveBalance).filter(Objects::nonNull).reduce(BigDecimal.ZERO, BigDecimal::add);
-            // 未开卡卡密金额总和
-            BigDecimal totalUnopenedCard = noOpenCardList.stream().map(RechargePasswordCard::getRechargeBalance).filter(Objects::nonNull).reduce(BigDecimal.ZERO, BigDecimal::add);
-            // 微信消费总和
-            BigDecimal totalWechat = wechatBillMstrList.stream().map(AppUserBillMstr::getPayTotalAmount).filter(Objects::nonNull).reduce(BigDecimal.ZERO, BigDecimal::add);
-            // 支付宝消费总和
-            BigDecimal totalAlipay = alipayBillMstrList.stream().map(AppUserBillMstr::getPayTotalAmount).filter(Objects::nonNull).reduce(BigDecimal.ZERO, BigDecimal::add);
-            // 材料金额
-            BigDecimal totalMaterialAmount = orderClothList.stream().map(OrderCloth::getPayAmount).filter(Objects::nonNull).reduce(BigDecimal.ZERO, BigDecimal::add);
-            // 系统维护金额
-            BigDecimal totalSystemAmount = orderGoodsList.stream().map(OrderGoods::getPayAmount).filter(Objects::nonNull).reduce(BigDecimal.ZERO, BigDecimal::add);
-            // 洗衣费
-            BigDecimal totalWashAmount = orderClothItemList.stream().map(OrderClothItem::getTotalPrice).filter(Objects::nonNull).reduce(BigDecimal.ZERO, BigDecimal::add);
-            // 跨店结算金 -收
-            BigDecimal totalCrossReceive = crossReceiveBillMstrList.stream().map(AppUserBillMstr::getOtherStoreAmount).filter(Objects::nonNull).reduce(BigDecimal.ZERO, BigDecimal::add);
-            // 跨店结算金 -支付
-            BigDecimal totalCrossSend = crossSendBillMstrList.stream().map(AppUserBillMstr::getOtherStoreAmount).filter(Objects::nonNull).reduce(BigDecimal.ZERO, BigDecimal::add);
-
-
-            // 设置 会员剩余金额 = 充值余额总和+福利金余额总和+赠送余额总和
-            BigDecimal addMemberBalance = totalRechargeBalance.add(totalWelfareBalance).add(totalGiveBalance);
-            settlementManageStore.setMemberBalance(addMemberBalance);
-            //`welfare_amount` '福利金额',
-            settlementManageStore.setWelfareAmount(totalWelfareBalance);
-            //   `unopened_card_password_amount` '未开卡卡密金额',
-            settlementManageStore.setUnopenedCardPasswordAmount(totalUnopenedCard);
-
-            List<SysSettlementRate> sysSettlementRates = storeRateMap.get(sysStore.getId());
-            // 应付押金
-            BigDecimal payableDeposit = BigDecimal.ZERO;
-            // 应付福利押金
-            BigDecimal welfareDeposit = BigDecimal.ZERO;
-            // 应付卡密押金
-            BigDecimal cardPasswordDeposit = BigDecimal.ZERO;
-            // 微信金额
-            BigDecimal wechatAmount = BigDecimal.ZERO;
-            // 支付宝金额
-            BigDecimal alipayAmount = BigDecimal.ZERO;
-            // 材料金额
-            BigDecimal materialAmount = BigDecimal.ZERO;
-            // 系统维护金额
-            BigDecimal systemMaintenanceAmount = BigDecimal.ZERO;
-            // 洗衣费金额
-            BigDecimal washClothAmount = BigDecimal.ZERO;
-
-            // 默认押金率
-            BigDecimal decimalDeposit = new BigDecimal(configService.selectConfigByKey(SysConfigKey.StoreSettlementDepositRate.getCode()));
-            // 默认微信率
-            BigDecimal decimalWechat = new BigDecimal(configService.selectConfigByKey(SysConfigKey.StoreSettlementWXRate.getCode()));
-            // 默认支付率
-            BigDecimal decimalAlipay = new BigDecimal(configService.selectConfigByKey(SysConfigKey.StoreSettlementAliRate.getCode()));
-            // 默认材料费率
-            BigDecimal decimalMaterial = new BigDecimal(configService.selectConfigByKey(SysConfigKey.StoreSettlementMaterialRate.getCode()));
-            // 默认系统维护费率
-            BigDecimal decimalSystem = new BigDecimal(configService.selectConfigByKey(SysConfigKey.StoreSettlementManageRate.getCode()));
-            // // 洗衣费率
-            BigDecimal decimalWashCloth = new BigDecimal(configService.selectConfigByKey(SysConfigKey.StoreSettlementFactoryRate.getCode()));
-            if (CollUtil.isEmpty(sysSettlementRates)) {
-                payableDeposit = addMemberBalance.multiply(decimalDeposit);
-                welfareDeposit = totalWelfareBalance.multiply(decimalDeposit);
-                cardPasswordDeposit = totalUnopenedCard.multiply(decimalDeposit);
-                wechatAmount = totalWechat.multiply((new BigDecimal("1").subtract(decimalWechat)));
-                alipayAmount = totalAlipay.multiply((new BigDecimal("1").subtract(decimalAlipay)));
-                materialAmount = totalMaterialAmount.multiply(decimalMaterial);
-                systemMaintenanceAmount = (totalMaterialAmount.add(totalSystemAmount)).multiply(decimalSystem);
-                washClothAmount = totalWashAmount.multiply(decimalWashCloth);
-
-                // 设置费率
-                settlementManageStore.setFactoryRate(decimalWashCloth);
-                settlementManageStore.setManageRate(decimalSystem);
-                settlementManageStore.setDepositRate(decimalDeposit);
-                settlementManageStore.setMaterialRate(decimalMaterial);
-                settlementManageStore.setWxPayRate(decimalWechat);
-                settlementManageStore.setAliPayRate(decimalAlipay);
-            } else {
-                SysSettlementRate rate = sysSettlementRates.get(0);
-                payableDeposit = addMemberBalance.multiply(rate.getDepositRate() == null ? decimalDeposit : rate.getDepositRate());
-                welfareDeposit = totalWelfareBalance.multiply(rate.getDepositRate() == null ? decimalDeposit : rate.getDepositRate());
-                cardPasswordDeposit = totalUnopenedCard.multiply(rate.getDepositRate() == null ? decimalDeposit : rate.getDepositRate());
-                wechatAmount = totalWechat.multiply((new BigDecimal("1").subtract(rate.getWxPayRate() == null ? decimalWechat : rate.getWxPayRate())));
-                alipayAmount = totalAlipay.multiply((new BigDecimal("1").subtract(rate.getAliPayRate() == null ? decimalAlipay : rate.getAliPayRate())));
-                materialAmount = totalMaterialAmount.multiply(rate.getMaterialRate() == null ? decimalMaterial : rate.getMaterialRate());
-                systemMaintenanceAmount = (totalMaterialAmount.add(totalSystemAmount)).multiply(rate.getManageRate() == null ? decimalSystem : rate.getManageRate());
-                washClothAmount = totalWashAmount.multiply(rate.getFactoryRate() == null ? decimalWashCloth : rate.getFactoryRate());
-
-                // 设置费率
-                settlementManageStore.setFactoryRate(rate.getFactoryRate());
-                settlementManageStore.setManageRate(rate.getManageRate());
-                settlementManageStore.setDepositRate(rate.getDepositRate());
-                settlementManageStore.setMaterialRate(rate.getMaterialRate());
-                settlementManageStore.setWxPayRate(rate.getWxPayRate());
-                settlementManageStore.setAliPayRate(rate.getAliPayRate());
-            }
-
-            // 设置微信金额
-            settlementManageStore.setWechatAmount(wechatAmount);
-            // 设置支付宝金额
-            settlementManageStore.setAlipayAmount(alipayAmount);
-            // 设置应付押金 payable_deposit = 会员剩余金额* 押金率
-            settlementManageStore.setPayableDeposit(payableDeposit);
-            // 设置'应付福利押金' `welfare_deposit`,
-            settlementManageStore.setWelfareDeposit(welfareDeposit);
-            //  设置'应付卡密押金' `card_password_deposit`,
-            settlementManageStore.setCardPasswordDeposit(cardPasswordDeposit);
-            //原材料备用金(材料费)
-            settlementManageStore.setMaterialImprestAmount(materialAmount);
-            //系统维护费
-            settlementManageStore.setSystemMaintenanceAmount(systemMaintenanceAmount);
-            //洗衣费
-            settlementManageStore.setWashClothAmount(washClothAmount);
-            //跨店结算金
-            settlementManageStore.setCrossStoreSettlementAmount(totalCrossSend.subtract(totalCrossReceive));
-            //超额订货金额
-            settlementManageStore.setOverOrderingAmount(BigDecimal.ZERO);
-
-            // 查询上期结算
-            List<SettlementManageStore> settlementManageStoreLastList = settlementManageStoreService.list(new QueryWrapper<SettlementManageStore>().lambda()
-                    .eq(SettlementManageStore::getOrgId, sysStore.getId())
-                    .eq(SettlementManageStore::getBeginTime, DateUtils.addMonths(settlementManageStore.getBeginTime(), -1)));
-
-            if (CollUtil.isEmpty(settlementManageStoreLastList)) {
-                // `paid_deposit` '已付押金', = 上个月的应付押金
-                settlementManageStore.setPaidDeposit(BigDecimal.ZERO);
-                // `paid_welfare_deposit`  '已付福利押金',= 上个月的应付福利押金
-                settlementManageStore.setPaidWelfareDeposit(BigDecimal.ZERO);
-                //   `paid_card_password_deposit`'已付卡密押金',
-                settlementManageStore.setPaidCardPasswordDeposit(BigDecimal.ZERO);
-            } else {
-                SettlementManageStore settlementManageStoreLast = settlementManageStoreLastList.get(0);
-                settlementManageStore.setPaidDeposit(settlementManageStoreLast.getPayableDeposit());
-                settlementManageStore.setPaidWelfareDeposit(settlementManageStoreLast.getWelfareDeposit());
-                settlementManageStore.setPaidCardPasswordDeposit(settlementManageStoreLast.getCardPasswordDeposit());
-            }
-
-            //结算金额
-
-            BigDecimal total = wechatAmount.add(alipayAmount).subtract(
-                    payableDeposit.subtract(settlementManageStore.getPaidDeposit())
-            ).subtract(
-                    welfareDeposit.subtract(settlementManageStore.getPaidWelfareDeposit())
-            ).subtract(
-                    cardPasswordDeposit.subtract(settlementManageStore.getPaidCardPasswordDeposit())
-            ).subtract(
-                    materialAmount
-            ).subtract(
-                    systemMaintenanceAmount
-            ).subtract(
-                    washClothAmount
-            ).subtract(
-                    totalCrossSend.subtract(totalCrossReceive)
-            );
-
-            settlementManageStore.setSettlementAmount(total);
-            settlementManageStoreList.add(settlementManageStore);
+        SettlementManageStore settlementManageStore = new SettlementManageStore();
+        this.buildStoreSettlementInfo(settlementManageStore, settlementManageBill, sysStore);
+        // 查询门店有效充值会员卡
+        List<RechargePasswordCard> rechargePasswordCardList = rechargePasswordCardService.list(new QueryWrapper<RechargePasswordCard>().lambda()
+                        .eq(RechargePasswordCard::getUseBindStoreId, sysStore.getId())
+                .eq(RechargePasswordCard::getRechargeStatus, RechargeStatusType.HAS_USE.getCode()));
+
+        // 查询门店未开卡
+        List<RechargePasswordCard> noOpenCardList = rechargePasswordCardService.list(new QueryWrapper<RechargePasswordCard>().lambda()
+                .eq(RechargePasswordCard::getRechargeStatus, RechargeStatusType.NOT_UES.getCode())
+                .eq(RechargePasswordCard::getRechargeStoreId, sysStore.getId()));
+
+        // 查询门店微信消费记录
+        List<AppUserBillMstr> wechatBillMstrList = appUserBillMstrService.list(new QueryWrapper<AppUserBillMstr>().lambda()
+                .ne(AppUserBillMstr::getIsRefund, SysBoolType.YES.getCode())
+                .eq(AppUserBillMstr::getSourceType, SourceType.STORE.getCode())
+                .eq(AppUserBillMstr::getOrgId, sysStore.getId())
+                .eq(AppUserBillMstr::getPayType, PayType.WECHAT.getCode())
+                .ge(AppUserBillMstr::getCreateTime, settlementManageBill.getBeginTime())
+                .lt(AppUserBillMstr::getCreateTime, DateUtils.addDays(settlementManageBill.getEndTime(), 1)));
+        // 查询门店支付宝消费记录
+        List<AppUserBillMstr> alipayBillMstrList = appUserBillMstrService.list(new QueryWrapper<AppUserBillMstr>().lambda()
+                .ne(AppUserBillMstr::getIsRefund, SysBoolType.YES.getCode())
+                .eq(AppUserBillMstr::getSourceType, SourceType.STORE.getCode())
+                .eq(AppUserBillMstr::getOrgId, sysStore.getId())
+                .eq(AppUserBillMstr::getPayType, PayType.ALIPAY.getCode())
+                .ge(AppUserBillMstr::getCreateTime, settlementManageBill.getBeginTime())
+                .lt(AppUserBillMstr::getCreateTime, DateUtils.addDays(settlementManageBill.getEndTime(), 1)));
+        // 查询衣服单项订单
+        ArrayList<String> statusList = new ArrayList<>();
+        statusList.add(ClothOrderFlowStatus.inFactory.getCode());
+        statusList.add(ClothOrderFlowStatus.checkCloth.getCode());
+        statusList.add(ClothOrderFlowStatus.outFactory.getCode());
+        statusList.add(ClothOrderFlowStatus.hangering.getCode());
+        statusList.add(ClothOrderFlowStatus.hasTake.getCode());
+        statusList.add(ClothOrderFlowStatus.reWash.getCode());
+
+        List<OrderClothItem> orderClothItemList = orderClothItemService.list(new QueryWrapper<OrderClothItem>().lambda()
+                .in(OrderClothItem::getFlowStatus, statusList)
+                .eq(OrderClothItem::getSourceType, SourceType.STORE.getCode())
+                .eq(OrderClothItem::getOrgId, sysStore.getId())
+                .ge(OrderClothItem::getCreateTime, settlementManageBill.getBeginTime())
+                .lt(OrderClothItem::getCreateTime, DateUtils.addDays(settlementManageBill.getEndTime(), 1)));
+        // 查询衣服订单
+        List<OrderCloth> orderClothList = orderClothService.list(new QueryWrapper<OrderCloth>().lambda()
+                .ne(OrderCloth::getRefundStatus, OrderRefundStatus.REFUND_SUCCESS.getCode())
+                .eq(OrderCloth::getSourceType, SourceType.STORE.getCode())
+                .eq(OrderCloth::getOrgId, sysStore.getId())
+                .ge(OrderCloth::getCreateTime, settlementManageBill.getBeginTime())
+                .lt(OrderCloth::getCreateTime, DateUtils.addDays(settlementManageBill.getEndTime(), 1)));
+        // 查询商品订单
+        List<OrderGoods> orderGoodsList = orderGoodsService.list(new QueryWrapper<OrderGoods>().lambda()
+                .ne(OrderGoods::getRefundStatus, OrderRefundStatus.REFUND_SUCCESS.getCode())
+                .eq(OrderGoods::getSourceType, SourceType.STORE.getCode())
+                .eq(OrderGoods::getOrgId, sysStore.getId())
+                .ge(OrderGoods::getCreateTime, settlementManageBill.getBeginTime())
+                .lt(OrderGoods::getCreateTime, DateUtils.addDays(settlementManageBill.getEndTime(), 1)));
+
+        // 查询门店跨店结算  收记录
+        List<AppUserBillMstr> crossReceiveBillMstrList = appUserBillMstrService.list(new QueryWrapper<AppUserBillMstr>().lambda()
+                .eq(AppUserBillMstr::getSourceType, SourceType.STORE.getCode())
+                .eq(AppUserBillMstr::getOrgId, sysStore.getId())
+                .eq(AppUserBillMstr::getIsOtherStore, SysBoolType.YES.getCode())
+                .eq(AppUserBillMstr::getPayType, PayType.BALANCE.getCode())
+                .ge(AppUserBillMstr::getCreateTime, settlementManageBill.getBeginTime())
+                .lt(AppUserBillMstr::getCreateTime, DateUtils.addDays(settlementManageBill.getEndTime(), 1)));
+        // 查询门店跨店结算  分红 (给出去)记录
+        List<AppUserBillMstr> crossSendBillMstrList = appUserBillMstrService.list(new QueryWrapper<AppUserBillMstr>().lambda()
+                .eq(AppUserBillMstr::getSourceType, SourceType.STORE.getCode())
+                .eq(AppUserBillMstr::getOtherStoreOrgId, sysStore.getId())
+                .eq(AppUserBillMstr::getIsOtherStore, SysBoolType.YES.getCode())
+                .eq(AppUserBillMstr::getPayType, PayType.BALANCE.getCode())
+                .ge(AppUserBillMstr::getCreateTime, settlementManageBill.getBeginTime())
+                .lt(AppUserBillMstr::getCreateTime, DateUtils.addDays(settlementManageBill.getEndTime(), 1)));
+        // 充值余额总和
+        BigDecimal totalRechargeBalance = rechargePasswordCardList.stream().map(RechargePasswordCard::getRechargeBalance).filter(Objects::nonNull).reduce(BigDecimal.ZERO, BigDecimal::add);
+        // 福利金余额总和
+       BigDecimal totalWelfareBalance = rechargePasswordCardList.stream().map(RechargePasswordCard::getWelfareBalance).filter(Objects::nonNull).reduce(BigDecimal.ZERO, BigDecimal::add);
+        // 赠送余额总和
+        BigDecimal totalGiveBalance = rechargePasswordCardList.stream().map(RechargePasswordCard::getGiveBalance).filter(Objects::nonNull).reduce(BigDecimal.ZERO, BigDecimal::add);
+        // 未开卡卡密金额总和
+        BigDecimal totalUnopenedCard = noOpenCardList.stream().map(RechargePasswordCard::getRechargeBalance).filter(Objects::nonNull).reduce(BigDecimal.ZERO, BigDecimal::add);
+        // 微信消费总和
+        BigDecimal totalWechat = wechatBillMstrList.stream().map(AppUserBillMstr::getPayTotalAmount).filter(Objects::nonNull).reduce(BigDecimal.ZERO, BigDecimal::add);
+        // 支付宝消费总和
+        BigDecimal totalAlipay = alipayBillMstrList.stream().map(AppUserBillMstr::getPayTotalAmount).filter(Objects::nonNull).reduce(BigDecimal.ZERO, BigDecimal::add);
+        // 材料金额
+        BigDecimal totalMaterialAmount = orderClothList.stream().map(OrderCloth::getPayAmount).filter(Objects::nonNull).reduce(BigDecimal.ZERO, BigDecimal::add);
+        // 系统维护金额
+        BigDecimal totalSystemAmount = orderGoodsList.stream().map(OrderGoods::getPayAmount).filter(Objects::nonNull).reduce(BigDecimal.ZERO, BigDecimal::add);
+        // 洗衣费
+        BigDecimal totalWashAmount = orderClothItemList.stream().map(OrderClothItem::getTotalPrice).filter(Objects::nonNull).reduce(BigDecimal.ZERO, BigDecimal::add);
+        // 跨店结算金 -收
+        BigDecimal totalCrossReceive = crossReceiveBillMstrList.stream().map(AppUserBillMstr::getOtherStoreAmount).filter(Objects::nonNull).reduce(BigDecimal.ZERO, BigDecimal::add);
+        // 跨店结算金 -支付
+        BigDecimal totalCrossSend = crossSendBillMstrList.stream().map(AppUserBillMstr::getOtherStoreAmount).filter(Objects::nonNull).reduce(BigDecimal.ZERO, BigDecimal::add);
+
+
+        // 设置 会员剩余金额 = 充值余额总和+福利金余额总和+赠送余额总和
+        BigDecimal addMemberBalance = totalRechargeBalance.add(totalWelfareBalance).add(totalGiveBalance);
+        settlementManageStore.setMemberBalance(addMemberBalance);
+        //`welfare_amount` '福利金额',
+        settlementManageStore.setWelfareAmount(totalWelfareBalance);
+        //   `unopened_card_password_amount` '未开卡卡密金额',
+        settlementManageStore.setUnopenedCardPasswordAmount(totalUnopenedCard);
+
+        List<SysSettlementRate> sysSettlementRates = storeRateMap.get(sysStore.getId());
+        // 应付押金
+        BigDecimal payableDeposit = BigDecimal.ZERO;
+        // 应付福利押金
+        BigDecimal welfareDeposit = BigDecimal.ZERO;
+        // 应付卡密押金
+        BigDecimal cardPasswordDeposit = BigDecimal.ZERO;
+        // 微信金额
+        BigDecimal wechatAmount = BigDecimal.ZERO;
+        // 支付宝金额
+        BigDecimal alipayAmount = BigDecimal.ZERO;
+        // 材料金额
+        BigDecimal materialAmount = BigDecimal.ZERO;
+        // 系统维护金额
+        BigDecimal systemMaintenanceAmount = BigDecimal.ZERO;
+        // 洗衣费金额
+        BigDecimal washClothAmount = BigDecimal.ZERO;
+
+        // 默认押金率
+        BigDecimal decimalDeposit = new BigDecimal(configService.selectConfigByKey(SysConfigKey.StoreSettlementDepositRate.getCode()));
+        // 默认微信率
+        BigDecimal decimalWechat = new BigDecimal(configService.selectConfigByKey(SysConfigKey.StoreSettlementWXRate.getCode()));
+        // 默认支付率
+        BigDecimal decimalAlipay = new BigDecimal(configService.selectConfigByKey(SysConfigKey.StoreSettlementAliRate.getCode()));
+        // 默认材料费率
+        BigDecimal decimalMaterial = new BigDecimal(configService.selectConfigByKey(SysConfigKey.StoreSettlementMaterialRate.getCode()));
+        // 默认系统维护费率
+        BigDecimal decimalSystem = new BigDecimal(configService.selectConfigByKey(SysConfigKey.StoreSettlementManageRate.getCode()));
+        // // 洗衣费率
+        BigDecimal decimalWashCloth = new BigDecimal(configService.selectConfigByKey(SysConfigKey.StoreSettlementFactoryRate.getCode()));
+        if (CollUtil.isEmpty(sysSettlementRates)) {
+            payableDeposit = addMemberBalance.multiply(decimalDeposit);
+            welfareDeposit = totalWelfareBalance.multiply(decimalDeposit);
+            cardPasswordDeposit = totalUnopenedCard.multiply(decimalDeposit);
+            wechatAmount = totalWechat.multiply((new BigDecimal("1").subtract(decimalWechat)));
+            alipayAmount = totalAlipay.multiply((new BigDecimal("1").subtract(decimalAlipay)));
+            materialAmount = totalMaterialAmount.multiply(decimalMaterial);
+            systemMaintenanceAmount = (totalMaterialAmount.add(totalSystemAmount)).multiply(decimalSystem);
+            washClothAmount = totalWashAmount.multiply(decimalWashCloth);
+
+            // 设置费率
+            settlementManageStore.setFactoryRate(decimalWashCloth);
+            settlementManageStore.setManageRate(decimalSystem);
+            settlementManageStore.setDepositRate(decimalDeposit);
+            settlementManageStore.setMaterialRate(decimalMaterial);
+            settlementManageStore.setWxPayRate(decimalWechat);
+            settlementManageStore.setAliPayRate(decimalAlipay);
+        } else {
+            SysSettlementRate rate = sysSettlementRates.get(0);
+            payableDeposit = addMemberBalance.multiply(rate.getDepositRate() == null ? decimalDeposit : rate.getDepositRate());
+            welfareDeposit = totalWelfareBalance.multiply(rate.getDepositRate() == null ? decimalDeposit : rate.getDepositRate());
+            cardPasswordDeposit = totalUnopenedCard.multiply(rate.getDepositRate() == null ? decimalDeposit : rate.getDepositRate());
+            wechatAmount = totalWechat.multiply((new BigDecimal("1").subtract(rate.getWxPayRate() == null ? decimalWechat : rate.getWxPayRate())));
+            alipayAmount = totalAlipay.multiply((new BigDecimal("1").subtract(rate.getAliPayRate() == null ? decimalAlipay : rate.getAliPayRate())));
+            materialAmount = totalMaterialAmount.multiply(rate.getMaterialRate() == null ? decimalMaterial : rate.getMaterialRate());
+            systemMaintenanceAmount = (totalMaterialAmount.add(totalSystemAmount)).multiply(rate.getManageRate() == null ? decimalSystem : rate.getManageRate());
+            washClothAmount = totalWashAmount.multiply(rate.getFactoryRate() == null ? decimalWashCloth : rate.getFactoryRate());
+
+            // 设置费率
+            settlementManageStore.setFactoryRate(rate.getFactoryRate());
+            settlementManageStore.setManageRate(rate.getManageRate());
+            settlementManageStore.setDepositRate(rate.getDepositRate());
+            settlementManageStore.setMaterialRate(rate.getMaterialRate());
+            settlementManageStore.setWxPayRate(rate.getWxPayRate());
+            settlementManageStore.setAliPayRate(rate.getAliPayRate());
         }
+
+        // 设置微信金额
+        settlementManageStore.setWechatAmount(wechatAmount);
+        // 设置支付宝金额
+        settlementManageStore.setAlipayAmount(alipayAmount);
+        // 设置应付押金 payable_deposit = 会员剩余金额* 押金率
+        settlementManageStore.setPayableDeposit(payableDeposit);
+        // 设置'应付福利押金' `welfare_deposit`,
+        settlementManageStore.setWelfareDeposit(welfareDeposit);
+        //  设置'应付卡密押金' `card_password_deposit`,
+        settlementManageStore.setCardPasswordDeposit(cardPasswordDeposit);
+        //原材料备用金(材料费)
+        settlementManageStore.setMaterialImprestAmount(materialAmount);
+        //系统维护费
+        settlementManageStore.setSystemMaintenanceAmount(systemMaintenanceAmount);
+        //洗衣费
+        settlementManageStore.setWashClothAmount(washClothAmount);
+        //跨店结算金
+        settlementManageStore.setCrossStoreSettlementAmount(totalCrossSend.subtract(totalCrossReceive));
+        //超额订货金额
+        settlementManageStore.setOverOrderingAmount(BigDecimal.ZERO);
+
+        // 查询上期结算
+        List<SettlementManageStore> settlementManageStoreLastList = settlementManageStoreService.list(new QueryWrapper<SettlementManageStore>().lambda()
+                .eq(SettlementManageStore::getOrgId, sysStore.getId())
+                .eq(SettlementManageStore::getBeginTime, DateUtils.addMonths(settlementManageStore.getBeginTime(), -1)));
+
+        if (CollUtil.isEmpty(settlementManageStoreLastList)) {
+            // `paid_deposit` '已付押金', = 上个月的应付押金
+            settlementManageStore.setPaidDeposit(BigDecimal.ZERO);
+            // `paid_welfare_deposit`  '已付福利押金',= 上个月的应付福利押金
+            settlementManageStore.setPaidWelfareDeposit(BigDecimal.ZERO);
+            //   `paid_card_password_deposit`'已付卡密押金',
+            settlementManageStore.setPaidCardPasswordDeposit(BigDecimal.ZERO);
+        } else {
+            SettlementManageStore settlementManageStoreLast = settlementManageStoreLastList.get(0);
+            settlementManageStore.setPaidDeposit(settlementManageStoreLast.getPayableDeposit());
+            settlementManageStore.setPaidWelfareDeposit(settlementManageStoreLast.getWelfareDeposit());
+            settlementManageStore.setPaidCardPasswordDeposit(settlementManageStoreLast.getCardPasswordDeposit());
+        }
+
+        //结算金额
+
+        BigDecimal total = wechatAmount.add(alipayAmount).subtract(
+                payableDeposit.subtract(settlementManageStore.getPaidDeposit())
+        ).subtract(
+                welfareDeposit.subtract(settlementManageStore.getPaidWelfareDeposit())
+        ).subtract(
+                cardPasswordDeposit.subtract(settlementManageStore.getPaidCardPasswordDeposit())
+        ).subtract(
+                materialAmount
+        ).subtract(
+                systemMaintenanceAmount
+        ).subtract(
+                washClothAmount
+        ).subtract(
+                totalCrossSend.subtract(totalCrossReceive)
+        );
+
+        settlementManageStore.setSettlementAmount(total);
+        settlementManageStoreList.add(settlementManageStore);
+
+
         settlementManageBill.setStatus(SettlementBillStatusType.WAITING.getCode());
         this.updateById(settlementManageBill);
         settlementManageStoreService.saveBatch(settlementManageStoreList);
@@ -472,37 +485,12 @@ public class SettlementManageBillServiceImpl extends ServiceImpl<SettlementManag
         BigDecimal managetAmount = CurrencyUtil.mul(settlementFactoryRate.getManagementRate(), orderClothItemTotalPrice);
         settlementManageFactory.setManageAmount(managetAmount);
         //工厂结算金额总和
-        BigDecimal factorySettlementAmount = CurrencyUtil.mul(settlementFactoryRate.getDepositRate(), orderClothItemTotalPrice);
-        settlementManageFactory.setFactorySettlementAmount(managetAmount);
-
-        // 工厂结算金额总和
-        settlementManageFactory.setFactorySettlementAmount(
-                orderClothItemList.stream().map(OrderClothItem::getFactorySettlementAmount).filter(Objects::nonNull).reduce(BigDecimal.ZERO, BigDecimal::add));
-        // 材料结算金额总和
-        settlementManageFactory.setMaterialAmount(
-                orderClothItemList.stream().map(OrderClothItem::getMaterialAmount).filter(Objects::nonNull).reduce(BigDecimal.ZERO, BigDecimal::add));
-        // 管理结算金额总和
-        settlementManageFactory.setManageAmount(
-                orderClothItemList.stream().map(OrderClothItem::getManageAmount).filter(Objects::nonNull).reduce(BigDecimal.ZERO, BigDecimal::add));
-        // 总交易金额
-        settlementManageFactory.setTotalTransactionAmount(
-                orderClothItemList.stream().map(OrderClothItem::getTotalPrice).filter(Objects::nonNull).reduce(BigDecimal.ZERO, BigDecimal::add));
-        // 总交易件数
-        settlementManageFactory.setTotalTransactionNum(orderClothItemList.size());
-
+        BigDecimal factorySettlementAmount = orderClothItemList.stream().map(OrderClothItem::getFactorySettlementAmount).filter(Objects::nonNull).reduce(BigDecimal.ZERO, BigDecimal::add);
+        settlementManageFactory.setFactorySettlementAmount(factorySettlementAmount);
         // 工厂消费 = 材料费+ 管理费
         BigDecimal payMoney = settlementManageFactory.getManageAmount().add(settlementManageFactory.getMaterialAmount());
         // 工厂实际收入 = 工厂结算金额总和 - 工厂消费
         settlementManageFactory.setRealIncomeAmount(settlementManageFactory.getFactorySettlementAmount().subtract(payMoney));
-
-
-        if (map.containsKey(factory.getId())) {
-            // 本工厂有订单衣服,进行计算
-            this.buildHasClothFactory(settlementManageFactory, map.get(factory.getId()));
-        } else {
-            // 本工厂没有订单衣服,设置为0
-            this.build0ClothFactory(settlementManageFactory);
-        }
         settlementManageFactoryService.save(settlementManageFactory);
 
         // 设置账单洗衣费

+ 4 - 5
yiqi-core/src/main/java/com/yiqi/delay/impl/DelayTaskRunService.java

@@ -9,7 +9,6 @@ import com.yiqi.order.domain.OrderPayInfo;
 import com.yiqi.order.domain.dto.PayRefundDTO;
 import com.yiqi.order.domain.dto.PayResponseDTO;
 import com.yiqi.order.domain.dto.RefundResponseDTO;
-import com.yiqi.order.domain.vo.OrderPayResultVO;
 import com.yiqi.order.service.IPayService;
 import lombok.extern.slf4j.Slf4j;
 import org.springframework.beans.factory.annotation.Autowired;
@@ -39,9 +38,9 @@ public class DelayTaskRunService {
                 PayResponseDTO payResponseDTO = payService.orderPayQuery(orderPayInfo);
                 log.info("订单支付查询结果:{}", JSONUtil.toJsonStr(payResponseDTO));
                 if (payResponseDTO.getPayResult().equals(PayResult.success.getCode())) {
-                    R result = payService.unifiePaySuccessNotify(orderPayInfo.getPayOrderNo(), orderPayInfo.getOrderNo(), payResponseDTO.getOutTradeNo());
+                    R result = payService.unifiePaySuccessNotify(orderPayInfo.getRequestNo(), orderPayInfo.getOrderNo(), payResponseDTO.getOutTradeNo());
                     if (R.isSuccess(result)) {
-                        delayQueueCache.deleteDelayJob(orderPayInfo.getPayOrderNo());
+                        delayQueueCache.deleteDelayJob(orderPayInfo.getRequestNo());
                     } else {
                         log.error("订单支付成功,更新订单失败,订单号:{},错误信息:{}", orderPayInfo.getOrderNo(), result.getMsg());
                         //继续增加到延迟队列
@@ -49,14 +48,14 @@ public class DelayTaskRunService {
                         delayQueueCache.addDelayJob(delayMessage, PayQueryTimesEnum.getDelayTime(delayMessage.getPollingNum()));
                     }
                 } else if (payResponseDTO.getPayResult().equals(PayResult.fail.getCode())) {
-                    delayQueueCache.deleteDelayJob(orderPayInfo.getPayOrderNo());
+                    delayQueueCache.deleteDelayJob(orderPayInfo.getRequestNo());
                 } else {
                     //继续增加到延迟队列
                     delayMessage.setPollingNum(delayMessage.getPollingNum() + 1);
                     delayQueueCache.addDelayJob(delayMessage, PayQueryTimesEnum.getDelayTime(delayMessage.getPollingNum()));
                 }
                 if(delayMessage.getPollingNum() > 16){
-                    delayQueueCache.deleteDelayJob(orderPayInfo.getPayOrderNo());
+                    delayQueueCache.deleteDelayJob(orderPayInfo.getRequestNo());
                 }
                 break;
             case ORDER_REUND_DELAY_QUEUE_TASK:

+ 67 - 0
yiqi-core/src/main/java/com/yiqi/order/mapper/OrderRefundInfoMapper.java

@@ -0,0 +1,67 @@
+package com.yiqi.order.mapper;
+
+import java.util.List;
+
+import com.baomidou.mybatisplus.core.mapper.BaseMapper;
+import org.apache.ibatis.annotations.Mapper;
+import com.yiqi.order.domain.OrderRefundInfo;
+
+/**
+ * 第三方退款记录Mapper接口
+ *
+ * @author douya
+ * @date 2024-09-16
+ */
+@Mapper
+public interface OrderRefundInfoMapper extends BaseMapper<OrderRefundInfo> {
+    //<editor-folder desc="基础韩素">
+
+    /**
+     * 查询第三方退款记录
+     *
+     * @param id 第三方退款记录主键
+     * @return 第三方退款记录
+     */
+    public OrderRefundInfo selectOrderRefundInfoById(Long id);
+
+    /**
+     * 查询第三方退款记录列表
+     *
+     * @param orderRefundInfo 第三方退款记录
+     * @return 第三方退款记录集合
+     */
+    public List<OrderRefundInfo> selectOrderRefundInfoList(OrderRefundInfo orderRefundInfo);
+
+    /**
+     * 新增第三方退款记录
+     *
+     * @param orderRefundInfo 第三方退款记录
+     * @return 结果
+     */
+    public int insertOrderRefundInfo(OrderRefundInfo orderRefundInfo);
+
+    /**
+     * 修改第三方退款记录
+     *
+     * @param orderRefundInfo 第三方退款记录
+     * @return 结果
+     */
+    public int updateOrderRefundInfo(OrderRefundInfo orderRefundInfo);
+
+    /**
+     * 删除第三方退款记录
+     *
+     * @param id 第三方退款记录主键
+     * @return 结果
+     */
+    public int deleteOrderRefundInfoById(Long id);
+
+    /**
+     * 批量删除第三方退款记录
+     *
+     * @param ids 需要删除的数据主键集合
+     * @return 结果
+     */
+    public int deleteOrderRefundInfoByIds(Long[] ids);
+    //</editor-folder>
+}

+ 6 - 5
yiqi-core/src/main/java/com/yiqi/order/service/impl/OrderClothServiceImpl.java

@@ -183,7 +183,7 @@ public class OrderClothServiceImpl extends ServiceImpl<OrderClothMapper, OrderCl
 
     @Override
     public R payExpireOrCancelNotify(String orderNo) {
-        OrderPayInfo orderPayInfo = orderPayInfoService.getOrderPayInfoByPayOrderNo(orderNo);
+        OrderPayInfo orderPayInfo = orderPayInfoService.getOrderPayInfoByRequestNo(orderNo);
         if (orderPayInfo == null) {
             return R.fail("未查询到订单");
         }
@@ -452,6 +452,7 @@ public class OrderClothServiceImpl extends ServiceImpl<OrderClothMapper, OrderCl
             PayRefundDTO payRefundDTO = new PayRefundDTO(orderCloth.getPayType(), orderCloth.getOrderNo(), orderClothRefund.getRefundAmount(), orderClothRefund.getRefundNo(), orderCloth.getOutTradeOrderNo(), remark);
             //执行微信退款逻辑
             payRefundDTO.setTotalAmount(orderCloth.getPayAmount());
+            payRefundDTO.setStoreId(orderCloth.getOrgId());
             RefundResponseDTO refundResponse = payService.refundApply(payRefundDTO);
 
             if (refundResponse.getRefundResult().equals(PayResult.success.getCode())) {
@@ -508,18 +509,18 @@ public class OrderClothServiceImpl extends ServiceImpl<OrderClothMapper, OrderCl
                 //创建支付订单,防止出现错误
                 OrderPayInfo orderPayInfo = orderPayInfoService.createOrderPayInfo(orderCloth.getOrderNo(), orderCloth.getPayAmount(), orderCloth.getPayType());
                 //优先增加到延迟队列
-                DelayMessage delayMessage = new DelayMessage(orderPayInfo.getPayOrderNo(), DelayTagsEnum.ORDER_PAY_DELAY_QUEUE.getCode(), JSONUtil.toJsonStr(orderPayInfo));
+                DelayMessage delayMessage = new DelayMessage(orderPayInfo.getRequestNo(), DelayTagsEnum.ORDER_PAY_DELAY_QUEUE.getCode(), JSONUtil.toJsonStr(orderPayInfo));
                 //暂不执行
                 delayMessage.setIsRun(0);
                 delayQueueCache.addDelayJob(delayMessage, PayQueryTimesEnum.getDelayTime(delayMessage.getPollingNum()));
 
-                PayResponseDTO payResponseDTO = payService.faceToFacePay(PayOrderFaceToFaceDTO.createRechargeOrderPayData(orderPayInfo.getPayOrderNo(), orderPayInfo.getPayAmount(), orderPayInfo.getPayType(), orderClothPayDTO.getAuthCode()));
+                PayResponseDTO payResponseDTO = payService.faceToFacePay(PayOrderFaceToFaceDTO.createRechargeOrderPayData(orderPayInfo.getRequestNo(), orderPayInfo.getPayAmount(), orderPayInfo.getPayType(), orderClothPayDTO.getAuthCode()));
                 if (payResponseDTO.getPayResult().equals(PayResult.success.getCode())) {
                     paySuccess(orderCloth);
-                    delayQueueCache.deleteDelayJob(orderPayInfo.getPayOrderNo());
+                    delayQueueCache.deleteDelayJob(orderPayInfo.getRequestNo());
                     return OrderPayResultVO.paySuccess(orderCloth.getOrderNo());
                 } else if (payResponseDTO.getPayResult().equals(PayResult.fail.getCode())) {
-                    delayQueueCache.deleteDelayJob(orderPayInfo.getPayOrderNo());
+                    delayQueueCache.deleteDelayJob(orderPayInfo.getRequestNo());
                     return OrderPayResultVO.payError(payResponseDTO.getPayMsg());
                 } else {
                     //更新开始执行查询

+ 4 - 6
yiqi-core/src/main/java/com/yiqi/order/service/impl/OrderGoodsServiceImpl.java

@@ -7,7 +7,6 @@ import java.util.stream.Collectors;
 
 import cn.binarywang.wx.miniapp.bean.express.result.WxMaExpressOrderInfoResult;
 import cn.hutool.core.collection.CollUtil;
-import cn.hutool.core.util.StrUtil;
 import cn.hutool.json.JSONUtil;
 import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
 import com.yiqi.app.domain.AppGoodsMarket;
@@ -43,7 +42,6 @@ import com.yiqi.order.domain.dto.weapp.AppOrderGoodsRefundDTO;
 import com.yiqi.order.domain.vo.*;
 import com.yiqi.order.domain.vo.weapp.AppGoodsOrderInfoQueryVO;
 import com.yiqi.order.service.*;
-import com.yiqi.recharge.domain.RechargePasswordCard;
 import com.yiqi.recharge.domain.dto.ConsumeOrderDTO;
 import com.yiqi.recharge.service.IRechargePasswordCardService;
 import org.springframework.beans.BeanUtils;
@@ -301,19 +299,19 @@ public class OrderGoodsServiceImpl extends ServiceImpl<OrderGoodsMapper, OrderGo
                 //创建支付订单,防止出现错误
                 OrderPayInfo orderPayInfo = orderPayInfoService.createOrderPayInfo(orderGoods.getOrderNo(), orderGoods.getPayAmount(), orderGoods.getPayType());
                 //优先增加到延迟队列
-                DelayMessage delayMessage = new DelayMessage(orderPayInfo.getPayOrderNo(), DelayTagsEnum.ORDER_PAY_DELAY_QUEUE.getCode(), JSONUtil.toJsonStr(orderPayInfo));
+                DelayMessage delayMessage = new DelayMessage(orderPayInfo.getRequestNo(), DelayTagsEnum.ORDER_PAY_DELAY_QUEUE.getCode(), JSONUtil.toJsonStr(orderPayInfo));
                 //暂不执行
                 delayMessage.setIsRun(0);
                 delayQueueCache.addDelayJob(delayMessage, PayQueryTimesEnum.getDelayTime(delayMessage.getPollingNum()));
-                PayResponseDTO payResponseDTO = payService.faceToFacePay(PayOrderFaceToFaceDTO.createRechargeOrderPayData(orderPayInfo.getPayOrderNo(), orderPayInfo.getPayAmount(), orderPayInfo.getPayType(), orderGoodsDTO.getAuthCode()));
+                PayResponseDTO payResponseDTO = payService.faceToFacePay(PayOrderFaceToFaceDTO.createRechargeOrderPayData(orderPayInfo.getRequestNo(), orderPayInfo.getPayAmount(), orderPayInfo.getPayType(), orderGoodsDTO.getAuthCode()));
                 if (payResponseDTO.getPayResult().equals(PayResult.success.getCode())) {
                     this.handlePaySuccessUpdateOrderStatus(orderGoods.getOrderNo(), null);
                     orderPayResultVO = OrderPayResultVO.paySuccess(orderGoods.getOrderNo());
                     orderPayResultVO.setOrderId(orderGoods.getId());
-                    delayQueueCache.deleteDelayJob(orderPayInfo.getPayOrderNo());
+                    delayQueueCache.deleteDelayJob(orderPayInfo.getRequestNo());
                     return orderPayResultVO;
                 } else if (payResponseDTO.getPayResult().equals(PayResult.fail.getCode())) {
-                    delayQueueCache.deleteDelayJob(orderPayInfo.getPayOrderNo());
+                    delayQueueCache.deleteDelayJob(orderPayInfo.getRequestNo());
                     return OrderPayResultVO.payError(payResponseDTO.getPayMsg());
                 } else {
                     //更新开始执行查询

+ 5 - 9
yiqi-core/src/main/java/com/yiqi/order/service/impl/OrderPayInfoServiceImpl.java

@@ -6,8 +6,6 @@ import java.util.List;
 import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
 import com.yiqi.common.utils.DateUtils;
 import com.yiqi.common.utils.OrderNoUtils;
-import com.yiqi.common.utils.SecurityUtils;
-import com.yiqi.order.domain.OrderCloth;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 import com.yiqi.order.mapper.OrderPayInfoMapper;
@@ -26,8 +24,6 @@ public class OrderPayInfoServiceImpl extends ServiceImpl<OrderPayInfoMapper, Ord
     @Autowired
     private OrderNoUtils orderNoUtils;
 
-    //<editor-folder desc="基础韩素">
-
     /**
      * 查询第三方支付记录
      *
@@ -59,7 +55,7 @@ public class OrderPayInfoServiceImpl extends ServiceImpl<OrderPayInfoMapper, Ord
     @Override
     public int insertOrderPayInfo(OrderPayInfo orderPayInfo) {
         orderPayInfo.setCreateTime(DateUtils.getNowDate());
-        return baseMapper.insertOrderPayInfo(orderPayInfo);
+        return baseMapper.insert(orderPayInfo);
     }
 
     /**
@@ -70,7 +66,7 @@ public class OrderPayInfoServiceImpl extends ServiceImpl<OrderPayInfoMapper, Ord
      */
     @Override
     public int updateOrderPayInfo(OrderPayInfo orderPayInfo) {
-        return baseMapper.updateOrderPayInfo(orderPayInfo);
+        return baseMapper.updateById(orderPayInfo);
     }
 
     /**
@@ -101,15 +97,15 @@ public class OrderPayInfoServiceImpl extends ServiceImpl<OrderPayInfoMapper, Ord
         orderPayInfo.setPayType(payType);
         orderPayInfo.setOrderNo(orderNo);
         orderPayInfo.setPayAmount(payAmount);
-        orderPayInfo.setPayOrderNo(orderNoUtils.getOrderNo(orderNo.substring(0, 2)));
+        orderPayInfo.setRequestNo(orderNoUtils.getOrderNo(orderNo.substring(0, 2)));
         orderPayInfo.setCreateTime(DateUtils.getNowDate());
         baseMapper.insert(orderPayInfo);
         return orderPayInfo;
     }
 
     @Override
-    public OrderPayInfo getOrderPayInfoByPayOrderNo(String payOrderNo) {
-        return getOne(new QueryWrapper<OrderPayInfo>().lambda().eq(OrderPayInfo::getPayOrderNo, payOrderNo));
+    public OrderPayInfo getOrderPayInfoByRequestNo(String payOrderNo) {
+        return getOne(new QueryWrapper<OrderPayInfo>().lambda().eq(OrderPayInfo::getRequestNo, payOrderNo));
     }
 
 }

+ 6 - 6
yiqi-core/src/main/java/com/yiqi/order/service/impl/OrderRechargeServiceImpl.java

@@ -9,8 +9,6 @@ import com.yiqi.activity.domain.ActivityRechargeItem;
 import com.yiqi.app.domain.AppUser;
 import com.yiqi.app.service.IAppUserPointLogService;
 import com.yiqi.app.service.IAppUserService;
-import com.yiqi.app.service.impl.AppUserBillMstrServiceImpl;
-import com.yiqi.app.service.impl.AppUserPointLogServiceImpl;
 import com.yiqi.common.exception.ServiceException;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
 import com.yiqi.activity.service.IActivityRechargeItemService;
@@ -275,6 +273,8 @@ public class OrderRechargeServiceImpl extends ServiceImpl<OrderRechargeMapper, O
                     , orderRechargeRefund.getWxRefundAmount(), orderRechargeRefund.getRefundNo(), orderRecharge.getOutTradeOrderNo()
                     , orderRechargeRefund.getRefundReason());
         }
+        payRefundDTO.setTotalAmount(orderRecharge.getPayAmount());
+        payRefundDTO.setStoreId(orderRecharge.getStoreId());
         RefundResponseDTO refundResponse = payService.refundApply(payRefundDTO);
         if (refundResponse.getRefundResult().equals(PayResult.success.getCode())) {
             refundSuccess(orderRechargeRefund.getOrderNo());
@@ -448,17 +448,17 @@ public class OrderRechargeServiceImpl extends ServiceImpl<OrderRechargeMapper, O
                     BigDecimal payAmount = CurrencyUtil.add(orderRecharge.getWxPayAmount(), orderRecharge.getAliPayAmount());
                     OrderPayInfo orderPayInfo = orderPayInfoService.createOrderPayInfo(orderRecharge.getOrderNo(), payAmount, orderRecharge.getWxPayAmount().compareTo(BigDecimal.ZERO) > 0 ? PayType.WECHAT.getCode() : PayType.ALIPAY.getCode());
                     //优先增加到延迟队列
-                    DelayMessage delayMessage = new DelayMessage(orderPayInfo.getPayOrderNo(), DelayTagsEnum.ORDER_PAY_DELAY_QUEUE.getCode(), JSONUtil.toJsonStr(orderPayInfo));
+                    DelayMessage delayMessage = new DelayMessage(orderPayInfo.getRequestNo(), DelayTagsEnum.ORDER_PAY_DELAY_QUEUE.getCode(), JSONUtil.toJsonStr(orderPayInfo));
                     //暂不执行
                     delayMessage.setIsRun(0);
                     delayQueueCache.addDelayJob(delayMessage, PayQueryTimesEnum.getDelayTime(delayMessage.getPollingNum()));
-                    PayResponseDTO payResponseDTO = payService.faceToFacePay(PayOrderFaceToFaceDTO.createRechargeOrderPayData(orderPayInfo.getPayOrderNo(), orderPayInfo.getPayAmount(), orderPayInfo.getPayType(), orderRechargeCreateDTO.getAuthCode()));
+                    PayResponseDTO payResponseDTO = payService.faceToFacePay(PayOrderFaceToFaceDTO.createRechargeOrderPayData(orderPayInfo.getRequestNo(), orderPayInfo.getPayAmount(), orderPayInfo.getPayType(), orderRechargeCreateDTO.getAuthCode()));
                     if (payResponseDTO.getPayResult().equals(PayResult.success.getCode())) {
                         paySuccess(orderRecharge, payResponseDTO.getOutTradeNo());
-                        delayQueueCache.deleteDelayJob(orderPayInfo.getPayOrderNo());
+                        delayQueueCache.deleteDelayJob(orderPayInfo.getRequestNo());
                         return OrderPayResultVO.paySuccess(orderRecharge.getOrderNo());
                     } else if (payResponseDTO.getPayResult().equals(PayResult.fail.getCode())) {
-                        delayQueueCache.deleteDelayJob(orderPayInfo.getPayOrderNo());
+                        delayQueueCache.deleteDelayJob(orderPayInfo.getRequestNo());
                         return OrderPayResultVO.payError(payResponseDTO.getPayMsg());
                     } else {//更新开始执行查询
                         delayMessage.setIsRun(1);

+ 118 - 0
yiqi-core/src/main/java/com/yiqi/order/service/impl/OrderRefundInfoServiceImpl.java

@@ -0,0 +1,118 @@
+package com.yiqi.order.service.impl;
+
+import java.util.List;
+
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
+import com.yiqi.common.utils.DateUtils;
+import com.yiqi.common.utils.OrderNoUtils;
+import com.yiqi.common.utils.SecurityUtils;
+import com.yiqi.order.domain.OrderPayInfo;
+import com.yiqi.order.domain.dto.PayRefundDTO;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
+import com.yiqi.order.mapper.OrderRefundInfoMapper;
+import com.yiqi.order.domain.OrderRefundInfo;
+import com.yiqi.order.service.IOrderRefundInfoService;
+import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
+
+/**
+ * 第三方退款记录Service业务层处理
+ *
+ * @author douya
+ * @date 2024-09-16
+ */
+@Service
+public class OrderRefundInfoServiceImpl extends ServiceImpl<OrderRefundInfoMapper, OrderRefundInfo> implements IOrderRefundInfoService {
+
+    @Autowired
+    private OrderNoUtils orderNoUtils;
+
+    /**
+     * 查询第三方退款记录
+     *
+     * @param id 第三方退款记录主键
+     * @return 第三方退款记录
+     */
+    @Override
+    public OrderRefundInfo selectOrderRefundInfoById(Long id) {
+        return baseMapper.selectOrderRefundInfoById(id);
+    }
+
+    /**
+     * 查询第三方退款记录列表
+     *
+     * @param orderRefundInfo 第三方退款记录
+     * @return 第三方退款记录
+     */
+    @Override
+    public List<OrderRefundInfo> selectOrderRefundInfoList(OrderRefundInfo orderRefundInfo) {
+        return baseMapper.selectOrderRefundInfoList(orderRefundInfo);
+    }
+
+    /**
+     * 新增第三方退款记录
+     *
+     * @param orderRefundInfo 第三方退款记录
+     * @return 结果
+     */
+    @Override
+    public int insertOrderRefundInfo(OrderRefundInfo orderRefundInfo) {
+        orderRefundInfo.setCreateTime(DateUtils.getNowDate());
+        return baseMapper.insert(orderRefundInfo);
+    }
+
+    /**
+     * 修改第三方退款记录
+     *
+     * @param orderRefundInfo 第三方退款记录
+     * @return 结果
+     */
+    @Override
+    public int updateOrderRefundInfo(OrderRefundInfo orderRefundInfo) {
+        return baseMapper.updateById(orderRefundInfo);
+    }
+
+    /**
+     * 批量删除第三方退款记录
+     *
+     * @param ids 需要删除的第三方退款记录主键
+     * @return 结果
+     */
+    @Override
+    public int deleteOrderRefundInfoByIds(Long[] ids) {
+        return baseMapper.deleteOrderRefundInfoByIds(ids);
+    }
+
+    /**
+     * 删除第三方退款记录信息
+     *
+     * @param id 第三方退款记录主键
+     * @return 结果
+     */
+    @Override
+    public int deleteOrderRefundInfoById(Long id) {
+        return baseMapper.deleteOrderRefundInfoById(id);
+    }
+
+    @Override
+    public OrderRefundInfo createOrderRefundInfo(PayRefundDTO payRefundDTO) {
+        OrderRefundInfo orderRefundInfo = new OrderRefundInfo();
+        orderRefundInfo.setStoreId(payRefundDTO.getStoreId());
+        orderRefundInfo.setOriginOrderNo(payRefundDTO.getOrderNo());
+        orderRefundInfo.setRefundOrderNo(payRefundDTO.getOutRequestNo());
+        orderRefundInfo.setRequestNo(orderNoUtils.getOrderNo(payRefundDTO.getOrderNo().substring(0, 2)));
+        orderRefundInfo.setRefundAmount(payRefundDTO.getRefundAmount());
+        orderRefundInfo.setPayAmount(payRefundDTO.getTotalAmount());
+        orderRefundInfo.setPayType(payRefundDTO.getPayType());
+        orderRefundInfo.setRefundStatus("0");
+        orderRefundInfo.setCreateTime(DateUtils.getNowDate());
+        insertOrderRefundInfo(orderRefundInfo);
+        return orderRefundInfo;
+    }
+
+    @Override
+    public OrderRefundInfo getOrderRefundInfoByRequestNo(String requestNo) {
+        return getOne(new QueryWrapper<OrderRefundInfo>().lambda().eq(OrderRefundInfo::getRequestNo, requestNo));
+    }
+
+}

+ 23 - 55
yiqi-core/src/main/java/com/yiqi/order/service/impl/PayServiceImpl.java

@@ -5,21 +5,10 @@ import com.alipay.api.AlipayApiException;
 import com.alipay.api.AlipayClient;
 import com.alipay.api.AlipayConfig;
 import com.alipay.api.DefaultAlipayClient;
-import com.alipay.api.request.AlipayTradeAppPayRequest;
-import com.alipay.api.request.AlipayTradePayRequest;
 import com.alipay.api.request.AlipayTradeQueryRequest;
 import com.alipay.api.request.AlipayTradeRefundRequest;
-import com.alipay.api.response.AlipayTradeAppPayResponse;
-import com.alipay.api.response.AlipayTradePayResponse;
 import com.alipay.api.response.AlipayTradeQueryResponse;
 import com.alipay.api.response.AlipayTradeRefundResponse;
-import com.github.wxpay.sdk.WXPay;
-import com.github.wxpay.sdk.WXPayUtil;
-import com.wechat.pay.java.service.payments.app.AppServiceExtension;
-import com.wechat.pay.java.service.payments.app.model.PrepayWithRequestPaymentResponse;
-import com.wechat.pay.java.service.payments.jsapi.JsapiService;
-import com.wechat.pay.java.service.payments.jsapi.model.Payer;
-import com.wechat.pay.java.service.payments.jsapi.model.PrepayRequest;
 import com.wechat.pay.java.service.refund.RefundService;
 import com.wechat.pay.java.service.refund.model.AmountReq;
 import com.wechat.pay.java.service.refund.model.CreateRequest;
@@ -31,21 +20,16 @@ import com.yiqi.common.config.WxMaProperties;
 import com.yiqi.common.config.WxPayConfigs;
 import com.yiqi.common.core.domain.AuthHolder;
 import com.yiqi.common.core.domain.R;
-import com.yiqi.common.utils.DateUtils;
 import com.yiqi.common.utils.EnumUtils;
 import com.yiqi.common.utils.OrderNoUtils;
 import com.yiqi.common.utils.StringUtils;
-import com.yiqi.common.utils.pay.WxPayV2Config;
 import com.yiqi.order.domain.OrderPayInfo;
+import com.yiqi.order.domain.OrderRefundInfo;
 import com.yiqi.order.domain.dto.*;
 import com.yiqi.order.domain.vo.weapp.AppPayRespVO;
 import com.yiqi.order.service.*;
 import com.yiqi.payment.AliPayService;
 import com.yiqi.payment.WechatPayService;
-import org.dom4j.Document;
-import org.dom4j.DocumentException;
-import org.dom4j.DocumentHelper;
-import org.dom4j.Element;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.springframework.beans.factory.annotation.Autowired;
@@ -53,14 +37,9 @@ import org.springframework.stereotype.Service;
 
 import java.math.BigDecimal;
 import java.math.RoundingMode;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
 import java.util.concurrent.ScheduledExecutorService;
 
 import org.springframework.transaction.annotation.Transactional;
-import org.springframework.web.context.request.RequestContextHolder;
-import org.springframework.web.context.request.ServletRequestAttributes;
 
 
 /**
@@ -89,6 +68,8 @@ public class PayServiceImpl implements IPayService {
     private WechatPayService wechatPayService;
     @Autowired
     private IOrderPayInfoService orderPayInfoService;
+    @Autowired
+    private IOrderRefundInfoService orderRefundInfoService;
 
     private static final Logger log = LoggerFactory.getLogger(PayServiceImpl.class);
 
@@ -96,12 +77,14 @@ public class PayServiceImpl implements IPayService {
     @Override
     @Transactional(rollbackFor = Exception.class)
     public R unifiePaySuccessNotify(String orderPayNo, String orderNo, String outTradeNo) {
+        OrderPayInfo orderPayInfo = orderPayInfoService.getOrderPayInfoByRequestNo(orderPayNo);
+        if (orderPayInfo == null) {
+            return R.fail("未查询到订单");
+        }
+        orderPayInfo.setPayStatus("1");
+        orderPayInfoService.updateById(orderPayInfo);
         String header = orderPayNo.substring(0, 2);
         if (StringUtils.isBlank(orderNo)) {
-            OrderPayInfo orderPayInfo = orderPayInfoService.getOrderPayInfoByPayOrderNo(orderPayNo);
-            if (orderPayInfo == null) {
-                return R.fail("未查询到订单");
-            }
             orderNo = orderPayInfo.getOrderNo();
         }
 
@@ -124,7 +107,14 @@ public class PayServiceImpl implements IPayService {
 
     @Override
     @Transactional(rollbackFor = Exception.class)
-    public R unifieRefundSuccessNotify(String refundNo, String orderNo, String outTradeNo) {
+    public R unifieRefundSuccessNotify(String requestNo, String orderNo, String outTradeNo) {
+        OrderRefundInfo orderRefundInfo = orderRefundInfoService.getOrderRefundInfoByRequestNo(requestNo);
+        if (orderRefundInfo == null) {
+            return R.fail("未查询到订单");
+        }
+        orderRefundInfo.setRefundStatus("1");
+        orderRefundInfoService.updateById(orderRefundInfo);
+        String refundNo = orderRefundInfo.getRefundOrderNo();
         String header = refundNo.substring(0, 2);
         switch (EnumUtils.getEnumByType(header, OrderNoHeaderType.class)) {
             case cloth_order_header: {
@@ -144,34 +134,10 @@ public class PayServiceImpl implements IPayService {
         return R.fail("订单类型不正确");
     }
 
-
-    @Override
-    public R alipayPayExpireOrCancelNotify(String orderNo) {
-        String header = orderNo.substring(0, 2);
-        switch (EnumUtils.getEnumByType(header, OrderNoHeaderType.class)) {
-            case cloth_order_header: {
-                break;
-            }
-            case goods_order_header: {
-                orderGoodsService.handlePayFailCancelOrder(orderNo);
-                break;
-            }
-            case recharge_order_header: {
-                orderRechargeService.handleCancelRecharge(orderNo);
-                break;
-            }
-            case activity_order_header: {
-                orderActivityService.handleCancelActivityOrder(orderNo);
-                break;
-            }
-        }
-        return R.fail("订单类型不正确");
-    }
-
     @Override
     public AppPayRespVO appPay(PayOrderAppDTO payOrderAppDTO) {
         OrderPayInfo orderPayInfo = orderPayInfoService.createOrderPayInfo(payOrderAppDTO.getOrderNo(), payOrderAppDTO.getPayAmount(), payOrderAppDTO.getPayType());
-        payOrderAppDTO.setOrderNo(orderPayInfo.getPayOrderNo());
+        payOrderAppDTO.setOrderNo(orderPayInfo.getRequestNo());
         switch (EnumUtils.getEnumByType(payOrderAppDTO.getPayType(), PayType.class)) {
             case WECHAT: {
                 if ("APP".equals(payOrderAppDTO.getPlatform())) {
@@ -216,15 +182,15 @@ public class PayServiceImpl implements IPayService {
         PayResponseDTO payResponseDTO = null;
         switch (EnumUtils.getEnumByType(orderPayInfo.getPayType(), PayType.class)) {
             case WECHAT: {
-                payResponseDTO = wechatPayService.orderPayQuery(orderPayInfo.getPayOrderNo());
+                payResponseDTO = wechatPayService.orderPayQuery(orderPayInfo.getRequestNo());
                 break;
             }
             case ALIPAY: {
-                payResponseDTO = aliPayService.orderPayQuery(orderPayInfo.getPayOrderNo());
+                payResponseDTO = aliPayService.orderPayQuery(orderPayInfo.getRequestNo());
                 break;
             }
             default:
-                payResponseDTO = PayResponseDTO.payWait(orderPayInfo.getPayOrderNo());
+                payResponseDTO = PayResponseDTO.payWait(orderPayInfo.getRequestNo());
         }
         return payResponseDTO;
     }
@@ -272,6 +238,8 @@ public class PayServiceImpl implements IPayService {
 
     @Override
     public RefundResponseDTO refundApply(PayRefundDTO payRefundDTO) {
+        OrderRefundInfo orderRefundInfo = orderRefundInfoService.createOrderRefundInfo(payRefundDTO);
+        payRefundDTO.setOutRequestNo(orderRefundInfo.getRequestNo());
         switch (EnumUtils.getEnumByType(payRefundDTO.getPayType(), PayType.class)) {
             case WECHAT: {
                 return wechatPayService.orderRefund(payRefundDTO);

+ 15 - 0
yiqi-core/src/main/java/com/yiqi/settlement/service/impl/SettlementStoreRateServiceImpl.java

@@ -1,9 +1,12 @@
 package com.yiqi.settlement.service.impl;
 
+import java.util.Date;
 import java.util.List;
 
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
 import com.yiqi.common.utils.DateUtils;
 import com.yiqi.common.utils.SecurityUtils;
+import com.yiqi.settlement.domain.SettlementFactoryRate;
 import com.yiqi.settlement.domain.SettlementStoreRate;
 import com.yiqi.settlement.domain.dto.SettlementStoreRateQueryDTO;
 import com.yiqi.settlement.domain.vo.SettlementStoreRateListVO;
@@ -29,4 +32,16 @@ public class SettlementStoreRateServiceImpl extends ServiceImpl<SettlementStoreR
         return voList;
     }
 
+    @Override
+    public SettlementStoreRate getByStoreId(Long storeId, Date date) {
+        QueryWrapper<SettlementStoreRate> queryWrapper = new QueryWrapper<>();
+        queryWrapper.lambda()
+                .eq(SettlementStoreRate::getStoreId, storeId)
+                .le(SettlementStoreRate::getStartDate, date)
+                .ge(SettlementStoreRate::getEndDate, date)
+                .last("ORDER BY id DESC LIMIT 1");
+        return baseMapper.selectOne(queryWrapper);
+    }
+
+
 }

+ 1 - 2
yiqi-core/src/main/resources/mapper/order/OrderPayInfoMapper.xml

@@ -17,8 +17,7 @@
     </resultMap>
 
     <sql id="selectOrderPayInfoVo">
-        select id, order_no, pay_order_no, pay_amount, pay_mno, pay_type, pay_status, msg, create_time
-        from order_pay_info
+        select * from order_pay_info
     </sql>
 
     <select id="selectOrderPayInfoList" parameterType="OrderPayInfo" resultMap="OrderPayInfoResult">

+ 175 - 0
yiqi-core/src/main/resources/mapper/order/OrderRefundInfoMapper.xml

@@ -0,0 +1,175 @@
+<?xml version="1.0" encoding="UTF-8" ?>
+<!DOCTYPE mapper
+        PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
+        "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
+<mapper namespace="com.yiqi.order.mapper.OrderRefundInfoMapper">
+
+    <resultMap type="OrderRefundInfo" id="OrderRefundInfoResult">
+        <result property="id" column="id"/>
+        <result property="storeId" column="store_id"/>
+        <result property="originOrderNo" column="origin_order_no"/>
+        <result property="refundOrderNo" column="refund_order_no"/>
+        <result property="requestNo" column="request_no"/>
+        <result property="payAmount" column="pay_amount"/>
+        <result property="refundAmount" column="refund_amount"/>
+        <result property="payMno" column="pay_mno"/>
+        <result property="payType" column="pay_type"/>
+        <result property="refundStatus" column="refund_status"/>
+        <result property="msg" column="msg"/>
+        <result property="createTime" column="create_time"/>
+    </resultMap>
+
+    <sql id="selectOrderRefundInfoVo">
+        select id, store_id, origin_order_no, refund_order_no, request_no, pay_amount, refund_amount, pay_mno, pay_type, refund_status, msg, create_time
+        from order_refund_info
+    </sql>
+
+    <select id="selectOrderRefundInfoList" parameterType="OrderRefundInfo" resultMap="OrderRefundInfoResult">
+        <include refid="selectOrderRefundInfoVo"/>
+        <where>
+            <if test="storeId != null ">
+                and store_id = #{storeId}
+            </if>
+            <if test="originOrderNo != null  and originOrderNo != ''">
+                and origin_order_no = #{originOrderNo}
+            </if>
+            <if test="refundOrderNo != null  and refundOrderNo != ''">
+                and refund_order_no = #{refundOrderNo}
+            </if>
+            <if test="requestNo != null  and requestNo != ''">
+                and request_no = #{requestNo}
+            </if>
+            <if test="payAmount != null ">
+                and pay_amount = #{payAmount}
+            </if>
+            <if test="refundAmount != null ">
+                and refund_amount = #{refundAmount}
+            </if>
+            <if test="payMno != null  and payMno != ''">
+                and pay_mno = #{payMno}
+            </if>
+            <if test="payType != null  and payType != ''">
+                and pay_type = #{payType}
+            </if>
+            <if test="refundStatus != null  and refundStatus != ''">
+                and refund_status = #{refundStatus}
+            </if>
+            <if test="msg != null  and msg != ''">
+                and msg = #{msg}
+            </if>
+        </where>
+    </select>
+
+    <select id="selectOrderRefundInfoById" parameterType="Long"
+            resultMap="OrderRefundInfoResult">
+        <include refid="selectOrderRefundInfoVo"/>
+        where id = #{id}
+    </select>
+
+    <insert id="insertOrderRefundInfo" parameterType="OrderRefundInfo" useGeneratedKeys="true"
+            keyProperty="id">
+        insert into order_refund_info
+        <trim prefix="(" suffix=")" suffixOverrides=",">
+            <if test="storeId != null">store_id,
+            </if>
+            <if test="originOrderNo != null">origin_order_no,
+            </if>
+            <if test="refundOrderNo != null">refund_order_no,
+            </if>
+            <if test="requestNo != null">request_no,
+            </if>
+            <if test="payAmount != null">pay_amount,
+            </if>
+            <if test="refundAmount != null">refund_amount,
+            </if>
+            <if test="payMno != null">pay_mno,
+            </if>
+            <if test="payType != null">pay_type,
+            </if>
+            <if test="refundStatus != null">refund_status,
+            </if>
+            <if test="msg != null">msg,
+            </if>
+            <if test="createTime != null">create_time,
+            </if>
+        </trim>
+        <trim prefix="values (" suffix=")" suffixOverrides=",">
+            <if test="storeId != null">#{storeId},
+            </if>
+            <if test="originOrderNo != null">#{originOrderNo},
+            </if>
+            <if test="refundOrderNo != null">#{refundOrderNo},
+            </if>
+            <if test="requestNo != null">#{requestNo},
+            </if>
+            <if test="payAmount != null">#{payAmount},
+            </if>
+            <if test="refundAmount != null">#{refundAmount},
+            </if>
+            <if test="payMno != null">#{payMno},
+            </if>
+            <if test="payType != null">#{payType},
+            </if>
+            <if test="refundStatus != null">#{refundStatus},
+            </if>
+            <if test="msg != null">#{msg},
+            </if>
+            <if test="createTime != null">#{createTime},
+            </if>
+        </trim>
+    </insert>
+
+    <update id="updateOrderRefundInfo" parameterType="OrderRefundInfo">
+        update order_refund_info
+        <trim prefix="SET" suffixOverrides=",">
+            <if test="storeId != null">store_id =
+                #{storeId},
+            </if>
+            <if test="originOrderNo != null">origin_order_no =
+                #{originOrderNo},
+            </if>
+            <if test="refundOrderNo != null">refund_order_no =
+                #{refundOrderNo},
+            </if>
+            <if test="requestNo != null">request_no =
+                #{requestNo},
+            </if>
+            <if test="payAmount != null">pay_amount =
+                #{payAmount},
+            </if>
+            <if test="refundAmount != null">refund_amount =
+                #{refundAmount},
+            </if>
+            <if test="payMno != null">pay_mno =
+                #{payMno},
+            </if>
+            <if test="payType != null">pay_type =
+                #{payType},
+            </if>
+            <if test="refundStatus != null">refund_status =
+                #{refundStatus},
+            </if>
+            <if test="msg != null">msg =
+                #{msg},
+            </if>
+            <if test="createTime != null">create_time =
+                #{createTime},
+            </if>
+        </trim>
+        where id = #{id}
+    </update>
+
+    <delete id="deleteOrderRefundInfoById" parameterType="Long">
+        delete from order_refund_info where id = #{id}
+    </delete>
+
+    <delete id="deleteOrderRefundInfoByIds" parameterType="String">
+        delete from order_refund_info where id in
+        <foreach item="id" collection="array" open="(" separator="," close=")">
+            #{id}
+        </foreach>
+    </delete>
+
+
+
+</mapper>