zhibing.pu
2024-09-04 13d2bd6a27f941cfd8f096a7ae2def858a565363
UserIGOTravel/guns-admin/src/main/java/com/stylefeng/guns/modular/smallLogistics/server/impl/OrderLogisticsServiceImpl.java
@@ -1045,13 +1045,13 @@
        }
    
        //计算红包
        if(null != redDeduction && 1 == redDeduction){
        if(null != redDeduction && 1 == redDeduction && null == orderLogistics.getRedPacketId()){
            RedEnvelopePaymentSettings redEnvelopePaymentSettings = redEnvelopePaymentSettingsService.getRedEnvelopePaymentSettings();
            if(null != redEnvelopePaymentSettings){
                Double total = userRedPacketRecordService.queryRemainingAmount(uid);
                List<UserRedPacketRecord> userRedPacketRecords = userRedPacketRecordService.selectList(new EntityWrapper<UserRedPacketRecord>().eq("userId", uid)
                        .eq("state", 1).eq("companyId", orderLogistics.getCompanyId()).gt("remainingAmount", 0).orderBy("insertTime", false));
                BigDecimal deductionRatio = redEnvelopePaymentSettings.getDeductionRatio();
                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){
@@ -1061,12 +1061,12 @@
                    //获取红包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(BigDecimal.ZERO) == 0){
                            break;
                        }
                        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());
@@ -1074,14 +1074,15 @@
                            multiply1 = multiply1.subtract(remainingAmount).setScale(2, RoundingMode.HALF_EVEN);
                            jsonObject.put("money", remainingAmount);
                            jsonArray.add(jsonObject);
                            userRedPacketRecordService.updateById(userRedPacketRecord);
                        }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);
                            multiply1 = BigDecimal.ZERO;
                        }
                    }
                    if(userRedPacketRecords.size() > 0){
                        userRedPacketRecordService.updateBatchById(userRedPacketRecords);
                    }
                    orderLogistics.setRedPacketId(jsonArray.toJSONString());
                }
@@ -1090,29 +1091,18 @@
                    orderMoney = orderMoney.subtract(new BigDecimal(total)).setScale(2, RoundingMode.HALF_EVEN);
                    //获取红包id
                    JSONArray jsonArray = new JSONArray();
                    BigDecimal multiply = new BigDecimal(total);
                    for (UserRedPacketRecord userRedPacketRecord : userRedPacketRecords) {
                        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());
                            userRedPacketRecord.setState(2);
                            multiply = multiply.subtract(remainingAmount).setScale(2, RoundingMode.HALF_EVEN);
                            jsonObject.put("money", remainingAmount);
                            jsonArray.add(jsonObject);
                            userRedPacketRecordService.updateById(userRedPacketRecord);
                        }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);
                            multiply = BigDecimal.ZERO;
                        }
                        jsonObject.put("money", userRedPacketRecord.getRemainingAmount());
                        jsonArray.add(jsonObject);
                        userRedPacketRecord.setRemainingAmount(0D);
                        userRedPacketRecord.setEndTime(new Date());
                        userRedPacketRecord.setState(2);
                    }
                    if(userRedPacketRecords.size() > 0){
                        userRedPacketRecordService.updateBatchById(userRedPacketRecords);
                    }
                    orderLogistics.setRedPacketId(jsonArray.toJSONString());
                }