From f72ae151cc12b219cb5f39eea3ec0ea089a6ef2a Mon Sep 17 00:00:00 2001
From: Pu Zhibing <393733352@qq.com>
Date: 星期三, 27 八月 2025 23:53:05 +0800
Subject: [PATCH] 修改bug

---
 UserQYTTravel/guns-admin/src/main/java/com/stylefeng/guns/modular/taxi/service/impl/OrderTaxiServiceImpl.java |  231 +++++++++++++++++++++++++++++++++++++--------------------
 1 files changed, 148 insertions(+), 83 deletions(-)

diff --git a/UserQYTTravel/guns-admin/src/main/java/com/stylefeng/guns/modular/taxi/service/impl/OrderTaxiServiceImpl.java b/UserQYTTravel/guns-admin/src/main/java/com/stylefeng/guns/modular/taxi/service/impl/OrderTaxiServiceImpl.java
index c486976..735aba3 100644
--- a/UserQYTTravel/guns-admin/src/main/java/com/stylefeng/guns/modular/taxi/service/impl/OrderTaxiServiceImpl.java
+++ b/UserQYTTravel/guns-admin/src/main/java/com/stylefeng/guns/modular/taxi/service/impl/OrderTaxiServiceImpl.java
@@ -440,6 +440,15 @@
 		if (null == orderTaxi) {
 			return ResultUtil.error("获取数据失败,订单信息有误");
 		}
+		if (orderTaxi.getState() == 5) {
+			return ResultUtil.error("订单已开始服务,不能取消订单");
+		}
+		if (orderTaxi.getState() == 6 || orderTaxi.getState() == 7 || orderTaxi.getState() == 8 || orderTaxi.getState() == 9) {
+			return ResultUtil.error("订单已完成,不能取消订单");
+		}
+		if (orderTaxi.getState() == 10) {
+			return ResultUtil.error("订单已被取消,不能重复操作");
+		}
 		double amount = 0;
 		OpenCity openCity = openCityService.openCity1(orderTaxi.getStartLon().toString(), orderTaxi.getStartLat().toString());
 		CancleOrder query = cancleOrderService.query(orderTaxi.getOrderType(), 2, openCity.getId());
@@ -525,23 +534,25 @@
 				}
 				this.deleteTask(id);//删除定时任务
 				
-				Driver driver1 = null;
-				Company company = null;
-				//中台修改订单状态
-				ModifyTravelItineraryRequest request = new ModifyTravelItineraryRequest();
-				request.setOrderId(orderTaxi.getTravelId());
-				request.setStatus(orderTaxi.getState());
-				if (null != orderTaxi.getDriverId()) {
-					driver1 = driverService.selectById(orderTaxi.getDriverId());
-					company = companyService.selectById(driver1.getCompanyId());
-					request.setDriverId(driver1.getEmpId().toString());
-					request.setSupplierShopId(company.getEnterCode());
+				if(ToolUtil.isNotEmpty(orderTaxi.getTravelId())){
+					Driver driver1 = null;
+					Company company = null;
+					//中台修改订单状态
+					ModifyTravelItineraryRequest request = new ModifyTravelItineraryRequest();
+					request.setOrderId(orderTaxi.getTravelId());
+					request.setStatus(orderTaxi.getState());
+					if (null != orderTaxi.getDriverId()) {
+						driver1 = driverService.selectById(orderTaxi.getDriverId());
+						company = companyService.selectById(driver1.getCompanyId());
+						request.setDriverId(driver1.getEmpId().toString());
+						request.setSupplierShopId(company.getEnterCode());
+					}
+					if (2 == orderTaxi.getPromotion()) {
+						Driver driver2 = driverService.selectById(orderTaxi.getPromotionDriverId());
+						request.setPromoterId(driver2.getEmpId().toString());
+					}
+					OrderUtil.modifyTravelItinerary(request);
 				}
-				if (2 == orderTaxi.getPromotion()) {
-					Driver driver2 = driverService.selectById(orderTaxi.getPromotionDriverId());
-					request.setPromoterId(driver2.getEmpId().toString());
-				}
-				OrderUtil.modifyTravelItinerary(request);
 				
 				new Thread(new Runnable() {
 					@Override
@@ -662,23 +673,25 @@
 				orderTaxi.setBindId("");
 				this.updateById(orderTaxi);
 				
-				Driver driver = null;
-				Company company = null;
-				//中台修改订单状态
-				ModifyTravelItineraryRequest request = new ModifyTravelItineraryRequest();
-				request.setOrderId(orderTaxi.getTravelId());
-				request.setStatus(orderTaxi.getState());
-				if (null != orderTaxi.getDriverId()) {
-					driver = driverService.selectById(orderTaxi.getDriverId());
-					company = companyService.selectById(driver.getCompanyId());
-					request.setDriverId(driver.getEmpId().toString());
-					request.setSupplierShopId(company.getEnterCode());
+				if(ToolUtil.isNotEmpty(orderTaxi.getTravelId())){
+					Driver driver = null;
+					Company company = null;
+					//中台修改订单状态
+					ModifyTravelItineraryRequest request = new ModifyTravelItineraryRequest();
+					request.setOrderId(orderTaxi.getTravelId());
+					request.setStatus(orderTaxi.getState());
+					if (null != orderTaxi.getDriverId()) {
+						driver = driverService.selectById(orderTaxi.getDriverId());
+						company = companyService.selectById(driver.getCompanyId());
+						request.setDriverId(driver.getEmpId().toString());
+						request.setSupplierShopId(company.getEnterCode());
+					}
+					if (2 == orderTaxi.getPromotion()) {
+						Driver driver1 = driverService.selectById(orderTaxi.getPromotionDriverId());
+						request.setPromoterId(driver1.getEmpId().toString());
+					}
+					OrderUtil.modifyTravelItinerary(request);
 				}
-				if (2 == orderTaxi.getPromotion()) {
-					Driver driver1 = driverService.selectById(orderTaxi.getPromotionDriverId());
-					request.setPromoterId(driver1.getEmpId().toString());
-				}
-				OrderUtil.modifyTravelItinerary(request);
 				
 				orderCancel.setState(2);
 				orderCancel.setPayType(3);
@@ -1334,6 +1347,7 @@
 			orderTaxi.setState(8);
 			orderTaxi.setPayType(3);
 			orderTaxi.setPayMoney(orderMoney);
+			orderTaxi.setPayTime(new Date());
 			
 			//处理优惠券和红包
 			if (null != userCouponRecord) {
@@ -1389,7 +1403,7 @@
 			return ResultUtil.error("订单不在待支付状态,不允许支付", "");
 		}
 		Integer uid = orderTaxi.getUserId();
-		Double orderMoney = orderTaxi.getOrderMoney();
+		Double orderMoney = (1 == orderTaxi.getAbnormal() ? orderTaxi.getOrderMoney() : orderTaxi.getResponsibilityMoney().doubleValue());
 		UserInfo userInfo = userInfoService.selectById(uid);
 		ResultUtil resultUtil = ResultUtil.success(new Object());
 		orderTaxi.setCouponMoney(0D);//初始化历史数据
@@ -1555,6 +1569,39 @@
 //			resultUtil = payMoneyUtil.weixinpay("完成订单", "", orderId + "_2_" + UUIDUtil.getRandomCode(5), orderMoney.toString(), "/base/wxPayOrderTaxi", app, userInfo.getAppletsOpenId());
 			
 			Driver driver = driverService.selectById(orderTaxi.getDriverId());
+			if(ToolUtil.isEmpty(orderTaxi.getTravelId())){
+				Company company = companyService.selectById(driver.getCompanyId());
+				//调三方订单中心创建行程单
+				CreateTravelItineraryRequest request = new CreateTravelItineraryRequest();
+				request.setOrderNo("TA" + orderTaxi.getId());
+				request.setCustomerId(userInfo.getOnconUUID());
+				request.setDriverId(driver.getEmpId().toString());
+				request.setSupplierShopId(company.getEnterCode());
+				if(orderTaxi.getPromotion() !=null && 2 == orderTaxi.getPromotion()){
+					Driver driver1 = driverService.selectById(orderTaxi.getPromotionDriverId());
+					request.setPromoterId(driver1.getEmpId().toString());
+				}
+				request.setServiceType(2);
+				String travelItinerary = OrderUtil.createTravelItinerary(request);
+				orderTaxi.setTravelId(travelItinerary);
+
+				//创建订单
+				//中台修改订单状态
+				ModifyTravelItineraryRequest request1 = new ModifyTravelItineraryRequest();
+				request1.setOrderId(orderTaxi.getTravelId());
+				request1.setStatus(orderTaxi.getState());
+				if (null != orderTaxi.getDriverId()) {
+					request1.setDriverId(driver.getEmpId().toString());
+					request1.setSupplierShopId(company.getEnterCode());
+				}
+				if (2 == orderTaxi.getPromotion()) {
+					Driver driver2 = driverService.selectById(orderTaxi.getPromotionDriverId());
+					request1.setPromoterId(driver2.getEmpId().toString());
+				}
+				OrderUtil.modifyTravelItinerary(request1);
+			}
+
+
 			if(null == orderTaxi.getIsCreated() || 0 == orderTaxi.getIsCreated()){
 				//调用中台创建订单及拉起支付接口
 				TradeOrderCreateData tradeOrderCreateData = new TradeOrderCreateData();
@@ -1585,7 +1632,7 @@
 				}
 				goodsInfo.add(goodsInfoRequest);
 				tradeOrderCreateData.setGoodsInfo(goodsInfo);
-				TradeOrderCreate tradeOrderCreate = OrderUtil.tradeOrderCreate1(tradeOrderCreateData);
+				TradeOrderCreate tradeOrderCreate = OrderUtil.tradeOrderCreate1(tradeOrderCreateData, orderTaxi.getRecoveryOrder());
 				PayInfo payInfo = tradeOrderCreate.getPayInfo();
 				if(!"000000".equals(payInfo.getRetCode())){
 					return ResultUtil.error(payInfo.getRetMsg());
@@ -1610,7 +1657,7 @@
 				}
 				goodsInfo.add(goodsInfoRequest);
 				tradePayOff1Data.setGoodsInfo(goodsInfo);
-				PayInfo payInfo = OrderUtil.tradePayOff1(tradePayOff1Data);
+				PayInfo payInfo = OrderUtil.tradePayOff1(tradePayOff1Data, orderTaxi.getRecoveryOrder());
 				if(!"000000".equals(payInfo.getRetCode())){
 					return ResultUtil.error(payInfo.getRetMsg());
 				}
@@ -1652,6 +1699,7 @@
 			orderTaxi.setState(8);
 			orderTaxi.setPayType(3);
 			orderTaxi.setPayMoney(orderMoney);
+			orderTaxi.setPayTime(new Date());
 			
 			//处理优惠券和红包
 			if (null != userCouponRecord) {
@@ -1703,6 +1751,7 @@
 			if (orderMoney == 0) {
 				return ResultUtil.error("请使用余额支付");
 			}
+			orderTaxi.setPayTime(new Date());
 			Double payMoney = orderTaxi.getOrderMoney();
 			Integer integer = paymentRecordService.saveData(1, orderTaxi.getUserId(), 1, orderId, 2, 4, orderMoney, "", 1);
 			resultUtil = appOrderController.placeAnOrder(new BigDecimal(orderMoney), 4, orderId, 9, integer);
@@ -1743,6 +1792,7 @@
 		orderTaxi.setDiscountMoney(0D);
 		orderTaxi.setPayMoney(orderTaxi.getOrderMoney());
 		orderTaxi.setState(8);
+		orderTaxi.setPayTime(new Date());
 		this.updateById(orderTaxi);
 		
 		new Thread(new Runnable() {
@@ -2091,6 +2141,7 @@
 			orderTaxi.setState(8);
 			orderTaxi.setPayType(type);
 			orderTaxi.setPayMoney(query.getAmount());
+			orderTaxi.setPayTime(new Date());
 			
 			UserInfo userInfo = userInfoService.selectById(orderTaxi.getUserId());
 			OpenCity openCity = openCityService.openCity1(orderTaxi.getStartLon().toString(), orderTaxi.getStartLat().toString());
@@ -2185,23 +2236,25 @@
 			orderTaxi.setTelX("");
 			this.updateById(orderTaxi);
 			
-			Driver driver = null;
-			Company company = null;
-			//中台修改订单状态
-			ModifyTravelItineraryRequest request = new ModifyTravelItineraryRequest();
-			request.setOrderId(orderTaxi.getTravelId());
-			request.setStatus(orderTaxi.getState());
-			if (null != orderTaxi.getDriverId()) {
-				driver = driverService.selectById(orderTaxi.getDriverId());
-				company = companyService.selectById(driver.getCompanyId());
-				request.setDriverId(driver.getEmpId().toString());
-				request.setSupplierShopId(company.getEnterCode());
+			if(ToolUtil.isNotEmpty(orderTaxi.getTravelId())){
+				Driver driver = null;
+				Company company = null;
+				//中台修改订单状态
+				ModifyTravelItineraryRequest request = new ModifyTravelItineraryRequest();
+				request.setOrderId(orderTaxi.getTravelId());
+				request.setStatus(orderTaxi.getState());
+				if (null != orderTaxi.getDriverId()) {
+					driver = driverService.selectById(orderTaxi.getDriverId());
+					company = companyService.selectById(driver.getCompanyId());
+					request.setDriverId(driver.getEmpId().toString());
+					request.setSupplierShopId(company.getEnterCode());
+				}
+				if (2 == orderTaxi.getPromotion()) {
+					Driver driver1 = driverService.selectById(orderTaxi.getPromotionDriverId());
+					request.setPromoterId(driver1.getEmpId().toString());
+				}
+				OrderUtil.modifyTravelItinerary(request);
 			}
-			if (2 == orderTaxi.getPromotion()) {
-				Driver driver1 = driverService.selectById(orderTaxi.getPromotionDriverId());
-				request.setPromoterId(driver1.getEmpId().toString());
-			}
-			OrderUtil.modifyTravelItinerary(request);
 			
 			query.setState(2);
 			query.setCode(order_id);
@@ -2256,45 +2309,57 @@
 					OpenCity openCity = openCityService.openCity1(orderTaxi.getStartLon().toString(), orderTaxi.getStartLat().toString());
 					List<PushOrder> querys = pushOrderService.querys(null, 2, openCity.getId());//获取需要推送的次数
 					//整轮派单结束,若无司机接单,系统自动增加派单5轮,若增加5轮后任无司机接单,则系统结束派单,乘客端显示无司机接单、是否再次打车
-					for (int i = 1; i <= querys.size() + 15; i++) {
-						int finalI = i;
-						PushOrder pushOrder = querys.stream().filter(s -> s.getType() == (finalI <= 3 ? finalI : 3)).findFirst().orElse(null);
-						System.out.println("pushOrder:" + pushOrder);
-						//获取空闲司机
-						List<Driver> list = driverService.queryIdleDriver(2, orderTaxi.getStartLon(), orderTaxi.getStartLat(), pushOrder.getPushDistance(), null);//所有附近空闲司机
-						if (list.size() > 0) {
-							double driverProportion = pushOrder.getDriverProportion() / 100;//推送占比计算成小数
-							int lastIndex = Double.valueOf(list.size() * driverProportion).intValue();//计算占比转成整数(下标截取)
-							lastIndex = lastIndex == 0 ? list.size() : lastIndex;
-							list = list.subList(0, lastIndex);//获取空闲司机中占比数据
-							for (Driver driver : list) {//开始进行推送
-								//查询是否在限制推单范围内
-								boolean bo = false;
-								for (Integer integer : integers) {
-									if (integer.compareTo(driver.getId()) == 0) {
-										bo = true;
-										break;
+					int num = 0;
+					for (int j = 0; j < 6; j++) {
+						Boolean push = false;
+						for (int i = 1; i <= querys.size(); i++) {
+							num++;
+							int finalI = i;
+							PushOrder pushOrder = querys.stream().filter(s -> s.getType() == (finalI <= 3 ? finalI : 3)).findFirst().orElse(null);
+							System.out.println("pushOrder:" + pushOrder);
+							//获取空闲司机
+							List<Driver> list = driverService.queryIdleDriver(2, orderTaxi.getStartLon(), orderTaxi.getStartLat(), pushOrder.getPushDistance(), null);//所有附近空闲司机
+							//随机排序
+							Collections.shuffle(list);
+							if (list.size() > 0) {
+								double driverProportion = pushOrder.getDriverProportion() / 100;//推送占比计算成小数
+								int lastIndex = Double.valueOf(list.size() * driverProportion).intValue();//计算占比转成整数(下标截取)
+								lastIndex = lastIndex == 0 ? list.size() : lastIndex;
+								list = list.subList(0, lastIndex);//获取空闲司机中占比数据
+								for (Driver driver : list) {//开始进行推送
+									//查询是否在限制推单范围内
+									boolean bo = false;
+									for (Integer integer : integers) {
+										if (integer.compareTo(driver.getId()) == 0) {
+											bo = true;
+											break;
+										}
 									}
+									if (bo) {
+										continue;
+									}
+									pushUtil.pushOrderState(2, driver.getId(), orderTaxi.getId(), 2, orderTaxi.getState(), pushOrder.getPushTime());
 								}
-								if (bo) {
-									continue;
-								}
-								pushUtil.pushOrderState(2, driver.getId(), orderTaxi.getId(), 2, orderTaxi.getState(), pushOrder.getPushTime());
+							}
+							Thread.sleep(pushOrder.getPushTime() * 1000);//设置等待时间
+							OrderPrivateCar orderTaxi1 = orderPrivateCarService.selectById(orderTaxi.getId());
+							Integer state = orderTaxi1.getState();
+							if (state != 1) {
+								push = true;
+								break;
+							}
+							if (num == 18 && state == 1) {
+								orderTaxi1.setState(10);
+								orderPrivateCarService.updateById(orderTaxi1);
+								pushUtil.pushEndPush(1, orderTaxi.getUserId(), orderTaxi.getId(), 2, 1);
+								orderIds.remove(orderTaxi.getId());
 							}
 						}
-						Thread.sleep(pushOrder.getPushTime() * 1000);//设置等待时间
-						OrderPrivateCar orderTaxi1 = orderPrivateCarService.selectById(orderTaxi.getId());
-						Integer state = orderTaxi1.getState();
-						if (state != 1) {
+						if(push){
 							break;
 						}
-						if (i == querys.size() + 15 && state == 1) {
-							orderTaxi1.setState(10);
-							orderPrivateCarService.updateById(orderTaxi1);
-							pushUtil.pushEndPush(1, orderTaxi.getUserId(), orderTaxi.getId(), 2);
-							orderIds.remove(orderTaxi.getId());
-						}
 					}
+
 				} catch (Exception e) {
 					e.printStackTrace();
 				}

--
Gitblit v1.7.1