Commit 793ec24d by 吕明尚

优化会员等级滚动降级定时任务

parent 1f1cc81f
...@@ -344,110 +344,7 @@ public class RedisTask { ...@@ -344,110 +344,7 @@ public class RedisTask {
redisUtil.delete(o); redisUtil.delete(o);
throw new BaseException("订单不存在!"); throw new BaseException("订单不存在!");
} }
//查询是否有上级 extracted(sOrder);
LambdaQueryWrapper<SharingActivities> sharingActivitiesLambdaQueryWrapper = new LambdaQueryWrapper<>();
sharingActivitiesLambdaQueryWrapper.eq(SharingActivities::getNewUid, sOrder.getConsumerId());
sharingActivitiesLambdaQueryWrapper.eq(SharingActivities::getIsDelete, YesNoEnum.no.getIndex());
SharingActivities sharingActivities = sharingActivitiesService.getOne(sharingActivitiesLambdaQueryWrapper);
if (ObjectUtil.isNotEmpty(sharingActivities)) {
//查询当前用户是否只有一个订单
LambdaQueryWrapper<SOrder> sOrderLambdaQueryWrapper = new LambdaQueryWrapper<>();
sOrderLambdaQueryWrapper.eq(SOrder::getConsumerId, sOrder.getConsumerId());
sOrderLambdaQueryWrapper.eq(SOrder::getPayStatus, YesNoEnum.yes.getIndex());
sOrderLambdaQueryWrapper.notIn(SOrder::getRefundStatus, RefundStatusEnum.getRefundedStatus());
sOrderLambdaQueryWrapper.in(SOrder::getStatus, OrderStatusEnum.getValidOrderStatus());
sOrderLambdaQueryWrapper.eq(SOrder::getIsDelete, YesNoEnum.no.getIndex());
List<SOrder> sOrderList = isOrderService.list(sOrderLambdaQueryWrapper);
if (sOrderList.size() == 1) {
LambdaQueryWrapper<ConsumerWallet> consumerWalletLambdaQueryWrapper = new LambdaQueryWrapper<>();
consumerWalletLambdaQueryWrapper.eq(ConsumerWallet::getConsumerId, sharingActivities.getUid());
ConsumerWallet consumerWallet = consumerWalletService.getOne(consumerWalletLambdaQueryWrapper);
if (ObjectUtil.isNotEmpty(consumerWallet)) {
//添加时长
BigDecimal anHour = new BigDecimal(1.0);
BigDecimal accumulateEquityFund = ObjectUtil.isNotEmpty(consumerWallet.getRemainingDuration()) ? consumerWallet.getRemainingDuration() : BigDecimal.ZERO;
consumerWallet.setRemainingDuration(accumulateEquityFund.add(anHour));
consumerWallet.setUpdateTime(DateUtils.getNowDate());
DurationLog durationLog = new DurationLog();
durationLog.setConsumerId(consumerWallet.getConsumerId());
durationLog.setVariableDuration(anHour);
durationLog.setCurrentDuration(accumulateEquityFund);
durationLog.setOperationType(YesNoEnum.yes.getIndex());
durationLog.setOperationTime(DateUtils.getNowDate());
durationLogService.insertDurationLog(durationLog);
consumerWalletService.updateConsumerWallet(consumerWallet);
} else {
//新增钱包
ConsumerWallet newConsumerWallet = new ConsumerWallet();
BigDecimal defaultVlue = new BigDecimal(0.0);
newConsumerWallet.setConsumerId(sharingActivities.getUid());
newConsumerWallet.setBalance(defaultVlue);
newConsumerWallet.setRemainingIntegral(defaultVlue);
newConsumerWallet.setEquityFund(defaultVlue);
newConsumerWallet.setAccumulateEquityFund(defaultVlue);
BigDecimal anHour = new BigDecimal(1.0);
newConsumerWallet.setRemainingDuration(defaultVlue.add(anHour));
newConsumerWallet.setUpdateTime(DateUtils.getNowDate());
consumerWalletService.insertConsumerWallet(newConsumerWallet);
DurationLog newDurationLog = new DurationLog();
newDurationLog.setConsumerId(consumerWallet.getConsumerId());
newDurationLog.setVariableDuration(anHour);
newDurationLog.setCurrentDuration(consumerWallet.getRemainingDuration());
newDurationLog.setOperationType(YesNoEnum.yes.getIndex());
newDurationLog.setOperationTime(DateUtils.getNowDate());
durationLogService.insertDurationLog(newDurationLog);
}
}
//查询会员用户类型
LambdaQueryWrapper<ConsumerMember> consumerMemberWrapper = new LambdaQueryWrapper<>();
consumerMemberWrapper.eq(ConsumerMember::getConsumerId, sharingActivities.getUid());
ConsumerMember consumerMember = consumerMemberService.getOne(consumerMemberWrapper);
LambdaQueryWrapper<ConsumerMember> newConsumerMemberQueryWrapper = new LambdaQueryWrapper<>();
newConsumerMemberQueryWrapper.eq(ConsumerMember::getConsumerId, sharingActivities.getNewUid());
ConsumerMember newConsumerMember = consumerMemberService.getOne(newConsumerMemberQueryWrapper);
if (!(ObjectUtils.isEmpty(newConsumerMember)) && !(ObjectUtils.isEmpty(consumerMember))) {
//判断是否为权益会员和会员是否有效
if (YesNoEnum.yes.getIndex().equals(consumerMember.getIsRights())
&& new Date().getTime() < consumerMember.getExpirationDate().getTime()
&& ((YesNoEnum.yes.getIndex().equals(newConsumerMember.getIsRights())
&& new Date().getTime() < newConsumerMember.getExpirationDate().getTime())
|| (newConsumerMember.getIsRecharge().equals(YesNoEnum.yes.getIndex())))
) {
Boolean aBoolean = redisTemplate.hasKey(ReceiptRdeisEnum.EQUITY_MEMBERS_TIME.getValue() + sharingActivities.getUid().toString());
Boolean newAboolean = redisTemplate.hasKey(ReceiptRdeisEnum.EQUITY_MEMBERS_TIME.getValue() + sharingActivities.getNewUid().toString());
if (aBoolean && (newAboolean || newConsumerMember.getIsRecharge().equals(YesNoEnum.yes.getIndex()))) {
LambdaQueryWrapper<ConsumerWallet> consumerWalletLambdaQueryWrapper = new LambdaQueryWrapper<>();
consumerWalletLambdaQueryWrapper.eq(ConsumerWallet::getConsumerId, sharingActivities.getUid());
ConsumerWallet consumerWallet = consumerWalletService.getOne(consumerWalletLambdaQueryWrapper);
BigDecimal payPrice = sOrder.getPayPrice();
if (payPrice.signum() > 0) {
String equityFund = sysConfigService.selectConfigByKey("sys.equityFundLog.equityFund");
BigDecimal addEquityFund = payPrice.multiply(new BigDecimal(equityFund)).setScale(2, RoundingMode.HALF_UP);
// BigDecimal addEquityFund = new BigDecimal(99).multiply(new BigDecimal(equityFund)).setScale(2, RoundingMode.HALF_UP);
// BigDecimal aEquityFund = ObjectUtil.isNotEmpty(consumerWallet.getEquityFund()) ? consumerWallet.getEquityFund() : BigDecimal.ZERO;
// consumerWallet.setEquityFund(aEquityFund.add(addEquityFund));
BigDecimal accumulateEquityFund = ObjectUtil.isNotEmpty(consumerWallet.getAccumulateEquityFund()) ? consumerWallet.getAccumulateEquityFund() : BigDecimal.ZERO;
consumerWallet.setAccumulateEquityFund(accumulateEquityFund.
add(addEquityFund));
consumerWallet.setUpdateTime(DateUtils.getNowDate());
consumerWalletService.updateConsumerWallet(consumerWallet);
//添加临时权益金日志记录
String equityFundExc = sysConfigService.selectConfigByKey("sys.equityFundExcess.equityFundExcess");
EquityFundExcess equityFundExcess = new EquityFundExcess();
equityFundExcess.setExpireTime(DateUtils.addDays(new Date(), Integer.parseInt(equityFundExc)));
equityFundExcess.setEquityFund(addEquityFund);
equityFundExcess.setOutTradeNo(sOrder.getOrderNo());
equityFundExcess.setUid(sharingActivities.getUid());
equityFundExcess.setNewUid(sharingActivities.getNewUid());
equityFundExcessService.insertEquityFundExcess(equityFundExcess);
}
}
}
}
}
if (extracted(o, sOrders, sOrder)) return; if (extracted(o, sOrders, sOrder)) return;
//更改订单状态 //更改订单状态
sOrder.setStatus(OrderStatusEnum.USED.getCode()); sOrder.setStatus(OrderStatusEnum.USED.getCode());
...@@ -486,6 +383,111 @@ public class RedisTask { ...@@ -486,6 +383,111 @@ public class RedisTask {
logger.debug("AutoAddSCleanRecords:自动添加保洁记录结束"); logger.debug("AutoAddSCleanRecords:自动添加保洁记录结束");
} }
private void extracted(SOrder sOrder) {
//查询是否有上级
LambdaQueryWrapper<SharingActivities> sharingActivitiesLambdaQueryWrapper = new LambdaQueryWrapper<>();
sharingActivitiesLambdaQueryWrapper.eq(SharingActivities::getNewUid, sOrder.getConsumerId());
sharingActivitiesLambdaQueryWrapper.eq(SharingActivities::getIsDelete, YesNoEnum.no.getIndex());
SharingActivities sharingActivities = sharingActivitiesService.getOne(sharingActivitiesLambdaQueryWrapper);
if (ObjectUtil.isNotEmpty(sharingActivities)) {
//查询当前用户是否只有一个订单
LambdaQueryWrapper<SOrder> sOrderLambdaQueryWrapper = new LambdaQueryWrapper<>();
sOrderLambdaQueryWrapper.eq(SOrder::getConsumerId, sOrder.getConsumerId());
sOrderLambdaQueryWrapper.eq(SOrder::getPayStatus, YesNoEnum.yes.getIndex());
sOrderLambdaQueryWrapper.notIn(SOrder::getRefundStatus, RefundStatusEnum.getRefundedStatus());
sOrderLambdaQueryWrapper.in(SOrder::getStatus, OrderStatusEnum.getValidOrderStatus());
sOrderLambdaQueryWrapper.eq(SOrder::getIsDelete, YesNoEnum.no.getIndex());
List<SOrder> sOrderList = isOrderService.list(sOrderLambdaQueryWrapper);
if (sOrderList.size() == 1) {
LambdaQueryWrapper<ConsumerWallet> consumerWalletLambdaQueryWrapper = new LambdaQueryWrapper<>();
consumerWalletLambdaQueryWrapper.eq(ConsumerWallet::getConsumerId, sharingActivities.getUid());
ConsumerWallet consumerWallet = consumerWalletService.getOne(consumerWalletLambdaQueryWrapper);
if (ObjectUtil.isNotEmpty(consumerWallet)) {
//添加时长
BigDecimal anHour = new BigDecimal(1.0);
BigDecimal accumulateEquityFund = ObjectUtil.isNotEmpty(consumerWallet.getRemainingDuration()) ? consumerWallet.getRemainingDuration() : BigDecimal.ZERO;
consumerWallet.setRemainingDuration(accumulateEquityFund.add(anHour));
consumerWallet.setUpdateTime(DateUtils.getNowDate());
DurationLog durationLog = new DurationLog();
durationLog.setConsumerId(consumerWallet.getConsumerId());
durationLog.setVariableDuration(anHour);
durationLog.setCurrentDuration(accumulateEquityFund);
durationLog.setOperationType(YesNoEnum.yes.getIndex());
durationLog.setOperationTime(DateUtils.getNowDate());
durationLogService.insertDurationLog(durationLog);
consumerWalletService.updateConsumerWallet(consumerWallet);
} else {
//新增钱包
ConsumerWallet newConsumerWallet = new ConsumerWallet();
BigDecimal defaultVlue = new BigDecimal(0.0);
newConsumerWallet.setConsumerId(sharingActivities.getUid());
newConsumerWallet.setBalance(defaultVlue);
newConsumerWallet.setRemainingIntegral(defaultVlue);
newConsumerWallet.setEquityFund(defaultVlue);
newConsumerWallet.setAccumulateEquityFund(defaultVlue);
BigDecimal anHour = new BigDecimal(1.0);
newConsumerWallet.setRemainingDuration(defaultVlue.add(anHour));
newConsumerWallet.setUpdateTime(DateUtils.getNowDate());
consumerWalletService.insertConsumerWallet(newConsumerWallet);
DurationLog newDurationLog = new DurationLog();
newDurationLog.setConsumerId(consumerWallet.getConsumerId());
newDurationLog.setVariableDuration(anHour);
newDurationLog.setCurrentDuration(consumerWallet.getRemainingDuration());
newDurationLog.setOperationType(YesNoEnum.yes.getIndex());
newDurationLog.setOperationTime(DateUtils.getNowDate());
durationLogService.insertDurationLog(newDurationLog);
}
}
//查询会员用户类型
LambdaQueryWrapper<ConsumerMember> consumerMemberWrapper = new LambdaQueryWrapper<>();
consumerMemberWrapper.eq(ConsumerMember::getConsumerId, sharingActivities.getUid());
ConsumerMember consumerMember = consumerMemberService.getOne(consumerMemberWrapper);
LambdaQueryWrapper<ConsumerMember> newConsumerMemberQueryWrapper = new LambdaQueryWrapper<>();
newConsumerMemberQueryWrapper.eq(ConsumerMember::getConsumerId, sharingActivities.getNewUid());
ConsumerMember newConsumerMember = consumerMemberService.getOne(newConsumerMemberQueryWrapper);
if (!(ObjectUtils.isEmpty(newConsumerMember)) && !(ObjectUtils.isEmpty(consumerMember))) {
//判断是否为权益会员和会员是否有效
if (YesNoEnum.yes.getIndex().equals(consumerMember.getIsRights())
&& new Date().getTime() < consumerMember.getExpirationDate().getTime()
&& ((YesNoEnum.yes.getIndex().equals(newConsumerMember.getIsRights())
&& new Date().getTime() < newConsumerMember.getExpirationDate().getTime())
|| (newConsumerMember.getIsRecharge().equals(YesNoEnum.yes.getIndex())))
) {
Boolean aBoolean = redisTemplate.hasKey(ReceiptRdeisEnum.EQUITY_MEMBERS_TIME.getValue() + sharingActivities.getUid().toString());
Boolean newAboolean = redisTemplate.hasKey(ReceiptRdeisEnum.EQUITY_MEMBERS_TIME.getValue() + sharingActivities.getNewUid().toString());
if (aBoolean && (newAboolean || newConsumerMember.getIsRecharge().equals(YesNoEnum.yes.getIndex()))) {
LambdaQueryWrapper<ConsumerWallet> consumerWalletLambdaQueryWrapper = new LambdaQueryWrapper<>();
consumerWalletLambdaQueryWrapper.eq(ConsumerWallet::getConsumerId, sharingActivities.getUid());
ConsumerWallet consumerWallet = consumerWalletService.getOne(consumerWalletLambdaQueryWrapper);
BigDecimal payPrice = sOrder.getPayPrice();
if (payPrice.signum() > 0) {
String equityFund = sysConfigService.selectConfigByKey("sys.equityFundLog.equityFund");
BigDecimal addEquityFund = payPrice.multiply(new BigDecimal(equityFund)).setScale(2, RoundingMode.HALF_UP);
// BigDecimal addEquityFund = new BigDecimal(99).multiply(new BigDecimal(equityFund)).setScale(2, RoundingMode.HALF_UP);
// BigDecimal aEquityFund = ObjectUtil.isNotEmpty(consumerWallet.getEquityFund()) ? consumerWallet.getEquityFund() : BigDecimal.ZERO;
// consumerWallet.setEquityFund(aEquityFund.add(addEquityFund));
BigDecimal accumulateEquityFund = ObjectUtil.isNotEmpty(consumerWallet.getAccumulateEquityFund()) ? consumerWallet.getAccumulateEquityFund() : BigDecimal.ZERO;
consumerWallet.setAccumulateEquityFund(accumulateEquityFund.
add(addEquityFund));
consumerWallet.setUpdateTime(DateUtils.getNowDate());
consumerWalletService.updateConsumerWallet(consumerWallet);
//添加临时权益金日志记录
String equityFundExc = sysConfigService.selectConfigByKey("sys.equityFundExcess.equityFundExcess");
EquityFundExcess equityFundExcess = new EquityFundExcess();
equityFundExcess.setExpireTime(DateUtils.addDays(new Date(), Integer.parseInt(equityFundExc)));
equityFundExcess.setEquityFund(addEquityFund);
equityFundExcess.setOutTradeNo(sOrder.getOrderNo());
equityFundExcess.setUid(sharingActivities.getUid());
equityFundExcess.setNewUid(sharingActivities.getNewUid());
equityFundExcessService.insertEquityFundExcess(equityFundExcess);
}
}
}
}
}
}
@XxlJob("autoRoomExpireTime") @XxlJob("autoRoomExpireTime")
public void autoRoomExpireTime() { public void autoRoomExpireTime() {
logger.debug("autoRoomExpireTime:房间15分钟续单开始"); logger.debug("autoRoomExpireTime:房间15分钟续单开始");
......
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