From 0a6f905b50a88993da05b9b3114394fb91dbc7d0 Mon Sep 17 00:00:00 2001 From: puzhibing <393733352@qq.com> Date: 星期三, 31 五月 2023 19:05:56 +0800 Subject: [PATCH] 修改bug --- driver/guns-admin/src/main/java/com/agentdriving/driver/modular/system/service/impl/OrderServiceImpl.java | 185 ++++++++++++++++++++++++++++++++++----------- 1 files changed, 138 insertions(+), 47 deletions(-) diff --git a/driver/guns-admin/src/main/java/com/agentdriving/driver/modular/system/service/impl/OrderServiceImpl.java b/driver/guns-admin/src/main/java/com/agentdriving/driver/modular/system/service/impl/OrderServiceImpl.java index 1e54420..4441c08 100644 --- a/driver/guns-admin/src/main/java/com/agentdriving/driver/modular/system/service/impl/OrderServiceImpl.java +++ b/driver/guns-admin/src/main/java/com/agentdriving/driver/modular/system/service/impl/OrderServiceImpl.java @@ -158,16 +158,26 @@ if(null != appUser){ order.setUserId(appUser.getId()); } + String startAddress = addOrderWarpper.getStartAddress(); + startAddress = startAddress.replaceAll("& #40;", "("); + startAddress = startAddress.replaceAll("& #41;", ")"); order.setUserName(addOrderWarpper.getUserName()); order.setUserPhone(addOrderWarpper.getPhone()); order.setAgentId(driver.getAgentId()); order.setBranchOfficeId(driver.getBranchOfficeId()); - order.setStartAddress(addOrderWarpper.getStartAddress()); + order.setStartAddress(startAddress); order.setStartLat(addOrderWarpper.getStartLat()); order.setStartLng(addOrderWarpper.getStartLng()); - order.setEndAddress(addOrderWarpper.getEndAddress()); - order.setEndLat(addOrderWarpper.getEndLat()); - order.setEndLng(addOrderWarpper.getEndLng()); + + String endAddress = addOrderWarpper.getEndAddress(); + if(ToolUtil.isNotEmpty(endAddress)){ + endAddress = endAddress.replaceAll("& #40;", "("); + endAddress = endAddress.replaceAll("& #41;", ")"); + order.setEndAddress(endAddress); + order.setEndLat(addOrderWarpper.getEndLat()); + order.setEndLng(addOrderWarpper.getEndLng()); + } + Double d = 0D; if(ToolUtil.isNotEmpty(addOrderWarpper.getEndAddress())){ Map<String, String> distance = MapUtil.getDistance(order.getStartLng() + "," + order.getStartLat(), order.getEndLng() + "," + order.getEndLat(), 1); @@ -233,19 +243,18 @@ JSONArray chargeStandard = jsonObject.getJSONArray("ChargeStandard"); JSONObject extraCost = jsonObject.getJSONObject("ExtraCost"); Date date = new Date(); - for (int i = 0; i < chargeStandard.size(); i++) { + + boolean b = true; + for (int i = 1; i < chargeStandard.size(); i++) {//各种时间段 JSONObject jsonObject1 = chargeStandard.getJSONObject(i); String num1 = jsonObject1.getString("num1"); String num2 = jsonObject1.getString("num2"); - Double num3 = jsonObject1.getDouble("num3");//起步里程 - Double num4 = jsonObject1.getDouble("num4");//起步价格 - Double num5 = jsonObject1.getDouble("num5");//超过公里 - Double num6 = jsonObject1.getDouble("num6");//超过num3每num5公里收取num6 - Double num7 = jsonObject1.getDouble("num7");//长途起始公里 - Double num8 = jsonObject1.getDouble("num8");//长途结束公里 - Double num9 = jsonObject1.getDouble("num9");//长途费 - Double num10 = jsonObject1.getDouble("num10");//超出长途里程每num10公里 - Double num11 = jsonObject1.getDouble("num11");//超过num8每num10公里收取num11 + JSONArray num3 = jsonObject1.getJSONArray("num3");//起步里程 + Double num4 = jsonObject1.getDouble("num4");//长途里程 + Double num5 = jsonObject1.getDouble("num5");//长途里程 + Double num6 = jsonObject1.getDouble("num6");//长途费 + Double num7 = jsonObject1.getDouble("num7");//超出长途里程每num10公里 + Double num8 = jsonObject1.getDouble("num8");//超过num8每num10公里收取num11 String[] split = num1.split(":"); Calendar s = Calendar.getInstance(); @@ -262,33 +271,81 @@ e.set(Calendar.SECOND, 0); if(date.getTime() >= s.getTimeInMillis() && date.getTime() < e.getTimeInMillis()){ - if(num3.compareTo(distance) >= 0){//起步里程内 - order.setStartDistance(distance);//起步里程 - order.setStartPrice(num4);//起步价 - }else{ - BigDecimal subtract = new BigDecimal(distance).subtract(new BigDecimal(num3));//超出起步里程 - BigDecimal divide = subtract.divide(new BigDecimal(num5), new MathContext(2, RoundingMode.HALF_EVEN)); - BigDecimal multiply = divide.multiply(new BigDecimal(num6)); - order.setStartDistance(num3);//起步里程 - order.setStartPrice(num4);//起步价 - order.setOverDriveDistance(subtract.doubleValue());//超出起步里程 - order.setOverDrivePrice(multiply.doubleValue());//超出起步里程费 - + b = false; + Double dd = 0d; + for (int j = 0; j < num3.size(); j++) { + JSONObject jsonObject2 = num3.getJSONObject(j); + Double num1_1 = jsonObject2.getDouble("num1"); + Double num2_1 = jsonObject2.getDouble("num2"); + Double num3_1 = jsonObject2.getDouble("num3"); + if(num1_1.compareTo(distance) <= 0 && num2_1.compareTo(distance) > 0){ + order.setStartDistance(distance);//起步里程 + order.setStartPrice(num3_1);//起步价 + } + if(j == num3.size() - 1 && order.getStartPrice() == 0){ + order.setStartDistance(num2_1);//起步里程 + order.setStartPrice(num3_1);//起步价 + dd = distance - num2_1; + } + } + if(dd != 0){ //计算长途费 - if(distance.compareTo(num7) > 0){ - order.setLongDistance(num7 + "-" + num8);//长途里程 - order.setLongDistancePrice(num9);//长途费 + if(distance.compareTo(num4) > 0){ + order.setLongDistance(num4 + "-" + num5);//长途里程 + order.setLongDistancePrice(num6);//长途费 } //计算长途里程超出的部分 - if(distance.compareTo(num8) > 0){ - BigDecimal subtract1 = new BigDecimal(distance).subtract(new BigDecimal(num8)); - BigDecimal divide1 = subtract1.divide(new BigDecimal(num10), new MathContext(2, RoundingMode.HALF_EVEN)); - BigDecimal multiply1 = divide1.multiply(new BigDecimal(num11)); + if(distance.compareTo(num5) > 0){ + BigDecimal subtract1 = new BigDecimal(distance).subtract(new BigDecimal(num5)); + BigDecimal divide1 = subtract1.divide(new BigDecimal(num7), new MathContext(2, RoundingMode.HALF_EVEN)); + BigDecimal multiply1 = divide1.multiply(new BigDecimal(num8)); order.setOverLongDistance(subtract1.doubleValue());//超出长途里程 order.setOverLongDistancePrice(multiply1.doubleValue());//超出长途里程费 } } break; + } + } + + if(b){//默认配置 + JSONObject jsonObject1 = chargeStandard.getJSONObject(0); + JSONArray num3 = jsonObject1.getJSONArray("num3");//起步里程 + Double num4 = jsonObject1.getDouble("num4");//长途里程 + Double num5 = jsonObject1.getDouble("num5");//长途里程 + Double num6 = jsonObject1.getDouble("num6");//长途费 + Double num7 = jsonObject1.getDouble("num7");//超出长途里程每num10公里 + Double num8 = jsonObject1.getDouble("num8");//超过num8每num10公里收取num11 + + Double dd = 0d; + for (int j = 0; j < num3.size(); j++) { + JSONObject jsonObject2 = num3.getJSONObject(j); + Double num1_1 = jsonObject2.getDouble("num1"); + Double num2_1 = jsonObject2.getDouble("num2"); + Double num3_1 = jsonObject2.getDouble("num3"); + if(num1_1.compareTo(distance) <= 0 && num2_1.compareTo(distance) > 0){ + order.setStartDistance(distance);//起步里程 + order.setStartPrice(num3_1);//起步价 + } + if(j == num3.size() - 1 && order.getStartPrice() == 0){ + order.setStartDistance(num2_1);//起步里程 + order.setStartPrice(num3_1);//起步价 + dd = distance - num2_1; + } + } + if(dd != 0){ + //计算长途费 + if(distance.compareTo(num4) > 0){ + order.setLongDistance(num4 + "-" + num5);//长途里程 + order.setLongDistancePrice(num6);//长途费 + } + //计算长途里程超出的部分 + if(distance.compareTo(num5) > 0){ + BigDecimal subtract1 = new BigDecimal(distance).subtract(new BigDecimal(num5)); + BigDecimal divide1 = subtract1.divide(new BigDecimal(num7), new MathContext(2, RoundingMode.HALF_EVEN)); + BigDecimal multiply1 = divide1.multiply(new BigDecimal(num8)); + order.setOverLongDistance(subtract1.doubleValue());//超出长途里程 + order.setOverLongDistancePrice(multiply1.doubleValue());//超出长途里程费 + } } } @@ -316,7 +373,7 @@ //恶劣天气 systemConfig = systemConfigService.selectOne(new EntityWrapper<SystemConfig>().eq("type", 8)); - if(null != systemConfig) { + if(null != systemConfig){ JSONObject jsonObject1 = JSON.parseObject(systemConfig.getContent()); Integer num11 = jsonObject1.getInteger("num1");//开启恶劣天气计价 if(1 == num11){ @@ -345,11 +402,6 @@ } } - - //计算折扣 - if(null != order.getUserId()){ - - } //计算总金额 BigDecimal bigDecimal = new BigDecimal(order.getStartPrice() + order.getOverDrivePrice() + order.getLongDistancePrice() + order.getOverLongDistancePrice() + @@ -548,7 +600,7 @@ List<HallOrderList> hallOrderLists = this.baseMapper.queryOrderHall(pageNum, pageSize); hallOrderLists.forEach(hallOrderList -> { if(ToolUtil.isEmpty(hallOrderList.getAvatar())){ - hallOrderList.setAvatar("https://csxdj.obs.cn-south-1.myhuaweicloud.com:443/66cc269703a84e4da87fb21e2c21ab1f.png"); + hallOrderList.setAvatar("https://fanghuadaijia.obs.cn-southwest-2.myhuaweicloud.com:443/img%2Fc68f32a7e78e4ef1b0c018fd2c15d7a7.png"); } hallOrderList.setCurrentDistance(0D); if(ToolUtil.isNotEmpty(value)){ @@ -698,8 +750,10 @@ orderTransferService.insert(orderTransfer); } - pushUtil.pushTransferSuccessful(order.getUserId(), 1, order.getId()); pushUtil.pushTransferSuccessful(oldDriverId, 2, order.getId()); + if(null != order.getUserId()){ + pushUtil.pushTransferSuccessful(order.getUserId(), 1, order.getId()); + } } //推动订单数据 @@ -813,6 +867,7 @@ Driver driver = driverService.selectById(order.getDriverId()); driver.setServerStatus(1); driverService.updateById(driver); + accountChangeDetailService.deductionInsurance(order.getDriverId());//扣减保险费 saveIntegral(order); break; case 401: @@ -939,7 +994,7 @@ } pushOrderInfoWarpper.setWaitTime(order.getWaitTime() + w); pushOrderInfoWarpper.setState(order.getState()); - pushOrderInfoWarpper.setActualMileage(Double.valueOf(order.getActualMileage() / 1000)); + pushOrderInfoWarpper.setActualMileage(new BigDecimal(order.getActualMileage() / 1000).setScale(2, BigDecimal.ROUND_HALF_EVEN).doubleValue()); pushOrderInfoWarpper.setTravelTime(0); if(null != order.getStartTime()){ int travelTime = Double.valueOf((System.currentTimeMillis() - order.getStartTime().getTime()) / 60000).intValue(); @@ -1097,7 +1152,9 @@ driverService.updateById(driver); } - pushUtil.pushOrderStatus(order.getUserId(), 1, order.getId(), order.getStatus()); + if(null != order.getUserId()){ + pushUtil.pushOrderStatus(order.getUserId(), 1, order.getId(), order.getStatus()); + } return ResultUtil.success(); } @@ -1162,6 +1219,8 @@ order.setCouponId(coupon.getId()); order.setDiscountAmount(coupon.getCouponPreferentialAmount()); order.setPayMoney(order.getOrderMoney() - coupon.getCouponPreferentialAmount()); + }else{ + order.setPayMoney(order.getOrderMoney()); } } @@ -1173,9 +1232,6 @@ 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(); @@ -1632,6 +1688,41 @@ */ @Override public void completeCollection() { - this.baseMapper.completeCollection(); + List<Order> orders = this.selectList(new EntityWrapper<Order>().eq("state", 107).eq("status", 1).eq("payType", 3)); + for (Order order : orders) { + order.setState(108); + order.setPayTime(new Date()); + 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()); + + 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.getBalance() + driver.getBackgroundBalance() + driver.getCouponBalance() + driver.getCommission()); + accountChangeDetail.setType(1); + accountChangeDetail.setChangeType(7); + accountChangeDetail.setOrderId(order.getId()); + accountChangeDetail.setExplain("优惠券收入"); + driver.setCouponBalance(driver.getCouponBalance() + coupon.getCouponPreferentialAmount()); + accountChangeDetail.setNewData(driver.getBalance() + driver.getBackgroundBalance() + driver.getCouponBalance() + driver.getCommission()); + driverService.updateById(driver); + accountChangeDetailService.insert(accountChangeDetail); + } + } + this.updateById(order); + + try { + saveRevenue(order); + } catch (Exception e) { + e.printStackTrace(); + } + } } } -- Gitblit v1.7.1