Commit e22fd60d by 吕明尚

用户成为充值会员或者权益会员时,前三个月的累计消费进行积分

parent 4dfba59d
......@@ -397,7 +397,7 @@ public class RedisTask {
Map<String, String> map = new HashMap<>();
map.put("orderNo", sOrder.getOrderNo());
//当前时间加15分钟
Date date = DateUtil.offsetMinute(new Date(), 15);
Date date = DateUtil.offsetMinute(sOrder.getEndDate(), 15);
map.put("expirationTime", date.toString());
JSONObject json = new JSONObject(map);
redisUtil.set(ReceiptRdeisEnum.ROOM_EXPIRE_TIME.getValue() + sOrder.getOrderNo(), json.toString());
......
......@@ -68,4 +68,6 @@ public interface ConsumerWalletService extends IService<ConsumerWallet> {
boolean addConsumerWallet(ConsumerWallet consumerWallet);
boolean editConsumerWallet(ConsumerWallet consumerWallet, Recharge recharge, ConsumerMember one);
void accumulatedConsumptionStatistics(Long consumerId);
}
package share.system.service.impl;
import cn.hutool.core.collection.CollectionUtil;
import cn.hutool.core.util.ObjectUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
......@@ -7,9 +8,7 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import share.common.enums.GiveTypeEnum;
import share.common.enums.MemberTypeEnum;
import share.common.enums.YesNoEnum;
import share.common.enums.*;
import share.common.utils.DateUtils;
import share.system.domain.*;
import share.system.domain.vo.ConsumerWalletVo;
......@@ -18,8 +17,10 @@ import share.system.service.*;
import java.math.BigDecimal;
import java.math.RoundingMode;
import java.util.Date;
import java.util.List;
import java.text.SimpleDateFormat;
import java.util.*;
import java.util.function.Function;
import java.util.stream.Collectors;
/**
* 会员钱包Service业务层处理
......@@ -32,7 +33,8 @@ public class ConsumerWalletServiceImpl extends ServiceImpl<ConsumerWalletMapper,
private static final Logger logger = LoggerFactory.getLogger(ConsumerWalletServiceImpl.class);
@Autowired
private ConsumerWalletMapper consumerWalletMapper;
@Autowired
private ConsumerWalletService consumerWalletService;
@Autowired
private SConsumerService sConsumerService;
@Autowired
......@@ -49,6 +51,12 @@ public class ConsumerWalletServiceImpl extends ServiceImpl<ConsumerWalletMapper,
private ConsumerMemberService consumerMemberService;
@Autowired
private MemberProgressLogService memberProgressLogService;
@Autowired
private ISOrderService orderService;
@Autowired
private ISCouponService sCouponService;
@Autowired
private ISConsumerCouponService consumerCouponService;
/**
* 查询会员钱包
......@@ -152,6 +160,7 @@ public class ConsumerWalletServiceImpl extends ServiceImpl<ConsumerWalletMapper,
durationLogService.save(durationLog);
}
if (consumerWallet.getRemainingIntegral().compareTo(new BigDecimal(0)) > 0) {
accumulatedConsumptionStatistics(consumerWallet, one, memberConfig);
IntegralLog integralLog = new IntegralLog();
integralLog.setConsumerId(consumerWallet.getConsumerId());
integralLog.setCurrentIntegral(new BigDecimal(0));
......@@ -266,4 +275,98 @@ public class ConsumerWalletServiceImpl extends ServiceImpl<ConsumerWalletMapper,
consumerMemberService.updateConsumerMember(one);
return i == 1;
}
private void accumulatedConsumptionStatistics(ConsumerWallet consumerWallet, ConsumerMember one, MemberConfig memberConfig) {
final BigDecimal[] consumption = {BigDecimal.ZERO};
//查询含当天23:59:59以及往前90天的00:00:00整天的订单
Calendar calendar = Calendar.getInstance();
// 设置时间为当天的23:59:59
calendar.set(Calendar.HOUR_OF_DAY, 23);
calendar.set(Calendar.MINUTE, 59);
calendar.set(Calendar.SECOND, 59);
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
Date sameDay = calendar.getTime();
// 计算往前90天的日期
calendar.add(Calendar.DATE, -90);
// 设置为那天的00:00:00
calendar.set(Calendar.HOUR_OF_DAY, 0);
calendar.set(Calendar.MINUTE, 0);
calendar.set(Calendar.SECOND, 0);
Date beforeDay = calendar.getTime();
List<SOrder> orderList = orderService.list(new LambdaQueryWrapper<SOrder>()
.between(SOrder::getCreateTime, beforeDay, sameDay)
.eq(SOrder::getConsumerId, one.getConsumerId())
.eq(SOrder::getPayStatus, YesNoEnum.yes.getIndex())
.notIn(SOrder::getRefundStatus, RefundStatusEnum.getRefundedStatus())
.in(SOrder::getStatus, OrderStatusEnum.getValidOrderStatus())
.eq(SOrder::getIsDelete, YesNoEnum.no.getIndex()));
if (CollectionUtil.isEmpty(orderList)) {
return;
}
Map<Long, SCoupon> sCouponMap = sCouponService.list().stream().collect(Collectors.toMap(SCoupon::getId, Function.identity()));
//优惠券id集合,去掉为null的
List<Long> ids = orderList.stream().map(SOrder::getCouponId).filter(Objects::nonNull).collect(Collectors.toList());
List<SConsumerCoupon> consumerCouponList = consumerCouponService.selectByIds(ids).stream()
.filter(s -> s.getCouponType().equals(CouponTypeEnum.CASH.getCode())).collect(Collectors.toList());
consumerCouponList.stream().forEach(item -> {
if (ObjectUtil.isNotEmpty(item.getCouponPayPrice())) {
consumption[0] = consumption[0].add(item.getCouponPayPrice());
} else {
consumption[0] = consumption[0].add(sCouponMap.get(item.getCouponId()).getCouponPayPrice());
}
});
if (one.getMemberType().equals(MemberTypeEnum.RIGHTS.getIndex())) {
//orderList累加payPrice
consumption[0] = consumption[0].add(orderList.stream().map(SOrder::getPayPrice).reduce(BigDecimal.ZERO, BigDecimal::add));
}
if (consumption[0].compareTo(BigDecimal.ZERO) != 0) {
IntegralLog integralLog = new IntegralLog();
integralLog.setConsumerId(consumerWallet.getConsumerId());
integralLog.setCurrentIntegral(new BigDecimal(0));
integralLog.setVariableIntegral(consumerWallet.getRemainingIntegral());
integralLog.setOperationTime(new Date());
integralLog.setCreateTime(new Date());
integralLog.setOperationType(YesNoEnum.yes.getIndex());
integralLogService.save(integralLog);
MemberProgressLog memberProgressLog = new MemberProgressLog();
memberProgressLog.setConsumerId(consumerWallet.getConsumerId());
memberProgressLog.setCurrentProgress(new BigDecimal(0));
memberProgressLog.setVariableProgress(consumerWallet.getRemainingIntegral());
memberProgressLog.setOperationTime(new Date());
memberProgressLog.setOperationType(YesNoEnum.yes.getIndex());
memberProgressLog.setCreateTime(new Date());
memberProgressLog.setExpirationTime(DateUtils.addYears(new Date(), memberConfig.getValidityPeriod().intValue()));
memberProgressLogService.save(memberProgressLog);
MemberConfig newOne = memberConfigService.getOne(new LambdaQueryWrapper<MemberConfig>()
.eq(MemberConfig::getMemberType, one.getMemberType())
.eq(MemberConfig::getMembershipLevel, one.getMembershipLevel() + 1L));
MemberConfig newTwo = memberConfigService.getOne(new LambdaQueryWrapper<MemberConfig>()
.eq(MemberConfig::getMemberType, one.getMemberType())
.eq(MemberConfig::getMembershipLevel, one.getMembershipLevel() + 2L));
if (ObjectUtil.isNotEmpty(newOne) && one.getMembershipProgress().compareTo(BigDecimal.valueOf(newOne.getLimitRequirements())) >= 0) {
if (ObjectUtil.isNotEmpty(newTwo) && one.getMembershipProgress().compareTo(BigDecimal.valueOf(newTwo.getLimitRequirements())) <= 0) {
one.setMembershipLevel(one.getMembershipLevel() + 1L);
one.setMemberConfigId(newOne.getId());
consumerMemberService.updateConsumerMember(one);
} else {
one.setMembershipLevel(one.getMembershipLevel() + 2L);
one.setMemberConfigId(newTwo.getId());
consumerMemberService.updateConsumerMember(one);
}
}
consumerWallet.setRemainingIntegral(consumerWallet.getRemainingIntegral().add(consumption[0]));
consumerWalletMapper.updateConsumerWallet(consumerWallet);
}
}
@Override
public void accumulatedConsumptionStatistics(Long consumerId) {
ConsumerWallet consumerWallet = consumerWalletService.getOne(new LambdaQueryWrapper<ConsumerWallet>().eq(ConsumerWallet::getConsumerId, consumerId));
ConsumerMember one = consumerMemberService.getOne(new LambdaQueryWrapper<ConsumerMember>().eq(ConsumerMember::getConsumerId, consumerId));
MemberConfig memberConfig = memberConfigService.getById(one.getMemberConfigId());
accumulatedConsumptionStatistics(consumerWallet, one, memberConfig);
}
}
......@@ -251,6 +251,7 @@ public class EquityMembersOrderServiceImpl extends ServiceImpl<EquityMembersOrde
}
consumerWalletOne.setCreateTime(new Date());
consumerWalletService.save(consumerWalletOne);
consumerWalletService.accumulatedConsumptionStatistics(equityMembersOrder.getConsumerId());
}
updateEquityMembersOrder(equityMembersOrder);
}
......
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