From 4bff66cbe2f53d97766e190bdb0fbe131cadd900 Mon Sep 17 00:00:00 2001 From: Pu Zhibing <393733352@qq.com> Date: 星期五, 25 四月 2025 18:25:28 +0800 Subject: [PATCH] 修改bug --- UserIGOTravel/guns-admin/src/main/java/com/stylefeng/guns/modular/specialTrain/server/impl/OrderPrivateCarServiceImpl.java | 174 +++++++++++++++++++++++++++++++++------------------------- 1 files changed, 99 insertions(+), 75 deletions(-) diff --git a/UserIGOTravel/guns-admin/src/main/java/com/stylefeng/guns/modular/specialTrain/server/impl/OrderPrivateCarServiceImpl.java b/UserIGOTravel/guns-admin/src/main/java/com/stylefeng/guns/modular/specialTrain/server/impl/OrderPrivateCarServiceImpl.java index be291b5..bb826ae 100644 --- a/UserIGOTravel/guns-admin/src/main/java/com/stylefeng/guns/modular/specialTrain/server/impl/OrderPrivateCarServiceImpl.java +++ b/UserIGOTravel/guns-admin/src/main/java/com/stylefeng/guns/modular/specialTrain/server/impl/OrderPrivateCarServiceImpl.java @@ -1,5 +1,6 @@ package com.stylefeng.guns.modular.specialTrain.server.impl; +import cn.hutool.db.nosql.redis.RedisDS; import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSONArray; import com.alibaba.fastjson.JSONObject; @@ -59,6 +60,7 @@ import java.math.RoundingMode; import java.text.SimpleDateFormat; import java.util.*; +import java.util.concurrent.TimeUnit; import java.util.stream.Collectors; @@ -147,7 +149,7 @@ @Resource private IUserActivityRedenvelopeService userActivityRedenvelopeService; - + @Resource private RedisUtil redisUtil; @@ -244,8 +246,7 @@ if(ToolUtil.isEmpty(userInfo.getPhone())){ return ResultUtil.error(language == 1 ? "请先绑定手机号码" : language == 2 ? "Please bind your mobile phone number first." : "Veuillez d’abord vous inscrire en liant votre numéro de téléphone portable."); } - String[] split1 = placementLon.split(","); - Company company = companyCityService.query1(uid, split1[0], split1[1]); + Company company = companyCityService.query1(uid, placementLon, placementLat); if(null != userInfo && null != company){ userInfo.setCompanyId(company.getId()); userInfoService.updateById(userInfo); @@ -312,7 +313,7 @@ orderPrivateCar.setPassengers(name); orderPrivateCar.setPassengersPhone(phone); if(instead == 0 || ToolUtil.isEmpty(orderPrivateCar.getPassengers())){ - orderPrivateCar.setPassengers(userInfo.getFirstName() + "." + userInfo.getLastName()); + orderPrivateCar.setPassengers(ToolUtil.isNotEmpty(userInfo.getFirstName()) ? userInfo.getFirstName() + "." + userInfo.getLastName() : ""); orderPrivateCar.setPassengersPhone(userInfo.getPhone()); } orderPrivateCar.setState(1); @@ -375,6 +376,7 @@ orderPrivateCar.setIsReassign(1); orderPrivateCar.setIsDelete(1); orderPrivateCar.setTripId(tripId); + orderPrivateCar.setIsover(0); DistancematrixVo distancematrix1 = GoogleMapUtil.getDistancematrix(orderPrivateCar.getStartLat(), orderPrivateCar.getStartLon(), orderPrivateCar.getEndLat(), orderPrivateCar.getEndLon(), tripId); Long distance1 = distancematrix1.getDistance(); orderPrivateCar.setEstimatedMileage(new BigDecimal(distance1).divide(new BigDecimal(1000)).setScale(2, RoundingMode.HALF_EVEN).doubleValue()); @@ -573,6 +575,16 @@ CarService query1 = carServiceMapper.query(1, dr.getCarId()); orderPrivateCar.setServerCarModelId(query1.getServerCarModelId()); orderPrivateCar.setSnatchOrderTime(new Date()); + + String value = redisUtil.getValue("DRIVER" + driver.getId()); + if(ToolUtil.isNotEmpty(value)) { + String[] split = value.split(","); + DistancematrixVo distancematrix = GoogleMapUtil.getDistancematrix(orderPrivateCar.getStartLat(), orderPrivateCar.getStartLon(), Double.valueOf(split[1]), Double.valueOf(split[0]), tripId); + //超时时间 + long timeOut = System.currentTimeMillis() + (distancematrix.getDuration() * 1000); + orderPrivateCar.setEstimateArriveTime(new Date(timeOut)); + orderPrivateCar.setEstimateArriveMileage(distancematrix.getDistance()); + } dr.setState(3); driverService.updateById(dr); @@ -720,7 +732,10 @@ BaseWarpper baseWarpper = new BaseWarpper(); double amount = 0; CancleOrder query = cancleOrderService.query(orderPrivateCar.getCompanyId()); - if(null == query || null == orderPrivateCar.getDriverId() || orderPrivateCar.getState() == 11){ + if(null == query){ + return ResultUtil.error("请先添加取消规则"); + } + if(null == orderPrivateCar.getDriverId() || orderPrivateCar.getState() == 11){ baseWarpper.setAmount(amount); return ResultUtil.success(baseWarpper); } @@ -728,6 +743,10 @@ long t = object.getInteger("driverTimeout") * 60000L; //司机超时未到达起点,免费取消 if(orderPrivateCar.getOrderType() == 1){ + if(orderPrivateCar.getState() == 1 || orderPrivateCar.getState() == 11){ + baseWarpper.setAmount(0D); + return ResultUtil.success(baseWarpper); + } if(orderPrivateCar.getState() <= 3 && orderPrivateCar.getEstimateArriveTime().getTime() + t <= System.currentTimeMillis()){ baseWarpper.setAmount(amount); return ResultUtil.success(baseWarpper); @@ -812,6 +831,8 @@ if(orderPrivateCar.getState() > 5 && orderPrivateCar.getState() != 11 && orderPrivateCar.getState() != 12){ return ResultUtil.error(language == 1 ? "取消订单失败,不合法的操作" : language == 2 ? "Failed to cancel order, illegal operation." : "Échec de l’annulation de la commande, opération illégale."); } + + orderCancelService.delete(new EntityWrapper<OrderCancel>().eq("orderId", orderPrivateCar.getId()).eq("orderType", 1)); //服务中也可以取消订单,所以取消订单时需要计算订单费用 if(null == orderPrivateCar.getDriverId()){//没有接单的情况 @@ -830,7 +851,7 @@ orderTaxiService.updateById(orderTaxi); } }else{ - integer = orderCancelService.saveData(id, 1, language == 1 ? "无司机接单" : language == 2 ? "No driver to take orders" : "Pas de chauffeur pour prendre les commandes", language == 1 ? "无司机接单" : language == 2 ? "No driver to take orders" : "Pas de chauffeur pour prendre les commandes", null, null, 2, 1, uid); + integer = orderCancelService.saveData(id, 1, language == 1 ? "无司机接单" : language == 2 ? "No driver to take orders" : "Pas de chauffeur pour prendre les commandes", language == 1 ? "无司机接单" : language == 2 ? "No driver to take orders" : "Pas de chauffeur pour prendre les commandes", null, 0D, 2, 1, uid); orderPrivateCar.setState(10); this.updateById(orderPrivateCar); } @@ -838,7 +859,7 @@ BaseWarpper data = queryCancleAmount(id, language).getData(); Double amount = data.getAmount(); if(0 == amount){ - integer = orderCancelService.saveData(id, 1, reason, remark, null, null, 2, 1, uid); + integer = orderCancelService.saveData(id, 1, reason, remark, null, 0D, 2, 1, uid); if(5 == orderPrivateCar.getState()){ orderPrivateCar.setState(6); orderPrivateCar.setGetoffLon(lon); @@ -1282,11 +1303,12 @@ ResultUtil resultUtil = ResultUtil.success(""); orderPrivateCar.setCouponMoney(0D);//初始化历史数据 orderPrivateCar.setCouponId(null); - + //计算折扣 UserActivityDiscount1 query2 = userActivityDiscount1Mapper.query(orderPrivateCar.getCompanyId()); if(null != query2){ - Integer orderNum=this.selectCount(new EntityWrapper<OrderPrivateCar>().eq("userId",orderPrivateCar.getUserId()).eq("activityId",query2.getId()).last(" and to_days(getoffTime) = to_days(now())")); + Integer orderNum=this.selectCount(new EntityWrapper<OrderPrivateCar>().eq("userId",orderPrivateCar.getUserId()) + .eq("activityId",query2.getId()).last(" and to_days(getoffTime) = to_days(now())")); if(query2.getDistance()*1000>orderPrivateCar.getMileage() && query2.getOrderNum()>orderNum){ Double special = query2.getSpecial(); if(null != special){ @@ -1300,7 +1322,7 @@ } } } - + //计算优惠券 UserCouponRecord userCouponRecord = null; if(null != couponId){ @@ -1327,7 +1349,7 @@ orderPrivateCar.setCouponMoney(userCouponRecord.getMoney()); orderPrivateCar.setCouponId(couponId); } - + //计算红包 if(null != redDeduction && 1 == redDeduction && null == orderPrivateCar.getRedPacketId()){ RedEnvelopePaymentSettings redEnvelopePaymentSettings = redEnvelopePaymentSettingsService.getRedEnvelopePaymentSettings(); @@ -1340,14 +1362,14 @@ if(total > 0 && multiply1.doubleValue() > 0 && total.compareTo(multiply1.doubleValue()) >= 0){ orderPrivateCar.setRedPacketMoney(multiply1.doubleValue()); orderMoney = orderMoney.subtract(multiply1).setScale(2, RoundingMode.HALF_EVEN); - + //获取红包id JSONArray jsonArray = new JSONArray(); for (UserRedPacketRecord userRedPacketRecord : userRedPacketRecords) { JSONObject jsonObject = new JSONObject(); jsonObject.put("id", userRedPacketRecord.getId()); BigDecimal remainingAmount = new BigDecimal(userRedPacketRecord.getRemainingAmount()); - + if(multiply1.compareTo(remainingAmount) >= 0){ userRedPacketRecord.setRemainingAmount(0D); userRedPacketRecord.setEndTime(new Date()); @@ -1377,7 +1399,7 @@ jsonObject.put("id", userRedPacketRecord.getId()); jsonObject.put("money", userRedPacketRecord.getRemainingAmount()); jsonArray.add(jsonObject); - + userRedPacketRecord.setRemainingAmount(0D); userRedPacketRecord.setEndTime(new Date()); userRedPacketRecord.setState(2); @@ -1389,8 +1411,8 @@ } } } - - + + if(payType == 1){//手机支付 SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMddHHmmssSSS"); String merchantTransactionId = sdf.format(new Date()) + "1" + language + orderId; @@ -1408,14 +1430,14 @@ checkoutRequest.setSuccessRedirectUrl("https://igo.i-go.group/payMoney/pages/success.html"); checkoutRequest.setFailRedirectUrl("https://igo.i-go.group/payMoney/pages/fail.html"); resultUtil = TinggPayUtil.checkoutRequest(checkoutRequest); - + if(resultUtil.getCode()==200){ paymentRecordService.saveData(1, null, null, orderId, 1, 1, orderMoney.setScale(2, RoundingMode.HALF_EVEN).doubleValue(), null, 1);//添加预支付数据 }else{ resultUtil = ResultUtil.error(language == 1 ? "支付失败" : language == 2 ? "Payment failure" : "Paiement échoué", ""); } - + } if(payType == 2){//银行卡支付 BankCard bankCard = bankCardService.selectById(bankCardId); @@ -1435,7 +1457,7 @@ checkoutRequest.setSuccessRedirectUrl("https://igo.i-go.group/payMoney/pages/success.html"); checkoutRequest.setFailRedirectUrl("https://igo.i-go.group/payMoney/pages/fail.html"); resultUtil = TinggPayUtil.checkoutRequest(checkoutRequest); - + if(resultUtil.getCode()==200){ paymentRecordService.saveData(1, null, null, orderId, 1, 2, orderMoney.setScale(2, RoundingMode.HALF_EVEN).doubleValue(), null, 1);//添加预支付数据 @@ -1447,28 +1469,28 @@ if(userInfo.getBalance() == null || new BigDecimal(userInfo.getBalance()).compareTo(orderMoney) < 0){ return ResultUtil.error(language == 1 ? "账户余额不足" : language == 2 ? "Insufficient balance" : "Solde insuffisant", ""); } - + userInfo.setBalance(new BigDecimal(userInfo.getBalance()).subtract(orderMoney).setScale(2, BigDecimal.ROUND_HALF_EVEN).doubleValue()); - + SysIntegral query1 = sysIntegralMapper.query(orderPrivateCar.getCompanyId()); userInfo.setIntegral(userInfo.getIntegral() + (orderMoney.intValue() * query1.getIntegral()));//积分 - + //添加交易明细 transactionDetailsService.saveData(uid, "完成订单", orderMoney.setScale(2, RoundingMode.HALF_EVEN).doubleValue(), 2, 1, 1, 1, orderId); userInfoService.updateById(userInfo); - + orderPrivateCar.setState(8); orderPrivateCar.setPayType(3); orderPrivateCar.setPayMoney(orderMoney.setScale(2, RoundingMode.HALF_EVEN).doubleValue()); - + //处理优惠券和红包 if(null != userCouponRecord){ userCouponRecord.setState(2); userCouponRecord.setEndTime(new Date()); userCouponRecordService.updateById(userCouponRecord); } - + //添加已收入明细 Company company = companyService.selectById(orderPrivateCar.getCompanyId()); Double speMoney = company.getSpeMoney(); @@ -1490,7 +1512,7 @@ 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); - + if(ToolUtil.isNotEmpty(userInfo.getEmail())){ new Thread(new Runnable() { @Override @@ -1830,7 +1852,7 @@ server_tel_french.attr("href", "tel:" + (null != phone ? phone.getPhone() : "")); } EmailUtil.send(userInfo.getEmail(), language == 1 ? "打车收据" : language == 2 ? "Ride receipt" : "Reçu de course", document.html()); - + //开始生成pdf收据和html收据 File file = new File("/home/igotechgh/nginx/html/files/html/"); if(!file.exists()){ @@ -1844,7 +1866,7 @@ fileWriter.write(document.html()); fileWriter.flush(); fileWriter.close(); - + File file1 = new File("/home/igotechgh/nginx/html/files/pdf/"); if(!file1.exists()){ file1.mkdirs(); @@ -1860,7 +1882,7 @@ e.printStackTrace(); System.out.println("html转pdf异常"); } - + String link ="https://igo.i-go.group/files/html/ride_receipt_" + orderId + ".html"; TEmail tEmail = new TEmail(); tEmail.setLink(link); @@ -1878,18 +1900,18 @@ tEmail.setAmOrPm(language==1?"下午":language==2?"afternoon":"après-midi"); } emailService.insert(tEmail); - - - + + + }catch (Exception e){ e.printStackTrace(); } } }).start(); } - - - + + + // TODO: 2020/5/24 这里需要给司机和用户推送订单状态 new Thread(new Runnable() { @Override @@ -1898,7 +1920,7 @@ pushUtil.pushOrderState(2, orderPrivateCar.getDriverId(), orderPrivateCar.getId(), 1, orderPrivateCar.getState(), 0, ""); } }).start(); - + systemNoticeService.addSystemNotice(1, language == 1 ? "您已成功完成出行订单支付,谢谢使用!" : language == 2 ? "You've paid for the ride order successfully, thank you for using I-GO" : "Vous avez payé la commande de course avec succès, merci d’utiliser I-GO", orderPrivateCar.getUserId(), 1); @@ -1906,19 +1928,19 @@ if(payType == 4){//现金支付 SysIntegral query1 = sysIntegralMapper.query(orderPrivateCar.getCompanyId()); userInfo.setIntegral(userInfo.getIntegral() + (orderMoney.intValue() * query1.getIntegral()));//积分 - + //添加交易明细 transactionDetailsService.saveData(uid, "完成订单", orderMoney.setScale(2, RoundingMode.HALF_EVEN).doubleValue(), 2, 1, 1, 1, orderId); userInfoService.updateById(userInfo); - + orderPrivateCar.setState(8); orderPrivateCar.setPayType(4); orderPrivateCar.setDriverPay(2); orderPrivateCar.setPayMoney(orderMoney.setScale(2, RoundingMode.HALF_EVEN).doubleValue()); - + Driver driver = driverService.selectById(orderPrivateCar.getDriverId()); - + //处理优惠券和红包 if(null != userCouponRecord){ userCouponRecord.setState(2); @@ -1932,7 +1954,7 @@ driver.setBalance(new BigDecimal(null != driver.getBalance() ? driver.getBalance() : 0).add(new BigDecimal(money)).setScale(2, BigDecimal.ROUND_HALF_EVEN).doubleValue()); driverService.updateById(driver); } - + if(null != orderPrivateCar.getRedPacketId()){ Double money = orderPrivateCar.getRedPacketMoney(); incomeService.saveData(2, orderPrivateCar.getDriverId(), 7, orderPrivateCar.getId(), 1, money); @@ -1941,7 +1963,7 @@ driver.setBalance(new BigDecimal(null != driver.getBalance() ? driver.getBalance() : 0).add(new BigDecimal(money)).setScale(2, BigDecimal.ROUND_HALF_EVEN).doubleValue()); driverService.updateById(driver); } - + if(null != orderPrivateCar.getDiscountMoney() && 0 < orderPrivateCar.getDiscountMoney()){ Double money = orderPrivateCar.getDiscountMoney(); incomeService.saveData(2, orderPrivateCar.getDriverId(), 6, orderPrivateCar.getId(), 1, money); @@ -1950,8 +1972,8 @@ driver.setBalance(new BigDecimal(null != driver.getBalance() ? driver.getBalance() : 0).add(new BigDecimal(money)).setScale(2, BigDecimal.ROUND_HALF_EVEN).doubleValue()); driverService.updateById(driver); } - - + + //添加已收入明细 Company company = companyService.selectById(orderPrivateCar.getCompanyId()); Double speMoney = company.getSpeMoney(); @@ -1973,8 +1995,8 @@ // 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); - - + + //记录司机待结算金额 if(d.compareTo(new BigDecimal(0)) > 0){ SettlementDetail settlementDetail = new SettlementDetail(); @@ -1985,7 +2007,7 @@ 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()); @@ -2033,7 +2055,7 @@ car.setVehicleId(UUIDUtil.getRandomCode()); carService.updateById(car); } - + //司机下班,修改谷歌上的车辆信息 new Thread(()->{ try { @@ -2081,7 +2103,7 @@ } } } - + if(ToolUtil.isNotEmpty(userInfo.getEmail())){ new Thread(new Runnable() { @Override @@ -2420,9 +2442,9 @@ Element server_tel_french = document.getElementById("server_tel_french"); server_tel_french.attr("href", "tel:" + (null != phone ? phone.getPhone() : "")); } - + EmailUtil.send(userInfo.getEmail(), language == 1 ? "打车收据" : language == 2 ? "Ride receipt" : "Reçu de course", document.html()); - + //开始生成pdf收据和html收据 File file = new File("/home/igotechgh/nginx/html/files/html/"); if(!file.exists()){ @@ -2436,7 +2458,7 @@ fileWriter.write(document.html()); fileWriter.flush(); fileWriter.close(); - + File file1 = new File("/home/igotechgh/nginx/html/files/pdf/"); if(!file1.exists()){ file1.mkdirs(); @@ -2469,17 +2491,17 @@ tEmail.setAmOrPm(language==1?"下午":language==2?"afternoon":"après-midi"); } emailService.insert(tEmail); - - + + }catch (Exception e){ e.printStackTrace(); } } }).start(); } - - - + + + // TODO: 2020/5/24 这里需要给司机和用户推送订单状态 new Thread(new Runnable() { @Override @@ -2498,7 +2520,7 @@ case 3: text = "Le client a choisi de payer en espèces, vous devez donc encaisser le paiement.Confirmez si vous avez reçu les frais pour cette commande : Espèces GHS " + orderPrivateCar.getPayMoney(); break; - + } String audioUrl = ""; String fileName = "offlinePayment" + orderPrivateCar.getDriverId() + UUIDUtil.getRandomCode(5) + ".mp3"; @@ -2532,12 +2554,12 @@ pushUtil.pushOfflinePayment(2, orderPrivateCar.getDriverId(), orderPrivateCar.getId(), 1, orderPrivateCar.getPayMoney(), audioUrl); } }).start(); - + systemNoticeService.addSystemNotice(1, language == 1 ? "您已成功完成出行订单支付,谢谢使用!" : language == 2 ? "You've paid for the ride order successfully, thank you for using I-GO" : "Vous avez payé la commande de course avec succès, merci d’utiliser I-GO", orderPrivateCar.getUserId(), 1); } - + this.updateAllColumnById(orderPrivateCar); return resultUtil; } @@ -3359,21 +3381,23 @@ Integer driverTimeOutTime = 0; Integer driverTimeOut = 0; CancleOrder cancleOrder = cancleOrderService.selectOne(new EntityWrapper<CancleOrder>().eq("companyId", companyId)); - JSONObject jsonObject = JSON.parseObject(cancleOrder.getContent()); - int driverTimeout1 = jsonObject.getIntValue("driverTimeout"); - if(orderPrivateCar.getOrderType() == 1 && null != orderPrivateCar.getEstimateArriveTime()){ - long time = orderPrivateCar.getEstimateArriveTime().getTime() + driverTimeout1 * 60000L; - if(System.currentTimeMillis() > time){ - driverTimeOutTime = Double.valueOf((System.currentTimeMillis() - time) / 60000).intValue(); - driverTimeOutTime = driverTimeOutTime == 0 ? 1 : driverTimeOutTime; - driverTimeOut = 1; - } - }else{ - long time = orderPrivateCar.getTravelTime().getTime() + driverTimeout1 * 60000L; - if(System.currentTimeMillis() >= time){ - driverTimeOutTime = Double.valueOf((System.currentTimeMillis() - time) / 60000).intValue(); - driverTimeOutTime = driverTimeOutTime == 0 ? 1 : driverTimeOutTime; - driverTimeOut = 1; + if(null != cancleOrder){ + JSONObject jsonObject = JSON.parseObject(cancleOrder.getContent()); + int driverTimeout1 = jsonObject.getIntValue("driverTimeout"); + if(orderPrivateCar.getOrderType() == 1 && null != orderPrivateCar.getEstimateArriveTime()){ + long time = orderPrivateCar.getEstimateArriveTime().getTime() + driverTimeout1 * 60000L; + if(System.currentTimeMillis() > time){ + driverTimeOutTime = Double.valueOf((System.currentTimeMillis() - time) / 60000).intValue(); + driverTimeOutTime = driverTimeOutTime == 0 ? 1 : driverTimeOutTime; + driverTimeOut = 1; + } + }else{ + long time = orderPrivateCar.getTravelTime().getTime() + driverTimeout1 * 60000L; + if(System.currentTimeMillis() >= time){ + driverTimeOutTime = Double.valueOf((System.currentTimeMillis() - time) / 60000).intValue(); + driverTimeOutTime = driverTimeOutTime == 0 ? 1 : driverTimeOutTime; + driverTimeOut = 1; + } } } -- Gitblit v1.7.1