Pu Zhibing
2025-04-25 fc5b7d2d48a90ffbd0d033598f12ee3d9c1625f7
UserIGOTravel/guns-admin/src/main/java/com/stylefeng/guns/modular/specialTrain/server/impl/OrderPrivateCarServiceImpl.java
@@ -1,5 +1,6 @@
package com.stylefeng.guns.modular.specialTrain.server.impl;
import cn.hutool.db.nosql.redis.RedisDS;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
@@ -59,6 +60,7 @@
import java.math.RoundingMode;
import java.text.SimpleDateFormat;
import java.util.*;
import java.util.concurrent.TimeUnit;
import java.util.stream.Collectors;
@@ -147,7 +149,7 @@
    @Resource
    private IUserActivityRedenvelopeService userActivityRedenvelopeService;
    @Resource
    private RedisUtil redisUtil;
@@ -1301,7 +1303,7 @@
        ResultUtil resultUtil = ResultUtil.success("");
        orderPrivateCar.setCouponMoney(0D);//初始化历史数据
        orderPrivateCar.setCouponId(null);
        //计算折扣
        UserActivityDiscount1 query2 = userActivityDiscount1Mapper.query(orderPrivateCar.getCompanyId());
        if(null != query2){
@@ -1320,7 +1322,7 @@
                }
            }
        }
        //计算优惠券
        UserCouponRecord userCouponRecord = null;
        if(null != couponId){
@@ -1347,7 +1349,7 @@
            orderPrivateCar.setCouponMoney(userCouponRecord.getMoney());
            orderPrivateCar.setCouponId(couponId);
        }
        //计算红包
        if(null != redDeduction && 1 == redDeduction && null == orderPrivateCar.getRedPacketId()){
            RedEnvelopePaymentSettings redEnvelopePaymentSettings = redEnvelopePaymentSettingsService.getRedEnvelopePaymentSettings();
@@ -1360,14 +1362,14 @@
                if(total > 0 && multiply1.doubleValue() > 0 && total.compareTo(multiply1.doubleValue()) >= 0){
                    orderPrivateCar.setRedPacketMoney(multiply1.doubleValue());
                    orderMoney = orderMoney.subtract(multiply1).setScale(2, RoundingMode.HALF_EVEN);
                    //获取红包id
                    JSONArray jsonArray = new JSONArray();
                    for (UserRedPacketRecord userRedPacketRecord : userRedPacketRecords) {
                        JSONObject jsonObject = new JSONObject();
                        jsonObject.put("id", userRedPacketRecord.getId());
                        BigDecimal remainingAmount = new BigDecimal(userRedPacketRecord.getRemainingAmount());
                        if(multiply1.compareTo(remainingAmount) >= 0){
                            userRedPacketRecord.setRemainingAmount(0D);
                            userRedPacketRecord.setEndTime(new Date());
@@ -1397,7 +1399,7 @@
                        jsonObject.put("id", userRedPacketRecord.getId());
                        jsonObject.put("money", userRedPacketRecord.getRemainingAmount());
                        jsonArray.add(jsonObject);
                        userRedPacketRecord.setRemainingAmount(0D);
                        userRedPacketRecord.setEndTime(new Date());
                        userRedPacketRecord.setState(2);
@@ -1409,8 +1411,8 @@
                }
            }
        }
        if(payType == 1){//手机支付
            SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMddHHmmssSSS");
            String merchantTransactionId = sdf.format(new Date()) + "1" + language + orderId;
@@ -1428,14 +1430,14 @@
            checkoutRequest.setSuccessRedirectUrl("https://igo.i-go.group/payMoney/pages/success.html");
            checkoutRequest.setFailRedirectUrl("https://igo.i-go.group/payMoney/pages/fail.html");
            resultUtil = TinggPayUtil.checkoutRequest(checkoutRequest);
            if(resultUtil.getCode()==200){
                paymentRecordService.saveData(1, null, null, orderId, 1, 1,
                        orderMoney.setScale(2, RoundingMode.HALF_EVEN).doubleValue(), null, 1);//添加预支付数据
            }else{
                resultUtil = ResultUtil.error(language == 1 ? "支付失败" : language == 2 ? "Payment failure" : "Paiement échoué", "");
            }
        }
        if(payType == 2){//银行卡支付
            BankCard bankCard = bankCardService.selectById(bankCardId);
@@ -1455,7 +1457,7 @@
            checkoutRequest.setSuccessRedirectUrl("https://igo.i-go.group/payMoney/pages/success.html");
            checkoutRequest.setFailRedirectUrl("https://igo.i-go.group/payMoney/pages/fail.html");
            resultUtil = TinggPayUtil.checkoutRequest(checkoutRequest);
            if(resultUtil.getCode()==200){
                paymentRecordService.saveData(1, null, null, orderId, 1, 2,
                        orderMoney.setScale(2, RoundingMode.HALF_EVEN).doubleValue(), null, 1);//添加预支付数据
@@ -1467,28 +1469,28 @@
            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(orderMoney).setScale(2, BigDecimal.ROUND_HALF_EVEN).doubleValue());
            SysIntegral query1 = sysIntegralMapper.query(orderPrivateCar.getCompanyId());
            userInfo.setIntegral(userInfo.getIntegral() + (orderMoney.intValue() * query1.getIntegral()));//积分
            //添加交易明细
            transactionDetailsService.saveData(uid, "完成订单", orderMoney.setScale(2, RoundingMode.HALF_EVEN).doubleValue(),
                    2, 1, 1, 1, orderId);
            userInfoService.updateById(userInfo);
            orderPrivateCar.setState(8);
            orderPrivateCar.setPayType(3);
            orderPrivateCar.setPayMoney(orderMoney.setScale(2, RoundingMode.HALF_EVEN).doubleValue());
            //处理优惠券和红包
            if(null != userCouponRecord){
                userCouponRecord.setState(2);
                userCouponRecord.setEndTime(new Date());
                userCouponRecordService.updateById(userCouponRecord);
            }
            //添加已收入明细
            Company company = companyService.selectById(orderPrivateCar.getCompanyId());
            Double speMoney = company.getSpeMoney();
@@ -1510,7 +1512,7 @@
            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);
            if(ToolUtil.isNotEmpty(userInfo.getEmail())){
                new Thread(new Runnable() {
                    @Override
@@ -1850,7 +1852,7 @@
                                server_tel_french.attr("href", "tel:" + (null != phone ? phone.getPhone() : ""));
                            }
                            EmailUtil.send(userInfo.getEmail(), language == 1 ? "打车收据" : language == 2 ? "Ride receipt" : "Reçu de course",  document.html());
                            //开始生成pdf收据和html收据
                            File file = new File("/home/igotechgh/nginx/html/files/html/");
                            if(!file.exists()){
@@ -1864,7 +1866,7 @@
                            fileWriter.write(document.html());
                            fileWriter.flush();
                            fileWriter.close();
                            File file1 = new File("/home/igotechgh/nginx/html/files/pdf/");
                            if(!file1.exists()){
                                file1.mkdirs();
@@ -1880,7 +1882,7 @@
                                e.printStackTrace();
                                System.out.println("html转pdf异常");
                            }
                            String link ="https://igo.i-go.group/files/html/ride_receipt_" + orderId + ".html";
                            TEmail tEmail = new TEmail();
                            tEmail.setLink(link);
@@ -1898,18 +1900,18 @@
                                tEmail.setAmOrPm(language==1?"下午":language==2?"afternoon":"après-midi");
                            }
                            emailService.insert(tEmail);
                        }catch (Exception e){
                            e.printStackTrace();
                        }
                    }
                }).start();
            }
            // TODO: 2020/5/24 这里需要给司机和用户推送订单状态
            new Thread(new Runnable() {
                @Override
@@ -1918,7 +1920,7 @@
                    pushUtil.pushOrderState(2, orderPrivateCar.getDriverId(), orderPrivateCar.getId(), 1, orderPrivateCar.getState(), 0, "");
                }
            }).start();
            systemNoticeService.addSystemNotice(1, language == 1 ? "您已成功完成出行订单支付,谢谢使用!" : language == 2
                    ? "You've paid for the ride order successfully, thank you for using I-GO"
                    : "Vous avez payé la commande de course avec succès, merci d’utiliser I-GO", orderPrivateCar.getUserId(), 1);
@@ -1926,19 +1928,19 @@
        if(payType == 4){//现金支付
            SysIntegral query1 = sysIntegralMapper.query(orderPrivateCar.getCompanyId());
            userInfo.setIntegral(userInfo.getIntegral() + (orderMoney.intValue() * query1.getIntegral()));//积分
            //添加交易明细
            transactionDetailsService.saveData(uid, "完成订单", orderMoney.setScale(2, RoundingMode.HALF_EVEN).doubleValue(),
                    2, 1, 1, 1, orderId);
            userInfoService.updateById(userInfo);
            orderPrivateCar.setState(8);
            orderPrivateCar.setPayType(4);
            orderPrivateCar.setDriverPay(2);
            orderPrivateCar.setPayMoney(orderMoney.setScale(2, RoundingMode.HALF_EVEN).doubleValue());
            Driver driver = driverService.selectById(orderPrivateCar.getDriverId());
            //处理优惠券和红包
            if(null != userCouponRecord){
                userCouponRecord.setState(2);
@@ -1952,7 +1954,7 @@
                driver.setBalance(new BigDecimal(null != driver.getBalance() ? driver.getBalance() : 0).add(new BigDecimal(money)).setScale(2, BigDecimal.ROUND_HALF_EVEN).doubleValue());
                driverService.updateById(driver);
            }
            if(null != orderPrivateCar.getRedPacketId()){
                Double money = orderPrivateCar.getRedPacketMoney();
                incomeService.saveData(2, orderPrivateCar.getDriverId(), 7, orderPrivateCar.getId(), 1, money);
@@ -1961,7 +1963,7 @@
                driver.setBalance(new BigDecimal(null != driver.getBalance() ? driver.getBalance() : 0).add(new BigDecimal(money)).setScale(2, BigDecimal.ROUND_HALF_EVEN).doubleValue());
                driverService.updateById(driver);
            }
            if(null != orderPrivateCar.getDiscountMoney() && 0 < orderPrivateCar.getDiscountMoney()){
                Double money = orderPrivateCar.getDiscountMoney();
                incomeService.saveData(2, orderPrivateCar.getDriverId(), 6, orderPrivateCar.getId(), 1, money);
@@ -1970,8 +1972,8 @@
                driver.setBalance(new BigDecimal(null != driver.getBalance() ? driver.getBalance() : 0).add(new BigDecimal(money)).setScale(2, BigDecimal.ROUND_HALF_EVEN).doubleValue());
                driverService.updateById(driver);
            }
            //添加已收入明细
            Company company = companyService.selectById(orderPrivateCar.getCompanyId());
            Double speMoney = company.getSpeMoney();
@@ -1993,8 +1995,8 @@
//                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);
            //记录司机待结算金额
            if(d.compareTo(new BigDecimal(0)) > 0){
                SettlementDetail settlementDetail = new SettlementDetail();
@@ -2005,7 +2007,7 @@
                settlementDetail.setPrice(d.doubleValue());
                settlementDetail.setCreateTime(new Date());
                settlementDetailService.insert(settlementDetail);
                SettlementAllocation settlementAllocation = settlementAllocationService.selectOne(null);
                if(null != settlementAllocation){
                    JSONObject jsonObject = JSON.parseObject(settlementAllocation.getContent());
@@ -2053,7 +2055,7 @@
                                    car.setVehicleId(UUIDUtil.getRandomCode());
                                    carService.updateById(car);
                                }
                                //司机下班,修改谷歌上的车辆信息
                                new Thread(()->{
                                    try {
@@ -2101,7 +2103,7 @@
                    }
                }
            }
            if(ToolUtil.isNotEmpty(userInfo.getEmail())){
                new Thread(new Runnable() {
                    @Override
@@ -2440,9 +2442,9 @@
                                Element server_tel_french = document.getElementById("server_tel_french");
                                server_tel_french.attr("href", "tel:" + (null != phone ? phone.getPhone() : ""));
                            }
                            EmailUtil.send(userInfo.getEmail(), language == 1 ? "打车收据" : language == 2 ? "Ride receipt" : "Reçu de course",  document.html());
                            //开始生成pdf收据和html收据
                            File file = new File("/home/igotechgh/nginx/html/files/html/");
                            if(!file.exists()){
@@ -2456,7 +2458,7 @@
                            fileWriter.write(document.html());
                            fileWriter.flush();
                            fileWriter.close();
                            File file1 = new File("/home/igotechgh/nginx/html/files/pdf/");
                            if(!file1.exists()){
                                file1.mkdirs();
@@ -2489,17 +2491,17 @@
                                tEmail.setAmOrPm(language==1?"下午":language==2?"afternoon":"après-midi");
                            }
                            emailService.insert(tEmail);
                        }catch (Exception e){
                            e.printStackTrace();
                        }
                    }
                }).start();
            }
            // TODO: 2020/5/24 这里需要给司机和用户推送订单状态
            new Thread(new Runnable() {
                @Override
@@ -2518,7 +2520,7 @@
                        case 3:
                            text = "Le client a choisi de payer en espèces, vous devez donc encaisser le paiement.Confirmez si vous avez reçu les frais pour cette commande : Espèces GHS " + orderPrivateCar.getPayMoney();
                            break;
                    }
                    String audioUrl = "";
                    String fileName = "offlinePayment" + orderPrivateCar.getDriverId() + UUIDUtil.getRandomCode(5) + ".mp3";
@@ -2552,12 +2554,12 @@
                    pushUtil.pushOfflinePayment(2, orderPrivateCar.getDriverId(), orderPrivateCar.getId(), 1, orderPrivateCar.getPayMoney(), audioUrl);
                }
            }).start();
            systemNoticeService.addSystemNotice(1, language == 1 ? "您已成功完成出行订单支付,谢谢使用!" : language == 2
                    ? "You've paid for the ride order successfully, thank you for using I-GO"
                    : "Vous avez payé la commande de course avec succès, merci d’utiliser I-GO", orderPrivateCar.getUserId(), 1);
        }
        this.updateAllColumnById(orderPrivateCar);
        return resultUtil;
    }