| | |
| | | } |
| | | |
| | | //计算红包 |
| | | 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); |
| | |
| | | //获取红包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()); |
| | |
| | | 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()); |
| | | } |
| | |
| | | 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){ |
| | | jsonObject.put("money", userRedPacketRecord.getRemainingAmount()); |
| | | jsonArray.add(jsonObject); |
| | | |
| | | 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; |
| | | } |
| | | if(userRedPacketRecords.size() > 0){ |
| | | userRedPacketRecordService.updateBatchById(userRedPacketRecords); |
| | | } |
| | | orderLogistics.setRedPacketId(jsonArray.toJSONString()); |
| | | } |