| | |
| | | private OrderCrossCityMapper orderCrossCityMapper; |
| | | |
| | | @Resource |
| | | private LinePriceMapper linePriceMapper; |
| | | |
| | | @Resource |
| | | private LineMapper lineMapper; |
| | | |
| | | @Resource |
| | |
| | | if (lineId < 0 && (lineDestinationId == null || lineDestinationId < 0)) { |
| | | lineShifDriverId = lineShiftDriverMapper.selectLineShiftDriverIdByCustomerId(-lineId); |
| | | } |
| | | ResultUtil<Map<String, Object>> result = this.getPriceV2(lineId, lineDestinationId, totalSeat, peopleNumber, endLon, endLat, lineShifDriverId); |
| | | ResultUtil<Map<String, Object>> result = this.getPriceV2(lineId, lineDestinationId, totalSeat, peopleNumber, endLon, endLat, lineShifDriverId, travelMode); |
| | | if (result.getCode() != 200) { |
| | | return result; |
| | | } |
| | |
| | | * 鍏堝垽鏂徃鏈哄骇浣嶆暟鏄惁绗﹀悎鍑鸿浜烘暟 |
| | | */ |
| | | LineShiftDriver lineShiftDriver = lineShiftDriverMapper.selectById(orderCrossCityWarpper.getLineShiftDriverId()); |
| | | if (lineShiftDriver == null) { |
| | | return ResultUtil.error("班次信息不存在"); |
| | | } |
| | | if (orderCrossCityWarpper.getTravelMode() == 1) {//拼车判断座位数 |
| | | if (lineShiftDriver.getLaveSeat() < orderCrossCityWarpper.getPeopleNumber()) { |
| | | return ResultUtil.error("司机剩余座位数小于出行人数"); |
| | | } |
| | | } else { |
| | | List<OrderCrossCity> charterOrders = this.selectList(new EntityWrapper<OrderCrossCity>() |
| | | .eq("lineShiftDriverId", orderCrossCityWarpper.getLineShiftDriverId()) |
| | | .eq("isDelete", 1) |
| | | .ne("state", 10)); |
| | | if (charterOrders.size() > 0) { |
| | | return ResultUtil.error("已有其他人下单无法包车"); |
| | | } |
| | | if (lineShiftDriver.getLaveSeat() != lineShiftDriver.getTotalSeat()) { |
| | | return ResultUtil.error("司机车辆上已经有人占座,不能下包车订单"); |
| | | return ResultUtil.error("已有其他人下单无法包车"); |
| | | } |
| | | if (lineShiftDriver.getLaveSeat() == 0) { |
| | | return ResultUtil.error("司机车辆没有剩余空位了"); |
| | |
| | | if (orderCrossCityWarpper.getLineId() < 0 && (lineDestinationId == null || lineDestinationId < 0)) { |
| | | lineShifDriverId = lineShiftDriverMapper.selectLineShiftDriverIdByCustomerId(-orderCrossCityWarpper.getLineId()); |
| | | } |
| | | Integer orderPeopleNumber = orderCrossCityWarpper.getTravelMode() == 2 ? lineShiftDriver.getLaveSeat() : orderCrossCityWarpper.getPeopleNumber(); |
| | | Integer priceTotalSeat = orderCrossCityWarpper.getTravelMode() == 2 ? lineShiftDriver.getTotalSeat() : orderCrossCityWarpper.getTotalSeat(); |
| | | ResultUtil<Map<String, Object>> price = this.getPriceV2(orderCrossCityWarpper.getLineId(), orderCrossCityWarpper.getLineDestinationId(), |
| | | orderCrossCityWarpper.getTotalSeat(), orderCrossCityWarpper.getPeopleNumber(), orderCrossCityWarpper.getEndLon(), |
| | | orderCrossCityWarpper.getEndLat(), lineShifDriverId); |
| | | priceTotalSeat, orderPeopleNumber, orderCrossCityWarpper.getEndLon(), |
| | | orderCrossCityWarpper.getEndLat(), lineShifDriverId, orderCrossCityWarpper.getTravelMode()); |
| | | if (price.getCode() != 200) { |
| | | return ResultUtil.error("计算价格失败"); |
| | | } |
| | |
| | | UserInfo userInfo = userInfoService.selectById(uid); |
| | | orderCrossCity.setPassengers(userInfo.getNickName()); |
| | | orderCrossCity.setPassengersPhone(userInfo.getPhone()); |
| | | orderCrossCity.setPeopleNumber(orderCrossCityWarpper.getPeopleNumber()); |
| | | orderCrossCity.setPeopleNumber(orderPeopleNumber); |
| | | List<OrderCrossCity> orderCrossCities = this.selectList(new EntityWrapper<OrderCrossCity>().eq("orderNum", orderCrossCity.getOrderNum()).eq("isDelete", 1)); |
| | | orderCrossCity.setSort(orderCrossCities.size() + 1); |
| | | orderCrossCity.setState(7);//待支付 |
| | |
| | | } |
| | | |
| | | Map<String, Object> map = new HashMap<>(); |
| | | double distance1 = distance.doubleValue() / 1000;//鍏噷 |
| | | map.put("distance", distance); |
| | | |
| | | /** |
| | | * 1.固定价格的包车是整车价格 |
| | | * 2.五座车和七座车的优惠系数是中间特殊位置的优惠折扣 |
| | | * 3.包车的情况不享受中间特殊位置的优惠折扣 |
| | | * 4.浮动计费拼车如果选中中间特殊位置时享受优惠系数又享受中间特殊位置的优惠折扣 |
| | | */ |
| | | Map<String, Object> query = linePriceMapper.query(lineId, serverCarModelId); |
| | | if (null == query) { |
| | | map.put("distance", 0); |
| | | map.put("price", 0); |
| | | return ResultUtil.success(map); |
| | | } |
| | | String content = query.get("content").toString(); |
| | | JSONObject jsonObject = JSON.parseObject(content); |
| | | if (Integer.valueOf(query.get("type").toString()) == 1) {//固定金额 |
| | | double num1 = Double.valueOf(jsonObject.getString("num1")).doubleValue(); |
| | | double num2 = Double.valueOf(jsonObject.getString("num2")).doubleValue(); |
| | | double num3 = Double.valueOf(jsonObject.getString("num3")).doubleValue(); |
| | | double num4 = Double.valueOf(jsonObject.getString("num4")).doubleValue(); |
| | | if (travelMode == 1) {//拼车 |
| | | String[] split = seatNumber.split(","); |
| | | boolean b = false; |
| | | for (String s : split) { |
| | | if ((totalSeat == 4 && s.equals("3")) || (totalSeat == 6 && s.equals("5"))) { |
| | | b = true; |
| | | break; |
| | | } |
| | | } |
| | | double price1 = 0D; |
| | | if (b) { |
| | | price1 = num1 * (totalSeat == 4 ? num3 : num4); |
| | | peopleNumber -= 1; |
| | | } |
| | | double price = (num1 * peopleNumber) + price1; |
| | | map.put("price", new BigDecimal(price).setScale(2, BigDecimal.ROUND_HALF_EVEN).doubleValue()); |
| | | } else { |
| | | map.put("price", num2);//包车价 |
| | | } |
| | | |
| | | } else {//浮动计费 |
| | | //计算公式:实际里程 * 基础单价 * (参考费用 / (参考里程 * 基础单价)) + (实际里程 - 参考里程) * 基础单价 * 优惠系数 |
| | | double num1 = Double.valueOf(jsonObject.getString("num1")).doubleValue();//参考价格 |
| | | double num2 = Double.valueOf(jsonObject.getString("num2")).doubleValue();//参考里程 |
| | | double num3 = Double.valueOf(jsonObject.getString("num3")).doubleValue();//保底价 |
| | | double num4 = Double.valueOf(jsonObject.getString("num4")).doubleValue();//超出参考里程优惠系数 |
| | | double num5 = Double.valueOf(jsonObject.getString("num5")).doubleValue();//低于参考里程优惠系数 |
| | | double num6 = Double.valueOf(jsonObject.getString("num6")).doubleValue();//包车系数 |
| | | double num7 = Double.valueOf(jsonObject.getString("num7")).doubleValue();//五座系数 |
| | | double num8 = Double.valueOf(jsonObject.getString("num8")).doubleValue();//七座系数 |
| | | |
| | | |
| | | /** |
| | | * 1、实际里程 > 参考里程 |
| | | * 参考价 + ((实际里程 - 参考里程)*(参考价 / 参考里程)*超出参考里程优惠系数) |
| | | * |
| | | * 2、实际里程 < 参考里程 |
| | | * 参考价 - ((参考里程 - 实际里程)*(参考价 / 参考里程)*低于参考里程优惠系数) |
| | | */ |
| | | double unitPrice = 0d; |
| | | if (distance1 > num2) {//1 |
| | | unitPrice = num1 + ((distance1 - num2) * (num1 / num2) * num4); |
| | | } |
| | | if (distance1 < num2) {//2 |
| | | unitPrice = num1 - ((num2 - distance1) * (num1 / num2) * num5); |
| | | } |
| | | if (distance1 == num2) { |
| | | unitPrice = num1; |
| | | } |
| | | if (travelMode == 1) {//拼车 |
| | | String[] split = seatNumber.split(","); |
| | | boolean b = false; |
| | | for (String s : split) { |
| | | if ((totalSeat == 4 && s.equals("3")) || (totalSeat == 6 && s.equals("5"))) { |
| | | b = true; |
| | | break; |
| | | } |
| | | } |
| | | double price1 = 0D; |
| | | if (b) { |
| | | price1 = unitPrice * (totalSeat == 4 ? num7 : num8); |
| | | peopleNumber -= 1; |
| | | } |
| | | double price = (unitPrice * peopleNumber) + price1; |
| | | map.put("price", new BigDecimal(num3 > price ? num3 : price).setScale(2, BigDecimal.ROUND_HALF_EVEN).doubleValue()); |
| | | } else { |
| | | double price = unitPrice * totalSeat * num6; |
| | | map.put("price", new BigDecimal(num3 > price ? num3 : price).setScale(2, BigDecimal.ROUND_HALF_EVEN).doubleValue()); |
| | | } |
| | | } |
| | | Integer pricePeopleNumber = travelMode != null && travelMode == 2 && totalSeat != null && totalSeat > 0 ? totalSeat : peopleNumber; |
| | | BigDecimal unitPrice = queryDefaultLineDestinationPrice(lineId, totalSeat); |
| | | map.put("price", unitPrice == null ? -1 : multiplyPeopleNumber(unitPrice, pricePeopleNumber).doubleValue()); |
| | | return ResultUtil.success(map); |
| | | } |
| | | |
| | |
| | | unPayOrderVO.setDriverInfoWarpper(driverInfoWarpper); |
| | | //其他信息 |
| | | BeanUtils.copyProperties(orderCrossCity, unPayOrderVO); |
| | | unPayOrderVO.setPayMoney(orderCrossCity.getPayMoney() == null ? orderCrossCity.getOrderMoney() : orderCrossCity.getPayMoney()); |
| | | unPayOrderVOList.add(unPayOrderVO); |
| | | } |
| | | return unPayOrderVOList; |
| | |
| | | result.setLaveSeat(data.get("laveSeat") != null ? Integer.parseInt(data.get("laveSeat").toString()) : null); |
| | | result.setLaveSeatNumber(data.get("laveSeatNumber") != null ? data.get("laveSeatNumber").toString() : null); |
| | | |
| | | // 3. 解析价格JSON获取单人价格 |
| | | String priceContent = data.get("priceContent") != null ? data.get("priceContent").toString() : null; |
| | | if (priceContent != null && !priceContent.isEmpty()) { |
| | | JSONObject json = JSON.parseObject(priceContent); |
| | | String num1 = json.getString("num1"); |
| | | if (num1 != null && !num1.isEmpty()) { |
| | | result.setUnitPrice(Double.parseDouble(num1)); |
| | | } |
| | | } |
| | | result.setUnitPrice(queryDefaultLineDestinationPriceDouble(result.getLineId(), result.getTotalSeat())); |
| | | |
| | | // 站点信息 |
| | | result.setStartSiteId(data.get("startSiteId") != null ? Integer.parseInt(data.get("startSiteId").toString()) : null); |
| | |
| | | } |
| | | |
| | | public ResultUtil<Map<String, Object>> getPriceV2(Integer lineId, Integer lineDestinationId, Integer totalSeat, |
| | | Integer peopleNumber, Double endLon, Double endLat, Integer lineShiftDriverId) { |
| | | Integer peopleNumber, Double endLon, Double endLat, Integer lineShiftDriverId, Integer travelMode) { |
| | | Map<String, Object> map = new HashMap<>(); |
| | | map.put("distance", 0); |
| | | if (peopleNumber == null || peopleNumber <= 0 || endLon == null || endLat == null) { |
| | | map.put("price", -1); |
| | | return ResultUtil.success(map); |
| | | } |
| | | Integer pricePeopleNumber = travelMode != null && travelMode == 2 && totalSeat != null && totalSeat > 0 ? totalSeat : peopleNumber; |
| | | if (lineDestinationId != null && lineDestinationId > 0) { |
| | | Map<String, Object> destination = lineMapper.queryLineDestinationById(lineDestinationId, lineId); |
| | | BigDecimal unitPrice = null; |
| | | if (destination != null) { |
| | | unitPrice = totalSeat != null && totalSeat == 6 ? getBigDecimal(destination.get("price7")) : getBigDecimal(destination.get("price5")); |
| | | if (unitPrice == null) { |
| | | unitPrice = getBigDecimal(destination.get("price5")); |
| | | } |
| | | unitPrice = getDestinationPrice(destination, totalSeat); |
| | | } |
| | | map.put("price", unitPrice == null ? -1 : multiplyPeopleNumber(unitPrice, peopleNumber).doubleValue()); |
| | | map.put("price", unitPrice == null ? -1 : multiplyPeopleNumber(unitPrice, pricePeopleNumber).doubleValue()); |
| | | return ResultUtil.success(map); |
| | | } |
| | | if (lineId != null && lineId < -1) { |
| | | if (lineId != null && lineId <= -1) { |
| | | if (lineShiftDriverId == null) { |
| | | map.put("price", -1); |
| | | return ResultUtil.success(map); |
| | |
| | | OrderCrossCityScanWarpper warpper = new OrderCrossCityScanWarpper(); |
| | | warpper.setEndLon(endLon); |
| | | warpper.setEndLat(endLat); |
| | | warpper.setPeopleNumber(peopleNumber); |
| | | warpper.setPeopleNumber(pricePeopleNumber); |
| | | return getPriceV2(lineId, lineShiftDriver, warpper); |
| | | } |
| | | List<Map<String, Object>> destinations = lineMapper.queryLineDestinations(lineId); |
| | |
| | | map.put("price", -1); |
| | | return ResultUtil.success(map); |
| | | } |
| | | BigDecimal defaultPrice5 = getBigDecimal(destinations.get(0).get("price5")); |
| | | BigDecimal defaultPrice = getDestinationPrice(destinations.get(0), totalSeat); |
| | | BigDecimal matchedPrice = null; |
| | | for (Map<String, Object> destination : destinations) { |
| | | if (isPointInDestinationFence(destination, endLon, endLat)) { |
| | | matchedPrice = totalSeat != null && totalSeat == 6 ? getBigDecimal(destination.get("price7")) : getBigDecimal(destination.get("price5")); |
| | | if (matchedPrice == null) { |
| | | matchedPrice = getBigDecimal(destination.get("price5")); |
| | | } |
| | | matchedPrice = getDestinationPrice(destination, totalSeat); |
| | | break; |
| | | } |
| | | } |
| | | BigDecimal finalPrice = matchedPrice == null ? defaultPrice5 : matchedPrice; |
| | | map.put("price", finalPrice == null ? -1 : multiplyPeopleNumber(finalPrice, peopleNumber).doubleValue()); |
| | | BigDecimal finalPrice = matchedPrice == null ? defaultPrice : matchedPrice; |
| | | map.put("price", finalPrice == null ? -1 : multiplyPeopleNumber(finalPrice, pricePeopleNumber).doubleValue()); |
| | | return ResultUtil.success(map); |
| | | } |
| | | |
| | |
| | | if (destinations == null || destinations.size() == 0) { |
| | | return null; |
| | | } |
| | | BigDecimal defaultPrice5 = getBigDecimal(destinations.get(0).get("price5")); |
| | | BigDecimal defaultPrice = getDestinationPrice(destinations.get(0), lineShiftDriver.getTotalSeat()); |
| | | for (Map<String, Object> destination : destinations) { |
| | | if (isPointInDestinationFence(destination, warpper.getEndLon(), warpper.getEndLat())) { |
| | | if (lineShiftDriver.getTotalSeat() != null && lineShiftDriver.getTotalSeat() == 6) { |
| | | BigDecimal price7 = getBigDecimal(destination.get("price7")); |
| | | return price7 == null ? defaultPrice5 : price7; |
| | | } |
| | | BigDecimal price5 = getBigDecimal(destination.get("price5")); |
| | | return price5 == null ? defaultPrice5 : price5; |
| | | BigDecimal price = getDestinationPrice(destination, lineShiftDriver.getTotalSeat()); |
| | | return price == null ? defaultPrice : price; |
| | | } |
| | | } |
| | | return defaultPrice5; |
| | | return defaultPrice; |
| | | } |
| | | |
| | | private boolean isPointInDestinationFence(Map<String, Object> destination, Double lon, Double lat) { |
| | |
| | | } |
| | | } |
| | | |
| | | private BigDecimal queryDefaultLineDestinationPrice(Integer lineId, Integer totalSeat) { |
| | | List<Map<String, Object>> destinations = lineMapper.queryLineDestinations(lineId); |
| | | if (destinations == null || destinations.size() == 0) { |
| | | return null; |
| | | } |
| | | return getDestinationPrice(destinations.get(0), totalSeat); |
| | | } |
| | | |
| | | private Double queryDefaultLineDestinationPriceDouble(Integer lineId, Integer totalSeat) { |
| | | BigDecimal price = queryDefaultLineDestinationPrice(lineId, totalSeat); |
| | | return price == null ? 0.0D : price.doubleValue(); |
| | | } |
| | | |
| | | private BigDecimal getDestinationPrice(Map<String, Object> destination, Integer totalSeat) { |
| | | if (destination == null) { |
| | | return null; |
| | | } |
| | | BigDecimal price = totalSeat != null && totalSeat == 6 |
| | | ? getBigDecimal(destination.get("price7")) |
| | | : getBigDecimal(destination.get("price5")); |
| | | return price == null ? getBigDecimal(destination.get("price5")) : price; |
| | | } |
| | | |
| | | private BigDecimal multiplyPeopleNumber(BigDecimal price, Integer peopleNumber) { |
| | | if (price == null || peopleNumber == null || peopleNumber <= 0) { |
| | | return null; |