From c1a537aaa86fbb878cea6ab29a2df41ae15a4c48 Mon Sep 17 00:00:00 2001
From: puzhibing <393733352@qq.com>
Date: 星期日, 18 二月 2024 16:22:35 +0800
Subject: [PATCH] 修改bug

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

diff --git a/UserIGOTravel/guns-admin/src/main/java/com/stylefeng/guns/modular/smallLogistics/server/impl/OrderLogisticsServiceImpl.java b/UserIGOTravel/guns-admin/src/main/java/com/stylefeng/guns/modular/smallLogistics/server/impl/OrderLogisticsServiceImpl.java
index b5d2a2a..9c3b445 100644
--- a/UserIGOTravel/guns-admin/src/main/java/com/stylefeng/guns/modular/smallLogistics/server/impl/OrderLogisticsServiceImpl.java
+++ b/UserIGOTravel/guns-admin/src/main/java/com/stylefeng/guns/modular/smallLogistics/server/impl/OrderLogisticsServiceImpl.java
@@ -181,12 +181,12 @@
         String[] split = endLonLat.split(",");
         Double lng = Double.valueOf(split[0]);
         Double lat = Double.valueOf(split[1]);
-        ResultUtil<Map<String, Double>> price = this.getPrice1(type, startLonLat.split(",")[0], startLonLat.split(",")[1], lng.toString(), lat.toString(), language);
+        ResultUtil<Map<String, Object>> price = this.getPrice1(type, startLonLat.split(",")[0], startLonLat.split(",")[1], lng.toString(), lat.toString(), language);
         if(price.getCode() != 200){
             return price;
         }
         Integer i = this.selectCount(new EntityWrapper<OrderLogistics>().eq("userId", uid).eq("isDelete", 1));
-        Map<String, Double> map = price.getData();
+        Map<String, Object> map = price.getData();
         map.put("first", i.doubleValue());
         return price;
     }
@@ -204,11 +204,21 @@
         String[] split = endLonLat.split(",");
         Double lng = Double.valueOf(split[0]);
         Double lat = Double.valueOf(split[1]);
-        ResultUtil<Map<String, Double>> price = this.getPrice1(type, startLonLat.split(",")[0], startLonLat.split(",")[1], lng.toString(), lat.toString(), language);
+        ResultUtil<Map<String, Object>> price = this.getPrice1(type, startLonLat.split(",")[0], startLonLat.split(",")[1], lng.toString(), lat.toString(), language);
         if(price.getCode() == 200 && type == 5){
-            Map<String, Double> data = price.getData();
-            data.put("ordinary", data.get("ordinary") * number);
-            data.put("precious", data.get("precious") * number);
+            Map<String, Object> data = price.getData();
+            Double ordinary = Double.valueOf(data.get("ordinary").toString());
+            Double precious = Double.valueOf(data.get("precious").toString());
+            data.put("ordinary", ordinary * number);
+            data.put("precious", precious * number);
+        }
+        if(price.getCode() == 200){
+            Map<String, Object> data = price.getData();
+            Double ordinary = Double.valueOf(data.get("ordinary").toString());
+            Double precious = Double.valueOf(data.get("precious").toString());
+            Double discountMoney = Double.valueOf(data.get("discountMoney").toString());
+            data.put("ordinary", ordinary - discountMoney);
+            data.put("precious", precious - discountMoney);
         }
         return price;
     }
@@ -280,17 +290,31 @@
         orderLogistics.setMileage(0D);
         orderLogistics.setIsReassign(1);
         orderLogistics.setReassignNotice(0);
-        ResultUtil<Map<String, Double>> price = this.getPrice1(type, String.valueOf(startLon), String.valueOf(startLat), lng.toString(), lat.toString(), language);
+        ResultUtil<Map<String, Object>> price = this.getPrice1(type, String.valueOf(startLon), String.valueOf(startLat), lng.toString(), lat.toString(), language);
         if(price.getCode() != 200){
             return price;
         }
-        Map<String, Double> data = price.getData();
-        orderLogistics.setOrderMoney((cargoType == 1 ? data.get("ordinary") : data.get("precious")) + tipMoney);
-        orderLogistics.setTravelMoney(cargoType == 1 ? data.get("ordinary") : data.get("precious"));
-        if(type == 5){
-            orderLogistics.setOrderMoney(((cargoType == 1 ? data.get("ordinary") : data.get("precious")) * cargoNumber) + tipMoney);
-            orderLogistics.setTravelMoney((cargoType == 1 ? data.get("ordinary") : data.get("precious")) * cargoNumber);
+        Map<String, Object> data = price.getData();
+        Double ordinary = Double.valueOf(data.get("ordinary").toString());
+        Double precious = Double.valueOf(data.get("precious").toString());
+        Double discount = null;
+        if(null != data.get("discount")){
+            discount = Double.valueOf(data.get("discount").toString());
         }
+        Double discountMoney = Double.valueOf(data.get("discountMoney").toString());
+        Integer activityId = null;
+        if(null != data.get("activityId")){
+            activityId = Integer.valueOf(data.get("activityId").toString());
+        }
+        orderLogistics.setOrderMoney((cargoType == 1 ? ordinary : precious) + tipMoney);
+        orderLogistics.setTravelMoney((cargoType == 1 ? ordinary : precious));
+        if(type == 5){
+            orderLogistics.setOrderMoney(((cargoType == 1 ? ordinary : precious) * cargoNumber) + tipMoney);
+            orderLogistics.setTravelMoney((cargoType == 1 ? ordinary : precious) * cargoNumber);
+        }
+        orderLogistics.setDiscount(discount);
+        orderLogistics.setDiscountMoney(discountMoney);
+        orderLogistics.setActivityId(activityId);
         orderLogistics.setTipMoney(tipMoney);
         orderLogistics.setState(7);//待支付
         orderLogistics.setInsertTime(new Date());
@@ -360,7 +384,7 @@
 
 
 
-    public ResultUtil<Map<String, Double>> getPrice1(Integer type, String startLon, String startLat, String endLon, String endLat, Integer language) throws Exception{
+    public ResultUtil<Map<String, Object>> getPrice1(Integer type, String startLon, String startLat, String endLon, String endLat, Integer language) throws Exception{
         Company query = companyCityService.query1(startLon, startLat);
         if(null == query){
             return ResultUtil.error(language == 1 ? "预约取货点暂无企业服务" : language == 2 ?
@@ -368,6 +392,9 @@
         }
         Double price1 = 0D;
         Double price2 = 0D;
+        Double discount = null;
+        Double discountMoney = 0D;
+        Integer activityId = null;
         if(type == 4){//同城
             Map<String, Object> query1 = systemPriceMapper.query(query.getId(), type, null);
             DistancematrixVo distancematrix = GoogleMapUtil.getDistancematrix(Double.valueOf(startLat), Double.valueOf(startLon), Double.valueOf(endLat), Double.valueOf(endLon));
@@ -403,9 +430,23 @@
             price1 = jsonObject.getDouble("num1");
             price2 = jsonObject.getDouble("num2");
         }
-        Map<String, Double> map = new HashMap<>();
+
+        //计算折扣
+        UserActivityDiscount1 query2 = userActivityDiscount1Mapper.query(query.getId());
+        if(null != query2){
+            activityId = query2.getId();
+            discount = query2.getLogistics();
+            if(null != discount){
+                discountMoney = new BigDecimal(price1).multiply(new BigDecimal(discount / 10)).setScale(2, BigDecimal.ROUND_HALF_EVEN).doubleValue();
+            }
+        }
+
+        Map<String, Object> map = new HashMap<>();
         map.put("ordinary", price1);//普通
         map.put("precious", price2);//贵重
+        map.put("discount", discount);//折扣
+        map.put("discountMoney", discountMoney);//折扣金额
+        map.put("activityId", activityId);//折扣活动id
         return ResultUtil.success(map);
     }
 
@@ -508,7 +549,7 @@
             if(userCouponRecord.getState() == 3){
                 return ResultUtil.error(language == 1 ? "优惠券已过期" : language == 2 ? "Coupon is expired." : "Le coupon a expiré.", "");
             }
-            if(userCouponRecord.getCouponUseType() != 0 && userCouponRecord.getCouponUseType() != 1){
+            if(userCouponRecord.getCouponUseType() != 0 && userCouponRecord.getCouponUseType() != 4){
                 return ResultUtil.error(language == 1 ? "优惠券不能用于此订单" : language == 2 ? "Coupon cannot be used for this order." : "Le coupon ne peut pas être utilisé pour cette commande.", "");
             }
             if(userCouponRecord.getCouponType() == 2 && orderMoney.compareTo(userCouponRecord.getFullMoney()) < 0){
@@ -517,6 +558,10 @@
             orderMoney = orderMoney - userCouponRecord.getMoney();
             orderLogistics.setCouponMoney(userCouponRecord.getMoney());
             orderLogistics.setCouponId(couponId);
+        }
+        //折扣
+        if(null != orderLogistics.getActivityId()){
+            orderMoney = orderMoney - orderLogistics.getDiscount();
         }
         orderMoney=new BigDecimal(orderMoney).setScale(2, BigDecimal.ROUND_HALF_EVEN).doubleValue();
 
@@ -582,6 +627,13 @@
             SysIntegral query1 = sysIntegralMapper.query(orderLogistics.getCompanyId());
             userInfo.setIntegral(userInfo.getIntegral() + (orderMoney.intValue() * query1.getIntegral()));//积分
 
+            //处理优惠券
+            if(null != userCouponRecord){
+                userCouponRecord.setState(2);
+                userCouponRecord.setEndTime(new Date());
+                userCouponRecordService.updateById(userCouponRecord);
+            }
+
             //添加交易明细
             transactionDetailsService.saveData(uid, "包裹下单支付", orderMoney, 2, 1, 1, 4, orderId);
             userInfoService.updateById(userInfo);
@@ -607,6 +659,13 @@
         if(payType == 4){//现金支付
             SysIntegral query1 = sysIntegralMapper.query(orderLogistics.getCompanyId());
             userInfo.setIntegral(userInfo.getIntegral() + (orderMoney.intValue() * query1.getIntegral()));//积分
+
+            //处理优惠券和红包
+            if(null != userCouponRecord){
+                userCouponRecord.setState(2);
+                userCouponRecord.setEndTime(new Date());
+                userCouponRecordService.updateById(userCouponRecord);
+            }
 
             //添加交易明细
             transactionDetailsService.saveData(uid, "包裹下单支付", orderMoney, 2, 1, 1, 4, orderId);
@@ -774,30 +833,31 @@
             orderLogisticsSpreadService.updateById(orderLogisticsSpread);
 
             //添加已收入明细
-            Company company = companyService.selectById(orderLogistics.getCompanyId());
-            Double speMoney =  orderLogistics.getType() == 4 ? company.getSameLogisticsMoney() : company.getCrossLogisticsMoney();
-            BigDecimal d = null;
-            BigDecimal c = null;
-            if(company.getIsSpeFixedOrProportional() == 2){//固定
-                d = new BigDecimal(speMoney);
-                c = new BigDecimal(orderMoney).subtract(d);
-            }
-            if(company.getIsSpeFixedOrProportional() == 1){//比例
-                d = new BigDecimal(orderMoney).multiply(new BigDecimal(speMoney).divide(new BigDecimal(100), new MathContext(2, RoundingMode.HALF_EVEN)));
-                c = new BigDecimal(orderMoney).subtract(d).setScale(2, BigDecimal.ROUND_HALF_EVEN);
-            }
-
-            Income income = incomeService.selectOne(new EntityWrapper<Income>().eq("userType", 1).eq("objectId", orderLogistics.getCompanyId()).eq("type", 2).eq("incomeId", orderLogistics.getId()).eq("orderType", orderLogistics.getType()));
-            income.setMoney(income.getMoney() + d.doubleValue());
-            incomeService.updateById(income);
-            income = incomeService.selectOne(new EntityWrapper<Income>().eq("userType", 2).eq("objectId", orderLogistics.getCompanyId()).eq("type", 2).eq("incomeId", orderLogistics.getId()).eq("orderType", orderLogistics.getType()));
-            income.setMoney(income.getMoney() + c.doubleValue());
-            incomeService.updateById(income);
-            Driver driver = driverService.selectById(orderLogistics.getDriverId());
-            driver.setBusinessMoney(new BigDecimal(null != driver.getBusinessMoney() ? driver.getBusinessMoney() : 0).add(c).setScale(2, BigDecimal.ROUND_HALF_EVEN).doubleValue());
-            driver.setLaveBusinessMoney(new BigDecimal(null != driver.getLaveBusinessMoney() ? driver.getLaveBusinessMoney() : 0).add(c).setScale(2, BigDecimal.ROUND_HALF_EVEN).doubleValue());
-            driver.setBalance(new BigDecimal(null != driver.getBalance() ? driver.getBalance() : 0).add(c).setScale(2, BigDecimal.ROUND_HALF_EVEN).doubleValue());
-            driverService.updateById(driver);
+//            Company company = companyService.selectById(orderLogistics.getCompanyId());
+//            Double speMoney =  orderLogistics.getType() == 4 ? company.getSameLogisticsMoney() : company.getCrossLogisticsMoney();
+//            BigDecimal d = BigDecimal.ZERO;
+//            BigDecimal c = BigDecimal.ZERO;
+//            if(company.getIsSpeFixedOrProportional() == 2){//固定
+//                d = new BigDecimal(speMoney);
+//                c = new BigDecimal(orderMoney).subtract(d);
+//            }
+//            if(company.getIsSpeFixedOrProportional() == 1){//比例
+//                d = new BigDecimal(orderMoney).multiply(new BigDecimal(speMoney).divide(new BigDecimal(100), new MathContext(2, RoundingMode.HALF_EVEN)));
+//                c = new BigDecimal(orderMoney).subtract(d).setScale(2, BigDecimal.ROUND_HALF_EVEN);
+//            }
+//
+//            Income income = incomeService.selectOne(new EntityWrapper<Income>().eq("userType", 1).eq("objectId", orderLogistics.getCompanyId()).eq("type", 2).eq("incomeId", orderLogistics.getId()).eq("orderType", orderLogistics.getType()));
+//            income.setMoney(income.getMoney() + d.doubleValue());
+//            incomeService.updateById(income);
+//            income = incomeService.selectOne(new EntityWrapper<Income>().eq("userType", 2).eq("objectId", orderLogistics.getCompanyId()).eq("type", 2).eq("incomeId", orderLogistics.getId()).eq("orderType", orderLogistics.getType()));
+//            System.out.println("小件物流补差价income======"+income);
+//            income.setMoney(income.getMoney() + c.doubleValue());
+//            incomeService.updateById(income);
+//            Driver driver = driverService.selectById(orderLogistics.getDriverId());
+//            driver.setBusinessMoney(new BigDecimal(null != driver.getBusinessMoney() ? driver.getBusinessMoney() : 0).add(c).setScale(2, BigDecimal.ROUND_HALF_EVEN).doubleValue());
+//            driver.setLaveBusinessMoney(new BigDecimal(null != driver.getLaveBusinessMoney() ? driver.getLaveBusinessMoney() : 0).add(c).setScale(2, BigDecimal.ROUND_HALF_EVEN).doubleValue());
+//            driver.setBalance(new BigDecimal(null != driver.getBalance() ? driver.getBalance() : 0).add(c).setScale(2, BigDecimal.ROUND_HALF_EVEN).doubleValue());
+//            driverService.updateById(driver);
 
             // TODO: 2020/5/24 这里需要给司机和用户推送订单状态
             new Thread(new Runnable() {
@@ -836,6 +896,14 @@
             SysIntegral query1 = sysIntegralMapper.query(orderLogistics.getCompanyId());
             userInfo.setIntegral(userInfo.getIntegral() + (query.getAmount().intValue() * query1.getIntegral()));//积分
             userInfoService.updateById(userInfo);
+
+            //处理优惠券和红包
+            if(null != orderLogistics.getCouponId()){
+                UserCouponRecord userCouponRecord = userCouponRecordService.selectById(orderLogistics.getCouponId());
+                userCouponRecord.setState(2);
+                userCouponRecord.setEndTime(new Date());
+                userCouponRecordService.updateById(userCouponRecord);
+            }
 
             query.setState(2);
             query.setCode(order_id);
@@ -976,6 +1044,11 @@
                 map.put("receipt", "http://182.160.16.251:81/files/html/parcel_receipt_" + orderId + ".html");
             }else{
                 map.put("receipt", "");
+            }
+            if(state == 7){
+                Double discountMoney = Double.valueOf(map.get("discountMoney").toString());
+                Double orderMoney = Double.valueOf(map.get("orderMoney").toString());
+                map.put("orderMoney", orderMoney - discountMoney);
             }
         }
         return maps;
@@ -1288,8 +1361,8 @@
     @Override
     public List<Map<String, Object>> queryCoupon(Integer language, Integer orderId, Integer uid, Integer pageNum, Integer size) throws Exception {
         OrderLogistics orderLogistics = this.selectById(orderId);
-        List<Map<String, Object>> list = userCouponRecordService.queryCoupon(language, uid, orderLogistics.getCompanyId(), 1, 4, orderLogistics.getOrderMoney(), pageNum, size);
-        List<Map<String, Object>> list1 = userCouponRecordService.queryCoupon(language, uid, orderLogistics.getCompanyId(), 1, 0, orderLogistics.getOrderMoney(), pageNum, size);
+        List<Map<String, Object>> list = userCouponRecordService.queryCoupon(language, uid, orderLogistics.getCompanyId(), 1, 4, orderLogistics.getOrderMoney() -  orderLogistics.getDiscountMoney(), pageNum, size);
+        List<Map<String, Object>> list1 = userCouponRecordService.queryCoupon(language, uid, orderLogistics.getCompanyId(), 1, 0, orderLogistics.getOrderMoney() -  orderLogistics.getDiscountMoney(), pageNum, size);
         list.addAll(list1);
         return list;
     }

--
Gitblit v1.7.1