| | |
| | | package com.stylefeng.guns.modular.specialTrain.server.impl; |
| | | |
| | | import com.alibaba.fastjson.JSON; |
| | | import com.alibaba.fastjson.JSONArray; |
| | | import com.alibaba.fastjson.JSONObject; |
| | | import com.alipay.api.domain.CarModel; |
| | | import com.baomidou.mybatisplus.mapper.EntityWrapper; |
| | | import com.baomidou.mybatisplus.service.impl.ServiceImpl; |
| | | import com.stylefeng.guns.core.shiro.ShiroKit; |
| | | import com.stylefeng.guns.core.util.ToolUtil; |
| | | import com.stylefeng.guns.modular.crossCity.dao.OrderCrossCityMapper; |
| | | import com.stylefeng.guns.modular.crossCity.model.OrderCrossCity; |
| | | import com.stylefeng.guns.modular.crossCity.server.IOrderCrossCityService; |
| | | import com.stylefeng.guns.modular.crossCity.server.impl.OrderCrossCityServiceImpl; |
| | | import com.stylefeng.guns.modular.smallLogistics.server.IOrderLogisticsService; |
| | | import com.stylefeng.guns.modular.specialTrain.dao.OrderPrivateCarMapper; |
| | | import com.stylefeng.guns.modular.specialTrain.model.OrderPrivateCar; |
| | | import com.stylefeng.guns.modular.specialTrain.server.IOrderPrivateCarService; |
| | |
| | | import com.stylefeng.guns.modular.system.model.*; |
| | | import com.stylefeng.guns.modular.system.service.*; |
| | | import com.stylefeng.guns.modular.system.util.*; |
| | | import com.stylefeng.guns.modular.system.warpper.*; |
| | | import com.stylefeng.guns.modular.system.util.LiuZhouBank.PayUtil; |
| | | import com.stylefeng.guns.modular.system.warpper.BaseWarpper; |
| | | import com.stylefeng.guns.modular.system.warpper.EndPushWarpper; |
| | | import com.stylefeng.guns.modular.system.warpper.OrderServerWarpper; |
| | | import com.stylefeng.guns.modular.system.warpper.SmartScreenOrderVo; |
| | | 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 com.stylefeng.guns.modular.taxi.service.IOrderTaxiService; |
| | | import com.stylefeng.guns.modular.taxi.service.IPaymentRecordService; |
| | | import com.stylefeng.guns.modular.taxi.service.ITransactionDetailsService; |
| | | import com.stylefeng.guns.modular.taxi.warpper.OrderTaxiWarpper; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.beans.factory.annotation.Value; |
| | | import org.springframework.http.HttpEntity; |
| | |
| | | |
| | | import javax.annotation.Resource; |
| | | import java.math.BigDecimal; |
| | | import java.math.MathContext; |
| | | import java.math.RoundingMode; |
| | | import java.text.SimpleDateFormat; |
| | | import java.text.SimpleDateFormat; |
| | | import java.util.*; |
| | | import java.util.stream.Collectors; |
| | | |
| | | |
| | | @Service |
| | |
| | | |
| | | @Resource |
| | | private RegionMapper regionMapper; |
| | | |
| | | @Resource |
| | | private UserInfoMapper userInfoMapper; |
| | | |
| | | @Autowired |
| | | private DateUtil dateUtil; |
| | |
| | | @Autowired |
| | | private IOrderTaxiService orderTaxiService; |
| | | |
| | | @Resource |
| | | private ServerCarModelMapper serverCarModelMapper; |
| | | |
| | | @Resource |
| | | private CarMapper carMapper; |
| | | |
| | | @Autowired |
| | | private PayMoneyUtil payMoneyUtil; |
| | | |
| | | @Autowired |
| | | private IOrderLogisticsService orderLogisticsService; |
| | | |
| | | @Autowired |
| | | private ITaxiCardPaymentService taxiCardPaymentService; |
| | | |
| | | @Autowired |
| | | private ITaxiCardService taxiCardService; |
| | | |
| | | @Autowired |
| | | private IOpenCityService openCityService; |
| | | |
| | | @Autowired |
| | | private IUserUserService userUserService; |
| | | |
| | | @Autowired |
| | | private IUserTaxiCardService userTaxiCardService; |
| | | |
| | | @Autowired |
| | | private IRegionService regionService; |
| | | |
| | | |
| | | public static List<Integer> orderIds = new ArrayList<>(); |
| | | |
| | |
| | | |
| | | @Value("${pushMinistryOfTransport}") |
| | | private boolean pushMinistryOfTransport; |
| | | |
| | | @Autowired |
| | | private ITbSpellOrderRuleService spellOrderRuleService; |
| | | |
| | | |
| | | |
| | |
| | | */ |
| | | @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 peopleNum,Integer rideType) throws Exception { |
| | | String startAddress, String endLon, String endLat, String endAddress, String name, String phone, Integer orderSource, Integer driverId, Integer type, Integer uid, String deviceCode) throws Exception { |
| | | |
| | | //如果出行时间大于当前10分钟则默认为预约单 |
| | | if(travelTime.getTime() > (System.currentTimeMillis() + 600000)){ |
| | |
| | | } |
| | | |
| | | /** |
| | | * 1.出租车、专车、跨城有待支付的订单不能叫车 |
| | | * 2.小件物流有未完成的订单可以下跨城、专车、出租车 |
| | | * 3.出租车、专车、跨城有预约单可以下即时单 |
| | | * 1.下了即时单就不能下预约单和即时单 |
| | | * 2.下了预约单和再下一张即时单不能再下预约单 |
| | | */ |
| | | List<OrderPrivateCar> orderPrivateCars = orderPrivateCarMapper.queryByState(uid, null, 1, 7, 12); |
| | | List<OrderPrivateCar> orderPrivateCars = orderPrivateCarMapper.queryByState(uid, 1, 1, 1, 2, 3, 4, 5, 6, 7, 11); |
| | | if(orderPrivateCars.size() > 0){ |
| | | return ResultUtil.error("有未完成的订单"); |
| | | } |
| | | List<OrderTaxi> list = orderTaxiMapper.queryByState_(uid, null, 1, 7, 12); |
| | | List<OrderTaxi> list = orderTaxiMapper.queryByState_(uid, 1, 1, 1, 2, 3, 4, 5, 6, 11); |
| | | if(list.size() > 0){ |
| | | return ResultUtil.error("有未完成的订单"); |
| | | } |
| | | List<OrderCrossCity> orderCrossCities1 = orderCrossCityMapper.queryByState(uid, 7, 12); |
| | | if(orderCrossCities1.size() > 0){ |
| | | |
| | | orderPrivateCars = orderPrivateCarMapper.queryByState(uid, 2, 1, 1, 2, 3, 4, 5, 6, 7, 11); |
| | | if(orderPrivateCars.size() > 0 && reservation == 2){ |
| | | return ResultUtil.error("有未完成的订单"); |
| | | } |
| | | if(reservation == 1){ |
| | | orderPrivateCars = orderPrivateCarMapper.queryByState(uid, 1, 1, 1, 2, 3, 4, 5, 6, 7, 11, 12); |
| | | if(orderPrivateCars.size() > 0){ |
| | | list = orderTaxiMapper.queryByState_(uid, 2, 1, 1, 2, 3, 4, 5, 6, 11); |
| | | if(list.size() > 0 && reservation == 2){ |
| | | return ResultUtil.error("有未完成的订单"); |
| | | } |
| | | list = orderTaxiMapper.queryByState_(uid, 1, 1, 1, 2, 3, 4, 5, 6, 7, 11, 12); |
| | | if(list.size() > 0){ |
| | | return ResultUtil.error("有未完成的订单"); |
| | | } |
| | | } |
| | | |
| | | |
| | | |
| | | |
| | | startAddress = startAddress.replaceAll("& #40;", "("); |
| | | startAddress = startAddress.replaceAll("& #41;", ")"); |
| | |
| | | } |
| | | |
| | | OrderPrivateCar orderPrivateCar = new OrderPrivateCar(); |
| | | orderPrivateCar.setPeopleNum(peopleNum); |
| | | orderPrivateCar.setRideType(rideType); |
| | | orderPrivateCar.setType(type); |
| | | orderPrivateCar.setUserId(uid); |
| | | orderPrivateCar.setServerCarModelId(serverCarModelId); |
| | |
| | | orderPrivateCar.setStartLon(Double.valueOf(startLon)); |
| | | orderPrivateCar.setStartLat(Double.valueOf(startLat)); |
| | | orderPrivateCar.setStartAddress(startAddress); |
| | | if(ToolUtil.isNotEmpty(endLon)){ |
| | | orderPrivateCar.setEndLon(Double.valueOf(endLon)); |
| | | } |
| | | if(ToolUtil.isNotEmpty(endLat)){ |
| | | orderPrivateCar.setEndLat(Double.valueOf(endLat)); |
| | | } |
| | | if(ToolUtil.isNotEmpty(endAddress)){ |
| | | orderPrivateCar.setEndAddress(endAddress); |
| | | } |
| | | orderPrivateCar.setSubstitute(instead); |
| | | orderPrivateCar.setPassengers(name); |
| | | orderPrivateCar.setPassengersPhone(phone); |
| | | Map<String,String> distanceMap = gdMapElectricFenceUtil.getDistance(orderPrivateCar.getStartLon() + "," + orderPrivateCar.getStartLat(), orderPrivateCar.getEndLon() + "," + orderPrivateCar.getEndLat(), 1); |
| | | orderPrivateCar.setEstimateMileage(Double.valueOf(distanceMap.get("distance").toString())); |
| | | orderPrivateCar.setEstimateTime(Double.valueOf(distanceMap.get("duration").toString())/60); |
| | | if(instead == 0 || ToolUtil.isEmpty(orderPrivateCar.getPassengers())){ |
| | | UserInfo userInfo = userInfoService.selectById(uid); |
| | | if(ToolUtil.isEmpty(userInfo.getPhone())){ |
| | |
| | | if(driver.getState() == 3){ |
| | | return ResultUtil.error("司机正在服务中,无法提供服务"); |
| | | } |
| | | Integer orderType = orderPrivateCar.getRideType()==1?1:orderPrivateCar.getRideType()==2?9:8; |
| | | //List<DriverService> query = driverServiceService.query(driverId, orderType); |
| | | List<Integer> query = driverServiceService.getDriverService(driverId, orderType); |
| | | List<DriverService> query = driverServiceService.query(driverId, 1); |
| | | if(query.size() == 0){ |
| | | return ResultUtil.error("该司机不能服务此业务"); |
| | | } |
| | |
| | | orderPrivateCar.setServerCarModelId(query1.getServerCarModelId()); |
| | | orderPrivateCar.setSnatchOrderTime(new Date()); |
| | | |
| | | // //调用高德创建轨迹 |
| | | // String s = gdFalconUtil.selectTerminal(driver.getPhone()); |
| | | // String track = gdFalconUtil.createTrack(s); |
| | | // orderPrivateCar.setTrackId(track); |
| | | // |
| | | //调用高德创建轨迹 |
| | | String s = gdFalconUtil.selectTerminal(driver.getPhone()); |
| | | String track = gdFalconUtil.createTrack(s); |
| | | orderPrivateCar.setTrackId(track); |
| | | |
| | | //调用移动的小号接口 |
| | | Map<String, String> map = chinaMobileUtil.midAxbBindSend(orderPrivateCar.getPassengersPhone(), driver.getPhone(), (System.currentTimeMillis() + 86400000)); |
| | | 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(), Integer.valueOf(region.getCitycode().substring(1))); |
| | | if(String.valueOf(map.get("code")).equals("200")){ |
| | | orderPrivateCar.setTelX(map.get("telX")); |
| | | orderPrivateCar.setBindId(map.get("bindId")); |
| | |
| | | driver.setState(3); |
| | | driverService.updateById(driver); |
| | | } |
| | | //判断独享,一口价,拼车 |
| | | if(orderPrivateCar.getRideType()!=3){ |
| | | orderPrivateCar.setTotalPeopleNum(peopleNum); |
| | | |
| | | orderPrivateCar.setIsReassign(1); |
| | | orderPrivateCar.setIsDelete(1); |
| | | this.insert(orderPrivateCar); |
| | |
| | | }).start(); |
| | | } |
| | | |
| | | //推单操作-独享 |
| | | //推单操作 |
| | | if(orderPrivateCar.getState() == 1){ |
| | | this.pushOrder(orderPrivateCar); |
| | | } |
| | | }else{ |
| | | OrderPrivateCar orderPrivateCar1 = null; |
| | | //判断是否有相同线路的拼车-有直接拼成功,或者推送拼车订单 |
| | | List<OrderPrivateCar> orderList = orderPrivateCarMapper.selectList(new EntityWrapper<OrderPrivateCar>().eq("rideType",3).in("state","2,3,4").le("totalPeopleNum",4-peopleNum)); |
| | | for(OrderPrivateCar order:orderList){ |
| | | TbSpellOrderRule spellOrderRule = spellOrderRuleService.selectOne(new EntityWrapper<TbSpellOrderRule>().eq("companyId",order.getCompanyId())); |
| | | if(spellOrderRule!=null){ |
| | | JSONObject jsonObject = JSONObject.parseObject(spellOrderRule.getContent()); |
| | | //判断时间 |
| | | |
| | | if(travelTime.getTime()>=order.getTravelTime().getTime()-jsonObject.getInteger("num5")*60000L && travelTime.getTime()<=order.getTravelTime().getTime()+jsonObject.getInteger("num6")*60000L){ |
| | | Double dis1 = Double.valueOf(gdMapElectricFenceUtil.getDistance(orderPrivateCar.getStartLon() + "," + orderPrivateCar.getStartLat(), order.getStartLon() + "," + order.getStartLat(), 1).get("distance").toString()); |
| | | Double dis2 = Double.valueOf(gdMapElectricFenceUtil.getDistance(orderPrivateCar.getEndLon() + "," + orderPrivateCar.getEndLat(), order.getEndLon() + "," + order.getEndLat(), 1).get("distance").toString()); |
| | | //判断距离 |
| | | if(dis1<=jsonObject.getInteger("num1")*1000 && dis2<=jsonObject.getInteger("num2")*1000){ |
| | | orderPrivateCar1=order; |
| | | break; |
| | | } |
| | | } |
| | | } |
| | | } |
| | | if(orderPrivateCar1==null){ |
| | | orderList = orderPrivateCarMapper.selectList(new EntityWrapper<OrderPrivateCar>().eq("rideType",3).eq("state",5).le("totalPeopleNum",4-peopleNum)); |
| | | for(OrderPrivateCar order:orderList){ |
| | | TbSpellOrderRule spellOrderRule = spellOrderRuleService.selectOne(new EntityWrapper<TbSpellOrderRule>().eq("companyId",order.getCompanyId())); |
| | | if(spellOrderRule!=null){ |
| | | JSONObject jsonObject = JSONObject.parseObject(spellOrderRule.getContent()); |
| | | //判断时间 |
| | | if(travelTime.getTime()>=order.getTravelTime().getTime()-jsonObject.getInteger("num5")*60000L && travelTime.getTime()<=order.getTravelTime().getTime()+jsonObject.getInteger("num6")*60000L){ |
| | | String value = redisUtil.getValue("DRIVER" + String.valueOf(order.getDriverId())); |
| | | Double dis1 = Double.valueOf(gdMapElectricFenceUtil.getDistance(orderPrivateCar.getStartLon() + "," + orderPrivateCar.getStartLat(), value, 1).get("distance").toString()); |
| | | Double dis2 = Double.valueOf(gdMapElectricFenceUtil.getDistance(orderPrivateCar.getEndLon() + "," + orderPrivateCar.getEndLat(), order.getEndLon() + "," + order.getEndLat(), 1).get("distance").toString()); |
| | | //判断距离 |
| | | if(dis1<=jsonObject.getInteger("num3")*1000 && dis2<=jsonObject.getInteger("num4")*1000){ |
| | | orderPrivateCar1=order; |
| | | break; |
| | | } |
| | | } |
| | | } |
| | | } |
| | | } |
| | | if(orderPrivateCar1==null){ |
| | | orderPrivateCar.setTotalPeopleNum(peopleNum); |
| | | orderPrivateCar.setIsReassign(1); |
| | | orderPrivateCar.setIsDelete(1); |
| | | this.insert(orderPrivateCar); |
| | | this.pushOrder(orderPrivateCar); |
| | | }else{ |
| | | Driver driver = driverService.selectById(orderPrivateCar1.getDriverId()); |
| | | 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.setDriverId(driver.getId()); |
| | | orderPrivateCar.setCarId(driver.getCarId()); |
| | | CarService query1 = carServiceMapper.query(1, driver.getCarId()); |
| | | orderPrivateCar.setServerCarModelId(query1.getServerCarModelId()); |
| | | orderPrivateCar.setSnatchOrderTime(new Date()); |
| | | orderPrivateCar.setTotalPeopleNum(peopleNum+orderPrivateCar1.getTotalPeopleNum()); |
| | | orderPrivateCar.setIsReassign(1); |
| | | orderPrivateCar.setIsDelete(1); |
| | | orderPrivateCar.setPid(orderPrivateCar1.getPid()==null?orderPrivateCar1.getId():orderPrivateCar1.getPid()); |
| | | this.insert(orderPrivateCar); |
| | | //修改总订单人数 |
| | | OrderPrivateCar orderPrivateCar2 = new OrderPrivateCar(); |
| | | orderPrivateCar2.setSpellSuccess(1); |
| | | orderPrivateCar2.setTotalPeopleNum(peopleNum+orderPrivateCar1.getTotalPeopleNum()); |
| | | this.update(orderPrivateCar2,new EntityWrapper<OrderPrivateCar>().eq("pid",orderPrivateCar1.getPid()==null?orderPrivateCar1.getId():orderPrivateCar1.getPid()).lt("state",6)); |
| | | this.update(orderPrivateCar2,new EntityWrapper<OrderPrivateCar>().eq("id",orderPrivateCar1.getPid()==null?orderPrivateCar1.getId():orderPrivateCar1.getPid()).lt("state",6)); |
| | | // |
| | | //调用移动的小号接口 |
| | | Map<String, String> map = chinaMobileUtil.midAxbBindSend(orderPrivateCar.getPassengersPhone(), driver.getPhone(), (System.currentTimeMillis() + 86400000)); |
| | | if(String.valueOf(map.get("code")).equals("200")){ |
| | | orderPrivateCar.setTelX(map.get("telX")); |
| | | orderPrivateCar.setBindId(map.get("bindId")); |
| | | } |
| | | 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, 100, 0); |
| | | pushUtil.pushDriverPosition(orderPrivateCar.getId(), 1); |
| | | |
| | | } |
| | | }).start(); |
| | | List<OrderPrivateCar> orderList1 = this.selectList(new EntityWrapper<OrderPrivateCar>().eq("pid",orderPrivateCar.getPid())); |
| | | for(OrderPrivateCar orderPrivateCar3:orderList1){ |
| | | pushUtil.pushOrderState(1, orderPrivateCar3.getUserId(), orderPrivateCar3.getId(), 1, 13, 0); |
| | | } |
| | | OrderPrivateCar orderPrivateCar3 = this.selectById(orderPrivateCar.getPid()); |
| | | pushUtil.pushOrderState(1, orderPrivateCar3.getUserId(), orderPrivateCar3.getId(), 1, 13, 0); |
| | | } |
| | | |
| | | } |
| | | |
| | | |
| | | //添加消息 |
| | | systemNoticeService.addSystemNotice(1, "您的快车订单已下单成功,我们正在为您指派司机,请稍后!", orderPrivateCar.getUserId(), 1); |
| | | systemNoticeService.addSystemNotice(1, "您的专车订单已下单成功,我们正在为您指派司机,请稍后!", orderPrivateCar.getUserId(), 1); |
| | | |
| | | BaseWarpper baseWarpper = new BaseWarpper(); |
| | | baseWarpper.setId(orderPrivateCar.getId()); |
| | |
| | | orderCrossCityService.pushOrder(orders); |
| | | |
| | | }else{ |
| | | //判断独享,一口价,拼车 |
| | | if(orderPrivateCar.getRideType()!=3){ |
| | | this.pushOrder(orderPrivateCar); |
| | | }else{ |
| | | OrderPrivateCar orderPrivateCar1 = null; |
| | | //判断是否有相同线路的拼车-有直接拼成功,或者推送拼车订单 |
| | | List<OrderPrivateCar> orderList = orderPrivateCarMapper.selectList(new EntityWrapper<OrderPrivateCar>().eq("rideType",3).in("state","2,3,4").le("totalPeopleNum",4-orderPrivateCar.getPeopleNum())); |
| | | for(OrderPrivateCar order:orderList){ |
| | | TbSpellOrderRule spellOrderRule = spellOrderRuleService.selectOne(new EntityWrapper<TbSpellOrderRule>().eq("companyId",order.getCompanyId())); |
| | | if(spellOrderRule!=null){ |
| | | JSONObject jsonObject = JSONObject.parseObject(spellOrderRule.getContent()); |
| | | //判断时间 |
| | | if(orderPrivateCar.getTravelTime().getTime()>=order.getTravelTime().getTime()-jsonObject.getInteger("num5")*60000L && orderPrivateCar.getTravelTime().getTime()<=order.getTravelTime().getTime()+jsonObject.getInteger("num6")*60000L){ |
| | | Double dis1 = Double.valueOf(gdMapElectricFenceUtil.getDistance(orderPrivateCar.getStartLon() + "," + orderPrivateCar.getStartLat(), order.getStartLon() + "," + order.getStartLat(), 1).get("distance").toString()); |
| | | Double dis2 = Double.valueOf(gdMapElectricFenceUtil.getDistance(orderPrivateCar.getEndLon() + "," + orderPrivateCar.getEndLat(), order.getEndLon() + "," + order.getEndLat(), 1).get("distance").toString()); |
| | | //判断距离 |
| | | if(dis1<=jsonObject.getInteger("num1")*1000 && dis2<=jsonObject.getInteger("num2")*1000){ |
| | | orderPrivateCar1=orderPrivateCar; |
| | | break; |
| | | } |
| | | } |
| | | } |
| | | } |
| | | if(orderPrivateCar1==null){ |
| | | orderList = orderPrivateCarMapper.selectList(new EntityWrapper<OrderPrivateCar>().eq("rideType",3).eq("state",5).le("totalPeopleNum",4-orderPrivateCar.getPeopleNum())); |
| | | for(OrderPrivateCar order:orderList){ |
| | | TbSpellOrderRule spellOrderRule = spellOrderRuleService.selectOne(new EntityWrapper<TbSpellOrderRule>().eq("companyId",order.getCompanyId())); |
| | | if(spellOrderRule!=null){ |
| | | JSONObject jsonObject = JSONObject.parseObject(spellOrderRule.getContent()); |
| | | //判断时间 |
| | | if(orderPrivateCar.getTravelTime().getTime()>=order.getTravelTime().getTime()-jsonObject.getInteger("num5")*60000L && orderPrivateCar.getTravelTime().getTime()<=order.getTravelTime().getTime()+jsonObject.getInteger("num6")*60000L){ |
| | | String value = redisUtil.getValue("DRIVER" + String.valueOf(order.getDriverId())); |
| | | Double dis1 = Double.valueOf(gdMapElectricFenceUtil.getDistance(orderPrivateCar.getStartLon() + "," + orderPrivateCar.getStartLat(), value, 1).get("distance").toString()); |
| | | Double dis2 = Double.valueOf(gdMapElectricFenceUtil.getDistance(orderPrivateCar.getEndLon() + "," + orderPrivateCar.getEndLat(), order.getEndLon() + "," + order.getEndLat(), 1).get("distance").toString()); |
| | | //判断距离 |
| | | if(dis1<=jsonObject.getInteger("num3")*1000 && dis2<=jsonObject.getInteger("num4")*1000){ |
| | | orderPrivateCar1=order; |
| | | break; |
| | | } |
| | | } |
| | | } |
| | | } |
| | | } |
| | | if(orderPrivateCar1==null){ |
| | | this.pushOrder(orderPrivateCar); |
| | | }else{ |
| | | Driver driver = driverService.selectById(orderPrivateCar1.getDriverId()); |
| | | orderPrivateCar.setDriverId(orderPrivateCar1.getDriverId()); |
| | | 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()); |
| | | orderPrivateCar.setDriverId(driver.getId()); |
| | | CarService query1 = carServiceMapper.query(1, driver.getCarId()); |
| | | orderPrivateCar.setServerCarModelId(query1.getServerCarModelId()); |
| | | orderPrivateCar.setSnatchOrderTime(new Date()); |
| | | |
| | | orderPrivateCar.setTotalPeopleNum(orderPrivateCar.getPeopleNum()+orderPrivateCar1.getTotalPeopleNum()); |
| | | orderPrivateCar.setPid(orderPrivateCar1.getPid()==null?orderPrivateCar1.getId():orderPrivateCar1.getPid()); |
| | | orderPrivateCar.setIsReassign(1); |
| | | orderPrivateCar.setIsDelete(1); |
| | | this.updateById(orderPrivateCar); |
| | | // |
| | | //修改总订单人数 |
| | | OrderPrivateCar orderPrivateCar2 = new OrderPrivateCar(); |
| | | orderPrivateCar2.setTotalPeopleNum(orderPrivateCar.getPeopleNum()+orderPrivateCar1.getTotalPeopleNum()); |
| | | this.update(orderPrivateCar2,new EntityWrapper<OrderPrivateCar>().eq("pid",orderPrivateCar1.getPid()==null?orderPrivateCar1.getId():orderPrivateCar1.getPid()).lt("state",6)); |
| | | this.update(orderPrivateCar2,new EntityWrapper<OrderPrivateCar>().eq("id",orderPrivateCar1.getPid()==null?orderPrivateCar1.getId():orderPrivateCar1.getPid()).lt("state",6)); |
| | | // |
| | | //调用移动的小号接口 |
| | | Map<String, String> map = chinaMobileUtil.midAxbBindSend(orderPrivateCar.getPassengersPhone(), driver.getPhone(), (System.currentTimeMillis() + 86400000)); |
| | | if(String.valueOf(map.get("code")).equals("200")){ |
| | | orderPrivateCar.setTelX(map.get("telX")); |
| | | orderPrivateCar.setBindId(map.get("bindId")); |
| | | } |
| | | new Thread(new Runnable() { |
| | | @Override |
| | | public void run() { |
| | | pushUtil.pushOrderState(1, orderPrivateCar.getUserId(), orderPrivateCar.getId(), 1, 2, 0); |
| | | pushUtil.pushOrderState(2, orderPrivateCar.getDriverId(), orderPrivateCar.getId(), 1, 100, 0); |
| | | pushUtil.pushDriverPosition(orderPrivateCar.getId(), 1); |
| | | } |
| | | }).start(); |
| | | List<OrderPrivateCar> orderList1 = this.selectList(new EntityWrapper<OrderPrivateCar>().eq("pid",orderPrivateCar.getPid())); |
| | | for(OrderPrivateCar orderPrivateCar3:orderList1){ |
| | | pushUtil.pushOrderState(1, orderPrivateCar3.getUserId(), orderPrivateCar3.getId(), 1, 13, 0); |
| | | } |
| | | OrderPrivateCar orderPrivateCar3 = this.selectById(orderPrivateCar.getPid()); |
| | | pushUtil.pushOrderState(1, orderPrivateCar3.getUserId(), orderPrivateCar3.getId(), 1, 13, 0); |
| | | } |
| | | } |
| | | |
| | | } |
| | | return ResultUtil.success(); |
| | | } |
| | |
| | | } |
| | | |
| | | OrderPrivateCar orderPrivateCar = this.selectById(id); |
| | | if(null == uid){ |
| | | uid = orderPrivateCar.getUserId(); |
| | | } |
| | | |
| | | Integer integer = null; |
| | | if(null == orderPrivateCar){ |
| | | return ResultUtil.error("取消订单失败,订单信息有误"); |
| | | } |
| | | // if(orderPrivateCar.getState() == 4){ |
| | | // return ResultUtil.error("司机已到达预约点,取消会产生一定的费用"); |
| | | // } |
| | | if(orderPrivateCar.getState() >= 5 && orderPrivateCar.getState() != 11){ |
| | | if(orderPrivateCar.getState() > 5 && orderPrivateCar.getState() != 11){ |
| | | return ResultUtil.error("取消订单失败,不合法的操作"); |
| | | } |
| | | Integer number1 = this.selectCount(new EntityWrapper<OrderPrivateCar>().eq("pid",orderPrivateCar.getPid()==null?orderPrivateCar.getId():orderPrivateCar.getPid()).lt("state",6)); |
| | | Integer number2 = this.selectCount(new EntityWrapper<OrderPrivateCar>().eq("id",orderPrivateCar.getPid()==null?orderPrivateCar.getId():orderPrivateCar.getPid()).lt("state",6)); |
| | | if(number1+number2<=2){ |
| | | OrderPrivateCar orderPrivateCar2 = new OrderPrivateCar(); |
| | | orderPrivateCar2.setTotalPeopleNum(orderPrivateCar.getTotalPeopleNum()-orderPrivateCar.getPeopleNum()); |
| | | orderPrivateCar2.setSpellSuccess(0); |
| | | this.update(orderPrivateCar2,new EntityWrapper<OrderPrivateCar>().eq("pid",orderPrivateCar.getPid()==null?orderPrivateCar.getId():orderPrivateCar.getPid()).lt("state",6)); |
| | | this.update(orderPrivateCar2,new EntityWrapper<OrderPrivateCar>().eq("id",orderPrivateCar.getPid()==null?orderPrivateCar.getId():orderPrivateCar.getPid()).lt("state",6)); |
| | | |
| | | }else{ |
| | | OrderPrivateCar orderPrivateCar2 = new OrderPrivateCar(); |
| | | orderPrivateCar2.setTotalPeopleNum(orderPrivateCar.getTotalPeopleNum()-orderPrivateCar.getPeopleNum()); |
| | | this.update(orderPrivateCar2,new EntityWrapper<OrderPrivateCar>().eq("pid",orderPrivateCar.getPid()==null?orderPrivateCar.getId():orderPrivateCar.getPid()).lt("state",6)); |
| | | this.update(orderPrivateCar2,new EntityWrapper<OrderPrivateCar>().eq("id",orderPrivateCar.getPid()==null?orderPrivateCar.getId():orderPrivateCar.getPid()).lt("state",6)); |
| | | } |
| | | if(null == orderPrivateCar.getDriverId()){//没有接单的情况 |
| | | if(orderPrivateCar.getType() == 2){//摆渡车 |
| | |
| | | OrderPrivateCar orderPrivateCar = this.selectById(id); |
| | | Integer uid = orderPrivateCar.getUserId(); |
| | | UserInfo userInfo = userInfoService.selectById(uid); |
| | | ResultUtil resultUtil = ResultUtil.success(new Object()); |
| | | ResultUtil resultUtil = ResultUtil.success(); |
| | | |
| | | if(null == orderPrivateCar){ |
| | | return ResultUtil.error("取消订单失败,订单信息有误", ""); |
| | | return ResultUtil.error("取消订单失败,订单信息有误"); |
| | | } |
| | | if(orderPrivateCar.getState() != 12){ |
| | | return ResultUtil.error("取消订单失败,不合法的操作", ""); |
| | | return ResultUtil.error("取消订单失败,不合法的操作"); |
| | | } |
| | | OrderCancel orderCancel = null; |
| | | if(null == cancleId){ |
| | |
| | | } |
| | | |
| | | CancleOrder query = cancleOrderService.query(orderPrivateCar.getOrderType(), 1, orderPrivateCar.getCompanyId()); |
| | | if(null != query){ |
| | | if(payType == 1){//微信支付 |
| | | String value = redisUtil.getValue("appletOpenId"); |
| | | String appletsOpenId = null; |
| | | if(ToolUtil.isNotEmpty(value)){ |
| | | JSONObject jsonObject = JSON.parseObject(value); |
| | | appletsOpenId = jsonObject.getString(uid.toString()); |
| | | }else{ |
| | | appletsOpenId = userInfo.getAppletsOpenId(); |
| | | } |
| | | orderCancel.setPayType(1); |
| | | orderCancelService.updateById(orderCancel); |
| | | String app = type == 1 ? "APP" : "JSAPI"; |
| | | resultUtil = payMoneyUtil.weixinpay("订单取消", "", id + "_1_" + UUIDUtil.getRandomCode(5), query.getMoney().toString(), "/base/wxCancelOrderTaxi", app, userInfo.getAppletsOpenId()); |
| | | paymentRecordService.saveData(1, orderPrivateCar.getUserId(), 1, id, 1, 1, query.getMoney(), "", 1);//添加预支付数据 |
| | | |
| | | // Map<String, String> map = icbcPayUtil.placeAnOrder(id + ",1", 9, 5, uid.toString(), "订单取消", query.getMoney(), callbackPath + "/base/wxCancelOrderTaxi", "", type, appletsOpenId); |
| | | // if(map.get("code").equals("200")){ |
| | | // paymentRecordService.saveData(1, orderPrivateCar.getUserId(), 1, id, 1, 1, query.getMoney(), map.get("order_id"), 1);//添加预支付数据 |
| | | // resultUtil = ResultUtil.success(map.get("data")); |
| | | // }else{ |
| | | // resultUtil = ResultUtil.error(map.get("msg"), ""); |
| | | // } |
| | | if(null != query){ |
| | | SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMddHHmmssSSS"); |
| | | String out_trade_no = sdf.format(new Date()) + 1 + id; |
| | | |
| | | if(payType == 1){//微信支付 |
| | | String appletsOpenId = ""; |
| | | String tradeType = "APP"; |
| | | if(type == 3){ |
| | | appletsOpenId = userInfo.getAppletsOpenId(); |
| | | tradeType = "JSAPI"; |
| | | if(ToolUtil.isEmpty(userInfo.getAppletsOpenId())){ |
| | | return ResultUtil.error("支付异常,请重新授权登录小程序"); |
| | | } |
| | | } |
| | | resultUtil = payMoneyUtil.weixinpay("订单取消", "", out_trade_no, query.getMoney().toString(), callbackPath + "/base/wxCancelOrderTaxi", tradeType, appletsOpenId); |
| | | if(resultUtil.getCode() == 200){ |
| | | paymentRecordService.saveData(1, orderPrivateCar.getUserId(), 1, id, 1, 1, query.getMoney(), "", 1);//添加预支付数据 |
| | | } |
| | | } |
| | | if(payType == 2){//支付宝支付 |
| | | orderCancel.setPayType(2); |
| | | orderCancelService.updateById(orderCancel); |
| | | |
| | | resultUtil = payMoneyUtil.alipay("订单取消", "订单取消", "", id + "_1_" + UUIDUtil.getRandomCode(5), query.getMoney().toString(), "/base/aliCancelOrderTaxi"); |
| | | resultUtil = payMoneyUtil.alipay("取消订单支付", "取消订单", out_trade_no, query.getMoney().toString(), callbackPath + "/base/aliCancelOrderTaxi"); |
| | | if(resultUtil.getCode() == 200){ |
| | | paymentRecordService.saveData(1, orderPrivateCar.getUserId(), 1, id, 1, 2, query.getMoney(), "", 1);//添加预支付数据 |
| | | |
| | | // Map<String, String> map = icbcPayUtil.placeAnOrder(id + ",1", 10, 5, uid.toString(), "订单取消", query.getMoney(), callbackPath + "/base/aliCancelOrderTaxi", "", type, null); |
| | | // if(map.get("code").equals("200")){ |
| | | // paymentRecordService.saveData(1, orderPrivateCar.getUserId(), 1, id, 1, 2, query.getMoney(), map.get("order_id"), 1);//添加预支付数据 |
| | | // resultUtil = ResultUtil.success(map.get("data")); |
| | | // }else{ |
| | | // resultUtil = ResultUtil.error(map.get("msg"), ""); |
| | | // } |
| | | } |
| | | } |
| | | if(payType == 3){//余额支付 |
| | | if(userInfo.getBalance() != null && userInfo.getBalance() < query.getMoney()){ |
| | | return ResultUtil.error("余额不足,无法完成支付", ""); |
| | | 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); |
| | | transactionDetailsService.saveData(uid, "取消订单", query.getMoney(), 2, 1, 1, 1, id); |
| | | userInfoService.updateById(userInfo); |
| | | |
| | | //解除小号绑定 |
| | | if(orderPrivateCar.getBindId() != null){ |
| | | chinaMobileUtil.midAxbUnBindSend(orderPrivateCar.getBindId(), orderPrivateCar.getTelX(), (System.currentTimeMillis() + 600000)); |
| | | chinaMobileUtil.midAxbUnBindSend(orderPrivateCar.getBindId()); |
| | | } |
| | | |
| | | orderPrivateCar.setState(10); |
| | |
| | | @Override |
| | | public void run() { |
| | | try { |
| | | Integer orderType = orderPrivateCar.getRideType()==1?1:orderPrivateCar.getRideType()==2?9:8; |
| | | orderIds.add(orderPrivateCar.getId());//添加记录,防止调用接口重复提醒无人接单 |
| | | String vehicle = redisUtil.getValue("VEHICLE"); |
| | | List<Integer> integers = new ArrayList<>(); |
| | |
| | | List<PushOrder> querys = pushOrderService.querys(null, 1, query.getId());//获取需要推送的次数 |
| | | for(int i = 1; i <= querys.size(); i++){ |
| | | PushOrder pushOrder = pushOrderService.querys(i, 1, query.getId()).get(0); |
| | | //获取空闲司机 |
| | | List<Driver> list = driverService.queryIdleDriver(orderType, orderPrivateCar.getServerCarModelId(), orderPrivateCar.getStartLon(), orderPrivateCar.getStartLat(), pushOrder.getPushDistance(), null);//所有附近空闲司机 |
| | | //获取空闲司机(智慧屏下单不需要判断车型) |
| | | List<Driver> list = driverService.queryIdleDriver(1, orderPrivateCar.getOrderSource() == 6 ? null : orderPrivateCar.getServerCarModelId(), orderPrivateCar.getStartLon(), orderPrivateCar.getStartLat(), pushOrder.getPushDistance(), null);//所有附近空闲司机 |
| | | if(list.size() > 0){ |
| | | double driverProportion = pushOrder.getDriverProportion() / 100;//推送占比计算成小数 |
| | | int lastIndex = Double.valueOf(list.size() * driverProportion).intValue();//计算占比转成整数(下标截取) |
| | | lastIndex = lastIndex == 0 ? list.size() : lastIndex; |
| | | list = list.subList(0, lastIndex);//获取空闲司机中占比数据 |
| | | for(Driver driver : list){//开始进行推送 |
| | | boolean bo = false; |
| | |
| | | } |
| | | |
| | | @Override |
| | | public PreferentialDataVo queryBalance1(Integer orderId, Integer uid) throws Exception { |
| | | UserInfo userInfo = userInfoService.selectById(uid); |
| | | PreferentialDataVo preferentialDataVo = new PreferentialDataVo(); |
| | | preferentialDataVo.setBalance(userInfo.getBalance()); |
| | | OrderPrivateCar orderPrivateCar = this.selectById(orderId); |
| | | |
| | | //获取优惠券中最优数据 |
| | | List<UserCouponRecord> list = userCouponRecordService.selectList(new EntityWrapper<UserCouponRecord>().eq("companyId", orderPrivateCar.getCompanyId()).eq("state", 1).in("couponUseType", Arrays.asList(0, 1)).eq("userId", uid).where("now() < expirationTime")); |
| | | Integer id = null; |
| | | Double price = 0d; |
| | | Integer type = 0; |
| | | for (UserCouponRecord userCouponRecord : list){ |
| | | if(userCouponRecord.getCouponType() == 1){//抵扣券 |
| | | if(price.compareTo(userCouponRecord.getMoney()) < 0){ |
| | | price = userCouponRecord.getMoney(); |
| | | id = userCouponRecord.getId(); |
| | | type = 1; |
| | | } |
| | | }else{//满减券 |
| | | if(orderPrivateCar.getOrderMoney().compareTo(userCouponRecord.getFullMoney()) >= 0 && price.compareTo(userCouponRecord.getMoney()) < 0){ |
| | | price = userCouponRecord.getMoney(); |
| | | id = userCouponRecord.getId(); |
| | | type = 1; |
| | | } |
| | | } |
| | | } |
| | | |
| | | //获取打车卡中最优数 |
| | | Map<String, String> geocode = gdMapGeocodingUtil.geocode(orderPrivateCar.getStartLon().toString(), orderPrivateCar.getStartLat().toString()); |
| | | CompanyCity companyCity = companyCityService.selectOne(new EntityWrapper<CompanyCity>().eq("companyId", orderPrivateCar.getCompanyId()).eq("areaCode", geocode.get("districtCode")).eq("state", 1)); |
| | | if(null == companyCity){ |
| | | companyCity = companyCityService.selectOne(new EntityWrapper<CompanyCity>().eq("companyId", orderPrivateCar.getCompanyId()).eq("cityCode", geocode.get("cityCode")).eq("state", 1)); |
| | | } |
| | | if(null == companyCity){ |
| | | companyCity = companyCityService.selectOne(new EntityWrapper<CompanyCity>().eq("companyId", orderPrivateCar.getCompanyId()).eq("provinceCode", geocode.get("provinceCode")).eq("state", 1)); |
| | | } |
| | | List<UserTaxiCard> userTaxiCards = userTaxiCardService.selectList(new EntityWrapper<UserTaxiCard>().like("companyCityId", "%" + companyCity.getId() + "%") |
| | | .in("type", Arrays.asList(1, 2, 3, 4)).eq("userId", uid).where("now() between startTime and endTime")); |
| | | |
| | | //全国卡 |
| | | List<TaxiCard> taxiCards = taxiCardService.selectList(new EntityWrapper<TaxiCard>().eq("taxiCardType", 2).in("type", Arrays.asList(1, 2, 3, 4)).eq("state", 1)); |
| | | if(taxiCards.size() > 0) { |
| | | List<UserTaxiCard> userTaxiCards2 = userTaxiCardService.selectList(new EntityWrapper<UserTaxiCard>().eq("userId", uid) |
| | | .in("type", Arrays.asList(1, 2, 3, 4)).in("taxiCardId", taxiCards.stream().map(TaxiCard::getId).collect(Collectors.toList())).where("now() between startTime and endTime")); |
| | | userTaxiCards.addAll(userTaxiCards2); |
| | | } |
| | | //亲密账户中有相同的卡优先使用自己的 |
| | | // 因为比对中只有优惠金额最高的才会被替换,所以先查找自己的数据再查找亲密账户的数据 |
| | | Map<String, Object> map = getOptimalTaxiCards(orderPrivateCar, price, id, type, userTaxiCards); |
| | | price = Double.valueOf(map.get("price").toString()); |
| | | id = null != map.get("id") ? Integer.valueOf(map.get("id").toString()) : null; |
| | | type = Integer.valueOf(map.get("type").toString()); |
| | | |
| | | //亲密账户 |
| | | List<UserTaxiCard> userTaxiCards_ = new ArrayList<>(); |
| | | List<UserUser> bindUserId = userUserService.selectList(new EntityWrapper<UserUser>().eq("bindUserId", uid)); |
| | | CompanyCity finalCompanyCity = companyCity; |
| | | bindUserId.forEach(userUser -> { |
| | | List<UserTaxiCard> userTaxiCards1 = userTaxiCardService.selectList(new EntityWrapper<UserTaxiCard>().in("type", Arrays.asList(1, 2, 3, 4)) |
| | | .like("companyCityId", "%" + finalCompanyCity.getId() + "%").eq("userId", userUser.getUserId()).where("now() between startTime and endTime")); |
| | | userTaxiCards_.addAll(userTaxiCards1); |
| | | |
| | | //全国卡 |
| | | if(taxiCards.size() > 0) { |
| | | List<UserTaxiCard> userTaxiCards2 = userTaxiCardService.selectList(new EntityWrapper<UserTaxiCard>().eq("userId", userUser.getUserId()) |
| | | .in("type", Arrays.asList(1, 2, 3, 4)).in("taxiCardId", taxiCards.stream().map(TaxiCard::getId).collect(Collectors.toList())).where("now() between startTime and endTime")); |
| | | userTaxiCards_.addAll(userTaxiCards2); |
| | | } |
| | | }); |
| | | map = getOptimalTaxiCards(orderPrivateCar, price, id, type, userTaxiCards_); |
| | | price = Double.valueOf(map.get("price").toString()); |
| | | id = null != map.get("id") ? Integer.valueOf(map.get("id").toString()) : null; |
| | | type = Integer.valueOf(map.get("type").toString()); |
| | | |
| | | preferentialDataVo.setObjectId(id); |
| | | preferentialDataVo.setDiscountAmount(price); |
| | | preferentialDataVo.setType(type); |
| | | return preferentialDataVo; |
| | | } |
| | | |
| | | |
| | | /** |
| | | * 获取最优打车卡数据 |
| | | * @param orderPrivateCar |
| | | * @param price |
| | | * @param id |
| | | * @param type |
| | | * @param userTaxiCards |
| | | * @throws Exception |
| | | */ |
| | | public Map<String, Object> getOptimalTaxiCards(OrderPrivateCar orderPrivateCar, Double price, Integer id, Integer type, List<UserTaxiCard> userTaxiCards) throws Exception{ |
| | | Map<String, Object> map = new HashMap<>(); |
| | | for(UserTaxiCard t : userTaxiCards){ |
| | | JSONObject jsonObject = JSON.parseObject(t.getContent()); |
| | | List<Integer> integers = jsonObject.getJSONArray("businessTypes").toJavaList(Integer.class); |
| | | if(!integers.contains(1)){ |
| | | continue; |
| | | } |
| | | if(t.getType() == 1){//打折次数卡{"businessTypes":[1,2,3],"time":5,"timeQuantum":["08:00:00 - 09:00:00","17:00:00 - 18:00:00"],"discount":5} |
| | | Integer time = jsonObject.getInteger("time"); |
| | | if(time == 0){ |
| | | continue; |
| | | } |
| | | JSONArray timeQuantum = jsonObject.getJSONArray("timeQuantum"); |
| | | Double discount = jsonObject.getDouble("discount"); |
| | | SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd"); |
| | | SimpleDateFormat sdf1 = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); |
| | | Date date = new Date(); |
| | | for(int i = 0; i < timeQuantum.size(); i++){ |
| | | String[] split = timeQuantum.getString(i).split(" - "); |
| | | Date s = sdf1.parse(sdf.format(date) + " " + split[0]); |
| | | Date e = sdf1.parse(sdf.format(date) + " " + split[1]); |
| | | if(s.getTime() <= System.currentTimeMillis() && System.currentTimeMillis() < e.getTime()){ |
| | | double v = new BigDecimal(orderPrivateCar.getOrderMoney()).multiply(new BigDecimal((10 - discount) / 10)).setScale(2, RoundingMode.HALF_EVEN).doubleValue(); |
| | | if(price.compareTo(v) < 0){ |
| | | price = v; |
| | | id = t.getId(); |
| | | type = 2; |
| | | } |
| | | if(price.compareTo(v) < 0){ |
| | | price = v; |
| | | id = t.getId(); |
| | | type = 2; |
| | | } |
| | | } |
| | | } |
| | | |
| | | } |
| | | if(t.getType() == 2){//优惠卡{"businessTypes":[1,2,3],"timeQuantum":["08:00:00 - 09:00:00","17:00:00 - 18:00:00"],"fullReduction":[[50,3],[100,5],[150,10]]} |
| | | JSONArray timeQuantum = jsonObject.getJSONArray("timeQuantum"); |
| | | JSONArray fullReduction = jsonObject.getJSONArray("fullReduction"); |
| | | SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd"); |
| | | SimpleDateFormat sdf1 = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); |
| | | Date date = new Date(); |
| | | for(int i = 0; i < timeQuantum.size(); i++){ |
| | | String[] split = timeQuantum.getString(i).split(" - "); |
| | | Date s = sdf1.parse(sdf.format(date) + " " + split[0]); |
| | | Date e = sdf1.parse(sdf.format(date) + " " + split[1]); |
| | | if(s.getTime() <= System.currentTimeMillis() && System.currentTimeMillis() < e.getTime()){ |
| | | for(int j = fullReduction.size() - 1; j >= 0; j--){ |
| | | JSONArray jsonArray = fullReduction.getJSONArray(j); |
| | | Double p = jsonArray.getDouble(0);//满金额 |
| | | Double y = jsonArray.getDouble(1);//优惠金额 |
| | | if(orderPrivateCar.getOrderMoney().compareTo(p) >= 0 && price.compareTo(y) < 0){ |
| | | price = y; |
| | | id = t.getId(); |
| | | type = 2; |
| | | } |
| | | } |
| | | } |
| | | } |
| | | } |
| | | if(t.getType() == 3){//次数卡{"businessTypes":[1,2,3],"timeQuantum":["08:00:00 - 09:00:00","17:00:00 - 18:00:00"],"time":1,"discountAmount":10} |
| | | Integer time = jsonObject.getInteger("time"); |
| | | if(time == 0){ |
| | | continue; |
| | | } |
| | | JSONArray timeQuantum = jsonObject.getJSONArray("timeQuantum"); |
| | | Double discountAmount = jsonObject.getDouble("discountAmount"); |
| | | SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd"); |
| | | SimpleDateFormat sdf1 = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); |
| | | Date date = new Date(); |
| | | for(int i = 0; i < timeQuantum.size(); i++){ |
| | | String[] split = timeQuantum.getString(i).split(" - "); |
| | | Date s = sdf1.parse(sdf.format(date) + " " + split[0]); |
| | | Date e = sdf1.parse(sdf.format(date) + " " + split[1]); |
| | | if(s.getTime() <= System.currentTimeMillis() && System.currentTimeMillis() < e.getTime()){ |
| | | if(price.compareTo(discountAmount) < 0){ |
| | | price = discountAmount; |
| | | id = t.getId(); |
| | | type = 2; |
| | | } |
| | | } |
| | | } |
| | | } |
| | | if(t.getType() == 4){//打折天数卡{"businessTypes":[1,2,3],"discount":5,"timeQuantum":["08:00:00 - 09:00:00","17:00:00 - 18:00:00"]} |
| | | Double discount = jsonObject.getDouble("discount");//折扣 |
| | | JSONArray timeQuantum = jsonObject.getJSONArray("timeQuantum");//使用时间段 |
| | | SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd"); |
| | | SimpleDateFormat sdf1 = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); |
| | | Date date = new Date(); |
| | | for(int i = 0; i < timeQuantum.size(); i++){ |
| | | String[] split = timeQuantum.getString(i).split(" - "); |
| | | Date s = sdf1.parse(sdf.format(date) + " " + split[0]); |
| | | Date e = sdf1.parse(sdf.format(date) + " " + split[1]); |
| | | if(s.getTime() <= System.currentTimeMillis() && System.currentTimeMillis() < e.getTime()){ |
| | | double v = new BigDecimal(orderPrivateCar.getOrderMoney()).multiply(new BigDecimal((10 - discount) / 10)).setScale(2, RoundingMode.HALF_EVEN).doubleValue(); |
| | | if(price.compareTo(v) < 0){ |
| | | price = v; |
| | | id = t.getId(); |
| | | type = 2; |
| | | } |
| | | } |
| | | } |
| | | } |
| | | } |
| | | map.put("price", price); |
| | | map.put("id", id); |
| | | map.put("type", type); |
| | | return map; |
| | | } |
| | | |
| | | |
| | | |
| | | |
| | | @Override |
| | | public List<Map<String, Object>> queryCoupon(Integer orderId, Integer uid, Integer pageNum, Integer size) throws Exception { |
| | | OrderPrivateCar orderPrivateCar = this.selectById(orderId); |
| | | List<Map<String, Object>> list = userCouponRecordService.queryCoupon(uid, orderPrivateCar.getCompanyId(), 1, 1, orderPrivateCar.getOrderMoney(), pageNum, size); |
| | |
| | | } |
| | | |
| | | @Override |
| | | public List<CouponsListVo> queryCouponList(Integer orderId, Integer uid, Integer pageNum, Integer size) throws Exception { |
| | | pageNum = (pageNum - 1) * size; |
| | | OrderPrivateCar orderPrivateCar = this.selectById(orderId); |
| | | List<CouponsListVo> rows = new ArrayList<>(); |
| | | List<UserCouponRecord> list = userCouponRecordService.selectList(new EntityWrapper<UserCouponRecord>().eq("companyId", orderPrivateCar.getCompanyId()) |
| | | .eq("state", 1).in("couponUseType", Arrays.asList(0, 1)).eq("userId", uid).where("expirationTime >= now()")); |
| | | SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); |
| | | for (UserCouponRecord userCouponRecord : list){ |
| | | if(userCouponRecord.getCouponType() == 2){//满减券 |
| | | if(orderPrivateCar.getOrderMoney().compareTo(userCouponRecord.getFullMoney()) < 0){ |
| | | continue; |
| | | } |
| | | } |
| | | CouponsListVo couponsListVo = new CouponsListVo(); |
| | | couponsListVo.setId(userCouponRecord.getId()); |
| | | couponsListVo.setDataType(1); |
| | | couponsListVo.setMoney(userCouponRecord.getMoney()); |
| | | couponsListVo.setUserType(userCouponRecord.getCouponUseType()); |
| | | couponsListVo.setTime(sdf.format(userCouponRecord.getExpirationTime())); |
| | | couponsListVo.setType(userCouponRecord.getCouponType()); |
| | | couponsListVo.setFullMoney(userCouponRecord.getFullMoney()); |
| | | couponsListVo.setState(userCouponRecord.getState()); |
| | | Company company = companyService.selectById(userCouponRecord.getCompanyId()); |
| | | couponsListVo.setCompany(company.getName()); |
| | | rows.add(couponsListVo); |
| | | } |
| | | |
| | | Map<String, String> geocode = gdMapGeocodingUtil.geocode(orderPrivateCar.getStartLon().toString(), orderPrivateCar.getStartLat().toString()); |
| | | CompanyCity companyCity = companyCityService.selectOne(new EntityWrapper<CompanyCity>().eq("companyId", orderPrivateCar.getCompanyId()).eq("areaCode", geocode.get("districtCode")).eq("state", 1)); |
| | | if(null == companyCity){ |
| | | companyCity = companyCityService.selectOne(new EntityWrapper<CompanyCity>().eq("companyId", orderPrivateCar.getCompanyId()).eq("cityCode", geocode.get("cityCode")).eq("state", 1)); |
| | | } |
| | | if(null == companyCity){ |
| | | companyCity = companyCityService.selectOne(new EntityWrapper<CompanyCity>().eq("companyId", orderPrivateCar.getCompanyId()).eq("provinceCode", geocode.get("provinceCode")).eq("state", 1)); |
| | | } |
| | | List<UserTaxiCard> userTaxiCards = userTaxiCardService.selectList(new EntityWrapper<UserTaxiCard>().eq("userId", uid) |
| | | .in("type", Arrays.asList(1, 2, 3, 4)).like("companyCityId", "%" + companyCity.getId() + "%").where("now() between startTime and endTime")); |
| | | |
| | | //全国卡 |
| | | List<TaxiCard> taxiCards = taxiCardService.selectList(new EntityWrapper<TaxiCard>().eq("taxiCardType", 2).in("type", Arrays.asList(1, 2, 3, 4)).eq("state", 1)); |
| | | if(taxiCards.size() > 0) { |
| | | List<UserTaxiCard> userTaxiCards1 = userTaxiCardService.selectList(new EntityWrapper<UserTaxiCard>().eq("userId", uid) |
| | | .in("type", Arrays.asList(1, 2, 3, 4)).in("taxiCardId", taxiCards.stream().map(TaxiCard::getId).collect(Collectors.toList())).where("now() between startTime and endTime")); |
| | | userTaxiCards.addAll(userTaxiCards1); |
| | | } |
| | | |
| | | |
| | | //亲密账户 |
| | | List<UserUser> bindUserId = userUserService.selectList(new EntityWrapper<UserUser>().eq("bindUserId", uid)); |
| | | CompanyCity finalCompanyCity = companyCity; |
| | | bindUserId.forEach(userUser -> { |
| | | List<UserTaxiCard> taxiCardPayments1 = userTaxiCardService.selectList(new EntityWrapper<UserTaxiCard>().in("type", Arrays.asList(1, 2, 3, 4)) |
| | | .like("companyCityId", "%" + finalCompanyCity.getId() + "%").eq("userId", userUser.getUserId()).where("now() between startTime and endTime")); |
| | | userTaxiCards.addAll(taxiCardPayments1); |
| | | |
| | | //全国卡 |
| | | if(taxiCards.size() > 0) { |
| | | List<UserTaxiCard> userTaxiCards1 = userTaxiCardService.selectList(new EntityWrapper<UserTaxiCard>().eq("userId", userUser.getUserId()) |
| | | .in("type", Arrays.asList(1, 2, 3, 4)).in("taxiCardId", taxiCards.stream().map(TaxiCard::getId).collect(Collectors.toList())).where("now() between startTime and endTime")); |
| | | userTaxiCards.addAll(userTaxiCards1); |
| | | } |
| | | }); |
| | | |
| | | for(UserTaxiCard t : userTaxiCards){ |
| | | try { |
| | | CouponsListVo couponsListVo = new CouponsListVo(); |
| | | couponsListVo.setId(t.getId()); |
| | | couponsListVo.setDataType(2); |
| | | couponsListVo.setUserType(1); |
| | | couponsListVo.setTime(sdf.format(t.getEndTime())); |
| | | couponsListVo.setState(1); |
| | | couponsListVo.setTaxiCardType(t.getType()); |
| | | Company company = companyService.selectById(t.getCompanyId()); |
| | | couponsListVo.setCompany(company.getName()); |
| | | couponsListVo.setName(taxiCardService.selectById(t.getTaxiCardId()).getName()); |
| | | |
| | | |
| | | JSONObject jsonObject = JSON.parseObject(t.getContent()); |
| | | JSONArray businessTypes = jsonObject.getJSONArray("businessTypes"); |
| | | if(!businessTypes.toJavaList(Integer.class).contains(1)){ |
| | | continue; |
| | | } |
| | | if(t.getType() == 1){//{"businessTypes":[1,2,3],"time":5,"timeQuantum":["08:00:00 - 09:00:00","17:00:00 - 18:00:00"],"discount":5} |
| | | Integer time = jsonObject.getInteger("time"); |
| | | if(time == 0){ |
| | | continue; |
| | | } |
| | | JSONArray timeQuantum = jsonObject.getJSONArray("timeQuantum"); |
| | | SimpleDateFormat sdf1 = new SimpleDateFormat("yyyy-MM-dd"); |
| | | boolean b = true; |
| | | for(int i = 0; i < timeQuantum.size(); i++){ |
| | | String[] split = timeQuantum.getString(i).split(" - "); |
| | | Date s = sdf.parse(sdf1.format(new Date()) + " " + split[0]); |
| | | Date e = sdf.parse(sdf1.format(new Date()) + " " + split[1]); |
| | | if(s.getTime() <= System.currentTimeMillis() && System.currentTimeMillis() < e.getTime()){ |
| | | b = false; |
| | | break; |
| | | } |
| | | } |
| | | if(b){ |
| | | continue; |
| | | } |
| | | couponsListVo.setMoney(jsonObject.getDouble("discount")); |
| | | couponsListVo.setType(1); |
| | | } |
| | | if(t.getType() == 2){//{"businessTypes":[1,2,3],"fullReduction":[[50,3],[100,5],[150,10]]} |
| | | JSONArray timeQuantum = jsonObject.getJSONArray("timeQuantum"); |
| | | SimpleDateFormat sdf1 = new SimpleDateFormat("yyyy-MM-dd"); |
| | | boolean b = true; |
| | | for(int i = 0; i < timeQuantum.size(); i++){ |
| | | String[] split = timeQuantum.getString(i).split(" - "); |
| | | Date s = sdf.parse(sdf1.format(new Date()) + " " + split[0]); |
| | | Date e = sdf.parse(sdf1.format(new Date()) + " " + split[1]); |
| | | if(s.getTime() <= System.currentTimeMillis() && System.currentTimeMillis() < e.getTime()){ |
| | | b = false; |
| | | break; |
| | | } |
| | | } |
| | | if(b){ |
| | | continue; |
| | | } |
| | | JSONArray fullReduction = jsonObject.getJSONArray("fullReduction"); |
| | | b = true; |
| | | for(int i = fullReduction.size() - 1; i >= 0; i--){ |
| | | JSONArray jsonArray = fullReduction.getJSONArray(i); |
| | | Double m = jsonArray.getDouble(0); |
| | | Double j = jsonArray.getDouble(1); |
| | | if(orderPrivateCar.getOrderMoney().compareTo(m) >= 0){ |
| | | couponsListVo.setFullMoney(m); |
| | | couponsListVo.setMoney(j); |
| | | b = false; |
| | | break; |
| | | } |
| | | } |
| | | if(b){ |
| | | continue; |
| | | } |
| | | couponsListVo.setType(2); |
| | | } |
| | | if(t.getType() == 3){//{"businessTypes":[1,2,3],"time":1,"discountAmount":10} |
| | | Integer time = jsonObject.getInteger("time"); |
| | | if(time == 0){ |
| | | continue; |
| | | } |
| | | JSONArray timeQuantum = jsonObject.getJSONArray("timeQuantum"); |
| | | SimpleDateFormat sdf1 = new SimpleDateFormat("yyyy-MM-dd"); |
| | | boolean b = true; |
| | | for(int i = 0; i < timeQuantum.size(); i++){ |
| | | String[] split = timeQuantum.getString(i).split(" - "); |
| | | Date s = sdf.parse(sdf1.format(new Date()) + " " + split[0]); |
| | | Date e = sdf.parse(sdf1.format(new Date()) + " " + split[1]); |
| | | if(s.getTime() <= System.currentTimeMillis() && System.currentTimeMillis() < e.getTime()){ |
| | | b = false; |
| | | break; |
| | | } |
| | | } |
| | | if(b){ |
| | | continue; |
| | | } |
| | | couponsListVo.setFullMoney(0D); |
| | | couponsListVo.setMoney(jsonObject.getDouble("discountAmount")); |
| | | couponsListVo.setType(2); |
| | | } |
| | | if(t.getType() == 4){//{"businessTypes":[1,2,3],"discount":5,"timeQuantum":["08:00:00 - 09:00:00","17:00:00 - 18:00:00"]} |
| | | JSONArray timeQuantum = jsonObject.getJSONArray("timeQuantum"); |
| | | SimpleDateFormat sdf1 = new SimpleDateFormat("yyyy-MM-dd"); |
| | | boolean b = true; |
| | | for(int i = 0; i < timeQuantum.size(); i++){ |
| | | String[] split = timeQuantum.getString(i).split(" - "); |
| | | Date s = sdf.parse(sdf1.format(new Date()) + " " + split[0]); |
| | | Date e = sdf.parse(sdf1.format(new Date()) + " " + split[1]); |
| | | if(s.getTime() <= System.currentTimeMillis() && System.currentTimeMillis() < e.getTime()){ |
| | | b = false; |
| | | break; |
| | | } |
| | | } |
| | | if(b){ |
| | | continue; |
| | | } |
| | | couponsListVo.setMoney(jsonObject.getDouble("discount")); |
| | | couponsListVo.setType(1); |
| | | } |
| | | |
| | | |
| | | String str = ""; |
| | | TaxiCard taxiCard = taxiCardService.selectById(t.getTaxiCardId()); |
| | | if(taxiCard.getTaxiCardType() == 1){ |
| | | String[] split = taxiCard.getCompanyCityId().split(";"); |
| | | for(String c : split){ |
| | | CompanyCity companyCity1 = companyCityService.selectById(c); |
| | | if(ToolUtil.isNotEmpty(companyCity1.getAreaCode())){ |
| | | Region region = regionService.selectOne(new EntityWrapper<Region>().eq("code", companyCity1.getAreaCode())); |
| | | str += region.getName() + ";"; |
| | | continue; |
| | | } |
| | | if(ToolUtil.isNotEmpty(companyCity1.getCityCode())){ |
| | | Region region = regionService.selectOne(new EntityWrapper<Region>().eq("code", companyCity1.getCityCode())); |
| | | str += region.getName() + ";"; |
| | | continue; |
| | | } |
| | | if(ToolUtil.isNotEmpty(companyCity1.getProvinceCode())){ |
| | | Region region = regionService.selectOne(new EntityWrapper<Region>().eq("code", companyCity1.getProvinceCode())); |
| | | str += region.getName() + ";"; |
| | | continue; |
| | | } |
| | | } |
| | | }else{ |
| | | str = "全国;"; |
| | | } |
| | | couponsListVo.setCity(str.substring(0, str.length() - 1)); |
| | | |
| | | |
| | | rows.add(couponsListVo); |
| | | }catch (Exception e){ |
| | | e.printStackTrace(); |
| | | } |
| | | } |
| | | Collections.sort(rows, new Comparator<CouponsListVo>() { |
| | | public int compare(CouponsListVo s1, CouponsListVo s2) { |
| | | return Integer.compare(s1.getId(), s2.getId()); |
| | | } |
| | | }); |
| | | |
| | | if(rows.size() >= (pageNum + 1) * size){ |
| | | rows = rows.subList(pageNum, pageNum + size); |
| | | }else if(pageNum < rows.size() && rows.size() < (pageNum + 1) * size){ |
| | | rows = rows.subList(pageNum, rows.size()); |
| | | }else{ |
| | | rows = new ArrayList<>(); |
| | | } |
| | | return rows; |
| | | } |
| | | |
| | | @Override |
| | | public ResultUtil payPrivateCarOrder(Integer payType, Integer orderId, Integer couponId, Integer type) throws Exception { |
| | | OrderPrivateCar orderPrivateCar = this.selectById(orderId); |
| | | if(orderPrivateCar.getState() == 8 || orderPrivateCar.getState() == 9){ |
| | | return ResultUtil.error("订单已完成支付,不允许重复支付", ""); |
| | | return ResultUtil.error("订单已完成支付,不允许重复支付"); |
| | | } |
| | | if(orderPrivateCar.getState() != 7){ |
| | | return ResultUtil.error("订单不在待支付状态,不允许支付", ""); |
| | | return ResultUtil.error("订单不在待支付状态,不允许支付"); |
| | | } |
| | | Integer uid = orderPrivateCar.getUserId(); |
| | | Double orderMoney = orderPrivateCar.getOrderMoney(); |
| | | UserInfo userInfo = userInfoService.selectById(uid); |
| | | ResultUtil resultUtil = ResultUtil.success(new Object()); |
| | | ResultUtil resultUtil = ResultUtil.success(); |
| | | orderPrivateCar.setCouponMoney(0D);//初始化历史数据 |
| | | orderPrivateCar.setCouponId(null); |
| | | |
| | |
| | | if(null != couponId){ |
| | | userCouponRecord = userCouponRecordService.selectById(couponId); |
| | | if(userCouponRecord.getCompanyId() != orderPrivateCar.getCompanyId()){ |
| | | return ResultUtil.error("优惠券不能用于此订单", ""); |
| | | return ResultUtil.error("优惠券不能用于此订单"); |
| | | } |
| | | if(userCouponRecord.getState() == 2){ |
| | | return ResultUtil.error("优惠券已使用", ""); |
| | | return ResultUtil.error("优惠券已使用"); |
| | | } |
| | | if(userCouponRecord.getState() == 3){ |
| | | return ResultUtil.error("优惠券已过期", ""); |
| | | return ResultUtil.error("优惠券已过期"); |
| | | } |
| | | if(userCouponRecord.getCouponUseType() != 0 && userCouponRecord.getCouponUseType() != 1){ |
| | | return ResultUtil.error("优惠券不能用于此类型订单", ""); |
| | | return ResultUtil.error("优惠券不能用于此类型订单"); |
| | | } |
| | | if(userCouponRecord.getCouponType() == 2 && orderMoney.compareTo(userCouponRecord.getFullMoney()) < 0){ |
| | | return ResultUtil.error("优惠券不能用于此订单", ""); |
| | | return ResultUtil.error("优惠券不能用于此订单"); |
| | | } |
| | | orderMoney = orderMoney - userCouponRecord.getMoney(); |
| | | orderPrivateCar.setCouponMoney(userCouponRecord.getMoney()); |
| | |
| | | orderMoney = v; |
| | | } |
| | | } |
| | | orderMoney = orderMoney < 0 ? 0 : orderMoney; |
| | | |
| | | SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMddHHmmssSSS"); |
| | | String out_trade_no = sdf.format(new Date()) + 1 + orderPrivateCar.getId(); |
| | | |
| | | if(payType == 1){//微信支付 |
| | | String app = type == 1 ? "APP" : "JSAPI"; |
| | | resultUtil = payMoneyUtil.weixinpay("完成订单", "", orderId + "_1_" + UUIDUtil.getRandomCode(5), orderMoney.toString(), "/base/wxPayOrderTaxi", app, userInfo.getAppletsOpenId()); |
| | | String appletsOpenId = ""; |
| | | String tradeType = "APP"; |
| | | if(type == 3){ |
| | | appletsOpenId = userInfo.getAppletsOpenId(); |
| | | tradeType = "JSAPI"; |
| | | if(ToolUtil.isEmpty(userInfo.getAppletsOpenId())){ |
| | | return ResultUtil.error("支付异常,请重新授权登录小程序"); |
| | | } |
| | | } |
| | | resultUtil = payMoneyUtil.weixinpay("完成订单", "", out_trade_no, orderMoney.toString(), callbackPath + "/base/wxPayOrderTaxi", tradeType, appletsOpenId); |
| | | if(resultUtil.getCode() == 200){ |
| | | paymentRecordService.saveData(1, orderPrivateCar.getUserId(), 1, orderId, 1, 1, orderMoney, "", 1);//添加预支付数据 |
| | | } |
| | | } |
| | | if(payType == 2) {//支付宝支付 |
| | | resultUtil = payMoneyUtil.alipay("完成订单", "完成订单", "", orderId + "_1_" + UUIDUtil.getRandomCode(5), orderMoney.toString(), "/base/aliPayOrderTaxi"); |
| | | resultUtil = payMoneyUtil.alipay("订单完成支付", "支付订单", out_trade_no, orderMoney.toString(), callbackPath + "/base/aliPayOrderTaxi"); |
| | | if(resultUtil.getCode() == 200){ |
| | | paymentRecordService.saveData(1, orderPrivateCar.getUserId(), 1, orderId, 1, 2, orderMoney, "", 1);//添加预支付数据 |
| | | } |
| | | } |
| | | if(payType == 3){//余额支付 |
| | | if(userInfo.getBalance() == null || userInfo.getBalance() < orderMoney){ |
| | | return ResultUtil.error("余额不足,无法完成支付", ""); |
| | | return ResultUtil.error("余额不足,无法完成支付"); |
| | | } |
| | | |
| | | userInfo.setBalance(new BigDecimal(userInfo.getBalance()).subtract(new BigDecimal(orderMoney)).setScale(2, BigDecimal.ROUND_HALF_EVEN).doubleValue()); |
| | |
| | | userInfo.setIntegral(userInfo.getIntegral() + (orderMoney.intValue() * query1.getIntegral()));//积分 |
| | | |
| | | //添加交易明细 |
| | | transactionDetailsService.saveData(uid, "快车订单", orderMoney, 2, 1, 1, 1, orderId); |
| | | transactionDetailsService.saveData(uid, "完成订单", orderMoney, 2, 1, 1, 1, orderId); |
| | | userInfoService.updateById(userInfo); |
| | | |
| | | orderPrivateCar.setState(8); |
| | |
| | | Double price = orderPrivateCar.getStartMoney() + orderPrivateCar.getMileageMoney() + orderPrivateCar.getWaitMoney() + orderPrivateCar.getDurationMoney() + orderPrivateCar.getLongDistanceMoney(); |
| | | d = new BigDecimal(price).multiply(new BigDecimal(speMoney).divide(new BigDecimal(100))).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()); |
| | | 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() { |
| | | @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); |
| | | |
| | | new Thread(new Runnable() { |
| | | @Override |
| | | public void run() { |
| | | if(pushMinistryOfTransport){//上传数据 |
| | | pushMinistryOfTransportUtil.operatePay(orderId); |
| | | } |
| | | } |
| | | }).start(); |
| | | } |
| | | |
| | | this.updateAllColumnById(orderPrivateCar); |
| | | return resultUtil; |
| | | } |
| | | |
| | | |
| | | @Override |
| | | public ResultUtil payPrivateCarOrder1(Integer payType, Integer orderId, Integer objectId, Integer objectType, Integer type) throws Exception { |
| | | OrderPrivateCar orderPrivateCar = this.selectById(orderId); |
| | | if(orderPrivateCar.getState() == 8 || orderPrivateCar.getState() == 9){ |
| | | return ResultUtil.error("订单已完成支付,不允许重复支付", ""); |
| | | } |
| | | if(orderPrivateCar.getState() != 7){ |
| | | return ResultUtil.error("订单不在待支付状态,不允许支付", ""); |
| | | } |
| | | Integer uid = orderPrivateCar.getUserId(); |
| | | Double orderMoney = orderPrivateCar.getOrderMoney(); |
| | | UserInfo userInfo = userInfoService.selectById(uid); |
| | | ResultUtil resultUtil = ResultUtil.success(new Object()); |
| | | orderPrivateCar.setCouponMoney(0D);//初始化历史数据 |
| | | orderPrivateCar.setCouponId(null); |
| | | |
| | | //计算优惠券 |
| | | UserCouponRecord userCouponRecord = null; |
| | | if(null != objectId && objectType == 1){ |
| | | userCouponRecord = userCouponRecordService.selectById(objectId); |
| | | if(userCouponRecord.getCompanyId() != orderPrivateCar.getCompanyId()){ |
| | | return ResultUtil.error("优惠券不能用于此订单", ""); |
| | | } |
| | | if(userCouponRecord.getState() == 2){ |
| | | return ResultUtil.error("优惠券已使用", ""); |
| | | } |
| | | if(userCouponRecord.getState() == 3){ |
| | | return ResultUtil.error("优惠券已过期", ""); |
| | | } |
| | | if(userCouponRecord.getCouponUseType() != 0 && userCouponRecord.getCouponUseType() != 1){ |
| | | return ResultUtil.error("优惠券不能用于此类型订单", ""); |
| | | } |
| | | if(userCouponRecord.getCouponType() == 2 && orderMoney.compareTo(userCouponRecord.getFullMoney()) < 0){ |
| | | return ResultUtil.error("优惠券不能用于此订单", ""); |
| | | } |
| | | orderMoney = orderMoney - userCouponRecord.getMoney(); |
| | | orderPrivateCar.setCouponMoney(userCouponRecord.getMoney()); |
| | | orderPrivateCar.setCouponId(objectId); |
| | | } |
| | | |
| | | //打车卡 |
| | | UserTaxiCard userTaxiCard = null; |
| | | if(null != objectId && objectType == 2){ |
| | | userTaxiCard = userTaxiCardService.selectById(objectId); |
| | | TaxiCard taxiCard = taxiCardService.selectById(userTaxiCard.getTaxiCardId()); |
| | | if(taxiCard.getTaxiCardType() == 1 && userTaxiCard.getCompanyId() != orderPrivateCar.getCompanyId()){ |
| | | return ResultUtil.error("打车卡不能用于此订单", ""); |
| | | } |
| | | if(System.currentTimeMillis() > userTaxiCard.getEndTime().getTime()){ |
| | | return ResultUtil.error("打车卡已过期", ""); |
| | | } |
| | | if(userTaxiCard.getType() == 1 || userTaxiCard.getType() == 3){ |
| | | Integer time = JSON.parseObject(userTaxiCard.getContent()).getInteger("time"); |
| | | if(0 == time){ |
| | | return ResultUtil.error("打车卡已使用完", ""); |
| | | } |
| | | } |
| | | List<Integer> integers = JSON.parseObject(userTaxiCard.getContent()).getJSONArray("businessTypes").toJavaList(Integer.class); |
| | | if(!integers.contains(1)){ |
| | | return ResultUtil.error("打车卡不能用于此类型订单", ""); |
| | | } |
| | | |
| | | Double yh = 0D; |
| | | JSONObject jsonObject = JSON.parseObject(userTaxiCard.getContent()); |
| | | if(userTaxiCard.getType() == 1){//打折次数卡{"businessTypes":[1,2,3],"time":5,"timeQuantum":["08:00:00 - 09:00:00","17:00:00 - 18:00:00"],"discount":5} |
| | | JSONArray timeQuantum = jsonObject.getJSONArray("timeQuantum"); |
| | | Double discount = jsonObject.getDouble("discount"); |
| | | SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd"); |
| | | SimpleDateFormat sdf1 = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); |
| | | Date date = new Date(); |
| | | for(int i = 0; i < timeQuantum.size(); i++){ |
| | | String[] split = timeQuantum.getString(i).split(" - "); |
| | | Date s = sdf1.parse(sdf.format(date) + " " + split[0]); |
| | | Date e = sdf1.parse(sdf.format(date) + " " + split[1]); |
| | | if(s.getTime() <= System.currentTimeMillis() && System.currentTimeMillis() < e.getTime()){ |
| | | yh = new BigDecimal(orderPrivateCar.getOrderMoney()).multiply(new BigDecimal((10 - discount) / 10)).setScale(2, RoundingMode.HALF_EVEN).doubleValue(); |
| | | jsonObject.put("time", jsonObject.getInteger("time") - 1); |
| | | userTaxiCard.setContent(jsonObject.toJSONString()); |
| | | break; |
| | | } |
| | | } |
| | | |
| | | } |
| | | if(userTaxiCard.getType() == 2){//优惠卡{"businessTypes":[1,2,3],"fullReduction":[[50,3],[100,5],[150,10]]} |
| | | JSONArray timeQuantum = jsonObject.getJSONArray("timeQuantum"); |
| | | JSONArray fullReduction = jsonObject.getJSONArray("fullReduction"); |
| | | SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd"); |
| | | SimpleDateFormat sdf1 = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); |
| | | Date date = new Date(); |
| | | for(int i = 0; i < timeQuantum.size(); i++){ |
| | | String[] split = timeQuantum.getString(i).split(" - "); |
| | | Date s = sdf1.parse(sdf.format(date) + " " + split[0]); |
| | | Date e = sdf1.parse(sdf.format(date) + " " + split[1]); |
| | | if(s.getTime() <= System.currentTimeMillis() && System.currentTimeMillis() < e.getTime()){ |
| | | for(int j = fullReduction.size() - 1; j >= 0; j--){ |
| | | JSONArray jsonArray = fullReduction.getJSONArray(j); |
| | | Double p = jsonArray.getDouble(0);//满金额 |
| | | if(orderPrivateCar.getOrderMoney().compareTo(p) >= 0){ |
| | | yh = jsonArray.getDouble(1);//优惠金额 |
| | | break; |
| | | } |
| | | } |
| | | } |
| | | } |
| | | |
| | | } |
| | | if(userTaxiCard.getType() == 3){//次数卡{"businessTypes":[1,2,3],"time":1,"discountAmount":10} |
| | | JSONArray timeQuantum = jsonObject.getJSONArray("timeQuantum"); |
| | | SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd"); |
| | | SimpleDateFormat sdf1 = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); |
| | | Date date = new Date(); |
| | | for(int i = 0; i < timeQuantum.size(); i++){ |
| | | String[] split = timeQuantum.getString(i).split(" - "); |
| | | Date s = sdf1.parse(sdf.format(date) + " " + split[0]); |
| | | Date e = sdf1.parse(sdf.format(date) + " " + split[1]); |
| | | if(s.getTime() <= System.currentTimeMillis() && System.currentTimeMillis() < e.getTime()){ |
| | | yh = jsonObject.getDouble("discountAmount"); |
| | | jsonObject.put("time", jsonObject.getInteger("time") - 1); |
| | | userTaxiCard.setContent(jsonObject.toJSONString()); |
| | | } |
| | | } |
| | | |
| | | } |
| | | if(userTaxiCard.getType() == 4){//打折天数卡{"businessTypes":[1,2,3],"discount":5,"timeQuantum":["08:00:00 - 09:00:00","17:00:00 - 18:00:00"]} |
| | | Double discount = jsonObject.getDouble("discount");//折扣 |
| | | JSONArray timeQuantum = jsonObject.getJSONArray("timeQuantum");//使用时间段 |
| | | SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd"); |
| | | SimpleDateFormat sdf1 = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); |
| | | Date date = new Date(); |
| | | for(int i = 0; i < timeQuantum.size(); i++){ |
| | | String[] split = timeQuantum.getString(i).split(" - "); |
| | | Date s = sdf1.parse(sdf.format(date) + " " + split[0]); |
| | | Date e = sdf1.parse(sdf.format(date) + " " + split[1]); |
| | | if(s.getTime() <= System.currentTimeMillis() && System.currentTimeMillis() < e.getTime()){ |
| | | yh = new BigDecimal(orderPrivateCar.getOrderMoney()).multiply(new BigDecimal((10 - discount) / 10)).setScale(2, RoundingMode.HALF_EVEN).doubleValue(); |
| | | break; |
| | | } |
| | | } |
| | | } |
| | | |
| | | orderMoney = orderMoney - yh; |
| | | orderPrivateCar.setTaxiCardId(userTaxiCard.getTaxiCardId()); |
| | | orderPrivateCar.setUserTaxiCardId(objectId); |
| | | orderPrivateCar.setDiscountAmount(yh); |
| | | } |
| | | |
| | | |
| | | |
| | | //计算红包 |
| | | UserRedPacketRecord query = userRedPacketRecordService.query(uid, orderPrivateCar.getCompanyId(), 1, 1, orderMoney); |
| | | if(null != query && query.getMoney().compareTo(orderMoney) < 0){ |
| | | orderMoney = orderMoney - query.getMoney(); |
| | | orderPrivateCar.setRedPacketMoney(query.getMoney()); |
| | | orderPrivateCar.setRedPacketId(query.getId()); |
| | | } |
| | | |
| | | //计算折扣 |
| | | UserActivityDiscount1 query2 = userActivityDiscount1Mapper.query(orderPrivateCar.getCompanyId()); |
| | | if(null != query2){ |
| | | Double special = query2.getSpecial(); |
| | | orderPrivateCar.setDiscount(special); |
| | | double v = new BigDecimal(orderMoney).multiply(new BigDecimal(special / 10)).setScale(2, BigDecimal.ROUND_HALF_EVEN).doubleValue(); |
| | | if(orderMoney.compareTo(v) > 0){ |
| | | orderPrivateCar.setDiscountMoney(orderMoney - v); |
| | | orderPrivateCar.setActivityId(query2.getId()); |
| | | orderMoney = v; |
| | | } |
| | | } |
| | | orderMoney = orderMoney < 0 ? 0 : orderMoney; |
| | | if(payType == 1){//微信支付 |
| | | if(orderMoney == 0){ |
| | | return ResultUtil.error("请使用余额支付"); |
| | | } |
| | | String app = type == 1 ? "APP" : "JSAPI"; |
| | | resultUtil = payMoneyUtil.weixinpay("完成订单", "", orderId + "_1_" + UUIDUtil.getRandomCode(5), orderMoney.toString(), "/base/wxPayOrderTaxi", app, userInfo.getAppletsOpenId()); |
| | | paymentRecordService.saveData(1, orderPrivateCar.getUserId(), 1, orderId, 1, 1, orderMoney, "", 1);//添加预支付数据 |
| | | } |
| | | if(payType == 2) {//支付宝支付 |
| | | if(orderMoney == 0){ |
| | | return ResultUtil.error("请使用余额支付"); |
| | | } |
| | | resultUtil = payMoneyUtil.alipay("完成订单", "完成订单", "", orderId + "_1_" + UUIDUtil.getRandomCode(5), orderMoney.toString(), "/base/aliPayOrderTaxi"); |
| | | paymentRecordService.saveData(1, orderPrivateCar.getUserId(), 1, orderId, 1, 2, orderMoney, "", 1);//添加预支付数据 |
| | | } |
| | | if(payType == 3){//余额支付 |
| | | 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()); |
| | | if(null != 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.setPayType(3); |
| | | orderPrivateCar.setPayMoney(orderMoney); |
| | | |
| | | //处理优惠券和红包 |
| | | if(null != userCouponRecord){ |
| | | userCouponRecord.setState(2); |
| | | userCouponRecord.setEndTime(new Date()); |
| | | userCouponRecordService.updateById(userCouponRecord); |
| | | } |
| | | //处理打车卡 |
| | | if(null != userTaxiCard){ |
| | | userTaxiCardService.updateById(userTaxiCard); |
| | | } |
| | | if(null != query){ |
| | | query.setState(2); |
| | | query.setEndTime(new Date()); |
| | | userRedPacketRecordService.updateById(query); |
| | | } |
| | | |
| | | //添加已收入明细 |
| | | Company company = companyService.selectById(orderPrivateCar.getCompanyId()); |
| | | Double speMoney = company.getSpeMoney(); |
| | | BigDecimal d = null;//企业收入 |
| | | BigDecimal c = null;//司机收入 |
| | | // TODO: 2022/3/19 抽成按照订单金额计算,优先保证司机的收入,用户支付金额不够,则在平台收入中补贴司机收入 |
| | | //例如:订单金额10元,优惠3元,司机收入比例80%,平台收入比例20%。 |
| | | //司机收入:10 * 0.8 = 8 |
| | | //平台收入:7 - 8 = -1 |
| | | if(company.getIsSpeFixedOrProportional() == 2){//固定 |
| | | d = new BigDecimal(speMoney.compareTo(orderPrivateCar.getOrderMoney()) > 0 ? orderPrivateCar.getOrderMoney() : speMoney); |
| | | c = new BigDecimal(orderPrivateCar.getOrderMoney()).subtract(d);//只有出行金额参与抽成,其余归属司机 |
| | | } |
| | | if(company.getIsSpeFixedOrProportional() == 1){//比例 |
| | | c = new BigDecimal(orderPrivateCar.getOrderMoney()).multiply(new BigDecimal(1 - (speMoney / 100))).setScale(2, BigDecimal.ROUND_HALF_EVEN); |
| | | d = new BigDecimal(orderPrivateCar.getPayMoney()).subtract(c).setScale(2, BigDecimal.ROUND_HALF_EVEN); |
| | | } |
| | | incomeService.saveData(1, orderPrivateCar.getCompanyId(), 2, orderPrivateCar.getId(), 1, d.doubleValue()); |
| | | incomeService.saveData(2, orderPrivateCar.getDriverId(), 2, orderPrivateCar.getId(), 1, c.doubleValue()); |
| | |
| | | PaymentRecord query = paymentRecordService.query(1, orderPrivateCar.getUserId(), 1, Integer.valueOf(id), 1, type, 1); |
| | | if(null != query){ |
| | | //添加交易明细 |
| | | transactionDetailsService.saveData(orderPrivateCar.getUserId(), "快车取消订单", query.getAmount(), 2, 1, 1, 1, query.getOrderId()); |
| | | transactionDetailsService.saveData(orderPrivateCar.getUserId(), "取消订单", query.getAmount(), 2, 1, 1, 1, query.getOrderId()); |
| | | orderPrivateCar.setState(10); |
| | | //解除小号绑定 |
| | | if(orderPrivateCar.getBindId() != null){ |
| | | chinaMobileUtil.midAxbUnBindSend(orderPrivateCar.getBindId(), orderPrivateCar.getTelX(), (System.currentTimeMillis() + 600000)); |
| | | chinaMobileUtil.midAxbUnBindSend(orderPrivateCar.getBindId()); |
| | | } |
| | | orderPrivateCar.setBindId(""); |
| | | orderPrivateCar.setTelX(""); |
| | |
| | | public void payOrderPrivateCarCallback(Integer id, String order_id, Integer type) throws Exception { |
| | | OrderPrivateCar orderPrivateCar = this.selectById(id); |
| | | PaymentRecord query = paymentRecordService.query(1, orderPrivateCar.getUserId(), 1, Integer.valueOf(id), 1, type, 1); |
| | | if(null != query && query.getState() == 1){ |
| | | if(null != query){ |
| | | //添加交易明细 |
| | | transactionDetailsService.saveData(orderPrivateCar.getUserId(), "快车订单", query.getAmount(), 2, 1, 1, 1, query.getOrderId()); |
| | | transactionDetailsService.saveData(orderPrivateCar.getUserId(), "完成订单", query.getAmount(), 2, 1, 1, 1, query.getOrderId()); |
| | | orderPrivateCar.setState(8); |
| | | orderPrivateCar.setPayType(type); |
| | | orderPrivateCar.setPayMoney(query.getAmount()); |
| | |
| | | userCouponRecord.setState(2); |
| | | userCouponRecord.setEndTime(new Date()); |
| | | userCouponRecordService.updateById(userCouponRecord); |
| | | } |
| | | if(null != orderPrivateCar.getUserTaxiCardId()){ |
| | | UserTaxiCard userTaxiCard = userTaxiCardService.selectById(orderPrivateCar.getUserTaxiCardId()); |
| | | if(userTaxiCard.getType() == 1 || userTaxiCard.getType() == 3){ |
| | | JSONObject jsonObject = JSON.parseObject(userTaxiCard.getContent()); |
| | | jsonObject.put("time", jsonObject.getInteger("time") - 1); |
| | | userTaxiCard.setContent(jsonObject.toJSONString()); |
| | | userTaxiCardService.updateById(userTaxiCard); |
| | | } |
| | | } |
| | | if(null != orderPrivateCar.getRedPacketId()){ |
| | | UserRedPacketRecord userRedPacketRecord = userRedPacketRecordService.selectById(orderPrivateCar.getRedPacketId()); |
| | |
| | | Double taxi = company.getSpeMoney(); |
| | | BigDecimal d = null;//企业收入 |
| | | BigDecimal c = null;//司机收入 |
| | | // TODO: 2022/3/19 抽成按照订单金额计算,优先保证司机的收入,用户支付金额不够,则在平台收入中补贴司机收入 |
| | | //例如:订单金额10元,优惠3元,司机收入比例80%,平台收入比例20%。 |
| | | //司机收入:10 * 0.8 = 8 |
| | | //平台收入:7 - 8 = -1 |
| | | if(company.getIsSpeFixedOrProportional() == 2){//固定 |
| | | d = new BigDecimal(taxi.compareTo(orderPrivateCar.getOrderMoney()) > 0 ? orderPrivateCar.getOrderMoney() : taxi); |
| | | d = new BigDecimal(taxi); |
| | | c = new BigDecimal(orderPrivateCar.getOrderMoney()).subtract(d).setScale(2, BigDecimal.ROUND_HALF_EVEN); |
| | | } |
| | | if(company.getIsSpeFixedOrProportional() == 1){//比例 |
| | | c = new BigDecimal(orderPrivateCar.getOrderMoney()).multiply(new BigDecimal(1 - (taxi / 100))).setScale(2, BigDecimal.ROUND_HALF_EVEN); |
| | | d = new BigDecimal(orderPrivateCar.getPayMoney()).subtract(c).setScale(2, BigDecimal.ROUND_HALF_EVEN); |
| | | Double price = orderPrivateCar.getStartMoney() + orderPrivateCar.getMileageMoney() + orderPrivateCar.getWaitMoney() + orderPrivateCar.getDurationMoney() + orderPrivateCar.getLongDistanceMoney(); |
| | | d = new BigDecimal(price).multiply(new BigDecimal(taxi).divide(new BigDecimal(100))).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()); |
| | | incomeService.saveData(2, orderPrivateCar.getDriverId(), 2, orderPrivateCar.getId(), 1, c.doubleValue()); |
| | |
| | | if(null == distance){ |
| | | System.err.println("查询距离出错了"); |
| | | }else{ |
| | | d = new BigDecimal(distance.get("distance")).divide(new BigDecimal(1000)).setScale(2, BigDecimal.ROUND_HALF_EVEN).toString(); |
| | | t = new BigDecimal(distance.get("duration")).divide(new BigDecimal(60),2).setScale(2, BigDecimal.ROUND_HALF_EVEN).intValue() + ""; |
| | | d = new BigDecimal(distance.get("distance")).divide(new BigDecimal(1000), new MathContext(2, RoundingMode.HALF_EVEN)).setScale(2, BigDecimal.ROUND_HALF_EVEN).toString(); |
| | | t = new BigDecimal(distance.get("duration")).divide(new BigDecimal(60), new MathContext(2, RoundingMode.HALF_EVEN)).setScale(2, BigDecimal.ROUND_HALF_EVEN).intValue() + ""; |
| | | } |
| | | OrderServerWarpper orderServerWarpper = new OrderServerWarpper(); |
| | | orderServerWarpper.setOrderId(orderPrivateCar.getId()); |
| | |
| | | if(null == distance){ |
| | | System.err.println("查询距离出错了"); |
| | | }else{ |
| | | d = new BigDecimal(distance.get("distance")).divide(new BigDecimal(1000)).setScale(2, BigDecimal.ROUND_HALF_EVEN).toString(); |
| | | t = new BigDecimal(distance.get("duration")).divide(new BigDecimal(60),2).setScale(2, BigDecimal.ROUND_HALF_EVEN).intValue() + ""; |
| | | d = new BigDecimal(distance.get("distance")).divide(new BigDecimal(1000), new MathContext(2, RoundingMode.HALF_EVEN)).setScale(2, BigDecimal.ROUND_HALF_EVEN).toString(); |
| | | t = new BigDecimal(distance.get("duration")).divide(new BigDecimal(60), new MathContext(2, RoundingMode.HALF_EVEN)).setScale(2, BigDecimal.ROUND_HALF_EVEN).intValue() + ""; |
| | | } |
| | | orderServerWarpper.setReservationMileage("0"); |
| | | orderServerWarpper.setReservationTime("0"); |
| | |
| | | return endPushWarpper; |
| | | } |
| | | |
| | | |
| | | @Override |
| | | public ResultUtil payThankYouFee(Integer uid, Integer orderId, Double money, Integer payType, Integer type) throws Exception { |
| | | UserInfo userInfo = userInfoService.selectById(uid); |
| | | OrderPrivateCar orderPrivateCar = this.selectById(orderId); |
| | | ResultUtil resultUtil = ResultUtil.success(); |
| | | if(payType == 1){//微信支付 |
| | | String app = type == 1 ? "APP" : "JSAPI"; |
| | | resultUtil = payMoneyUtil.weixinpay("感谢费", "", orderId + "_1_" + UUIDUtil.getRandomCode(5), money.toString(), "/base/wxPayThankYouFee", app, userInfo.getAppletsOpenId()); |
| | | paymentRecordService.saveData(3, uid, 1, orderId, 1, 1, money, "", 1);//添加预支付数据 |
| | | } |
| | | if(payType == 2){//支付宝支付 |
| | | resultUtil = payMoneyUtil.alipay("感谢费", "感谢费", "", orderId + "_1_" + UUIDUtil.getRandomCode(5), money.toString(), "/base/aliPayThankYouFee"); |
| | | paymentRecordService.saveData(1, uid, 1, orderId, 1, 2, money, "", 1);//添加预支付数据 |
| | | } |
| | | if(payType == 3){//余额支付 |
| | | if(userInfo.getBalance() == null || userInfo.getBalance() < money){ |
| | | return ResultUtil.error("余额不足,无法完成支付", ""); |
| | | public ResultUtil<BaseWarpper> directCallCar(String phone, String placementLon, String placementLat, String startLon, String startLat, String startAddress, String deviceCode) throws Exception { |
| | | //查找与起点匹配的企业(经营范围) |
| | | Map<String, String> geocode = gdMapGeocodingUtil.geocode(startLon, startLat); |
| | | Company query = companyCityService.query(geocode.get("districtCode")); |
| | | if(null == query){ |
| | | return ResultUtil.error("起点暂无企业提供服务"); |
| | | } |
| | | |
| | | userInfo.setBalance(new BigDecimal(userInfo.getBalance()).subtract(new BigDecimal(money)).setScale(2, BigDecimal.ROUND_HALF_EVEN).doubleValue()); |
| | | UserInfo userInfo = userInfoMapper.queryByPhone(phone); |
| | | if(null == userInfo){ |
| | | userInfo = new UserInfo(); |
| | | userInfo.setPhone(phone); |
| | | userInfo.setPassWord(ShiroKit.md5("", "&a.s")); |
| | | userInfo.setNickName(userInfoService.getDefaultName()); |
| | | userInfo.setIsAuth(1); |
| | | userInfo.setConsumption(0D); |
| | | userInfo.setBalance(0D); |
| | | userInfo.setState(1); |
| | | |
| | | SysIntegral query1 = sysIntegralMapper.query(orderPrivateCar.getCompanyId()); |
| | | userInfo.setIntegral(userInfo.getIntegral() + (money.intValue() * query1.getIntegral()));//积分 |
| | | |
| | | //添加交易明细 |
| | | transactionDetailsService.saveData(uid, "快车订单-感谢费", money, 2, 1, 1, 1, orderId); |
| | | userInfoService.updateById(userInfo); |
| | | |
| | | orderPrivateCar.setThankYouFee(money); |
| | | this.updateById(orderPrivateCar); |
| | | |
| | | //添加已收入明细 |
| | | incomeService.saveData(2, orderPrivateCar.getDriverId(), 6, orderPrivateCar.getId(), 1, money); |
| | | Driver driver = driverService.selectById(orderPrivateCar.getDriverId()); |
| | | driver.setBusinessMoney(new BigDecimal(null != driver.getBusinessMoney() ? driver.getBusinessMoney() : 0).add(new BigDecimal(money)).setScale(2, BigDecimal.ROUND_HALF_EVEN).doubleValue()); |
| | | driver.setLaveBusinessMoney(new BigDecimal(null != driver.getLaveBusinessMoney() ? driver.getLaveBusinessMoney() : 0).add(new BigDecimal(money)).setScale(2, BigDecimal.ROUND_HALF_EVEN).doubleValue()); |
| | | driver.setBalance(new BigDecimal(null != driver.getBalance() ? driver.getBalance() : 0).add(new BigDecimal(money)).setScale(2, BigDecimal.ROUND_HALF_EVEN).doubleValue()); |
| | | driverService.updateById(driver); |
| | | systemNoticeService.addSystemNotice(1, "您已使用余额成功完成感谢费支付,谢谢使用!", uid, 1); |
| | | //用户所属企业 |
| | | if(null != geocode){ |
| | | userInfo.setCompanyId(null != query ? query.getId() : null); |
| | | userInfo.setRegistAreaCode(geocode.get("districtCode")); |
| | | } |
| | | userInfoService.insert(userInfo); |
| | | |
| | | userInfoService.addCoupon(userInfo);//添加优惠券 |
| | | |
| | | UserInfo finalUserInfo = userInfo; |
| | | new Thread(new Runnable() { |
| | | @Override |
| | | public void run() { |
| | | if(pushMinistryOfTransport){ |
| | | //上传数据 |
| | | pushMinistryOfTransportUtil.baseInfoPassenger(finalUserInfo.getId()); |
| | | } |
| | | } |
| | | }).start(); |
| | | |
| | | } |
| | | List<Map<String, Object>> list = serverCarModelMapper.queryServerCarModel(1); |
| | | if(list.size() == 0){ |
| | | return ResultUtil.error("暂无可用的车型"); |
| | | } |
| | | Date travelTime = new Date(System.currentTimeMillis() + 300000); |
| | | |
| | | |
| | | OrderTaxi orderTaxi = new OrderTaxi(); |
| | | orderTaxi.setType(1); |
| | | orderTaxi.setUserId(userInfo.getId()); |
| | | orderTaxi.setOrderNum(this.getOrderNum()); |
| | | orderTaxi.setPlacementLon(Double.valueOf(placementLon)); |
| | | orderTaxi.setPlacementLat(Double.valueOf(placementLat)); |
| | | orderTaxi.setStartLon(Double.valueOf(startLon)); |
| | | orderTaxi.setStartLat(Double.valueOf(startLat)); |
| | | orderTaxi.setStartAddress(startAddress); |
| | | orderTaxi.setSubstitute(0); |
| | | orderTaxi.setPassengers(userInfo.getNickName()); |
| | | orderTaxi.setPassengersPhone(phone); |
| | | orderTaxi.setState(1); |
| | | orderTaxi.setInsertTime(new Date()); |
| | | orderTaxi.setTravelTime(travelTime); |
| | | orderTaxi.setOrderType(1); |
| | | orderTaxi.setOrderSource(7); |
| | | orderTaxi.setIsReassign(1); |
| | | orderTaxi.setDeviceCode(deviceCode); |
| | | orderTaxi.setIsDelete(1); |
| | | |
| | | ResultUtil<BaseWarpper> resultUtil = orderTaxiService.taxiOrder(orderTaxi, userInfo.getId()); |
| | | return resultUtil; |
| | | } |
| | | |
| | | @Override |
| | | public void payThankYouFeeCallback(Integer orderId, String order_id, Integer payType) throws Exception { |
| | | OrderPrivateCar orderPrivateCar = this.selectById(orderId); |
| | | UserInfo userInfo = userInfoService.selectById(orderPrivateCar.getUserId()); |
| | | PaymentRecord query = paymentRecordService.query(3, userInfo.getId(), 1, orderId, 1, payType, 1); |
| | | query.setState(2); |
| | | query.setCode(order_id); |
| | | paymentRecordService.updateById(query); |
| | | |
| | | SysIntegral query1 = sysIntegralMapper.query(orderPrivateCar.getCompanyId()); |
| | | userInfo.setIntegral(userInfo.getIntegral() + (query.getAmount().intValue() * query1.getIntegral()));//积分 |
| | | |
| | | //添加交易明细 |
| | | transactionDetailsService.saveData(userInfo.getId(), "快车订单-感谢费", query.getAmount(), 2, 1, 1, 1, orderId); |
| | | userInfoService.updateById(userInfo); |
| | | |
| | | orderPrivateCar.setThankYouFee(query.getAmount()); |
| | | this.updateById(orderPrivateCar); |
| | | |
| | | //添加已收入明细 |
| | | incomeService.saveData(2, orderPrivateCar.getDriverId(), 6, orderPrivateCar.getId(), 1, query.getAmount()); |
| | | Driver driver = driverService.selectById(orderPrivateCar.getDriverId()); |
| | | driver.setBusinessMoney(new BigDecimal(null != driver.getBusinessMoney() ? driver.getBusinessMoney() : 0).add(new BigDecimal(query.getAmount())).setScale(2, BigDecimal.ROUND_HALF_EVEN).doubleValue()); |
| | | driver.setLaveBusinessMoney(new BigDecimal(null != driver.getLaveBusinessMoney() ? driver.getLaveBusinessMoney() : 0).add(new BigDecimal(query.getAmount())).setScale(2, BigDecimal.ROUND_HALF_EVEN).doubleValue()); |
| | | driver.setBalance(new BigDecimal(null != driver.getBalance() ? driver.getBalance() : 0).add(new BigDecimal(query.getAmount())).setScale(2, BigDecimal.ROUND_HALF_EVEN).doubleValue()); |
| | | driverService.updateById(driver); |
| | | systemNoticeService.addSystemNotice(1, "您已使用" + (payType == 1 ? "微信" : "支付宝") + "成功完成感谢费支付,谢谢使用!", userInfo.getId(), 1); |
| | | public List<SmartScreenOrderVo> querySmartScreenOrder(String deviceCode, String lonLat) throws Exception { |
| | | List<OrderTaxi> list = orderTaxiService.selectList(new EntityWrapper<OrderTaxi>().eq("orderSource", 7).eq("deviceCode", deviceCode).eq("isDelete", 1).in("state", Arrays.asList(1, 2, 3, 4))); |
| | | List<SmartScreenOrderVo> orderVos = new ArrayList<>(); |
| | | SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); |
| | | for (OrderTaxi orderTaxi : list) { |
| | | SmartScreenOrderVo smartScreenOrderVo = new SmartScreenOrderVo(); |
| | | smartScreenOrderVo.setId(orderTaxi.getId()); |
| | | smartScreenOrderVo.setUserPhone(orderTaxi.getPassengersPhone()); |
| | | smartScreenOrderVo.setInsertTime(sdf.format(orderTaxi.getInsertTime())); |
| | | smartScreenOrderVo.setDistance(0D); |
| | | smartScreenOrderVo.setMinute(0); |
| | | if(null != orderTaxi.getDriverId()){ |
| | | Driver driver = driverService.selectById(orderTaxi.getDriverId()); |
| | | Car car = carMapper.selectById(driver.getCarId()); |
| | | smartScreenOrderVo.setCarLicensePlate(car.getCarLicensePlate()); |
| | | smartScreenOrderVo.setDriverPhone(driver.getPhone()); |
| | | String value = redisUtil.getValue("DRIVER" + driver.getId());//lon + "," + lat |
| | | if(ToolUtil.isNotEmpty(value)){ |
| | | Map<String, String> distance = gdMapElectricFenceUtil.getDistance(value, orderTaxi.getStartLon() + "," + orderTaxi.getStartLat(), 1); |
| | | if(null != distance){ |
| | | BigDecimal bigDecimal = new BigDecimal(distance.get("distance")).divide(new BigDecimal(1000)).setScale(2, BigDecimal.ROUND_HALF_EVEN); |
| | | int duration = Double.valueOf(Integer.valueOf(distance.get("duration")) / 60).intValue(); |
| | | smartScreenOrderVo.setDistance(bigDecimal.doubleValue()); |
| | | smartScreenOrderVo.setMinute(duration); |
| | | } |
| | | } |
| | | |
| | | @Override |
| | | public List<Map<String, Object>> queryOrderInfo2(Integer orderId, Integer state, String lon, String lat) { |
| | | return this.baseMapper.queryOrderInfo2(orderId,state,lon,lat); |
| | | } |
| | | smartScreenOrderVo.setStatus(orderTaxi.getState()); |
| | | smartScreenOrderVo.setArrivalTime(null == orderTaxi.getArriveTime() ? "" : sdf.format(orderTaxi.getArriveTime())); |
| | | orderVos.add(smartScreenOrderVo); |
| | | } |
| | | return orderVos; |
| | | } |
| | | } |