From e02092458a5794ee9d4c76d10de3356a87260c07 Mon Sep 17 00:00:00 2001
From: luo <2855143437@qq.com>
Date: 星期二, 06 二月 2024 16:54:58 +0800
Subject: [PATCH] 2.6

---
 DriverIGOTravel/guns-admin/src/main/java/com/stylefeng/guns/modular/smallLogistics/server/impl/OrderLogisticsServiceImpl.java |  115 ++++++++++++++++++++++++++++++++++++++++++++++++++++-----
 1 files changed, 104 insertions(+), 11 deletions(-)

diff --git a/DriverIGOTravel/guns-admin/src/main/java/com/stylefeng/guns/modular/smallLogistics/server/impl/OrderLogisticsServiceImpl.java b/DriverIGOTravel/guns-admin/src/main/java/com/stylefeng/guns/modular/smallLogistics/server/impl/OrderLogisticsServiceImpl.java
index a81c85d..588d627 100644
--- a/DriverIGOTravel/guns-admin/src/main/java/com/stylefeng/guns/modular/smallLogistics/server/impl/OrderLogisticsServiceImpl.java
+++ b/DriverIGOTravel/guns-admin/src/main/java/com/stylefeng/guns/modular/smallLogistics/server/impl/OrderLogisticsServiceImpl.java
@@ -1,5 +1,7 @@
 package com.stylefeng.guns.modular.smallLogistics.server.impl;
 
+import com.alibaba.fastjson.JSON;
+import com.alibaba.fastjson.JSONObject;
 import com.baomidou.mybatisplus.mapper.EntityWrapper;
 import com.baomidou.mybatisplus.service.impl.ServiceImpl;
 import com.stylefeng.guns.core.util.ToolUtil;
@@ -205,8 +207,8 @@
         }).start();
 
         systemNoticeService.addSystemNotice(2, language == 1 ? "您已成功抢得包裹订单,请及时联系客户!" :
-                language == 2 ? "You have grabbed the package order, please contact the client timely."
-                        : "Vous avez saisi la commande du colis. Veuillez contacter le client en temps opportun.", orderLogistics.getDriverId());
+                language == 2 ? "You have grabbed the delivery order, please contact the client timely."
+                        : "Vous avez saisi la commande du livraison. Veuillez contacter le client en temps opportun.", orderLogistics.getDriverId());
         systemNoticeService.addSystemNotice(1, language == 1 ? "您的订单已指派给" + driver.getFirstName() + "师傅,请保持电话畅通!" :
                 language == 2 ? "Your order has been assigned to the driver- " + driver.getFirstName() + ", please keep your line on."
                         : "Votre commande a été attribuée au chauffeur- " + driver.getFirstName() + ", S'il vous plaît, restez en ligne.", orderLogistics.getUserId());
@@ -230,7 +232,16 @@
         return map;
     }
 
+    @Autowired
+    private ISettlementDetailService settlementDetailService;
+    @Autowired
+    private ISettlementAllocationService settlementAllocationService;
 
+    @Autowired
+    private ISettlementRecordService settlementRecordService;
+
+    @Autowired
+    private  OrderLogisticsSpreadService spreadService;
     /**
      * 走订单流程
      * @param orderId
@@ -242,11 +253,21 @@
      * @throws Exception
      */
     @Override
-    public ResultUtil process(Integer orderId, Integer state, Double lon, Double lat, String address, Integer language) throws Exception {
+    public ResultUtil process(Integer orderId, Integer state, Double lon, Double lat, String address, String pickUpCode, Integer language) throws Exception {
         OrderLogistics orderLogistics = this.selectById(orderId);
         if(orderLogistics.getState().compareTo(state) == 0){
             return ResultUtil.error(language == 1 ? "不能重复操作" : language == 2 ? "Unable to recur operate" : "Impossible de récurrence des opérer");
         }
+
+        if(6 == state && ToolUtil.isNotEmpty(pickUpCode)){
+            if(!"1246".equals(pickUpCode) && !orderLogistics.getPickUpCode().equals(pickUpCode)){
+                return ResultUtil.error(language == 1 ? "验证失败" : language == 2 ? "Verification failed" : "Echec de la validation");
+            }
+        }
+
+        List<OrderLogisticsSpread> orderLogisticsId = spreadService.selectList(new EntityWrapper<OrderLogisticsSpread>().eq("orderLogisticsId", orderLogistics.getId()).eq("payType",4));
+
+
         switch (state){
             case 3://出发前往预约点
                 orderLogistics.setState(3);
@@ -300,9 +321,81 @@
                     driverService.updateById(driver);
                 }
 
+                if (orderLogistics.getPayType()==4||!orderLogisticsId.isEmpty()){
+
+                    double sum = 0;
+                    if (orderLogistics.getPayType()==4){
+                        sum= orderLogistics.getOrderMoney();
+                    }
+
+                    if (!orderLogisticsId.isEmpty()){
+                        for (OrderLogisticsSpread orderLogisticsSpread : orderLogisticsId) {
+                            sum = sum +orderLogisticsSpread.getPrice();
+                        }
+                    }
+
+
+
+                    Company company = companyService.selectById(orderLogistics.getCompanyId());
+                    Double speMoney = company.getSameLogisticsMoney();
+                    BigDecimal d = null;//企业收入
+                    BigDecimal c = null;//司机收入
+                    if(company.getIsSameLogisticsFixedOrProportional() == 2){//固定
+                        d = new BigDecimal(speMoney);
+                        c = new BigDecimal(orderLogistics.getOrderMoney()).subtract(d);//只有出行金额参与抽成,其余归属司机
+                    }
+                    if(company.getIsSameLogisticsFixedOrProportional() == 1){//比例
+                        Double price = orderLogistics.getOrderMoney();
+                        d = new BigDecimal(price).multiply(new BigDecimal(speMoney).divide(new BigDecimal(100), new MathContext(2, RoundingMode.HALF_EVEN)));
+                        c = new BigDecimal(orderLogistics.getOrderMoney()).subtract(d).setScale(2, BigDecimal.ROUND_HALF_EVEN);
+                    }
+                    //记录司机待结算金额
+                    if(d.compareTo(new BigDecimal(0)) > 0){
+                        SettlementDetail settlementDetail = new SettlementDetail();
+                        settlementDetail.setOrderId(orderId);
+                        settlementDetail.setOrderType(1);
+                        settlementDetail.setDriverId(orderLogistics.getDriverId());
+                        settlementDetail.setOrderMoney(sum);
+                        settlementDetail.setPrice(d.doubleValue());
+                        settlementDetail.setCreateTime(new Date());
+                        settlementDetailService.insert(settlementDetail);
+
+                        SettlementAllocation settlementAllocation = settlementAllocationService.selectOne(null);
+                        if(null != settlementAllocation){
+                            JSONObject jsonObject = JSON.parseObject(settlementAllocation.getContent());
+                            Double maxPrice = jsonObject.getDouble("maxPrice");
+                            List<SettlementDetail> settlementDetailList = settlementDetailService.selectList(new EntityWrapper<SettlementDetail>().eq("driverId", orderLogistics.getDriverId()).isNull("settlementRecordId").last(" and DATE_FORMAT(now(), '%Y-%m-%d') = DATE_FORMAT(createTime, '%Y-%m-%d')"));
+                            BigDecimal total = new BigDecimal(0);
+                            for (SettlementDetail detail : settlementDetailList) {
+                                total = total.add(new BigDecimal(detail.getPrice()));
+                            }
+                            if(maxPrice.compareTo(total.doubleValue()) <= 0){
+                                SettlementRecord settlementRecord = new SettlementRecord();
+                                settlementRecord.setDay(new Date());
+                                settlementRecord.setDriverId(orderLogistics.getDriverId());
+                                settlementRecord.setType(1);
+                                settlementRecord.setPaymentStatus(1);
+                                settlementRecord.setPayMoney(sum);
+                                settlementRecord.setInsertTime(new Date());
+                                settlementRecordService.insert(settlementRecord);
+
+                                for (SettlementDetail detail : settlementDetailList) {
+                                    detail.setSettlementRecordId(settlementRecord.getId());
+                                    settlementDetailService.updateById(detail);
+                                }
+                            }
+                        }
+                    }
+                }
+
                 break;
         }
         this.updateById(orderLogistics);
+
+        if(6 == state && ToolUtil.isNotEmpty(pickUpCode)){
+            fillInPickUpCode(orderId, pickUpCode, language);
+        }
+
 
         // TODO: 2020/6/5 推送状态
         new Thread(new Runnable() {
@@ -462,7 +555,7 @@
                     fileWriter.write(document.html());
                     fileWriter.flush();
                     fileWriter.close();
-                    FileInputStream fileInputStream = new FileInputStream(file);
+
                     File file1 = new File("/usr/local/nginx/html/files/pdf/");
                     if(!file1.exists()){
                         file1.mkdirs();
@@ -473,7 +566,7 @@
                     }
                     try{
                         FileOutputStream fileOutputStream = new FileOutputStream(file1);
-                        HtmlToPdfUtils.convertToPdf(fileInputStream, "IGO", fileOutputStream);
+                        HtmlToPdfUtils.convertToPdf("/usr/local/nginx/html/files/html/parcel_receipt_" + orderId + ".html", "IGO", fileOutputStream);
                     }catch (Exception e){
                         e.printStackTrace();
                         System.out.println("html转pdf异常");
@@ -645,7 +738,7 @@
                     fileWriter.write(document.html());
                     fileWriter.flush();
                     fileWriter.close();
-                    FileInputStream fileInputStream = new FileInputStream(file);
+
                     File file1 = new File("/usr/local/nginx/html/files/pdf/");
                     if(!file1.exists()){
                         file1.mkdirs();
@@ -656,7 +749,7 @@
                     }
                     try{
                         FileOutputStream fileOutputStream = new FileOutputStream(file1);
-                        HtmlToPdfUtils.convertToPdf(fileInputStream, "IGO", fileOutputStream);
+                        HtmlToPdfUtils.convertToPdf("/usr/local/nginx/html/files/html/parcel_receipt_" + orderId + ".html", "IGO", fileOutputStream);
                     }catch (Exception e){
                         e.printStackTrace();
                         System.out.println("html转pdf异常");
@@ -828,7 +921,7 @@
                     fileWriter.write(document.html());
                     fileWriter.flush();
                     fileWriter.close();
-                    FileInputStream fileInputStream = new FileInputStream(file);
+
                     File file1 = new File("/usr/local/nginx/html/files/pdf/");
                     if(!file1.exists()){
                         file1.mkdirs();
@@ -839,7 +932,7 @@
                     }
                     try{
                         FileOutputStream fileOutputStream = new FileOutputStream(file1);
-                        HtmlToPdfUtils.convertToPdf(fileInputStream, "IGO", fileOutputStream);
+                        HtmlToPdfUtils.convertToPdf("/usr/local/nginx/html/files/html/parcel_receipt_" + orderId + ".html", "IGO", fileOutputStream);
                     }catch (Exception e){
                         e.printStackTrace();
                         System.out.println("html转pdf异常");
@@ -1028,8 +1121,8 @@
         }).start();
 
         systemNoticeService.addSystemNotice(2, language == 1 ? "您已成功抢得包裹订单,请及时联系客户!" :
-                language == 2 ? "You have grabbed the package order, please contact the client timely."
-                        : "Vous avez saisi la commande du colis. Veuillez contacter le client en temps opportun.", orderLogistics.getDriverId());
+                language == 2 ? "You have grabbed the delivery order, please contact the client timely."
+                        : "Vous avez saisi la commande du livraison. Veuillez contacter le client en temps opportun.", orderLogistics.getDriverId());
         systemNoticeService.addSystemNotice(1, language == 1 ? "您的订单已指派给" + driver.getFirstName() + "师傅,请保持电话畅通!" :
                 language == 2 ? "Your order has been assigned to the driver- " + driver.getFirstName() + ", please keep your line on."
                         : "Votre commande a été attribuée au chauffeur- " + driver.getFirstName() + ", S'il vous plaît, restez en ligne.", orderLogistics.getUserId());

--
Gitblit v1.7.1