Bläddra i källkod

根据测试结果调整相关计算逻辑

codingliang 1 år sedan
förälder
incheckning
9a26edd1c7

+ 41 - 15
src/main/java/com/sqx/modules/reconciliation/service/impl/PlatformBillServiceImpl.java

@@ -337,7 +337,6 @@ public class PlatformBillServiceImpl extends ServiceImpl<PlatformBillMapper, Pla
         // 查询前一天账单
         LambdaQueryWrapper<PlatformBill> queryWrapper = Wrappers.lambdaQuery();
         queryWrapper.eq(PlatformBill::getDayId, date.minusDays(1));
-        queryWrapper.eq(PlatformBill::getType, "1");
         List<PlatformBill> prePlatformBillDataS = list(queryWrapper);
         Map<String, PlatformBill> platformBillMap = prePlatformBillDataS.stream().collect(Collectors.toMap(e -> (e.getUserId() + "-" + e.getType()), Function.identity()));
 
@@ -405,8 +404,15 @@ public class PlatformBillServiceImpl extends ServiceImpl<PlatformBillMapper, Pla
         platformBill.setRefundCount(sumInt(shopPlatformBills, PlatformBill::getRefundCount));
         // 平台抽成手续费
         platformBill.setPlatformRates(sum(shopPlatformBills, PlatformBill::getPlatformRates));
-        // 截止金额
-        platformBill.setEndMoney(platformBill.getRevenue());
+
+        // 期末金额 = 期初金额 + 当天收入 - 商家当天提现手续费 - 商家当天提现金额(已转账和待转账) - 骑手当天提现手续费 - 骑手当天提现金额(已转账+待转账+已拒绝)
+        BigDecimal endMoney = platformBill.getStartMoney()
+                .add(platformBill.getRevenue())
+                .subtract(platformBill.getShopPayoutsRates())
+                .subtract(platformBill.getShopPayouts())
+                .subtract(platformBill.getRiderPayoutsRates())
+                .subtract(platformBill.getRiderPayouts());
+        platformBill.setEndMoney(endMoney);
 
         return platformBill;
     }
@@ -489,17 +495,28 @@ public class PlatformBillServiceImpl extends ServiceImpl<PlatformBillMapper, Pla
                 platformBill.setSysGiftAmount(BigDecimal.ZERO);
             }
 
-            PlatformBill preBill = platformBillMap.get(riderInfo.getUserId() + "-" + "2");
+            platformBill.setTotalIncome(platformBill.getRevenue());
+
+
+            PlatformBill preBill = platformBillMap.get(riderInfo.getUserId() + "-2");
+
+            // 期初金额 = 前一天期末金额
+            // 期末金额 = 期初金额 + 当天收入 - 当天提现金额 - 当天提现手续费 + 当天骑手赠送余额
+            // 如果前一天对账数据为空,则期初金额为骑手账户余额
             if (ObjectUtil.isNotNull(preBill)) {
                 platformBill.setStartMoney(preBill.getEndMoney());
+
+                BigDecimal endMoney = preBill.getEndMoney()
+                        .add(platformBill.getRevenue())
+                        .subtract(platformBill.getRiderPayouts())
+                        .subtract(platformBill.getRiderPayoutsRates())
+                        .add(platformBill.getSysGiftAmount());
+                platformBill.setEndMoney(endMoney);
             } else {
                 platformBill.setStartMoney(BigDecimal.ZERO);
+                platformBill.setEndMoney(riderInfo.getBalance());
             }
 
-            platformBill.setTotalIncome(platformBill.getRevenue());
-
-            platformBill.setEndMoney(riderInfo.getBalance());
-
             return platformBill;
         }).collect(Collectors.toList());
     }
@@ -558,7 +575,6 @@ public class PlatformBillServiceImpl extends ServiceImpl<PlatformBillMapper, Pla
         List<UserMoneyBalanceBO> userMoneyBalances = baseMapper.getUserMoneyBalance(userIds);
         Map<Object, UserMoneyBalanceBO> userMoneyBalanceMap = userMoneyBalances.stream().collect(Collectors.toMap(UserMoneyBalanceBO::getUserId, Function.identity()));
 
-
         // 拼装商家对账数据
         return goodsShops.stream().map(goodsShop -> {
             PlatformBill platformBill = new PlatformBill();
@@ -608,18 +624,28 @@ public class PlatformBillServiceImpl extends ServiceImpl<PlatformBillMapper, Pla
                 platformBill.setShopBalance(BigDecimal.ZERO);
             }
 
-            PlatformBill preBill = platformBillMap.get(goodsShop.getUserId() + "1");
+            // 总收益等于完成订单收入
+            platformBill.setTotalIncome(platformBill.getRevenue());
+
+            // 期初金额 = 前一天的期末金额
+            // 期末金额 = 期初金额 + 当天收入 - 当天提现金额 - 当天提现手续费
+            // 如果前一天没有数据,则期初金额账户余额
+            PlatformBill preBill = platformBillMap.get(goodsShop.getUserId() + "-1");
             if (ObjectUtil.isNotNull(preBill)) {
                 platformBill.setStartMoney(preBill.getEndMoney());
+
+                // 期末金额 = 期初金额 + 当天收入 - 当天提现金额 - 当天提现手续费
+                BigDecimal endMoney = preBill.getEndMoney()
+                        .add(platformBill.getRevenue())
+                        .subtract(platformBill.getShopPayouts())
+                        .subtract(platformBill.getShopPayoutsRates());
+
+                platformBill.setEndMoney(endMoney);
             } else {
                 platformBill.setStartMoney(BigDecimal.ZERO);
+                platformBill.setEndMoney(platformBill.getShopBalance());
             }
 
-            // 总收益等于完成订单收入
-            platformBill.setTotalIncome(platformBill.getRevenue());
-            // 期末金额等于商家余额
-            platformBill.setEndMoney(platformBill.getShopBalance());
-
             return platformBill;
         }).collect(Collectors.toList());
     }

+ 8 - 8
src/main/resources/mapper/reconciliation/PlatformBillMapper.xml

@@ -24,7 +24,7 @@
                 and tu.user_name like concat('%',#{params.riderName},'%')
             </if>
         </where>
-        order by pb.bill_id desc
+        order by pb.dayId desc
     </select>
 
     <select id="shopBill" resultType="com.sqx.modules.reconciliation.model.ShopBillVo">
@@ -46,7 +46,7 @@
                 and gs.shop_name like concat('%',#{params.shopName},'%')
             </if>
         </where>
-        order by pb.bill_id desc
+        order by pb.dayId desc
     </select>
     <select id="platformBill" resultType="com.sqx.modules.reconciliation.model.PlatformBill">
         select pb.*
@@ -60,7 +60,7 @@
                 and pb.day_id <![CDATA[ <= ]]> #{params.endDate}
             </if>
         </where>
-        order by pb.bill_id desc
+        order by pb.dayId desc
     </select>
 
     <select id="excelRiderBillList" resultType="com.sqx.modules.reconciliation.model.RiderBillVo">
@@ -85,7 +85,7 @@
                 and tu.user_name like concat('%',#{params.riderName},'%')
             </if>
         </where>
-        order by pb.bill_id desc
+        order by pb.dayId desc
     </select>
 
     <select id="excelShopBillList" resultType="com.sqx.modules.reconciliation.model.ShopBillVo">
@@ -107,7 +107,7 @@
                 and gs.shop_name like concat('%',#{params.shopName},'%')
             </if>
         </where>
-        order by pb.bill_id desc
+        order by pb.dayId desc
     </select>
 
     <select id="excelPlatformBillList" resultType="com.sqx.modules.reconciliation.model.PlatformBill">
@@ -122,7 +122,7 @@
                 and pb.day_id <![CDATA[ <= ]]> #{params.endDate}
             </if>
         </where>
-        order by pb.bill_id desc
+        order by pb.dayId desc
     </select>
 
     <update id="updatePlatFormStartMoney">
@@ -336,7 +336,7 @@
             cash_out
         WHERE
             state != -1 -- 提现成功
-            AND out_at BETWEEN #{startTime} AND #{endTime}
+            AND create_at BETWEEN #{startTime} AND #{endTime}
             AND shop_id IS NOT NULL
         GROUP BY user_id;
     </select>
@@ -351,7 +351,7 @@
         cash_out
         WHERE
             type = 1
-            AND out_at BETWEEN #{startTime} AND #{endTime}
+            AND create_at BETWEEN #{startTime} AND #{endTime}
             AND shop_id IS NULL
         GROUP BY user_id;
     </select>