Commit 4b7ff02e by 吕明尚

订单计算,增加次卡,月卡计算逻辑,增加自动删除月卡,次卡定时任务

parent c29a6e2e
......@@ -13,7 +13,9 @@ public enum ReceiptRdeisEnum {
//房间15分钟过期
ROOM_EXPIRE_TIME(9, "ROOM_EXPIRE_TIME."),
ORDER_CANCEL_PAY(10, "ORDER_CANCEL_PAY."),
EQUITY_MEMBERS_TIME(11, "EQUITY_MEMBERS_TIME.")
EQUITY_MEMBERS_TIME(11, "EQUITY_MEMBERS_TIME."),
MONTHLY_CARD(12, "MONTHLY_CARD."),
SECONDARY_CARD(13, "SECONDARY_CARD.")
;
......
......@@ -109,6 +109,10 @@ public class RedisTask {
@Autowired
private SharingActivitiesService sharingActivitiesService;
@Autowired
private ConsumerSecondaryCardService consumerSecondaryCardService;
@Autowired
private ConsumerMonthlyCardService consumerMonthlyCardService;
//15分钟的常量
......@@ -767,4 +771,56 @@ public class RedisTask {
});
logger.debug("AutoUpdateOpenid:自动更新用户unionid结束");
}
//自动删除次卡
@XxlJob("AutomaticallyDeleteSecondaryCards")
public void AutomaticallyDeleteSecondaryCards() {
logger.debug("AutomaticallyDeleteSecondaryCards:自动删除次卡开始");
Set<String> keys = redisTemplate.keys(ReceiptRdeisEnum.SECONDARY_CARD + "*");
if (keys.size() == 0) {
return;
}
keys.stream().forEach(key -> {
String value = redisUtil.get(String.valueOf(key));
JSONObject jsonObject = new JSONObject(value);
Date expirationTime = jsonObject.getDate("expirationTime");
Long consumerSecondaryCardId = jsonObject.getLong("consumerSecondaryCardId");
if (expirationTime.getTime() < new Date().getTime()) {
ConsumerSecondaryCard byId = consumerSecondaryCardService.getById(consumerSecondaryCardId);
if (ObjectUtil.isNotEmpty(byId)) {
byId.setIsDelete(YesNoEnum.yes.getIndex());
consumerSecondaryCardService.updateById(byId);
}
redisUtil.delete(key);
}
});
logger.debug("AutomaticallyDeleteSecondaryCards:自动删除次卡结束");
}
//自动删除月卡
@XxlJob("AutomaticallyDeleteMonthlyCards")
public void AutomaticallyDeleteMonthlyCards() {
logger.debug("AutomaticallyDeleteSecondaryCards:自动删除月卡开始");
Set<String> keys = redisTemplate.keys(ReceiptRdeisEnum.MONTHLY_CARD + "*");
if (keys.size() == 0) {
return;
}
keys.stream().forEach(key -> {
String value = redisUtil.get(String.valueOf(key));
JSONObject jsonObject = new JSONObject(value);
Date expirationTime = jsonObject.getDate("expirationTime");
Long consumerMonthlyCardId = jsonObject.getLong("consumerMonthlyCardId");
if (expirationTime.getTime() < new Date().getTime()) {
ConsumerMonthlyCard byId = consumerMonthlyCardService.getById(consumerMonthlyCardId);
if (ObjectUtil.isNotEmpty(byId)) {
byId.setIsDelete(YesNoEnum.yes.getIndex());
consumerMonthlyCardService.updateById(byId);
}
redisUtil.delete(key);
}
});
logger.debug("AutomaticallyDeleteSecondaryCards:自动删除月卡结束");
}
}
package share.system.domain;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableLogic;
import com.baomidou.mybatisplus.annotation.TableName;
import com.fasterxml.jackson.annotation.JsonFormat;
import lombok.Data;
......@@ -8,6 +10,7 @@ import org.apache.commons.lang3.builder.ToStringStyle;
import share.common.annotation.Excel;
import share.common.core.domain.BaseEntity;
import java.math.BigDecimal;
import java.util.Date;
/**
......@@ -48,7 +51,7 @@ public class ConsumerMonthlyCard extends BaseEntity {
* 免费时长
*/
@Excel(name = "免费时长")
private Long freeDuration;
private BigDecimal freeDuration;
/**
* 月卡天数
......@@ -66,7 +69,10 @@ public class ConsumerMonthlyCard extends BaseEntity {
/**
* 删除标记:1-删除,0-正常
*/
private Long isDelete;
//逻辑删除注解(0 未删除 1 已删除)
@TableLogic
@TableField(select = false)
private Integer isDelete;
@Override
......
......@@ -43,7 +43,7 @@ public class MonthlyCardConf extends BaseEntity {
* 免费时长
*/
@Excel(name = "免费时长")
private Long freeDuration;
private BigDecimal freeDuration;
/**
* 月卡天数
......
package share.system.service.impl;
import cn.hutool.core.util.ObjectUtil;
import cn.hutool.json.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import share.common.core.redis.RedisUtil;
import share.common.enums.ReceiptRdeisEnum;
import share.common.enums.YesNoEnum;
import share.common.exception.base.BaseException;
import share.common.utils.BaseUtil;
......@@ -24,7 +27,9 @@ import share.system.response.MonthlyyCardPayResultResponse;
import share.system.service.*;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
* 月卡订单Service业务层处理
......@@ -44,6 +49,8 @@ public class MonthlyCardOrderServiceImpl extends ServiceImpl<MonthlyCardOrderMap
private MonthlyCardConfService monthlyCardConfService;
@Autowired
private ConsumerMonthlyCardService consumerMonthlyCardService;
@Autowired
private RedisUtil redisUtil;
/**
* 查询月卡订单
......@@ -168,6 +175,18 @@ public class MonthlyCardOrderServiceImpl extends ServiceImpl<MonthlyCardOrderMap
consumerMonthlyCard.setFreeDuration(byId.getFreeDuration());
consumerMonthlyCard.setMonthlyCardDays(byId.getMonthlyCardDays());
consumerMonthlyCardService.save(consumerMonthlyCard);
Map<String, String> map = new HashMap<>();
map.put("consumerMonthlyCardId", String.valueOf(consumerMonthlyCard.getId()));
map.put("expirationTime", consumerMonthlyCard.getExpirationDate().toString());
JSONObject jsonObject = new JSONObject(map);
new Thread(() -> {
try {
Thread.sleep(1000);
redisUtil.set(ReceiptRdeisEnum.MONTHLY_CARD.getValue() + consumerMonthlyCard.getId(), jsonObject.toString());
} catch (InterruptedException e) {
e.printStackTrace();
}
}).start();
}
@Override
......
......@@ -170,6 +170,10 @@ public class SOrderServiceImpl extends ServiceImpl<SOrderMapper, SOrder> impleme
@Autowired
private RechargeService rechargeService;
@Autowired
private ConsumerMonthlyCardService consumerMonthlyCardService;
@Autowired
private ConsumerSecondaryCardService consumerSecondaryCardService;
private final static Long FIVE = 5L;
......@@ -2379,10 +2383,16 @@ public class SOrderServiceImpl extends ServiceImpl<SOrderMapper, SOrder> impleme
Activity activity = null;
ConsumerMember consumerMember = null;
ConsumerWallet consumerWallet = null;
ConsumerMonthlyCard consumerMonthlyCard = null;
List<ConsumerSecondaryCard> consumerSecondaryCardList = null;
LambdaQueryWrapper<Activity> queryWrapper = new LambdaQueryWrapper<>();
if (ObjectUtil.isNotEmpty(user)) {
consumerWallet = consumerWalletService.getOne(new LambdaQueryWrapper<ConsumerWallet>().eq(ConsumerWallet::getConsumerId, user.getId()));
consumerMember = consumerMemberService.getOne(new LambdaQueryWrapper<ConsumerMember>().eq(ConsumerMember::getConsumerId, user.getId()));
consumerMonthlyCard = consumerMonthlyCardService.getOne(new LambdaQueryWrapper<ConsumerMonthlyCard>().eq(ConsumerMonthlyCard::getConsumerId, user.getId()));
consumerSecondaryCardList = consumerSecondaryCardService.list(new LambdaQueryWrapper<ConsumerSecondaryCard>().eq(ConsumerSecondaryCard::getConsumerId, user.getId())
.ne(ConsumerSecondaryCard::getNumber, YesNoEnum.no.getIndex())
);
if (ObjectUtil.isNotEmpty(consumerMember)) {
queryWrapper.eq(Activity::getIsOpen, YesNoEnum.yes.getIndex());
queryWrapper.eq(Activity::getMemberType, consumerMember.getMemberType());
......@@ -2413,6 +2423,9 @@ public class SOrderServiceImpl extends ServiceImpl<SOrderMapper, SOrder> impleme
priceResponse.setDiscount(totalFee.divide(payPrice, 2, RoundingMode.HALF_UP).multiply(new BigDecimal(100)));
totalFee = getBigDecimal(consumerWallet, activity, timeLong, priceResponse, totalFee, room, request, consumerMember);
}
if (ObjectUtil.isNotEmpty(consumerMonthlyCard)) {
totalFee = getBigDecimal(consumerMonthlyCard, timeLong, priceResponse, totalPrice, room);
}
} else {
SPack byId = packService.getById(roomLabel.getPackId());
if (!ObjectUtils.isEmpty(byId) && byId.getIsOpen().equals(YesNoEnum.yes.getIndex())) {
......@@ -2429,6 +2442,12 @@ public class SOrderServiceImpl extends ServiceImpl<SOrderMapper, SOrder> impleme
priceResponse.setDiscount(totalFee.divide(payPrice, 2, RoundingMode.HALF_UP).multiply(new BigDecimal(100)));
totalFee = getBigDecimal(consumerWallet, activity, timeLong, priceResponse, totalFee, byId, request);
}
if (CollectionUtils.isNotEmpty(consumerSecondaryCardList)) {
totalFee = getBigDecimal(consumerSecondaryCardList, priceResponse, byId, payPrice);
}
// if(ObjectUtil.isNotEmpty(consumerMonthlyCard)){
// totalFee = getBigDecimal(consumerMonthlyCard,timeLong,priceResponse,totalFee,room);
// }
// totalFee = getBigDecimal(consumerWallet, timeLong, priceResponse, totalFee, byId);
} else {
......@@ -2445,6 +2464,9 @@ public class SOrderServiceImpl extends ServiceImpl<SOrderMapper, SOrder> impleme
priceResponse.setDiscount(totalFee.divide(payPrice, 2, RoundingMode.HALF_UP).multiply(new BigDecimal(100)));
totalFee = getBigDecimal(consumerWallet, activity, timeLong, priceResponse, totalFee, room, request, consumerMember);
}
if (ObjectUtil.isNotEmpty(consumerMonthlyCard)) {
totalFee = getBigDecimal(consumerMonthlyCard, timeLong, priceResponse, totalPrice, room);
}
// totalFee = getBigDecimal(consumerWallet, timeLong, priceResponse, totalFee, room);
}
......@@ -2464,10 +2486,16 @@ public class SOrderServiceImpl extends ServiceImpl<SOrderMapper, SOrder> impleme
priceResponse.setDiscount(totalFee.divide(payPrice, 2, RoundingMode.HALF_UP).multiply(new BigDecimal(100)));
totalFee = getBigDecimal(consumerWallet, activity, timeLong, priceResponse, totalFee, byId, request);
}
// if(ObjectUtil.isNotEmpty(consumerMonthlyCard)){
// totalFee = getBigDecimal(consumerMonthlyCard,timeLong,priceResponse,totalFee,room);
// }
if (CollectionUtils.isNotEmpty(consumerSecondaryCardList)) {
totalFee = getBigDecimal(consumerSecondaryCardList, priceResponse, byId, payPrice);
}
}
priceResponse.setTotalFee(payPrice);
if (ObjectUtil.isEmpty(consumerWallet) && totalFee.compareTo(new BigDecimal(0)) == 0) {
if (ObjectUtil.isEmpty(consumerWallet) && totalFee.compareTo(new BigDecimal(0)) == 0 && CollectionUtils.isEmpty(consumerSecondaryCardList) && ObjectUtil.isNotEmpty(consumerMonthlyCard)) {
priceResponse.setPayFee(payPrice);
} else {
priceResponse.setPayFee(totalFee);
......@@ -2774,6 +2802,43 @@ public class SOrderServiceImpl extends ServiceImpl<SOrderMapper, SOrder> impleme
return payPrice;
}
private BigDecimal getBigDecimal(ConsumerMonthlyCard consumerMonthlyCard, BigDecimal timeLong,
ComputedOrderPriceResponse priceResponse, BigDecimal totalFee, SRoom room) {
if (consumerMonthlyCard.getFreeDuration().compareTo(timeLong) >= 0) {
priceResponse.setDuration(timeLong);
priceResponse.setRemainingDuration(consumerMonthlyCard.getFreeDuration().subtract(timeLong));
priceResponse.setDiscount(BigDecimal.ZERO);
totalFee = new BigDecimal(0);
priceResponse.setMemberDiscount(new BigDecimal(0.00));
priceResponse.setTotalFeeNow(priceResponse.getTotalFee());
priceResponse.setPayFee(BigDecimal.ZERO);
} else if (consumerMonthlyCard.getFreeDuration().compareTo(timeLong) < 0) {
priceResponse.setDuration(consumerMonthlyCard.getFreeDuration());
priceResponse.setRemainingDuration(new BigDecimal(0));
BigDecimal remainingBalance = consumerMonthlyCard.getFreeDuration().multiply(room.getPrice());
remainingBalance = totalFee.subtract(remainingBalance);
priceResponse.setTotalFeeNow(remainingBalance);
priceResponse.setMemberDiscount(totalFee.subtract(remainingBalance));
totalFee = remainingBalance;
priceResponse.setPayFee(remainingBalance);
}
return totalFee;
}
private BigDecimal getBigDecimal(List<ConsumerSecondaryCard> consumerSecondaryCardList,
ComputedOrderPriceResponse priceResponse, SPack byId, BigDecimal payPrice) {
//获取集合中次数最少的次卡,次数不低于0
ConsumerSecondaryCard consumerSecondaryCard = consumerSecondaryCardList.stream().min(Comparator.comparing(ConsumerSecondaryCard::getNumber)).get();
if (consumerSecondaryCard.getPackId().equals(byId.getId())) {
priceResponse.setDiscount(BigDecimal.ZERO);
priceResponse.setMemberDiscount(BigDecimal.ZERO);
priceResponse.setTotalFeeNow(payPrice);
priceResponse.setPayFee(BigDecimal.ZERO);
payPrice = BigDecimal.ZERO;
}
return payPrice;
}
private BigDecimal computeTotalPrice(Long packId, BigDecimal totalPrice) {
SPack pack = packService.getById(packId);
if (Objects.isNull(pack)) {
......
package share.system.service.impl;
import cn.hutool.core.util.ObjectUtil;
import cn.hutool.json.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import share.common.core.redis.RedisUtil;
import share.common.enums.ReceiptRdeisEnum;
import share.common.enums.YesNoEnum;
import share.common.exception.base.BaseException;
import share.common.utils.BaseUtil;
......@@ -23,7 +26,9 @@ import share.system.response.SecondaryCardOrderPayResultResponse;
import share.system.service.*;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
* 次卡购买记录Service业务层处理
......@@ -43,6 +48,8 @@ public class SecondaryCardOrderServiceImpl extends ServiceImpl<SecondaryCardOrde
private SecondaryCardConfService secondaryCardConfService;
@Autowired
private ConsumerSecondaryCardService consumerSecondaryCardService;
@Autowired
private RedisUtil redisUtil;
/**
* 查询次卡购买记录
......@@ -157,7 +164,20 @@ public class SecondaryCardOrderServiceImpl extends ServiceImpl<SecondaryCardOrde
consumerSecondaryCard.setPackId(secondaryCardConf.getPackId());
consumerSecondaryCard.setExpirationDate(DateUtils.addYears(new Date(), secondaryCardConf.getValidityPeriod()));
consumerSecondaryCard.setNumber(secondaryCardConf.getNumber());
//添加,返回id
consumerSecondaryCardService.save(consumerSecondaryCard);
Map<String, String> map = new HashMap<>();
map.put("consumerSecondaryCardId", String.valueOf(consumerSecondaryCard.getId()));
map.put("expirationTime", consumerSecondaryCard.getExpirationDate().toString());
JSONObject jsonObject = new JSONObject(map);
new Thread(() -> {
try {
Thread.sleep(1000);
redisUtil.set(ReceiptRdeisEnum.SECONDARY_CARD.getValue() + consumerSecondaryCard.getId(), jsonObject.toString());
} catch (InterruptedException e) {
e.printStackTrace();
}
}).start();
}
@Override
......
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