yanghb
2023-04-21 75a2623173bcc4a235aa1f99f7ef28519186160b
UserTravel/guns-admin/src/main/java/com/stylefeng/guns/modular/taxi/service/impl/OrderTaxiServiceImpl.java
@@ -6,12 +6,8 @@
import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.service.impl.ServiceImpl;
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.model.OrderLogistics;
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;
@@ -19,7 +15,9 @@
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.warpper.BaseWarpper;
import com.stylefeng.guns.modular.system.warpper.EndPushWarpper;
import com.stylefeng.guns.modular.system.warpper.OrderServerWarpper;
import com.stylefeng.guns.modular.taxi.dao.OrderTaxiMapper;
import com.stylefeng.guns.modular.taxi.model.OrderTaxi;
import com.stylefeng.guns.modular.taxi.model.PaymentRecord;
@@ -42,10 +40,10 @@
import javax.annotation.Resource;
import java.math.BigDecimal;
import java.math.MathContext;
import java.math.RoundingMode;
import java.text.SimpleDateFormat;
import java.util.*;
import java.util.stream.Collectors;
@Service
@Transactional(isolation = Isolation.READ_UNCOMMITTED, propagation = Propagation.REQUIRED, rollbackFor = Exception.class)
@@ -156,30 +154,6 @@
    @Autowired
    private IOrderCrossCityService orderCrossCityService;
    @Resource
    private OrderCrossCityMapper orderCrossCityMapper;
    @Autowired
    private IOrderLogisticsService orderLogisticsService;
    @Autowired
    private IOpenCityService openCityService;
    @Autowired
    private ITaxiCardService taxiCardService;
    @Autowired
    private ITaxiCardPaymentService taxiCardPaymentService;
    @Autowired
    private IUserUserService userUserService;
    @Autowired
    private IUserTaxiCardService userTaxiCardService;
    @Autowired
    private IRegionService regionService;
    public static List<Integer> orderIds = new ArrayList<>();
@@ -218,39 +192,37 @@
        /**
         * 1.出租车、专车、跨城有待支付的订单不能叫车
         * 2.小件物流有未完成的订单可以下跨城、专车、出租车
         * 3.出租车、专车、跨城有预约单可以下即时单
         * 1.下了即时单就不能下预约单和即时单
         * 2.下了预约单和再下一张即时单不能再下预约单
         */
        List<OrderPrivateCar> orderPrivateCars = orderPrivateCarMapper.queryByState(uid, null, 1, 7, 12);
        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){
        List<OrderPrivateCar> orderPrivateCars = orderPrivateCarMapper.queryByState(uid, 1, 1, 1, 2, 3, 4, 5, 6, 7, 11);
        if(orderPrivateCars.size() > 0){
            return ResultUtil.error("有未完成的订单");
        }
        if(orderTaxi.getOrderType() == 1){
            orderPrivateCars = orderPrivateCarMapper.queryByState(uid, 1, 1, 1, 2, 3, 4, 5, 6, 7, 11, 12);
            if(orderPrivateCars.size() > 0){
                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("有未完成的订单");
            }
        list = orderTaxiMapper.queryByState_(uid, 2, 1, 1, 2, 3, 4, 5, 6, 11);
        if(list.size() > 0 && orderTaxi.getOrderType() == 2){
            return ResultUtil.error("有未完成的订单");
        }
        orderPrivateCars = orderPrivateCarMapper.queryByState(uid, 2, 1, 1, 2, 3, 4, 5, 6, 7, 11);
        if(orderPrivateCars.size() > 0 && orderTaxi.getOrderType() == 2){
            return ResultUtil.error("有未完成的订单");
        }
        orderTaxi.setOrderNum(this.getOrderNum());
        Map<String, String> geocode = gdMapGeocodingUtil.geocode(String.valueOf(orderTaxi.getPlacementLon()), String.valueOf(orderTaxi.getPlacementLat()));
        orderTaxi.setPlacementAddress(geocode.get("address"));
        orderTaxi.setStartAddress(orderTaxi.getStartAddress().replaceAll("& #40;", "\\("));//特殊字符转义
        orderTaxi.setStartAddress(orderTaxi.getStartAddress().replaceAll("& #41;", "\\)"));
        orderTaxi.setEndAddress(orderTaxi.getEndAddress().replaceAll("& #40;", "\\("));
        orderTaxi.setEndAddress(orderTaxi.getEndAddress().replaceAll("& #41;", "\\)"));
        if(ToolUtil.isNotEmpty(orderTaxi.getEndAddress())){
            orderTaxi.setEndAddress(orderTaxi.getEndAddress().replaceAll("& #40;", "\\("));
            orderTaxi.setEndAddress(orderTaxi.getEndAddress().replaceAll("& #41;", "\\)"));
        }
        orderTaxi.setUserId(uid);
        orderTaxi.setMileage(0D);
        orderTaxi.setOrderMoney(0D);
@@ -300,14 +272,15 @@
            orderTaxi.setCarId(driver.getCarId());
            orderTaxi.setState(2);//待出发
            orderTaxi.setSnatchOrderTime(new Date());
            //调用高德创建轨迹
            String s = gdFalconUtil.selectTerminal(driver.getPhone());
            String track = gdFalconUtil.createTrack(s);
            orderTaxi.setTrackId(track);
//            //调用高德创建轨迹
//            String s = gdFalconUtil.selectTerminal(driver.getPhone());
//            String track = gdFalconUtil.createTrack(s);
//            orderTaxi.setTrackId(track);
//
            //调用移动的小号接口
            Map<String, String> map = chinaMobileUtil.midAxbBindSend(orderTaxi.getPassengersPhone(), driver.getPhone(), (System.currentTimeMillis() + 86400000));
            Map<String, String> geocode1 = gdMapGeocodingUtil.geocode(orderTaxi.getStartLon().toString(), orderTaxi.getStartLat().toString());
            Region region = regionMapper.query(geocode1.get("districtCode"));
            Map<String, String> map = chinaMobileUtil.midAxbBindSend(orderTaxi.getPassengersPhone(), driver.getPhone(), Integer.valueOf(region.getCitycode().substring(1)));
            if(String.valueOf(map.get("code")).equals("200")){
                orderTaxi.setTelX(map.get("telX"));
                orderTaxi.setBindId(map.get("bindId"));
@@ -440,14 +413,14 @@
        }
        OrderTaxi orderTaxi = this.selectById(id);
        if(null == uid){
            uid = orderTaxi.getUserId();
        }
        Integer integer = null;
        if(null == orderTaxi){
            return ResultUtil.error("取消订单失败,订单信息有误");
        }
//        if(orderTaxi.getState() == 4){
//            return ResultUtil.error("司机已到达预约点,取消会产生一定的费用");
//        }
        if(orderTaxi.getState() >= 5 && orderTaxi.getState() != 11){
        if(orderTaxi.getState() > 5 && orderTaxi.getState() != 11){
            return ResultUtil.error("取消订单失败,不合法的操作");
        }
        if(null == orderTaxi.getDriverId()){//没有接单的情况
@@ -522,13 +495,13 @@
        OrderTaxi orderTaxi = this.selectById(id);
        Integer uid = orderTaxi.getUserId();
        UserInfo userInfo = userInfoService.selectById(uid);
        ResultUtil resultUtil = ResultUtil.success(new Object());
        ResultUtil resultUtil = ResultUtil.success();
        if(null == orderTaxi){
            return ResultUtil.error("取消订单失败,订单信息有误", "");
            return ResultUtil.error("取消订单失败,订单信息有误");
        }
        if(orderTaxi.getState() != 12){
            return ResultUtil.error("取消订单失败,不合法的操作", "");
            return ResultUtil.error("取消订单失败,不合法的操作");
        }
        OrderCancel orderCancel = null;
        if(null == cancleId){
@@ -539,56 +512,42 @@
        CancleOrder query = cancleOrderService.query(orderTaxi.getOrderType(), 2, orderTaxi.getCompanyId());
        if(null != query){
            SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMddHHmmssSSS");
            String out_trade_no = sdf.format(new Date()) + 2 + id;
            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{
                String appletsOpenId = "";
                String tradeType = "APP";
                if(type == 3){
                    appletsOpenId = userInfo.getAppletsOpenId();
                    tradeType = "JSAPI";
                    if(ToolUtil.isEmpty(userInfo.getAppletsOpenId())){
                        return ResultUtil.error("支付异常,请重新授权登录小程序");
                    }
                }
                orderCancel.setPayType(1);
                orderCancelService.updateById(orderCancel);
                String app = type == 1 ? "APP" : "JSAPI";
                resultUtil = payMoneyUtil.weixinpay("订单取消", "", id + "_2_" + UUIDUtil.getRandomCode(5), query.getMoney().toString(), "/base/wxCancelOrderTaxi", app, userInfo.getAppletsOpenId());
                paymentRecordService.saveData(1, orderTaxi.getUserId(), 1, id, 2, 1, query.getMoney(), "", 1);//添加预支付数据
//                Map<String, String> map = icbcPayUtil.placeAnOrder(id + ",2", 9, 5, uid.toString(), "订单取消", query.getMoney(), callbackPath + "/base/wxCancelOrderTaxi", "", type, appletsOpenId);
//                if(map.get("code").equals("200")){
//                    paymentRecordService.saveData(1, orderTaxi.getUserId(), 1, id, 2, 1, query.getMoney(), map.get("order_id"), 1);//添加预支付数据
//                    resultUtil = ResultUtil.success(map.get("data"));
//                }else{
//                    resultUtil = ResultUtil.error(map.get("msg"), "");
//                }
                resultUtil = payMoneyUtil.weixinpay("订单取消", "", out_trade_no,  query.getMoney().toString(), callbackPath + "/base/wxCancelOrderTaxi", tradeType, appletsOpenId);
                if(resultUtil.getCode() == 200){
                    paymentRecordService.saveData(1, orderTaxi.getUserId(), 1, id, 2, 1, query.getMoney(), "", 1);//添加预支付数据
                }
            }
            if(payType == 2){//支付宝支付
                orderCancel.setPayType(2);
                orderCancelService.updateById(orderCancel);
                resultUtil = payMoneyUtil.alipay("订单取消", "订单取消", "", id + "_2_" + UUIDUtil.getRandomCode(5), query.getMoney().toString(), "/base/aliCancelOrderTaxi");
                paymentRecordService.saveData(1, orderTaxi.getUserId(), 1, id, 2, 2, query.getMoney(), "", 1);//添加预支付数据
//                Map<String, String> map = icbcPayUtil.placeAnOrder(id + ",2", 10, 5, uid.toString(), "订单取消", query.getMoney(), callbackPath + "/base/aliCancelOrderTaxi", "", type, null);
//                if(map.get("code").equals("200")){
//                    paymentRecordService.saveData(1, orderTaxi.getUserId(), 1, id, 2, 2, query.getMoney(), map.get("order_id"), 1);//添加预支付数据
//                    resultUtil = ResultUtil.success(map.get("data"));
//                }else{
//                    resultUtil = ResultUtil.error(map.get("msg"), "");
//                }
                resultUtil = payMoneyUtil.alipay("取消订单支付", "取消订单", out_trade_no, query.getMoney().toString(), callbackPath + "/base/aliCancelOrderTaxi");
                if(resultUtil.getCode() == 200){
                    paymentRecordService.saveData(1, orderTaxi.getUserId(), 1, id, 2, 2, query.getMoney(), "", 1);//添加预支付数据
                }
            }
            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, 2, id);
                transactionDetailsService.saveData(uid, "取消订单", query.getMoney(), 2, 1, 1, 2, id);
                userInfoService.updateById(userInfo);
                //解除小号绑定
                if(orderTaxi.getBindId() != null){
                    chinaMobileUtil.midAxbUnBindSend(orderTaxi.getBindId(), orderTaxi.getTelX(), (System.currentTimeMillis() + 600000));
                    chinaMobileUtil.midAxbUnBindSend(orderTaxi.getBindId());
                }
                orderTaxi.setState(10);
@@ -661,206 +620,6 @@
        return map;
    }
    @Override
    public PreferentialDataVo queryBalance1(Integer orderId, Integer uid) throws Exception {
        UserInfo userInfo = userInfoService.selectById(uid);
        PreferentialDataVo preferentialDataVo = new PreferentialDataVo();
        preferentialDataVo.setBalance(userInfo.getBalance());
        OrderTaxi orderTaxi = this.selectById(orderId);
        //获取优惠券中最优数据
        List<UserCouponRecord> list = userCouponRecordService.selectList(new EntityWrapper<UserCouponRecord>().eq("companyId", orderTaxi.getCompanyId()).eq("state", 1).in("couponUseType", Arrays.asList(0, 2)).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(orderTaxi.getOrderMoney().compareTo(userCouponRecord.getFullMoney()) >= 0 && price.compareTo(userCouponRecord.getMoney()) < 0){
                    price = userCouponRecord.getMoney();
                    id = userCouponRecord.getId();
                    type = 1;
                }
            }
        }
        //获取打车卡中最优数
        Map<String, String> geocode = gdMapGeocodingUtil.geocode(orderTaxi.getStartLon().toString(), orderTaxi.getStartLat().toString());
        CompanyCity companyCity = companyCityService.selectOne(new EntityWrapper<CompanyCity>().eq("companyId", orderTaxi.getCompanyId()).eq("areaCode", geocode.get("districtCode")).eq("state", 1));
        if(null == companyCity){
            companyCity = companyCityService.selectOne(new EntityWrapper<CompanyCity>().eq("companyId", orderTaxi.getCompanyId()).eq("cityCode", geocode.get("cityCode")).eq("state", 1));
        }
        if(null == companyCity){
            companyCity = companyCityService.selectOne(new EntityWrapper<CompanyCity>().eq("companyId", orderTaxi.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(orderTaxi, 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(orderTaxi, 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 orderTaxi
     * @param price
     * @param id
     * @param type
     * @param userTaxiCards
     * @return
     */
    public Map<String, Object> getOptimalTaxiCards(OrderTaxi orderTaxi, 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(2)){
                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(orderTaxi.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(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(orderTaxi.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(orderTaxi.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;
    }
    /**
     * 获取优惠券列表
@@ -878,238 +637,6 @@
    }
    @Override
    public List<CouponsListVo> queryCouponList(Integer orderId, Integer uid, Integer pageNum, Integer size) throws Exception {
        pageNum = (pageNum - 1) * size;
        OrderTaxi orderTaxi = this.selectById(orderId);
        List<CouponsListVo> rows = new ArrayList<>();
        List<UserCouponRecord> list = userCouponRecordService.selectList(new EntityWrapper<UserCouponRecord>().eq("companyId", orderTaxi.getCompanyId())
                .eq("state", 1).in("couponUseType", Arrays.asList(0, 2)).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(orderTaxi.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(orderTaxi.getStartLon().toString(), orderTaxi.getStartLat().toString());
        CompanyCity companyCity = companyCityService.selectOne(new EntityWrapper<CompanyCity>().eq("companyId", orderTaxi.getCompanyId()).eq("areaCode", geocode.get("districtCode")).eq("state", 1));
        if(null == companyCity){
            companyCity = companyCityService.selectOne(new EntityWrapper<CompanyCity>().eq("companyId", orderTaxi.getCompanyId()).eq("cityCode", geocode.get("cityCode")).eq("state", 1));
        }
        if(null == companyCity){
            companyCity = companyCityService.selectOne(new EntityWrapper<CompanyCity>().eq("companyId", orderTaxi.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.setTaxiCardType(t.getType());
                couponsListVo.setTime(sdf.format(t.getEndTime()));
                couponsListVo.setState(1);
                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(2)){
                    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(orderTaxi.getOrderMoney().compareTo(m) >= 0){
                            couponsListVo.setMoney(j);
                            couponsListVo.setFullMoney(m);
                            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.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;
    }
    /**
     * 订单完成支付订单操作
     * @param payType   1=微信,2=支付宝,3=余额
@@ -1121,15 +648,15 @@
    public ResultUtil payTaxiOrder(Integer payType, Integer orderId, Integer couponId, Integer type) throws Exception {
        OrderTaxi orderTaxi = this.selectById(orderId);
        if(orderTaxi.getState() == 8 || orderTaxi.getState() == 9){
            return ResultUtil.error("订单已完成支付,不允许重复支付", "");
            return ResultUtil.error("订单已完成支付,不允许重复支付");
        }
        if(orderTaxi.getState() != 7){
            return ResultUtil.error("订单不在待支付状态,不允许支付", "");
            return ResultUtil.error("订单不在待支付状态,不允许支付");
        }
        Integer uid = orderTaxi.getUserId();
        Double orderMoney = orderTaxi.getOrderMoney();
        UserInfo userInfo = userInfoService.selectById(uid);
        ResultUtil resultUtil = ResultUtil.success(new Object());
        ResultUtil resultUtil = ResultUtil.success();
        orderTaxi.setCouponMoney(0D);//初始化历史数据
        orderTaxi.setCouponId(null);
@@ -1138,19 +665,19 @@
        if(null != couponId){
            userCouponRecord = userCouponRecordService.selectById(couponId);
            if(userCouponRecord.getCompanyId() != orderTaxi.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() != 2){
                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();
            orderTaxi.setCouponMoney(userCouponRecord.getMoney());
@@ -1178,18 +705,33 @@
            }
        }
        SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMddHHmmssSSS");
        String out_trade_no = sdf.format(new Date()) + 2 + orderTaxi.getId();
        if(payType == 1){//微信支付
            String app = type == 1 ? "APP" : "JSAPI";
            resultUtil = payMoneyUtil.weixinpay("完成订单", "", orderId + "_2_" + UUIDUtil.getRandomCode(5), orderMoney.toString(), "/base/wxPayOrderTaxi", app, userInfo.getAppletsOpenId());
            paymentRecordService.saveData(1, orderTaxi.getUserId(), 1, orderId, 2, 1, orderMoney, "", 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, orderMoney.toString(), callbackPath + "/base/wxPayOrderTaxi", tradeType, appletsOpenId);
            if(resultUtil.getCode() == 200){
                paymentRecordService.saveData(1, orderTaxi.getUserId(), 1, orderId, 2, 1, orderMoney, "", 1);//添加预支付数据
            }
        }
        if(payType == 2){//支付宝支付
            resultUtil = payMoneyUtil.alipay("完成订单", "完成订单", "", orderId + "_2_" + UUIDUtil.getRandomCode(5), orderMoney.toString(), "/base/aliPayOrderTaxi");
            paymentRecordService.saveData(1, orderTaxi.getUserId(), 1, orderId, 2, 2, orderMoney, "", 1);//添加预支付数据
            resultUtil = payMoneyUtil.alipay("订单完成支付", "支付订单", out_trade_no, orderMoney.toString(), callbackPath + "/base/aliPayOrderTaxi");
            if(resultUtil.getCode() == 200){
                paymentRecordService.saveData(1, orderTaxi.getUserId(), 1, orderId, 2, 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());
@@ -1198,7 +740,7 @@
            userInfo.setIntegral(userInfo.getIntegral() + (orderMoney.intValue() * query1.getIntegral()));//积分
            //添加交易明细
            transactionDetailsService.saveData(uid, "出租车", orderMoney, 2, 1, 1, 2, orderId);
            transactionDetailsService.saveData(uid, "完成订单", orderMoney, 2, 1, 1, 2, orderId);
            userInfoService.updateById(userInfo);
            orderTaxi.setState(8);
@@ -1266,275 +808,6 @@
        return resultUtil;
    }
    @Override
    public ResultUtil payTaxiOrder1(Integer payType, Integer orderId, Integer objectId, Integer objectType, Integer type) throws Exception {
        OrderTaxi orderTaxi = this.selectById(orderId);
        if(orderTaxi.getState() == 8 || orderTaxi.getState() == 9){
            return ResultUtil.error("订单已完成支付,不允许重复支付", "");
        }
        if(orderTaxi.getState() != 7){
            return ResultUtil.error("订单不在待支付状态,不允许支付", "");
        }
        Integer uid = orderTaxi.getUserId();
        Double orderMoney = orderTaxi.getOrderMoney();
        UserInfo userInfo = userInfoService.selectById(uid);
        ResultUtil resultUtil = ResultUtil.success(new Object());
        orderTaxi.setCouponMoney(0D);//初始化历史数据
        orderTaxi.setCouponId(null);
        //计算优惠券
        UserCouponRecord userCouponRecord = null;
        if(null != objectId && 1 == objectType){
            userCouponRecord = userCouponRecordService.selectById(objectId);
            if(userCouponRecord.getCompanyId() != orderTaxi.getCompanyId()){
                return ResultUtil.error("优惠券不能用于此订单", "");
            }
            if(userCouponRecord.getState() == 2){
                return ResultUtil.error("优惠券已使用", "");
            }
            if(userCouponRecord.getState() == 3){
                return ResultUtil.error("优惠券已过期", "");
            }
            if(userCouponRecord.getCouponUseType() != 0 && userCouponRecord.getCouponUseType() != 2){
                return ResultUtil.error("优惠券不能用于此类型订单", "");
            }
            if(userCouponRecord.getCouponType() == 2 && orderMoney.compareTo(userCouponRecord.getFullMoney()) < 0){
                return ResultUtil.error("优惠券不能用于此订单", "");
            }
            orderMoney = orderMoney - userCouponRecord.getMoney();
            orderTaxi.setCouponMoney(userCouponRecord.getMoney());
            orderTaxi.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() != orderTaxi.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(2)){
                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(orderTaxi.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(orderTaxi.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(orderTaxi.getOrderMoney()).multiply(new BigDecimal((10 - discount) / 10)).setScale(2, RoundingMode.HALF_EVEN).doubleValue();
                        break;
                    }
                }
            }
            orderMoney = orderMoney - yh;
            orderTaxi.setTaxiCardId(userTaxiCard.getTaxiCardId());
            orderTaxi.setUserTaxiCardId(objectId);
            orderTaxi.setDiscountAmount(yh);
        }
        //计算红包
        UserRedPacketRecord query = userRedPacketRecordService.query(uid, orderTaxi.getCompanyId(), 1, 2, orderMoney);
        if(null != query && orderMoney.compareTo(query.getMoney()) > 0){
            orderMoney = orderMoney - query.getMoney();
            orderTaxi.setRedPacketMoney(query.getMoney());
            orderTaxi.setRedPacketId(query.getId());
        }
        //计算折扣
        UserActivityDiscount1 query2 = userActivityDiscount1Mapper.query(orderTaxi.getCompanyId());
        if(null != query2){
            Double taxi = query2.getTaxi();
            orderTaxi.setDiscount(taxi);
            double v = new BigDecimal(orderMoney).multiply(new BigDecimal(taxi / 10)).setScale(2, BigDecimal.ROUND_HALF_EVEN).doubleValue();
            if(orderMoney.compareTo(v) > 0){
                orderTaxi.setDiscountMoney(orderMoney - v);
                orderTaxi.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 + "_2_" + UUIDUtil.getRandomCode(5), orderMoney.toString(), "/base/wxPayOrderTaxi", app, userInfo.getAppletsOpenId());
            paymentRecordService.saveData(1, orderTaxi.getUserId(), 1, orderId, 2, 1, orderMoney, "", 1);//添加预支付数据
        }
        if(payType == 2){//支付宝支付
            if(orderMoney == 0){
                return ResultUtil.error("请使用余额支付");
            }
            resultUtil = payMoneyUtil.alipay("完成订单", "完成订单", "", orderId + "_2_" + UUIDUtil.getRandomCode(5), orderMoney.toString(), "/base/aliPayOrderTaxi");
            paymentRecordService.saveData(1, orderTaxi.getUserId(), 1, orderId, 2, 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(orderTaxi.getCompanyId());
            if(null != query1){
                userInfo.setIntegral(userInfo.getIntegral() + (orderMoney.intValue() * query1.getIntegral()));//积分
            }
            //添加交易明细
            transactionDetailsService.saveData(uid, "出租车", orderMoney, 2, 1, 1, 2, orderId);
            userInfoService.updateById(userInfo);
            orderTaxi.setState(8);
            orderTaxi.setPayType(3);
            orderTaxi.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(orderTaxi.getCompanyId());
            Double taxi = company.getTaxiMoney();
            BigDecimal d = null;//企业收入
            BigDecimal c = null;//司机收入
            // TODO: 2022/3/19  抽成按照订单金额计算,优先保证司机的收入,用户支付金额不够,则在平台收入中补贴司机收入
            //例如:订单金额10元,优惠3元,司机收入比例80%,平台收入比例20%。
            //司机收入:10 * 0.8 = 8
            //平台收入:7 - 8 = -1
            if(company.getIsTaxiFixedOrProportional() == 2){//固定
                d = new BigDecimal(taxi.compareTo(orderTaxi.getOrderMoney()) > 0 ? orderTaxi.getOrderMoney() : taxi);
                c = new BigDecimal(orderTaxi.getOrderMoney()).subtract(d);
            }
            if(company.getIsTaxiFixedOrProportional() == 1){//比例
                c = new BigDecimal(orderTaxi.getOrderMoney()).multiply(new BigDecimal(1 - (taxi / 100))).setScale(2, BigDecimal.ROUND_HALF_EVEN);
                d = new BigDecimal(orderTaxi.getPayMoney()).subtract(c).setScale(2, BigDecimal.ROUND_HALF_EVEN);
            }
            incomeService.saveData(1, orderTaxi.getCompanyId(), 2, orderTaxi.getId(), 2, d.doubleValue());
            incomeService.saveData(2, orderTaxi.getDriverId(), 2, orderTaxi.getId(), 2, c.doubleValue());
            Driver driver = driverService.selectById(orderTaxi.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, orderTaxi.getUserId(), orderTaxi.getId(), 2, orderTaxi.getState(), 0);
                    pushUtil.pushOrderState(2, orderTaxi.getDriverId(), orderTaxi.getId(), 2, orderTaxi.getState(), 0);
                }
            }).start();
            //用户付款后,删除限制司机6分钟不能接单的标识
            String vehicle = redisUtil.getValue("VEHICLE");
            if(ToolUtil.isNotEmpty(vehicle)){
                JSONArray jsonArray = JSON.parseArray(vehicle);
                for(int i = 0; i < jsonArray.size(); i++){
                    if(jsonArray.getInteger(i).compareTo(orderTaxi.getDriverId()) == 0){
                        jsonArray.remove(i);
                        break;
                    }
                }
                redisUtil.setStrValue("VEHICLE", jsonArray.toJSONString());
            }
            systemNoticeService.addSystemNotice(1, "您已使用余额成功完成出行订单支付,谢谢使用!", uid, 1);
        }
        this.updateAllColumnById(orderTaxi);
        return resultUtil;
    }
    /**
     * 手动完成订单操作
@@ -1722,8 +995,8 @@
        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(orderTaxi.getId());
@@ -1745,8 +1018,8 @@
            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");
@@ -1876,9 +1149,9 @@
    public void payOrderTaxiCallback(Integer id, String order_id, Integer type) throws Exception {
        OrderTaxi orderTaxi = this.selectById(id);
        PaymentRecord query = paymentRecordService.query(1, orderTaxi.getUserId(), 1, Integer.valueOf(id), 2, type, 1);
        if(null != query && query.getState() == 1){
        if(null != query){
            //添加交易明细
            transactionDetailsService.saveData(orderTaxi.getUserId(), "出租车", query.getAmount(), 2, 1, 1, 2, query.getOrderId());
            transactionDetailsService.saveData(orderTaxi.getUserId(), "完成订单", query.getAmount(), 2, 1, 1, 2, query.getOrderId());
            orderTaxi.setState(8);
            orderTaxi.setPayType(type);
            orderTaxi.setPayMoney(query.getAmount());
@@ -1895,15 +1168,6 @@
                userCouponRecord.setState(2);
                userCouponRecord.setEndTime(new Date());
                userCouponRecordService.updateById(userCouponRecord);
            }
            if(null != orderTaxi.getUserTaxiCardId()){
                UserTaxiCard userTaxiCard = userTaxiCardService.selectById(orderTaxi.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 != orderTaxi.getRedPacketId()){
                UserRedPacketRecord userRedPacketRecord = userRedPacketRecordService.selectById(orderTaxi.getRedPacketId());
@@ -1922,17 +1186,13 @@
            Double taxi = company.getTaxiMoney();
            BigDecimal d = null;//企业收入
            BigDecimal c = null;//司机收入
            // TODO: 2022/3/19  抽成按照订单金额计算,优先保证司机的收入,用户支付金额不够,则在平台收入中补贴司机收入
            //例如:订单金额10元,优惠3元,司机收入比例80%,平台收入比例20%。
            //司机收入:10 * 0.8 = 8
            //平台收入:7 - 8 = -1
            if(company.getIsTaxiFixedOrProportional() == 2){//固定
                d = new BigDecimal(taxi.compareTo(orderTaxi.getOrderMoney()) > 0 ? orderTaxi.getOrderMoney() : taxi);
                d = new BigDecimal(taxi);
                c = new BigDecimal(orderTaxi.getOrderMoney()).subtract(d).setScale(2, BigDecimal.ROUND_HALF_EVEN);
            }
            if(company.getIsTaxiFixedOrProportional() == 1){//比例
                c = new BigDecimal(orderTaxi.getOrderMoney()).multiply(new BigDecimal(1 - (taxi / 100))).setScale(2, BigDecimal.ROUND_HALF_EVEN);
                d = new BigDecimal(orderTaxi.getPayMoney()).subtract(c).setScale(2, BigDecimal.ROUND_HALF_EVEN);
                d = new BigDecimal(orderTaxi.getTravelMoney()).multiply(new BigDecimal(taxi).divide(new BigDecimal(100))).setScale(2, BigDecimal.ROUND_HALF_EVEN);
                c = new BigDecimal(orderTaxi.getOrderMoney()).subtract(d).setScale(2, BigDecimal.ROUND_HALF_EVEN);
            }
            incomeService.saveData(1, orderTaxi.getCompanyId(), 2, orderTaxi.getId(), 2, d.doubleValue());
            incomeService.saveData(2, orderTaxi.getDriverId(), 2, orderTaxi.getId(), 2, c.doubleValue());
@@ -1985,11 +1245,11 @@
        PaymentRecord query = paymentRecordService.query(1, orderTaxi.getUserId(), 1, Integer.valueOf(id), 2, type, 1);
        if(null != query){
            //添加交易明细
            transactionDetailsService.saveData(orderTaxi.getUserId(), "出租车取消订单", query.getAmount(), 2, 1, 1, 2, query.getOrderId());
            transactionDetailsService.saveData(orderTaxi.getUserId(), "取消订单", query.getAmount(), 2, 1, 1, 2, query.getOrderId());
            orderTaxi.setState(10);
            //解除小号绑定
            if(orderTaxi.getBindId() != null){
                chinaMobileUtil.midAxbUnBindSend(orderTaxi.getBindId(), orderTaxi.getTelX(), (System.currentTimeMillis() + 600000));
                chinaMobileUtil.midAxbUnBindSend(orderTaxi.getBindId());
            }
            orderTaxi.setBindId("");
            orderTaxi.setTelX("");
@@ -2051,7 +1311,6 @@
                        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){//开始进行推送
                                //查询是否在限制推单范围内
@@ -2091,77 +1350,5 @@
    public synchronized String getOrderNum() throws Exception{
        int size = this.selectCount(null);
        return "TAXI" + String.valueOf(1000000 + size + 1).substring(1);
    }
    @Override
    public ResultUtil payThankYouFee(Integer uid, Integer orderId, Double money, Integer payType, Integer type) throws Exception {
        UserInfo userInfo = userInfoService.selectById(uid);
        OrderTaxi orderTaxi = this.selectById(orderId);
        ResultUtil resultUtil = ResultUtil.success();
        if(payType == 1){//微信支付
            String app = type == 1 ? "APP" : "JSAPI";
            resultUtil = payMoneyUtil.weixinpay("感谢费", "", orderId + "_2_" + UUIDUtil.getRandomCode(5), money.toString(), "/base/wxPayThankYouFee", app, userInfo.getAppletsOpenId());
            paymentRecordService.saveData(3, uid, 1, orderId, 2, 1, money, "", 1);//添加预支付数据
        }
        if(payType == 2){//支付宝支付
            resultUtil = payMoneyUtil.alipay("感谢费", "感谢费", "", orderId + "_2_" + UUIDUtil.getRandomCode(5), money.toString(), "/base/aliPayThankYouFee");
            paymentRecordService.saveData(1, uid, 1, orderId, 2, 2, money, "", 1);//添加预支付数据
        }
        if(payType == 3){//余额支付
            if(userInfo.getBalance() == null || userInfo.getBalance() < money){
                return ResultUtil.error("余额不足,无法完成支付", "");
            }
            userInfo.setBalance(new BigDecimal(userInfo.getBalance()).subtract(new BigDecimal(money)).setScale(2, BigDecimal.ROUND_HALF_EVEN).doubleValue());
            SysIntegral query1 = sysIntegralMapper.query(orderTaxi.getCompanyId());
            userInfo.setIntegral(userInfo.getIntegral() + (money.intValue() * query1.getIntegral()));//积分
            //添加交易明细
            transactionDetailsService.saveData(uid, "出租车-感谢费", money, 2, 1, 1, 2, orderId);
            userInfoService.updateById(userInfo);
            orderTaxi.setThankYouFee(money);
            this.updateById(orderTaxi);
            //添加已收入明细
            incomeService.saveData(2, orderTaxi.getDriverId(), 6, orderTaxi.getId(), 2, money);
            Driver driver = driverService.selectById(orderTaxi.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);
        }
        return resultUtil;
    }
    @Override
    public void payThankYouFeeCallback(Integer orderId, String order_id, Integer payType) throws Exception {
        OrderTaxi orderTaxi = this.selectById(orderId);
        UserInfo userInfo = userInfoService.selectById(orderTaxi.getUserId());
        PaymentRecord query = paymentRecordService.query(3, userInfo.getId(), 1, orderId, 2, payType, 1);
        query.setState(2);
        query.setCode(order_id);
        paymentRecordService.updateById(query);
        SysIntegral query1 = sysIntegralMapper.query(orderTaxi.getCompanyId());
        userInfo.setIntegral(userInfo.getIntegral() + (query.getAmount().intValue() * query1.getIntegral()));//积分
        //添加交易明细
        transactionDetailsService.saveData(userInfo.getId(), "出租车-感谢费", query.getAmount(), 2, 1, 1, 2, orderId);
        userInfoService.updateById(userInfo);
        orderTaxi.setThankYouFee(query.getAmount());
        this.updateById(orderTaxi);
        //添加已收入明细
        incomeService.saveData(2, orderTaxi.getDriverId(), 6, orderTaxi.getId(), 2, query.getAmount());
        Driver driver = driverService.selectById(orderTaxi.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);
    }
}