skyline 1 year ago
parent
commit
4ef7f87375
34 changed files with 362 additions and 272 deletions
  1. 6 4
      car-wash-entity/src/main/java/com/kym/entity/InvestorAccount.java
  2. 0 38
      car-wash-entity/src/main/java/com/kym/entity/MerchantStation.java
  3. 10 2
      car-wash-entity/src/main/java/com/kym/entity/SplitRecord.java
  4. 5 0
      car-wash-entity/src/main/java/com/kym/entity/WashOrder.java
  5. 4 2
      car-wash-entity/src/main/java/com/kym/entity/common/RedisKeys.java
  6. 2 1
      car-wash-entity/src/main/java/com/kym/entity/queryParams/WxLoginParams.java
  7. 5 0
      car-wash-entity/src/main/java/com/kym/entity/vo/WashOrderVo.java
  8. 2 2
      car-wash-mapper/src/main/java/com/kym/mapper/AdminUserMapper.java
  9. 2 2
      car-wash-mapper/src/main/java/com/kym/mapper/AdminUserRoleMapper.java
  10. 2 2
      car-wash-mapper/src/main/java/com/kym/mapper/AdminUserStationMapper.java
  11. 2 2
      car-wash-mapper/src/main/java/com/kym/mapper/InvestorAccountMapper.java
  12. 0 16
      car-wash-mapper/src/main/java/com/kym/mapper/MerchantStationMapper.java
  13. 0 16
      car-wash-mapper/src/main/resources/mappers/MerchantAccountMapper.xml
  14. 0 17
      car-wash-mapper/src/main/resources/mappers/MerchantStationMapper.xml
  15. 3 3
      car-wash-miniapp/src/main/java/com/kym/admin/controller/InvestorAccountController.java
  16. 0 18
      car-wash-miniapp/src/main/java/com/kym/admin/controller/MerchantStationController.java
  17. 2 3
      car-wash-service/src/main/java/com/kym/service/AdminUserRoleService.java
  18. 4 1
      car-wash-service/src/main/java/com/kym/service/AdminUserService.java
  19. 17 0
      car-wash-service/src/main/java/com/kym/service/InvestorAccountService.java
  20. 0 17
      car-wash-service/src/main/java/com/kym/service/MerchantAccountService.java
  21. 0 16
      car-wash-service/src/main/java/com/kym/service/MerchantStationService.java
  22. 120 8
      car-wash-service/src/main/java/com/kym/service/awoara/event/handle/OrderCloseEventHandler.java
  23. 9 6
      car-wash-service/src/main/java/com/kym/service/awoara/factory/AwoaraEventHandlerFactory.java
  24. 45 7
      car-wash-service/src/main/java/com/kym/service/cache/KymCache.java
  25. 2 1
      car-wash-service/src/main/java/com/kym/service/impl/AdminUserRoleServiceImpl.java
  26. 28 5
      car-wash-service/src/main/java/com/kym/service/impl/AdminUserServiceImpl.java
  27. 28 2
      car-wash-service/src/main/java/com/kym/service/impl/AdminUserStationServiceImpl.java
  28. 3 1
      car-wash-service/src/main/java/com/kym/service/impl/DeviceRelationServiceImpl.java
  29. 25 0
      car-wash-service/src/main/java/com/kym/service/impl/InvestorAccountServiceImpl.java
  30. 0 25
      car-wash-service/src/main/java/com/kym/service/impl/MerchantAccountServiceImpl.java
  31. 0 35
      car-wash-service/src/main/java/com/kym/service/impl/MerchantStationServiceImpl.java
  32. 25 12
      car-wash-service/src/main/java/com/kym/service/impl/UserServiceImpl.java
  33. 2 1
      car-wash-service/src/main/java/com/kym/service/impl/WashOrderServiceImpl.java
  34. 9 7
      car-wash-service/src/main/java/com/kym/service/wechat/impl/WxPayServiceImpl.java

+ 6 - 4
car-wash-entity/src/main/java/com/kym/entity/MerchantAccount.java → car-wash-entity/src/main/java/com/kym/entity/InvestorAccount.java

@@ -1,8 +1,6 @@
 package com.kym.entity;
 
 import com.baomidou.mybatisplus.annotation.TableName;
-import com.kym.entity.BaseEntity;
-import java.io.Serializable;
 import lombok.Getter;
 import lombok.Setter;
 
@@ -16,11 +14,15 @@ import lombok.Setter;
  */
 @Getter
 @Setter
-@TableName("t_merchant_account")
-public class MerchantAccount extends BaseEntity {
+@TableName("t_investor_account")
+public class InvestorAccount extends BaseEntity {
 
     private static final long serialVersionUID = 1L;
 
+    /**
+     * 商户用户id
+     */
+    private Long adminUserId;
     /**
      * 总余额(分)
      */

+ 0 - 38
car-wash-entity/src/main/java/com/kym/entity/MerchantStation.java

@@ -1,38 +0,0 @@
-package com.kym.entity;
-
-import com.baomidou.mybatisplus.annotation.TableName;
-import com.kym.entity.BaseEntity;
-import java.io.Serializable;
-import lombok.Getter;
-import lombok.Setter;
-
-/**
- * <p>
- * 商户站点表
- * </p>
- *
- * @author skyline
- * @since 2025-02-25
- */
-@Getter
-@Setter
-@TableName("t_merchant_station")
-public class MerchantStation extends BaseEntity {
-
-    private static final long serialVersionUID = 1L;
-
-    /**
-     * 商户id
-     */
-    private Long merchantId;
-
-    /**
-     * 站点id
-     */
-    private String stationId;
-
-    /**
-     * 状态:0无效,1有效
-     */
-    private Integer status;
-}

+ 10 - 2
car-wash-entity/src/main/java/com/kym/entity/SplitRecord.java

@@ -1,10 +1,9 @@
 package com.kym.entity;
 
 import com.baomidou.mybatisplus.annotation.TableName;
-import com.kym.entity.BaseEntity;
-import java.io.Serializable;
 import lombok.Getter;
 import lombok.Setter;
+import lombok.experimental.Accessors;
 
 /**
  * <p>
@@ -16,11 +15,20 @@ import lombok.Setter;
  */
 @Getter
 @Setter
+@Accessors(chain = true)
 @TableName("t_split_record")
 public class SplitRecord extends BaseEntity {
 
     private static final long serialVersionUID = 1L;
 
+    /**
+     * 交易类型(1-充值 2-消费 3-解冻 4-退款)
+     */
+    public static final Integer TYPE_CHARGE = 1;
+    public static final Integer TYPE_CONSUME = 2;
+    public static final Integer TYPE_UNFREEZE = 3;
+    public static final Integer TYPE_REFUND = 4;
+
     /**
      * 出账账户ID
      */

+ 5 - 0
car-wash-entity/src/main/java/com/kym/entity/WashOrder.java

@@ -189,4 +189,9 @@ public class WashOrder extends BaseEntity {
      */
     private Long invoiceId;
 
+    /**
+     * 是否跨店:0-否,1-是
+     */
+    private Boolean isCross;
+
 }

+ 4 - 2
car-wash-entity/src/main/java/com/kym/entity/common/RedisKeys.java

@@ -14,8 +14,10 @@ public interface RedisKeys {
 
     // =======================================洗车======================================
 
-    String WASH_SHORT_ID_TO_PRODUCT_KEY_AND_DEVICE_NAME = "WASH_SHORT_ID_TO_PRODUCT_KEY_AND_DEVICE_NAME:";
-    String STATION_ID_TO_MERCHANT_ID = "STATION_ID_TO_MERCHANT_ID:";
+    String SHORT_ID_TO_STATION_ID = "SHORT_ID_TO_STATION_ID:";
+    String SHORT_ID_TO_PRODUCT_KEY_AND_DEVICE_NAME = "SHORT_ID_TO_PRODUCT_KEY_AND_DEVICE_NAME:";
+    String STATION_ID_TO_INVESTOR_ADMIN_USER_ID = "STATION_ID_TO_INVESTOR_ADMIN_USER_ID:";
+    String USER_ID_TO_STATION_ID = "USER_ID_TO_STATION_ID:";
 
     // =======================================洗车======================================
 

+ 2 - 1
car-wash-entity/src/main/java/com/kym/entity/queryParams/WxLoginParams.java

@@ -16,5 +16,6 @@ public class WxLoginParams {
     private String phoneCode;
     private String avatar;
     private String nickname;
-    private String stationId;
+    private String shortId;
+//    private String stationId;
 }

+ 5 - 0
car-wash-entity/src/main/java/com/kym/entity/vo/WashOrderVo.java

@@ -134,4 +134,9 @@ public class WashOrderVo extends BaseEntity {
      * 发票id
      */
     private Long invoiceId;
+
+    /**
+     * 是否跨店:0-否,1-是
+     */
+    private Boolean isCross;
 }

+ 2 - 2
car-wash-mapper/src/main/java/com/kym/mapper/AdminUserMapper.java

@@ -1,9 +1,9 @@
 package com.kym.mapper;
 
-import com.github.yulichang.base.MPJBaseMapper;
 import com.kym.entity.AdminUser;
 import com.kym.entity.queryParams.CommonQueryParam;
 import com.kym.entity.vo.AdminUserVo;
+import com.kym.mapper.mybatisplus.MyBaseMapper;
 import org.apache.ibatis.annotations.Param;
 
 import java.util.List;
@@ -16,7 +16,7 @@ import java.util.List;
  * @author skyline
  * @since 2023-07-11
  */
-public interface AdminUserMapper extends MPJBaseMapper<AdminUser> {
+public interface AdminUserMapper extends MyBaseMapper<AdminUser> {
     List<AdminUserVo> listUserPermissions(@Param("userId") Long loginId);
 
     List<AdminUserVo> listAdminUser(@Param("params") CommonQueryParam params);

+ 2 - 2
car-wash-mapper/src/main/java/com/kym/mapper/AdminUserRoleMapper.java

@@ -1,7 +1,7 @@
 package com.kym.mapper;
 
-import com.github.yulichang.base.MPJBaseMapper;
 import com.kym.entity.AdminUserRole;
+import com.kym.mapper.mybatisplus.MyBaseMapper;
 
 /**
  * <p>
@@ -11,6 +11,6 @@ import com.kym.entity.AdminUserRole;
  * @author skyline
  * @since 2023-09-04
  */
-public interface AdminUserRoleMapper extends MPJBaseMapper<AdminUserRole> {
+public interface AdminUserRoleMapper extends MyBaseMapper<AdminUserRole> {
 
 }

+ 2 - 2
car-wash-mapper/src/main/java/com/kym/mapper/AdminUserStationMapper.java

@@ -1,7 +1,7 @@
 package com.kym.mapper;
 
-import com.github.yulichang.base.MPJBaseMapper;
 import com.kym.entity.AdminUserStation;
+import com.kym.mapper.mybatisplus.MyBaseMapper;
 
 /**
  * <p>
@@ -11,6 +11,6 @@ import com.kym.entity.AdminUserStation;
  * @author skyline
  * @since 2023-09-18
  */
-public interface AdminUserStationMapper extends MPJBaseMapper<AdminUserStation> {
+public interface AdminUserStationMapper extends MyBaseMapper<AdminUserStation> {
 
 }

+ 2 - 2
car-wash-mapper/src/main/java/com/kym/mapper/MerchantAccountMapper.java → car-wash-mapper/src/main/java/com/kym/mapper/InvestorAccountMapper.java

@@ -1,6 +1,6 @@
 package com.kym.mapper;
 
-import com.kym.entity.MerchantAccount;
+import com.kym.entity.InvestorAccount;
 import com.kym.mapper.mybatisplus.MyBaseMapper;
 
 /**
@@ -11,6 +11,6 @@ import com.kym.mapper.mybatisplus.MyBaseMapper;
  * @author skyline
  * @since 2025-02-24
  */
-public interface MerchantAccountMapper extends MyBaseMapper<MerchantAccount> {
+public interface InvestorAccountMapper extends MyBaseMapper<InvestorAccount> {
 
 }

+ 0 - 16
car-wash-mapper/src/main/java/com/kym/mapper/MerchantStationMapper.java

@@ -1,16 +0,0 @@
-package com.kym.mapper;
-
-import com.kym.entity.MerchantStation;
-import com.kym.mapper.mybatisplus.MyBaseMapper;
-
-/**
- * <p>
- * 商户站点表 Mapper 接口
- * </p>
- *
- * @author skyline
- * @since 2025-02-25
- */
-public interface MerchantStationMapper extends MyBaseMapper<MerchantStation> {
-
-}

+ 0 - 16
car-wash-mapper/src/main/resources/mappers/MerchantAccountMapper.xml

@@ -1,16 +0,0 @@
-<?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.kym.mapper.MerchantAccountMapper">
-
-    <!-- 通用查询映射结果 -->
-    <resultMap id="BaseResultMap" type="com.kym.entity.MerchantAccount">
-        <result column="balance" property="balance" />
-        <result column="frozen_amount" property="frozenAmount" />
-    </resultMap>
-
-    <!-- 通用查询结果列 -->
-    <sql id="Base_Column_List">
-        balance, frozen_amount
-    </sql>
-
-</mapper>

+ 0 - 17
car-wash-mapper/src/main/resources/mappers/MerchantStationMapper.xml

@@ -1,17 +0,0 @@
-<?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.kym.mapper.MerchantStationMapper">
-
-    <!-- 通用查询映射结果 -->
-    <resultMap id="BaseResultMap" type="com.kym.entity.MerchantStation">
-        <result column="merchant_id" property="merchantId" />
-        <result column="station_id" property="stationId" />
-        <result column="status" property="status" />
-    </resultMap>
-
-    <!-- 通用查询结果列 -->
-    <sql id="Base_Column_List">
-        merchant_id, station_id, status
-    </sql>
-
-</mapper>

+ 3 - 3
car-wash-miniapp/src/main/java/com/kym/admin/controller/MerchantAccountController.java → car-wash-miniapp/src/main/java/com/kym/admin/controller/InvestorAccountController.java

@@ -1,4 +1,4 @@
-package com.kym.controller;
+package com.kym.admin.controller;
 
 import org.springframework.web.bind.annotation.RequestMapping;
 import org.springframework.web.bind.annotation.RestController;
@@ -12,7 +12,7 @@ import org.springframework.web.bind.annotation.RestController;
  * @since 2025-02-24
  */
 @RestController
-@RequestMapping("/merchant-account")
-public class MerchantAccountController {
+@RequestMapping("/investor-account")
+public class InvestorAccountController {
 
 }

+ 0 - 18
car-wash-miniapp/src/main/java/com/kym/admin/controller/MerchantStationController.java

@@ -1,18 +0,0 @@
-package com.kym.controller;
-
-import org.springframework.web.bind.annotation.RequestMapping;
-import org.springframework.web.bind.annotation.RestController;
-
-/**
- * <p>
- * 商户站点表 前端控制器
- * </p>
- *
- * @author skyline
- * @since 2025-02-25
- */
-@RestController
-@RequestMapping("/merchant-station")
-public class MerchantStationController {
-
-}

+ 2 - 3
car-wash-service/src/main/java/com/kym/service/AdminUserRoleService.java

@@ -1,8 +1,7 @@
 package com.kym.service;
 
-import com.github.yulichang.base.MPJBaseService;
 import com.kym.entity.AdminUserRole;
-import com.baomidou.mybatisplus.extension.service.IService;
+import com.kym.service.mybatisplus.MyBaseService;
 
 /**
  * <p>
@@ -12,6 +11,6 @@ import com.baomidou.mybatisplus.extension.service.IService;
  * @author skyline
  * @since 2023-09-04
  */
-public interface AdminUserRoleService extends MPJBaseService<AdminUserRole> {
+public interface AdminUserRoleService extends MyBaseService<AdminUserRole> {
 
 }

+ 4 - 1
car-wash-service/src/main/java/com/kym/service/AdminUserService.java

@@ -6,6 +6,7 @@ import com.kym.entity.AdminUser;
 import com.kym.entity.queryParams.CommonQueryParam;
 import com.kym.entity.vo.AdminUserVo;
 import com.kym.entity.common.PageBean;
+import com.kym.service.mybatisplus.MyBaseService;
 
 import java.util.List;
 
@@ -17,7 +18,9 @@ import java.util.List;
  * @author skyline
  * @since 2023-07-11
  */
-public interface AdminUserService extends MPJBaseService<AdminUser> {
+public interface AdminUserService extends MyBaseService<AdminUser> {
+
+    List<AdminUser> getInvestorAdminUsers();
 
     R login(String mobilePhone, String password);
 

+ 17 - 0
car-wash-service/src/main/java/com/kym/service/InvestorAccountService.java

@@ -0,0 +1,17 @@
+package com.kym.service;
+
+import com.kym.entity.InvestorAccount;
+import com.kym.service.mybatisplus.MyBaseService;
+
+/**
+ * <p>
+ * 商户账户表 服务类
+ * </p>
+ *
+ * @author skyline
+ * @since 2025-02-24
+ */
+public interface InvestorAccountService extends MyBaseService<InvestorAccount> {
+
+    InvestorAccount getInvestorAccount(String stationId);
+}

+ 0 - 17
car-wash-service/src/main/java/com/kym/service/MerchantAccountService.java

@@ -1,17 +0,0 @@
-package com.kym.service;
-
-import com.kym.entity.MerchantAccount;
-import com.kym.service.mybatisplus.MyBaseService;
-
-/**
- * <p>
- * 商户账户表 服务类
- * </p>
- *
- * @author skyline
- * @since 2025-02-24
- */
-public interface MerchantAccountService extends MyBaseService<MerchantAccount> {
-
-    MerchantAccount getStationBasicAccount(String stationId);
-}

+ 0 - 16
car-wash-service/src/main/java/com/kym/service/MerchantStationService.java

@@ -1,16 +0,0 @@
-package com.kym.service;
-
-import com.kym.entity.MerchantStation;
-import com.kym.service.mybatisplus.MyBaseService;
-
-/**
- * <p>
- * 商户站点表 服务类
- * </p>
- *
- * @author skyline
- * @since 2025-02-25
- */
-public interface MerchantStationService extends MyBaseService<MerchantStation> {
-
-}

+ 120 - 8
car-wash-service/src/main/java/com/kym/service/awoara/event/handle/OrderCloseEventHandler.java

@@ -1,20 +1,17 @@
 package com.kym.service.awoara.event.handle;
 
+import com.kym.entity.*;
 import com.kym.entity.awoara.MessageBody;
 import com.kym.entity.awoara.OrderInfoObject;
-import com.kym.entity.Account;
-import com.kym.entity.WalletDetail;
-import com.kym.entity.WashOrder;
-import com.kym.service.AccountService;
-import com.kym.service.WalletDetailService;
-import com.kym.service.WashOrderService;
+import com.kym.service.*;
+import com.kym.service.cache.KymCache;
 import lombok.extern.slf4j.Slf4j;
 import org.springframework.stereotype.Component;
 import org.springframework.transaction.annotation.Transactional;
 
 import java.time.Duration;
 import java.time.LocalDateTime;
-import java.time.LocalTime;
+import java.util.List;
 
 /**
  * 关闭订单事件(订单结算)
@@ -27,11 +24,16 @@ public class OrderCloseEventHandler implements AwoaraEventHandler<OrderInfoObjec
     private final WashOrderService washOrderService;
     private final WalletDetailService walletDetailService;
     private final AccountService accountService;
+    private final InvestorAccountService investorAccountService;
+    private final SplitRecordService splitRecordService;
 
-    public OrderCloseEventHandler(WashOrderService washOrderService, WalletDetailService walletDetailService, AccountService accountService) {
+    public OrderCloseEventHandler(WashOrderService washOrderService, WalletDetailService walletDetailService,
+                                  AccountService accountService, InvestorAccountService investorAccountService, SplitRecordService splitRecordService) {
         this.washOrderService = washOrderService;
         this.walletDetailService = walletDetailService;
         this.accountService = accountService;
+        this.investorAccountService = investorAccountService;
+        this.splitRecordService = splitRecordService;
     }
 
 
@@ -66,6 +68,17 @@ public class OrderCloseEventHandler implements AwoaraEventHandler<OrderInfoObjec
                         .eq(Account::getUserId, washOrder.getUserId()).update();
             }
 
+
+            // todo t_account减(上面已完成),t_investor_account冻结户减,t_investor_account商户加,t_split_record记录
+            // todo 需要判断是否跨网点,分开处理;跨网点结算比例是消费站点分订单额的30%,充值站点分70%
+            if (washOrder.getIsCross()) {
+                // 跨网点订单结算比例是消费站点分订单额的30%,充值站点分70%
+                doCrossSplit(washOrder, KymCache.INSTANCE.getInvestorAdminUserIdByUserId(washOrder.getUserId()));
+            } else {
+                // 不跨网点订单结算比例是消费站点分订单额的100%,消费金额*商家消费分润比例30%-消费金额*平台分润10%=消费金额*(商家消费分润比例-平台分润)
+                doLocalSplit(washOrder);
+            }
+
             washOrder
                     .setCloseType(orderInfo.getClose_type())
                     .setAmount(orderInfo.getAmount())
@@ -91,9 +104,108 @@ public class OrderCloseEventHandler implements AwoaraEventHandler<OrderInfoObjec
             walletDetail.setTransactionTime(LocalDateTime.now());
             walletDetail.setStatus(WalletDetail.STATUS_已确认);
             walletDetailService.save(walletDetail);
+
+
         } else {
             log.error("订单不存在,订单号:{}", orderInfo.getOrder_id());
         }
 
     }
+
+    /**
+     * 执行(本店)分账操作
+     *
+     * @param washOrder
+     */
+    private void doLocalSplit(WashOrder washOrder) {
+        var investorAccount = investorAccountService.getInvestorAccount(washOrder.getStationId());
+        var amount = (int) (washOrder.getAmount() * (0.3 - 0.1));
+        investorAccountService.lambdaUpdate()
+                .setSql("frozen_amount = frozen_amount - {0}", amount)
+                .eq(InvestorAccount::getId, investorAccount.getId())
+                .update();
+        // 冻结户解冻
+        var splitRecord1 = new SplitRecord()
+                .setFromAccount(investorAccount.getAdminUserId())
+                .setToAccount(investorAccount.getAdminUserId())
+                .setTradeNo(washOrder.getOrderId())
+                .setAmount(amount)
+                .setType(SplitRecord.TYPE_UNFREEZE);
+
+        // 基本户入账
+        var splitRecord2 = new SplitRecord()
+                .setFromAccount(investorAccount.getAdminUserId())
+                .setToAccount(investorAccount.getAdminUserId())
+                .setTradeNo(washOrder.getOrderId())
+                .setAmount(amount)
+                .setType(SplitRecord.TYPE_CONSUME);
+
+        splitRecordService.saveBatch(List.of(splitRecord1, splitRecord2));
+
+
+    }
+
+    /**
+     * 执行跨店分账操作
+     *
+     * @param washOrder
+     * @param InvestorAdminUserId 用户归属的站点的商户投资者adminUserId
+     */
+    private void doCrossSplit(WashOrder washOrder, Long InvestorAdminUserId) {
+        var investorAccount = investorAccountService.getInvestorAccount(washOrder.getStationId());
+        var splitAmount = (int) (washOrder.getAmount() * (0.3 - 0.1));
+        var localAmount = (int) (splitAmount * 0.7);
+        var crossAmount = splitAmount - localAmount;
+
+        // 当前消费站点收入(跨店消费,原充值站点要分订单的70%)
+        investorAccountService.lambdaUpdate()
+                .setSql("balance = balance + {0}", crossAmount)
+                .eq(InvestorAccount::getId, investorAccount.getId())
+                .update();
+
+//        // 充值站点收入
+//        investorAccountService.lambdaUpdate()
+//                .setSql("balance = balance + {0}, frozen_amount = frozen_amount - {1}", localAmount, splitAmount)
+//                .eq(InvestorAccount::getId, investorAccount.getId())
+//                .update();
+//
+//        // 充值站点支出
+//        investorAccountService.lambdaUpdate()
+//                .setSql("balance = balance - {0}", crossAmount)
+//                .eq(InvestorAccount::getId, investorAccount.getId())
+//                .update();
+
+        // 以上充值站点的两次操作进行合并
+        // 充值站点收入
+        investorAccountService.lambdaUpdate()
+                .setSql("balance = balance + {0}, frozen_amount = frozen_amount - {1}", localAmount - crossAmount, splitAmount)
+                .eq(InvestorAccount::getId, investorAccount.getId())
+                .update();
+
+
+        // t_split_record 1.消费站点收入 2.归属站点收入 3.充值站点支出
+        var splitRecord1 = new SplitRecord()
+                .setFromAccount(InvestorAdminUserId)
+                .setToAccount(investorAccount.getAdminUserId())
+                .setTradeNo(washOrder.getOrderId())
+                .setAmount(crossAmount)
+                .setType(SplitRecord.TYPE_CONSUME);
+
+        var splitRecord2 = new SplitRecord()
+                .setFromAccount(InvestorAdminUserId)
+                .setToAccount(InvestorAdminUserId)
+                .setTradeNo(washOrder.getOrderId())
+                .setAmount(localAmount)
+                .setType(SplitRecord.TYPE_CONSUME);
+
+        var splitRecord3 = new SplitRecord()
+                .setFromAccount(investorAccount.getAdminUserId())
+                .setToAccount(investorAccount.getAdminUserId())
+                .setTradeNo(washOrder.getOrderId())
+                .setAmount(splitAmount)
+                .setType(SplitRecord.TYPE_UNFREEZE);
+
+        splitRecordService.saveBatch(List.of(splitRecord1, splitRecord2, splitRecord3));
+
+    }
 }

+ 9 - 6
car-wash-service/src/main/java/com/kym/service/awoara/factory/AwoaraEventHandlerFactory.java

@@ -2,11 +2,8 @@ package com.kym.service.awoara.factory;
 
 import com.kym.common.exception.BusinessException;
 import com.kym.entity.awoara.Event;
+import com.kym.service.*;
 import com.kym.service.awoara.event.handle.*;
-import com.kym.service.AccountService;
-import com.kym.service.WalletDetailService;
-import com.kym.service.WashDeviceService;
-import com.kym.service.WashOrderService;
 import org.springframework.stereotype.Component;
 
 /**
@@ -21,11 +18,16 @@ public class AwoaraEventHandlerFactory {
     private static WalletDetailService walletDetailService;
     private static AccountService accountService;
 
-    public AwoaraEventHandlerFactory(WashDeviceService washDeviceService,WashOrderService washOrderService, WalletDetailService walletDetailService, AccountService accountService) {
+    private static InvestorAccountService investorAccountService;
+    private static SplitRecordService splitRecordService;
+
+    public AwoaraEventHandlerFactory(WashDeviceService washDeviceService, WashOrderService washOrderService, WalletDetailService walletDetailService, AccountService accountService, InvestorAccountService investorAccountService, SplitRecordService splitRecordService) {
         AwoaraEventHandlerFactory.washDeviceService = washDeviceService;
         AwoaraEventHandlerFactory.washOrderService = washOrderService;
         AwoaraEventHandlerFactory.walletDetailService = walletDetailService;
         AwoaraEventHandlerFactory.accountService = accountService;
+        AwoaraEventHandlerFactory.investorAccountService = investorAccountService;
+        AwoaraEventHandlerFactory.splitRecordService = splitRecordService;
     }
 
     public static AwoaraEventHandler getEventHandler(String eventName) {
@@ -36,7 +38,8 @@ public class AwoaraEventHandlerFactory {
                 case device_state -> new DeviceStateEventHandler(washDeviceService);
                 case order_create -> new OrderCreateEventHandler(washOrderService);
                 case order_update -> new OrderUpdateEventHandler(washOrderService);
-                case order_close -> new OrderCloseEventHandler(washOrderService, walletDetailService, accountService);
+                case order_close ->
+                        new OrderCloseEventHandler(washOrderService, walletDetailService, accountService, investorAccountService, splitRecordService);
                 case user_login -> new UserLoginEventHandler();
                 case card_event -> new CardEventHandler();
             };

+ 45 - 7
car-wash-service/src/main/java/com/kym/service/cache/KymCache.java

@@ -25,13 +25,31 @@ public enum KymCache {
     private static ConcurrentHashMap<String, String> SHORT_ID_TO_PRODUCT_KEY_AND_DEVICE_NAME_MAPPING = new ConcurrentHashMap<>();
 
 
+    /**
+     * 用户id与归属站点id映射
+     *
+     * @param map
+     */
+    public void putUserId2StationId(Map<Long, String> map) {
+        map.forEach((k, v) -> KymCacheInjector.redisTemplate.opsForValue().set(RedisKeys.USER_ID_TO_STATION_ID + k, v));
+    }
+
+    /**
+     * 通过消费用户id获取站点商户投资者adminUserId
+     *
+     * @param userId
+     */
+    public Long getInvestorAdminUserIdByUserId(Long userId) {
+        return  getInvestorAdminUserIdByStationId(Objects.requireNonNull(KymCacheInjector.redisTemplate.opsForValue().get(RedisKeys.USER_ID_TO_STATION_ID + userId)));
+    }
+
     /**
      * 站点id与商户id映射
      *
      * @param map
      */
-    public void putStationId2MerchantId(Map<String, String> map) {
-        map.forEach((k, v) -> KymCacheInjector.redisTemplate.opsForValue().set(RedisKeys.STATION_ID_TO_MERCHANT_ID + k, v));
+    public void putStationId2InvestorAdminUserId(Map<String, String> map) {
+        map.forEach((k, v) -> KymCacheInjector.redisTemplate.opsForValue().set(RedisKeys.STATION_ID_TO_INVESTOR_ADMIN_USER_ID + k, v));
     }
 
     /**
@@ -49,8 +67,8 @@ public enum KymCache {
      * @param stationId
      * @return
      */
-    public String getMerchantIdByStationId(String stationId) {
-        return KymCacheInjector.redisTemplate.opsForValue().get(RedisKeys.STATION_ID_TO_MERCHANT_ID + stationId);
+    public Long getInvestorAdminUserIdByStationId(String stationId) {
+        return Long.valueOf(Objects.requireNonNull(KymCacheInjector.redisTemplate.opsForValue().get(RedisKeys.STATION_ID_TO_INVESTOR_ADMIN_USER_ID + stationId)));
     }
 
     /**
@@ -65,7 +83,7 @@ public enum KymCache {
 
 
     /**
-     * 操作员对应有权限的站点
+     * 运营平台账号(包含运营,投资者,物业等)对应有权限的站点
      *
      * @param map
      */
@@ -84,10 +102,30 @@ public enum KymCache {
      * @param map
      */
     public void putWashShortId2ProductKeyAndDeviceName(Map<String, String> map) {
-        map.forEach((k, v) -> KymCacheInjector.redisTemplate.opsForValue().set(RedisKeys.WASH_SHORT_ID_TO_PRODUCT_KEY_AND_DEVICE_NAME + k, v));
+        map.forEach((k, v) -> KymCacheInjector.redisTemplate.opsForValue().set(RedisKeys.SHORT_ID_TO_PRODUCT_KEY_AND_DEVICE_NAME + k, v));
         SHORT_ID_TO_PRODUCT_KEY_AND_DEVICE_NAME_MAPPING.putAll(map);
     }
 
+
+    /**
+     * 缓存短编号与站点id映射
+     *
+     * @param map
+     */
+    public void putShortId2StationId(Map<String, String> map) {
+        map.forEach((k, v) -> KymCacheInjector.redisTemplate.opsForValue().set(RedisKeys.SHORT_ID_TO_STATION_ID + k, v));
+    }
+
+    /**
+     * 通过短编号获取站点id
+     *
+     * @param shortId
+     * @return
+     */
+    public String gesStationIdByShortId(String shortId) {
+        return KymCacheInjector.redisTemplate.opsForValue().get(RedisKeys.SHORT_ID_TO_STATION_ID + shortId);
+    }
+
     /**
      * 通过短编号获取productKey和deviceName
      *
@@ -96,7 +134,7 @@ public enum KymCache {
      */
     public String[] getProductKeyAndDeviceNameByWashShortId(String shortId) {
         var res = new String[]{};
-        var s = Objects.requireNonNull(KymCacheInjector.redisTemplate.opsForValue().get(RedisKeys.WASH_SHORT_ID_TO_PRODUCT_KEY_AND_DEVICE_NAME + shortId));
+        var s = Objects.requireNonNull(KymCacheInjector.redisTemplate.opsForValue().get(RedisKeys.SHORT_ID_TO_PRODUCT_KEY_AND_DEVICE_NAME + shortId));
         if (CommUtil.isNotEmptyAndNull(s)) {
             res = s.split(",");
         }

+ 2 - 1
car-wash-service/src/main/java/com/kym/service/impl/AdminUserRoleServiceImpl.java

@@ -5,6 +5,7 @@ import com.github.yulichang.base.MPJBaseServiceImpl;
 import com.kym.entity.AdminUserRole;
 import com.kym.mapper.AdminUserRoleMapper;
 import com.kym.service.AdminUserRoleService;
+import com.kym.service.mybatisplus.MyBaseServiceImpl;
 import org.springframework.stereotype.Service;
 
 /**
@@ -16,6 +17,6 @@ import org.springframework.stereotype.Service;
  * @since 2023-09-04
  */
 @Service
-public class AdminUserRoleServiceImpl extends MPJBaseServiceImpl<AdminUserRoleMapper, AdminUserRole> implements AdminUserRoleService {
+public class AdminUserRoleServiceImpl extends MyBaseServiceImpl<AdminUserRoleMapper, AdminUserRole> implements AdminUserRoleService {
 
 }

+ 28 - 5
car-wash-service/src/main/java/com/kym/service/impl/AdminUserServiceImpl.java

@@ -6,10 +6,10 @@ import cn.hutool.crypto.asymmetric.KeyType;
 import cn.hutool.crypto.asymmetric.RSA;
 import cn.hutool.crypto.digest.DigestAlgorithm;
 import cn.hutool.crypto.digest.Digester;
-
 import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
 import com.github.pagehelper.PageHelper;
-import com.github.yulichang.base.MPJBaseServiceImpl;
+import com.github.yulichang.toolkit.JoinWrappers;
+import com.github.yulichang.wrapper.MPJLambdaWrapper;
 import com.kym.common.R;
 import com.kym.common.constant.ResponseEnum;
 import com.kym.common.exception.BusinessException;
@@ -18,13 +18,16 @@ import com.kym.common.utils.IDGenerator;
 import com.kym.entity.AdminUser;
 import com.kym.entity.AdminUserRole;
 import com.kym.entity.InvestorInfo;
+import com.kym.entity.Role;
+import com.kym.entity.common.PageBean;
 import com.kym.entity.queryParams.CommonQueryParam;
 import com.kym.entity.vo.AdminUserVo;
-import com.kym.entity.common.PageBean;
 import com.kym.mapper.AdminUserMapper;
 import com.kym.service.AdminUserRoleService;
 import com.kym.service.AdminUserService;
 import com.kym.service.InvestorInfoService;
+import com.kym.service.RoleService;
+import com.kym.service.mybatisplus.MyBaseServiceImpl;
 import jakarta.annotation.Resource;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -49,10 +52,11 @@ import java.util.Map;
  * @since 2023-07-11
  */
 @Service
-public class AdminUserServiceImpl extends MPJBaseServiceImpl<AdminUserMapper, AdminUser> implements AdminUserService {
+public class AdminUserServiceImpl extends MyBaseServiceImpl<AdminUserMapper, AdminUser> implements AdminUserService {
     final static Digester MD5 = new Digester(DigestAlgorithm.MD5);
     private static final Logger LOGGER = LoggerFactory.getLogger(AdminUserServiceImpl.class);
     private final InvestorInfoService investorInfoService;
+    private final RoleService roleService;
     @Value("${password.privateKey}")
     private String privateKey;
     @Value("${password.publicKey}")
@@ -60,8 +64,27 @@ public class AdminUserServiceImpl extends MPJBaseServiceImpl<AdminUserMapper, Ad
     @Resource
     private AdminUserRoleService adminUserRoleService;
 
-    public AdminUserServiceImpl(InvestorInfoService investorInfoService) {
+    public AdminUserServiceImpl(InvestorInfoService investorInfoService, RoleService roleService) {
         this.investorInfoService = investorInfoService;
+        this.roleService = roleService;
+    }
+
+    /**
+     * 获取投资者角色对应的adminUser用户
+     */
+    @Override
+    public List<AdminUser> getInvestorAdminUsers() {
+        // 投资者角色ID
+        var investorRole = roleService.lambdaQuery()
+                .eq(Role::getRoleName, "投资者")
+                .eq(Role::getRoleDesc, "investor").one();
+        // 查找所有角色为investor的adminUser用户
+        MPJLambdaWrapper<AdminUser> wrapper = JoinWrappers.lambda(AdminUser.class)
+                .selectAll(AdminUser.class)
+                .leftJoin(AdminUserRole.class, AdminUserRole::getAdminUserId, AdminUser::getId)
+                .eq(AdminUserRole::getRoleId, investorRole.getId());
+        return this.selectJoinList(AdminUser.class, wrapper);
+
     }
 
     @Override

+ 28 - 2
car-wash-service/src/main/java/com/kym/service/impl/AdminUserStationServiceImpl.java

@@ -1,15 +1,19 @@
 package com.kym.service.impl;
 
-import com.github.yulichang.base.MPJBaseServiceImpl;
+import com.kym.common.utils.CommUtil;
+import com.kym.entity.AdminUser;
 import com.kym.entity.AdminUserStation;
 import com.kym.mapper.AdminUserStationMapper;
+import com.kym.service.AdminUserService;
 import com.kym.service.AdminUserStationService;
 import com.kym.service.cache.KymCache;
+import com.kym.service.mybatisplus.MyBaseServiceImpl;
 import jakarta.annotation.PostConstruct;
 import org.springframework.stereotype.Service;
 
 import java.util.ArrayList;
 import java.util.List;
+import java.util.Map;
 import java.util.stream.Collectors;
 
 /**
@@ -21,7 +25,13 @@ import java.util.stream.Collectors;
  * @since 2023-09-18
  */
 @Service
-public class AdminUserStationServiceImpl extends MPJBaseServiceImpl<AdminUserStationMapper, AdminUserStation> implements AdminUserStationService {
+public class AdminUserStationServiceImpl extends MyBaseServiceImpl<AdminUserStationMapper, AdminUserStation> implements AdminUserStationService {
+
+    private final AdminUserService adminUserService;
+
+    public AdminUserStationServiceImpl(AdminUserService adminUserService) {
+        this.adminUserService = adminUserService;
+    }
 
     @PostConstruct
     private void init() {
@@ -38,5 +48,21 @@ public class AdminUserStationServiceImpl extends MPJBaseServiceImpl<AdminUserSta
         ));
 
         KymCache.INSTANCE.putAdminUser2Stations(adminUser2Stations);
+
+        // 筛选出角色为投资者的用户,缓存站点-投资者对应关系
+        var investorAdminUserIds = adminUserService.getInvestorAdminUsers().stream().map(AdminUser::getId).toList();
+
+        var investorAdminUser2Stations = adminUser2Stations.entrySet().stream()
+                .filter(entry -> investorAdminUserIds.contains(entry.getKey()))
+                .collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue));
+
+        investorAdminUser2Stations.forEach((adminUserId, stationIds) -> {
+            if (CommUtil.isNotEmptyAndNull(stationIds) && stationIds.size() == 1) {
+                KymCache.INSTANCE.putStationId2InvestorAdminUserId(Map.of(stationIds.get(0), String.valueOf(adminUserId)));
+            }
+        });
+
     }
+
+
 }

+ 3 - 1
car-wash-service/src/main/java/com/kym/service/impl/DeviceRelationServiceImpl.java

@@ -2,8 +2,8 @@ package com.kym.service.impl;
 
 import com.kym.entity.DeviceRelation;
 import com.kym.mapper.DeviceRelationMapper;
-import com.kym.service.cache.KymCache;
 import com.kym.service.DeviceRelationService;
+import com.kym.service.cache.KymCache;
 import com.kym.service.mybatisplus.MyBaseServiceImpl;
 import jakarta.annotation.PostConstruct;
 import org.springframework.stereotype.Service;
@@ -26,6 +26,8 @@ public class DeviceRelationServiceImpl extends MyBaseServiceImpl<DeviceRelationM
         list().forEach(item -> {
             // 初始化短编号和设备信息的关联
             KymCache.INSTANCE.putWashShortId2ProductKeyAndDeviceName(Map.of(item.getShortId(), item.getProductKey() + "," + item.getDeviceName()));
+            // shortId和stationId的对应关系
+            KymCache.INSTANCE.putShortId2StationId(Map.of(item.getShortId(), item.getStationId()));
         });
     }
 

+ 25 - 0
car-wash-service/src/main/java/com/kym/service/impl/InvestorAccountServiceImpl.java

@@ -0,0 +1,25 @@
+package com.kym.service.impl;
+
+import com.kym.entity.InvestorAccount;
+import com.kym.mapper.InvestorAccountMapper;
+import com.kym.service.InvestorAccountService;
+import com.kym.service.cache.KymCache;
+import com.kym.service.mybatisplus.MyBaseServiceImpl;
+import org.springframework.stereotype.Service;
+
+/**
+ * <p>
+ * 商户账户表 服务实现类
+ * </p>
+ *
+ * @author skyline
+ * @since 2025-02-24
+ */
+@Service
+public class InvestorAccountServiceImpl extends MyBaseServiceImpl<InvestorAccountMapper, InvestorAccount> implements InvestorAccountService {
+
+    @Override
+    public InvestorAccount getInvestorAccount(String stationId) {
+        return getById(KymCache.INSTANCE.getInvestorAdminUserIdByStationId(stationId));
+    }
+}

+ 0 - 25
car-wash-service/src/main/java/com/kym/service/impl/MerchantAccountServiceImpl.java

@@ -1,25 +0,0 @@
-package com.kym.service.impl;
-
-import com.kym.entity.MerchantAccount;
-import com.kym.mapper.MerchantAccountMapper;
-import com.kym.service.MerchantAccountService;
-import com.kym.service.cache.KymCache;
-import com.kym.service.mybatisplus.MyBaseServiceImpl;
-import org.springframework.stereotype.Service;
-
-/**
- * <p>
- * 商户账户表 服务实现类
- * </p>
- *
- * @author skyline
- * @since 2025-02-24
- */
-@Service
-public class MerchantAccountServiceImpl extends MyBaseServiceImpl<MerchantAccountMapper, MerchantAccount> implements MerchantAccountService {
-
-    @Override
-    public MerchantAccount getStationBasicAccount(String stationId) {
-        return getById(KymCache.INSTANCE.getMerchantIdByStationId(stationId));
-    }
-}

+ 0 - 35
car-wash-service/src/main/java/com/kym/service/impl/MerchantStationServiceImpl.java

@@ -1,35 +0,0 @@
-package com.kym.service.impl;
-
-import com.kym.entity.MerchantStation;
-import com.kym.mapper.MerchantStationMapper;
-import com.kym.service.MerchantStationService;
-import com.kym.service.cache.KymCache;
-import com.kym.service.mybatisplus.MyBaseServiceImpl;
-import jakarta.annotation.PostConstruct;
-import org.springframework.stereotype.Service;
-
-import java.util.Map;
-
-/**
- * <p>
- * 商户站点表 服务实现类
- * </p>
- *
- * @author skyline
- * @since 2025-02-25
- */
-@Service
-public class MerchantStationServiceImpl extends MyBaseServiceImpl<MerchantStationMapper, MerchantStation> implements MerchantStationService {
-
-    /**
-     * 初始化缓存站点-商户对应关系
-     */
-    @PostConstruct
-    private void init() {
-        var merchantStationList = list();
-        for (MerchantStation ms : merchantStationList) {
-            KymCache.INSTANCE.putStationId2MerchantId(Map.of(ms.getStationId(), String.valueOf(ms.getId())));
-        }
-    }
-
-}

+ 25 - 12
car-wash-service/src/main/java/com/kym/service/impl/UserServiceImpl.java

@@ -22,7 +22,12 @@ import com.kym.entity.vo.UserVo;
 import com.kym.entity.wechat.WxPhoneNum;
 import com.kym.mapper.MpRelationMapper;
 import com.kym.mapper.UserMapper;
-import com.kym.service.*;
+import com.kym.service.AccountService;
+import com.kym.service.CarsService;
+import com.kym.service.RefundLogService;
+import com.kym.service.UserService;
+import com.kym.service.cache.KymCache;
+import jakarta.annotation.PostConstruct;
 import lombok.SneakyThrows;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -57,26 +62,27 @@ public class UserServiceImpl extends MPJBaseServiceImpl<UserMapper, User> implem
     private final AccountService accountService;
     private final RefundLogService refundLogService;
     private final CarsService carsService;
-    private final RechargeRightsService rechargeRightsService;
-    private final ActivityService activityService;
-    private final BannerService bannerService;
-
     private final MpRelationMapper mpRelationMapper;
 
 
     public UserServiceImpl(WxConfig wxConfig, @Lazy AccountService accountService, RefundLogService refundLogService,
-                           CarsService carsService, RechargeRightsService rechargeRightsService, @Lazy ActivityService activityService,
-                           BannerService bannerService, MpRelationMapper mpRelationMapper) {
+                           CarsService carsService, MpRelationMapper mpRelationMapper) {
         this.wxConfig = wxConfig;
         this.accountService = accountService;
         this.refundLogService = refundLogService;
         this.carsService = carsService;
-        this.rechargeRightsService = rechargeRightsService;
-        this.activityService = activityService;
-        this.bannerService = bannerService;
         this.mpRelationMapper = mpRelationMapper;
     }
 
+    @PostConstruct
+    private void init() {
+        // 初始化缓存
+        QueryWrapper<User> wrapper = new QueryWrapper<User>().select("id", "station_id");
+        List<User> users = baseMapper.selectList(wrapper);
+        var map = users.stream().collect(Collectors.toMap(User::getId, User::getStationId));
+        KymCache.INSTANCE.putUserId2StationId(map);
+    }
+
 
     @Transactional(rollbackFor = Exception.class)
     @SneakyThrows
@@ -121,8 +127,14 @@ public class UserServiceImpl extends MPJBaseServiceImpl<UserMapper, User> implem
                 newUser.setUsername(mobilePhone);
                 newUser.setAvatar(params.getAvatar());
                 newUser.setNickname(params.getNickname());
-                // 用户归属站点 todo 如何在用户注册时
-                newUser.setStationId(params.getStationId());
+                // 用户归属站点
+                if (CommUtil.isNotEmptyAndNull(params.getShortId())) {
+                    newUser.setStationId(KymCache.INSTANCE.gesStationIdByShortId(params.getShortId()));
+                } else {
+                    // todo 用户归属 扫设备二维码以外注册的用户,统一归属平台自己的商户,初始化系统时创建对应的商户
+                    newUser.setStationId("000");
+                }
+                KymCache.INSTANCE.putUserId2StationId(Map.of(newUser.getId(), newUser.getStationId()));
                 baseMapper.insert(newUser);
                 // 创建用户账户
                 var account = new Account();
@@ -171,6 +183,7 @@ public class UserServiceImpl extends MPJBaseServiceImpl<UserMapper, User> implem
         StpUtil.getSession().set("userId", user.getId());
         StpUtil.getSession().set("username", user.getUsername());
         StpUtil.getSession().set("mobilePhone", user.getMobilePhone());
+        StpUtil.getSession().set("stationId", user.getStationId());
         user.setLastLoginTime(LocalDateTime.now());
         updateById(user);
         LOGGER.info("用户:{}/{}登录成功,tokenName:{},tokenValue:{}", user.getMobilePhone(), user.getId(), StpUtil.getTokenName(), StpUtil.getTokenValue());

+ 2 - 1
car-wash-service/src/main/java/com/kym/service/impl/WashOrderServiceImpl.java

@@ -99,7 +99,8 @@ public class WashOrderServiceImpl extends MyBaseServiceImpl<WashOrderMapper, Was
                 .setPrepayMoney(account.getBalance() - 50)
                 .setStartTime(LocalDateTime.now())
                 .setOrderStatus(WashOrder.ORDER_STATUS_开机)
-                .setPayStatus(WashOrder.PAY_STATUS_未支付);
+                .setPayStatus(WashOrder.PAY_STATUS_未支付)
+                .setIsCross(StpUtil.getSession().getString("stationId").equals(params.getStationId()));
         save(washOrder);
         return orderId;
     }

+ 9 - 7
car-wash-service/src/main/java/com/kym/service/wechat/impl/WxPayServiceImpl.java

@@ -88,7 +88,7 @@ public class WxPayServiceImpl implements WxPayService {
     private final UserRechargeRightsService userRechargeRightsService;
 
     private final RechargeConfigService rechargeConfigService;
-    private final MerchantAccountService merchantAccountService;
+    private final InvestorAccountService investorAccountService;
 
 
     /**
@@ -101,7 +101,7 @@ public class WxPayServiceImpl implements WxPayService {
                             PayLogService payLogService, AccountService accountService,
                             RefundLogService refundLogService,
                             ActivityService activityService, UserRechargeRightsService userRechargeRightsService,
-                            RechargeConfigService rechargeConfigService, MerchantAccountService merchantAccountService) {
+                            RechargeConfigService rechargeConfigService, InvestorAccountService investorAccountService) {
         this.conf = conf;
         this.walletDetailService = walletDetailService;
         this.payLogService = payLogService;
@@ -110,7 +110,7 @@ public class WxPayServiceImpl implements WxPayService {
         this.activityService = activityService;
         this.userRechargeRightsService = userRechargeRightsService;
         this.rechargeConfigService = rechargeConfigService;
-        this.merchantAccountService = merchantAccountService;
+        this.investorAccountService = investorAccountService;
     }
 
     /**
@@ -279,7 +279,7 @@ public class WxPayServiceImpl implements WxPayService {
     }
 
     /**
-     * 微信支付结果通知
+     * 微信支付结果通知(充值完成)
      *
      * @param request
      * @return
@@ -342,11 +342,13 @@ public class WxPayServiceImpl implements WxPayService {
 
                 // 用户(此时要知道用户归属的站点)充值的资金先进到洗车站商户账户的基本户和冻结户,然后在消费时再将冻结户金额进行分润
                 var stationId = transaction.getAttach();
-                // 70%进入站点商户基本户,30%进入站点商户冻结户
+                // 70%进入站点商户基本户,30%进入站点商户冻结户 todo 后面将比例进行配置化(需要考虑历史数据处理)
                 var stationBasicAmount = (int) (totalAmount * 0.7);
                 var stationFreezeAmount = totalAmount - stationBasicAmount;
-                merchantAccountService.lambdaUpdate().setSql("balance = (balance + %d), frozen_amount = (frozen_amount + %d)".formatted(stationBasicAmount, stationFreezeAmount))
-                        .eq(MerchantAccount::getId, KymCache.INSTANCE.getMerchantIdByStationId(stationId)).update();
+                investorAccountService.lambdaUpdate()
+                        .setSql("balance = (balance + %d), frozen_amount = (frozen_amount + %d)".formatted(stationBasicAmount, stationFreezeAmount))
+                        .eq(InvestorAccount::getId, KymCache.INSTANCE.getInvestorAdminUserIdByStationId(stationId))
+                        .update();
 
                 LOGGER.info("微信支付回调{}:业务处理结束", notifyRes[2]);
                 return ResponseEntity.status(HttpStatus.OK).build();