From 5ee4dfad6e7b48885e205f8f945276b5d4ca5670 Mon Sep 17 00:00:00 2001
From: puzhibing <393733352@qq.com>
Date: 星期四, 18 五月 2023 16:34:27 +0800
Subject: [PATCH] 修改支付

---
 user/guns-admin/src/main/java/com/supersavedriving/user/modular/system/service/impl/OrderServiceImpl.java |   96 +++++++++++++++++++++++++++++++++++++++--------
 1 files changed, 79 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 fd6c398..af5bc2e 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
@@ -431,6 +431,9 @@
                 return ResultUtil.error("司机还未上班");
             }
             Driver driver = driverService.selectById(travelOrder.getDriverId());
+            if(driver.getServerStatus() == 2){
+                return ResultUtil.error("司机正在服务中");
+            }
             order.setAgentId(driver.getAgentId());
             order.setBranchOfficeId(driver.getBranchOfficeId());
             order.setOrderTakingTime(new Date());
@@ -439,6 +442,7 @@
             driverService.updateById(driver);
 
             appUser.setCancelCount(0);
+            appUser.setIsException(1);
             appUserService.updateById(appUser);
         }
 
@@ -631,6 +635,9 @@
         this.updateById(order);
         AppUser appUser = appUserService.selectById(uid);
         appUser.setCancelCount(appUser.getCancelCount() + 1);
+        if(appUser.getCancelCount() >= 3){
+            appUser.setIsException(2);
+        }
         appUserService.updateById(appUser);
         Driver driver = driverService.selectById(order.getDriverId());
         if(null != driver){
@@ -710,6 +717,14 @@
         Order orderPrice = getOrderPrice(1, d, 0, order1, city);
         order.setEstimatedPrice(orderPrice.getEstimatedPrice());
         this.updateById(order);
+
+        PushOrderInfoWarpper pushOrderInfoWarpper = new PushOrderInfoWarpper();
+        pushOrderInfoWarpper.setId(order.getId());
+        pushOrderInfoWarpper.setState(order.getState());
+        pushOrderInfoWarpper.setEndAddress(order.getEndAddress());
+        pushOrderInfoWarpper.setEndLat(order.getEndLat());
+        pushOrderInfoWarpper.setEndLng(order.getEndLng());
+        pushUtil.pushOrderInfo(order.getDriverId(), 2, pushOrderInfoWarpper);
         return ResultUtil.success();
     }
 
@@ -725,20 +740,24 @@
         Order order = this.selectById(orderId);
         OrderPriceWarpper orderPriceWarpper = new OrderPriceWarpper();
         BeanUtils.copyProperties(order, orderPriceWarpper);
-        AppUser appUser = appUserService.selectById(uid);
-        orderPriceWarpper.setBalance(appUser.getAccountBalance());
-        Double orderMoney = order.getOrderMoney();
-        //先算优惠券
-        Coupon coupon = userToCouponService.queryCoupon(uid, orderMoney);
-        if(null != coupon){
-            orderMoney = orderMoney - coupon.getCouponPreferentialAmount();
-            orderPriceWarpper.setDiscountedPrice(coupon.getCouponPreferentialAmount());
-            orderPriceWarpper.setCouponId(coupon.getId());
+        orderPriceWarpper.setActualMileage(new BigDecimal(order.getActualMileage() / 1000).setScale(2, RoundingMode.HALF_EVEN).doubleValue());
+        orderPriceWarpper.setTravelTime(Double.valueOf((order.getGetoffTime().getTime() - order.getStartTime().getTime()) / 60000).intValue());
+        if(null == order.getPayTime()){
+            AppUser appUser = appUserService.selectById(uid);
+            orderPriceWarpper.setBalance(appUser.getAccountBalance());
+            Double orderMoney = order.getOrderMoney();
+            //先算优惠券
+            Coupon coupon = userToCouponService.queryCoupon(uid, orderMoney);
+            if(null != coupon){
+                orderMoney = orderMoney - coupon.getCouponPreferentialAmount();
+                orderPriceWarpper.setDiscountedPrice(coupon.getCouponPreferentialAmount());
+                orderPriceWarpper.setCouponId(coupon.getId());
+            }
+            orderPriceWarpper.setDiscount(0D);
+            orderPriceWarpper.setDiscountAmount(0D);
+            orderPriceWarpper.setPayType(1);//微信支付
+            orderPriceWarpper.setPayMoney(orderMoney);
         }
-        orderPriceWarpper.setDiscount(0D);
-        orderPriceWarpper.setDiscountAmount(0D);
-        orderPriceWarpper.setPayType(1);//微信支付
-        orderPriceWarpper.setPayMoney(orderMoney);
         return orderPriceWarpper;
     }
 
@@ -758,6 +777,8 @@
         OrderPriceWarpper orderPriceWarpper = new OrderPriceWarpper();
         BeanUtils.copyProperties(order, orderPriceWarpper);
         AppUser appUser = appUserService.selectById(uid);
+        orderPriceWarpper.setActualMileage(new BigDecimal(order.getActualMileage() / 1000).setScale(2, RoundingMode.HALF_EVEN).doubleValue());
+        orderPriceWarpper.setTravelTime(Double.valueOf((order.getGetoffTime().getTime() - order.getStartTime().getTime()) / 60000).intValue());
         orderPriceWarpper.setBalance(appUser.getAccountBalance());
         orderPriceWarpper.setDiscount(0D);
         orderPriceWarpper.setDiscountAmount(0D);
@@ -766,7 +787,6 @@
         //先算优惠券
         Coupon coupon = userToCouponService.queryCoupon(uid, orderMoney);
         if(null != coupon && null == couponId){
-            orderMoney = orderMoney - coupon.getCouponPreferentialAmount();
             orderPriceWarpper.setDiscountedPrice(coupon.getCouponPreferentialAmount());
             orderPriceWarpper.setCouponId(coupon.getId());
         }
@@ -777,10 +797,10 @@
             orderPriceWarpper.setDiscountedPrice(coupon1.getCouponPreferentialAmount());
             orderPriceWarpper.setCouponId(couponId);
         }
-        if(payType == 1 && appUser.getHavDiscount() == 1){//使用余额抵扣
+        if(payType == 1 && appUser.getHavDiscount() == 1 && balance >= orderMoney){//使用余额抵扣
             orderPriceWarpper.setDiscount(9D);
-            orderPriceWarpper.setDiscountAmount(orderMoney * 0.1);
-            orderMoney = orderMoney * 0.9;
+            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();
         }
         if(payType == 0){//不使用余额抵扣
             orderPriceWarpper.setPayType(1);
@@ -859,10 +879,12 @@
             UserToCoupon userToCoupon = userToCouponService.selectById(couponId);
             if(userToCoupon.getValidCount() > 0){
                 userToCoupon.setValidCount(userToCoupon.getValidCount() - 1);
+                userToCouponService.updateById(userToCoupon);
                 Coupon coupon = couponService.selectById(userToCoupon.getCouponId());
                 payMoney = payMoney - coupon.getCouponPreferentialAmount();
                 order.setCouponId(coupon.getId());
                 order.setDiscountedPrice(coupon.getCouponPreferentialAmount());
+                userToCouponService.updateById(userToCoupon);
             }
         }
         order.setPayType(1);
@@ -924,10 +946,27 @@
             UserToCoupon userToCoupon = userToCouponService.selectById(couponId);
             if(userToCoupon.getValidCount() > 0){
                 userToCoupon.setValidCount(userToCoupon.getValidCount() - 1);
+                userToCouponService.updateById(userToCoupon);
                 Coupon coupon = couponService.selectById(userToCoupon.getCouponId());
                 payMoney = payMoney - coupon.getCouponPreferentialAmount();
                 order.setCouponId(coupon.getId());
                 order.setDiscountedPrice(coupon.getCouponPreferentialAmount());
+
+                Driver driver = driverService.selectById(order.getDriverId());
+                AccountChangeDetail accountChangeDetail = new AccountChangeDetail();
+                accountChangeDetail.setCode(System.currentTimeMillis() + UUIDUtil.getNumberRandom(3));
+                accountChangeDetail.setUserType(2);
+                accountChangeDetail.setUserId(order.getDriverId());
+                accountChangeDetail.setCreateTime(new Date());
+                accountChangeDetail.setOldData(driver.getCouponBalance());
+                accountChangeDetail.setType(1);
+                accountChangeDetail.setChangeType(7);
+                accountChangeDetail.setOrderId(order.getId());
+                accountChangeDetail.setExplain("优惠券收入");
+                driver.setCouponBalance(driver.getCouponBalance() + coupon.getCouponPreferentialAmount());
+                accountChangeDetail.setNewData(driver.getCouponBalance());
+                driverService.updateById(driver);
+                accountChangeDetailService.insert(accountChangeDetail);
             }
         }
 
@@ -987,6 +1026,7 @@
             UserToCoupon userToCoupon = userToCouponService.selectById(couponId);
             if(userToCoupon.getValidCount() > 0){
                 userToCoupon.setValidCount(userToCoupon.getValidCount() - 1);
+                userToCouponService.updateById(userToCoupon);
                 Coupon coupon = couponService.selectById(userToCoupon.getCouponId());
                 payMoney = payMoney - coupon.getCouponPreferentialAmount();
                 order.setCouponId(coupon.getId());
@@ -1054,6 +1094,7 @@
             this.updateById(order);
             return ResultUtil.success(payCode);
 
+            // TODO: 2023/5/18 取消支付后需要处理优惠券数据回退
 //
 //
 //            new Thread(new Runnable() {
@@ -1237,6 +1278,25 @@
             List<PlatformRechargeRecord> platformRechargeRecords = platformRechargeRecordService.selectList(new EntityWrapper<PlatformRechargeRecord>().eq("state", 2).last(" and balance > 0 order by payTime"));
             Double discountedPrice = order.getDiscountedPrice();
             Driver driver = driverService.selectById(order.getDriverId());
+
+            UserToCoupon userToCoupon = userToCouponService.selectById(order.getCouponId());
+            Coupon coupon = couponService.selectById(userToCoupon.getCouponId());
+            AccountChangeDetail accountChangeDetail = new AccountChangeDetail();
+            accountChangeDetail.setCode(System.currentTimeMillis() + UUIDUtil.getNumberRandom(3));
+            accountChangeDetail.setUserType(2);
+            accountChangeDetail.setUserId(order.getDriverId());
+            accountChangeDetail.setCreateTime(new Date());
+            accountChangeDetail.setOldData(driver.getCouponBalance());
+            accountChangeDetail.setType(1);
+            accountChangeDetail.setChangeType(7);
+            accountChangeDetail.setOrderId(order.getId());
+            accountChangeDetail.setExplain("优惠券收入");
+            driver.setCouponBalance(driver.getCouponBalance() + coupon.getCouponPreferentialAmount());
+            accountChangeDetail.setNewData(driver.getCouponBalance());
+            driverService.updateById(driver);
+            accountChangeDetailService.insert(accountChangeDetail);
+
+
             for (PlatformRechargeRecord platformRechargeRecord : platformRechargeRecords) {
                 if(discountedPrice == 0){
                     break;
@@ -1661,4 +1721,6 @@
         notInvoiceOrder.setPageNum((notInvoiceOrder.getPageNum() - 1) * notInvoiceOrder.getPageSize());;
         return this.baseMapper.queryNotInvoiceOrder(uid, notInvoiceOrder);
     }
+
+
 }

--
Gitblit v1.7.1