liujie
2025-08-22 fa4d91768a990d5e8b759300a1271b12f54c10ca
UserOKTravel/guns-admin/src/main/java/com/stylefeng/guns/modular/smallLogistics/server/impl/OrderLogisticsServiceImpl.java
@@ -105,6 +105,9 @@
    private static List<Integer> orderIds = new ArrayList<>();
    @Autowired
    private PayMoneyUtil payMoneyUtil;
    /**
@@ -122,7 +125,7 @@
            return ResultUtil.error("收货地址有误,无法查询具体地址信息");
        }
        List<String> list = (List<String>)geocoding.get("data");
        Map<String, String> egeocode = gdMapGeocodingUtil.geocode(list.get(0).split(",")[0], list.get(0).split(",")[1]);
        Map<String, String> egeocode = gdMapGeocodingUtil.geocode(list.get(0).split(",")[1], list.get(0).split(",")[0]);
        String ecityCode = egeocode.get("cityCode");
        if(!scityCode.equals(ecityCode)){
            return ResultUtil.error("已超出服务范围,请重新选择跨城小件物流");
@@ -141,14 +144,14 @@
     */
    @Override
    public ResultUtil queryLogisticsUnitPrice(Integer type, String startLonLat, String endAddress, Integer uid) throws Exception {
        Company query = companyCityService.query(startLonLat.split(",")[0], startLonLat.split(",")[1]);
        if(null == query){
            return ResultUtil.error("预约取货点暂无企业服务");
        }
//        Company query = companyCityService.query(startLonLat.split(",")[0], startLonLat.split(",")[1]);
//        if(null == query){
//            return ResultUtil.error("预约取货点暂无企业服务");
//        }
        Double price1 = 0D;
        Double price2 = 0D;
        if(type == 4){//同城
            Map<String, Object> query1 = systemPriceMapper.query(query.getId(), type, null);
            Map<String, Object> query1 = systemPriceMapper.query(1, type, null);
            if(null == query1){
                return ResultUtil.error("请先完善价格设定");
            }
@@ -157,7 +160,7 @@
            price1 = jsonObject.getDouble("num2");
            price2 = jsonObject.getDouble("num13");
        }else{
            Map<String, Object> query1 = systemPriceMapper.query(query.getId(), type, null);
            Map<String, Object> query1 = systemPriceMapper.query(1, type, null);
            if(null == query1){
                return ResultUtil.error("请先完善价格设定");
            }
@@ -264,7 +267,7 @@
        orderLogistics.setMileage(0D);
        orderLogistics.setIsReassign(1);
        orderLogistics.setReassignNotice(0);
        ResultUtil<Map<String, Double>> price = this.getPrice(type, String.valueOf(startLon), String.valueOf(startLat), location.split(",")[0], location.split(",")[1]);
        ResultUtil<Map<String, Double>> price = this.getPrice(type, String.valueOf(startLat), String.valueOf(startLon), location.split(",")[0], location.split(",")[1]);
        if(price.getCode() != 200){
            return price;
        }
@@ -299,14 +302,14 @@
     * @throws Exception
     */
    public ResultUtil<Map<String, Double>> getPrice(Integer type, String startLon, String startLat, String endLon, String endLat) throws Exception{
        Company query = companyCityService.query(startLon, startLat);
        if(null == query){
            return ResultUtil.error("预约取货点暂无企业服务");
        }
//        Company query = companyCityService.query(startLon, startLat);
//        if(null == query){
//            return ResultUtil.error("预约取货点暂无企业服务");
//        }
        Double price1 = 0D;
        Double price2 = 0D;
        if(type == 4){//同城
            Map<String, Object> query1 = systemPriceMapper.query(query.getId(), type, null);
            Map<String, Object> query1 = systemPriceMapper.query(1, type, null);
            Map<String, String> distance = gdMapElectricFenceUtil.getDistance(startLon + "," + startLat, endLon + "," + endLat, 1);
            String content = String.valueOf(query1.get("content"));
            JSONObject jsonObject = JSON.parseObject(content);
@@ -340,7 +343,7 @@
                price2 = jsonObject.getDouble("num22");
            }
        }else{
            Map<String, Object> query1 = systemPriceMapper.query(query.getId(), type, null);
            Map<String, Object> query1 = systemPriceMapper.query(1, type, null);
            String content = String.valueOf(query1.get("content"));
            JSONObject jsonObject = JSON.parseObject(content);
            price1 = jsonObject.getDouble("num1");
@@ -371,9 +374,9 @@
                        integers = JSON.parseArray(vehicle).toJavaList(Integer.class);
                    }
                    Company query = companyCityService.query(String.valueOf(orderLogistics.getStartLon()), String.valueOf(orderLogistics.getStartLat()));//获取起点所属分公司
                    List<PushOrder> querys = pushOrderService.querys(null, 1, query.getId());//用专车的推单配置
                    List<PushOrder> querys = pushOrderService.querys(null, 2, query.getId());//用专车的推单配置
                    for(int i = 1; i <= querys.size(); i++){
                        PushOrder pushOrder = pushOrderService.querys(i, 1, query.getId()).get(0);
                        PushOrder pushOrder = pushOrderService.querys(i, 2, query.getId()).get(0);
                        //获取空闲司机
                        List<Driver> list = driverService.queryIdleDriver(orderLogistics.getType(), null, orderLogistics.getStartLon(), orderLogistics.getStartLat(), pushOrder.getPushDistance(), null);//所有附近空闲司机
                        if(list.size() > 0){
@@ -434,21 +437,10 @@
        ResultUtil resultUtil = ResultUtil.success("");
        if(payType == 1){//微信支付
            String value = redisUtil.getValue("appletOpenId");
            String appletsOpenId = null;
            if(ToolUtil.isNotEmpty(value)){
                JSONObject jsonObject = JSON.parseObject(value);
                appletsOpenId = jsonObject.getString(uid.toString());
            }else{
                appletsOpenId = userInfo.getAppletsOpenId();
            }
            Map<String, String> map = icbcPayUtil.placeAnOrder(orderId + "," + orderLogistics.getType(), 9, 5, uid.toString(), "小件物流下单支付", orderMoney, callbackPath + "/base/wxPayOrderTaxi", "", type, appletsOpenId);
            if(map.get("code").equals("200")){
                paymentRecordService.saveData(1, orderLogistics.getUserId(), 1, orderId, orderLogistics.getType(), 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 + "_4_" + UUIDUtil.getRandomCode(5), orderMoney.toString(), "/base/wxPayOrderTaxi", app, userInfo.getAppletsOpenId());
            paymentRecordService.saveData(1, orderLogistics.getUserId(), 1, orderId, 4, 1, Double.valueOf(orderMoney.toString()), "", 1);//添加预支付数据
        }
        if(payType == 2){//支付宝支付
            Map<String, String> map = icbcPayUtil.placeAnOrder(orderId + "," + orderLogistics.getType(), 10, 5, uid.toString(), "小件物流下单支付", orderMoney, callbackPath + "/base/aliPayOrderTaxi", "", type, null);
@@ -466,8 +458,8 @@
            userInfo.setBalance(new BigDecimal(userInfo.getBalance()).subtract(new BigDecimal(orderMoney)).setScale(2, BigDecimal.ROUND_HALF_EVEN).doubleValue());
            SysIntegral query1 = sysIntegralMapper.query(orderLogistics.getCompanyId());
            userInfo.setIntegral(userInfo.getIntegral() + (orderMoney.intValue() * query1.getIntegral()));//积分
//            SysIntegral query1 = sysIntegralMapper.query(orderLogistics.getCompanyId());
//            userInfo.setIntegral(userInfo.getIntegral() + (orderMoney.intValue() * query1.getIntegral()));//积分
            //添加交易明细
            transactionDetailsService.saveData(uid, "小件物流下单支付", orderMoney, 2, 1, 1, 4, orderId);
@@ -515,21 +507,10 @@
        ResultUtil resultUtil = ResultUtil.success("");
        if(payType == 1){//微信支付
            String value = redisUtil.getValue("appletOpenId");
            String appletsOpenId = null;
            if(ToolUtil.isNotEmpty(value)){
                JSONObject jsonObject = JSON.parseObject(value);
                appletsOpenId = jsonObject.getString(uid.toString());
            }else{
                appletsOpenId = userInfo.getAppletsOpenId();
            }
            Map<String, String> map = icbcPayUtil.placeAnOrder(orderId + "," + orderLogistics.getType(), 9, 5, uid.toString(), "小件物流补差价", orderMoney, callbackPath + "/base/wxPayOrderLogisticsSpread", "", type, appletsOpenId);
            if(map.get("code").equals("200")){
                paymentRecordService.saveData(1, orderLogistics.getUserId(), 1, orderId, orderLogistics.getType(), 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 + "_4_" + UUIDUtil.getRandomCode(5), orderMoney.toString(), "/base/wxPayOrderLogisticsSpread", app, userInfo.getAppletsOpenId());
            paymentRecordService.saveData(1, orderLogistics.getUserId(), 1, orderId, orderLogistics.getType(), 1, orderMoney, orderLogistics.getId().toString(), 1);//添加预支付数据
        }
        if(payType == 2){//支付宝支付
            Map<String, String> map = icbcPayUtil.placeAnOrder(orderId + "," + orderLogistics.getType(), 10, 5, uid.toString(), "小件物流补差价", orderMoney, callbackPath + "/base/aliPayOrderLogisticsSpread", "", type, null);
@@ -622,10 +603,10 @@
            orderLogistics.setPayMoney(query.getAmount());
            this.updateById(orderLogistics);
            UserInfo userInfo = userInfoService.selectById(orderLogistics.getUserId());
            SysIntegral query1 = sysIntegralMapper.query(orderLogistics.getCompanyId());
            userInfo.setIntegral(userInfo.getIntegral() + (query.getAmount().intValue() * query1.getIntegral()));//积分
            userInfoService.updateById(userInfo);
//            UserInfo userInfo = userInfoService.selectById(orderLogistics.getUserId());
//            SysIntegral query1 = sysIntegralMapper.query(orderLogistics.getCompanyId());
//            userInfo.setIntegral(userInfo.getIntegral() + (query.getAmount().intValue() * query1.getIntegral()));//积分
//            userInfoService.updateById(userInfo);
            query.setState(2);
            query.setCode(order_id);
@@ -669,39 +650,16 @@
            orderLogisticsSpread.setPayType(3);
            orderLogisticsSpreadService.updateById(orderLogisticsSpread);
            UserInfo userInfo = userInfoService.selectById(orderLogistics.getUserId());
            SysIntegral query1 = sysIntegralMapper.query(orderLogistics.getCompanyId());
            userInfo.setIntegral(userInfo.getIntegral() + (query.getAmount().intValue() * query1.getIntegral()));//积分
            userInfoService.updateById(userInfo);
//            UserInfo userInfo = userInfoService.selectById(orderLogistics.getUserId());
//            SysIntegral query1 = sysIntegralMapper.query(orderLogistics.getCompanyId());
//            userInfo.setIntegral(userInfo.getIntegral() + (query.getAmount().intValue() * query1.getIntegral()));//积分
//            userInfoService.updateById(userInfo);
            query.setState(2);
            query.setCode(order_id);
            paymentRecordService.updateById(query);
            //添加已收入明细
            Company company = companyService.selectById(orderLogistics.getCompanyId());
            Double speMoney =  orderLogistics.getType() == 4 ? company.getSameLogisticsMoney() : company.getCrossLogisticsMoney();
            BigDecimal d = null;
            BigDecimal c = null;
            if(company.getIsSpeFixedOrProportional() == 2){//固定
                d = new BigDecimal(speMoney);
                c = new BigDecimal(query.getAmount()).subtract(d).setScale(2, BigDecimal.ROUND_HALF_EVEN);
            }
            if(company.getIsSpeFixedOrProportional() == 1){//比例
                d = new BigDecimal(query.getAmount()).multiply(new BigDecimal(speMoney).divide(new BigDecimal(100))).setScale(2, BigDecimal.ROUND_HALF_EVEN);
                c = new BigDecimal(query.getAmount()).subtract(d).setScale(2, BigDecimal.ROUND_HALF_EVEN);
            }
            Income income = incomeService.selectOne(new EntityWrapper<Income>().eq("userType", 1).eq("objectId", orderLogistics.getCompanyId()).eq("type", 2).eq("incomeId", orderLogistics.getId()).eq("orderType", orderLogistics.getType()));
            income.setMoney(income.getMoney() + d.doubleValue());
            incomeService.updateById(income);
            income = incomeService.selectOne(new EntityWrapper<Income>().eq("userType", 2).eq("objectId", orderLogistics.getDriverId()).eq("type", 2).eq("incomeId", orderLogistics.getId()).eq("orderType", orderLogistics.getType()));
            income.setMoney(income.getMoney() + c.doubleValue());
            incomeService.updateById(income);
            Driver driver = driverService.selectById(orderLogistics.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() {
@@ -812,25 +770,12 @@
                userInfoService.updateById(userInfo);
            }else{
                //调用回退接口
                PaymentRecord query = paymentRecordService.query(1, orderLogistics.getUserId(), 1, orderLogistics.getId(), orderLogistics.getType(), orderLogistics.getPayType(), 2);
                boolean b = false;
                Map<String, Object> merrefund = icbcPayUtil.merrefund(query.getCode(), "", query.getAmount(), orderLogistics.getId() + "_" + orderLogistics.getType(), orderLogistics.getOrderNum());
                if (Integer.valueOf(merrefund.get("code").toString()) == 0) {
                    Map<String, Object> refundqry = icbcPayUtil.refundqry("", query.getCode(), orderLogistics.getOrderNum());
                    if (Integer.valueOf(refundqry.get("code").toString()) == 0 && Integer.valueOf(refundqry.get("pay_status").toString()) == 0) {//成功
                        b = true;
                    }
                    if (Integer.valueOf(refundqry.get("code").toString()) == 0 && Integer.valueOf(refundqry.get("pay_status").toString()) == 1) {//失败
                        return ResultUtil.error("订单取消失败(退款不成功)");
                    }
                    if (Integer.valueOf(refundqry.get("code").toString()) == 0 && Integer.valueOf(refundqry.get("pay_status").toString()) == 2) {//未知
                        return ResultUtil.error("退款返回未知异常");
                    }
                PaymentRecord query = paymentRecordService.query(1, orderLogistics.getUserId(), 1, id, 4, orderLogistics.getPayType(), 2);
                if(null == query){
                    return ResultUtil.error("订单还未进行支付");
                }
                if(b){
                }
                Map<String, String> merrefund = payMoneyUtil.wxRefund(query.getCode(), orderLogistics.getOrderNum(), String.valueOf(query.getAmount()), String.valueOf(query.getAmount()), "");
                System.err.println("跨城退款数据:::"+merrefund);
            }
            //添加交易明细
            transactionDetailsService.saveData(orderLogistics.getUserId(), "小件物流取消退款", orderLogistics.getPayMoney(), 1, 1, 1, 4, orderLogistics.getId());