Commit b4a10e8f by 吕明尚

下单计算月卡,次卡

parent 06d6a649
......@@ -9,6 +9,8 @@ import org.apache.commons.lang3.builder.ToStringStyle;
import share.common.annotation.Excel;
import share.common.core.domain.BaseEntity;
import java.math.BigDecimal;
/**
* 月卡使用记录对象 s_monthly_card_log
*
......@@ -47,13 +49,13 @@ public class MonthlyCardLog extends BaseEntity {
* 使用时长
*/
@Excel(name = "使用时长")
private Long useDuration;
private BigDecimal useDuration;
/**
* 剩余时长
*/
@Excel(name = "剩余时长")
private Long residueDuration;
private BigDecimal residueDuration;
/**
* 删除标记:1-删除,0-正常
......
......@@ -89,4 +89,12 @@ public class CreateOrderRequest {
@ApiModelProperty(value = "使用时长")
private BigDecimal duration;
//次卡ID
@ApiModelProperty(value = "次卡ID")
private Long secondaryCardId;
//月卡ID
@ApiModelProperty(value = "月卡ID")
private Long monthlyCardId;
}
......@@ -173,7 +173,11 @@ public class SOrderServiceImpl extends ServiceImpl<SOrderMapper, SOrder> impleme
@Autowired
private ConsumerMonthlyCardService consumerMonthlyCardService;
@Autowired
private MonthlyCardLogService monthlyCardLogService;
@Autowired
private ConsumerSecondaryCardService consumerSecondaryCardService;
@Autowired
private SecondaryCardLogService secondaryCardLogService;
private final static Long FIVE = 5L;
......@@ -876,6 +880,8 @@ public class SOrderServiceImpl extends ServiceImpl<SOrderMapper, SOrder> impleme
}
ConsumerWallet consumerWallet = consumerWalletService.getOne(new LambdaQueryWrapper<ConsumerWallet>().eq(ConsumerWallet::getConsumerId, user.getId()));
ConsumerMember consumerMember = consumerMemberService.getOne(new LambdaQueryWrapper<ConsumerMember>().eq(ConsumerMember::getConsumerId, user.getId()));
ConsumerMonthlyCard consumerMonthlyCard = consumerMonthlyCardService.getById(request.getMonthlyCardId());
ConsumerSecondaryCard consumerSecondaryCard = consumerSecondaryCardService.getById(request.getSecondaryCardId());
List<SStore> stores = storeService.list();
SRoom room = roomService.getById(request.getRoomId());
SStore sStore = storeService.getById(request.getStoreId());
......@@ -933,6 +939,7 @@ public class SOrderServiceImpl extends ServiceImpl<SOrderMapper, SOrder> impleme
sOrder.setPayStatus(YesNoEnum.yes.getIndex());
sOrder.setPayTime(DateUtils.getNowDate());
creatExtracted(consumerWallet, sOrder, consumerMember);
createCard(consumerMonthlyCard, sOrder, consumerSecondaryCard);
} else {
// response = orderPayService.payment(sOrder);
// 扫呗聚合支付
......@@ -1066,6 +1073,32 @@ public class SOrderServiceImpl extends ServiceImpl<SOrderMapper, SOrder> impleme
}
}
private void createCard(ConsumerMonthlyCard consumerMonthlyCard, SOrder sOrder, ConsumerSecondaryCard consumerSecondaryCard) {
if (ObjectUtil.isNotEmpty(consumerMonthlyCard)) {
MonthlyCardLog monthlyCardLog = new MonthlyCardLog();
monthlyCardLog.setConsumerMonthlyCardId(consumerMonthlyCard.getId());
monthlyCardLog.setConsumerId(sOrder.getConsumerId());
monthlyCardLog.setPhone(sOrder.getConsumerPhone());
monthlyCardLog.setUseDuration(sOrder.getDuration());
monthlyCardLog.setResidueDuration(consumerMonthlyCard.getFreeDuration().subtract(sOrder.getDuration()));
consumerMonthlyCard.setFreeDuration(consumerMonthlyCard.getFreeDuration().subtract(sOrder.getDuration()));
consumerMonthlyCardService.updateById(consumerMonthlyCard);
monthlyCardLogService.save(monthlyCardLog);
} else if (ObjectUtil.isNotEmpty(consumerSecondaryCard)) {
SecondaryCardLog secondaryCardLog = new SecondaryCardLog();
secondaryCardLog.setConsumerSecondaryCardId(consumerSecondaryCard.getId());
secondaryCardLog.setConsumerId(sOrder.getConsumerId());
secondaryCardLog.setPhone(sOrder.getConsumerPhone());
secondaryCardLog.setPackId(sOrder.getPackId());
secondaryCardLog.setUsageCount(1L);
secondaryCardLog.setResidueCount(consumerSecondaryCard.getNumber() - 1L);
consumerSecondaryCard.setNumber(consumerSecondaryCard.getNumber() - 1);
secondaryCardLogService.save(secondaryCardLog);
consumerSecondaryCardService.updateById(consumerSecondaryCard);
}
}
private void creatExtracted(ConsumerWallet consumerWallet, SOrder sOrder, ConsumerMember consumerMember) {
if (ObjectUtil.isNotEmpty(consumerWallet)) {
if (ObjectUtil.isNotEmpty(sOrder.getDuration()) && sOrder.getDuration().compareTo(BigDecimal.ZERO) > 0) {
......@@ -1585,10 +1618,18 @@ public class SOrderServiceImpl extends ServiceImpl<SOrderMapper, SOrder> impleme
order.setBalance(priceResponse.getBalance());
order.setDuration(priceResponse.getDuration());
order.setDiscountRatio(priceResponse.getDiscountRatio());
if (ObjectUtil.isNotEmpty(request.getMonthlyCardId())) {
order.setMonthlyCardId(request.getMonthlyCardId());
}
if (ObjectUtil.isNotEmpty(request.getSecondaryCardId())) {
order.setSecondaryCardId(request.getSecondaryCardId());
}
if (priceResponse.getPayFee().compareTo(order.getPayPrice()) != 0
&& priceResponse.getDuration().compareTo(request.getDuration()) != 0
&& priceResponse.getBalance().compareTo(request.getBalance()) != 0
&& priceResponse.getDiscountRatio().compareTo(request.getDiscountRatio()) != 0
&& (ObjectUtil.isNotEmpty(request.getSecondaryCardId()) && priceResponse.getSecondaryCardId().compareTo(request.getSecondaryCardId()) != 0)
&& (ObjectUtil.isNotEmpty(request.getMonthlyCardId()) && priceResponse.getMonthlyCardId().compareTo(request.getMonthlyCardId()) != 0)
) {
throw new BaseException("订单金额异常!");
}
......
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