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/specialTrain/server/impl/OrderPrivateCarServiceImpl.java |  449 ++++++++++++++++++++++++++++++++++++++++++++-----------
 1 files changed, 357 insertions(+), 92 deletions(-)

diff --git a/UserQYTTravel/guns-admin/src/main/java/com/stylefeng/guns/modular/specialTrain/server/impl/OrderPrivateCarServiceImpl.java b/UserQYTTravel/guns-admin/src/main/java/com/stylefeng/guns/modular/specialTrain/server/impl/OrderPrivateCarServiceImpl.java
index 4e068a8..47cd81d 100644
--- a/UserQYTTravel/guns-admin/src/main/java/com/stylefeng/guns/modular/specialTrain/server/impl/OrderPrivateCarServiceImpl.java
+++ b/UserQYTTravel/guns-admin/src/main/java/com/stylefeng/guns/modular/specialTrain/server/impl/OrderPrivateCarServiceImpl.java
@@ -11,7 +11,6 @@
 import com.stylefeng.guns.modular.crossCity.model.OrderCrossCity;
 import com.stylefeng.guns.modular.crossCity.server.IOrderCrossCityService;
 import com.stylefeng.guns.modular.crossCity.server.impl.OrderCrossCityServiceImpl;
-import com.stylefeng.guns.modular.smallLogistics.server.IOrderLogisticsService;
 import com.stylefeng.guns.modular.specialTrain.dao.OrderPrivateCarMapper;
 import com.stylefeng.guns.modular.specialTrain.model.OrderPrivateCar;
 import com.stylefeng.guns.modular.specialTrain.server.IOrderPrivateCarService;
@@ -20,6 +19,8 @@
 import com.stylefeng.guns.modular.system.model.vo.UnPayOrderVO;
 import com.stylefeng.guns.modular.system.service.*;
 import com.stylefeng.guns.modular.system.util.*;
+import com.stylefeng.guns.modular.system.util.qianyuntong.OrderUtil;
+import com.stylefeng.guns.modular.system.util.qianyuntong.model.*;
 import com.stylefeng.guns.modular.system.warpper.*;
 import com.stylefeng.guns.modular.taxi.dao.OrderTaxiMapper;
 import com.stylefeng.guns.modular.taxi.model.OrderTaxi;
@@ -43,10 +44,13 @@
 
 import javax.annotation.Resource;
 import java.math.BigDecimal;
+import java.math.BigInteger;
 import java.math.MathContext;
 import java.math.RoundingMode;
 import java.text.SimpleDateFormat;
 import java.util.*;
+import java.util.concurrent.LinkedBlockingQueue;
+import java.util.concurrent.ThreadPoolExecutor;
 import java.util.concurrent.TimeUnit;
 import java.util.concurrent.locks.Lock;
 import java.util.concurrent.locks.ReentrantLock;
@@ -394,7 +398,7 @@
 								JSONObject jsonObject = JSONObject.parseObject(spellOrderRule.getContent());
 								//判断时间
 								if (travelTime.getTime() >= order.getTravelTime().getTime() - jsonObject.getInteger("num5") * 60000L && travelTime.getTime() <= order.getTravelTime().getTime() + jsonObject.getInteger("num6") * 60000L) {
-									String value = (String) redisTemplate.opsForValue().get("DRIVER" + String.valueOf(order.getDriverId()));
+									String value = (String) redisTemplate.opsForValue().get("dache:DRIVER" + String.valueOf(order.getDriverId()));
 									//                            Double dis1 = Double.valueOf(gdMapElectricFenceUtil.getDistance(orderPrivateCar.getStartLon() + "," + orderPrivateCar.getStartLat(), value, 1).get("distance").toString());
 									//                            Double dis2 = Double.valueOf(gdMapElectricFenceUtil.getDistance(orderPrivateCar.getEndLon() + "," + orderPrivateCar.getEndLat(), order.getEndLon() + "," + order.getEndLat(), 1).get("distance").toString());
 									
@@ -581,8 +585,9 @@
 				Map<String, String> distanceMap = gdMapElectricFenceUtil.getDistance(orderPrivateCar.getStartLon() + "," + orderPrivateCar.getStartLat(), orderPrivateCar.getEndLon() + "," + orderPrivateCar.getEndLat(), 1);
 				orderPrivateCar.setEstimateMileage(Double.valueOf(distanceMap.get("distance")));
 				orderPrivateCar.setEstimateTime(Double.valueOf(distanceMap.get("duration")) / 60);
+				UserInfo userInfo = userInfoService.selectById(uid);
 				if (instead == 0 || ToolUtil.isEmpty(orderPrivateCar.getPassengers())) {
-					UserInfo userInfo = userInfoService.selectById(uid);
+
 					if (ToolUtil.isEmpty(userInfo.getPhone())) {
 						return ResultUtil.error("请先绑定手机号码");
 					}
@@ -598,21 +603,11 @@
 				orderPrivateCar.setIsReassign(1);
 				orderPrivateCar.setIsDelete(1);
 
-				// 是否推广订单
-				Integer promotion = isPromotion(uid);
-				if(promotion!=null){
-					orderPrivateCar.setPromotion(2);
-					Driver driver = driverService.selectById(promotion);
-					orderPrivateCar.setPromotionUser(driver.getName());
-					orderPrivateCar.setPromotionPhone(driver.getPhone());
-					orderPrivateCar.setPromotionDriverId(promotion);
-				}
-
-
-				this.insert(orderPrivateCar);
-				
 				//判断独享,一口价,拼车
 				JSONArray jsonArray = JSON.parseArray(serverCarModel);
+				this.insert(orderPrivateCar);
+
+
 				for (int i = 0; i < jsonArray.size(); i++) {
 					JSONObject jsonObject1 = jsonArray.getJSONObject(i);
 					Integer serverCarModelId = jsonObject1.getInteger("serverCarModelId");
@@ -633,14 +628,13 @@
 					} else {
 						OrderPrivateCar orderPrivateCar1 = null;
 						OpenCity openCity = openCityService.openCity1(orderPrivateCar.getStartLon().toString(), orderPrivateCar.getStartLat().toString());
+						TbSpellOrderRule spellOrderRule = spellOrderRuleService.selectOne(new EntityWrapper<TbSpellOrderRule>().eq("openCityId", openCity.getId()));
 						//判断是否有相同线路的拼车-有直接拼成功,或者推送拼车订单
 						List<OrderPrivateCar> orderList = orderPrivateCarMapper.selectList(new EntityWrapper<OrderPrivateCar>().eq("rideType", 3).in("state", "2,3,4").le("totalPeopleNum", 4 - peopleNum));
 						for (OrderPrivateCar order : orderList) {
-							TbSpellOrderRule spellOrderRule = spellOrderRuleService.selectOne(new EntityWrapper<TbSpellOrderRule>().eq("openCityId", openCity.getId()));
 							if (spellOrderRule != null) {
 								JSONObject jsonObject = JSONObject.parseObject(spellOrderRule.getContent());
 								//判断时间
-								
 								if (travelTime.getTime() >= order.getTravelTime().getTime() - jsonObject.getInteger("num5") * 60000L && travelTime.getTime() <= order.getTravelTime().getTime() + jsonObject.getInteger("num6") * 60000L) {
 									//                        Double dis1 = Double.valueOf(gdMapElectricFenceUtil.getDistance(orderPrivateCar.getStartLon() + "," + orderPrivateCar.getStartLat(), order.getStartLon() + "," + order.getStartLat(), 1).get("distance").toString());
 									//                        Double dis2 = Double.valueOf(gdMapElectricFenceUtil.getDistance(orderPrivateCar.getEndLon() + "," + orderPrivateCar.getEndLat(), order.getEndLon() + "," + order.getEndLat(), 1).get("distance").toString());
@@ -658,12 +652,11 @@
 						if (orderPrivateCar1 == null) {
 							orderList = orderPrivateCarMapper.selectList(new EntityWrapper<OrderPrivateCar>().eq("rideType", 3).eq("state", 5).le("totalPeopleNum", 4 - peopleNum));
 							for (OrderPrivateCar order : orderList) {
-								TbSpellOrderRule spellOrderRule = spellOrderRuleService.selectOne(new EntityWrapper<TbSpellOrderRule>().eq("openCityId", openCity.getId()));
 								if (spellOrderRule != null) {
 									JSONObject jsonObject = JSONObject.parseObject(spellOrderRule.getContent());
 									//判断时间
 									if (travelTime.getTime() >= order.getTravelTime().getTime() - jsonObject.getInteger("num5") * 60000L && travelTime.getTime() <= order.getTravelTime().getTime() + jsonObject.getInteger("num6") * 60000L) {
-										String value = (String) redisTemplate.opsForValue().get("DRIVER" + String.valueOf(order.getDriverId()));
+										String value = (String) redisTemplate.opsForValue().get("dache:DRIVER" + String.valueOf(order.getDriverId()));
 										//                            Double dis1 = Double.valueOf(gdMapElectricFenceUtil.getDistance(orderPrivateCar.getStartLon() + "," + orderPrivateCar.getStartLat(), value, 1).get("distance").toString());
 										//                            Double dis2 = Double.valueOf(gdMapElectricFenceUtil.getDistance(orderPrivateCar.getEndLon() + "," + orderPrivateCar.getEndLat(), order.getEndLon() + "," + order.getEndLat(), 1).get("distance").toString());
 										
@@ -697,7 +690,32 @@
 							orderPrivateCar.setIsReassign(1);
 							orderPrivateCar.setIsDelete(1);
 							orderPrivateCar.setPid(orderPrivateCar1.getPid() == null ? orderPrivateCar1.getId() : orderPrivateCar1.getPid());
+
+							Integer promotion1 = isPromotion(orderPrivateCar.getUserId(), driver.getPlaceOfEmployment());
+							if(promotion1!=null){
+								orderPrivateCar.setPromotion(2);
+								Driver driver1 = driverService.selectById(promotion1);
+								orderPrivateCar.setPromotionUser(driver1.getName());
+								orderPrivateCar.setPromotionPhone(driver1.getPhone());
+								orderPrivateCar.setPromotionDriverId(promotion1);
+							}
+
+							Company company = companyService.selectById(driver.getCompanyId());
+							//调三方订单中心创建行程单
+							CreateTravelItineraryRequest request = new CreateTravelItineraryRequest();
+							request.setOrderNo("PR" + orderPrivateCar.getId());
+							request.setCustomerId(userInfo.getOnconUUID());
+							request.setDriverId(driver.getEmpId().toString());
+							request.setSupplierShopId(company.getEnterCode());
+							if(orderPrivateCar.getPromotion() !=null && 2 == orderPrivateCar.getPromotion()){
+								Driver driver1 = driverService.selectById(orderPrivateCar.getPromotionDriverId());
+								request.setPromoterId(driver1.getEmpId().toString());
+							}
+							request.setServiceType(2);
+							String travelItinerary = OrderUtil.createTravelItinerary(request);
+							orderPrivateCar.setTravelId(travelItinerary);
 							this.insertOrUpdate(orderPrivateCar);
+
 							//修改总订单人数
 							OrderPrivateCar orderPrivateCar2 = new OrderPrivateCar();
 							orderPrivateCar2.setSpellSuccess(1);
@@ -732,7 +750,6 @@
 				
 				//添加消息
 				systemNoticeService.addSystemNotice(1, "您的快车订单已下单成功,我们正在为您指派司机,请稍后!", orderPrivateCar.getUserId(), 1);
-				
 				baseWarpper.setId(orderPrivateCar.getId());
 			} catch (Exception e) {
 				e.printStackTrace();
@@ -746,11 +763,11 @@
 	}
 
 
-	private Integer isPromotion(Integer userId){
+	private Integer isPromotion(Integer userId, String code){
 		UserInfo userInfo = userInfoService.selectById(userId);
-		if(userInfo.getBindDriverId()!=null && userInfo.getBindExpireDate().getTime()<=System.currentTimeMillis()){
-			String registAreaCode = userInfo.getRegistAreaCode();
-			TDriverPromotionActivity tDriverPromotionActivity = driverPromotionActivityService.selectOne(new EntityWrapper<TDriverPromotionActivity>().eq("districtCode", registAreaCode).ge("startTime", new Date()).lt("endTime", new Date()).last("AND FIND_IN_SET(" + 1 + ", bizType) limit 1"));
+		if(userInfo.getBindDriverId()!=null && userInfo.getBindExpireDate().getTime()>=System.currentTimeMillis()){
+			TDriverPromotionActivity tDriverPromotionActivity = driverPromotionActivityService.selectOne(new EntityWrapper<TDriverPromotionActivity>().eq("districtCode", code)
+					.eq("state",1).le("startTime", new Date()).ge("endTime", new Date()).last("AND FIND_IN_SET(" + 1 + ", bizType) limit 1"));
 			if(tDriverPromotionActivity!=null){
 				return userInfo.getBindDriverId();
 			}
@@ -839,7 +856,7 @@
 							JSONObject jsonObject = JSONObject.parseObject(spellOrderRule.getContent());
 							//判断时间
 							if (orderPrivateCar.getTravelTime().getTime() >= order.getTravelTime().getTime() - jsonObject.getInteger("num5") * 60000L && orderPrivateCar.getTravelTime().getTime() <= order.getTravelTime().getTime() + jsonObject.getInteger("num6") * 60000L) {
-								String value = (String) redisTemplate.opsForValue().get("DRIVER" + String.valueOf(order.getDriverId()));
+								String value = (String) redisTemplate.opsForValue().get("dache:DRIVER" + String.valueOf(order.getDriverId()));
 //                                Double dis1 = Double.valueOf(gdMapElectricFenceUtil.getDistance(orderPrivateCar.getStartLon() + "," + orderPrivateCar.getStartLat(), value, 1).get("distance").toString());
 //                                Double dis2 = Double.valueOf(gdMapElectricFenceUtil.getDistance(orderPrivateCar.getEndLon() + "," + orderPrivateCar.getEndLat(), order.getEndLon() + "," + order.getEndLat(), 1).get("distance").toString());
 								// TODO: 2023/11/4 已改成计算直线距离
@@ -911,6 +928,15 @@
 		if (null == orderPrivateCar) {
 			return ResultUtil.error("获取数据失败,订单信息有误");
 		}
+		if (orderPrivateCar.getState() == 5) {
+			return ResultUtil.error("订单已开始服务,不能取消订单");
+		}
+		if (orderPrivateCar.getState() == 6 || orderPrivateCar.getState() == 7 || orderPrivateCar.getState() == 8 || orderPrivateCar.getState() == 9) {
+			return ResultUtil.error("订单已完成,不能取消订单");
+		}
+		if (orderPrivateCar.getState() == 10) {
+			return ResultUtil.error("订单已被取消,不能重复操作");
+		}
 		OpenCity openCity = openCityService.openCity1(orderPrivateCar.getStartLon().toString(), orderPrivateCar.getStartLat().toString());
 		double amount = 0;
 		CancleOrder query = cancleOrderService.query(orderPrivateCar.getOrderType(), 1, openCity.getId());
@@ -945,7 +971,7 @@
 //            return ResultUtil.error("司机已到达预约点,取消会产生一定的费用");
 //        }
 		if (orderPrivateCar.getState() >= 5 && orderPrivateCar.getState() != 11) {
-			return ResultUtil.error("取消订单失败,不合法的操作");
+			return ResultUtil.error("订单已取消,请刷新页面");
 		}
 		Integer number1 = this.selectCount(new EntityWrapper<OrderPrivateCar>().eq("pid", orderPrivateCar.getPid() == null ? orderPrivateCar.getId() : orderPrivateCar.getPid()).lt("state", 6));
 		Integer number2 = this.selectCount(new EntityWrapper<OrderPrivateCar>().eq("id", orderPrivateCar.getPid() == null ? orderPrivateCar.getId() : orderPrivateCar.getPid()).lt("state", 6));
@@ -997,6 +1023,26 @@
 					this.updateById(orderPrivateCar);
 				}
 				this.deleteTask(id);//删除定时任务
+				
+				if(ToolUtil.isNotEmpty(orderPrivateCar.getTravelId())){
+					Driver driver1 = null;
+					Company company = null;
+					//中台修改订单状态
+					ModifyTravelItineraryRequest request = new ModifyTravelItineraryRequest();
+					request.setOrderId(orderPrivateCar.getTravelId());
+					request.setStatus(orderPrivateCar.getState());
+					if (null != orderPrivateCar.getDriverId()) {
+						driver1 = driverService.selectById(orderPrivateCar.getDriverId());
+						company = companyService.selectById(driver1.getCompanyId());
+						request.setDriverId(driver1.getEmpId().toString());
+						request.setSupplierShopId(company.getEnterCode());
+					}
+					if (2 == orderPrivateCar.getPromotion()) {
+						Driver driver2 = driverService.selectById(orderPrivateCar.getPromotionDriverId());
+						request.setPromoterId(driver2.getEmpId().toString());
+					}
+					OrderUtil.modifyTravelItinerary(request);
+				}
 				
 				new Thread(new Runnable() {
 					@Override
@@ -1059,7 +1105,7 @@
 			return ResultUtil.error("取消订单失败,订单信息有误", "");
 		}
 		if (orderPrivateCar.getState() != 12) {
-			return ResultUtil.error("取消订单失败,不合法的操作", "");
+			return ResultUtil.error("订单已取消,请刷新页面", "");
 		}
 		OrderCancel orderCancel = null;
 		if (null == cancleId) {
@@ -1115,6 +1161,26 @@
 				orderPrivateCar.setBindId("");
 				this.updateById(orderPrivateCar);
 				
+				if(ToolUtil.isNotEmpty(orderPrivateCar.getTravelId())){
+					Driver driver = null;
+					Company company = null;
+					//中台修改订单状态
+					ModifyTravelItineraryRequest request = new ModifyTravelItineraryRequest();
+					request.setOrderId(orderPrivateCar.getTravelId());
+					request.setStatus(orderPrivateCar.getState());
+					if (null != orderPrivateCar.getDriverId()) {
+						driver = driverService.selectById(orderPrivateCar.getDriverId());
+						company = companyService.selectById(driver.getCompanyId());
+						request.setDriverId(driver.getEmpId().toString());
+						request.setSupplierShopId(company.getEnterCode());
+					}
+					if (2 == orderPrivateCar.getPromotion()) {
+						Driver driver1 = driverService.selectById(orderPrivateCar.getPromotionDriverId());
+						request.setPromoterId(driver1.getEmpId().toString());
+					}
+					OrderUtil.modifyTravelItinerary(request);
+				}
+				
 				orderCancel.setState(2);
 				orderCancel.setPayType(3);
 				orderCancelService.updateById(orderCancel);
@@ -1157,14 +1223,10 @@
 		if(Integer.valueOf(String.valueOf(map.get("state"))) == 11){
 			map.put("state", map.get("oldState"));
 		}
-		if(Integer.valueOf(String.valueOf(map.get("state"))) ==7 &&  (map.get("responsibilityType")==null || Integer.valueOf(String.valueOf(map.get("responsibilityType")))<4)){
-			map.put("appealButton", 1);
-		}
 		if(map.get("abnormalIntro")!=null){
 			map.put("appealStatus", 1);
 		}
-		
-		
+
 		if(Integer.valueOf(String.valueOf(map.get("state"))) != 8 && Integer.valueOf(String.valueOf(map.get("state"))) != 9){
 			map.put("redPacketMoney", null);
 			map.put("couponMoney", null);
@@ -1189,7 +1251,7 @@
 			return orderTaxiService.queryOrderServer(orderId, uid);
 		}
 		//计算预计距离和剩余时间
-		String value = (String) redisTemplate.opsForValue().get("DRIVER" + String.valueOf(orderPrivateCar.getDriverId()));
+		String value = (String) redisTemplate.opsForValue().get("dache:DRIVER" + String.valueOf(orderPrivateCar.getDriverId()));
 		if(null == value || "".equals(value)){
 			System.err.println("司机没有上传位置信息");
 			
@@ -1864,6 +1926,7 @@
 			orderPrivateCar.setState(8);
 			orderPrivateCar.setPayType(3);
 			orderPrivateCar.setPayMoney(orderMoney);
+			orderPrivateCar.setPayTime(new Date());
 			
 			//处理优惠券和红包
 			if (null != userCouponRecord) {
@@ -1876,9 +1939,13 @@
 				query.setEndTime(new Date());
 				userRedPacketRecordService.updateById(query);
 			}
-			//添加收入
-			Map<String, Object> map = incomeService.saveIncome(orderPrivateCar.getId(), 1, orderPrivateCar.getOrderMoney());
-			orderPrivateCar.setSplitAllocation(JSON.toJSONString(map));
+			//非追缴单才需要添加收入
+			if(0 == orderPrivateCar.getRecoveryOrder()){
+				//添加收入
+				Double orderMoney1 = (1 == orderPrivateCar.getAbnormal() ? orderPrivateCar.getOrderMoney() : orderPrivateCar.getResponsibilityMoney().doubleValue());
+				Map<String, Object> map = incomeService.saveIncome(orderPrivateCar.getId(), 1, orderMoney1);
+				orderPrivateCar.setSplitAllocation(JSON.toJSONString(map));
+			}
 			
 			// TODO: 2020/5/24 这里需要给司机和用户推送订单状态
 			new Thread(new Runnable() {
@@ -1907,8 +1974,7 @@
 	
 	@Override
 	@Transactional(propagation = Propagation.REQUIRES_NEW)
-	public ResultUtil payPrivateCarOrder1(Integer payType, Integer orderId, Integer objectId, Integer objectType, Integer type) throws Exception {
-		
+	public ResultUtil payPrivateCarOrder1(Integer payType, Integer orderId, Integer objectId, Integer objectType, Integer type, String path, String ip) throws Exception {
 		OrderPrivateCar orderPrivateCar = this.selectById(orderId);
 		if (orderPrivateCar.getState() == 8 || orderPrivateCar.getState() == 9) {
 			return ResultUtil.error("订单已完成支付,不允许重复支付", new ArrayList<>());
@@ -1917,7 +1983,7 @@
 			return ResultUtil.error("订单不在待支付状态,不允许支付", new ArrayList<>());
 		}
 		Integer uid = orderPrivateCar.getUserId();
-		Double orderMoney = orderPrivateCar.getOrderMoney();
+		Double orderMoney = (1 == orderPrivateCar.getAbnormal() ? orderPrivateCar.getOrderMoney() : orderPrivateCar.getResponsibilityMoney().doubleValue());
 		UserInfo userInfo = userInfoService.selectById(uid);
 		ResultUtil resultUtil = ResultUtil.success(new Object());
 		orderPrivateCar.setCouponMoney(0D);//初始化历史数据
@@ -1927,7 +1993,7 @@
 		UserCouponRecord userCouponRecord = null;
 		if (null != objectId && objectType == 1) {
 			userCouponRecord = userCouponRecordService.selectById(objectId);
-			if (userCouponRecord.getCompanyId() != orderPrivateCar.getCompanyId()) {
+			if (userCouponRecord.getCompanyId().compareTo(orderPrivateCar.getCompanyId()) != 0) {
 				return ResultUtil.error("优惠券不能用于此订单", new ArrayList<>());
 			}
 			if (userCouponRecord.getState() == 2) {
@@ -2080,13 +2146,148 @@
 		orderMoney = new BigDecimal(orderMoney).setScale(2, RoundingMode.HALF_UP).doubleValue();
 		System.out.println("!!!" + orderMoney + "!!!!");
 		orderMoney = orderMoney < 0 ? 0 : orderMoney;
+		orderPrivateCar.setPayMoney(orderMoney);
 		if (payType == 1) {//微信支付
 			if (orderMoney == 0) {
 				return ResultUtil.error("请使用余额支付");
 			}
-			String app = type == 1 ? "APP" : "JSAPI";
-			resultUtil = payMoneyUtil.weixinpay("完成订单", "", orderId + "_1_" + UUIDUtil.getRandomCode(5), orderMoney.toString(), "/base/wxPayOrderTaxi", app, userInfo.getAppletsOpenId());
+//			String app = type == 1 ? "APP" : "JSAPI";
+//			resultUtil = payMoneyUtil.weixinpay("完成订单", "", orderId + "_1_" + UUIDUtil.getRandomCode(5), orderMoney.toString(), "/base/wxPayOrderTaxi", app, userInfo.getAppletsOpenId());
+			//如果没有创建行程,需要先创建行程单
+			Driver driver = driverService.selectById(orderPrivateCar.getDriverId());
+			if(ToolUtil.isEmpty(orderPrivateCar.getTravelId())){
+				Company company = companyService.selectById(driver.getCompanyId());
+				//调三方订单中心创建行程单
+				CreateTravelItineraryRequest request = new CreateTravelItineraryRequest();
+				request.setOrderNo("PR" + orderPrivateCar.getId());
+				request.setCustomerId(userInfo.getOnconUUID());
+				request.setDriverId(driver.getEmpId().toString());
+				request.setSupplierShopId(company.getEnterCode());
+				if(orderPrivateCar.getPromotion() !=null && 2 == orderPrivateCar.getPromotion()){
+					Driver driver1 = driverService.selectById(orderPrivateCar.getPromotionDriverId());
+					request.setPromoterId(driver1.getEmpId().toString());
+				}
+				request.setServiceType(2);
+				String travelItinerary = OrderUtil.createTravelItinerary(request);
+				orderPrivateCar.setTravelId(travelItinerary);
+
+				//创建订单
+				//中台修改订单状态
+				ModifyTravelItineraryRequest request1 = new ModifyTravelItineraryRequest();
+				request1.setOrderId(orderPrivateCar.getTravelId());
+				request1.setStatus(orderPrivateCar.getState());
+				if (null != orderPrivateCar.getDriverId()) {
+					request1.setDriverId(driver.getEmpId().toString());
+					request1.setSupplierShopId(company.getEnterCode());
+				}
+				if (2 == orderPrivateCar.getPromotion()) {
+					Driver driver2 = driverService.selectById(orderPrivateCar.getPromotionDriverId());
+					request1.setPromoterId(driver2.getEmpId().toString());
+				}
+				OrderUtil.modifyTravelItinerary(request1);
+			}
+
+
+			if(null == orderPrivateCar.getIsCreated() || 0 == orderPrivateCar.getIsCreated()){
+				//调用中台创建订单及拉起支付接口
+				TradeOrderCreateData tradeOrderCreateData = new TradeOrderCreateData();
+				tradeOrderCreateData.setTreatShopId(driver.getEmpId().toString());
+				//追缴单不要分账
+				if(0 == orderPrivateCar.getRecoveryOrder()){
+					tradeOrderCreateData.setField1("{\"profitSharing\":\"1\",\"isPromote\":\"" + (orderPrivateCar.getPromotion() == 2 ? 1 : 0) + "\"}");
+				}else{
+					tradeOrderCreateData.setField1("{\"profitSharing\":\"0\",\"isPromote\":\"0\"}");
+				}
+				tradeOrderCreateData.setCharge(new BigDecimal(orderMoney));
+				tradeOrderCreateData.setOrderId(orderPrivateCar.getTravelId());
+				tradeOrderCreateData.setOrderNo("PR" + orderPrivateCar.getId());
+				tradeOrderCreateData.setCustomerId(userInfo.getOnconUUID());
+				tradeOrderCreateData.setPartnerPayId(orderPrivateCar.getTravelId());
+				tradeOrderCreateData.setTotalFee(Double.valueOf(orderMoney * 100).intValue() + "");
+				tradeOrderCreateData.setOrderDesc("完成订单");
+				tradeOrderCreateData.setRetUrl(path);
+				tradeOrderCreateData.setClientIp(ip);
+
+				List<GoodsInfoRequest> goodsInfo = new ArrayList<>();
+				GoodsInfoRequest goodsInfoRequest = new GoodsInfoRequest();
+				goodsInfoRequest.setSubOpenId(userInfo.getAppletsOpenId());
+				if(0 == orderPrivateCar.getRecoveryOrder()){
+					goodsInfoRequest.setProfitSharing("1");
+				}else{
+					goodsInfoRequest.setProfitSharing("0");
+				}
+				goodsInfo.add(goodsInfoRequest);
+				tradeOrderCreateData.setGoodsInfo(goodsInfo);
+				TradeOrderCreate tradeOrderCreate = OrderUtil.tradeOrderCreate1(tradeOrderCreateData, orderPrivateCar.getRecoveryOrder());
+				PayInfo payInfo = tradeOrderCreate.getPayInfo();
+				if(!"000000".equals(payInfo.getRetCode())){
+					return ResultUtil.error(payInfo.getRetMsg());
+				}
+				orderPrivateCar.setIsCreated(1);
+				resultUtil = ResultUtil.success(payInfo.getData().getRedirectUrl());
+			}else{
+				//拉起支付
+				TradePayOff1Data tradePayOff1Data = new TradePayOff1Data();
+				tradePayOff1Data.setPartnerPayId(orderPrivateCar.getTravelId());
+				tradePayOff1Data.setTotalFee(Double.valueOf(orderMoney * 100).intValue() + "");
+				tradePayOff1Data.setRetUrl(path);
+				tradePayOff1Data.setClientIp(ip);
+				tradePayOff1Data.setOrderDesc("完成订单");
+				List<GoodsInfoRequest> goodsInfo = new ArrayList<>();
+				GoodsInfoRequest goodsInfoRequest = new GoodsInfoRequest();
+				goodsInfoRequest.setSubOpenId(userInfo.getAppletsOpenId());
+				if(0 == orderPrivateCar.getRecoveryOrder()){
+					goodsInfoRequest.setProfitSharing("1");
+				}else{
+					goodsInfoRequest.setProfitSharing("0");
+				}
+				goodsInfo.add(goodsInfoRequest);
+				tradePayOff1Data.setGoodsInfo(goodsInfo);
+				PayInfo payInfo = OrderUtil.tradePayOff1(tradePayOff1Data, orderPrivateCar.getRecoveryOrder());
+				if(!"000000".equals(payInfo.getRetCode())){
+					return ResultUtil.error(payInfo.getRetMsg());
+				}
+				resultUtil = ResultUtil.success(payInfo.getData().getRedirectUrl());
+			}
 			paymentRecordService.saveData(1, orderPrivateCar.getUserId(), 1, orderId, 1, 1, orderMoney, "", 1);//添加预支付数据
+			
+			//创建定时任务查询订单支付状态
+			ThreadPoolExecutor threadPoolExecutor = new ThreadPoolExecutor(1, 1, 0L, TimeUnit.MILLISECONDS, new LinkedBlockingQueue<Runnable>());
+			threadPoolExecutor.execute(()->{
+				try {
+					int num = 1;
+					int wait = 0;
+					while (num <= 13) {
+						int min = 5000;
+						wait += (min * num);
+						OrderPrivateCar orderPrivateCar1 = this.selectById(orderPrivateCar.getId());
+						if (orderPrivateCar1.getState() != 7) {
+							break;
+						}
+						GetTravelItineraryListRequest request = new GetTravelItineraryListRequest();
+						request.setCustomerId(userInfo.getOnconUUID());
+						request.setOrderNo("PR" + orderPrivateCar1.getId());
+						request.setDriverId(driver.getEmpId().toString());
+						ListPage<List<TravelItinerary>> travelItineraryList = OrderUtil.getTravelItineraryList(request);
+						TravelItinerary travelItinerary = travelItineraryList.getList().get(0);
+						if(travelItinerary.getStatus() != 7 || travelItinerary.getOrderStatus() == 11){
+							GetPaymentInfoDataRequest getPaymentInfoDataRequest = new GetPaymentInfoDataRequest();
+							getPaymentInfoDataRequest.setPartnerPayId(orderPrivateCar1.getTravelId());
+							GetPaymentInfo getPaymentInfo = OrderUtil.paymentInfo(getPaymentInfoDataRequest);
+							payOrderPrivateCarCallback(orderPrivateCar1.getId(), getPaymentInfo.getPayId(), 1);
+							break;
+						}
+						Thread.sleep(wait);
+						num++;
+					}
+				} catch (Exception e) {
+					e.printStackTrace();
+				}finally {
+					threadPoolExecutor.shutdown();
+				}
+				
+			});
+			
 		}
 		if (payType == 2) {//支付宝支付
 			if (orderMoney == 0) {
@@ -2099,12 +2300,7 @@
 			if (userInfo.getBalance() == null || userInfo.getBalance() < orderMoney) {
 				return ResultUtil.error("余额不足,无法完成支付");
 			}
-//            if(orderMoney > 0){
-//                resultUtil= appOrderController.moneyPay(orderId,userInfo.getId(),orderMoney);
-//                if(resultUtil.getCode()==500){
-//                    return ResultUtil.error("电子余额不足,无法完成支付");
-//                }
-//            }
+
 			userInfo.setBalance(new BigDecimal(userInfo.getBalance()).subtract(new BigDecimal(orderMoney)).setScale(2, BigDecimal.ROUND_HALF_EVEN).doubleValue());
 			
 			OpenCity openCity = openCityService.openCity1(orderPrivateCar.getStartLon().toString(), orderPrivateCar.getStartLat().toString());
@@ -2119,7 +2315,7 @@
 			
 			orderPrivateCar.setState(8);
 			orderPrivateCar.setPayType(3);
-			orderPrivateCar.setPayMoney(orderMoney);
+			orderPrivateCar.setPayTime(new Date());
 			
 			//处理优惠券和红包
 			if (null != userCouponRecord) {
@@ -2136,11 +2332,19 @@
 				query.setEndTime(new Date());
 				userRedPacketRecordService.updateById(query);
 			}
-			
-			//添加收入
-			Map<String, Object> map = incomeService.saveIncome(orderPrivateCar.getId(), 1, orderPrivateCar.getOrderMoney());
-			orderPrivateCar.setSplitAllocation(JSON.toJSONString(map));
-			
+			//非追缴单才添加收入记录
+			if(0 == orderPrivateCar.getRecoveryOrder()){
+				//添加收入
+				Double orderMoney1 = (1 == orderPrivateCar.getAbnormal() ? orderPrivateCar.getOrderMoney() : orderPrivateCar.getResponsibilityMoney().doubleValue());
+				Map<String, Object> map = incomeService.saveIncome(orderPrivateCar.getId(), 1, orderMoney1);
+				orderPrivateCar.setSplitAllocation(JSON.toJSONString(map));
+			}
+
+
+			this.updateAllColumnById(orderPrivateCar);
+			promotion(orderPrivateCar.getId());
+
+
 			// TODO: 2020/5/24 这里需要给司机和用户推送订单状态
 			new Thread(new Runnable() {
 				@Override
@@ -2164,12 +2368,17 @@
 			if (orderMoney == 0) {
 				return ResultUtil.error("请使用余额支付");
 			}
+			orderPrivateCar.setPayTime(new Date());
 			Integer integer = paymentRecordService.saveData(1, orderPrivateCar.getUserId(), 1, orderId, 1, 4, orderMoney, "", 1);
 			resultUtil = appOrderController.placeAnOrder(new BigDecimal(orderMoney), 4, orderId, 6, integer);
 			
 		}
-		
-		this.updateAllColumnById(orderPrivateCar);
+
+		if(payType != 3){
+			this.updateAllColumnById(orderPrivateCar);
+		}
+
+
 		return resultUtil;
 	}
 	
@@ -2277,6 +2486,26 @@
 			orderPrivateCar.setTelX("");
 			this.updateById(orderPrivateCar);
 			
+			if(ToolUtil.isNotEmpty(orderPrivateCar.getTravelId())){
+				Driver driver = null;
+				Company company = null;
+				//中台修改订单状态
+				ModifyTravelItineraryRequest request = new ModifyTravelItineraryRequest();
+				request.setOrderId(orderPrivateCar.getTravelId());
+				request.setStatus(orderPrivateCar.getState());
+				if (null != orderPrivateCar.getDriverId()) {
+					driver = driverService.selectById(orderPrivateCar.getDriverId());
+					company = companyService.selectById(driver.getCompanyId());
+					request.setDriverId(driver.getEmpId().toString());
+					request.setSupplierShopId(company.getEnterCode());
+				}
+				if (2 == orderPrivateCar.getPromotion()) {
+					Driver driver1 = driverService.selectById(orderPrivateCar.getPromotionDriverId());
+					request.setPromoterId(driver1.getEmpId().toString());
+				}
+				OrderUtil.modifyTravelItinerary(request);
+			}
+			
 			query.setState(2);
 			query.setCode(order_id);
 			paymentRecordService.updateById(query);
@@ -2317,6 +2546,7 @@
 			orderPrivateCar.setState(8);
 			orderPrivateCar.setPayType(type);
 			orderPrivateCar.setPayMoney(query.getAmount());
+			orderPrivateCar.setPayTime(new Date());
 			
 			UserInfo userInfo = userInfoService.selectById(orderPrivateCar.getUserId());
 			OpenCity openCity = openCityService.openCity1(orderPrivateCar.getStartLon().toString(), orderPrivateCar.getStartLat().toString());
@@ -2351,11 +2581,16 @@
 			query.setState(2);
 			query.setCode(order_id);
 			paymentRecordService.updateById(query);
-			
-			//添加收入
-			Map<String, Object> map = incomeService.saveIncome(orderPrivateCar.getId(), 1, orderPrivateCar.getOrderMoney());
-			orderPrivateCar.setSplitAllocation(JSON.toJSONString(map));
+
+			//非追缴单才需要记录收入
+			if(0 == orderPrivateCar.getRecoveryOrder()){
+				//添加收入
+				Double orderMoney = (1 == orderPrivateCar.getAbnormal() ? orderPrivateCar.getOrderMoney() : orderPrivateCar.getResponsibilityMoney().doubleValue());
+				Map<String, Object> map = incomeService.saveIncome(orderPrivateCar.getId(), 1, orderMoney);
+				orderPrivateCar.setSplitAllocation(JSON.toJSONString(map));
+			}
 			this.updateById(orderPrivateCar);
+			promotion(orderPrivateCar.getId());
 			
 			// TODO: 2020/5/24 这里需要给司机和用户推送订单状态
 			new Thread(new Runnable() {
@@ -2433,7 +2668,7 @@
 				OpenCity openCity = openCityService.openCity1(orderPrivateCar.getStartLon().toString(), orderPrivateCar.getStartLat().toString());
 				List<PushOrder> querys = pushOrderService.querys(null, 2, openCity.getId());//获取需要推送的次数
 				int time = 0;
-				for (int i = 1; i <= querys.size() + 5; i++) {
+				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);
 					time += pushOrder.getPushTime() * 1000;
@@ -2526,7 +2761,7 @@
 		paymentRecordService.updateById(query);
 		OpenCity openCity = openCityService.openCity1(orderPrivateCar.getStartLon().toString(), orderPrivateCar.getStartLat().toString());
 		SysIntegral query1 = sysIntegralMapper.query(openCity.getId());
-		System.out.println("query1:" + query1);
+//		System.out.println("query1:" + query1);
 		userInfo.setIntegral(userInfo.getIntegral() + (query.getAmount().intValue() * query1.getIntegral()));//积分
 		
 		//添加交易明细
@@ -2597,24 +2832,27 @@
 					OpenCity openCity = openCityService.openCity1(startLon.toString(), startLat.toString());
 					List<PushOrder> querys = pushOrderService.querys(null, 1, openCity.getId());//获取需要推送的次数
 					//整轮派单结束,若无司机接单,系统自动增加派单5轮,若增加5轮后任无司机接单,则系统结束派单,乘客端显示无司机接单、是否再次打车
-					for (int i = 1; i <= querys.size() + 5; i++) {
-						OrderPrivateCar orderPrivateCar = orderPrivateCarMapper.selectById(id);
-						if (null == orderPrivateCar || orderPrivateCar.getState() > 1) {
-							break;
-						}
-						int finalI = i;
-						PushOrder pushOrder = querys.stream().filter(s -> s.getType() == (finalI <= 3 ? finalI : 3)).findFirst().orElse(null);
-						System.out.println("pushOrder:" + pushOrder);
-						int i2 = pushOrder.getPushTime() / 10;
-						if (i2 == 0) {
-							i2 = 1;
-						}
-						for (int i1 = 0; i1 < i2; i1++) {
+					int num = 0;
+					for (int j = 0; j < 6; j++) {
+						Boolean push = false;
+						for (int i = 1; i <= querys.size(); i++) {
+							num++;
+							OrderPrivateCar orderPrivateCar = orderPrivateCarMapper.selectById(id);
+							if (null == orderPrivateCar || orderPrivateCar.getState() > 1) {
+								push = true;
+								break;
+							}
+							int finalI = i;
+							PushOrder pushOrder = querys.stream().filter(s -> s.getType() == (finalI <= 3 ? finalI : 3)).findFirst().orElse(null);
+							System.out.println("pushOrder:" + pushOrder);
 							if (orderPrivateCar.getState() > 1) {
+								push = true;
 								break;
 							}
 							//获取空闲司机
 							List<Driver> list = driverService.queryIdleDriver(orderType, serverCarModelId, startLon, startLat, pushOrder.getPushDistance(), null);//所有附近空闲司机
+							//随机排序
+							Collections.shuffle(list);
 							if (list.size() > 0) {
 								double driverProportion = pushOrder.getDriverProportion() / 100;//推送占比计算成小数
 								int lastIndex = Double.valueOf(list.size() * driverProportion).intValue();//计算占比转成整数(下标截取)
@@ -2634,18 +2872,26 @@
 									pushUtil.pushOrderState(2, driver.getId(), id, 1, 1, pushOrder.getPushTime());
 								}
 							}
-							Thread.sleep(10000);//设置等待时间
-							Integer state = orderPrivateCarMapper.selectById(orderPrivateCar.getId()).getState();
+							Thread.sleep(pushOrder.getPushTime() * 1000);//设置等待时间
+							OrderPrivateCar orderPrivateCar1 = orderPrivateCarMapper.selectById(orderPrivateCar.getId());
+							Integer state =orderPrivateCar1.getState();
 							if (state > 1) {
 								orderIds.remove(orderPrivateCar.getId());
+								push = true;
 								break;
 							}
-							if (i == querys.size() + 5) {
-								pushUtil.pushEndPush(1, orderPrivateCar.getUserId(), orderPrivateCar.getId(), 1);
+							if (num == 18) {
+								orderPrivateCar1.setState(10);
+								orderPrivateCarMapper.updateById(orderPrivateCar1);
+								pushUtil.pushEndPush(1, orderPrivateCar.getUserId(), orderPrivateCar.getId(), 1, 1);
 								orderIds.remove(orderPrivateCar.getId());
 							}
 						}
+						if(push){
+							break;
+						}
 					}
+
 				} catch (Exception e) {
 					e.printStackTrace();
 				}
@@ -2674,7 +2920,7 @@
 					}
 					OpenCity openCity = openCityService.openCity1(orderPrivateCar.getStartLon().toString(), orderPrivateCar.getStartLat().toString());
 					List<PushOrder> querys = pushOrderService.querys(null, 1, openCity.getId());//获取需要推送的次数
-					for (int i = 1; i <= querys.size() + 5; i++) {
+					for (int i = 1; i <= querys.size() + 15; i++) {
 						OrderPrivateCar orderPrivateCar = orderPrivateCarMapper.selectById(id);
 						if (null == orderPrivateCar || orderPrivateCar.getState() > 1) {
 							break;
@@ -2717,8 +2963,8 @@
 								orderIds.remove(orderPrivateCar.getId());
 								return;
 							}
-							if (i == querys.size() + 5 && state == 1) {
-								pushUtil.pushEndPush(1, orderPrivateCar.getUserId(), orderPrivateCar.getId(), 1);
+							if (i == querys.size() + 15 && state == 1) {
+								pushUtil.pushEndPush(1, orderPrivateCar.getUserId(), orderPrivateCar.getId(), 1, 1);
 								orderIds.remove(orderPrivateCar.getId());
 							}
 						}
@@ -2752,27 +2998,46 @@
 		UserInfo userInfo = userInfoService.selectById(orderPrivateCar.getUserId());
 //		if(userInfo.getBindDriverId()!=null && userInfo.getBindExpireDate().getTime()<=System.currentTimeMillis()){
 		// 开始绑定的  后面到期也结算
+		System.out.println("eeeee+"+orderPrivateCar.getPromotionDriverId());
 		if(orderPrivateCar.getPromotionDriverId()!=null ){
-			String registAreaCode = userInfo.getRegistAreaCode();
-			TDriverPromotionActivity tDriverPromotionActivity = driverPromotionActivityService.selectOne(new EntityWrapper<TDriverPromotionActivity>().eq("districtCode", registAreaCode).ge("startTime", new Date()).lt("endTime", new Date()).last("AND FIND_IN_SET(" + 1 + ", bizType) limit 1"));
+			String registAreaCode = driverService.selectById(orderPrivateCar.getPromotionDriverId()).getPlaceOfEmployment();
+			TDriverPromotionActivity tDriverPromotionActivity = driverPromotionActivityService.selectOne(new EntityWrapper<TDriverPromotionActivity>().eq("districtCode", registAreaCode).le("startTime", new Date()).ge("endTime", new Date()).last("AND FIND_IN_SET(" + 1 + ", bizType) limit 1"));
+			System.out.println("ddddd"+tDriverPromotionActivity);
 			if(tDriverPromotionActivity!=null){
 				Double payMoney = orderPrivateCar.getPayMoney();
+				System.out.println(payMoney);
 				BigDecimal bigDecimal = tDriverPromotionActivity.getCommissionRatio().divide(new BigDecimal(100), 2, RoundingMode.HALF_UP).multiply(new BigDecimal(payMoney)).setScale(2, RoundingMode.HALF_UP);
+				System.out.println(bigDecimal);
 				orderPrivateCar.setPromotionDriverId(userInfo.getBindDriverId());
 				orderPrivateCar.setPromotionMoney(bigDecimal);
 				orderPrivateCar.setPromotionActivityId(tDriverPromotionActivity.getId());
+				orderPrivateCar.setSuccessTime(new Date());
 				this.baseMapper.updateById(orderPrivateCar);
 			}
 		}
+	}
 
-		// 是否异常订单
-        if (orderPrivateCar.getResponsibilityType() !=null && orderPrivateCar.getResponsibilityType() >2) {
-			TAbnormalPayOrder tAbnormalPayOrder = abnormalPayOrderMapper.selectList(new EntityWrapper<TAbnormalPayOrder>().eq("type", 1).eq("orderNum", orderPrivateCar.getOrderNum())).stream().findFirst().orElse(null);
-			if (tAbnormalPayOrder != null) {
-				tAbnormalPayOrder.setPayStatus(2);
-				tAbnormalPayOrder.setPayTime(new Date());
-				abnormalPayOrderMapper.updateById(tAbnormalPayOrder);
+	@Override
+	public List<Map<String, Object>> queryMyTripList(Integer uid, Integer pageNum, Integer size) throws Exception {
+		pageNum = (pageNum - 1) * size;
+		List<Map<String, Object>> maps = orderPrivateCarMapper.queryMyTripList(uid, pageNum, size);
+		for (Map<String, Object> map : maps) {
+			if (Integer.valueOf(String.valueOf(map.get("state"))) == 11) {
+				map.put("state", map.get("oldState"));
 			}
 		}
+		return maps;
+	}
+
+	@Override
+	public List<Map<String, Object>> queryMyTripListAll(Integer uid) throws Exception {
+
+		List<Map<String, Object>> maps = orderPrivateCarMapper.queryMyTripListAll(uid);
+		for (Map<String, Object> map : maps) {
+			if (Integer.valueOf(String.valueOf(map.get("state"))) == 11) {
+				map.put("state", map.get("oldState"));
+			}
+		}
+		return maps;
 	}
 }

--
Gitblit v1.7.1