Prechádzať zdrojové kódy

分账调试:充值

skyline 1 rok pred
rodič
commit
cb9623dbce

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


+ 1 - 1
car-wash-miniapp/src/main/java/com/kym/admin/controller/SplitRecordController.java → car-wash-admin/src/main/java/com/kym/admin/controller/SplitRecordController.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;

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

@@ -24,7 +24,7 @@ public class SplitRecord extends BaseEntity {
     /**
      * 交易类型(1-充值 2-消费 3-解冻 4-退款)
      */
-    public static final Integer TYPE_CHARGE = 1;
+    public static final Integer TYPE_RECHARGE = 1;
     public static final Integer TYPE_CONSUME = 2;
     public static final Integer TYPE_UNFREEZE = 3;
     public static final Integer TYPE_REFUND = 4;

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

@@ -153,7 +153,7 @@ public class OrderCloseEventHandler implements AwoaraEventHandler<OrderInfoObjec
      * @param stationId 用户归属的站点Id
      */
     private void doCrossSplit(WashOrder washOrder, String stationId) {
-        var investorAccount = stationAccountService.getStationAccount(washOrder.getStationId());
+        var stationAccount = stationAccountService.getStationAccount(washOrder.getStationId());
         var splitAmount = (int) (washOrder.getAmount() * (0.3 - 0.1));
         var localAmount = (int) (splitAmount * 0.7);
         var crossAmount = splitAmount - localAmount;
@@ -161,33 +161,33 @@ public class OrderCloseEventHandler implements AwoaraEventHandler<OrderInfoObjec
         // 当前消费站点收入(跨店消费,原充值站点要分订单的70%)
         stationAccountService.lambdaUpdate()
                 .setSql("balance = balance + {0}", crossAmount)
-                .eq(StationAccount::getId, investorAccount.getId())
+                .eq(StationAccount::getId, stationAccount.getId())
                 .update();
 
 //        // 充值站点收入
 //        stationAccountService.lambdaUpdate()
 //                .setSql("balance = balance + {0}, frozen_amount = frozen_amount - {1}", localAmount, splitAmount)
-//                .eq(InvestorAccount::getId, investorAccount.getId())
+//                .eq(InvestorAccount::getId, stationAccount.getId())
 //                .update();
 //
 //        // 充值站点支出
 //        stationAccountService.lambdaUpdate()
 //                .setSql("balance = balance - {0}", crossAmount)
-//                .eq(InvestorAccount::getId, investorAccount.getId())
+//                .eq(InvestorAccount::getId, stationAccount.getId())
 //                .update();
 
         // 以上充值站点的两次操作进行合并
         // 充值站点收入
         stationAccountService.lambdaUpdate()
                 .setSql("balance = balance + {0}, frozen_amount = frozen_amount - {1}", localAmount - crossAmount, splitAmount)
-                .eq(StationAccount::getId, investorAccount.getId())
+                .eq(StationAccount::getId, stationAccount.getId())
                 .update();
 
 
         // t_split_record 1.消费站点收入 2.归属站点收入 3.充值站点支出
         var splitRecord1 = new SplitRecord()
                 .setFromStationId(stationId)
-                .setToStationId(investorAccount.getStationId())
+                .setToStationId(stationAccount.getStationId())
                 .setTradeNo(washOrder.getOrderId())
                 .setAmount(crossAmount)
                 .setType(SplitRecord.TYPE_CONSUME);
@@ -200,8 +200,8 @@ public class OrderCloseEventHandler implements AwoaraEventHandler<OrderInfoObjec
                 .setType(SplitRecord.TYPE_CONSUME);
 
         var splitRecord3 = new SplitRecord()
-                .setFromStationId(investorAccount.getStationId())
-                .setToStationId(investorAccount.getStationId())
+                .setFromStationId(stationAccount.getStationId())
+                .setToStationId(stationAccount.getStationId())
                 .setTradeNo(washOrder.getOrderId())
                 .setAmount(splitAmount)
                 .setType(SplitRecord.TYPE_UNFREEZE);

+ 13 - 3
car-wash-service/src/main/java/com/kym/service/wechat/impl/WxPayServiceImpl.java

@@ -16,7 +16,6 @@ import com.kym.common.utils.OrderUtils;
 import com.kym.entity.Account;
 import com.kym.entity.*;
 import com.kym.service.*;
-import com.kym.service.cache.KymCache;
 import com.kym.service.wechat.WxPayService;
 import com.wechat.pay.java.core.Config;
 import com.wechat.pay.java.core.RSAAutoCertificateConfig;
@@ -89,6 +88,7 @@ public class WxPayServiceImpl implements WxPayService {
 
     private final RechargeConfigService rechargeConfigService;
     private final StationAccountService stationAccountService;
+    private final SplitRecordService splitRecordService;
 
 
     /**
@@ -101,7 +101,7 @@ public class WxPayServiceImpl implements WxPayService {
                             PayLogService payLogService, AccountService accountService,
                             RefundLogService refundLogService,
                             ActivityService activityService, UserRechargeRightsService userRechargeRightsService,
-                            RechargeConfigService rechargeConfigService, StationAccountService stationAccountService) {
+                            RechargeConfigService rechargeConfigService, StationAccountService stationAccountService, SplitRecordService splitRecordService) {
         this.conf = conf;
         this.walletDetailService = walletDetailService;
         this.payLogService = payLogService;
@@ -111,6 +111,7 @@ public class WxPayServiceImpl implements WxPayService {
         this.userRechargeRightsService = userRechargeRightsService;
         this.rechargeConfigService = rechargeConfigService;
         this.stationAccountService = stationAccountService;
+        this.splitRecordService = splitRecordService;
     }
 
     /**
@@ -347,9 +348,18 @@ public class WxPayServiceImpl implements WxPayService {
                 var stationFreezeAmount = totalAmount - stationBasicAmount;
                 stationAccountService.lambdaUpdate()
                         .setSql("balance = (balance + %d), frozen_amount = (frozen_amount + %d)".formatted(stationBasicAmount, stationFreezeAmount))
-                        .eq(StationAccount::getId, KymCache.INSTANCE.getInvestorAdminUserIdByStationId(stationId))
+                        .eq(StationAccount::getStationId, stationId)
                         .update();
 
+                // 分账记录
+                var splitRecord = new SplitRecord()
+                        .setFromStationId(stationId)
+                        .setToStationId(stationId)
+                        .setTradeNo(transaction.getTransactionId())
+                        .setAmount(totalAmount)
+                        .setType(SplitRecord.TYPE_RECHARGE);
+                splitRecordService.save(splitRecord);
+
                 LOGGER.info("微信支付回调{}:业务处理结束", notifyRes[2]);
                 return ResponseEntity.status(HttpStatus.OK).build();