zhibing.pu
2024-08-10 155df5096da87c047ea5af3ce7f8b2284c02dd2d
UserIGOTravel/guns-admin/src/main/java/com/stylefeng/guns/modular/smallLogistics/server/impl/OrderLogisticsServiceImpl.java
@@ -208,6 +208,9 @@
    @Autowired
    private ICarService carService;
    
    @Resource
    private DriverWorkMapper driverWorkMapper;
    
    @Value("${filePath}")
    private String filePath;
@@ -559,6 +562,13 @@
                                if(bo){
                                    continue;
                                }
                                Driver driver1 = driverService.selectById(driver.getId());
                                DriverWork driverWork = driverWorkMapper.selectOne(new EntityWrapper<DriverWork>().eq("driverId", driver1.getId())
                                        .eq("state", 1).like("type", "4").getEntity());
                                if(null == driverWork || driver1.getState() != 2){
                                    continue;
                                }
                                String text = "";
                                Integer language1 = driver.getLanguage();
                                switch (language1){
@@ -879,63 +889,68 @@
                        dr = drivers.get(0);
                    }
    
                    orderLogistics.setDriverId(dr.getId());
                    orderLogistics.setCompanyId(dr.getFranchiseeId() != null && dr.getFranchiseeId() != 0 ? dr.getFranchiseeId() : (
                            dr.getCompanyId() != null && dr.getCompanyId() != 0 ? dr.getCompanyId() : 1));
                    orderLogistics.setState(2);
                    orderLogistics.setCarId(dr.getCarId());
                    CarService query1 = carServiceMapper.query(1, dr.getCarId());
                    orderLogistics.setServerCarModelId(query1.getServerCarModelId());
                    orderLogistics.setSnatchOrderTime(new Date());
                    dr.setState(3);
                    driverService.updateById(dr);
                    this.updateById(orderLogistics);
                    Driver driver1 = driverService.selectById(dr.getId());
                    DriverWork driverWork = driverWorkMapper.selectOne(new EntityWrapper<DriverWork>().eq("driverId", driver1.getId())
                            .eq("state", 1).like("type", "4").getEntity());
                    if(driver1.getState() == 2 || null != driverWork){
                        orderLogistics.setDriverId(dr.getId());
                        orderLogistics.setCompanyId(dr.getFranchiseeId() != null && dr.getFranchiseeId() != 0 ? dr.getFranchiseeId() : (
                                dr.getCompanyId() != null && dr.getCompanyId() != 0 ? dr.getCompanyId() : 1));
                        orderLogistics.setState(2);
                        orderLogistics.setCarId(dr.getCarId());
                        CarService query1 = carServiceMapper.query(1, dr.getCarId());
                        orderLogistics.setServerCarModelId(query1.getServerCarModelId());
                        orderLogistics.setSnatchOrderTime(new Date());
    
                    String text = "";
                    Integer language1 = dr.getLanguage();
                    switch (language1){
                        case 1:
                            text = "收到新的包裹订单,从" + orderLogistics.getStartAddress() + "出发,全程约" + orderLogistics.getEstimatedMileage() + "公里";
                            break;
                        case 2:
                            text = "Received a new delivery order, starting from " + orderLogistics.getStartAddress() + ", the whole journey is about " + orderLogistics.getEstimatedMileage() + "kilometre";
                            break;
                        case 3:
                            text = "J'ai reçu une nouvelle commande de livraison, à partir de " + orderLogistics.getStartAddress() + ", le trajet complet est d’environ " + orderLogistics.getEstimatedMileage() + "kilométrage";
                            break;
                        dr.setState(3);
                        driverService.updateById(dr);
                        this.updateById(orderLogistics);
                        String text = "";
                        Integer language1 = dr.getLanguage();
                        switch (language1){
                            case 1:
                                text = "收到新的包裹订单,从" + orderLogistics.getStartAddress() + "出发,全程约" + orderLogistics.getEstimatedMileage() + "公里";
                                break;
                            case 2:
                                text = "Received a new delivery order, starting from " + orderLogistics.getStartAddress() + ", the whole journey is about " + orderLogistics.getEstimatedMileage() + "kilometre";
                                break;
                            case 3:
                                text = "J'ai reçu une nouvelle commande de livraison, à partir de " + orderLogistics.getStartAddress() + ", le trajet complet est d’environ " + orderLogistics.getEstimatedMileage() + "kilométrage";
                                break;
        
                    }
                    String audioUrl = "";
                    String fileName = "pushOrder" + orderLogistics.getDriverId() + UUIDUtil.getRandomCode(5) + ".mp3";
                    try {
                        audioUrl = TextToSpeechUtil.create(language1 == 1 ? "cmn-CN" : language1 == 2 ? "en-US" : "fr-FR", text, fileName);
                    } catch (Exception e) {
                        throw new RuntimeException(e);
                    }
                    //定时任务删除语音文件
                    new Timer().schedule(new TimerTask() {
                        @Override
                        public void run() {
                            Process process = null;
                            try {
                                process = Runtime.getRuntime().exec("rm -rf /usr/local/nginx/html/files/audio/" + fileName);
                            } catch (IOException e) {
                                throw new RuntimeException(e);
                            }
                            if (process != null) {
                                process.destroy();
                            }
                        }
                    }, 30000);
                    String finalAudioUrl = audioUrl;
                    new Thread(new Runnable() {
                        @Override
                        public void run() {
                            pushUtil.pushOrderState(1, uid, orderLogistics.getId(), 4, 2, 0, "");
                            pushUtil.pushOrderState(2, orderLogistics.getDriverId(), orderLogistics.getId(), 4, 2, 0, finalAudioUrl);
                        String audioUrl = "";
                        String fileName = "pushOrder" + orderLogistics.getDriverId() + UUIDUtil.getRandomCode(5) + ".mp3";
                        try {
                            audioUrl = TextToSpeechUtil.create(language1 == 1 ? "cmn-CN" : language1 == 2 ? "en-US" : "fr-FR", text, fileName);
                        } catch (Exception e) {
                            throw new RuntimeException(e);
                        }
                    }).start();
                        //定时任务删除语音文件
                        new Timer().schedule(new TimerTask() {
                            @Override
                            public void run() {
                                Process process = null;
                                try {
                                    process = Runtime.getRuntime().exec("rm -rf /usr/local/nginx/html/files/audio/" + fileName);
                                } catch (IOException e) {
                                    throw new RuntimeException(e);
                                }
                                if (process != null) {
                                    process.destroy();
                                }
                            }
                        }, 30000);
                        String finalAudioUrl = audioUrl;
                        new Thread(new Runnable() {
                            @Override
                            public void run() {
                                pushUtil.pushOrderState(1, uid, orderLogistics.getId(), 4, 2, 0, "");
                                pushUtil.pushOrderState(2, orderLogistics.getDriverId(), orderLogistics.getId(), 4, 2, 0, finalAudioUrl);
                            }
                        }).start();
                    }
                }
            }
        }
@@ -944,22 +959,6 @@
        //推单操作
        if(orderLogistics.getState() == 1){
            this.pushOrder(orderLogistics);
        }else{
//            //接单后定时任务判断司机是否去接乘客,没有则推送提醒
//            CancleOrder cancleOrder = cancleOrderService.query(orderLogistics.getCompanyId());
//            if(null != cancleOrder){
//                JSONObject object = JSON.parseObject(cancleOrder.getContent());
//                long time = object.getInteger("driverTimeout") * 60000L;
//                new Timer().schedule(new TimerTask() {
//                    @Override
//                    public void run() {
//                        OrderLogistics orderLogistics1 = OrderLogisticsServiceImpl.this.selectById(orderLogistics.getId());
//                        if(orderLogistics1.getState() == 2){
//                            pushUtil.pushDriverTimeOut(1, orderLogistics1.getUserId(), orderLogistics1.getId(), 4);
//                        }
//                    }
//                }, time);
//            }
        }
    
    
@@ -990,7 +989,7 @@
            return ResultUtil.error(language == 1 ? "订单已完成支付,不允许重复支付" : language == 2 ? "The order has been paid, recurring payments is not allowed." : "La commande a été payée, les paiements récurrents ne sont pas autorisés.", "");
        }
        Integer uid = orderLogistics.getUserId();
        Double orderMoney = orderLogistics.getOrderMoney();
        BigDecimal orderMoney = new BigDecimal(orderLogistics.getOrderMoney());
        if(orderLogistics.getUrgent() == 2){
//            orderMoney += null != orderLogistics.getTipMoney() ? orderLogistics.getTipMoney() : 0;
        }
@@ -1004,9 +1003,9 @@
                Double special = query2.getLogistics();
                if(null != special){
                    orderLogistics.setDiscount(special);
                    double v = new BigDecimal(orderMoney).multiply(new BigDecimal(special / 10)).setScale(2, BigDecimal.ROUND_HALF_EVEN).doubleValue();
                    BigDecimal v = orderMoney.multiply(new BigDecimal(special / 10)).setScale(2, BigDecimal.ROUND_HALF_EVEN);
                    if(orderMoney.compareTo(v) > 0){
                        orderLogistics.setDiscountMoney(orderMoney - v);
                        orderLogistics.setDiscountMoney(orderMoney.subtract(v).setScale(2, BigDecimal.ROUND_HALF_EVEN).doubleValue());
                        orderLogistics.setActivityId(query2.getId());
                        orderMoney = v;
                    }
@@ -1034,10 +1033,10 @@
            if(userCouponRecord.getCouponUseType() != 0 && userCouponRecord.getCouponUseType() != 4){
                return ResultUtil.error(language == 1 ? "优惠券不能用于此订单" : language == 2 ? "Coupon cannot be used for this order." : "Le coupon ne peut pas être utilisé pour cette commande.", "");
            }
            if(userCouponRecord.getCouponType() == 2 && orderMoney.compareTo(userCouponRecord.getFullMoney()) < 0){
            if(userCouponRecord.getCouponType() == 2 && orderMoney.compareTo(new BigDecimal(userCouponRecord.getFullMoney())) < 0){
                return ResultUtil.error(language == 1 ? "优惠券不能用于此订单" : language == 2 ? "Coupon cannot be used for this order." : "Le coupon ne peut pas être utilisé pour cette commande.", "");
            }
            orderMoney = orderMoney - userCouponRecord.getMoney();
            orderMoney = orderMoney.subtract(new BigDecimal(userCouponRecord.getMoney())).setScale(2, RoundingMode.HALF_EVEN);
            orderLogistics.setCouponMoney(userCouponRecord.getMoney());
            orderLogistics.setCouponId(couponId);
        }
@@ -1051,10 +1050,10 @@
                        .eq("state", 1).eq("companyId", orderLogistics.getCompanyId()).gt("remainingAmount", 0).orderBy("insertTime", false));
    
                BigDecimal deductionRatio = redEnvelopePaymentSettings.getDeductionRatio();
                BigDecimal multiply1 = new BigDecimal(orderMoney).multiply(deductionRatio.divide(new BigDecimal(100))).setScale(2, RoundingMode.HALF_EVEN);
                if(total.compareTo(multiply1.doubleValue()) >= 0){
                BigDecimal multiply1 = orderMoney.multiply(deductionRatio.divide(new BigDecimal(100))).setScale(2, RoundingMode.HALF_EVEN);
                if(total > 0 && multiply1.doubleValue() > 0 && total.compareTo(multiply1.doubleValue()) >= 0){
                    orderLogistics.setRedPacketMoney(multiply1.doubleValue());
                    orderMoney = orderMoney - multiply1.doubleValue();
                    orderMoney = orderMoney.subtract(multiply1).setScale(2, RoundingMode.HALF_EVEN);
                
                    //获取红包id
                    JSONArray jsonArray = new JSONArray();
@@ -1062,6 +1061,9 @@
                        JSONObject jsonObject = new JSONObject();
                        jsonObject.put("id", userRedPacketRecord.getId());
                        BigDecimal remainingAmount = new BigDecimal(userRedPacketRecord.getRemainingAmount());
                        if(multiply1.compareTo(BigDecimal.ZERO) == 0){
                            break;
                        }
                        if(multiply1.compareTo(remainingAmount) >= 0){
                            userRedPacketRecord.setRemainingAmount(0D);
                            userRedPacketRecord.setEndTime(new Date());
@@ -1070,18 +1072,19 @@
                            jsonObject.put("money", remainingAmount);
                            jsonArray.add(jsonObject);
                            userRedPacketRecordService.updateById(userRedPacketRecord);
                        }else{
                        }else if(remainingAmount.compareTo(multiply1) > 0){
                            userRedPacketRecord.setRemainingAmount(remainingAmount.subtract(multiply1).setScale(2, RoundingMode.HALF_EVEN).doubleValue());
                            jsonObject.put("money", multiply1);
                            jsonArray.add(jsonObject);
                            userRedPacketRecordService.updateById(userRedPacketRecord);
                            break;
                            multiply1 = BigDecimal.ZERO;
                        }
                    }
                    orderLogistics.setRedPacketId(jsonArray.toJSONString());
                }else{
                }
                if(total > 0 && total.compareTo(multiply1.doubleValue()) < 0){
                    orderLogistics.setRedPacketMoney(total);
                    orderMoney = orderMoney - total;
                    orderMoney = orderMoney.subtract(new BigDecimal(total)).setScale(2, RoundingMode.HALF_EVEN);
                    //获取红包id
                    JSONArray jsonArray = new JSONArray();
                    BigDecimal multiply = new BigDecimal(total);
@@ -1089,6 +1092,9 @@
                        JSONObject jsonObject = new JSONObject();
                        jsonObject.put("id", userRedPacketRecord.getId());
                        BigDecimal remainingAmount = new BigDecimal(userRedPacketRecord.getRemainingAmount());
                        if(multiply.compareTo(BigDecimal.ZERO) == 0){
                            break;
                        }
                        if(multiply.compareTo(remainingAmount) >= 0){
                            userRedPacketRecord.setRemainingAmount(0D);
                            userRedPacketRecord.setEndTime(new Date());
@@ -1097,12 +1103,12 @@
                            jsonObject.put("money", remainingAmount);
                            jsonArray.add(jsonObject);
                            userRedPacketRecordService.updateById(userRedPacketRecord);
                        }else{
                        }else if(remainingAmount.compareTo(multiply) > 0){
                            userRedPacketRecord.setRemainingAmount(remainingAmount.subtract(multiply).setScale(2, RoundingMode.HALF_EVEN).doubleValue());
                            jsonObject.put("money", multiply);
                            jsonArray.add(jsonObject);
                            userRedPacketRecordService.updateById(userRedPacketRecord);
                            break;
                            multiply = BigDecimal.ZERO;
                        }
                    }
                    orderLogistics.setRedPacketId(jsonArray.toJSONString());
@@ -1110,8 +1116,6 @@
            }
        }
        
        orderMoney=new BigDecimal(orderMoney).setScale(2, BigDecimal.ROUND_HALF_EVEN).doubleValue();
        if(payType == 1) {//手机支付
            SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMddHHmmssSSS");
            String merchantTransactionId = sdf.format(new Date()) + "4" + language + orderId;
@@ -1121,7 +1125,7 @@
            checkoutRequest.setAccountNumber(userInfo.getPhone());
            checkoutRequest.setCustomerFirstName(userInfo.getFirstName());
            checkoutRequest.setCustomerLastName(userInfo.getLastName());
            checkoutRequest.setRequestAmount(orderMoney);
            checkoutRequest.setRequestAmount(orderMoney.setScale(2, RoundingMode.HALF_EVEN).doubleValue());
            checkoutRequest.setMerchantTransactionId(merchantTransactionId);
            checkoutRequest.setRequestDescription("Travel completion payment");
            checkoutRequest.setCallbackUrl(callbackPath + "/base/wxPayOrderTaxi");
@@ -1130,7 +1134,8 @@
            checkoutRequest.setFailRedirectUrl("http://182.160.16.251:81/payMoney/pages/fail.html");
            resultUtil = TinggPayUtil.checkoutRequest(checkoutRequest);
            if(resultUtil.getCode()==200){
                paymentRecordService.saveData(1, null, null, orderId, 4, 1, orderMoney, null, 1);//添加预支付数据
                paymentRecordService.saveData(1, null, null, orderId, 4, 1,
                        orderMoney.setScale(2, RoundingMode.HALF_EVEN).doubleValue(), null, 1);//添加预支付数据
            }else{
                resultUtil = ResultUtil.error(language == 1 ? "支付失败" : language == 2 ? "Payment failure" : "Paiement échoué", "");
            }
@@ -1147,7 +1152,7 @@
            checkoutRequest.setAccountNumber(bankCard.getCode());
            checkoutRequest.setCustomerFirstName(bankCard.getFirstName());
            checkoutRequest.setCustomerLastName(bankCard.getLastName());
            checkoutRequest.setRequestAmount(orderMoney);
            checkoutRequest.setRequestAmount(orderMoney.setScale(2, RoundingMode.HALF_EVEN).doubleValue());
            checkoutRequest.setMerchantTransactionId(merchantTransactionId);
            checkoutRequest.setRequestDescription("Travel completion payment");
            checkoutRequest.setCallbackUrl(callbackPath + "/base/wxPayOrderTaxi");
@@ -1157,7 +1162,8 @@
            resultUtil = TinggPayUtil.checkoutRequest(checkoutRequest);
            if(resultUtil.getCode()==200){
                paymentRecordService.saveData(1, null, null, orderId, 4, 2, orderMoney, null, 1);//添加预支付数据
                paymentRecordService.saveData(1, null, null, orderId, 4, 2,
                        orderMoney.setScale(2, RoundingMode.HALF_EVEN).doubleValue(), null, 1);//添加预支付数据
            }else{
                resultUtil = ResultUtil.error(language == 1 ? "支付失败" : language == 2 ? "Payment failure" : "Paiement échoué", "");
            }
@@ -1165,11 +1171,11 @@
        }
        if(payType == 3){//余额支付
            if(userInfo.getBalance() == null || userInfo.getBalance() < orderMoney){
            if(userInfo.getBalance() == null || new BigDecimal(userInfo.getBalance()).compareTo(orderMoney) < 0){
                return ResultUtil.error(language == 1 ? "账户余额不足" : language == 2 ? "Insufficient balance" : "Solde insuffisant", "");
            }
            userInfo.setBalance(new BigDecimal(userInfo.getBalance()).subtract(new BigDecimal(orderMoney)).setScale(2, BigDecimal.ROUND_HALF_EVEN).doubleValue());
            userInfo.setBalance(new BigDecimal(userInfo.getBalance()).subtract(orderMoney).setScale(2, BigDecimal.ROUND_HALF_EVEN).doubleValue());
            SysIntegral query1 = sysIntegralMapper.query(orderLogistics.getCompanyId());
            userInfo.setIntegral(userInfo.getIntegral() + (orderMoney.intValue() * query1.getIntegral()));//积分
@@ -1182,12 +1188,13 @@
            }
            //添加交易明细
            transactionDetailsService.saveData(uid, "包裹下单支付", orderMoney, 2, 1, 1, 4, orderId);
            transactionDetailsService.saveData(uid, "包裹下单支付",
                    orderMoney.setScale(2, RoundingMode.HALF_EVEN).doubleValue(), 2, 1, 1, 4, orderId);
            userInfoService.updateById(userInfo);
            orderLogistics.setState(8);
            orderLogistics.setPayType(3);
            orderLogistics.setPayMoney(orderMoney);
            orderLogistics.setPayMoney(orderMoney.setScale(2, RoundingMode.HALF_EVEN).doubleValue());
    
            //处理优惠券和红包
            if(null != userCouponRecord){
@@ -1638,13 +1645,14 @@
            userInfo.setIntegral(userInfo.getIntegral() + (orderMoney.intValue() * query1.getIntegral()));//积分
            //添加交易明细
            transactionDetailsService.saveData(uid, "包裹下单支付", orderMoney, 2, 1, 1, 4, orderId);
            transactionDetailsService.saveData(uid, "包裹下单支付",
                    orderMoney.setScale(2, RoundingMode.HALF_EVEN).doubleValue(), 2, 1, 1, 4, orderId);
            userInfoService.updateById(userInfo);
            orderLogistics.setState(8);//小件物流先支付后司机抢单
            orderLogistics.setDriverPay(1);
            orderLogistics.setPayType(4);
            orderLogistics.setPayMoney(orderMoney);
            orderLogistics.setPayMoney(orderMoney.setScale(2, RoundingMode.HALF_EVEN).doubleValue());
    
            //处理优惠券和红包
            if(null != userCouponRecord){
@@ -1737,7 +1745,7 @@
                                    settlementRecord.setInsertTime(new Date());
                                    settlementRecordService.insert(settlementRecord);
                                }else{
                                    settlementRecord.setPayMoney(total.doubleValue());
                                    settlementRecord.setPayMoney(settlementRecord.getPayMoney() + total.doubleValue());
                                    settlementRecordService.updateById(settlementRecord);
                                }
                                for (SettlementDetail detail : settlementDetailList) {
@@ -3642,7 +3650,7 @@
                    Element user_chinese = document.getElementById("user_chinese");
                    user_chinese.text("您好 " + userInfo.getNickName() + ",");
                    Element time_chinese = document.getElementById("time_chinese");
                    time_chinese.text("此活动有效期在 " + DateUtil.conversionFormat(language, sdf.format(id.getStartTime())) + " 至 " + DateUtil.conversionFormat(language, sdf.format(id.getEnable())) + ",详情请查看I-GO平台");
                    time_chinese.text("此活动有效期在 " + DateUtil.conversionFormat(language, sdf.format(id.getStartTime())) + " 至 " + DateUtil.conversionFormat(language, sdf.format(id.getEndTime())) + ",详情请查看I-GO平台");
                }
                if(2 == language){
                    document.getElementById("chinese").remove();
@@ -3651,7 +3659,7 @@
                    Element user_english = document.getElementById("user_english");
                    user_english.text("Hello " + userInfo.getNickName() + ",");
                    Element time_english = document.getElementById("time_english");
                    time_english.text("You could use it from " + DateUtil.conversionFormat(language, sdf.format(id.getStartTime())) + " to " + DateUtil.conversionFormat(language, sdf.format(id.getEnable())) + ",check more details on the app.");
                    time_english.text("You could use it from " + DateUtil.conversionFormat(language, sdf.format(id.getStartTime())) + " to " + DateUtil.conversionFormat(language, sdf.format(id.getEndTime())) + ",check more details on the app.");
                }
                if(3 == language){
                    document.getElementById("chinese").remove();
@@ -3660,7 +3668,7 @@
                    Element user_french = document.getElementById("user_french");
                    user_french.text("Bonjour " + userInfo.getNickName() + ",");
                    Element time_french = document.getElementById("time_french");
                    time_french.text("Cette promotion est valable du " + DateUtil.conversionFormat(language, sdf.format(id.getStartTime())) + " au " + DateUtil.conversionFormat(language, sdf.format(id.getEnable())) + ". Veuillez consulter la plateforme i-go pour plus de détails.");
                    time_french.text("Cette promotion est valable du " + DateUtil.conversionFormat(language, sdf.format(id.getStartTime())) + " au " + DateUtil.conversionFormat(language, sdf.format(id.getEndTime())) + ". Veuillez consulter la plateforme i-go pour plus de détails.");
                }
                
                EmailUtil.send(userInfo.getEmail(), language == 1 ? "红包活动" : language == 2 ? "Lucky-promo activities" : "Activités bonus",  document.html());