| | |
| | | import com.stylefeng.guns.modular.system.service.*; |
| | | import com.stylefeng.guns.modular.system.service.impl.OrderPositionServiceImpl; |
| | | import com.stylefeng.guns.modular.system.util.*; |
| | | import com.stylefeng.guns.modular.system.warpper.BaseWarpper; |
| | | import com.stylefeng.guns.modular.system.warpper.EndPushWarpper; |
| | | import com.stylefeng.guns.modular.system.warpper.OrderInfoWarpper; |
| | | import com.stylefeng.guns.modular.system.warpper.OrderServerWarpper; |
| | | import com.stylefeng.guns.modular.system.warpper.*; |
| | | import com.stylefeng.guns.modular.taxi.dao.OrderTaxiMapper; |
| | | import com.stylefeng.guns.modular.taxi.model.OrderTaxi; |
| | | import com.stylefeng.guns.modular.taxi.model.PaymentRecord; |
| | |
| | | import org.springframework.http.MediaType; |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.transaction.annotation.Transactional; |
| | | import org.springframework.util.CollectionUtils; |
| | | import org.springframework.util.LinkedMultiValueMap; |
| | | import org.springframework.util.MultiValueMap; |
| | | import org.springframework.web.client.RestTemplate; |
| | |
| | | |
| | | @Autowired |
| | | private IAssignOrderService assignOrderService; |
| | | |
| | | // @Autowired |
| | | // private ALiSendSms aLiSendSms; |
| | | |
| | | @Autowired |
| | | private IOpenCityService openCityService; |
| | | @Autowired |
| | | private IServerCarModelService serverCarModelService; |
| | | @Autowired |
| | | private IAppOpenInfoService appOpenInfoService; |
| | | |
| | | @Value("${filePath}") |
| | | private String filePath; |
| | |
| | | */ |
| | | @Override |
| | | public synchronized ResultUtil<BaseWarpper> saveOrderPrivateCar(Integer serverCarModelId, Date travelTime, Integer reservation, Integer instead, String placementLon, String placementLat, String startLon, String startLat, |
| | | String startAddress, String endLon, String endLat, String endAddress, String name, String phone, Integer orderSource, Integer driverId, Integer type, Integer uid) throws Exception { |
| | | String startAddress, String endLon, String endLat, String endAddress, String name, String phone, Integer orderSource, Integer driverId, Integer type, Integer uid, |
| | | BigDecimal estimatedPrice,String cityCode,Integer carIndex) throws Exception { |
| | | |
| | | //如果出行时间大于当前10分钟则默认为预约单 |
| | | if(travelTime.getTime() > (System.currentTimeMillis() + 600000)){ |
| | |
| | | CarService query1 = carServiceMapper.query(1, driver.getCarId()); |
| | | orderPrivateCar.setServerCarModelId(query1.getServerCarModelId()); |
| | | orderPrivateCar.setSnatchOrderTime(new Date()); |
| | | |
| | | //调用高德创建轨迹 |
| | | // String s = gdFalconUtil.selectTerminal(driver.getPhone()); |
| | | // String track = gdFalconUtil.createTrack(s); |
| | | // JSONObject jsonObject = JSONObject.parseObject(track); |
| | | // orderPrivateCar.setTrackId(String.valueOf(jsonObject.getInteger("trid"))); |
| | | |
| | | //调用移动的小号接口 |
| | | /* Map<String, String> geocode1 = gdMapGeocodingUtil.geocode(orderPrivateCar.getStartLon().toString(), orderPrivateCar.getStartLat().toString()); |
| | | Region region = regionMapper.query(geocode1.get("districtCode"));*/ |
| | | // Map<String, String> map = chinaMobileUtil.midAxbBindSend(orderPrivateCar.getPassengersPhone(), driver.getPhone(), null); |
| | | // if(String.valueOf(map.get("code")).equals("200")){ |
| | | // orderPrivateCar.setTelX(map.get("telX")); |
| | | // orderPrivateCar.setBindId(map.get("bindId")); |
| | | // } |
| | | |
| | | driver.setState(3); |
| | | driverService.updateById(driver); |
| | | } |
| | | |
| | | orderPrivateCar.setIsReassign(1); |
| | | orderPrivateCar.setIsDelete(1); |
| | | this.insert(orderPrivateCar); |
| | | |
| | | if(orderSource == 2){//扫码下单 |
| | | new Thread(new Runnable() { |
| | | @Override |
| | | public void run() { |
| | | pushUtil.pushOrderState(1, uid, orderPrivateCar.getId(), 1, 2, 0); |
| | | pushUtil.pushOrderState(2, orderPrivateCar.getDriverId(), orderPrivateCar.getId(), 1, 2, 0); |
| | | pushUtil.pushDriverPosition(orderPrivateCar.getId(), 1); |
| | | } |
| | | }).start(); |
| | | // 查询城市的订单额度 |
| | | OpenCity openCity = openCityService.selectOne(new EntityWrapper<OpenCity>() |
| | | .eq("code", cityCode) |
| | | .ne("flag", 3) |
| | | .orderBy("orderMagnitude", false) |
| | | .last("LIMIT 1")); |
| | | if(Objects.isNull(openCity)){ |
| | | String city = cityCode.substring(0, 4) + "00"; |
| | | openCity = openCityService.selectOne(new EntityWrapper<OpenCity>() |
| | | .eq("code", city) |
| | | .ne("flag", 3) |
| | | .orderBy("orderMagnitude", false) |
| | | .last("LIMIT 1")); |
| | | } |
| | | |
| | | |
| | | // TODO: 2021/5/11 修改,根据后台设定的派单范围查询范围内有无司机,将单子指派给距离最近的司机(距离相同随机取),范围内没有司机再进行推单流程 |
| | | if(orderPrivateCar.getState() == 1){ |
| | | Company query = companyCityService.query(orderPrivateCar.getStartLon().toString(), orderPrivateCar.getStartLat().toString()); |
| | | if(null == query){ |
| | | return ResultUtil.error("起点暂未企业提供服务"); |
| | | // 查询预估价格 |
| | | ResultUtil<List<ServerCarModelWarpper>> listResultUtil = serverCarModelService.queryServerCarModel(startLon + "," + startLat, endLon + "," + endLat, 1); |
| | | List<ServerCarModelWarpper> data = listResultUtil.getData(); |
| | | data = data.stream().filter(e -> serverCarModelId.equals(e.getId())).sorted(Comparator.comparing(ServerCarModelWarpper::getAmount)).collect(Collectors.toList()); |
| | | if(Objects.nonNull(openCity) && !CollectionUtils.isEmpty(data) && BigDecimal.valueOf(data.get(0).getAmount()).compareTo(openCity.getOrderMagnitude()) > 0){ |
| | | orderPrivateCar.setIsReassign(1); |
| | | orderPrivateCar.setIsDelete(1); |
| | | orderPrivateCar.setState(7); |
| | | if(orderSource == 2){ |
| | | orderPrivateCar.setOrderMoney(data.get(0).getAmount()); |
| | | orderPrivateCar.setEstimatedPrice(data.get(0).getAmount()); |
| | | }else { |
| | | orderPrivateCar.setOrderMoney(data.get(carIndex).getAmount()); |
| | | orderPrivateCar.setEstimatedPrice(data.get(carIndex).getAmount()); |
| | | } |
| | | AssignOrder assignOrder = assignOrderService.selectOne(new EntityWrapper<AssignOrder>().eq("companyId", query.getId()).eq("type", 1)); |
| | | if(null != assignOrder){//配置了指派规则才处理 |
| | | boolean lock = redisUtil.lock("order_lock", 10); |
| | | if(!lock){ |
| | | int num1 = 1; |
| | | while (num1 <= 10){ |
| | | Thread.sleep(3000);//等待3秒 |
| | | lock = redisUtil.lock("order_lock", 10); |
| | | if(lock){ |
| | | break; |
| | | }else{ |
| | | num1++; |
| | | orderPrivateCar.setPayMethod(0); |
| | | this.insert(orderPrivateCar); |
| | | BaseWarpper baseWarpper = new BaseWarpper(); |
| | | baseWarpper.setId(orderPrivateCar.getId()); |
| | | baseWarpper.setState(orderPrivateCar.getState()); |
| | | baseWarpper.setPayMethod(0); |
| | | baseWarpper.setAmount(orderPrivateCar.getOrderMoney()); |
| | | return ResultUtil.success(baseWarpper); |
| | | }else { |
| | | if(orderSource == 2){ |
| | | orderPrivateCar.setEstimatedPrice(data.get(0).getAmount()); |
| | | }else { |
| | | orderPrivateCar.setEstimatedPrice(data.get(carIndex).getAmount()); |
| | | } |
| | | orderPrivateCar.setIsReassign(1); |
| | | orderPrivateCar.setIsDelete(1); |
| | | orderPrivateCar.setPayMethod(1); |
| | | this.insert(orderPrivateCar); |
| | | |
| | | if(orderSource == 2){//扫码下单 |
| | | new Thread(new Runnable() { |
| | | @Override |
| | | public void run() { |
| | | pushUtil.pushOrderState(1, uid, orderPrivateCar.getId(), 1, 2, 0); |
| | | pushUtil.pushOrderState(2, orderPrivateCar.getDriverId(), orderPrivateCar.getId(), 1, 2, 0); |
| | | pushUtil.pushDriverPosition(orderPrivateCar.getId(), 1); |
| | | } |
| | | }).start(); |
| | | } |
| | | |
| | | |
| | | // TODO: 2021/5/11 修改,根据后台设定的派单范围查询范围内有无司机,将单子指派给距离最近的司机(距离相同随机取),范围内没有司机再进行推单流程 |
| | | if(orderPrivateCar.getState() == 1){ |
| | | Company query = companyCityService.query(orderPrivateCar.getStartLon().toString(), orderPrivateCar.getStartLat().toString()); |
| | | if(null == query){ |
| | | return ResultUtil.error("起点暂未企业提供服务"); |
| | | } |
| | | AssignOrder assignOrder = assignOrderService.selectOne(new EntityWrapper<AssignOrder>().eq("companyId", query.getId()).eq("type", 1)); |
| | | if(null != assignOrder){//配置了指派规则才处理 |
| | | boolean lock = redisUtil.lock("order_lock", 10); |
| | | if(!lock){ |
| | | int num1 = 1; |
| | | while (num1 <= 10){ |
| | | Thread.sleep(3000);//等待3秒 |
| | | lock = redisUtil.lock("order_lock", 10); |
| | | if(lock){ |
| | | break; |
| | | }else{ |
| | | num1++; |
| | | } |
| | | } |
| | | } |
| | | } |
| | | try { |
| | | //获取空闲司机 |
| | | List<Driver> drivers = driverService.queryIdleDriver(1, orderPrivateCar.getServerCarModelId(), orderPrivateCar.getStartLon(), orderPrivateCar.getStartLat(), assignOrder.getDistance(), null);//获取范围内空闲司机 |
| | | List<Integer> driverIds = drivers.stream().map(Driver::getId).collect(Collectors.toList()); |
| | | if(drivers.size() > 0) {//有司机,直接指派给司机 |
| | | Driver dr = null; |
| | | if (drivers.size() > 1) { |
| | | List<Driver> ds = new ArrayList<>();//存储直线距离最近的几个司机 |
| | | for (int i = 0; i < assignOrder.getPeople(); i++) { |
| | | Driver driver = null; |
| | | int m = 0; |
| | | int index = 0; |
| | | // 查询预约单 |
| | | List<OrderPrivateCar> orderPrivateCarss = orderPrivateCarMapper.queryOrderByState(driverIds, 2, 1, 2, 3, 4, 5, 6, 11); |
| | | List<Integer> orderPrivateCarDriverIds = orderPrivateCars.stream().map(OrderPrivateCar::getDriverId).collect(Collectors.toList()); |
| | | for (int j = 0; j < drivers.size(); j++) { |
| | | Driver driver1 = drivers.get(j); |
| | | if (orderPrivateCar.getOrderType() == 2 && orderPrivateCarDriverIds.contains(driver.getId())) { |
| | | continue; |
| | | } |
| | | // 判断该司机是否有30分钟内预约单 |
| | | long count = orderPrivateCarss.stream().filter(s -> s.getDriverId().equals(driver1.getId()) && |
| | | DateUtil.dateToLocalDateTime(s.getTravelTime()).minusMinutes(30).isBefore(LocalDateTime.now())).count(); |
| | | if (count > 0) { |
| | | continue; |
| | | } |
| | | String value = redisUtil.getValue("DRIVER" + drivers.get(j).getId()); |
| | | if (null != value) { |
| | | try { |
| | | //获取空闲司机 |
| | | List<Driver> drivers = driverService.queryIdleDriver(1, orderPrivateCar.getServerCarModelId(), orderPrivateCar.getStartLon(), orderPrivateCar.getStartLat(), assignOrder.getDistance(), null);//获取范围内空闲司机 |
| | | List<Integer> driverIds = drivers.stream().map(Driver::getId).collect(Collectors.toList()); |
| | | if(drivers.size() > 0) {//有司机,直接指派给司机 |
| | | Driver dr = null; |
| | | if (drivers.size() > 1) { |
| | | List<Driver> ds = new ArrayList<>();//存储直线距离最近的几个司机 |
| | | for (int i = 0; i < assignOrder.getPeople(); i++) { |
| | | Driver driver = null; |
| | | int m = 0; |
| | | int index = 0; |
| | | // 查询预约单 |
| | | List<OrderPrivateCar> orderPrivateCarss = orderPrivateCarMapper.queryOrderByState(driverIds, 2, 1, 2, 3, 4, 5, 6, 11); |
| | | List<Integer> orderPrivateCarDriverIds = orderPrivateCars.stream().map(OrderPrivateCar::getDriverId).collect(Collectors.toList()); |
| | | for (int j = 0; j < drivers.size(); j++) { |
| | | Driver driver1 = drivers.get(j); |
| | | if (orderPrivateCar.getOrderType() == 2 && orderPrivateCarDriverIds.contains(driver.getId())) { |
| | | continue; |
| | | } |
| | | // 判断该司机是否有30分钟内预约单 |
| | | long count = orderPrivateCarss.stream().filter(s -> s.getDriverId().equals(driver1.getId()) && |
| | | DateUtil.dateToLocalDateTime(s.getTravelTime()).minusMinutes(query.getLimitationTime()).isBefore(LocalDateTime.now())).count(); |
| | | if (count > 0) { |
| | | continue; |
| | | } |
| | | String value = redisUtil.getValue("DRIVER" + drivers.get(j).getId()); |
| | | if (null != value) { |
| | | // Map<String, String> distance1 = gdMapElectricFenceUtil.getDistance(orderPrivateCar.getStartLon() + "," + orderPrivateCar.getStartLat(), value, 0);//计算距离 |
| | | // Integer d = Integer.valueOf(distance1.get("distance")); |
| | | String[] split = value.split(","); |
| | | double distance = GDMapGeocodingUtil.getDistance(orderPrivateCar.getStartLat(), orderPrivateCar.getStartLon(), Double.valueOf(split[1]), Double.valueOf(split[0])); |
| | | int d = Double.valueOf(distance).intValue(); |
| | | if ((0 == m && null == driver) || (d < m)) { |
| | | driver = drivers.get(j); |
| | | String[] split = value.split(","); |
| | | double distance = GDMapGeocodingUtil.getDistance(orderPrivateCar.getStartLat(), orderPrivateCar.getStartLon(), Double.valueOf(split[1]), Double.valueOf(split[0])); |
| | | int d = Double.valueOf(distance).intValue(); |
| | | if ((0 == m && null == driver) || (d < m)) { |
| | | driver = drivers.get(j); |
| | | m = d; |
| | | index = j; |
| | | } |
| | | } |
| | | } |
| | | ds.add(driver); |
| | | drivers.remove(index); |
| | | } |
| | | |
| | | //再根据直线距离最短的司机中找出行驶距离最短的司机 |
| | | Integer m = 0; |
| | | for (Driver driver : ds) { |
| | | String value = redisUtil.getValue("DRIVER" + driver.getId()); |
| | | if (null != value) { |
| | | Map<String, String> distance1 = gdMapElectricFenceUtil.getDistance(orderPrivateCar.getStartLon() + "," + orderPrivateCar.getStartLat(), value, 1);//计算距离 |
| | | Integer d = Integer.valueOf(distance1.get("distance")); |
| | | if ((0 == m && null == dr) || (d.intValue() < m.intValue())) { |
| | | dr = driver; |
| | | m = d; |
| | | index = j; |
| | | } |
| | | } |
| | | } |
| | | ds.add(driver); |
| | | drivers.remove(index); |
| | | } else { |
| | | List<OrderPrivateCar> orderPrivateCarss = orderPrivateCarMapper.queryOrderByState(driverIds, 2, 1, 2, 3, 4, 5, 6, 11); |
| | | if (orderPrivateCarss.size() == 0) { |
| | | dr = drivers.get(0); |
| | | } |
| | | } |
| | | |
| | | //再根据直线距离最短的司机中找出行驶距离最短的司机 |
| | | Integer m = 0; |
| | | for (Driver driver : ds) { |
| | | String value = redisUtil.getValue("DRIVER" + driver.getId()); |
| | | if (null != value) { |
| | | Map<String, String> distance1 = gdMapElectricFenceUtil.getDistance(orderPrivateCar.getStartLon() + "," + orderPrivateCar.getStartLat(), value, 1);//计算距离 |
| | | Integer d = Integer.valueOf(distance1.get("distance")); |
| | | if ((0 == m && null == dr) || (d.intValue() < m.intValue())) { |
| | | dr = driver; |
| | | m = d; |
| | | |
| | | if (Objects.nonNull(dr)) { |
| | | orderPrivateCar.setDriverId(dr.getId()); |
| | | orderPrivateCar.setCompanyId(dr.getFranchiseeId() != null && dr.getFranchiseeId() != 0 ? dr.getFranchiseeId() : ( |
| | | dr.getCompanyId() != null && dr.getCompanyId() != 0 ? dr.getCompanyId() : 1)); |
| | | orderPrivateCar.setState(2); |
| | | orderPrivateCar.setCarId(dr.getCarId()); |
| | | CarService query1 = carServiceMapper.query(1, dr.getCarId()); |
| | | orderPrivateCar.setServerCarModelId(query1.getServerCarModelId()); |
| | | orderPrivateCar.setSnatchOrderTime(new Date()); |
| | | if (orderPrivateCar.getOrderType() != 2) { |
| | | dr.setState(3); |
| | | } |
| | | driverService.updateById(dr); |
| | | new Thread(new Runnable() { |
| | | @Override |
| | | public void run() { |
| | | pushUtil.pushOrderState(1, uid, orderPrivateCar.getId(), 1, 2, 0); |
| | | pushUtil.pushOrderState(2, orderPrivateCar.getDriverId(), orderPrivateCar.getId(), 1, 2, 0); |
| | | pushUtil.pushDriverPosition(orderPrivateCar.getId(), 1); |
| | | } |
| | | } |
| | | }).start(); |
| | | } |
| | | } else { |
| | | List<OrderPrivateCar> orderPrivateCarss = orderPrivateCarMapper.queryOrderByState(driverIds, 2, 1, 2, 3, 4, 5, 6, 11); |
| | | if (orderPrivateCarss.size() == 0) { |
| | | dr = drivers.get(0); |
| | | } |
| | | } |
| | | |
| | | if (Objects.nonNull(dr)) { |
| | | orderPrivateCar.setDriverId(dr.getId()); |
| | | orderPrivateCar.setCompanyId(dr.getFranchiseeId() != null && dr.getFranchiseeId() != 0 ? dr.getFranchiseeId() : ( |
| | | dr.getCompanyId() != null && dr.getCompanyId() != 0 ? dr.getCompanyId() : 1)); |
| | | orderPrivateCar.setState(2); |
| | | orderPrivateCar.setCarId(dr.getCarId()); |
| | | CarService query1 = carServiceMapper.query(1, dr.getCarId()); |
| | | orderPrivateCar.setServerCarModelId(query1.getServerCarModelId()); |
| | | orderPrivateCar.setSnatchOrderTime(new Date()); |
| | | if (orderPrivateCar.getOrderType() != 2) { |
| | | dr.setState(3); |
| | | } |
| | | driverService.updateById(dr); |
| | | new Thread(new Runnable() { |
| | | @Override |
| | | public void run() { |
| | | pushUtil.pushOrderState(1, uid, orderPrivateCar.getId(), 1, 2, 0); |
| | | pushUtil.pushOrderState(2, orderPrivateCar.getDriverId(), orderPrivateCar.getId(), 1, 2, 0); |
| | | pushUtil.pushDriverPosition(orderPrivateCar.getId(), 1); |
| | | } |
| | | }).start(); |
| | | } |
| | | |
| | | |
| | | //调用高德创建轨迹 |
| | | // String s = gdFalconUtil.selectTerminal(dr.getPhone()); |
| | | // String track = gdFalconUtil.createTrack(s); |
| | | // orderPrivateCar.setTrackId(track); |
| | | |
| | | //调用移动的小号接口 |
| | | /* Map<String, String> geocode1 = gdMapGeocodingUtil.geocode(orderPrivateCar.getStartLon().toString(), orderPrivateCar.getStartLat().toString()); |
| | | Region region = regionMapper.query(geocode1.get("districtCode"));*/ |
| | | // Map<String, String> map = chinaMobileUtil.midAxbBindSend(orderPrivateCar.getPassengersPhone(), dr.getPhone(), null); |
| | | // if(String.valueOf(map.get("code")).equals("200")){ |
| | | // orderPrivateCar.setTelX(map.get("telX")); |
| | | // orderPrivateCar.setBindId(map.get("bindId")); |
| | | // } |
| | | |
| | | this.updateById(orderPrivateCar); |
| | | |
| | | //发送短信给司机 |
| | | this.updateById(orderPrivateCar); |
| | | |
| | | //发送短信给司机 |
| | | // aLiSendSms.sendSms(dr.getPhone(), "SMS_216832951", "{\"" + orderPrivateCar.getStartAddress() + "\"}"); |
| | | } |
| | | }catch (Exception e){ |
| | | e.printStackTrace(); |
| | | }finally { |
| | | redisUtil.unlock("order_lock"); |
| | | } |
| | | }catch (Exception e){ |
| | | e.printStackTrace(); |
| | | }finally { |
| | | redisUtil.unlock("order_lock"); |
| | | } |
| | | } |
| | | |
| | | |
| | | //推单操作 |
| | | if(orderPrivateCar.getState() == 1){ |
| | | this.pushOrder(orderPrivateCar); |
| | | } |
| | | //添加消息 |
| | | systemNoticeService.addSystemNotice(1, "您的专车订单已下单成功,我们正在为您指派司机,请稍后!", orderPrivateCar.getUserId(), 1); |
| | | BaseWarpper baseWarpper = new BaseWarpper(); |
| | | baseWarpper.setState(orderPrivateCar.getState()); |
| | | baseWarpper.setId(orderPrivateCar.getId()); |
| | | baseWarpper.setPayMethod(1); |
| | | return ResultUtil.success(baseWarpper); |
| | | } |
| | | |
| | | |
| | | //推单操作 |
| | | if(orderPrivateCar.getState() == 1){ |
| | | this.pushOrder(orderPrivateCar); |
| | | } |
| | | |
| | | |
| | | //添加消息 |
| | | systemNoticeService.addSystemNotice(1, "您的专车订单已下单成功,我们正在为您指派司机,请稍后!", orderPrivateCar.getUserId(), 1); |
| | | |
| | | BaseWarpper baseWarpper = new BaseWarpper(); |
| | | baseWarpper.setState(orderPrivateCar.getState()); |
| | | baseWarpper.setId(orderPrivateCar.getId()); |
| | | return ResultUtil.success(baseWarpper); |
| | | } |
| | | |
| | | // @Override |
| | | // public synchronized ResultUtil<BaseWarpper> saveOrderPrivateCar(Integer serverCarModelId, Date travelTime, Integer reservation, Integer instead, String placementLon, String placementLat, String startLon, String startLat, |
| | | // String startAddress, String endLon, String endLat, String endAddress, String name, String phone, Integer orderSource, Integer driverId, Integer type, Integer uid,BigDecimal estimatedPrice) throws Exception { |
| | | // |
| | | // //如果出行时间大于当前10分钟则默认为预约单 |
| | | // if(travelTime.getTime() > (System.currentTimeMillis() + 600000)){ |
| | | // reservation = 2; |
| | | // } |
| | | // |
| | | // /** |
| | | // * 1.下了即时单就不能下预约单和即时单 |
| | | // * 2.下了预约单和再下一张即时单不能再下预约单 |
| | | // */ |
| | | // List<OrderPrivateCar> orderPrivateCars = orderPrivateCarMapper.queryByState(uid, 1, 1, 1, 2, 3, 4, 5, 6, 11); |
| | | // if(orderPrivateCars.size() > 0){ |
| | | // return ResultUtil.error("有未完成的订单"); |
| | | // } |
| | | // List<OrderTaxi> list = orderTaxiMapper.queryByState_(uid, 1, 1, 1, 2, 3, 4, 5, 6, 11); |
| | | // if(list.size() > 0){ |
| | | // return ResultUtil.error("有未完成的订单"); |
| | | // } |
| | | // |
| | | // orderPrivateCars = orderPrivateCarMapper.queryByState(uid, 2, 1, 1, 2, 3, 4, 5, 6, 11); |
| | | // if(orderPrivateCars.size() > 0 && reservation == 2){ |
| | | // return ResultUtil.error("有未完成的订单"); |
| | | // } |
| | | // |
| | | // orderPrivateCars = orderPrivateCarMapper.queryByState(uid, 1, 1, 7,12); |
| | | // if(orderPrivateCars.size() > 0){ |
| | | // BaseWarpper baseWarpper = new BaseWarpper(); |
| | | // baseWarpper.setState(7); |
| | | // baseWarpper.setId(orderPrivateCars.get(0).getId()); |
| | | // return ResultUtil.success(baseWarpper); |
| | | // } |
| | | // |
| | | // |
| | | // list = orderTaxiMapper.queryByState_(uid, 2, 1, 1, 2, 3, 4, 5, 6, 11); |
| | | // if(list.size() > 0 && reservation == 2){ |
| | | // return ResultUtil.error("有未完成的订单"); |
| | | // } |
| | | // |
| | | // startAddress = startAddress.replaceAll("& #40;", "("); |
| | | // startAddress = startAddress.replaceAll("& #41;", ")"); |
| | | // endAddress = endAddress.replaceAll("& #40;", "("); |
| | | // endAddress = endAddress.replaceAll("& #41;", ")"); |
| | | // if((orderSource == 1 || orderSource == 3) && null == serverCarModelId){ |
| | | // return ResultUtil.error("请选择服务车型"); |
| | | // } |
| | | // |
| | | // OrderPrivateCar orderPrivateCar = new OrderPrivateCar(); |
| | | // orderPrivateCar.setType(type); |
| | | // orderPrivateCar.setUserId(uid); |
| | | // orderPrivateCar.setServerCarModelId(serverCarModelId); |
| | | // orderPrivateCar.setOrderNum(this.getOrderNum()); |
| | | // orderPrivateCar.setPlacementLon(Double.valueOf(placementLon)); |
| | | // orderPrivateCar.setPlacementLat(Double.valueOf(placementLat)); |
| | | // Map<String, String> geocode = gdMapGeocodingUtil.geocode(placementLon, placementLat); |
| | | // orderPrivateCar.setPlacementAddress(geocode.get("address")); |
| | | // orderPrivateCar.setStartLon(Double.valueOf(startLon)); |
| | | // orderPrivateCar.setStartLat(Double.valueOf(startLat)); |
| | | // orderPrivateCar.setStartAddress(startAddress); |
| | | // orderPrivateCar.setEndLon(Double.valueOf(endLon)); |
| | | // orderPrivateCar.setEndLat(Double.valueOf(endLat)); |
| | | // orderPrivateCar.setEndAddress(endAddress); |
| | | // orderPrivateCar.setSubstitute(instead); |
| | | // orderPrivateCar.setPassengers(name); |
| | | // orderPrivateCar.setPassengersPhone(phone); |
| | | // if(instead == 0 || ToolUtil.isEmpty(orderPrivateCar.getPassengers())){ |
| | | // UserInfo userInfo = userInfoService.selectById(uid); |
| | | // if(ToolUtil.isEmpty(userInfo.getPhone())){ |
| | | // return ResultUtil.error("请先绑定手机号码"); |
| | | // } |
| | | // orderPrivateCar.setPassengers(userInfo.getName()); |
| | | // orderPrivateCar.setPassengersPhone(userInfo.getPhone()); |
| | | // } |
| | | // orderPrivateCar.setState(1); |
| | | // orderPrivateCar.setInsertTime(new Date()); |
| | | // orderPrivateCar.setTravelTime(travelTime); |
| | | // orderPrivateCar.setOrderType(reservation); |
| | | // orderPrivateCar.setOrderSource(orderSource); |
| | | // orderPrivateCar.setEstimatedPrice(estimatedPrice); |
| | | // if(orderSource == 2){//扫码下单 |
| | | // Driver driver = driverService.selectById(driverId); |
| | | // if(null == driver){ |
| | | // return ResultUtil.error("司机信息有误,无法完成下单"); |
| | | // } |
| | | // if(driver.getAuthState() == 1){ |
| | | // return ResultUtil.error("司机信息还未完成审核,无法完成下单"); |
| | | // } |
| | | // if(driver.getAuthState() == 3){ |
| | | // return ResultUtil.error("司机账户已被冻结,无法提供服务"); |
| | | // } |
| | | // if(driver.getAuthState() == 4){ |
| | | // return ResultUtil.error("司机信息未通过审核,无法提供服务"); |
| | | // } |
| | | // if(driver.getState() == 1){ |
| | | // return ResultUtil.error("司机还未上线,无法提供服务"); |
| | | // } |
| | | // if(driver.getState() == 3){ |
| | | // return ResultUtil.error("司机正在服务中,无法提供服务"); |
| | | // } |
| | | // List<DriverService> query = driverServiceService.query(driverId, 1); |
| | | // if(query.size() == 0){ |
| | | // return ResultUtil.error("该司机不能服务此业务"); |
| | | // } |
| | | // |
| | | // orderPrivateCar.setDriverId(driverId); |
| | | // orderPrivateCar.setCompanyId(driver.getFranchiseeId() != null && driver.getFranchiseeId() != 0 ? driver.getFranchiseeId() : ( |
| | | // driver.getCompanyId() != null && driver.getCompanyId() != 0 ? driver.getCompanyId() : 1)); |
| | | // orderPrivateCar.setState(2); |
| | | // orderPrivateCar.setCarId(driver.getCarId()); |
| | | // CarService query1 = carServiceMapper.query(1, driver.getCarId()); |
| | | // orderPrivateCar.setServerCarModelId(query1.getServerCarModelId()); |
| | | // orderPrivateCar.setSnatchOrderTime(new Date()); |
| | | // |
| | | // //调用高德创建轨迹 |
| | | //// String s = gdFalconUtil.selectTerminal(driver.getPhone()); |
| | | //// String track = gdFalconUtil.createTrack(s); |
| | | //// JSONObject jsonObject = JSONObject.parseObject(track); |
| | | //// orderPrivateCar.setTrackId(String.valueOf(jsonObject.getInteger("trid"))); |
| | | // |
| | | // //调用移动的小号接口 |
| | | // /* Map<String, String> geocode1 = gdMapGeocodingUtil.geocode(orderPrivateCar.getStartLon().toString(), orderPrivateCar.getStartLat().toString()); |
| | | // Region region = regionMapper.query(geocode1.get("districtCode"));*/ |
| | | //// Map<String, String> map = chinaMobileUtil.midAxbBindSend(orderPrivateCar.getPassengersPhone(), driver.getPhone(), null); |
| | | //// if(String.valueOf(map.get("code")).equals("200")){ |
| | | //// orderPrivateCar.setTelX(map.get("telX")); |
| | | //// orderPrivateCar.setBindId(map.get("bindId")); |
| | | //// } |
| | | // |
| | | // driver.setState(3); |
| | | // driverService.updateById(driver); |
| | | // } |
| | | // |
| | | // orderPrivateCar.setIsReassign(1); |
| | | // orderPrivateCar.setIsDelete(1); |
| | | // this.insert(orderPrivateCar); |
| | | // |
| | | // if(orderSource == 2){//扫码下单 |
| | | // new Thread(new Runnable() { |
| | | // @Override |
| | | // public void run() { |
| | | // pushUtil.pushOrderState(1, uid, orderPrivateCar.getId(), 1, 2, 0); |
| | | // pushUtil.pushOrderState(2, orderPrivateCar.getDriverId(), orderPrivateCar.getId(), 1, 2, 0); |
| | | // pushUtil.pushDriverPosition(orderPrivateCar.getId(), 1); |
| | | // } |
| | | // }).start(); |
| | | // } |
| | | // |
| | | // |
| | | // // TODO: 2021/5/11 修改,根据后台设定的派单范围查询范围内有无司机,将单子指派给距离最近的司机(距离相同随机取),范围内没有司机再进行推单流程 |
| | | // if(orderPrivateCar.getState() == 1){ |
| | | // Company query = companyCityService.query(orderPrivateCar.getStartLon().toString(), orderPrivateCar.getStartLat().toString()); |
| | | // if(null == query){ |
| | | // return ResultUtil.error("起点暂未企业提供服务"); |
| | | // } |
| | | // AssignOrder assignOrder = assignOrderService.selectOne(new EntityWrapper<AssignOrder>().eq("companyId", query.getId()).eq("type", 1)); |
| | | // if(null != assignOrder){//配置了指派规则才处理 |
| | | // boolean lock = redisUtil.lock("order_lock", 10); |
| | | // if(!lock){ |
| | | // int num1 = 1; |
| | | // while (num1 <= 10){ |
| | | // Thread.sleep(3000);//等待3秒 |
| | | // lock = redisUtil.lock("order_lock", 10); |
| | | // if(lock){ |
| | | // break; |
| | | // }else{ |
| | | // num1++; |
| | | // } |
| | | // } |
| | | // } |
| | | // try { |
| | | // //获取空闲司机 |
| | | // List<Driver> drivers = driverService.queryIdleDriver(1, orderPrivateCar.getServerCarModelId(), orderPrivateCar.getStartLon(), orderPrivateCar.getStartLat(), assignOrder.getDistance(), null);//获取范围内空闲司机 |
| | | // List<Integer> driverIds = drivers.stream().map(Driver::getId).collect(Collectors.toList()); |
| | | // if(drivers.size() > 0) {//有司机,直接指派给司机 |
| | | // Driver dr = null; |
| | | // if (drivers.size() > 1) { |
| | | // List<Driver> ds = new ArrayList<>();//存储直线距离最近的几个司机 |
| | | // for (int i = 0; i < assignOrder.getPeople(); i++) { |
| | | // Driver driver = null; |
| | | // int m = 0; |
| | | // int index = 0; |
| | | // // 查询预约单 |
| | | // List<OrderPrivateCar> orderPrivateCarss = orderPrivateCarMapper.queryOrderByState(driverIds, 2, 1, 2, 3, 4, 5, 6, 11); |
| | | // List<Integer> orderPrivateCarDriverIds = orderPrivateCars.stream().map(OrderPrivateCar::getDriverId).collect(Collectors.toList()); |
| | | // for (int j = 0; j < drivers.size(); j++) { |
| | | // Driver driver1 = drivers.get(j); |
| | | // if (orderPrivateCar.getOrderType() == 2 && orderPrivateCarDriverIds.contains(driver.getId())) { |
| | | // continue; |
| | | // } |
| | | // // 判断该司机是否有30分钟内预约单 |
| | | // long count = orderPrivateCarss.stream().filter(s -> s.getDriverId().equals(driver1.getId()) && |
| | | // DateUtil.dateToLocalDateTime(s.getTravelTime()).minusMinutes(query.getLimitationTime()).isBefore(LocalDateTime.now())).count(); |
| | | // if (count > 0) { |
| | | // continue; |
| | | // } |
| | | // String value = redisUtil.getValue("DRIVER" + drivers.get(j).getId()); |
| | | // if (null != value) { |
| | | //// Map<String, String> distance1 = gdMapElectricFenceUtil.getDistance(orderPrivateCar.getStartLon() + "," + orderPrivateCar.getStartLat(), value, 0);//计算距离 |
| | | //// Integer d = Integer.valueOf(distance1.get("distance")); |
| | | // String[] split = value.split(","); |
| | | // double distance = GDMapGeocodingUtil.getDistance(orderPrivateCar.getStartLat(), orderPrivateCar.getStartLon(), Double.valueOf(split[1]), Double.valueOf(split[0])); |
| | | // int d = Double.valueOf(distance).intValue(); |
| | | // if ((0 == m && null == driver) || (d < m)) { |
| | | // driver = drivers.get(j); |
| | | // m = d; |
| | | // index = j; |
| | | // } |
| | | // } |
| | | // } |
| | | // ds.add(driver); |
| | | // drivers.remove(index); |
| | | // } |
| | | // |
| | | // //再根据直线距离最短的司机中找出行驶距离最短的司机 |
| | | // Integer m = 0; |
| | | // for (Driver driver : ds) { |
| | | // String value = redisUtil.getValue("DRIVER" + driver.getId()); |
| | | // if (null != value) { |
| | | // Map<String, String> distance1 = gdMapElectricFenceUtil.getDistance(orderPrivateCar.getStartLon() + "," + orderPrivateCar.getStartLat(), value, 1);//计算距离 |
| | | // Integer d = Integer.valueOf(distance1.get("distance")); |
| | | // if ((0 == m && null == dr) || (d.intValue() < m.intValue())) { |
| | | // dr = driver; |
| | | // m = d; |
| | | // } |
| | | // } |
| | | // } |
| | | // } else { |
| | | // List<OrderPrivateCar> orderPrivateCarss = orderPrivateCarMapper.queryOrderByState(driverIds, 2, 1, 2, 3, 4, 5, 6, 11); |
| | | // if (orderPrivateCarss.size() == 0) { |
| | | // dr = drivers.get(0); |
| | | // } |
| | | // } |
| | | // |
| | | // if (Objects.nonNull(dr)) { |
| | | // orderPrivateCar.setDriverId(dr.getId()); |
| | | // orderPrivateCar.setCompanyId(dr.getFranchiseeId() != null && dr.getFranchiseeId() != 0 ? dr.getFranchiseeId() : ( |
| | | // dr.getCompanyId() != null && dr.getCompanyId() != 0 ? dr.getCompanyId() : 1)); |
| | | // orderPrivateCar.setState(2); |
| | | // orderPrivateCar.setCarId(dr.getCarId()); |
| | | // CarService query1 = carServiceMapper.query(1, dr.getCarId()); |
| | | // orderPrivateCar.setServerCarModelId(query1.getServerCarModelId()); |
| | | // orderPrivateCar.setSnatchOrderTime(new Date()); |
| | | // if (orderPrivateCar.getOrderType() != 2) { |
| | | // dr.setState(3); |
| | | // } |
| | | // driverService.updateById(dr); |
| | | // new Thread(new Runnable() { |
| | | // @Override |
| | | // public void run() { |
| | | // pushUtil.pushOrderState(1, uid, orderPrivateCar.getId(), 1, 2, 0); |
| | | // pushUtil.pushOrderState(2, orderPrivateCar.getDriverId(), orderPrivateCar.getId(), 1, 2, 0); |
| | | // pushUtil.pushDriverPosition(orderPrivateCar.getId(), 1); |
| | | // } |
| | | // }).start(); |
| | | // } |
| | | // |
| | | // |
| | | // //调用高德创建轨迹 |
| | | //// String s = gdFalconUtil.selectTerminal(dr.getPhone()); |
| | | //// String track = gdFalconUtil.createTrack(s); |
| | | //// orderPrivateCar.setTrackId(track); |
| | | // |
| | | // //调用移动的小号接口 |
| | | // /* Map<String, String> geocode1 = gdMapGeocodingUtil.geocode(orderPrivateCar.getStartLon().toString(), orderPrivateCar.getStartLat().toString()); |
| | | // Region region = regionMapper.query(geocode1.get("districtCode"));*/ |
| | | //// Map<String, String> map = chinaMobileUtil.midAxbBindSend(orderPrivateCar.getPassengersPhone(), dr.getPhone(), null); |
| | | //// if(String.valueOf(map.get("code")).equals("200")){ |
| | | //// orderPrivateCar.setTelX(map.get("telX")); |
| | | //// orderPrivateCar.setBindId(map.get("bindId")); |
| | | //// } |
| | | // |
| | | // this.updateById(orderPrivateCar); |
| | | // |
| | | // //发送短信给司机 |
| | | //// aLiSendSms.sendSms(dr.getPhone(), "SMS_216832951", "{\"" + orderPrivateCar.getStartAddress() + "\"}"); |
| | | // } |
| | | // }catch (Exception e){ |
| | | // e.printStackTrace(); |
| | | // }finally { |
| | | // redisUtil.unlock("order_lock"); |
| | | // } |
| | | // } |
| | | // } |
| | | // |
| | | // |
| | | // //推单操作 |
| | | // if(orderPrivateCar.getState() == 1){ |
| | | // this.pushOrder(orderPrivateCar); |
| | | // } |
| | | // |
| | | // |
| | | // //添加消息 |
| | | // systemNoticeService.addSystemNotice(1, "您的专车订单已下单成功,我们正在为您指派司机,请稍后!", orderPrivateCar.getUserId(), 1); |
| | | // |
| | | // BaseWarpper baseWarpper = new BaseWarpper(); |
| | | // baseWarpper.setState(orderPrivateCar.getState()); |
| | | // baseWarpper.setId(orderPrivateCar.getId()); |
| | | // return ResultUtil.success(baseWarpper); |
| | | // } |
| | | |
| | | |
| | | /** |
| | |
| | | if(null == orderPrivateCar){ |
| | | return ResultUtil.error("取消订单失败,订单信息有误"); |
| | | } |
| | | if(orderPrivateCar.getState() > 5 && orderPrivateCar.getState() != 11){ |
| | | if(orderPrivateCar.getPayMethod() == 0 && orderPrivateCar.getPaymentAdvanceMoney()>0 && orderPrivateCar.getState() > 5 && orderPrivateCar.getState() != 11){ |
| | | return ResultUtil.error("取消订单失败,当前状态无法取消"); |
| | | } |
| | | if(orderPrivateCar.getPayMethod() == 1 && orderPrivateCar.getState() > 5 && orderPrivateCar.getState() != 11){ |
| | | return ResultUtil.error("取消订单失败,不合法的操作"); |
| | | } |
| | | if(null == orderPrivateCar.getDriverId()){//没有接单的情况 |
| | |
| | | */ |
| | | @Override |
| | | public ResultUtil cancleOrderPrivateCar(Integer id, Integer payType, Integer cancleId, Integer type) throws Exception { |
| | | OrderPrivateCar orderPrivateCar = this.selectById(id); |
| | | Integer uid = orderPrivateCar.getUserId(); |
| | | UserInfo userInfo = userInfoService.selectById(uid); |
| | | ResultUtil resultUtil = ResultUtil.success(""); |
| | | |
| | | if(null == orderPrivateCar){ |
| | | return ResultUtil.error("取消订单失败,订单信息有误", ""); |
| | | } |
| | | if(orderPrivateCar.getState() != 12){ |
| | | return ResultUtil.error("取消订单失败,不合法的操作", ""); |
| | | } |
| | | OrderCancel orderCancel = null; |
| | | if(null == cancleId || cancleId==0){ |
| | | orderCancel = orderCancelService.query(id, 1, null, null, 1); |
| | | }else{ |
| | | orderCancel = orderCancelService.selectById(cancleId); |
| | | } |
| | | |
| | | CancleOrder query = cancleOrderService.query(orderPrivateCar.getOrderType(), 1, orderPrivateCar.getCompanyId()); |
| | | if(null != query){ |
| | | String code = id + "_1_" + UUIDUtil.getRandomCode(3); |
| | | if(payType == 1){//微信支付 |
| | | if(ToolUtil.isEmpty(userInfo.getAppletsOpenId())){ |
| | | return ResultUtil.error("未授权微信,无法完成支付"); |
| | | boolean lock = redisUtil.lock(id + "_cancleOrder", 10); |
| | | if(!lock){ |
| | | int num1 = 1; |
| | | while (num1 <= 10){ |
| | | Thread.sleep(3000);//等待3秒 |
| | | lock = redisUtil.lock(id + "_cancleOrder", 10); |
| | | if(lock){ |
| | | break; |
| | | }else{ |
| | | num1++; |
| | | } |
| | | orderCancel.setPayType(1); |
| | | orderCancelService.updateById(orderCancel); |
| | | resultUtil = payMoneyUtil.weixinpay("订单取消",id +"",code,query.getMoney()+"","/base/wxCancelOrderTaxi","JSAPI",userInfo.getAppletsOpenId()); |
| | | if(resultUtil.getCode()==200){ |
| | | paymentRecordService.saveData(1, null, null, id, 1, 1, query.getMoney(), null, 1, code);//添加预支付数据 |
| | | new Thread(()->{ |
| | | int num = 1; |
| | | int min = 5000; |
| | | int w = 0; |
| | | while (num <= 10) { |
| | | try { |
| | | w += min * num; |
| | | OrderPrivateCar orderPrivateCar1 = orderPrivateCarMapper.selectById(id); |
| | | if (orderPrivateCar1.getState() == 10) { |
| | | break; |
| | | } |
| | | ResultUtil<Map<String, Object>> resultUtil1 = payMoneyUtil.queryWXOrder("", code, "JSAPI"); |
| | | if (resultUtil1.getCode() == 200) { |
| | | /** |
| | | * SUCCESS--支付成功 |
| | | * REFUND--转入退款 |
| | | * NOTPAY--未支付 |
| | | * CLOSED--已关闭 |
| | | * REVOKED--已撤销(刷卡支付) |
| | | * USERPAYING--用户支付中 |
| | | * PAYERROR--支付失败(其他原因,如银行返回失败) |
| | | * ACCEPT--已接收,等待扣款 |
| | | */ |
| | | String s = resultUtil1.getData().get("trade_state").toString(); |
| | | if ("REFUND".equals(s) || "CLOSED".equals(s) || "REVOKED".equals(s) || "PAYERROR".equals(s) || num == 10) { |
| | | } |
| | | } |
| | | ResultUtil resultUtil = ResultUtil.success(""); |
| | | try { |
| | | OrderPrivateCar orderPrivateCar = this.selectById(id); |
| | | Integer uid = orderPrivateCar.getUserId(); |
| | | UserInfo userInfo = userInfoService.selectById(uid); |
| | | |
| | | if(null == orderPrivateCar){ |
| | | return ResultUtil.error("取消订单失败,订单信息有误", ""); |
| | | } |
| | | if(orderPrivateCar.getState() != 12){ |
| | | return ResultUtil.error("取消订单失败,不合法的操作", ""); |
| | | } |
| | | OrderCancel orderCancel = null; |
| | | if(null == cancleId || cancleId==0){ |
| | | orderCancel = orderCancelService.query(id, 1, null, null, 1); |
| | | }else{ |
| | | orderCancel = orderCancelService.selectById(cancleId); |
| | | } |
| | | |
| | | CancleOrder query = cancleOrderService.query(orderPrivateCar.getOrderType(), 1, orderPrivateCar.getCompanyId()); |
| | | if(null != query){ |
| | | String code = id + "_1_" + UUIDUtil.getRandomCode(3); |
| | | if(payType == 1){//微信支付 |
| | | if(ToolUtil.isEmpty(userInfo.getAppletsOpenId())){ |
| | | return ResultUtil.error("未授权微信,无法完成支付"); |
| | | } |
| | | orderCancel.setPayType(1); |
| | | orderCancelService.updateById(orderCancel); |
| | | resultUtil = payMoneyUtil.weixinpay("订单取消",id +"",code,query.getMoney()+"","/base/wxCancelOrderTaxi","JSAPI",userInfo.getAppletsOpenId()); |
| | | if(resultUtil.getCode()==200){ |
| | | paymentRecordService.saveData(1, null, null, id, 1, 1, query.getMoney(), null, 1, code);//添加预支付数据 |
| | | new Thread(()->{ |
| | | int num = 1; |
| | | int min = 5000; |
| | | int w = 0; |
| | | while (num <= 10) { |
| | | try { |
| | | w += min * num; |
| | | OrderPrivateCar orderPrivateCar1 = orderPrivateCarMapper.selectById(id); |
| | | if (orderPrivateCar1.getState() == 10) { |
| | | break; |
| | | } |
| | | if ("SUCCESS".equals(s) || "ACCEPT".equals(s)) { |
| | | String transaction_id = resultUtil1.getData().get("transaction_id").toString(); |
| | | payCancelOrderPrivateCar(id, transaction_id, 1); |
| | | break; |
| | | } |
| | | if ("NOTPAY".equals(s) || "USERPAYING".equals(s)) { |
| | | ResultUtil<Map<String, Object>> resultUtil1 = payMoneyUtil.queryWXOrder("", code, "JSAPI"); |
| | | if (resultUtil1.getCode() == 200) { |
| | | /** |
| | | * SUCCESS--支付成功 |
| | | * REFUND--转入退款 |
| | | * NOTPAY--未支付 |
| | | * CLOSED--已关闭 |
| | | * REVOKED--已撤销(刷卡支付) |
| | | * USERPAYING--用户支付中 |
| | | * PAYERROR--支付失败(其他原因,如银行返回失败) |
| | | * ACCEPT--已接收,等待扣款 |
| | | */ |
| | | String s = resultUtil1.getData().get("trade_state").toString(); |
| | | if ("REFUND".equals(s) || "CLOSED".equals(s) || "REVOKED".equals(s) || "PAYERROR".equals(s) || num == 10) { |
| | | break; |
| | | } |
| | | if ("SUCCESS".equals(s) || "ACCEPT".equals(s)) { |
| | | String transaction_id = resultUtil1.getData().get("transaction_id").toString(); |
| | | payCancelOrderPrivateCar(id, transaction_id, 1); |
| | | break; |
| | | } |
| | | if ("NOTPAY".equals(s) || "USERPAYING".equals(s)) { |
| | | Thread.sleep(w); |
| | | num++; |
| | | } |
| | | } else { |
| | | Thread.sleep(w); |
| | | num++; |
| | | } |
| | | } else { |
| | | Thread.sleep(w); |
| | | num++; |
| | | }catch (Exception e){ |
| | | e.printStackTrace(); |
| | | } |
| | | }catch (Exception e){ |
| | | e.printStackTrace(); |
| | | } |
| | | } |
| | | }).start(); |
| | | |
| | | }else{ |
| | | resultUtil = ResultUtil.error("支付失败", ""); |
| | | }).start(); |
| | | |
| | | }else{ |
| | | resultUtil = ResultUtil.error("支付失败", ""); |
| | | } |
| | | |
| | | } |
| | | |
| | | } |
| | | if(payType == 2){//支付宝支付 |
| | | orderCancel.setPayType(2); |
| | | orderCancelService.updateById(orderCancel); |
| | | resultUtil = payMoneyUtil.alipay("订单取消","订单取消", "",code,query.getMoney()+"","/base/aliCancelOrderTaxi"); |
| | | if(resultUtil.getCode()==200){ |
| | | paymentRecordService.saveData(1, null, null, id, 1, 2, query.getMoney(), null, 1, code);//添加预支付数据 |
| | | resultUtil = resultUtil; |
| | | }else{ |
| | | resultUtil = ResultUtil.error("支付失败", ""); |
| | | if(payType == 2){//支付宝支付 |
| | | orderCancel.setPayType(2); |
| | | orderCancelService.updateById(orderCancel); |
| | | resultUtil = payMoneyUtil.alipay("订单取消","订单取消", "",code,query.getMoney()+"","/base/aliCancelOrderTaxi"); |
| | | if(resultUtil.getCode()==200){ |
| | | paymentRecordService.saveData(1, null, null, id, 1, 2, query.getMoney(), null, 1, code);//添加预支付数据 |
| | | resultUtil = resultUtil; |
| | | }else{ |
| | | resultUtil = ResultUtil.error("支付失败", ""); |
| | | } |
| | | } |
| | | } |
| | | if(payType == 3){//余额支付 |
| | | if(userInfo.getBalance() != null && userInfo.getBalance() < query.getMoney()){ |
| | | return ResultUtil.error("余额不足,无法完成支付", ""); |
| | | } |
| | | |
| | | userInfo.setBalance(new BigDecimal(userInfo.getBalance()).subtract(new BigDecimal(query.getMoney())).setScale(2, BigDecimal.ROUND_HALF_EVEN).doubleValue()); |
| | | //添加交易明细 |
| | | transactionDetailsService.saveData(uid, "取消订单", query.getMoney(), 2, 1, 1, 1, id); |
| | | userInfoService.updateById(userInfo); |
| | | |
| | | //解除小号绑定 |
| | | if(payType == 3){//余额支付 |
| | | if(userInfo.getBalance() != null && userInfo.getBalance() < query.getMoney()){ |
| | | return ResultUtil.error("余额不足,无法完成支付", ""); |
| | | } |
| | | userInfo.setBalance(new BigDecimal(userInfo.getBalance()).subtract(new BigDecimal(query.getMoney())).setScale(2, BigDecimal.ROUND_HALF_EVEN).doubleValue()); |
| | | //添加交易明细 |
| | | transactionDetailsService.saveData(uid, "取消订单", query.getMoney(), 2, 1, 1, 1, id); |
| | | userInfoService.updateById(userInfo); |
| | | |
| | | //解除小号绑定 |
| | | // if(orderPrivateCar.getBindId() != null){ |
| | | // chinaMobileUtil.midAxbUnBindSend(orderPrivateCar.getBindId(),orderPrivateCar.getTelX()); |
| | | // } |
| | | |
| | | orderPrivateCar.setState(10); |
| | | orderPrivateCar.setTelX(""); |
| | | orderPrivateCar.setBindId(""); |
| | | this.updateById(orderPrivateCar); |
| | | |
| | | orderCancel.setState(2); |
| | | orderCancel.setPayType(3); |
| | | orderCancelService.updateById(orderCancel); |
| | | |
| | | //添加已收入明细 |
| | | incomeService.saveData(1, orderPrivateCar.getCompanyId(), 3, orderPrivateCar.getId(), 1, query.getMoney()); |
| | | //添加已收入明细 |
| | | Company company = companyService.selectById(orderPrivateCar.getCompanyId()); |
| | | Double taxi = company.getSpeMoney(); |
| | | BigDecimal c =new BigDecimal(query.getMoney());//司机收入 |
| | | Driver driver = driverService.selectById(orderPrivateCar.getDriverId()); |
| | | driver.setBusinessMoney(new BigDecimal(null != driver.getBusinessMoney() ? driver.getBusinessMoney() : 0).add(c).setScale(2, BigDecimal.ROUND_HALF_EVEN).doubleValue()); |
| | | 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); |
| | | incomeService.saveDriverData(2, orderPrivateCar.getDriverId(), 3, orderPrivateCar.getId(), 1, c.doubleValue(),driver.getLaveBusinessMoney()); |
| | | |
| | | orderPrivateCar.setState(10); |
| | | orderPrivateCar.setTelX(""); |
| | | orderPrivateCar.setBindId(""); |
| | | this.updateById(orderPrivateCar); |
| | | |
| | | orderCancel.setState(2); |
| | | orderCancel.setPayType(3); |
| | | orderCancelService.updateById(orderCancel); |
| | | |
| | | //添加已收入明细 |
| | | incomeService.saveData(1, orderPrivateCar.getCompanyId(), 3, orderPrivateCar.getId(), 1, query.getMoney()); |
| | | //添加已收入明细 |
| | | Company company = companyService.selectById(orderPrivateCar.getCompanyId()); |
| | | Double taxi = company.getSpeMoney(); |
| | | BigDecimal c =new BigDecimal(query.getMoney());//司机收入 |
| | | incomeService.saveData(2, orderPrivateCar.getDriverId(), 3, orderPrivateCar.getId(), 1, c.doubleValue()); |
| | | Driver driver = driverService.selectById(orderPrivateCar.getDriverId()); |
| | | driver.setBusinessMoney(new BigDecimal(null != driver.getBusinessMoney() ? driver.getBusinessMoney() : 0).add(c).setScale(2, BigDecimal.ROUND_HALF_EVEN).doubleValue()); |
| | | 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); |
| | | |
| | | this.deleteTask(id);//删除定时任务 |
| | | this.deleteTask(id);//删除定时任务 |
| | | |
| | | // new Thread(new Runnable() { |
| | | // @Override |
| | |
| | | // pushUtil.pushOrderState(2, orderPrivateCar.getDriverId(), orderPrivateCar.getId(), 1, orderPrivateCar.getState(), 0); |
| | | // } |
| | | // }).start(); |
| | | |
| | | //添加消息 |
| | | systemNoticeService.addSystemNotice(1, "您已使用余额成功支付取消订单费用,谢谢使用!", orderPrivateCar.getUserId(), 1); |
| | | |
| | | //添加消息 |
| | | systemNoticeService.addSystemNotice(1, "您已使用余额成功支付取消订单费用,谢谢使用!", orderPrivateCar.getUserId(), 1); |
| | | } |
| | | } |
| | | }catch (Exception e){ |
| | | e.printStackTrace(); |
| | | }finally { |
| | | redisUtil.unlock(id + "_cancleOrder"); |
| | | } |
| | | return resultUtil; |
| | | } |
| | |
| | | for(int i = 1; i <= querys.size(); i++){ |
| | | PushOrder pushOrder = pushOrderService.querys(i, 1, query.getId()).get(0); |
| | | //获取空闲司机 |
| | | // List<Driver> list = driverService.queryIdleDriver(1, orderPrivateCar.getServerCarModelId(), orderPrivateCar.getStartLon(), orderPrivateCar.getStartLat(), pushOrder.getPushDistance(), null);//所有附近空闲司机 |
| | | List<Driver> list = driverService.queryIdleDriver(1, orderPrivateCar.getServerCarModelId(), orderPrivateCar.getStartLon(), orderPrivateCar.getStartLat(), pushOrder.getPushDistance(), null);//所有附近空闲司机 |
| | | List<Driver> list1 = driverService.queryIdleDriver_(1, orderPrivateCar.getServerCarModelId(), orderPrivateCar.getStartLon(), orderPrivateCar.getStartLat(), 2.0D, null);//所有附近空闲司机 |
| | | list.addAll(list1); |
| | | list = list.stream().distinct().collect(Collectors.toList()); |
| | | if(list.size() > 0){ |
| | | // 查询预约单 |
| | | List<Integer> driverIds = list.stream().map(Driver::getId).collect(Collectors.toList()); |
| | |
| | | for(Driver driver : list){//开始进行推送 |
| | | // 判断该司机是否有30分钟内预约单 |
| | | long count = orderPrivateCars.stream().filter(orderPrivateCar1 -> driver.getId().equals(orderPrivateCar1.getDriverId()) |
| | | && DateUtil.dateToLocalDateTime(orderPrivateCar1.getTravelTime()).minusMinutes(30).isBefore(LocalDateTime.now()) |
| | | && DateUtil.dateToLocalDateTime(orderPrivateCar1.getTravelTime()).isAfter(LocalDateTime.now())).count(); |
| | | if(orderPrivateCar.getOrderType() == 2 && orderPrivateCarDriverIds.contains(driver.getId())){ |
| | | continue; |
| | | } |
| | | && DateUtil.dateToLocalDateTime(orderPrivateCar1.getTravelTime()).minusMinutes(query.getLimitationTime()).isBefore(LocalDateTime.now())).count(); |
| | | // if(orderPrivateCar.getOrderType() == 2 && orderPrivateCarDriverIds.contains(driver.getId())){ |
| | | // continue; |
| | | // } |
| | | if(count > 0){ |
| | | continue; |
| | | } |
| | |
| | | if(i == querys.size() && state == 1){ |
| | | pushUtil.pushEndPush(1, orderPrivateCar.getUserId(), orderPrivateCar.getId(), 1); |
| | | orderIds.remove(orderPrivateCar.getId()); |
| | | |
| | | // 第三轮取消订单 |
| | | orderPrivateCar.setState(10); |
| | | orderPrivateCarMapper.updateById(orderPrivateCar); |
| | | pushUtil.pushOrderState(1, orderPrivateCar.getUserId(), orderPrivateCar.getId(), 1, orderPrivateCar.getState(), 0); |
| | | // 添加站内信 |
| | | systemNoticeService.addSystemNotice(1, "当前区域未能及时为您匹配到合适车辆。为避免耽误您的行程,系统已自动取消订单,建议您稍后重新尝试。", orderPrivateCar.getUserId(), 1); |
| | | // 查询是否开启短信通知 |
| | | AppOpenInfo appOpenInfo = appOpenInfoService.selectOne(new EntityWrapper<AppOpenInfo>() |
| | | .eq("type", 3)); |
| | | if(Objects.nonNull(appOpenInfo) && appOpenInfo.getIsOpen() == 1){ |
| | | // 添加短信发送 |
| | | //发送记录集合 |
| | | JSONArray records = new JSONArray(); |
| | | JSONObject record = new JSONObject(); |
| | | UserInfo userInfo = userInfoService.selectById(orderPrivateCar.getUserId()); |
| | | //手机号 |
| | | record.put("mobile", userInfo.getPhone()); |
| | | //替换变量 |
| | | JSONObject param = new JSONObject(); |
| | | record.put("tpContent", param); |
| | | records.add(record); |
| | | SMSUtil.sendSmsTp(380702L, records); |
| | | } |
| | | } |
| | | } |
| | | } catch (Exception e) { |
| | |
| | | return ResultUtil.error("订单不在待支付状态,不允许支付", ""); |
| | | } |
| | | PaymentRecord query3 = paymentRecordService.query(1, null, null, orderId, 1, null, 1); |
| | | if(null != query3){ |
| | | ResultUtil<Map<String, Object>> resultUtil1 = payMoneyUtil.queryWXOrder("", query3.getSerialNumber(), "JSAPI"); |
| | | if (resultUtil1.getCode() == 200) { |
| | | /** |
| | | * SUCCESS--支付成功 |
| | | * REFUND--转入退款 |
| | | * NOTPAY--未支付 |
| | | * CLOSED--已关闭 |
| | | * REVOKED--已撤销(刷卡支付) |
| | | * USERPAYING--用户支付中 |
| | | * PAYERROR--支付失败(其他原因,如银行返回失败) |
| | | * ACCEPT--已接收,等待扣款 |
| | | */ |
| | | String result_code = resultUtil1.getData().get("result_code").toString(); |
| | | if("SUCCESS".equals(result_code)){ |
| | | String s = resultUtil1.getData().get("trade_state").toString(); |
| | | if ("REFUND".equals(s) || "CLOSED".equals(s) || "REVOKED".equals(s) || "PAYERROR".equals(s)) { |
| | | payMoneyUtil.closeWXOrder(query3.getSerialNumber()); |
| | | paymentRecordService.deleteById(query3.getId()); |
| | | } |
| | | if ("SUCCESS".equals(s) || "ACCEPT".equals(s)) { |
| | | return ResultUtil.error("不允许重复支付"); |
| | | } |
| | | if ("NOTPAY".equals(s) || "USERPAYING".equals(s)) { |
| | | payMoneyUtil.closeWXOrder(query3.getSerialNumber()); |
| | | paymentRecordService.deleteById(query3.getId()); |
| | | } |
| | | } |
| | | } |
| | | } |
| | | // if(null != query3){ |
| | | // ResultUtil<Map<String, Object>> resultUtil1 = payMoneyUtil.queryWXOrder("", query3.getSerialNumber(), "JSAPI"); |
| | | // if (resultUtil1.getCode() == 200) { |
| | | // /** |
| | | // * SUCCESS--支付成功 |
| | | // * REFUND--转入退款 |
| | | // * NOTPAY--未支付 |
| | | // * CLOSED--已关闭 |
| | | // * REVOKED--已撤销(刷卡支付) |
| | | // * USERPAYING--用户支付中 |
| | | // * PAYERROR--支付失败(其他原因,如银行返回失败) |
| | | // * ACCEPT--已接收,等待扣款 |
| | | // */ |
| | | // String result_code = resultUtil1.getData().get("result_code").toString(); |
| | | // if("SUCCESS".equals(result_code)){ |
| | | // String s = resultUtil1.getData().get("trade_state").toString(); |
| | | // if ("REFUND".equals(s) || "CLOSED".equals(s) || "REVOKED".equals(s) || "PAYERROR".equals(s)) { |
| | | // payMoneyUtil.closeWXOrder(query3.getSerialNumber()); |
| | | // paymentRecordService.deleteById(query3.getId()); |
| | | // } |
| | | // if ("SUCCESS".equals(s) || "ACCEPT".equals(s)) { |
| | | // return ResultUtil.error("不允许重复支付"); |
| | | // } |
| | | // if ("NOTPAY".equals(s) || "USERPAYING".equals(s)) { |
| | | // payMoneyUtil.closeWXOrder(query3.getSerialNumber()); |
| | | // paymentRecordService.deleteById(query3.getId()); |
| | | // } |
| | | // } |
| | | // } |
| | | // } |
| | | |
| | | |
| | | |
| | | Integer uid = orderPrivateCar.getUserId(); |
| | | Double orderMoney = orderPrivateCar.getOrderMoney(); |
| | | System.out.println("=========================订单金额====================="+orderMoney); |
| | | if(Objects.nonNull(orderPrivateCar.getPaymentAdvanceMoney()) && orderPrivateCar.getPaymentAdvanceMoney() > 0){ |
| | | double couponMoney1 = Objects.nonNull(orderPrivateCar.getCouponMoney()) ? orderPrivateCar.getCouponMoney() : 0.00; |
| | | orderMoney = orderMoney - orderPrivateCar.getPaymentAdvanceMoney() - couponMoney1; |
| | | System.out.println("=========================减去先付后金额====================="+orderMoney); |
| | | } |
| | | UserInfo userInfo = userInfoService.selectById(uid); |
| | | ResultUtil resultUtil = ResultUtil.success(new HashMap<>()); |
| | | orderPrivateCar.setCouponMoney(0D);//初始化历史数据 |
| | |
| | | if(userInfo.getBalance() == null || userInfo.getBalance() < orderMoney){ |
| | | return ResultUtil.error("余额不足,无法完成支付", ""); |
| | | } |
| | | |
| | | |
| | | userInfo.setBalance(new BigDecimal(userInfo.getBalance()).subtract(new BigDecimal(orderMoney)).setScale(2, BigDecimal.ROUND_HALF_EVEN).doubleValue()); |
| | | |
| | | SysIntegral query1 = sysIntegralMapper.query(orderPrivateCar.getCompanyId()); |
| | | userInfo.setIntegral(userInfo.getIntegral() + (orderMoney.intValue() * query1.getIntegral()));//积分 |
| | | |
| | | |
| | | // SysIntegral query1 = sysIntegralMapper.query(orderPrivateCar.getCompanyId()); |
| | | // if(Objects.nonNull(query1)){ |
| | | // userInfo.setIntegral(userInfo.getIntegral() + (orderMoney.intValue() * query1.getIntegral()));//积分 |
| | | // } |
| | | |
| | | //添加交易明细 |
| | | transactionDetailsService.saveData(uid, "完成订单", orderMoney, 2, 1, 1, 1, orderId); |
| | | userInfoService.updateById(userInfo); |
| | | |
| | | orderPrivateCar.setState(8); |
| | | |
| | | // orderPrivateCar.setState(8); |
| | | orderPrivateCar.setPayType(3); |
| | | orderPrivateCar.setPayMoney(orderMoney); |
| | | orderPrivateCar.setOrderMoney(orderPrivateCar.getOrderMoney()+orderPrivateCar.getFreeMoney().doubleValue()); |
| | | // orderPrivateCar.setPayMoney(orderMoney); |
| | | // orderPrivateCar.setOrderMoney(orderPrivateCar.getOrderMoney()+orderPrivateCar.getFreeMoney().doubleValue()); |
| | | |
| | | //处理优惠券和红包 |
| | | if(null != userCouponRecord){ |
| | |
| | | query.setEndTime(new Date()); |
| | | userRedPacketRecordService.updateById(query); |
| | | } |
| | | if(orderPrivateCar.getIsplatPay()==1){ |
| | | //添加已收入明细 |
| | | Company company = companyService.selectById(orderPrivateCar.getCompanyId()); |
| | | Double speMoney = company.getSpeMoney(); |
| | | BigDecimal d = null;//企业收入 |
| | | BigDecimal c = null;//司机收入 |
| | | if(company.getIsSpeFixedOrProportional() == 2){//固定 |
| | | d = new BigDecimal(speMoney); |
| | | c = new BigDecimal(orderPrivateCar.getOrderMoney()).subtract(d);//只有出行金额参与抽成,其余归属司机 |
| | | |
| | | if(orderPrivateCar.getPayMethod() == 0){ |
| | | // 先付 |
| | | if(Objects.nonNull(orderPrivateCar.getPaymentAdvanceMoney()) && orderPrivateCar.getPaymentAdvanceMoney() > 0){ |
| | | orderPrivateCar.setPayMoney(new BigDecimal(orderMoney).add(new BigDecimal(orderPrivateCar.getPaymentAdvanceMoney())).doubleValue()); |
| | | orderPrivateCar.setOrderMoney(orderPrivateCar.getPayMoney()); |
| | | |
| | | SysIntegral query1 = sysIntegralMapper.query(orderPrivateCar.getCompanyId()); |
| | | if(Objects.nonNull(query1)){ |
| | | userInfo.setIntegral(userInfo.getIntegral() + (orderMoney.intValue() * query1.getIntegral()));//积分 |
| | | } |
| | | //添加已收入明细 |
| | | Company company = companyService.selectById(orderPrivateCar.getCompanyId()); |
| | | Double speMoney = company.getSpeMoney(); |
| | | BigDecimal d = null;//企业收入 |
| | | BigDecimal c = null;//司机收入 |
| | | if(company.getIsSpeFixedOrProportional() == 2){//固定 |
| | | d = new BigDecimal(speMoney); |
| | | c = new BigDecimal(orderPrivateCar.getOrderMoney()).subtract(d);//只有出行金额参与抽成,其余归属司机 |
| | | if(c.compareTo(BigDecimal.ZERO)<1){ |
| | | c = BigDecimal.ZERO; |
| | | } |
| | | } |
| | | if(company.getIsSpeFixedOrProportional() == 1){//比例 |
| | | Double price = orderPrivateCar.getStartMoney() + orderPrivateCar.getMileageMoney() + orderPrivateCar.getWaitMoney() + orderPrivateCar.getDurationMoney() + orderPrivateCar.getLongDistanceMoney(); |
| | | d = new BigDecimal(price).multiply(new BigDecimal(speMoney).divide(new BigDecimal(100), new MathContext(2, RoundingMode.HALF_EVEN))).setScale(2, BigDecimal.ROUND_HALF_EVEN); |
| | | c = new BigDecimal(orderPrivateCar.getOrderMoney()).subtract(d).setScale(2, BigDecimal.ROUND_HALF_EVEN); |
| | | } |
| | | incomeService.saveData(1, orderPrivateCar.getCompanyId(), 2, orderPrivateCar.getId(), 1, d.doubleValue()); |
| | | Driver driver = driverService.selectById(orderPrivateCar.getDriverId()); |
| | | driver.setBusinessMoney(new BigDecimal(null != driver.getBusinessMoney() ? driver.getBusinessMoney() : 0).add(c).setScale(2, BigDecimal.ROUND_HALF_EVEN).doubleValue()); |
| | | 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); |
| | | incomeService.saveDriverData(2, orderPrivateCar.getDriverId(), 2, orderPrivateCar.getId(), 1, c.doubleValue(), driver.getLaveBusinessMoney()); |
| | | orderPrivateCar.setState(8); |
| | | }else { |
| | | if(orderPrivateCar.getOrderSource() == 2){ |
| | | orderPrivateCar.setState(2); |
| | | }else { |
| | | orderPrivateCar.setState(1); |
| | | } |
| | | orderPrivateCar.setPaymentAdvanceMoney(orderMoney); |
| | | orderPrivateCar.setOrderMoney(orderMoney); |
| | | orderPrivateCar.setPayMoney(orderMoney); |
| | | } |
| | | if(company.getIsSpeFixedOrProportional() == 1){//比例 |
| | | Double price = orderPrivateCar.getStartMoney() + orderPrivateCar.getMileageMoney() + orderPrivateCar.getWaitMoney() + orderPrivateCar.getDurationMoney() + orderPrivateCar.getLongDistanceMoney(); |
| | | d = new BigDecimal(price).multiply(new BigDecimal(speMoney).divide(new BigDecimal(100), new MathContext(2, RoundingMode.HALF_EVEN))).setScale(2, BigDecimal.ROUND_HALF_EVEN); |
| | | c = new BigDecimal(orderPrivateCar.getOrderMoney()).subtract(d).setScale(2, BigDecimal.ROUND_HALF_EVEN); |
| | | // new Thread(new Runnable() { |
| | | // @Override |
| | | // public void run() { |
| | | // pushUtil.pushOrderState(1, orderPrivateCar.getUserId(), orderPrivateCar.getId(), 1, orderPrivateCar.getState(), 0); |
| | | // pushUtil.pushOrderState(2, orderPrivateCar.getDriverId(), orderPrivateCar.getId(), 1, orderPrivateCar.getState(), 0); |
| | | // } |
| | | // }).start(); |
| | | userInfoService.updateById(userInfo); |
| | | systemNoticeService.addSystemNotice(1, "您已使用余额成功完成出行订单支付,谢谢使用!", uid, 1); |
| | | if(orderPrivateCar.getState() == 1){ |
| | | this.pushOrder(orderPrivateCar); |
| | | } |
| | | incomeService.saveData(1, orderPrivateCar.getCompanyId(), 2, orderPrivateCar.getId(), 1, d.doubleValue()); |
| | | incomeService.saveData(2, orderPrivateCar.getDriverId(), 2, orderPrivateCar.getId(), 1, c.doubleValue()); |
| | | Driver driver = driverService.selectById(orderPrivateCar.getDriverId()); |
| | | driver.setBusinessMoney(new BigDecimal(null != driver.getBusinessMoney() ? driver.getBusinessMoney() : 0).add(c).setScale(2, BigDecimal.ROUND_HALF_EVEN).doubleValue()); |
| | | 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); |
| | | }else { |
| | | // 后付 |
| | | orderPrivateCar.setPayMoney(orderMoney); |
| | | orderPrivateCar.setState(8); |
| | | if(orderPrivateCar.getIsplatPay()==1){ |
| | | //添加已收入明细 |
| | | Company company = companyService.selectById(orderPrivateCar.getCompanyId()); |
| | | Double speMoney = company.getSpeMoney(); |
| | | BigDecimal d = null;//企业收入 |
| | | BigDecimal c = null;//司机收入 |
| | | if(company.getIsSpeFixedOrProportional() == 2){//固定 |
| | | d = new BigDecimal(speMoney); |
| | | c = new BigDecimal(orderPrivateCar.getOrderMoney()).subtract(d);//只有出行金额参与抽成,其余归属司机 |
| | | if(c.compareTo(BigDecimal.ZERO)<1){ |
| | | c = BigDecimal.ZERO; |
| | | } |
| | | } |
| | | if(company.getIsSpeFixedOrProportional() == 1){//比例 |
| | | Double price = orderPrivateCar.getStartMoney() + orderPrivateCar.getMileageMoney() + orderPrivateCar.getWaitMoney() + orderPrivateCar.getDurationMoney() + orderPrivateCar.getLongDistanceMoney(); |
| | | d = new BigDecimal(price).multiply(new BigDecimal(speMoney).divide(new BigDecimal(100), new MathContext(2, RoundingMode.HALF_EVEN))).setScale(2, BigDecimal.ROUND_HALF_EVEN); |
| | | c = new BigDecimal(orderPrivateCar.getOrderMoney()).subtract(d).setScale(2, BigDecimal.ROUND_HALF_EVEN); |
| | | } |
| | | incomeService.saveData(1, orderPrivateCar.getCompanyId(), 2, orderPrivateCar.getId(), 1, d.doubleValue()); |
| | | Driver driver = driverService.selectById(orderPrivateCar.getDriverId()); |
| | | driver.setBusinessMoney(new BigDecimal(null != driver.getBusinessMoney() ? driver.getBusinessMoney() : 0).add(c).setScale(2, BigDecimal.ROUND_HALF_EVEN).doubleValue()); |
| | | 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); |
| | | incomeService.saveDriverData(2, orderPrivateCar.getDriverId(), 2, orderPrivateCar.getId(), 1, c.doubleValue(), driver.getLaveBusinessMoney()); |
| | | } |
| | | |
| | | |
| | | // TODO: 2020/5/24 这里需要给司机和用户推送订单状态 |
| | | new Thread(new Runnable() { |
| | | @Override |
| | | public void run() { |
| | | pushUtil.pushOrderState(1, orderPrivateCar.getUserId(), orderPrivateCar.getId(), 1, orderPrivateCar.getState(), 0); |
| | | pushUtil.pushOrderState(2, orderPrivateCar.getDriverId(), orderPrivateCar.getId(), 1, orderPrivateCar.getState(), 0); |
| | | } |
| | | }).start(); |
| | | |
| | | systemNoticeService.addSystemNotice(1, "您已使用余额成功完成出行订单支付,谢谢使用!", uid, 1); |
| | | } |
| | | |
| | | |
| | | // TODO: 2020/5/24 这里需要给司机和用户推送订单状态 |
| | | new Thread(new Runnable() { |
| | | @Override |
| | | public void run() { |
| | | pushUtil.pushOrderState(1, orderPrivateCar.getUserId(), orderPrivateCar.getId(), 1, orderPrivateCar.getState(), 0); |
| | | pushUtil.pushOrderState(2, orderPrivateCar.getDriverId(), orderPrivateCar.getId(), 1, orderPrivateCar.getState(), 0); |
| | | } |
| | | }).start(); |
| | | |
| | | systemNoticeService.addSystemNotice(1, "您已使用余额成功完成出行订单支付,谢谢使用!", uid, 1); |
| | | } |
| | | |
| | | this.updateAllColumnById(orderPrivateCar); |
| | |
| | | //添加交易明细 |
| | | transactionDetailsService.saveData(orderPrivateCar.getUserId(), "取消订单", query.getAmount(), 2, 1, 1, 1, query.getOrderId()); |
| | | orderPrivateCar.setState(10); |
| | | // 判断订单金额是否为空或者为0 |
| | | if(orderPrivateCar.getPayMethod() == 0){ |
| | | // 先付 |
| | | Double refundMoney = orderPrivateCar.getOrderMoney(); |
| | | if(Objects.nonNull(orderPrivateCar.getCouponMoney())){ |
| | | refundMoney = new BigDecimal(refundMoney).subtract(new BigDecimal(orderPrivateCar.getCouponMoney())).doubleValue(); |
| | | } |
| | | // 退款 |
| | | if(orderPrivateCar.getPayType() == 1 && orderPrivateCar.getOrderMoney() !=0){//微信退款 |
| | | // 微信退款 |
| | | payMoneyUtil.wxRefund(orderPrivateCar.getTransactionId(),orderPrivateCar.getOrderNum(),String.valueOf(orderPrivateCar.getOrderMoney()),String.valueOf(refundMoney),"/base/transferWXNotify"); |
| | | } |
| | | if(orderPrivateCar.getPayType() == 2 && orderPrivateCar.getOrderMoney() !=0) {//支付宝退款 |
| | | // 支付宝退款 |
| | | payMoneyUtil.aliRefund(orderPrivateCar.getTransactionId(),String.valueOf(refundMoney*100)); |
| | | } |
| | | if(orderPrivateCar.getPayType() == 3 && orderPrivateCar.getOrderMoney() !=0) {//余额退款 |
| | | // 余额退款 |
| | | UserInfo userInfo = userInfoService.selectById(orderPrivateCar.getUserId()); |
| | | userInfo.setBalance(new BigDecimal(userInfo.getBalance()).add(new BigDecimal(refundMoney)).doubleValue()); |
| | | userInfoService.updateById(userInfo); |
| | | //添加交易明细 |
| | | transactionDetailsService.saveData(orderPrivateCar.getUserId(), "专车取消退款", refundMoney, 2, 1, 1, 1, id); |
| | | } |
| | | } |
| | | |
| | | //解除小号绑定 |
| | | // if(orderPrivateCar.getBindId() != null){ |
| | | // chinaMobileUtil.midAxbUnBindSend(orderPrivateCar.getBindId(),orderPrivateCar.getTelX()); |
| | |
| | | Company company = companyService.selectById(orderPrivateCar.getCompanyId()); |
| | | Double taxi = company.getSpeMoney(); |
| | | BigDecimal c =new BigDecimal(query.getAmount());//司机收入 |
| | | incomeService.saveData(2, orderPrivateCar.getDriverId(), 3, orderPrivateCar.getId(), 1, c.doubleValue()); |
| | | Driver driver = driverService.selectById(orderPrivateCar.getDriverId()); |
| | | driver.setBusinessMoney(new BigDecimal(null != driver.getBusinessMoney() ? driver.getBusinessMoney() : 0).add(c).setScale(2, BigDecimal.ROUND_HALF_EVEN).doubleValue()); |
| | | 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); |
| | | incomeService.saveDriverData(2, orderPrivateCar.getDriverId(), 3, orderPrivateCar.getId(), 1, c.doubleValue(), driver.getLaveBusinessMoney()); |
| | | this.deleteTask(orderPrivateCar.getId());//删除定时任务 |
| | | |
| | | // TODO: 2020/5/24 这里需要给司机和用户推送订单状态 |
| | |
| | | return; |
| | | } |
| | | transactionDetailsService.saveData(orderPrivateCar.getUserId(), "完成订单", query.getAmount(), 2, 1, 1, 1, query.getOrderId()); |
| | | orderPrivateCar.setState(8); |
| | | // orderPrivateCar.setState(8); |
| | | orderPrivateCar.setPayType(type); |
| | | orderPrivateCar.setOrderMoney(orderPrivateCar.getOrderMoney()+orderPrivateCar.getFreeMoney().doubleValue()); |
| | | orderPrivateCar.setPayMoney(query.getAmount()); |
| | | orderPrivateCar.setTransactionId(order_id); |
| | | this.updateById(orderPrivateCar); |
| | | |
| | | UserInfo userInfo = userInfoService.selectById(orderPrivateCar.getUserId()); |
| | |
| | | query.setState(2); |
| | | query.setCode(order_id); |
| | | paymentRecordService.updateById(query); |
| | | |
| | | if(orderPrivateCar.getIsplatPay()==1){ |
| | | //添加已收入明细 |
| | | Company company = companyService.selectById(orderPrivateCar.getCompanyId()); |
| | | Double taxi = company.getSpeMoney(); |
| | | BigDecimal d = null;//企业收入 |
| | | BigDecimal c = null;//司机收入 |
| | | if(company.getIsSpeFixedOrProportional() == 2){//固定 |
| | | d = new BigDecimal(taxi); |
| | | c = new BigDecimal(orderPrivateCar.getOrderMoney()).subtract(d).setScale(2, BigDecimal.ROUND_HALF_EVEN); |
| | | |
| | | // 判断先付还是后付 |
| | | if(orderPrivateCar.getPayMethod() == 0){ |
| | | |
| | | if (Objects.nonNull(orderPrivateCar.getPaymentAdvanceMoney()) && orderPrivateCar.getPaymentAdvanceMoney() > 0 ) { |
| | | orderPrivateCar.setState(8); |
| | | orderPrivateCar.setOrderMoney(orderPrivateCar.getOrderMoney()+query.getAmount()); |
| | | orderPrivateCar.setPayMoney(orderPrivateCar.getPayMoney()+query.getAmount()); |
| | | //添加已收入明细 |
| | | Company company = companyService.selectById(orderPrivateCar.getCompanyId()); |
| | | Double speMoney = company.getSpeMoney(); |
| | | BigDecimal d = null;//企业收入 |
| | | BigDecimal c = null;//司机收入 |
| | | if(company.getIsSpeFixedOrProportional() == 2){//固定 |
| | | d = new BigDecimal(speMoney); |
| | | c = new BigDecimal(orderPrivateCar.getOrderMoney()).subtract(d);//只有出行金额参与抽成,其余归属司机 |
| | | if(c.compareTo(BigDecimal.ZERO)<1){ |
| | | c = BigDecimal.ZERO; |
| | | } |
| | | } |
| | | if(company.getIsSpeFixedOrProportional() == 1){//比例 |
| | | Double price = orderPrivateCar.getStartMoney() + orderPrivateCar.getMileageMoney() + orderPrivateCar.getWaitMoney() + orderPrivateCar.getDurationMoney() + orderPrivateCar.getLongDistanceMoney(); |
| | | d = new BigDecimal(price).multiply(new BigDecimal(speMoney).divide(new BigDecimal(100), new MathContext(2, RoundingMode.HALF_EVEN))).setScale(2, BigDecimal.ROUND_HALF_EVEN); |
| | | c = new BigDecimal(orderPrivateCar.getOrderMoney()).subtract(d).setScale(2, BigDecimal.ROUND_HALF_EVEN); |
| | | } |
| | | incomeService.saveData(1, orderPrivateCar.getCompanyId(), 2, orderPrivateCar.getId(), 1, d.doubleValue()); |
| | | Driver driver = driverService.selectById(orderPrivateCar.getDriverId()); |
| | | driver.setBusinessMoney(new BigDecimal(null != driver.getBusinessMoney() ? driver.getBusinessMoney() : 0).add(c).setScale(2, BigDecimal.ROUND_HALF_EVEN).doubleValue()); |
| | | 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); |
| | | incomeService.saveDriverData(2, orderPrivateCar.getDriverId(), 2, orderPrivateCar.getId(), 1, c.doubleValue(), driver.getLaveBusinessMoney()); |
| | | }else { |
| | | if(orderPrivateCar.getOrderSource() == 2){ |
| | | orderPrivateCar.setState(2); |
| | | }else { |
| | | orderPrivateCar.setState(1); |
| | | } |
| | | orderPrivateCar.setOrderMoney(orderPrivateCar.getOrderMoney()+orderPrivateCar.getFreeMoney().doubleValue()); |
| | | orderPrivateCar.setPayMoney(query.getAmount()); |
| | | orderPrivateCar.setPaymentAdvanceMoney(orderPrivateCar.getOrderMoney()); |
| | | } |
| | | if(company.getIsSpeFixedOrProportional() == 1){//比例 |
| | | Double price = orderPrivateCar.getStartMoney() + orderPrivateCar.getMileageMoney() + orderPrivateCar.getWaitMoney() + orderPrivateCar.getDurationMoney() + orderPrivateCar.getLongDistanceMoney(); |
| | | d = new BigDecimal(price).multiply(new BigDecimal(taxi).divide(new BigDecimal(100), new MathContext(2, RoundingMode.HALF_EVEN))).setScale(2, BigDecimal.ROUND_HALF_EVEN); |
| | | c = new BigDecimal(orderPrivateCar.getOrderMoney()).subtract(d).setScale(2, BigDecimal.ROUND_HALF_EVEN); |
| | | this.updateById(orderPrivateCar); |
| | | }else { |
| | | orderPrivateCar.setOrderMoney(orderPrivateCar.getOrderMoney()+orderPrivateCar.getFreeMoney().doubleValue()); |
| | | orderPrivateCar.setPayMoney(query.getAmount()); |
| | | orderPrivateCar.setState(8); |
| | | this.updateById(orderPrivateCar); |
| | | if(orderPrivateCar.getIsplatPay()==1){ |
| | | //添加已收入明细 |
| | | Company company = companyService.selectById(orderPrivateCar.getCompanyId()); |
| | | Double taxi = company.getSpeMoney(); |
| | | BigDecimal d = null;//企业收入 |
| | | BigDecimal c = null;//司机收入 |
| | | if(company.getIsSpeFixedOrProportional() == 2){//固定 |
| | | d = new BigDecimal(taxi); |
| | | c = new BigDecimal(orderPrivateCar.getOrderMoney()).subtract(d).setScale(2, BigDecimal.ROUND_HALF_EVEN); |
| | | } |
| | | if(company.getIsSpeFixedOrProportional() == 1){//比例 |
| | | Double price = orderPrivateCar.getStartMoney() + orderPrivateCar.getMileageMoney() + orderPrivateCar.getWaitMoney() + orderPrivateCar.getDurationMoney() + orderPrivateCar.getLongDistanceMoney(); |
| | | d = new BigDecimal(price).multiply(new BigDecimal(taxi).divide(new BigDecimal(100), new MathContext(2, RoundingMode.HALF_EVEN))).setScale(2, BigDecimal.ROUND_HALF_EVEN); |
| | | c = new BigDecimal(orderPrivateCar.getOrderMoney()).subtract(d).setScale(2, BigDecimal.ROUND_HALF_EVEN); |
| | | } |
| | | incomeService.saveData(1, orderPrivateCar.getCompanyId(), 2, orderPrivateCar.getId(), 1, d.doubleValue()); |
| | | Driver driver = driverService.selectById(orderPrivateCar.getDriverId()); |
| | | driver.setBusinessMoney(new BigDecimal(null != driver.getBusinessMoney() ? driver.getBusinessMoney() : 0).add(c).setScale(2, BigDecimal.ROUND_HALF_EVEN).doubleValue()); |
| | | 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); |
| | | incomeService.saveDriverData(2, orderPrivateCar.getDriverId(), 2, orderPrivateCar.getId(), 1, c.doubleValue(), driver.getLaveBusinessMoney()); |
| | | } |
| | | incomeService.saveData(1, orderPrivateCar.getCompanyId(), 2, orderPrivateCar.getId(), 1, d.doubleValue()); |
| | | incomeService.saveData(2, orderPrivateCar.getDriverId(), 2, orderPrivateCar.getId(), 1, c.doubleValue()); |
| | | Driver driver = driverService.selectById(orderPrivateCar.getDriverId()); |
| | | driver.setBusinessMoney(new BigDecimal(null != driver.getBusinessMoney() ? driver.getBusinessMoney() : 0).add(c).setScale(2, BigDecimal.ROUND_HALF_EVEN).doubleValue()); |
| | | 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); |
| | | } |
| | | // TODO: 2020/5/24 这里需要给司机和用户推送订单状态 |
| | | new Thread(new Runnable() { |
| | |
| | | } |
| | | if(Integer.valueOf(String.valueOf(map.get("state"))) == 7){ |
| | | OrderPrivateCar orderPrivateCar = orderPrivateCarMapper.selectById(orderId); |
| | | UserActivityDiscount1 query2 = userActivityDiscount1Mapper.query(Integer.valueOf(String.valueOf(map.get("companyId")))); |
| | | 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())")); |
| | | if(query2.getDistance()*1000>orderPrivateCar.getMileage() && query2.getOrderNum()>orderNum){ |
| | | Double special = query2.getSpecial(); |
| | | orderPrivateCar.setDiscount(special); |
| | | Double orderMoney = orderPrivateCar.getOrderMoney(); |
| | | double v = new BigDecimal(orderMoney).multiply(new BigDecimal(special / 10)).setScale(2, BigDecimal.ROUND_HALF_EVEN).doubleValue(); |
| | | if(orderMoney.compareTo(v) > 0){ |
| | | map.put("discountMoney",orderMoney - v); |
| | | Object companyId = map.get("companyId"); |
| | | if(Objects.nonNull(companyId)){ |
| | | UserActivityDiscount1 query2 = userActivityDiscount1Mapper.query(Integer.valueOf(String.valueOf(map.get("companyId")))); |
| | | 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())")); |
| | | if(query2.getDistance()*1000>orderPrivateCar.getMileage() && query2.getOrderNum()>orderNum){ |
| | | Double special = query2.getSpecial(); |
| | | orderPrivateCar.setDiscount(special); |
| | | Double orderMoney = orderPrivateCar.getOrderMoney(); |
| | | double v = new BigDecimal(orderMoney).multiply(new BigDecimal(special / 10)).setScale(2, BigDecimal.ROUND_HALF_EVEN).doubleValue(); |
| | | if(orderMoney.compareTo(v) > 0){ |
| | | map.put("discountMoney",orderMoney - v); |
| | | } |
| | | } |
| | | } |
| | | |
| | | }else{ |
| | | map.put("discountMoney",0); |
| | | } |
| | | } |
| | | |
| | |
| | | List<OrderPosition> list = JSONArray.parseArray(sb.toString(), OrderPosition.class); |
| | | orderServerWarpper.setOrderPositionList(JSONObject.toJSONString(list)); |
| | | } |
| | | // 查询司机服务中的订单 |
| | | OrderPrivateCar one = this.selectOne(new EntityWrapper<OrderPrivateCar>() |
| | | .eq("driverId", orderPrivateCar.getDriverId()) |
| | | .eq("state", 5) |
| | | .orderBy("insertTime", false) |
| | | .last("LIMIT 1")); |
| | | if(Objects.nonNull(one)){ |
| | | orderServerWarpper.setLastLon(one.getEndLon()+""); |
| | | orderServerWarpper.setLastLat(one.getEndLat()+""); |
| | | } |
| | | return orderServerWarpper; |
| | | } |
| | | |