From a5963ccfa9273f4b8ff0800c9d71c487f300debc Mon Sep 17 00:00:00 2001
From: Helius <wangdoubleone@gmail.com>
Date: Fri, 26 Jan 2024 11:36:35 +0800
Subject: [PATCH] fix
---
src/main/java/cc/mrbird/febs/mall/entity/MallMember.java | 4 ++
src/main/java/cc/mrbird/febs/mall/controller/ApiMallMemberController.java | 6 +++
src/main/java/cc/mrbird/febs/mall/service/IApiMallMemberService.java | 3 +
src/main/java/cc/mrbird/febs/mall/service/impl/ApiMallMemberServiceImpl.java | 56 ++++++++++++++++++++++++++++
4 files changed, 69 insertions(+), 0 deletions(-)
diff --git a/src/main/java/cc/mrbird/febs/mall/controller/ApiMallMemberController.java b/src/main/java/cc/mrbird/febs/mall/controller/ApiMallMemberController.java
index a69a704..34088f0 100644
--- a/src/main/java/cc/mrbird/febs/mall/controller/ApiMallMemberController.java
+++ b/src/main/java/cc/mrbird/febs/mall/controller/ApiMallMemberController.java
@@ -269,4 +269,10 @@
return memberService.couponDetails(id);
}
+
+ @ApiOperation(value = "登录事件", notes = "登录事件")
+ @GetMapping(value = "/loginEvent")
+ public FebsResponse loginEvent() {
+ return new FebsResponse().success().data(memberService.loginEvent());
+ }
}
diff --git a/src/main/java/cc/mrbird/febs/mall/entity/MallMember.java b/src/main/java/cc/mrbird/febs/mall/entity/MallMember.java
index 9ca0af3..f23b060 100644
--- a/src/main/java/cc/mrbird/febs/mall/entity/MallMember.java
+++ b/src/main/java/cc/mrbird/febs/mall/entity/MallMember.java
@@ -170,4 +170,8 @@
private Date birthday;
private String realName;
+
+ private Date lastLoginTime;
+
+ private Date vipLevelTime;
}
diff --git a/src/main/java/cc/mrbird/febs/mall/service/IApiMallMemberService.java b/src/main/java/cc/mrbird/febs/mall/service/IApiMallMemberService.java
index b5f756d..9bd68b3 100644
--- a/src/main/java/cc/mrbird/febs/mall/service/IApiMallMemberService.java
+++ b/src/main/java/cc/mrbird/febs/mall/service/IApiMallMemberService.java
@@ -14,6 +14,7 @@
import java.io.IOException;
import java.math.BigDecimal;
import java.util.List;
+import java.util.Map;
public interface IApiMallMemberService extends IService<MallMember> {
FebsResponse register(RegisterDto registerDto);
@@ -94,4 +95,6 @@
FebsResponse couponDetails(Long id);
FebsResponse setInvite(ApiSetInviteDto apiSetInviteDto);
+
+ Map<String, Object> loginEvent();
}
diff --git a/src/main/java/cc/mrbird/febs/mall/service/impl/ApiMallMemberServiceImpl.java b/src/main/java/cc/mrbird/febs/mall/service/impl/ApiMallMemberServiceImpl.java
index bf4b5ca..fdb54ab 100644
--- a/src/main/java/cc/mrbird/febs/mall/service/impl/ApiMallMemberServiceImpl.java
+++ b/src/main/java/cc/mrbird/febs/mall/service/impl/ApiMallMemberServiceImpl.java
@@ -14,10 +14,12 @@
import cc.mrbird.febs.mall.vo.*;
import cc.mrbird.febs.pay.model.BrandWCPayRequestData;
import cc.mrbird.febs.pay.service.IXcxPayService;
+import cc.mrbird.febs.vip.VipSettingUnAliveSettingBo;
import cc.mrbird.febs.vip.entity.MallVipConfig;
import cc.mrbird.febs.vip.mapper.MallVipConfigMapper;
import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.collection.CollUtil;
+import cn.hutool.core.date.DateUnit;
import cn.hutool.core.date.DateUtil;
import cn.hutool.core.util.IdUtil;
import cn.hutool.core.util.ObjectUtil;
@@ -43,6 +45,7 @@
import java.io.IOException;
import java.math.BigDecimal;
import java.util.*;
+import java.util.stream.Collectors;
/**
* @author wzy
@@ -1077,4 +1080,57 @@
String wechatLoginUrl =xcxProperties.getWecharLoginUrl();
return String.format(wechatLoginUrl, xcxProperties.getXcxAppid(), xcxProperties.getXcxSecret(), code);
}
+
+ @Override
+ public Map<String, Object> loginEvent() {
+ MallMember loginUser = LoginUserUtil.getLoginUser();
+
+ MallMember member = this.baseMapper.selectById(loginUser.getId());
+
+ DataDictionaryCustom dic = dataDictionaryCustomMapper.selectDicDataByTypeAndCode(DataDictionaryEnum.UNALIVE_COUPON.getType(), DataDictionaryEnum.UNALIVE_COUPON.getCode());
+ if (dic == null || StrUtil.isBlank(dic.getValue())) {
+ return new HashMap<>();
+ }
+
+ Date today = new Date();
+ Date lastLoginTime = member.getLastLoginTime();
+ if (lastLoginTime == null) {
+ lastLoginTime = new Date();
+ }
+
+ long days = DateUtil.between(DateUtil.endOfDay(lastLoginTime), DateUtil.endOfDay(today), DateUnit.DAY);
+
+ List<VipSettingUnAliveSettingBo> list = JSONObject.parseArray(dic.getValue(), VipSettingUnAliveSettingBo.class);
+ List<Long> couponIds = list.stream().filter(item -> {
+ return item.getDay() <= days && item.getCouponId() != null;
+ }).map(VipSettingUnAliveSettingBo::getCouponId).collect(Collectors.toList());
+
+ LambdaQueryWrapper<MallGoodsCoupon> query = new LambdaQueryWrapper<>();
+ query.in(MallGoodsCoupon::getId, couponIds)
+ .eq(MallGoodsCoupon::getState, 2);
+ List<MallGoodsCoupon> coupons = mallGoodsCouponMapper.selectList(query);
+
+ coupons.forEach(item -> {
+ MallMemberCoupon memberCoupon = new MallMemberCoupon();
+ memberCoupon.setCouponId(item.getId());
+ memberCoupon.setCouponName(item.getName());
+ memberCoupon.setInviteId(member.getInviteId());
+ memberCoupon.setCouponUuid(IdUtil.simpleUUID());
+ memberCoupon.setState(1);
+ memberCoupon.setExpireTime(DateUtil.offsetDay(DateUtil.date(), item.getExpireDay()));
+ memberCoupon.setMemberId(member.getId());
+ mallMemberCouponMapper.insert(memberCoupon);
+ });
+
+ MallMember mallMember = new MallMember();
+ mallMember.setId(member.getId());
+ mallMember.setLastLoginTime(new Date());
+ this.baseMapper.updateById(mallMember);
+
+ Map<String, Object> result = new HashMap<>();
+ result.put("coupon", coupons);
+ return result;
+ }
+
+
}
--
Gitblit v1.9.1