Pu Zhibing
2025-04-17 f4e12a183070e9fc1db174dfb7f1c9a59f7763a1
UserOKTravel/guns-admin/src/main/java/com/stylefeng/guns/modular/taxi/service/impl/OrderTaxiServiceImpl.java
@@ -5,6 +5,7 @@
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.service.impl.ServiceImpl;
import com.stylefeng.guns.core.util.GpsCoordinateUtils;
import com.stylefeng.guns.core.util.ToolUtil;
import com.stylefeng.guns.modular.crossCity.server.IOrderCrossCityService;
import com.stylefeng.guns.modular.crossCity.server.impl.OrderCrossCityServiceImpl;
@@ -20,12 +21,15 @@
import com.stylefeng.guns.modular.system.warpper.OrderServerWarpper;
import com.stylefeng.guns.modular.taxi.dao.OrderTaxiMapper;
import com.stylefeng.guns.modular.taxi.dao.TPhoneMapper;
import com.stylefeng.guns.modular.taxi.dao.TransactionDetailsMapper;
import com.stylefeng.guns.modular.taxi.model.OrderTaxi;
import com.stylefeng.guns.modular.taxi.model.PaymentRecord;
import com.stylefeng.guns.modular.taxi.model.TPhone;
import com.stylefeng.guns.modular.taxi.model.TransactionDetails;
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.ForecastPriceWarpper;
import com.stylefeng.guns.modular.taxi.warpper.OrderTaxiWarpper;
import org.bouncycastle.crypto.tls.MACAlgorithm;
import org.springframework.beans.factory.annotation.Autowired;
@@ -152,6 +156,9 @@
    @Autowired
    private IOrderPrivateCarService orderPrivateCarService;
    @Resource
    private SystemPriceMapper systemPriceMapper;
    @Autowired
    private IOrderCrossCityService orderCrossCityService;
@@ -161,7 +168,6 @@
    @Value("${callbackPath}")
    private String callbackPath;
@@ -177,7 +183,8 @@
     * @throws Exception
     */
    @Override
    public synchronized ResultUtil<BaseWarpper> taxiOrder(OrderTaxi orderTaxi, Integer uid) throws Exception {
    public synchronized ResultUtil<BaseWarpper> taxiOrder(OrderTaxi orderTaxi, Integer uid,String areaCode) throws Exception {
        System.out.println("出租车==========================================="+orderTaxi);
        //定义用户所属公司
        UserInfo userInfo1 = userInfoService.selectById(uid);
        if (userInfo1.getIsBlack()==1){
@@ -212,7 +219,7 @@
            return ResultUtil.error("有未完成的订单");
        }
        list = orderTaxiMapper.queryByState_(uid, 2, 1, 1, 2, 3, 4, 5, 6, 11);
        list = orderTaxiMapper.queryByState_(uid, 2, 1, 1, 2, 3, 4, 5, 6, 7, 11, 12);
        if(list.size() > 0 && orderTaxi.getOrderType() == 2){
            return ResultUtil.error("有未完成的订单");
        }
@@ -242,6 +249,13 @@
        UserInfo userInfo = userInfoService.selectById(uid);
        orderTaxi.setPassengersPhone(userInfo.getPhone());
        orderTaxi.setPassengers(userInfo.getNickName());
        //获取费用金额
        ForecastPriceWarpper warpper = new ForecastPriceWarpper();
        warpper.setPayManner(orderTaxi.getPayManner());
        warpper.setStartLat(orderTaxi.getStartLat());
        warpper.setStartLon(orderTaxi.getStartLon());
        warpper.setEndLat(orderTaxi.getEndLat());
        warpper.setEndLon(orderTaxi.getEndLon());
        if (!StringUtils.hasLength(orderTaxi.getPassengers())  || StringUtils.hasLength(orderTaxi.getPassengersPhone()) ){
            // 如果没有填写乘车人电话或者姓名 那么用用户的
@@ -330,8 +344,152 @@
        baseWarpper.setId(orderTaxi.getId());
        return ResultUtil.success(baseWarpper);
    }
    @Override
    public ResultUtil<Double> getForecastPrice(ForecastPriceWarpper warpper) {
        try {
            Company query = companyCityService.query(String.valueOf(warpper.getStartLon()), String.valueOf(warpper.getStartLat()));//获取起点所属分公司
            if(null == query){
                return ResultUtil.error("获取企业失败");
            }
            Map<String, String> distance = gdMapElectricFenceUtil.getDistance(warpper.getStartLon() + "," + warpper.getStartLat(),
                    warpper.getEndLon() + "," + warpper.getEndLat(), 1);
            if(null == distance){
                return ResultUtil.error("计算行驶距离失败");
            }
            double d = new BigDecimal(distance.get("distance")).divide(new BigDecimal(1000)).setScale(2, BigDecimal.ROUND_HALF_EVEN).doubleValue();
            double t = new BigDecimal(distance.get("duration")).divide(new BigDecimal(60)).setScale(2, BigDecimal.ROUND_HALF_EVEN).doubleValue();
            double amount = setMoney2(query.getId(), d, t);
            if(warpper.getPayManner() == 2){//其他支付,不需要操作,直接完成订单
                amount = amount + (new BigDecimal(Math.random()).setScale(2, BigDecimal.ROUND_HALF_EVEN).doubleValue());
            }
            return ResultUtil.success(amount);
        }catch (Exception e){
            e.printStackTrace();
            return ResultUtil.runErr();
        }
    }
    /**
     * 计算价格
     * @return
     * @throws Exception
     */
    public double setMoney2(Integer companyId, Double mileage, Double time) throws Exception {
        Map<String, Object> query1 = systemPriceMapper.query1(companyId, 2);
        //开始根据不同的方式计算金额
        JSONObject jsonObject = JSON.parseObject(String.valueOf(query1.get("content")));
        double amount = calculationPrice(jsonObject, mileage, time);
        return amount;
    }
    public double calculationPrice(JSONObject rule, double d, double t) throws Exception {
        double amount = 0.0;
        //等待费
        Date date = new Date();
        double d1 = (d - rule.getDouble("num2")) < 0 ? 0 : d - rule.getDouble("num2");//超出起步里程的公里
        double t1 = (t - rule.getDouble("num3")) < 0 ? 0 : t - rule.getDouble("num3");//超过起步分钟数的时间
        double yt1 = 0;//远途1段
        double yt2 = 0;//远途2段
        double yt3 = 0;//远途3段
        //夜间服务处理逻辑
        Calendar s = Calendar.getInstance();
        s.setTime(date);
        s.set(Calendar.HOUR_OF_DAY, Integer.valueOf(rule.getString("num14").split(" - ")[0].split(":")[0]));
        s.set(Calendar.MINUTE, Integer.valueOf(rule.getString("num14").split(" - ")[0].split(":")[1]));
        Calendar e = Calendar.getInstance();
        e.setTime(date);
        e.set(Calendar.HOUR_OF_DAY, Integer.valueOf(rule.getString("num14").split(" - ")[1].split(":")[0]));
        e.set(Calendar.MINUTE, Integer.valueOf(rule.getString("num14").split(" - ")[1].split(":")[1]));
        if(date.getTime() > s.getTimeInMillis() && date.getTime() < e.getTimeInMillis()){
            if(d > rule.getDouble("num6") && d < rule.getDouble("num7")){
                yt1 = rule.getDouble("num18") * d;
            }
            if(d >  rule.getDouble("num9") && d < rule.getDouble("num10")){
                yt1 = rule.getDouble("num18") * rule.getDouble("num7");
                yt2 = rule.getDouble("num19") * (d - rule.getDouble("num9"));
            }
            if(d > rule.getDouble("num12")){
                yt1 = rule.getDouble("num18") * rule.getDouble("num7");
                yt2 = rule.getDouble("num19") * (rule.getDouble("num10") - rule.getDouble("num9"));
                yt3 = rule.getDouble("num20") * (d - rule.getDouble("num12"));
            }
            Double startMoney = rule.getDouble("num15");//起步价
            Double mileageMoney = (new BigDecimal(d1 * rule.getDouble("num16")).setScale(2, BigDecimal.ROUND_DOWN).doubleValue());//里程费
            Double durationMoney = (new BigDecimal(t1 * rule.getDouble("num17")).setScale(2, BigDecimal.ROUND_DOWN).doubleValue());//时长费
            Double longDistanceMoney = (new BigDecimal(yt1 + yt2 + yt3).setScale(2, BigDecimal.ROUND_DOWN).doubleValue());//远途费
            amount = startMoney + mileageMoney + durationMoney + longDistanceMoney;
        }else{
            Calendar s1 = Calendar.getInstance();
            s1.setTime(date);
            s1.set(Calendar.HOUR_OF_DAY, Integer.valueOf(rule.getString("num21").split(" - ")[0].split(":")[0]));
            s1.set(Calendar.MINUTE, Integer.valueOf(rule.getString("num21").split(" - ")[0].split(":")[1]));
            Calendar e1 = Calendar.getInstance();
            e1.setTime(date);
            e1.set(Calendar.HOUR_OF_DAY, Integer.valueOf(rule.getString("num21").split(" - ")[1].split(":")[0]));
            e1.set(Calendar.MINUTE, Integer.valueOf(rule.getString("num21").split(" - ")[1].split(":")[1]));
            Calendar s2 = Calendar.getInstance();
            s2.setTime(date);
            s2.set(Calendar.HOUR_OF_DAY, Integer.valueOf(rule.getString("num22").split(" - ")[0].split(":")[0]));
            s2.set(Calendar.MINUTE, Integer.valueOf(rule.getString("num22").split(" - ")[0].split(":")[1]));
            Calendar e2 = Calendar.getInstance();
            e2.setTime(date);
            e2.set(Calendar.HOUR_OF_DAY, Integer.valueOf(rule.getString("num22").split(" - ")[1].split(":")[0]));
            e2.set(Calendar.MINUTE, Integer.valueOf(rule.getString("num22").split(" - ")[1].split(":")[1]));
            //高峰时段处理逻辑
            if((date.getTime() > s1.getTimeInMillis() && date.getTime() < e1.getTimeInMillis()) || (date.getTime() > s2.getTimeInMillis() && date.getTime() < e2.getTimeInMillis())){
                if(d > rule.getDouble("num6") && d < rule.getDouble("num7")){
                    yt1 = rule.getDouble("num26") * d;
                }
                if(d >  rule.getDouble("num9") && d < rule.getDouble("num10")){
                    yt1 = rule.getDouble("num26") * rule.getDouble("num7");
                    yt2 = rule.getDouble("num27") * (d - rule.getDouble("num9"));
                }
                if(d > rule.getDouble("num12")){
                    yt1 = rule.getDouble("num26") * rule.getDouble("num7");
                    yt2 = rule.getDouble("num27") * (rule.getDouble("num10") - rule.getDouble("num9"));
                    yt3 = rule.getDouble("num28") * (d - rule.getDouble("num12"));
                }
                Double startMoney = (rule.getDouble("num23"));//起步价
                Double mileageMoney = (new BigDecimal(d1 * rule.getDouble("num24")).setScale(2, BigDecimal.ROUND_DOWN).doubleValue());//里程费
                Double durationMoney = (new BigDecimal(t1 * rule.getDouble("num25")).setScale(2, BigDecimal.ROUND_DOWN).doubleValue());//时长费
                Double longDistanceMoney = (new BigDecimal(yt1 + yt2 + yt3).setScale(2, BigDecimal.ROUND_DOWN).doubleValue());//远途费
                amount = startMoney + mileageMoney + durationMoney + longDistanceMoney;
            }else{
                //其他时间段的计算
                if(d > rule.getDouble("num6") && d < rule.getDouble("num7")){
                    yt1 = rule.getDouble("num8") * d;
                }
                if(d >  rule.getDouble("num9") && d < rule.getDouble("num10")){
                    yt1 = rule.getDouble("num8") * rule.getDouble("num7");
                    yt2 = rule.getDouble("num11") * (d - rule.getDouble("num9"));
                }
                if(d > rule.getDouble("num12")){
                    yt1 = rule.getDouble("num8") * rule.getDouble("num7");
                    yt2 = rule.getDouble("num11") * (rule.getDouble("num10") - rule.getDouble("num9"));
                    yt3 = rule.getDouble("num13") * (d - rule.getDouble("num12"));
                }
                Double startMoney = (rule.getDouble("num1"));//起步价
                Double mileageMoney = (new BigDecimal(d1 * rule.getDouble("num4")).setScale(2, BigDecimal.ROUND_DOWN).doubleValue());//里程费
                Double durationMoney = (new BigDecimal(t1 * rule.getDouble("num5")).setScale(2, BigDecimal.ROUND_DOWN).doubleValue());//时长费
                Double longDistanceMoney = (new BigDecimal(yt1 + yt2 + yt3).setScale(2, BigDecimal.ROUND_DOWN).doubleValue());//远途费
                amount = startMoney + mileageMoney + durationMoney + longDistanceMoney;
            }
        }
        return amount;
    }
    /**
     * 继续执行推动等待操作
     * @param id
@@ -577,8 +735,9 @@
                        placeOrderWay = 3;
                        break;
                }
                Company company = companyService.selectById(orderTaxi.getCompanyId());
                //添加交易明细
                transactionDetailsService.saveDataTaxi(uid, "取消订单", query.getMoney(), 2, 1, 1, 2, id,placeOrderWay);
                transactionDetailsService.saveDataTaxi(uid, "取消订单", query.getMoney(), 2, 1, 1, 2, id,placeOrderWay,company.getId());
                userInfoService.updateById(userInfo);
                //解除小号绑定
@@ -650,8 +809,8 @@
        UserInfo userInfo = userInfoService.selectById(uid);
        map.put("balance", userInfo.getBalance());
        OrderTaxi orderTaxi = this.selectById(orderId);
        int i = userCouponRecordService.queryAvailable(uid, orderTaxi.getCompanyId(), 1, 2, orderTaxi.getOrderMoney());
        i = i + userCouponRecordService.queryAvailable(uid, orderTaxi.getCompanyId(), 1, 0, orderTaxi.getOrderMoney());
        int i = userCouponRecordService.queryAvailable(uid, null, 1, 2, orderTaxi.getOrderMoney());
        i = i + userCouponRecordService.queryAvailable(uid, null, 1, 0, orderTaxi.getOrderMoney());
        map.put("coupon", i);
        return map;
    }
@@ -666,8 +825,22 @@
    @Override
    public List<Map<String, Object>> queryCoupon(Integer orderId, Integer uid, Integer pageNum, Integer size) throws Exception {
        OrderTaxi orderTaxi = this.selectById(orderId);
        List<Map<String, Object>> list = userCouponRecordService.queryCoupon(uid, orderTaxi.getCompanyId(), 1, 2, orderTaxi.getOrderMoney(), pageNum, size);
        List<Map<String, Object>> list1 = userCouponRecordService.queryCoupon(uid, orderTaxi.getCompanyId(), 1, 0, orderTaxi.getOrderMoney(), pageNum, size);
        Driver driver = driverService.selectById(orderTaxi.getDriverId());
        Integer companyId = driver.getCompanyId();
        List<CompanyCity> companyCityList = companyCityService.selectList(new EntityWrapper<CompanyCity>().eq("companyId", companyId));
        List<Map<String, Integer>> cityCode = new ArrayList<>();
        for (CompanyCity companyCity : companyCityList) {
            Map<String, Integer> city = new HashMap<>();
            if(ToolUtil.isNotEmpty(companyCity.getAreaCode())){
                city.put("code", Integer.valueOf(companyCity.getAreaCode()));
            }else if(ToolUtil.isEmpty(companyCity.getAreaCode()) && ToolUtil.isNotEmpty(companyCity.getCityCode())){
                city.put("code", Integer.valueOf(companyCity.getCityCode()));
            }else if(ToolUtil.isEmpty(companyCity.getCityCode()) && ToolUtil.isNotEmpty(companyCity.getProvinceCode())){
                city.put("code", Integer.valueOf(companyCity.getProvinceCode()));
            }
        }
        List<Map<String, Object>> list = userCouponRecordService.queryCoupon1(uid, JSON.toJSONString(cityCode), 1, 2, orderTaxi.getOrderMoney(), pageNum, size);
        List<Map<String, Object>> list1 = userCouponRecordService.queryCoupon1(uid, JSON.toJSONString(cityCode), 1, 0, orderTaxi.getOrderMoney(), pageNum, size);
        list.addAll(list1);
        return list;
    }
@@ -700,9 +873,9 @@
        UserCouponRecord userCouponRecord = null;
        if(null != couponId){
            userCouponRecord = userCouponRecordService.selectById(couponId);
            if(userCouponRecord.getCompanyId() != orderTaxi.getCompanyId()){
                return ResultUtil.error("优惠券不能用于此订单", "");
            }
//            if(userCouponRecord.getCompanyId() != orderTaxi.getCompanyId()){
//                return ResultUtil.error("优惠券不能用于此订单", "");
//            }
            if(userCouponRecord.getState() == 2){
                return ResultUtil.error("优惠券已使用", "");
            }
@@ -751,12 +924,15 @@
                appletsOpenId = userInfo.getAppletsOpenId();
            }
            Map<String, String> map = icbcPayUtil.placeAnOrder(orderId + ",2", 9, 5, uid.toString(), "完成订单", orderMoney, callbackPath + "/base/wxPayOrderTaxi", "", type, appletsOpenId);
            if(map.get("code").equals("200")){
                paymentRecordService.saveData(1, orderTaxi.getUserId(), 1, orderId, 2, 1, orderMoney, map.get("order_id"), 1);//添加预支付数据
                resultUtil = ResultUtil.success(map.get("data"));
            }else{
                resultUtil = ResultUtil.error(map.get("msg"), "");
            }
            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(map.get("code").equals("200")){
//                paymentRecordService.saveData(1, orderTaxi.getUserId(), 1, orderId, 2, 1, orderMoney, map.get("order_id"), 1);//添加预支付数据
//                resultUtil = ResultUtil.success(map.get("data"));
//            }else{
//                resultUtil = ResultUtil.error(map.get("msg"), "");
//            }
        }
        if(payType == 2){//支付宝支付
            Map<String, String> map = icbcPayUtil.placeAnOrder(orderId + ",2", 10, 5, uid.toString(), "完成订单", orderMoney, callbackPath + "/base/aliPayOrderTaxi", "", type, null);
@@ -775,7 +951,7 @@
            userInfo.setBalance(new BigDecimal(userInfo.getBalance()).subtract(new BigDecimal(orderMoney)).setScale(2, BigDecimal.ROUND_HALF_EVEN).doubleValue());
            SysIntegral query1 = sysIntegralMapper.query(orderTaxi.getCompanyId());
            userInfo.setIntegral(userInfo.getIntegral() + (orderMoney.intValue() * query1.getIntegral()));//积分
//            userInfo.setIntegral(userInfo.getIntegral() + (orderMoney.intValue() * query1.getIntegral()));//积分
            Integer placeOrderWay = null;
            switch (orderTaxi.getOrderSource()){
                case 2:
@@ -795,7 +971,7 @@
                    break;
            }
            //添加交易明细
            transactionDetailsService.saveDataTaxi(uid, "完成订单", orderMoney, 2, 1, 1, 2, orderId,placeOrderWay);
//            transactionDetailsService.saveDataTaxi(uid, "完成订单", orderMoney, 2, 1, 1, 2, orderId,placeOrderWay);
            userInfoService.updateById(userInfo);
            orderTaxi.setState(8);
@@ -815,24 +991,46 @@
            }
            //添加已收入明细
            Company company = companyService.selectById(orderTaxi.getCompanyId());
            Double taxi = company.getTaxiMoney();
            BigDecimal d = null;//企业收入
            BigDecimal c = null;//司机收入
            if(company.getIsTaxiFixedOrProportional() == 2){//固定
                d = new BigDecimal(taxi);
                c = new BigDecimal(orderTaxi.getOrderMoney()).subtract(d);//只有出行金额参与抽成,其余归属司机
            }
            if(company.getIsTaxiFixedOrProportional() == 1){//比例
                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());
//            Company company = companyService.selectById(orderTaxi.getCompanyId());
//            Double taxi = company.getTaxiMoney();
//            BigDecimal d = null;//企业收入
//            BigDecimal c = null;//司机收入
//            if(company.getIsTaxiFixedOrProportional() == 2){//固定
//                d = new BigDecimal(taxi);
//                c = new BigDecimal(orderTaxi.getOrderMoney()).subtract(d);//只有出行金额参与抽成,其余归属司机
//            }
//            if(company.getIsTaxiFixedOrProportional() == 1){//比例
//                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());
            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());
//            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());
            Company company = companyService.selectById(driver.getFranchiseeId());
            if(Objects.isNull(company)){
                company = companyService.selectById(driver.getCompanyId());
            }
            // 司机收入
            double moneyTwo;
            // 平台收入
            double money;
            if(orderTaxi.getOrderSource() == 2 || orderTaxi.getOrderSource() == 3){
                double v = company.getPercentageDeduction() / 100;
                money = v * orderTaxi.getOrderMoney();
                moneyTwo = orderTaxi.getOrderMoney()-money;
            }else {
                money = company.getFixedDeduction();
                moneyTwo = orderTaxi.getOrderMoney()-money;
            }
            driver.setBalance(driver.getBalance() + moneyTwo);
            // 新增扣除使用费记录
            transactionDetailsService.saveDataTaxi(driver.getId(), "软件使用费", money, 2, 1, 2, 6, orderTaxi.getId(),placeOrderWay,company.getId());
            // 司机订单收入
            transactionDetailsService.saveDataTaxi(driver.getId(), "完成订单", moneyTwo, 1, 1, 2, 2, orderTaxi.getId(),placeOrderWay,company.getId());
            driverService.updateById(driver);
            // TODO: 2020/5/24 这里需要给司机和用户推送订单状态
@@ -1044,7 +1242,10 @@
                value = map.get("lon") + "," + map.get("lat");
            }
        }
        Map<String, String> distance = gdMapElectricFenceUtil.getDistance(value, orderTaxi.getStartLon() + "," + orderTaxi.getStartLat(), 1);
        // todo 注意 因更换地图为百度 两者lon和lat位置互换了
        String[] split = value.split(",");
        value = split[1] + "," + split[0];
        Map<String, String> distance = gdMapElectricFenceUtil.getDistance(value, orderTaxi.getStartLat() + "," + orderTaxi.getStartLon(), 1);
        String d = "0";
        String t = "0";
        if(null == distance){
@@ -1057,8 +1258,20 @@
        orderServerWarpper.setOrderId(orderTaxi.getId());
        orderServerWarpper.setOrderType(2);
        orderServerWarpper.setState(orderTaxi.getState());
        orderServerWarpper.setLon(null != value ? value.split(",")[0] : "0.0");
        orderServerWarpper.setLat(null != value ? value.split(",")[1] : "0.0");
        orderServerWarpper.setLon(null != value ? value.split(",")[1] : "0.0");
        orderServerWarpper.setLat(null != value ? value.split(",")[0] : "0.0");
        value = value == null ? "0.0,0.0" : value;
        double[] doubles = GpsCoordinateUtils.calBD09toGCJ02(Double.parseDouble(value.split(",")[1]), Double.parseDouble(value.split(",")[0]));
        orderServerWarpper.setNextLongitude(String.valueOf(doubles[0]));
        orderServerWarpper.setNextLatitude(String.valueOf(doubles[1]));
        // 起点地址转换
        doubles = GpsCoordinateUtils.calBD09toGCJ02(orderTaxi.getStartLat(), orderTaxi.getStartLon());
        orderServerWarpper.setStartLat(String.valueOf(doubles[0]));
        orderServerWarpper.setStartLon(String.valueOf(doubles[1]));
        // 终点地址转换
        doubles = GpsCoordinateUtils.calBD09toGCJ02(orderTaxi.getEndLat(), orderTaxi.getEndLon());
        orderServerWarpper.setEndLat(String.valueOf(doubles[0]));
        orderServerWarpper.setEndLon(String.valueOf(doubles[1]));
        orderServerWarpper.setReassignNotice(orderTaxi.getReassignNotice());
        if(orderTaxi.getState() == 2 || orderTaxi.getState() == 3){//前往预约地
            orderServerWarpper.setReservationMileage(d);
@@ -1069,12 +1282,12 @@
            orderServerWarpper.setLaveTime("0");
        }
        if(orderTaxi.getState() == 5 || orderTaxi.getState() == 6){//服务中
            distance = gdMapElectricFenceUtil.getDistance(value, orderTaxi.getEndLon() + "," + orderTaxi.getEndLat(), 1);
            distance = gdMapElectricFenceUtil.getDistance(value, orderTaxi.getEndLat() + "," + orderTaxi.getEndLon(), 1);
            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)).setScale(2, BigDecimal.ROUND_HALF_EVEN).intValue() + "";
                d = new BigDecimal(distance.get("distance")).divide(new BigDecimal(1000),2, RoundingMode.HALF_UP).toString();
                t = new BigDecimal(distance.get("duration")).divide(new BigDecimal(60),2, RoundingMode.HALF_UP) + "";
            }
            orderServerWarpper.setReservationMileage("0");
            orderServerWarpper.setReservationTime("0");
@@ -1223,17 +1436,18 @@
                    placeOrderWay = 3;
                    break;
            }
            //添加交易明细
            transactionDetailsService.saveDataTaxi(orderTaxi.getUserId(), "完成订单", query.getAmount(), 2, 1, 1, 2, query.getOrderId(),placeOrderWay);
//            Company company = companyService.selectById(orderTaxi.getCompanyId());
//            //添加交易明细
//            transactionDetailsService.saveDataTaxi(orderTaxi.getUserId(), "完成订单", query.getAmount(), 2, 1, 1, 2, query.getOrderId(),placeOrderWay,company.getId());
            orderTaxi.setState(8);
            orderTaxi.setPayType(type);
            orderTaxi.setPayMoney(query.getAmount());
            this.updateById(orderTaxi);
            UserInfo userInfo = userInfoService.selectById(orderTaxi.getUserId());
            SysIntegral query1 = sysIntegralMapper.query(orderTaxi.getCompanyId());
            userInfo.setIntegral(userInfo.getIntegral() + (query.getAmount().intValue() * query1.getIntegral()));//积分
            userInfoService.updateById(userInfo);
//            UserInfo userInfo = userInfoService.selectById(orderTaxi.getUserId());
//            SysIntegral query1 = sysIntegralMapper.query(orderTaxi.getCompanyId());
//            userInfo.setIntegral(userInfo.getIntegral() + (query.getAmount().intValue() * query1.getIntegral()));//积分
//            userInfoService.updateById(userInfo);
            //处理优惠券和红包
            if(null != orderTaxi.getCouponId()){
@@ -1255,24 +1469,46 @@
            paymentRecordService.updateById(query);
            //添加已收入明细
            Company company = companyService.selectById(orderTaxi.getCompanyId());
            Double taxi = company.getTaxiMoney();
            BigDecimal d = null;//企业收入
            BigDecimal c = null;//司机收入
            if(company.getIsTaxiFixedOrProportional() == 2){//固定
                d = new BigDecimal(taxi);
                c = new BigDecimal(orderTaxi.getOrderMoney()).subtract(d).setScale(2, BigDecimal.ROUND_HALF_EVEN);
            }
            if(company.getIsTaxiFixedOrProportional() == 1){//比例
                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());
//            Company company = companyService.selectById(orderTaxi.getCompanyId());
//            Double taxi = company.getTaxiMoney();
//            BigDecimal d = null;//企业收入
//            BigDecimal c = null;//司机收入
//            if(company.getIsTaxiFixedOrProportional() == 2){//固定
//                d = new BigDecimal(taxi);
//                c = new BigDecimal(orderTaxi.getOrderMoney()).subtract(d).setScale(2, BigDecimal.ROUND_HALF_EVEN);
//            }
//            if(company.getIsTaxiFixedOrProportional() == 1){//比例
//                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());
            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());
//            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());
            Company company = companyService.selectById(driver.getFranchiseeId());
            if(Objects.isNull(company)){
                company = companyService.selectById(driver.getCompanyId());
            }
            // 司机收入
            double moneyTwo;
            // 平台收入
            double money;
            if(orderTaxi.getOrderSource() == 2 || orderTaxi.getOrderSource() == 3){
                double v = company.getPercentageDeduction() / 100;
                money = v * orderTaxi.getOrderMoney();
                moneyTwo = orderTaxi.getOrderMoney()-money;
            }else {
                money = company.getFixedDeduction();
                moneyTwo = orderTaxi.getOrderMoney()-money;
            }
            driver.setBalance(driver.getBalance() + moneyTwo);
            // 新增扣除使用费记录
            transactionDetailsService.saveDataTaxi(driver.getId(), "软件使用费", money, 2, 1, 2, 6, orderTaxi.getId(),placeOrderWay,company.getId());
            // 司机订单收入
            transactionDetailsService.saveDataTaxi(driver.getId(), "完成订单", moneyTwo, 1, 1, 2, 2, orderTaxi.getId(),placeOrderWay,company.getId());
            driverService.updateById(driver);
            // TODO: 2020/5/24 这里需要给司机和用户推送订单状态
@@ -1299,6 +1535,10 @@
            systemNoticeService.addSystemNotice(1, "您已使用" + (type == 1 ? "微信" : "支付宝") + "成功完成出行订单支付,谢谢使用!", orderTaxi.getUserId(), 1);
            //添加司机消息提醒
            systemNoticeService.addSystemNotice(2, "用户已线上完成支付", driver.getId(), 1);
            //推送状态,让司机端播报语音
            pushUtil.pushOrderState(2, orderTaxi.getDriverId(), orderTaxi.getId(), 2, orderTaxi.getState(), 0);
        }else{
            System.err.println("预支付数据异常(orderId = "  + id + ")");
        }
@@ -1335,8 +1575,9 @@
                    placeOrderWay = 3;
                    break;
            }
            Company company = companyService.selectById(orderTaxi.getCompanyId());
            //添加交易明细
            transactionDetailsService.saveDataTaxi(orderTaxi.getUserId(), "取消订单", query.getAmount(), 2, 1, 1, 2, query.getOrderId(),placeOrderWay);
            transactionDetailsService.saveDataTaxi(orderTaxi.getUserId(), "取消订单", query.getAmount(), 2, 1, 1, 2, query.getOrderId(),placeOrderWay,company.getId());
            orderTaxi.setState(10);
            //解除小号绑定
            if(orderTaxi.getBindId() != null){
@@ -1387,20 +1628,15 @@
            @Override
            public void run() {
                try {
                    System.out.println("进入订单推送111111111111");
                    orderIds.add(orderTaxi.getId());//添加记录,防止调用接口重复提醒无人接单
                    String vehicle = redisUtil.getValue("VEHICLE");
                    List<Integer> integers = new ArrayList<>();
                    if(ToolUtil.isNotEmpty(vehicle)){
                        integers = JSON.parseArray(vehicle).toJavaList(Integer.class);
                    }
                    System.out.println("进入订单推送22222222222222=========="+integers);
                    Company query = companyCityService.query(String.valueOf(orderTaxi.getStartLon()), String.valueOf(orderTaxi.getStartLat()));//获取起点所属分公司
                    System.out.println("进入订单推送=========3==========="+query);
                    List<PushOrder> querys = pushOrderService.querys(null, 2, query.getId());//获取需要推送的次数
                    System.out.println("进入订单推送=========4==========="+querys);
                    for(int i = 1; i <= querys.size(); i++){
                        System.out.println("进入订单推送");
                        PushOrder pushOrder = pushOrderService.querys(i, 2, query.getId()).get(0);
                        System.out.println("进入订单推送");
                        //获取空闲司机
@@ -1409,11 +1645,8 @@
                        if(list.size() > 0){
                            System.out.println("进入司机推送");
                            double driverProportion = pushOrder.getDriverProportion() / 100;//推送占比计算成小数
                            System.out.println("推送占比计算成小数======="+driverProportion);
                            int lastIndex = Double.valueOf(list.size() * driverProportion).intValue();//计算占比转成整数(下标截取)
                            System.out.println("计算占比转成整数======="+lastIndex);
                            list = list.subList(0, lastIndex);//获取空闲司机中占比数据
                            System.out.println("获取空闲司机中占比数据======="+list);
                            for(Driver driver : list){//开始进行推送
                                System.out.println("开始进行推送======="+driver);
                                //查询是否在限制推单范围内
@@ -1427,7 +1660,6 @@
                                if(bo){
                                    continue;
                                }
                                System.out.println("推送订单前");
                                pushUtil.pushOrderState(2, driver.getId(), orderTaxi.getId(), 2, orderTaxi.getState(), pushOrder.getPushTime());
                                System.out.println("推送订单后");
                            }