Commit 7a8b7439 by 吕明尚

增加月卡时长和钱包时长混和使用

parent ea269889
...@@ -46,6 +46,8 @@ public class ConsumerMonthlyCardServiceImpl extends ServiceImpl<ConsumerMonthlyC ...@@ -46,6 +46,8 @@ public class ConsumerMonthlyCardServiceImpl extends ServiceImpl<ConsumerMonthlyC
private IPackService packService; private IPackService packService;
@Autowired @Autowired
private ISRoomService roomService; private ISRoomService roomService;
@Autowired
private ConsumerWalletService consumerWalletService;
/** /**
* 查询用户月卡 * 查询用户月卡
...@@ -128,12 +130,14 @@ public class ConsumerMonthlyCardServiceImpl extends ServiceImpl<ConsumerMonthlyC ...@@ -128,12 +130,14 @@ public class ConsumerMonthlyCardServiceImpl extends ServiceImpl<ConsumerMonthlyC
SConsumer user = sConsumerService.getInfo(); SConsumer user = sConsumerService.getInfo();
ConsumerMember consumerMember = consumerMemberService.getOne(new LambdaQueryWrapper<ConsumerMember>().eq(ConsumerMember::getConsumerId, user.getId()).eq(ConsumerMember::getIsRights ConsumerMember consumerMember = consumerMemberService.getOne(new LambdaQueryWrapper<ConsumerMember>().eq(ConsumerMember::getConsumerId, user.getId()).eq(ConsumerMember::getIsRights
, YesNoEnum.yes.getIndex())); , YesNoEnum.yes.getIndex()));
ConsumerWallet consumerWallet = consumerWalletService.getOne(new LambdaQueryWrapper<ConsumerWallet>().eq(ConsumerWallet::getConsumerId, user.getId()));
ConsumerMonthlyCard consumerMonthlyCard = null; ConsumerMonthlyCard consumerMonthlyCard = null;
List<ConsumerSecondaryCard> consumerSecondaryCard = null; List<ConsumerSecondaryCard> consumerSecondaryCard = null;
MonthlyCardResponse map = new MonthlyCardResponse(); MonthlyCardResponse map = new MonthlyCardResponse();
List<ConsumerMonthlyCard> consumerMonthlyCardList = new ArrayList<>(); List<ConsumerMonthlyCard> consumerMonthlyCardList = new ArrayList<>();
List<ConsumerSecondaryCard> consumerSecondaryCardList = new ArrayList<>(); List<ConsumerSecondaryCard> consumerSecondaryCardList = new ArrayList<>();
//可用时长
BigDecimal freeDuration = consumerWallet.getRemainingDuration();
if (ObjectUtil.isNotEmpty(consumerMember)) { if (ObjectUtil.isNotEmpty(consumerMember)) {
SRoom room = roomService.getById(monthlyCardRequest.getRoomId()); SRoom room = roomService.getById(monthlyCardRequest.getRoomId());
consumerMonthlyCard = baseMapper.selectOne(new LambdaQueryWrapper<ConsumerMonthlyCard>().eq(ConsumerMonthlyCard::getConsumerId, user.getId()).gt(ConsumerMonthlyCard::getFreeDuration, 0)); consumerMonthlyCard = baseMapper.selectOne(new LambdaQueryWrapper<ConsumerMonthlyCard>().eq(ConsumerMonthlyCard::getConsumerId, user.getId()).gt(ConsumerMonthlyCard::getFreeDuration, 0));
...@@ -142,6 +146,7 @@ public class ConsumerMonthlyCardServiceImpl extends ServiceImpl<ConsumerMonthlyC ...@@ -142,6 +146,7 @@ public class ConsumerMonthlyCardServiceImpl extends ServiceImpl<ConsumerMonthlyC
.gt(ConsumerSecondaryCard::getNumber, 0) .gt(ConsumerSecondaryCard::getNumber, 0)
.orderByAsc(ConsumerSecondaryCard::getNumber) .orderByAsc(ConsumerSecondaryCard::getNumber)
); );
freeDuration = freeDuration.add(consumerMonthlyCard.getFreeDuration());
if (!ObjectUtils.isEmpty(monthlyCardRequest.getRoomLabelId())) { if (!ObjectUtils.isEmpty(monthlyCardRequest.getRoomLabelId())) {
RoomLabel roomLabel = roomLabelService.selectRoomLabelById(monthlyCardRequest.getRoomLabelId()); RoomLabel roomLabel = roomLabelService.selectRoomLabelById(monthlyCardRequest.getRoomLabelId());
Label label = labelService.getById(roomLabel.getLabelId()); Label label = labelService.getById(roomLabel.getLabelId());
...@@ -179,7 +184,7 @@ public class ConsumerMonthlyCardServiceImpl extends ServiceImpl<ConsumerMonthlyC ...@@ -179,7 +184,7 @@ public class ConsumerMonthlyCardServiceImpl extends ServiceImpl<ConsumerMonthlyC
} }
}); });
} }
if (ObjectUtil.isNotEmpty(consumerMonthlyCard) && consumerMonthlyCard.getFreeDuration().compareTo(new BigDecimal(byId.getDuration())) >= 0) { if (ObjectUtil.isNotEmpty(consumerMonthlyCard) && freeDuration.compareTo(new BigDecimal(byId.getDuration())) >= 0) {
consumerMonthlyCardList.add(consumerMonthlyCard); consumerMonthlyCardList.add(consumerMonthlyCard);
map.setConsumerMonthlyCard(consumerMonthlyCardList); map.setConsumerMonthlyCard(consumerMonthlyCardList);
} }
...@@ -218,7 +223,7 @@ public class ConsumerMonthlyCardServiceImpl extends ServiceImpl<ConsumerMonthlyC ...@@ -218,7 +223,7 @@ public class ConsumerMonthlyCardServiceImpl extends ServiceImpl<ConsumerMonthlyC
} }
}); });
} }
if (ObjectUtil.isNotEmpty(consumerMonthlyCard) && consumerMonthlyCard.getFreeDuration().compareTo(new BigDecimal(pack.getDuration())) >= 0) { if (ObjectUtil.isNotEmpty(consumerMonthlyCard) && freeDuration.compareTo(new BigDecimal(pack.getDuration())) >= 0) {
consumerMonthlyCardList.add(consumerMonthlyCard); consumerMonthlyCardList.add(consumerMonthlyCard);
map.setConsumerMonthlyCard(consumerMonthlyCardList); map.setConsumerMonthlyCard(consumerMonthlyCardList);
} }
......
...@@ -528,11 +528,10 @@ public class SOrderServiceImpl extends ServiceImpl<SOrderMapper, SOrder> impleme ...@@ -528,11 +528,10 @@ public class SOrderServiceImpl extends ServiceImpl<SOrderMapper, SOrder> impleme
//退款 //退款
if (sOrder.getPayType().equals(PayTypeEnum.WECHAT.getCode())) { if (sOrder.getPayType().equals(PayTypeEnum.WECHAT.getCode())) {
try { try {
if (!ObjectUtils.isEmpty(sOrder.getMonthlyCardId()) || !ObjectUtils.isEmpty(sOrder.getSecondaryCardId())) { if (!ObjectUtils.isEmpty(sOrder.getSecondaryCardId())) {
refundExtracted(consumerMonthlyCard, sOrder, consumerSecondaryCard); refundExtracted(sOrder, consumerSecondaryCard);
} else {
refundExtracted(consumerWallet, sOrder, consumerMember);
} }
refundExtracted(consumerWallet, sOrder, consumerMember, consumerMonthlyCard);
orderRefundService.refundOp(request, sOrder); orderRefundService.refundOp(request, sOrder);
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
...@@ -540,11 +539,10 @@ public class SOrderServiceImpl extends ServiceImpl<SOrderMapper, SOrder> impleme ...@@ -540,11 +539,10 @@ public class SOrderServiceImpl extends ServiceImpl<SOrderMapper, SOrder> impleme
} }
} }
} else { } else {
if (!ObjectUtils.isEmpty(sOrder.getMonthlyCardId()) || !ObjectUtils.isEmpty(sOrder.getSecondaryCardId())) { if (!ObjectUtils.isEmpty(sOrder.getSecondaryCardId())) {
refundExtracted(consumerMonthlyCard, sOrder, consumerSecondaryCard); refundExtracted(sOrder, consumerSecondaryCard);
} else {
refundExtracted(consumerWallet, sOrder, consumerMember);
} }
refundExtracted(consumerWallet, sOrder, consumerMember, consumerMonthlyCard);
sOrder.setStatus(OrderStatusEnum.CANCEL.getCode()); sOrder.setStatus(OrderStatusEnum.CANCEL.getCode());
sOrder.setRefundStatus(RefundStatusEnum.REFUNDED.getCode()); sOrder.setRefundStatus(RefundStatusEnum.REFUNDED.getCode());
sOrder.setRefundReasonTime(cn.hutool.core.date.DateUtil.date()); sOrder.setRefundReasonTime(cn.hutool.core.date.DateUtil.date());
...@@ -992,10 +990,10 @@ public class SOrderServiceImpl extends ServiceImpl<SOrderMapper, SOrder> impleme ...@@ -992,10 +990,10 @@ public class SOrderServiceImpl extends ServiceImpl<SOrderMapper, SOrder> impleme
response.setOrderNo(sOrder.getOrderNo()); response.setOrderNo(sOrder.getOrderNo());
sOrder.setPayStatus(YesNoEnum.yes.getIndex()); sOrder.setPayStatus(YesNoEnum.yes.getIndex());
sOrder.setPayTime(DateUtils.getNowDate()); sOrder.setPayTime(DateUtils.getNowDate());
if (!ObjectUtils.isEmpty(request.getMonthlyCardId()) || !ObjectUtils.isEmpty(request.getSecondaryCardId())) { if (!ObjectUtils.isEmpty(request.getSecondaryCardId())) {
creatExtracted(consumerMonthlyCard, sOrder, consumerSecondaryCard); creatExtracted(sOrder, consumerSecondaryCard);
} }
creatExtracted(consumerWallet, sOrder, consumerMember); creatExtracted(consumerWallet, sOrder, consumerMember, consumerMonthlyCard);
} else { } else {
// response = orderPayService.payment(sOrder); // response = orderPayService.payment(sOrder);
// 扫呗聚合支付 // 扫呗聚合支付
...@@ -1129,20 +1127,67 @@ public class SOrderServiceImpl extends ServiceImpl<SOrderMapper, SOrder> impleme ...@@ -1129,20 +1127,67 @@ public class SOrderServiceImpl extends ServiceImpl<SOrderMapper, SOrder> impleme
} }
} }
private void creatExtracted(ConsumerWallet consumerWallet, SOrder sOrder, ConsumerMember consumerMember) { private void creatExtracted(ConsumerWallet consumerWallet, SOrder sOrder, ConsumerMember consumerMember, ConsumerMonthlyCard consumerMonthlyCard) {
if (ObjectUtil.isNotEmpty(consumerWallet)) { if (ObjectUtil.isNotEmpty(consumerWallet)) {
if (ObjectUtil.isNotEmpty(sOrder.getDuration()) && sOrder.getDuration().compareTo(BigDecimal.ZERO) > 0 && ObjectUtil.isEmpty(sOrder.getMonthlyCardId())) {
DurationLog durationLog = new DurationLog(); if (ObjectUtil.isNotEmpty(sOrder.getDuration()) && sOrder.getDuration().compareTo(BigDecimal.ZERO) > 0) {
durationLog.setConsumerId(sOrder.getConsumerId()); if (ObjectUtil.isEmpty(sOrder.getMonthlyCardId())) {
durationLog.setVariableDuration(sOrder.getDuration()); DurationLog durationLog = new DurationLog();
durationLog.setCurrentDuration(consumerWallet.getRemainingDuration()); durationLog.setConsumerId(sOrder.getConsumerId());
durationLog.setOperationType(YesNoEnum.no.getIndex()); durationLog.setVariableDuration(sOrder.getDuration());
durationLog.setDurationType(DurationTypeEnum.ORDER.getCode()); durationLog.setCurrentDuration(consumerWallet.getRemainingDuration());
durationLog.setOperationTime(new Date()); durationLog.setOperationType(YesNoEnum.no.getIndex());
durationLog.setCreateTime(new Date()); durationLog.setDurationType(DurationTypeEnum.ORDER.getCode());
durationLogService.save(durationLog); durationLog.setOperationTime(new Date());
consumerWallet.setRemainingDuration(consumerWallet.getRemainingDuration().subtract(sOrder.getDuration())); durationLog.setCreateTime(new Date());
consumerWalletService.updateById(consumerWallet); durationLogService.save(durationLog);
consumerWallet.setRemainingDuration(consumerWallet.getRemainingDuration().subtract(sOrder.getDuration()));
consumerWalletService.updateById(consumerWallet);
} else {
if (!ObjectUtils.isEmpty(sOrder.getMonthlyCardId()) && !ObjectUtils.isEmpty(sOrder.getDuration())) {
if (consumerMonthlyCard.getFreeDuration().compareTo(sOrder.getDuration()) >= 0) {
consumerMonthlyCard.setFreeDuration(consumerMonthlyCard.getFreeDuration().subtract(sOrder.getDuration()));
MonthlyCardLog monthlyCardLog = new MonthlyCardLog();
monthlyCardLog.setConsumerMonthlyCardId(sOrder.getMonthlyCardId());
monthlyCardLog.setConsumerId(consumerMonthlyCard.getConsumerId());
monthlyCardLog.setPhone(sOrder.getConsumerPhone());
monthlyCardLog.setUseDuration(sOrder.getDuration());
monthlyCardLog.setResidueDuration(consumerMonthlyCard.getFreeDuration());
monthlyCardLog.setOperationType(YesNoEnum.no.getIndex());
monthlyCardLog.setOperationTime(new Date());
monthlyCardLog.setCreateTime(new Date());
consumerMonthlyCardService.updateById(consumerMonthlyCard);
monthlyCardLogService.save(monthlyCardLog);
} else if (consumerMonthlyCard.getFreeDuration().compareTo(sOrder.getDuration()) < 0) {
BigDecimal duration = sOrder.getDuration();
MonthlyCardLog monthlyCardLog = new MonthlyCardLog();
monthlyCardLog.setConsumerMonthlyCardId(sOrder.getMonthlyCardId());
monthlyCardLog.setConsumerId(consumerMonthlyCard.getConsumerId());
monthlyCardLog.setPhone(sOrder.getConsumerPhone());
monthlyCardLog.setUseDuration(consumerMonthlyCard.getFreeDuration());
duration = duration.subtract(consumerMonthlyCard.getFreeDuration());
consumerMonthlyCard.setFreeDuration(BigDecimal.ZERO);
monthlyCardLog.setResidueDuration(consumerMonthlyCard.getFreeDuration());
monthlyCardLog.setOperationType(YesNoEnum.no.getIndex());
monthlyCardLog.setOperationTime(new Date());
monthlyCardLog.setCreateTime(new Date());
consumerMonthlyCardService.updateById(consumerMonthlyCard);
monthlyCardLogService.save(monthlyCardLog);
DurationLog durationLog = new DurationLog();
durationLog.setConsumerId(sOrder.getConsumerId());
durationLog.setVariableDuration(duration);
durationLog.setCurrentDuration(consumerWallet.getRemainingDuration());
durationLog.setOperationType(YesNoEnum.no.getIndex());
durationLog.setDurationType(DurationTypeEnum.ORDER.getCode());
durationLog.setOperationTime(new Date());
durationLog.setCreateTime(new Date());
durationLogService.save(durationLog);
consumerWallet.setRemainingDuration(consumerWallet.getRemainingDuration().subtract(duration));
consumerWalletService.updateById(consumerWallet);
}
}
}
} }
if (ObjectUtil.isNotEmpty(sOrder.getBalance()) && sOrder.getBalance().compareTo(BigDecimal.ZERO) > 0) { if (ObjectUtil.isNotEmpty(sOrder.getBalance()) && sOrder.getBalance().compareTo(BigDecimal.ZERO) > 0) {
BalanceLog balanceLog = new BalanceLog(); BalanceLog balanceLog = new BalanceLog();
...@@ -1321,23 +1366,8 @@ public class SOrderServiceImpl extends ServiceImpl<SOrderMapper, SOrder> impleme ...@@ -1321,23 +1366,8 @@ public class SOrderServiceImpl extends ServiceImpl<SOrderMapper, SOrder> impleme
} }
} }
private void creatExtracted(ConsumerMonthlyCard consumerMonthlyCard, SOrder sOrder, ConsumerSecondaryCard consumerSecondaryCard) { private void creatExtracted(SOrder sOrder, ConsumerSecondaryCard consumerSecondaryCard) {
if (!ObjectUtils.isEmpty(sOrder.getMonthlyCardId()) && !ObjectUtils.isEmpty(sOrder.getDuration())) {
if (consumerMonthlyCard.getFreeDuration().compareTo(sOrder.getDuration()) >= 0) {
consumerMonthlyCard.setFreeDuration(consumerMonthlyCard.getFreeDuration().subtract(sOrder.getDuration()));
MonthlyCardLog monthlyCardLog = new MonthlyCardLog();
monthlyCardLog.setConsumerMonthlyCardId(sOrder.getMonthlyCardId());
monthlyCardLog.setConsumerId(consumerMonthlyCard.getConsumerId());
monthlyCardLog.setPhone(sOrder.getConsumerPhone());
monthlyCardLog.setUseDuration(sOrder.getDuration());
monthlyCardLog.setResidueDuration(consumerMonthlyCard.getFreeDuration());
monthlyCardLog.setOperationType(YesNoEnum.no.getIndex());
monthlyCardLog.setOperationTime(new Date());
monthlyCardLog.setCreateTime(new Date());
consumerMonthlyCardService.updateById(consumerMonthlyCard);
monthlyCardLogService.save(monthlyCardLog);
}
}
if (!ObjectUtils.isEmpty(sOrder.getSecondaryCardId())) { if (!ObjectUtils.isEmpty(sOrder.getSecondaryCardId())) {
consumerSecondaryCard.setNumber(consumerSecondaryCard.getNumber() - 1); consumerSecondaryCard.setNumber(consumerSecondaryCard.getNumber() - 1);
SecondaryCardLog secondaryCardLog = new SecondaryCardLog(); SecondaryCardLog secondaryCardLog = new SecondaryCardLog();
...@@ -1354,20 +1384,77 @@ public class SOrderServiceImpl extends ServiceImpl<SOrderMapper, SOrder> impleme ...@@ -1354,20 +1384,77 @@ public class SOrderServiceImpl extends ServiceImpl<SOrderMapper, SOrder> impleme
} }
} }
private void refundExtracted(ConsumerWallet consumerWallet, SOrder sOrder, ConsumerMember consumerMember) { private void refundExtracted(ConsumerWallet consumerWallet, SOrder sOrder, ConsumerMember consumerMember, ConsumerMonthlyCard consumerMonthlyCard) {
if (ObjectUtil.isNotEmpty(consumerWallet)) { if (ObjectUtil.isNotEmpty(consumerWallet)) {
if (ObjectUtil.isNotEmpty(sOrder.getDuration()) && sOrder.getDuration().compareTo(BigDecimal.ZERO) > 0 && ObjectUtil.isEmpty(sOrder.getMonthlyCardId())) { if (ObjectUtil.isNotEmpty(sOrder.getDuration()) && sOrder.getDuration().compareTo(BigDecimal.ZERO) > 0) {
DurationLog durationLog = new DurationLog(); if (ObjectUtil.isEmpty(sOrder.getMonthlyCardId())) {
durationLog.setConsumerId(sOrder.getConsumerId()); DurationLog durationLog = new DurationLog();
durationLog.setVariableDuration(sOrder.getDuration()); durationLog.setConsumerId(sOrder.getConsumerId());
durationLog.setCurrentDuration(consumerWallet.getRemainingDuration()); durationLog.setVariableDuration(sOrder.getDuration());
durationLog.setOperationType(YesNoEnum.yes.getIndex()); durationLog.setCurrentDuration(consumerWallet.getRemainingDuration());
durationLog.setDurationType(DurationTypeEnum.ORDER_REFUND.getCode()); durationLog.setOperationType(YesNoEnum.yes.getIndex());
durationLog.setOperationTime(new Date()); durationLog.setDurationType(DurationTypeEnum.ORDER_REFUND.getCode());
durationLog.setCreateTime(new Date()); durationLog.setOperationTime(new Date());
durationLogService.save(durationLog); durationLog.setCreateTime(new Date());
consumerWallet.setRemainingDuration(consumerWallet.getRemainingDuration().add(sOrder.getDuration())); durationLogService.save(durationLog);
consumerWalletService.updateById(consumerWallet); consumerWallet.setRemainingDuration(consumerWallet.getRemainingDuration().add(sOrder.getDuration()));
consumerWalletService.updateById(consumerWallet);
} else {
if (!ObjectUtils.isEmpty(sOrder.getMonthlyCardId()) && !ObjectUtils.isEmpty(sOrder.getDuration())) {
BigDecimal duration = sOrder.getDuration();
BigDecimal monthlyCardTime = new BigDecimal(sysConfigService.selectConfigByKey("monthlyCardTime"));
if (monthlyCardTime.compareTo(duration) >= 0) {
//判断订单的下单时间是否是当前天
LocalDate localDate1 = sOrder.getCreateTime().toInstant().atZone(ZoneId.systemDefault()).toLocalDate();
LocalDate localDate2 = new Date().toInstant().atZone(ZoneId.systemDefault()).toLocalDate();
if (localDate1.equals(localDate2)) {
consumerMonthlyCard.setFreeDuration(consumerMonthlyCard.getFreeDuration().add(sOrder.getDuration()));
MonthlyCardLog monthlyCardLog = new MonthlyCardLog();
monthlyCardLog.setConsumerMonthlyCardId(sOrder.getMonthlyCardId());
monthlyCardLog.setConsumerId(consumerMonthlyCard.getConsumerId());
monthlyCardLog.setPhone(sOrder.getConsumerPhone());
monthlyCardLog.setUseDuration(sOrder.getDuration());
monthlyCardLog.setResidueDuration(consumerMonthlyCard.getFreeDuration());
monthlyCardLog.setOperationType(YesNoEnum.yes.getIndex());
monthlyCardLog.setOperationTime(new Date());
monthlyCardLog.setCreateTime(new Date());
consumerMonthlyCardService.updateById(consumerMonthlyCard);
monthlyCardLogService.save(monthlyCardLog);
}
} else if (monthlyCardTime.compareTo(duration) < 0) {
//判断订单的下单时间是否是当前天
LocalDate localDate1 = sOrder.getCreateTime().toInstant().atZone(ZoneId.systemDefault()).toLocalDate();
LocalDate localDate2 = new Date().toInstant().atZone(ZoneId.systemDefault()).toLocalDate();
duration = duration.subtract(monthlyCardTime);
if (localDate1.equals(localDate2)) {
consumerMonthlyCard.setFreeDuration(consumerMonthlyCard.getFreeDuration().add(monthlyCardTime));
MonthlyCardLog monthlyCardLog = new MonthlyCardLog();
monthlyCardLog.setConsumerMonthlyCardId(sOrder.getMonthlyCardId());
monthlyCardLog.setConsumerId(consumerMonthlyCard.getConsumerId());
monthlyCardLog.setPhone(sOrder.getConsumerPhone());
monthlyCardLog.setUseDuration(monthlyCardTime);
monthlyCardLog.setResidueDuration(consumerMonthlyCard.getFreeDuration());
monthlyCardLog.setOperationType(YesNoEnum.yes.getIndex());
monthlyCardLog.setOperationTime(new Date());
monthlyCardLog.setCreateTime(new Date());
consumerMonthlyCardService.updateById(consumerMonthlyCard);
monthlyCardLogService.save(monthlyCardLog);
}
DurationLog durationLog = new DurationLog();
durationLog.setConsumerId(sOrder.getConsumerId());
durationLog.setVariableDuration(duration);
durationLog.setCurrentDuration(consumerWallet.getRemainingDuration());
durationLog.setOperationType(YesNoEnum.yes.getIndex());
durationLog.setDurationType(DurationTypeEnum.ORDER_REFUND.getCode());
durationLog.setOperationTime(new Date());
durationLog.setCreateTime(new Date());
durationLogService.save(durationLog);
consumerWallet.setRemainingDuration(consumerWallet.getRemainingDuration().add(duration));
consumerWalletService.updateById(consumerWallet);
}
}
}
} }
if (ObjectUtil.isNotEmpty(sOrder.getBalance()) && sOrder.getBalance().compareTo(BigDecimal.ZERO) > 0) { if (ObjectUtil.isNotEmpty(sOrder.getBalance()) && sOrder.getBalance().compareTo(BigDecimal.ZERO) > 0) {
BalanceLog balanceLog = new BalanceLog(); BalanceLog balanceLog = new BalanceLog();
...@@ -1571,26 +1658,7 @@ public class SOrderServiceImpl extends ServiceImpl<SOrderMapper, SOrder> impleme ...@@ -1571,26 +1658,7 @@ public class SOrderServiceImpl extends ServiceImpl<SOrderMapper, SOrder> impleme
// } // }
} }
private void refundExtracted(ConsumerMonthlyCard consumerMonthlyCard, SOrder sOrder, ConsumerSecondaryCard consumerSecondaryCard) { private void refundExtracted(SOrder sOrder, ConsumerSecondaryCard consumerSecondaryCard) {
if (!ObjectUtils.isEmpty(sOrder.getMonthlyCardId()) && !ObjectUtils.isEmpty(sOrder.getDuration())) {
//判断订单的下单时间是否是当前天
LocalDate localDate1 = sOrder.getCreateTime().toInstant().atZone(ZoneId.systemDefault()).toLocalDate();
LocalDate localDate2 = new Date().toInstant().atZone(ZoneId.systemDefault()).toLocalDate();
if (localDate1.equals(localDate2)) {
consumerMonthlyCard.setFreeDuration(consumerMonthlyCard.getFreeDuration().add(sOrder.getDuration()));
MonthlyCardLog monthlyCardLog = new MonthlyCardLog();
monthlyCardLog.setConsumerMonthlyCardId(sOrder.getMonthlyCardId());
monthlyCardLog.setConsumerId(consumerMonthlyCard.getConsumerId());
monthlyCardLog.setPhone(sOrder.getConsumerPhone());
monthlyCardLog.setUseDuration(sOrder.getDuration());
monthlyCardLog.setResidueDuration(consumerMonthlyCard.getFreeDuration());
monthlyCardLog.setOperationType(YesNoEnum.yes.getIndex());
monthlyCardLog.setOperationTime(new Date());
monthlyCardLog.setCreateTime(new Date());
consumerMonthlyCardService.updateById(consumerMonthlyCard);
monthlyCardLogService.save(monthlyCardLog);
}
}
if (!ObjectUtils.isEmpty(sOrder.getSecondaryCardId())) { if (!ObjectUtils.isEmpty(sOrder.getSecondaryCardId())) {
consumerSecondaryCard.setNumber(consumerSecondaryCard.getNumber() + 1); consumerSecondaryCard.setNumber(consumerSecondaryCard.getNumber() + 1);
SecondaryCardLog secondaryCardLog = new SecondaryCardLog(); SecondaryCardLog secondaryCardLog = new SecondaryCardLog();
...@@ -1812,6 +1880,8 @@ public class SOrderServiceImpl extends ServiceImpl<SOrderMapper, SOrder> impleme ...@@ -1812,6 +1880,8 @@ public class SOrderServiceImpl extends ServiceImpl<SOrderMapper, SOrder> impleme
order.setBalance(priceResponse.getBalance()); order.setBalance(priceResponse.getBalance());
order.setDuration(priceResponse.getDuration()); order.setDuration(priceResponse.getDuration());
order.setDiscountRatio(priceResponse.getDiscountRatio()); order.setDiscountRatio(priceResponse.getDiscountRatio());
order.setMonthlyCardId(priceResponse.getMonthlyCardId());
order.setSecondaryCardId(priceResponse.getSecondaryCardId());
if (priceResponse.getPayFee().compareTo(order.getPayPrice()) != 0 if (priceResponse.getPayFee().compareTo(order.getPayPrice()) != 0
&& priceResponse.getDuration().compareTo(request.getDuration()) != 0 && priceResponse.getDuration().compareTo(request.getDuration()) != 0
&& priceResponse.getBalance().compareTo(request.getBalance()) != 0 && priceResponse.getBalance().compareTo(request.getBalance()) != 0
...@@ -2156,10 +2226,10 @@ public class SOrderServiceImpl extends ServiceImpl<SOrderMapper, SOrder> impleme ...@@ -2156,10 +2226,10 @@ public class SOrderServiceImpl extends ServiceImpl<SOrderMapper, SOrder> impleme
deviceOpService.openOrCloseDevice(sOrder.getRoomId(), sOrder.getConsumerPhone(), OpTypeEnum.CUT_ELECTRIC.getCode(), true, 5, deviceOpService.openOrCloseDevice(sOrder.getRoomId(), sOrder.getConsumerPhone(), OpTypeEnum.CUT_ELECTRIC.getCode(), true, 5,
DeviceOpSourceEnum.DEVICE_SOURCE_20.getCode()); DeviceOpSourceEnum.DEVICE_SOURCE_20.getCode());
} }
if (!ObjectUtils.isEmpty(sOrder.getMonthlyCardId()) || !ObjectUtils.isEmpty(sOrder.getSecondaryCardId())) { if (!ObjectUtils.isEmpty(sOrder.getSecondaryCardId())) {
refundExtracted(consumerMonthlyCard, sOrder, consumerSecondaryCard); refundExtracted(sOrder, consumerSecondaryCard);
} else { } else {
refundExtracted(consumerWallet, sOrder, consumerMember); refundExtracted(consumerWallet, sOrder, consumerMember, consumerMonthlyCard);
} }
} }
} else { } else {
...@@ -2191,10 +2261,10 @@ public class SOrderServiceImpl extends ServiceImpl<SOrderMapper, SOrder> impleme ...@@ -2191,10 +2261,10 @@ public class SOrderServiceImpl extends ServiceImpl<SOrderMapper, SOrder> impleme
if (sOrder.getIsDelete().equals(YesNoEnum.yes.getIndex()) && sOrder.getPayStatus().equals(YesNoEnum.yes.getIndex())) { if (sOrder.getIsDelete().equals(YesNoEnum.yes.getIndex()) && sOrder.getPayStatus().equals(YesNoEnum.yes.getIndex())) {
sOrder.setIsDelete(YesNoEnum.no.getIndex()); sOrder.setIsDelete(YesNoEnum.no.getIndex());
} }
if (!ObjectUtils.isEmpty(sOrder.getMonthlyCardId()) || !ObjectUtils.isEmpty(sOrder.getSecondaryCardId())) { if (!ObjectUtils.isEmpty(sOrder.getSecondaryCardId())) {
creatExtracted(consumerMonthlyCard, sOrder, consumerSecondaryCard); creatExtracted(sOrder, consumerSecondaryCard);
} }
creatExtracted(consumerWallet, sOrder, consumerMember); creatExtracted(consumerWallet, sOrder, consumerMember, consumerMonthlyCard);
baseMapper.updateSOrder(sOrder); baseMapper.updateSOrder(sOrder);
unLockOrder(sOrder.getRoomId()); unLockOrder(sOrder.getRoomId());
if (sOrder.getOrderType().equals(OrderTypeEnum.RENEW.getCode())) { if (sOrder.getOrderType().equals(OrderTypeEnum.RENEW.getCode())) {
...@@ -2348,10 +2418,10 @@ public class SOrderServiceImpl extends ServiceImpl<SOrderMapper, SOrder> impleme ...@@ -2348,10 +2418,10 @@ public class SOrderServiceImpl extends ServiceImpl<SOrderMapper, SOrder> impleme
deviceOpService.openOrCloseDevice(sOrder.getRoomId(), sOrder.getConsumerPhone(), OpTypeEnum.CUT_ELECTRIC.getCode(), true, 5, deviceOpService.openOrCloseDevice(sOrder.getRoomId(), sOrder.getConsumerPhone(), OpTypeEnum.CUT_ELECTRIC.getCode(), true, 5,
DeviceOpSourceEnum.DEVICE_SOURCE_20.getCode()); DeviceOpSourceEnum.DEVICE_SOURCE_20.getCode());
} }
if (!ObjectUtils.isEmpty(sOrder.getMonthlyCardId()) || !ObjectUtils.isEmpty(sOrder.getSecondaryCardId())) { if (!ObjectUtils.isEmpty(sOrder.getSecondaryCardId())) {
refundExtracted(consumerMonthlyCard, sOrder, consumerSecondaryCard); refundExtracted(sOrder, consumerSecondaryCard);
} }
refundExtracted(consumerWallet, sOrder, consumerMember); refundExtracted(consumerWallet, sOrder, consumerMember, consumerMonthlyCard);
} }
} catch (Exception e) { } catch (Exception e) {
...@@ -2379,10 +2449,10 @@ public class SOrderServiceImpl extends ServiceImpl<SOrderMapper, SOrder> impleme ...@@ -2379,10 +2449,10 @@ public class SOrderServiceImpl extends ServiceImpl<SOrderMapper, SOrder> impleme
try { try {
sOrder.setRefundReason(request.getRefundReason()); sOrder.setRefundReason(request.getRefundReason());
updateById(sOrder); updateById(sOrder);
if (!ObjectUtils.isEmpty(sOrder.getMonthlyCardId()) || !ObjectUtils.isEmpty(sOrder.getSecondaryCardId())) { if (!ObjectUtils.isEmpty(sOrder.getSecondaryCardId())) {
refundExtracted(consumerMonthlyCard, sOrder, consumerSecondaryCard); refundExtracted(sOrder, consumerSecondaryCard);
} }
refundExtracted(consumerWallet, sOrder, consumerMember); refundExtracted(consumerWallet, sOrder, consumerMember, consumerMonthlyCard);
//微信退款 //微信退款
// if (sOrder.getPayType().equals(PayTypeEnum.WECHAT.getCode()) && request.getAmount().compareTo(BigDecimal.ZERO) == 0) { // if (sOrder.getPayType().equals(PayTypeEnum.WECHAT.getCode()) && request.getAmount().compareTo(BigDecimal.ZERO) == 0) {
// 退款task, 定时任务退优惠券 // 退款task, 定时任务退优惠券
...@@ -2877,6 +2947,8 @@ public class SOrderServiceImpl extends ServiceImpl<SOrderMapper, SOrder> impleme ...@@ -2877,6 +2947,8 @@ public class SOrderServiceImpl extends ServiceImpl<SOrderMapper, SOrder> impleme
priceResponse.setBalance(new BigDecimal(0)); priceResponse.setBalance(new BigDecimal(0));
priceResponse.setRemainingBalance(new BigDecimal(0)); priceResponse.setRemainingBalance(new BigDecimal(0));
priceResponse.setRemainingDuration(new BigDecimal(0)); priceResponse.setRemainingDuration(new BigDecimal(0));
priceResponse.setMonthlyCardId(null);
priceResponse.setSecondaryCardId(null);
if (priceResponse.getPayFee().compareTo(new BigDecimal(0)) > 0) { if (priceResponse.getPayFee().compareTo(new BigDecimal(0)) > 0) {
if (ObjectUtil.isNotEmpty(consumerWallet) && ObjectUtil.isNotEmpty(consumerMember)) { if (ObjectUtil.isNotEmpty(consumerWallet) && ObjectUtil.isNotEmpty(consumerMember)) {
MemberConfig memberConfig = memberConfigService.getOne(new LambdaQueryWrapper<MemberConfig>().eq(MemberConfig::getMembershipLevel, consumerMember.getMembershipLevel())); MemberConfig memberConfig = memberConfigService.getOne(new LambdaQueryWrapper<MemberConfig>().eq(MemberConfig::getMembershipLevel, consumerMember.getMembershipLevel()));
...@@ -3180,21 +3252,21 @@ public class SOrderServiceImpl extends ServiceImpl<SOrderMapper, SOrder> impleme ...@@ -3180,21 +3252,21 @@ public class SOrderServiceImpl extends ServiceImpl<SOrderMapper, SOrder> impleme
priceResponse.setDiscountRatio(memberConfig.getDiscountRatio()); priceResponse.setDiscountRatio(memberConfig.getDiscountRatio());
priceResponse.setDiscount(memberConfig.getDiscountRatio()); priceResponse.setDiscount(memberConfig.getDiscountRatio());
priceResponse.setTotalFee(totalFee); priceResponse.setTotalFee(totalFee);
priceResponse.setAvailableDuration(consumerMonthlyCard.getFreeDuration()); priceResponse.setAvailableDuration(consumerMonthlyCard.getFreeDuration().add(consumerWallet.getRemainingDuration()));
if (consumerMonthlyCard.getFreeDuration().compareTo(timeLong) >= 0) { if (priceResponse.getAvailableDuration().compareTo(timeLong) >= 0) {
priceResponse.setDuration(timeLong); priceResponse.setDuration(timeLong);
priceResponse.setRemainingDuration(consumerMonthlyCard.getFreeDuration().subtract(timeLong)); priceResponse.setRemainingDuration(priceResponse.getAvailableDuration().subtract(timeLong));
totalFee = new BigDecimal(0); totalFee = new BigDecimal(0);
priceResponse.setDiscount(BigDecimal.ZERO); priceResponse.setDiscount(BigDecimal.ZERO);
priceResponse.setMemberDiscount(new BigDecimal(0.00)); priceResponse.setMemberDiscount(new BigDecimal(0.00));
priceResponse.setTotalFeeNow(priceResponse.getTotalFee()); priceResponse.setTotalFeeNow(priceResponse.getTotalFee());
priceResponse.setMonthlyCardId(consumerMonthlyCard.getId()); priceResponse.setMonthlyCardId(consumerMonthlyCard.getId());
priceResponse.setPayFee(BigDecimal.ZERO); priceResponse.setPayFee(BigDecimal.ZERO);
} else if (consumerMonthlyCard.getFreeDuration().compareTo(timeLong) < 0) { } else if (priceResponse.getAvailableDuration().compareTo(timeLong) < 0) {
priceResponse.setDuration(consumerMonthlyCard.getFreeDuration()); priceResponse.setDuration(priceResponse.getAvailableDuration());
priceResponse.setRemainingDuration(new BigDecimal(0)); priceResponse.setRemainingDuration(new BigDecimal(0));
//时长的金额 //时长的金额
BigDecimal remainingBalance = consumerMonthlyCard.getFreeDuration().multiply(room.getPrice()); BigDecimal remainingBalance = priceResponse.getAvailableDuration().multiply(room.getPrice());
//恢复原价 //恢复原价
// totalFee = totalFee.divide(memberConfig.getDiscountRatio(), 2, RoundingMode.HALF_UP).multiply(new BigDecimal(100)); // totalFee = totalFee.divide(memberConfig.getDiscountRatio(), 2, RoundingMode.HALF_UP).multiply(new BigDecimal(100));
//原价减时长 //原价减时长
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment