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

---
 driver/guns-admin/src/main/java/com/supersavedriving/driver/modular/system/service/impl/OrderServiceImpl.java |   87 ++++++++++++++++++++++++++++++++++++-------
 1 files changed, 73 insertions(+), 14 deletions(-)

diff --git a/driver/guns-admin/src/main/java/com/supersavedriving/driver/modular/system/service/impl/OrderServiceImpl.java b/driver/guns-admin/src/main/java/com/supersavedriving/driver/modular/system/service/impl/OrderServiceImpl.java
index 0b943a8..797f285 100644
--- a/driver/guns-admin/src/main/java/com/supersavedriving/driver/modular/system/service/impl/OrderServiceImpl.java
+++ b/driver/guns-admin/src/main/java/com/supersavedriving/driver/modular/system/service/impl/OrderServiceImpl.java
@@ -13,12 +13,8 @@
 import com.supersavedriving.driver.modular.system.util.mongodb.model.Location;
 import com.supersavedriving.driver.modular.system.warpper.*;
 import com.supersavedriving.driver.core.util.ToolUtil;
-import com.supersavedriving.driver.modular.system.util.*;
 import com.supersavedriving.driver.modular.system.util.GaoDe.model.District;
 import com.supersavedriving.driver.modular.system.util.juhe.WeatherUtil;
-import com.supersavedriving.driver.modular.system.warpper.*;
-import com.supersavedriving.driver.modular.system.model.*;
-import com.supersavedriving.driver.modular.system.service.*;
 import com.supersavedriving.driver.modular.system.util.PushUtil;
 import com.supersavedriving.driver.modular.system.warpper.AddOrderWarpper;
 import com.supersavedriving.driver.modular.system.warpper.HallOrderList;
@@ -93,6 +89,12 @@
 
     @Autowired
     private IRevenueService revenueService;
+
+    @Autowired
+    private ICouponService couponService;
+
+    @Autowired
+    private IUserToCouponService userToCouponService;
 
     private Map<String, Timer> timerMap = new HashMap<>();
 
@@ -580,7 +582,7 @@
         orderRefusal.setOrderId(orderId);
         orderRefusalService.insert(orderRefusal);
 
-        Driver driver = driverService.selectById(order.getDriverId());
+        Driver driver = driverService.selectById(uid);
         //扣除积分
         SystemConfig systemConfig = systemConfigService.selectOne(new EntityWrapper<SystemConfig>().eq("type", 4));
         if(null != systemConfig) {
@@ -591,8 +593,10 @@
                 AccountChangeDetail accountChangeDetail = new AccountChangeDetail();
                 accountChangeDetail.setCode(System.currentTimeMillis() + UUIDUtil.getNumberRandom(3));
                 accountChangeDetail.setUserType(2);
-                accountChangeDetail.setUserId(order.getDriverId());
+                accountChangeDetail.setUserId(uid);
                 accountChangeDetail.setType(2);
+                accountChangeDetail.setChangeType(2);
+                accountChangeDetail.setOrderId(orderId);
                 accountChangeDetail.setOldData(null == driver.getIntegral() ? 0 : driver.getIntegral().doubleValue());
                 driver.setIntegral((null == driver.getIntegral() ? 0 : driver.getIntegral()) - num10);
                 accountChangeDetail.setNewData(driver.getIntegral().doubleValue());
@@ -635,7 +639,7 @@
                 redisUtil.unlock();
                 return ResultUtil.error("订单已被取消");
             }
-            if(state != 101){
+            if(state != 101 && state != 201){
                 redisUtil.unlock();
                 return ResultUtil.error("手速慢了哦");
             }
@@ -650,6 +654,7 @@
             if(null != order.getUserId()){
                 AppUser appUser = appUserService.selectById(order.getUserId());
                 appUser.setCancelCount(0);
+                appUser.setIsException(1);
                 appUserService.updateById(appUser);
             }
 
@@ -758,6 +763,10 @@
         }
         if(order.getState() == 201){
             return ResultUtil.error("订单正在转单中");
+        }
+        if(order.getState() == 301){
+            redisUtil.unlock();
+            return ResultUtil.error("订单已被取消");
         }
         order.setState(processOperationsWarpper.getState());
         switch (processOperationsWarpper.getState()){
@@ -928,10 +937,16 @@
                     int travelTime = Double.valueOf((System.currentTimeMillis() - order.getStartTime().getTime()) / 60000).intValue();
                     pushOrderInfoWarpper.setTravelTime(travelTime);
                 }
-                pushUtil.pushOrderInfo(uid, 2, pushOrderInfoWarpper);
                 if(null != order.getUserId()){
                     pushUtil.pushOrderInfo(order.getUserId(), 1, pushOrderInfoWarpper);
                 }
+                if(order.getState() == 301){//司机取消不推送给司机
+                    CancelOrder cancelOrder = cancelOrderService.selectOne(new EntityWrapper<CancelOrder>().eq("orderId", order.getId()).eq("status", 1));
+                    if(null != cancelOrder && cancelOrder.getUserType() == 2){
+                        return;
+                    }
+                }
+                pushUtil.pushOrderInfo(uid, 2, pushOrderInfoWarpper);
             }
         },0, 10000);
         timerMap.put(orderId.toString(), timer);
@@ -1073,6 +1088,8 @@
             driver.setServerStatus(1);
             driverService.updateById(driver);
         }
+
+        pushUtil.pushOrderStatus(order.getUserId(), 1, order.getId(), order.getStatus());
         return ResultUtil.success();
     }
 
@@ -1122,17 +1139,59 @@
      * @throws Exception
      */
     @Override
-    public ResultUtil setOrderStatus(Integer uid, Long orderId, Integer state) throws Exception {
+    public ResultUtil setOrderStatus(Integer uid, Long orderId, Integer payType, Integer state) throws Exception {
         List<Integer> s = Arrays.asList(107, 108);
         if(!s.contains(state)){
             return ResultUtil.error("操作失败");
         }
         Order order = this.selectById(orderId);
         order.setState(state);
+
+        // TODO: 2023/5/18 临时 
+        payType = 1;
         if(state == 108){
+            payType = 2;
+        }
+
+        if(payType == 2 && state == 107){
+            Coupon coupon = userToCouponService.queryCoupon(order.getUserId(), order.getOrderMoney());
+            if(null != coupon){
+                order.setCouponId(coupon.getId());
+                order.setDiscountAmount(coupon.getCouponPreferentialAmount());
+                order.setPayMoney(order.getOrderMoney() - coupon.getCouponPreferentialAmount());
+            }
+        }
+
+        if(payType == 2 && state == 108){
             order.setPayType(3);
             order.setPayTime(new Date());
-            order.setPayMoney(order.getOrderMoney() - order.getDiscountAmount());
+            if(null != order.getCouponId()){
+                UserToCoupon userToCoupon = userToCouponService.selectById(order.getCouponId());
+                if(userToCoupon.getValidCount() > 0){
+                    userToCoupon.setValidCount(userToCoupon.getValidCount() - 1);
+                    userToCouponService.updateById(userToCoupon);
+                    Coupon coupon = couponService.selectById(userToCoupon.getCouponId());
+                    order.setPayMoney(order.getPayMoney() - 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);
+                }
+            }
         }
         this.updateById(order);
 
@@ -1211,9 +1270,9 @@
                     //开始处理层级抽佣
                     if(null != driver.getInviterType() && driver.getInviterType() == 2){
                         Driver driver1 = driverService.selectById(driver.getInviterId());//一级司机
-                        if(null != driver1.getInviterType() && driver1.getInviterType() == 2){
+                        if(null != driver1 && null != driver1.getInviterType() && driver1.getInviterType() == 2){
                             Driver driver2 = driverService.selectById(driver1.getInviterId());//二级司机
-                            if(null != driver2.getInviterType() && driver2.getInviterType() == 2){
+                            if(null != driver2 && null != driver2.getInviterType() && driver2.getInviterType() == 2){
                                 Driver driver3 = driverService.selectById(driver2.getInviterId());//三级级司机
                                 Double num5 = jsonObject1.getDouble("num5");
                                 Double num6 = jsonObject1.getDouble("num6");
@@ -1505,9 +1564,9 @@
     @Override
     public List<MyAchievementWarpper> queryMyAchievement(Integer driverId, String time) throws Exception {
         List<MyAchievementWarpper> list = new ArrayList<>();
-        time = time.replaceAll("-", "年") + "月";
+//        time = time.replaceAll("-", "年");
         //订单量
-        List<PerformanceRankingWarpper> performanceRankingWarppers = performanceRankingWarppers = this.baseMapper.queryDriverRank(time, 2);
+        List<PerformanceRankingWarpper> performanceRankingWarppers = this.baseMapper.queryDriverRank(time, 2);
         int position = 0;
         Double d = 0D;
         for (int i = 0; i < performanceRankingWarppers.size(); i++) {

--
Gitblit v1.7.1