| | |
| | | |
| | | import com.alibaba.fastjson.JSON; |
| | | import com.alibaba.fastjson.JSONArray; |
| | | import com.alibaba.fastjson.JSONObject; |
| | | import com.baomidou.mybatisplus.mapper.EntityWrapper; |
| | | import com.baomidou.mybatisplus.service.impl.ServiceImpl; |
| | | import com.stylefeng.guns.core.util.ToolUtil; |
| | |
| | | |
| | | @Autowired |
| | | private IUserRedPacketRecordService userRedPacketRecordService; |
| | | |
| | | @Resource |
| | | private SystemPriceMapper systemPriceMapper; |
| | | @Autowired |
| | | private PushUtil pushUtil; |
| | | |
| | |
| | | OrderTaxi orderTaxi = this.selectById(orderId); |
| | | orderTaxi.setPayManner(type); |
| | | if(type == 2){//其他支付,不需要操作,直接完成订单 |
| | | orderTaxi.setOrderMoney(0D); |
| | | orderTaxi.setTravelMoney(0D); |
| | | orderTaxi.setParkMoney(0D); |
| | | orderTaxi.setRoadTollMoney(0D); |
| | | orderTaxi.setRedPacketMoney(0D); |
| | | orderTaxi.setCouponMoney(0D); |
| | | orderTaxi.setDiscount(0D); |
| | | orderTaxi.setDiscountMoney(0D); |
| | | orderTaxi.setPayMoney(0D); |
| | | orderTaxi = this.setMoney1(orderTaxi, travelFee, parkingFee, crossingFee); |
| | | orderTaxi.setState(8); |
| | | }else{ |
| | | orderTaxi = this.setMoney(orderTaxi, travelFee, parkingFee, crossingFee); |
| | | orderTaxi = this.setMoney2(orderTaxi, parkingFee, crossingFee); |
| | | orderTaxi.setState(7); |
| | | } |
| | | this.updateById(orderTaxi); |
| | |
| | | public List<OrderTaxi> taskMidAxbUnBindSend() throws Exception { |
| | | return orderTaxiMapper.taskMidAxbUnBindSend(); |
| | | } |
| | | /** |
| | | * 计算价格 |
| | | * @param orderTaxi |
| | | * @param parkingFee |
| | | * @param crossingFee |
| | | * @return |
| | | * @throws Exception |
| | | */ |
| | | public OrderTaxi setMoney1(OrderTaxi orderTaxi, Double travelFee, Double parkingFee, Double crossingFee) throws Exception{ |
| | | |
| | | if (travelFee!=null){ |
| | | String s = travelFee.toString(); |
| | | BigDecimal trave = new BigDecimal(s); |
| | | orderTaxi.setTravelMoney(trave.setScale(2, BigDecimal.ROUND_DOWN).doubleValue()); |
| | | }else{ |
| | | orderTaxi.setTravelMoney(0.0); |
| | | |
| | | } |
| | | if (parkingFee!=null){ |
| | | String s1 = parkingFee.toString(); |
| | | BigDecimal parking = new BigDecimal(s1); |
| | | orderTaxi.setParkMoney(parking.setScale(2, BigDecimal.ROUND_DOWN).doubleValue()); |
| | | }else{ |
| | | orderTaxi.setParkMoney(0.0); |
| | | |
| | | } |
| | | if (crossingFee!=null){ |
| | | String s2 = crossingFee.toString(); |
| | | |
| | | BigDecimal crossing = new BigDecimal(s2); |
| | | orderTaxi.setRoadTollMoney(crossing.setScale(2, BigDecimal.ROUND_DOWN).doubleValue()); |
| | | }else{ |
| | | orderTaxi.setRoadTollMoney(0.0); |
| | | } |
| | | BigDecimal sum = new BigDecimal(null == travelFee ? 0 : travelFee).add(new BigDecimal(null == parkingFee ? 0 : parkingFee)) |
| | | .add(new BigDecimal(null == crossingFee ? 0 : crossingFee)).add(new BigDecimal(null == orderTaxi.getTipMoney() ? 0 : orderTaxi.getTipMoney())); |
| | | orderTaxi.setOrderMoney(sum.setScale(2, BigDecimal.ROUND_DOWN).doubleValue()); |
| | | return orderTaxi; |
| | | } |
| | | |
| | | /** |
| | | * 计算价格 |
| | | * @param orderTaxi |
| | | * @param parkingFee |
| | | * @param crossingFee |
| | | * @return |
| | | * @throws Exception |
| | | */ |
| | | public OrderTaxi setMoney2(OrderTaxi orderTaxi, Double parkingFee, Double crossingFee) throws Exception { |
| | | Map<String, Object> query1 = systemPriceMapper.query1(orderTaxi.getCompanyId(), 1); |
| | | //开始根据不同的方式计算金额 |
| | | double amount = 0; |
| | | JSONObject jsonObject = JSON.parseObject(String.valueOf(query1.get("content"))); |
| | | |
| | | JSONObject contentExclusive = JSON.parseObject(query1.get("contentExclusive").toString());//独享 |
| | | System.out.println("独享内容"+contentExclusive); |
| | | //乘车类型(1=独享,2=一口价,3=拼车) |
| | | double d = (null == orderTaxi.getMileage() ? 0D : orderTaxi.getMileage()); |
| | | System.out.println("行驶里程数"+d); |
| | | //在价格区间按照一口价算,不在区间按实时价格算 |
| | | System.out.println("不在区间===================="); |
| | | orderTaxi = calculationPrice(orderTaxi,contentExclusive,jsonObject.getLongValue("num1"),jsonObject.getDouble("num2"),parkingFee,crossingFee); |
| | | System.out.println("返回订单数据"+orderTaxi); |
| | | return orderTaxi; |
| | | } |
| | | |
| | | public OrderTaxi calculationPrice(OrderTaxi OrderTaxi,JSONObject rule, long wait,Double waitMoney, Double parkingFee, Double crossingFee) throws Exception { |
| | | double amount = 0.0; |
| | | //等待费 |
| | | Date date = new Date(); |
| | | if(OrderTaxi.getEndServiceTime()==null)OrderTaxi.setEndServiceTime(date); |
| | | double d = (null == OrderTaxi.getMileage() ? 0D : OrderTaxi.getMileage()) / 1000;//实际公里 |
| | | double t = ((OrderTaxi.getEndServiceTime().getTime() - OrderTaxi.getStartServiceTime().getTime()) / 60000) + 1;//实际时间(不满一分钟按一分钟算) |
| | | double d1 = (d - rule.getDouble("num2")) < 0 ? 0 : d - rule.getDouble("num2");//超出起步里程的公里 |
| | | double t1 = (t - rule.getDouble("num3")) < 0 ? 0 : t - rule.getDouble("num3");//超过起步分钟数的时间 |
| | | double w = ((OrderTaxi.getStartServiceTime().getTime() - OrderTaxi.getArriveTime().getTime()) / 60000) + 1;//等待分钟(不满一分钟按一分钟算) |
| | | double w1 = (w - wait) < 0 ? 0 : new BigDecimal(w - wait).setScale(0, BigDecimal.ROUND_UP).doubleValue();//超出等待时间的时间 |
| | | double yt1 = 0;//远途1段 |
| | | double yt2 = 0;//远途2段 |
| | | double yt3 = 0;//远途3段 |
| | | |
| | | |
| | | //夜间服务处理逻辑 |
| | | Calendar s = Calendar.getInstance(); |
| | | s.setTime(date); |
| | | s.set(Calendar.HOUR_OF_DAY, Integer.valueOf(rule.getString("num14").split(" - ")[0].split(":")[0])); |
| | | s.set(Calendar.MINUTE, Integer.valueOf(rule.getString("num14").split(" - ")[0].split(":")[1])); |
| | | |
| | | Calendar e = Calendar.getInstance(); |
| | | e.setTime(date); |
| | | e.set(Calendar.HOUR_OF_DAY, Integer.valueOf(rule.getString("num14").split(" - ")[1].split(":")[0])); |
| | | e.set(Calendar.MINUTE, Integer.valueOf(rule.getString("num14").split(" - ")[1].split(":")[1])); |
| | | |
| | | if(date.getTime() > s.getTimeInMillis() && date.getTime() < e.getTimeInMillis()){ |
| | | if(d > rule.getDouble("num6") && d < rule.getDouble("num7")){ |
| | | yt1 = rule.getDouble("num18") * d; |
| | | // OrderTaxi.setLongDistance(new BigDecimal((d > rule.getDouble("num6")) ? d - rule.getDouble("num6") : 0).setScale(2, BigDecimal.ROUND_HALF_EVEN).doubleValue()); |
| | | } |
| | | if(d > rule.getDouble("num9") && d < rule.getDouble("num10")){ |
| | | yt1 = rule.getDouble("num18") * rule.getDouble("num7"); |
| | | yt2 = rule.getDouble("num19") * (d - rule.getDouble("num9")); |
| | | // OrderTaxi.setLongDistance(new BigDecimal((d > rule.getDouble("num9")) ? d - rule.getDouble("num9") : 0).setScale(2, BigDecimal.ROUND_HALF_EVEN).doubleValue()); |
| | | } |
| | | if(d > rule.getDouble("num12")){ |
| | | yt1 = rule.getDouble("num18") * rule.getDouble("num7"); |
| | | yt2 = rule.getDouble("num19") * (rule.getDouble("num10") - rule.getDouble("num9")); |
| | | yt3 = rule.getDouble("num20") * (d - rule.getDouble("num12")); |
| | | // OrderTaxi.setLongDistance(new BigDecimal((d > rule.getDouble("num12")) ? d - rule.getDouble("num12") : 0).setScale(2, BigDecimal.ROUND_HALF_EVEN).doubleValue()); |
| | | } |
| | | // amount = rule.getDouble("num15") + (d1 * rule.getDouble("num16")) + (t1 * rule.getDouble("num17")) + (w1 * waitMoney) + yt1 + yt2 + yt3; |
| | | OrderTaxi.setStartMileage(rule.getDouble("num2")); |
| | | OrderTaxi.setStartMoney(rule.getDouble("num15"));//起步价 |
| | | OrderTaxi.setMileageKilometers(new BigDecimal(d1).setScale(2, BigDecimal.ROUND_HALF_EVEN).doubleValue()); |
| | | OrderTaxi.setMileageMoney(new BigDecimal(d1 * rule.getDouble("num16")).setScale(2, BigDecimal.ROUND_DOWN).doubleValue());//里程费 |
| | | OrderTaxi.setDuration(new BigDecimal(t1).setScale(2, BigDecimal.ROUND_HALF_EVEN).doubleValue()); |
| | | OrderTaxi.setDurationMoney(new BigDecimal(t1 * rule.getDouble("num17")).setScale(2, BigDecimal.ROUND_DOWN).doubleValue());//时长费 |
| | | OrderTaxi.setWait(new BigDecimal(w1).setScale(2, BigDecimal.ROUND_HALF_EVEN).doubleValue()); |
| | | OrderTaxi.setWaitMoney(new BigDecimal(w1 * waitMoney).setScale(2, BigDecimal.ROUND_DOWN).doubleValue());//等待费 |
| | | // OrderTaxi.setLongDistance(new BigDecimal((d > rule.getDouble("num6")) ? d - rule.getDouble("num6") : 0).setScale(2, BigDecimal.ROUND_HALF_EVEN).doubleValue()); |
| | | OrderTaxi.setLongDistance(new BigDecimal((d > rule.getDouble("num6")) ? d - rule.getDouble("num6") : 0).setScale(2, BigDecimal.ROUND_HALF_EVEN).doubleValue()); |
| | | OrderTaxi.setLongDistanceMoney(new BigDecimal(yt1 + yt2 + yt3).setScale(2, BigDecimal.ROUND_DOWN).doubleValue());//远途费 |
| | | OrderTaxi.setParkMoney(parkingFee);//停车费 |
| | | OrderTaxi.setRoadTollMoney(crossingFee);//过路费 |
| | | OrderTaxi.setRedPacketMoney(0D);//红包抵扣 |
| | | OrderTaxi.setCouponMoney(0D);//优惠券抵扣 |
| | | OrderTaxi.setDiscount(0D);//优惠抵扣 |
| | | OrderTaxi.setPayMoney(0D);//支付金额 |
| | | amount = OrderTaxi.getStartMoney() + OrderTaxi.getMileageMoney() + |
| | | OrderTaxi.getDurationMoney() + OrderTaxi.getWaitMoney() + OrderTaxi.getLongDistanceMoney(); |
| | | OrderTaxi.setOrderMoney(amount+OrderTaxi.getParkMoney()+OrderTaxi.getRoadTollMoney()); |
| | | }else{ |
| | | Calendar s1 = Calendar.getInstance(); |
| | | s1.setTime(date); |
| | | s1.set(Calendar.HOUR_OF_DAY, Integer.valueOf(rule.getString("num21").split(" - ")[0].split(":")[0])); |
| | | s1.set(Calendar.MINUTE, Integer.valueOf(rule.getString("num21").split(" - ")[0].split(":")[1])); |
| | | |
| | | Calendar e1 = Calendar.getInstance(); |
| | | e1.setTime(date); |
| | | e1.set(Calendar.HOUR_OF_DAY, Integer.valueOf(rule.getString("num21").split(" - ")[1].split(":")[0])); |
| | | e1.set(Calendar.MINUTE, Integer.valueOf(rule.getString("num21").split(" - ")[1].split(":")[1])); |
| | | |
| | | Calendar s2 = Calendar.getInstance(); |
| | | s2.setTime(date); |
| | | s2.set(Calendar.HOUR_OF_DAY, Integer.valueOf(rule.getString("num22").split(" - ")[0].split(":")[0])); |
| | | s2.set(Calendar.MINUTE, Integer.valueOf(rule.getString("num22").split(" - ")[0].split(":")[1])); |
| | | |
| | | Calendar e2 = Calendar.getInstance(); |
| | | e2.setTime(date); |
| | | e2.set(Calendar.HOUR_OF_DAY, Integer.valueOf(rule.getString("num22").split(" - ")[1].split(":")[0])); |
| | | e2.set(Calendar.MINUTE, Integer.valueOf(rule.getString("num22").split(" - ")[1].split(":")[1])); |
| | | //高峰时段处理逻辑 |
| | | if((date.getTime() > s1.getTimeInMillis() && date.getTime() < e1.getTimeInMillis()) || (date.getTime() > s2.getTimeInMillis() && date.getTime() < e2.getTimeInMillis())){ |
| | | if(d > rule.getDouble("num6") && d < rule.getDouble("num7")){ |
| | | yt1 = rule.getDouble("num26") * d; |
| | | // OrderTaxi.setLongDistance(new BigDecimal((d > rule.getDouble("num6")) ? d - rule.getDouble("num6") : 0).setScale(2, BigDecimal.ROUND_HALF_EVEN).doubleValue()); |
| | | } |
| | | if(d > rule.getDouble("num9") && d < rule.getDouble("num10")){ |
| | | yt1 = rule.getDouble("num26") * rule.getDouble("num7"); |
| | | yt2 = rule.getDouble("num27") * (d - rule.getDouble("num9")); |
| | | // OrderTaxi.setLongDistance(new BigDecimal((d > rule.getDouble("num9")) ? d - rule.getDouble("num9") : 0).setScale(2, BigDecimal.ROUND_HALF_EVEN).doubleValue()); |
| | | } |
| | | if(d > rule.getDouble("num12")){ |
| | | yt1 = rule.getDouble("num26") * rule.getDouble("num7"); |
| | | yt2 = rule.getDouble("num27") * (rule.getDouble("num10") - rule.getDouble("num9")); |
| | | yt3 = rule.getDouble("num28") * (d - rule.getDouble("num12")); |
| | | // OrderTaxi.setLongDistance(new BigDecimal((d > rule.getDouble("num12")) ? d - rule.getDouble("num12") : 0).setScale(2, BigDecimal.ROUND_HALF_EVEN).doubleValue()); |
| | | } |
| | | // amount = rule.getDouble("num23") + (d1 * rule.getDouble("num24")) + (t1 * rule.getDouble("num25")) + (w1 * waitMoney) + yt1 + yt2 + yt3; |
| | | OrderTaxi.setStartMileage(rule.getDouble("num2")); |
| | | OrderTaxi.setStartMoney(rule.getDouble("num23"));//起步价 |
| | | OrderTaxi.setMileageKilometers(new BigDecimal(d1).setScale(2, BigDecimal.ROUND_HALF_EVEN).doubleValue()); |
| | | OrderTaxi.setMileageMoney(new BigDecimal(d1 * rule.getDouble("num24")).setScale(2, BigDecimal.ROUND_DOWN).doubleValue());//里程费 |
| | | OrderTaxi.setDuration(new BigDecimal(t1).setScale(2, BigDecimal.ROUND_HALF_EVEN).doubleValue()); |
| | | OrderTaxi.setDurationMoney(new BigDecimal(t1 * rule.getDouble("num25")).setScale(2, BigDecimal.ROUND_DOWN).doubleValue());//时长费 |
| | | OrderTaxi.setWait(new BigDecimal(w1).setScale(2, BigDecimal.ROUND_HALF_EVEN).doubleValue()); |
| | | OrderTaxi.setWaitMoney(new BigDecimal(w1 * waitMoney).setScale(2, BigDecimal.ROUND_DOWN).doubleValue());//等待费 |
| | | // OrderTaxi.setLongDistance(new BigDecimal((d > rule.getDouble("num6")) ? d - rule.getDouble("num6") : 0).setScale(2, BigDecimal.ROUND_HALF_EVEN).doubleValue()); |
| | | OrderTaxi.setLongDistance(new BigDecimal((d > rule.getDouble("num6")) ? d - rule.getDouble("num6") : 0).setScale(2, BigDecimal.ROUND_HALF_EVEN).doubleValue()); |
| | | OrderTaxi.setLongDistanceMoney(new BigDecimal(yt1 + yt2 + yt3).setScale(2, BigDecimal.ROUND_DOWN).doubleValue());//远途费 |
| | | OrderTaxi.setParkMoney(parkingFee);//停车费 |
| | | OrderTaxi.setRoadTollMoney(crossingFee);//过路费 |
| | | OrderTaxi.setRedPacketMoney(0D);//红包抵扣 |
| | | OrderTaxi.setCouponMoney(0D);//优惠券抵扣 |
| | | OrderTaxi.setDiscount(0D);//优惠抵扣 |
| | | OrderTaxi.setPayMoney(0D);//支付金额 |
| | | // amount = new BigDecimal(OrderTaxi.getStartMoney()) |
| | | // .add(new BigDecimal(OrderTaxi.getMileageMoney())) |
| | | // .add(new BigDecimal(OrderTaxi.getDurationMoney())) |
| | | // .add(new BigDecimal(OrderTaxi.getWaitMoney())) |
| | | // .add(new BigDecimal(OrderTaxi.getLongDistanceMoney())); |
| | | // OrderTaxi.setOrderMoney(amount.add(new BigDecimal(parkingFee)).add(new BigDecimal(parkingFee)).setScale(2, BigDecimal.ROUND_DOWN).doubleValue()); |
| | | amount = OrderTaxi.getStartMoney() + OrderTaxi.getMileageMoney() + |
| | | OrderTaxi.getDurationMoney() + OrderTaxi.getWaitMoney() + OrderTaxi.getLongDistanceMoney(); |
| | | OrderTaxi.setOrderMoney(amount+OrderTaxi.getParkMoney()+OrderTaxi.getRoadTollMoney()); |
| | | }else{ |
| | | //其他时间段的计算 |
| | | if(d > rule.getDouble("num6") && d < rule.getDouble("num7")){ |
| | | yt1 = rule.getDouble("num8") * d; |
| | | // OrderTaxi.setLongDistance(new BigDecimal((d > rule.getDouble("num6")) ? d - rule.getDouble("num6") : 0).setScale(2, BigDecimal.ROUND_HALF_EVEN).doubleValue()); |
| | | } |
| | | if(d > rule.getDouble("num9") && d < rule.getDouble("num10")){ |
| | | yt1 = rule.getDouble("num8") * rule.getDouble("num7"); |
| | | yt2 = rule.getDouble("num11") * (d - rule.getDouble("num9")); |
| | | // OrderTaxi.setLongDistance(new BigDecimal((d > rule.getDouble("num9")) ? d - rule.getDouble("num9") : 0).setScale(2, BigDecimal.ROUND_HALF_EVEN).doubleValue()); |
| | | } |
| | | if(d > rule.getDouble("num12")){ |
| | | yt1 = rule.getDouble("num8") * rule.getDouble("num7"); |
| | | yt2 = rule.getDouble("num11") * (rule.getDouble("num10") - rule.getDouble("num9")); |
| | | yt3 = rule.getDouble("num13") * (d - rule.getDouble("num12")); |
| | | // OrderTaxi.setLongDistance(new BigDecimal((d > rule.getDouble("num12")) ? d - rule.getDouble("num12") : 0).setScale(2, BigDecimal.ROUND_HALF_EVEN).doubleValue()); |
| | | } |
| | | // amount = rule.getDouble("num1") + (d1 * rule.getDouble("num4")) + (t1 * rule.getDouble("num5")) + (w1 * waitMoney) + yt1 + yt2 + yt3; |
| | | OrderTaxi.setStartMileage(rule.getDouble("num2")); |
| | | OrderTaxi.setStartMoney(rule.getDouble("num1"));//起步价 |
| | | OrderTaxi.setMileageKilometers(new BigDecimal(d1).setScale(2, BigDecimal.ROUND_HALF_EVEN).doubleValue()); |
| | | OrderTaxi.setMileageMoney(new BigDecimal(d1 * rule.getDouble("num4")).setScale(2, BigDecimal.ROUND_DOWN).doubleValue());//里程费 |
| | | OrderTaxi.setDuration(new BigDecimal(t1).setScale(2, BigDecimal.ROUND_HALF_EVEN).doubleValue()); |
| | | OrderTaxi.setDurationMoney(new BigDecimal(t1 * rule.getDouble("num5")).setScale(2, BigDecimal.ROUND_DOWN).doubleValue());//时长费 |
| | | OrderTaxi.setWait(new BigDecimal(w1).setScale(2, BigDecimal.ROUND_HALF_EVEN).doubleValue()); |
| | | OrderTaxi.setWaitMoney(new BigDecimal(w1 * waitMoney).setScale(2, BigDecimal.ROUND_DOWN).doubleValue());//等待费 |
| | | // OrderTaxi.setLongDistance(new BigDecimal((d > rule.getDouble("num6")) ? d - rule.getDouble("num6") : 0).setScale(2, BigDecimal.ROUND_HALF_EVEN).doubleValue()); |
| | | OrderTaxi.setLongDistance(new BigDecimal((d > rule.getDouble("num6")) ? d - rule.getDouble("num6") : 0).setScale(2, BigDecimal.ROUND_HALF_EVEN).doubleValue()); |
| | | OrderTaxi.setLongDistanceMoney(new BigDecimal(yt1 + yt2 + yt3).setScale(2, BigDecimal.ROUND_DOWN).doubleValue());//远途费 |
| | | OrderTaxi.setParkMoney(parkingFee);//停车费 |
| | | OrderTaxi.setRoadTollMoney(crossingFee);//过路费 |
| | | OrderTaxi.setRedPacketMoney(0D);//红包抵扣 |
| | | OrderTaxi.setCouponMoney(0D);//优惠券抵扣 |
| | | OrderTaxi.setDiscount(0D);//优惠抵扣 |
| | | OrderTaxi.setPayMoney(0D);//支付金额 |
| | | amount = OrderTaxi.getStartMoney() + OrderTaxi.getMileageMoney() + |
| | | OrderTaxi.getDurationMoney() + OrderTaxi.getWaitMoney() + OrderTaxi.getLongDistanceMoney(); |
| | | OrderTaxi.setOrderMoney(amount+OrderTaxi.getParkMoney()+OrderTaxi.getRoadTollMoney()); |
| | | } |
| | | } |
| | | return OrderTaxi; |
| | | } |
| | | /** |
| | | * 计算费用 |
| | | * @param orderTaxi |