From 927afebd4a79f9a78759930bfaff9a5ed6abeb6e Mon Sep 17 00:00:00 2001
From: puzhibing <393733352@qq.com>
Date: 星期日, 30 七月 2023 04:50:08 +0800
Subject: [PATCH] 增加企业流水记录

---
 user/guns-admin/src/main/java/com/supersavedriving/user/modular/system/service/impl/OrderServiceImpl.java |   75 +++++++++++++++++++++++++++++--------
 1 files changed, 58 insertions(+), 17 deletions(-)

diff --git a/user/guns-admin/src/main/java/com/supersavedriving/user/modular/system/service/impl/OrderServiceImpl.java b/user/guns-admin/src/main/java/com/supersavedriving/user/modular/system/service/impl/OrderServiceImpl.java
index 8a5c823..dc24dcc 100644
--- a/user/guns-admin/src/main/java/com/supersavedriving/user/modular/system/service/impl/OrderServiceImpl.java
+++ b/user/guns-admin/src/main/java/com/supersavedriving/user/modular/system/service/impl/OrderServiceImpl.java
@@ -112,6 +112,12 @@
     @Autowired
     private IRechargeRecordService rechargeRecordService;
 
+    @Autowired
+    private IOrderService orderService;
+
+    @Autowired
+    private ICompanyFundFlowService companyFundFlowService;
+
     @Value("${wx.appletsAppid}")
     private String appletsAppid;
 
@@ -417,18 +423,6 @@
             return ResultUtil.error("您还有正在进行的订单");
         }
 
-        String value = redisUtil.getValue("USER" + uid);
-        if(ToolUtil.isEmpty(value)){
-            redisUtil.setStrValue("USER" + uid, System.currentTimeMillis() + "", 60);
-        }else{
-            Long s = System.currentTimeMillis() - Long.valueOf(value);
-            if(s.compareTo(60000L) < 0){//1分钟
-                return ResultUtil.error("数据处理中");
-            }
-            redisUtil.setStrValue("USER" + uid, System.currentTimeMillis() + "", 60);
-        }
-
-
         String startAddress = travelOrder.getStartAddress();
         startAddress = startAddress.replaceAll("& #40;", "(");
         startAddress = startAddress.replaceAll("& #41;", ")");
@@ -583,7 +577,8 @@
                         continue;
                     }
                     Driver driver1 = driverService.selectById(youTuiDriver.getDriverId());
-                    if(driver1.getServerStatus() == 2 || driver1.getOpenOrderQRCode() == 1){
+                    int count = orderService.selectCount(new EntityWrapper<Order>().eq("driverId", youTuiDriver.getDriverId()).eq("status", 1).in("state", Arrays.asList(102, 103, 104, 105, 201, 401)));
+                    if(driver1.getServerStatus() == 2 || driver1.getOpenOrderQRCode() == 1 || count > 0){
                         continue;
                     }
                     DriverWork driverWork = driverWorkService.selectOne(new EntityWrapper<DriverWork>().eq("driverId", driver1.getId()).eq("status", 1));
@@ -637,6 +632,10 @@
                             }
                             DriverWork driverWork = driverWorkService.selectOne(new EntityWrapper<DriverWork>().eq("driverId", driver1.getId()).eq("status", 1));
                             if(null == driverWork){
+                                continue;
+                            }
+                            int count = orderService.selectCount(new EntityWrapper<Order>().eq("driverId", driver1.getId()).eq("status", 1).in("state", Arrays.asList(102, 103, 104, 105, 201, 401)));
+                            if(count > 0){
                                 continue;
                             }
 
@@ -836,6 +835,12 @@
     @Override
     public ResultUtil editOrderEndAddress(Integer uid, EditOrderEndAddress editOrderEndAddress) throws Exception {
         Order order = this.selectById(editOrderEndAddress.getOrderId());
+
+        String endAddress = editOrderEndAddress.getEndAddress();
+        endAddress = endAddress.replaceAll("& #40;", "(");
+        endAddress = endAddress.replaceAll("& #41;", ")");
+        editOrderEndAddress.setEndAddress(endAddress);
+
         order.setEndAddress(editOrderEndAddress.getEndAddress());
         order.setEndLat(editOrderEndAddress.getEndLat().toString());
         order.setEndLng(editOrderEndAddress.getEndLng().toString());
@@ -908,6 +913,7 @@
         orderPriceWarpper.setDiscountedPrice(order.getDiscountedPrice());
         orderPriceWarpper.setBadWeatherPrice(order.getBadWeatherPrice());
         orderPriceWarpper.setPayMoney(order.getPayMoney());
+        orderPriceWarpper.setOrderMoney(order.getOrderMoney());
         if(order.getState() < 107){
             orderPriceWarpper.setPayMoney(order.getOrderMoney());
         }
@@ -948,9 +954,9 @@
             orderPriceWarpper.setCouponId(coupon.getId());
         }
         if(payType == 1 && null == couponId && appUser.getHavDiscount() == 1 && balance.compareTo(orderMoney) >= 0){//使用余额抵扣
-            orderPriceWarpper.setDiscount(9D);
-            orderPriceWarpper.setDiscountAmount(new BigDecimal(orderMoney * 0.1).setScale(2, RoundingMode.HALF_EVEN).doubleValue());
-            orderMoney = new BigDecimal(orderMoney * 0.9).setScale(2, RoundingMode.HALF_EVEN).doubleValue();
+            orderPriceWarpper.setDiscount(9.5D);
+            orderPriceWarpper.setDiscountAmount(new BigDecimal(orderMoney * 0.05).setScale(2, RoundingMode.HALF_EVEN).doubleValue());
+            orderMoney = new BigDecimal(orderMoney * 0.95).setScale(2, RoundingMode.HALF_EVEN).doubleValue();
         }
         if(null != couponId){
             UserToCoupon userToCoupon = userToCouponService.selectById(couponId);
@@ -1485,6 +1491,7 @@
             accountChangeDetailService.saveData(accountChangeDetail);
 
             //补贴中分账
+            Double balance = revenueService.queryCompanyBalance();//平台账户余额
             Double discountedPrice = order.getDiscountedPrice();
             List<RechargeRecord> rechargeRecords = rechargeRecordService.selectList(new EntityWrapper<RechargeRecord>().eq("type", 4).eq("payStatus", 2).gt("surplusDividedAmount", 0).orderBy("createTime"));
             for (RechargeRecord rechargeRecord : rechargeRecords) {
@@ -1510,6 +1517,13 @@
                 }
             }
 
+            CompanyFundFlow companyFundFlow = new CompanyFundFlow();
+            companyFundFlow.setBalance(new BigDecimal(balance));
+            companyFundFlow.setObjectType(1);
+            companyFundFlow.setType(5);
+            companyFundFlow.setMoney(new BigDecimal(order.getDiscountedPrice()));
+            companyFundFlow.setCreateTime(new Date());
+            companyFundFlowService.insert(companyFundFlow);
         }
     }
 
@@ -1958,6 +1972,7 @@
                     }
                     //处理代理商抽佣
                     if(num3 > 0 && null != driver){
+                        Double balance = revenueService.queryAgentBalance(driver.getAgentId());
                         Revenue revenue = new Revenue();
                         revenue.setType(1);
                         revenue.setUserType(3);
@@ -1991,6 +2006,15 @@
                                 }
                             }
                         }
+
+                        CompanyFundFlow companyFundFlow = new CompanyFundFlow();
+                        companyFundFlow.setType(3);
+                        companyFundFlow.setObjectType(2);
+                        companyFundFlow.setObjectId(driver.getAgentId());
+                        companyFundFlow.setBalance(new BigDecimal(balance));
+                        companyFundFlow.setMoney(new BigDecimal(num3));
+                        companyFundFlow.setCreateTime(new Date());
+                        companyFundFlowService.insert(companyFundFlow);
                     }
                 }
             }
@@ -2015,7 +2039,7 @@
         revenue.setUserType(2);
         revenue.setUserId(driver.getId());
         revenue.setOrderId(order.getId());
-        revenue.setAmount(order.getPayMoney() + order.getDiscountedPrice() + order.getDiscountAmount());
+        revenue.setAmount(order.getPayMoney() + order.getDiscountedPrice());//todo 折扣司机承担
         revenue.setCreateTime(new Date());
         revenueService.insert(revenue);
 
@@ -2076,6 +2100,7 @@
             accountChangeDetailService.saveData(accountChangeDetail);
 
             //补贴中分账
+            Double balance = revenueService.queryCompanyBalance();
             Double discountedPrice = order.getDiscountedPrice();
             List<RechargeRecord> rechargeRecords1 = rechargeRecordService.selectList(new EntityWrapper<RechargeRecord>().eq("type", 4).eq("payStatus", 2).gt("surplusDividedAmount", 0).orderBy("createTime"));
             for (RechargeRecord rechargeRecord : rechargeRecords1) {
@@ -2100,6 +2125,13 @@
                     }
                 }
             }
+            CompanyFundFlow companyFundFlow = new CompanyFundFlow();
+            companyFundFlow.setBalance(new BigDecimal(balance));
+            companyFundFlow.setObjectType(1);
+            companyFundFlow.setType(5);
+            companyFundFlow.setMoney(new BigDecimal(order.getDiscountedPrice()));
+            companyFundFlow.setCreateTime(new Date());
+            companyFundFlowService.insert(companyFundFlow);
 
         }
         // TODO: 2023/6/25 折扣优惠由司机承担
@@ -2240,6 +2272,7 @@
             driverService.updateById(driver);
             accountChangeDetailService.saveData(accountChangeDetail);
             //补贴中分账
+            Double balance = revenueService.queryCompanyBalance();
             Double discountedPrice = order.getDiscountedPrice();
             List<RechargeRecord> rechargeRecords = rechargeRecordService.selectList(new EntityWrapper<RechargeRecord>().eq("type", 4).eq("payStatus", 2).gt("surplusDividedAmount", 0).orderBy("createTime"));
             for (RechargeRecord rechargeRecord : rechargeRecords) {
@@ -2265,6 +2298,14 @@
                 }
             }
 
+            CompanyFundFlow companyFundFlow = new CompanyFundFlow();
+            companyFundFlow.setBalance(new BigDecimal(balance));
+            companyFundFlow.setObjectType(1);
+            companyFundFlow.setType(5);
+            companyFundFlow.setMoney(new BigDecimal(order.getDiscountedPrice()));
+            companyFundFlow.setCreateTime(new Date());
+            companyFundFlowService.insert(companyFundFlow);
+
         }
     }
 

--
Gitblit v1.7.1