| | |
| | | import java.math.RoundingMode; |
| | | import java.text.SimpleDateFormat; |
| | | import java.util.*; |
| | | import java.util.stream.Collectors; |
| | | |
| | | |
| | | @Service |
| | |
| | | @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, Integer language) throws Exception { |
| | | |
| | | |
| | | UserInfo userInfo = userInfoService.selectById(uid); |
| | | if(ToolUtil.isEmpty(userInfo.getPhone())){ |
| | | return ResultUtil.error(language == 1 ? "请先绑定手机号码" : language == 2 ? "Please bind your mobile phone number first." : "Veuillez d’abord vous inscrire en liant votre numéro de téléphone portable."); |
| | | } |
| | | Company company = companyCityService.query1(uid, placementLon, placementLat); |
| | | if(null != userInfo && null != company){ |
| | | userInfo.setCompanyId(company.getId()); |
| | | userInfoService.updateById(userInfo); |
| | | } |
| | | |
| | | //如果出行时间大于当前10分钟则默认为预约单 |
| | | if(travelTime.getTime() > (System.currentTimeMillis() + 600000)){ |
| | | reservation = 2; |
| | |
| | | if((orderSource == 1 || orderSource == 3) && null == serverCarModelId){ |
| | | return ResultUtil.error(language == 1 ? "请选择服务车型" : language == 2 ? "Please select vehicle-type" : "Veuillez sélectionner le type de véhicule"); |
| | | } |
| | | |
| | | userInfo.setLanguage(language); |
| | | userInfoService.updateById(userInfo); |
| | | OrderPrivateCar orderPrivateCar = new OrderPrivateCar(); |
| | | orderPrivateCar.setType(type); |
| | | orderPrivateCar.setUserId(uid); |
| | |
| | | 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(language == 1 ? "请先绑定手机号码" : language == 2 ? "Please bind your mobile phone number first." : "Veuillez d’abord vous inscrire en liant votre numéro de téléphone portable."); |
| | | } |
| | | orderPrivateCar.setPassengers(userInfo.getFirstName() + "." + userInfo.getLastName()); |
| | | orderPrivateCar.setPassengers(ToolUtil.isNotEmpty(userInfo.getFirstName()) ? userInfo.getFirstName() + "." + userInfo.getLastName() : ""); |
| | | orderPrivateCar.setPassengersPhone(userInfo.getPhone()); |
| | | } |
| | | orderPrivateCar.setState(1); |
| | |
| | | orderPrivateCar.setIsReassign(1); |
| | | orderPrivateCar.setIsDelete(1); |
| | | orderPrivateCar.setTripId(tripId); |
| | | orderPrivateCar.setIsover(0); |
| | | DistancematrixVo distancematrix1 = GoogleMapUtil.getDistancematrix(orderPrivateCar.getStartLat(), orderPrivateCar.getStartLon(), orderPrivateCar.getEndLat(), orderPrivateCar.getEndLon(), tripId); |
| | | Long distance1 = distancematrix1.getDistance(); |
| | | orderPrivateCar.setEstimatedMileage(new BigDecimal(distance1).divide(new BigDecimal(1000)).setScale(2, RoundingMode.HALF_EVEN).doubleValue()); |
| | | this.insert(orderPrivateCar); |
| | | |
| | | UserInfo userInfo = userInfoService.selectById(uid); |
| | | userInfo.setLanguage(language); |
| | | userInfoService.updateById(userInfo); |
| | | |
| | | |
| | | //google创建车辆信息 |
| | | String vehicleId = null; |
| | |
| | | CarService query1 = carServiceMapper.query(1, dr.getCarId()); |
| | | orderPrivateCar.setServerCarModelId(query1.getServerCarModelId()); |
| | | orderPrivateCar.setSnatchOrderTime(new Date()); |
| | | |
| | | String value = redisUtil.getValue("DRIVER" + driver.getId()); |
| | | if(ToolUtil.isNotEmpty(value)) { |
| | | String[] split = value.split(","); |
| | | DistancematrixVo distancematrix = GoogleMapUtil.getDistancematrix(orderPrivateCar.getStartLat(), orderPrivateCar.getStartLon(), Double.valueOf(split[1]), Double.valueOf(split[0]), tripId); |
| | | //超时时间 |
| | | long timeOut = System.currentTimeMillis() + (distancematrix.getDuration() * 1000); |
| | | orderPrivateCar.setEstimateArriveTime(new Date(timeOut)); |
| | | orderPrivateCar.setEstimateArriveMileage(distancematrix.getDistance()); |
| | | } |
| | | |
| | | dr.setState(3); |
| | | driverService.updateById(dr); |
| | |
| | | BaseWarpper baseWarpper = new BaseWarpper(); |
| | | double amount = 0; |
| | | CancleOrder query = cancleOrderService.query(orderPrivateCar.getCompanyId()); |
| | | if(null == query || null == orderPrivateCar.getDriverId() || orderPrivateCar.getState() == 11){ |
| | | if(null == query){ |
| | | return ResultUtil.error("请先添加取消规则"); |
| | | } |
| | | if(null == orderPrivateCar.getDriverId() || orderPrivateCar.getState() == 11){ |
| | | baseWarpper.setAmount(amount); |
| | | return ResultUtil.success(baseWarpper); |
| | | } |
| | |
| | | long t = object.getInteger("driverTimeout") * 60000L; |
| | | //司机超时未到达起点,免费取消 |
| | | if(orderPrivateCar.getOrderType() == 1){ |
| | | if(orderPrivateCar.getState() == 1 || orderPrivateCar.getState() == 11){ |
| | | baseWarpper.setAmount(0D); |
| | | return ResultUtil.success(baseWarpper); |
| | | } |
| | | if(orderPrivateCar.getState() <= 3 && orderPrivateCar.getEstimateArriveTime().getTime() + t <= System.currentTimeMillis()){ |
| | | baseWarpper.setAmount(amount); |
| | | return ResultUtil.success(baseWarpper); |
| | |
| | | public ResultUtil addCancle(Integer id, String reason, String remark, Integer uid, Double lon, Double lat, String address, Integer language) throws Exception { |
| | | if(ToolUtil.isNotEmpty(remark)){ |
| | | if(ToolUtil.isNotEmpty(remark)){ |
| | | remark = remark.toLowerCase(); |
| | | List<SensitiveWords> sensitiveWords = sensitiveWordsMapper.selectList(null); |
| | | for(SensitiveWords s : sensitiveWords){ |
| | | remark = remark.replaceAll(s.getContent(), "***"); |
| | | for(SensitiveWords s : sensitiveWords) { |
| | | remark = remark.replaceAll(s.getContent().toLowerCase(), "***"); |
| | | } |
| | | } |
| | | } |
| | |
| | | if(orderPrivateCar.getState() > 5 && orderPrivateCar.getState() != 11 && orderPrivateCar.getState() != 12){ |
| | | return ResultUtil.error(language == 1 ? "取消订单失败,不合法的操作" : language == 2 ? "Failed to cancel order, illegal operation." : "Échec de l’annulation de la commande, opération illégale."); |
| | | } |
| | | |
| | | orderCancelService.delete(new EntityWrapper<OrderCancel>().eq("orderId", orderPrivateCar.getId()).eq("orderType", 1)); |
| | | |
| | | //服务中也可以取消订单,所以取消订单时需要计算订单费用 |
| | | if(null == orderPrivateCar.getDriverId()){//没有接单的情况 |
| | |
| | | orderTaxiService.updateById(orderTaxi); |
| | | } |
| | | }else{ |
| | | integer = orderCancelService.saveData(id, 1, language == 1 ? "无司机接单" : language == 2 ? "No driver to take orders" : "Pas de chauffeur pour prendre les commandes", language == 1 ? "无司机接单" : language == 2 ? "No driver to take orders" : "Pas de chauffeur pour prendre les commandes", null, null, 2, 1, uid); |
| | | integer = orderCancelService.saveData(id, 1, language == 1 ? "无司机接单" : language == 2 ? "No driver to take orders" : "Pas de chauffeur pour prendre les commandes", language == 1 ? "无司机接单" : language == 2 ? "No driver to take orders" : "Pas de chauffeur pour prendre les commandes", null, 0D, 2, 1, uid); |
| | | orderPrivateCar.setState(10); |
| | | this.updateById(orderPrivateCar); |
| | | } |
| | |
| | | BaseWarpper data = queryCancleAmount(id, language).getData(); |
| | | Double amount = data.getAmount(); |
| | | if(0 == amount){ |
| | | integer = orderCancelService.saveData(id, 1, reason, remark, null, null, 2, 1, uid); |
| | | integer = orderCancelService.saveData(id, 1, reason, remark, null, 0D, 2, 1, uid); |
| | | if(5 == orderPrivateCar.getState()){ |
| | | orderPrivateCar.setState(6); |
| | | orderPrivateCar.setGetoffLon(lon); |
| | |
| | | //修改行程信息 |
| | | if(orderPrivateCar.getState() == 10 || orderPrivateCar.getState() == 12){ |
| | | Car car = carService.selectById(orderPrivateCar.getCarId()); |
| | | boolean updateTrip = fleetEngineUtil.updateTrip("CANCELED", car.getVehicleId(), null, orderPrivateCar.getTripId(), null, null, null, null); |
| | | boolean updateTrip = fleetEngineUtil.updateTrip("CANCELED", (null != car ? car.getVehicleId() : null), null, orderPrivateCar.getTripId(), null, null, null, null); |
| | | if(!updateTrip){ |
| | | for (int i = 0; i < 5; i++) { |
| | | updateTrip = fleetEngineUtil.updateTrip("CANCELED", car.getVehicleId(), null, orderPrivateCar.getTripId(), null, null, null, null); |
| | | updateTrip = fleetEngineUtil.updateTrip("CANCELED", (null != car ? car.getVehicleId() : null), null, orderPrivateCar.getTripId(), null, null, null, null); |
| | | if(updateTrip){ |
| | | orderPrivateCar.setIsover(1); |
| | | this.updateById(orderPrivateCar); |
| | | break; |
| | | } |
| | | Thread.sleep(3000L); |
| | | } |
| | | }else{ |
| | | orderPrivateCar.setIsover(1); |
| | | this.updateById(orderPrivateCar); |
| | | } |
| | | } |
| | | //添加消息 |
| | |
| | | ChinaMobileUtil.midAxbUnBindSend(orderPrivateCar.getBindId(),orderPrivateCar.getTelX()); |
| | | } |
| | | |
| | | if(5 == orderPrivateCar.getOldState()){ |
| | | orderPrivateCar.setState(6); |
| | | }else{ |
| | | orderPrivateCar.setState(10); |
| | | } |
| | | orderPrivateCar.setState(10); |
| | | orderPrivateCar.setTelX(""); |
| | | orderPrivateCar.setBindId(""); |
| | | this.updateById(orderPrivateCar); |
| | |
| | | |
| | | |
| | | @Override |
| | | @Transactional |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public ResultUtil payPrivateCarOrder(Integer payType, Integer bankCardId, Integer orderId, Integer couponId, Integer redDeduction, Integer type, Integer language) throws Exception { |
| | | OrderPrivateCar orderPrivateCar = this.selectById(orderId); |
| | | if(orderPrivateCar.getState() == 8 || orderPrivateCar.getState() == 9){ |
| | |
| | | //计算折扣 |
| | | UserActivityDiscount1 query2 = userActivityDiscount1Mapper.query(orderPrivateCar.getCompanyId()); |
| | | if(null != query2){ |
| | | Integer orderNum=this.selectCount(new EntityWrapper<OrderPrivateCar>().eq("userId",orderPrivateCar.getUserId()).eq("activityId",query2.getId()).last(" and to_days(getoffTime) = to_days(now())")); |
| | | Integer orderNum=this.selectCount(new EntityWrapper<OrderPrivateCar>().eq("userId",orderPrivateCar.getUserId()) |
| | | .eq("activityId",query2.getId()).last(" and to_days(getoffTime) = to_days(now())")); |
| | | if(query2.getDistance()*1000>orderPrivateCar.getMileage() && query2.getOrderNum()>orderNum){ |
| | | Double special = query2.getSpecial(); |
| | | if(null != special){ |
| | |
| | | if(null != redDeduction && 1 == redDeduction && null == orderPrivateCar.getRedPacketId()){ |
| | | RedEnvelopePaymentSettings redEnvelopePaymentSettings = redEnvelopePaymentSettingsService.getRedEnvelopePaymentSettings(); |
| | | if(null != redEnvelopePaymentSettings){ |
| | | Double total = userRedPacketRecordService.queryRemainingAmount(uid); |
| | | List<UserRedPacketRecord> userRedPacketRecords = userRedPacketRecordService.selectList(new EntityWrapper<UserRedPacketRecord>().eq("userId", uid) |
| | | .eq("state", 1).eq("companyId", orderPrivateCar.getCompanyId()).gt("remainingAmount", 0).orderBy("insertTime", false)); |
| | | |
| | | Double total = userRedPacketRecords.stream().mapToDouble(UserRedPacketRecord::getRemainingAmount).sum(); |
| | | BigDecimal deductionRatio = redEnvelopePaymentSettings.getDeductionRatio(); |
| | | BigDecimal multiply1 = orderMoney.multiply(deductionRatio.divide(new BigDecimal(100))).setScale(2, RoundingMode.HALF_EVEN); |
| | | if(total > 0 && multiply1.doubleValue() > 0 && total.compareTo(multiply1.doubleValue()) >= 0){ |
| | |
| | | //获取红包id |
| | | JSONArray jsonArray = new JSONArray(); |
| | | for (UserRedPacketRecord userRedPacketRecord : userRedPacketRecords) { |
| | | if(multiply1.compareTo(BigDecimal.ZERO) == 0){ |
| | | break; |
| | | } |
| | | JSONObject jsonObject = new JSONObject(); |
| | | jsonObject.put("id", userRedPacketRecord.getId()); |
| | | BigDecimal remainingAmount = new BigDecimal(userRedPacketRecord.getRemainingAmount()); |
| | | |
| | | if(multiply1.compareTo(remainingAmount) >= 0){ |
| | | userRedPacketRecord.setRemainingAmount(0D); |
| | | userRedPacketRecord.setEndTime(new Date()); |
| | |
| | | jsonObject.put("money", multiply1.setScale(2, RoundingMode.HALF_EVEN)); |
| | | jsonArray.add(jsonObject); |
| | | multiply1 = BigDecimal.ZERO; |
| | | break; |
| | | } |
| | | } |
| | | if(userRedPacketRecords.size() > 0){ |
| | | userRedPacketRecordService.updateBatchById(userRedPacketRecords); |
| | | } |
| | | orderPrivateCar.setRedPacketId(jsonArray.toJSONString()); |
| | | } |
| | | if(total > 0 && total.compareTo(multiply1.doubleValue()) < 0){ |
| | | }else if(total > 0 && total.compareTo(multiply1.doubleValue()) < 0){ |
| | | orderPrivateCar.setRedPacketMoney(total); |
| | | orderMoney = orderMoney.subtract(new BigDecimal(total)).setScale(2, RoundingMode.HALF_EVEN); |
| | | //获取红包id |
| | |
| | | if(null != query){ |
| | | //添加交易明细 |
| | | transactionDetailsService.saveData(orderPrivateCar.getUserId(), "取消订单", query.getAmount(), 2, 1, 1, 1, query.getOrderId()); |
| | | if(5 == orderPrivateCar.getOldState()){ |
| | | orderPrivateCar.setState(6); |
| | | }else{ |
| | | orderPrivateCar.setState(10); |
| | | } |
| | | orderPrivateCar.setState(10); |
| | | //解除小号绑定 |
| | | if(orderPrivateCar.getBindId() != null){ |
| | | ChinaMobileUtil.midAxbUnBindSend(orderPrivateCar.getBindId(),orderPrivateCar.getTelX()); |
| | |
| | | Integer driverTimeOutTime = 0; |
| | | Integer driverTimeOut = 0; |
| | | CancleOrder cancleOrder = cancleOrderService.selectOne(new EntityWrapper<CancleOrder>().eq("companyId", companyId)); |
| | | JSONObject jsonObject = JSON.parseObject(cancleOrder.getContent()); |
| | | int driverTimeout1 = jsonObject.getIntValue("driverTimeout"); |
| | | if(orderPrivateCar.getOrderType() == 1 && null != orderPrivateCar.getEstimateArriveTime()){ |
| | | long time = orderPrivateCar.getEstimateArriveTime().getTime() + driverTimeout1 * 60000L; |
| | | if(System.currentTimeMillis() > time){ |
| | | driverTimeOutTime = Double.valueOf((System.currentTimeMillis() - time) / 60000).intValue(); |
| | | driverTimeOutTime = driverTimeOutTime == 0 ? 1 : driverTimeOutTime; |
| | | driverTimeOut = 1; |
| | | } |
| | | }else{ |
| | | long time = orderPrivateCar.getTravelTime().getTime() + driverTimeout1 * 60000L; |
| | | if(System.currentTimeMillis() >= time){ |
| | | driverTimeOutTime = Double.valueOf((System.currentTimeMillis() - time) / 60000).intValue(); |
| | | driverTimeOutTime = driverTimeOutTime == 0 ? 1 : driverTimeOutTime; |
| | | driverTimeOut = 1; |
| | | if(null != cancleOrder){ |
| | | JSONObject jsonObject = JSON.parseObject(cancleOrder.getContent()); |
| | | int driverTimeout1 = jsonObject.getIntValue("driverTimeout"); |
| | | if(orderPrivateCar.getOrderType() == 1 && null != orderPrivateCar.getEstimateArriveTime()){ |
| | | long time = orderPrivateCar.getEstimateArriveTime().getTime() + driverTimeout1 * 60000L; |
| | | if(System.currentTimeMillis() > time){ |
| | | driverTimeOutTime = Double.valueOf((System.currentTimeMillis() - time) / 60000).intValue(); |
| | | driverTimeOutTime = driverTimeOutTime == 0 ? 1 : driverTimeOutTime; |
| | | driverTimeOut = 1; |
| | | } |
| | | }else{ |
| | | long time = orderPrivateCar.getTravelTime().getTime() + driverTimeout1 * 60000L; |
| | | if(System.currentTimeMillis() >= time){ |
| | | driverTimeOutTime = Double.valueOf((System.currentTimeMillis() - time) / 60000).intValue(); |
| | | driverTimeOutTime = driverTimeOutTime == 0 ? 1 : driverTimeOutTime; |
| | | driverTimeOut = 1; |
| | | } |
| | | } |
| | | } |
| | | |