生日有礼 弹窗 优惠券有效期
短信店铺配置 所有店铺
This commit is contained in:
@@ -57,6 +57,10 @@ public class ShopUser implements Serializable {
|
|||||||
* 会员生日
|
* 会员生日
|
||||||
*/
|
*/
|
||||||
private String birthDay;
|
private String birthDay;
|
||||||
|
/**
|
||||||
|
* 会员生日提醒
|
||||||
|
*/
|
||||||
|
private String birthDayRemind;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 0-女 1男
|
* 0-女 1男
|
||||||
|
|||||||
@@ -1,10 +1,6 @@
|
|||||||
package com.czg.market.entity;
|
package com.czg.market.entity;
|
||||||
|
|
||||||
import com.czg.market.dto.CouponInfoDTO;
|
import com.czg.market.dto.CouponInfoDTO;
|
||||||
import com.mybatisflex.annotation.Column;
|
|
||||||
import com.mybatisflex.annotation.Id;
|
|
||||||
import com.mybatisflex.annotation.KeyType;
|
|
||||||
import com.mybatisflex.annotation.Table;
|
|
||||||
import jakarta.validation.Valid;
|
import jakarta.validation.Valid;
|
||||||
import lombok.AllArgsConstructor;
|
import lombok.AllArgsConstructor;
|
||||||
import lombok.Builder;
|
import lombok.Builder;
|
||||||
@@ -13,7 +9,6 @@ import lombok.NoArgsConstructor;
|
|||||||
|
|
||||||
import java.io.Serial;
|
import java.io.Serial;
|
||||||
import java.io.Serializable;
|
import java.io.Serializable;
|
||||||
import java.time.LocalDateTime;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -37,9 +32,13 @@ public class MkBirthdayGiftConfig implements Serializable {
|
|||||||
private String userType;
|
private String userType;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 是否开启
|
* 提前天数 负数
|
||||||
*/
|
*/
|
||||||
private Integer deliverTime;
|
private Integer deliverTime;
|
||||||
|
/**
|
||||||
|
* day 天数偏移
|
||||||
|
* month 月份偏移
|
||||||
|
*/
|
||||||
private String deliverDate;
|
private String deliverDate;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ package com.czg.service.market.service.impl;
|
|||||||
import cn.hutool.core.bean.BeanUtil;
|
import cn.hutool.core.bean.BeanUtil;
|
||||||
import cn.hutool.core.date.DateTime;
|
import cn.hutool.core.date.DateTime;
|
||||||
import cn.hutool.core.date.DateUtil;
|
import cn.hutool.core.date.DateUtil;
|
||||||
|
import cn.hutool.core.date.LocalDateTimeUtil;
|
||||||
import cn.hutool.core.util.StrUtil;
|
import cn.hutool.core.util.StrUtil;
|
||||||
import com.alibaba.fastjson2.JSONArray;
|
import com.alibaba.fastjson2.JSONArray;
|
||||||
import com.alibaba.fastjson2.JSONObject;
|
import com.alibaba.fastjson2.JSONObject;
|
||||||
@@ -35,7 +36,11 @@ import org.springframework.stereotype.Service;
|
|||||||
|
|
||||||
import java.time.LocalDate;
|
import java.time.LocalDate;
|
||||||
import java.time.LocalDateTime;
|
import java.time.LocalDateTime;
|
||||||
|
import java.time.LocalTime;
|
||||||
|
import java.time.temporal.ChronoUnit;
|
||||||
|
import java.time.temporal.TemporalAdjusters;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
@@ -47,7 +52,7 @@ import java.util.stream.Collectors;
|
|||||||
*/
|
*/
|
||||||
@Slf4j
|
@Slf4j
|
||||||
@Service
|
@Service
|
||||||
public class MkBirthdayGiftServiceImpl extends ServiceImpl<MkBirthdayGiftMapper, MkBirthdayGift> implements MkBirthdayGiftService{
|
public class MkBirthdayGiftServiceImpl extends ServiceImpl<MkBirthdayGiftMapper, MkBirthdayGift> implements MkBirthdayGiftService {
|
||||||
@Resource
|
@Resource
|
||||||
private MkBirthdayGiftRecordService birthdayGiftRecordService;
|
private MkBirthdayGiftRecordService birthdayGiftRecordService;
|
||||||
@Resource
|
@Resource
|
||||||
@@ -65,6 +70,7 @@ public class MkBirthdayGiftServiceImpl extends ServiceImpl<MkBirthdayGiftMapper,
|
|||||||
|
|
||||||
@DubboReference
|
@DubboReference
|
||||||
private ShopUserService shopUserService;
|
private ShopUserService shopUserService;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public MkBirthdayGiftVO detail(Long shopId) {
|
public MkBirthdayGiftVO detail(Long shopId) {
|
||||||
MkBirthdayGift gift = getOne(new QueryWrapper().eq(MkBirthdayGift::getMainShopId, shopId));
|
MkBirthdayGift gift = getOne(new QueryWrapper().eq(MkBirthdayGift::getMainShopId, shopId));
|
||||||
@@ -115,7 +121,7 @@ public class MkBirthdayGiftServiceImpl extends ServiceImpl<MkBirthdayGiftMapper,
|
|||||||
birthdayGiftRecordCouponService.list(new QueryWrapper().eq(MkBirthdayGiftRecordCoupon::getRecordId, item.getId())).forEach(info -> {
|
birthdayGiftRecordCouponService.list(new QueryWrapper().eq(MkBirthdayGiftRecordCoupon::getRecordId, item.getId())).forEach(info -> {
|
||||||
if ("give".equals(info.getType())) {
|
if ("give".equals(info.getType())) {
|
||||||
item.getCouponList().add(info);
|
item.getCouponList().add(info);
|
||||||
}else {
|
} else {
|
||||||
item.getUsedCouponList().add(info);
|
item.getUsedCouponList().add(info);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@@ -161,7 +167,7 @@ public class MkBirthdayGiftServiceImpl extends ServiceImpl<MkBirthdayGiftMapper,
|
|||||||
if (config.getDeliverTime() != 1) {
|
if (config.getDeliverTime() != 1) {
|
||||||
current = current.plusDays(config.getDeliverTime());
|
current = current.plusDays(config.getDeliverTime());
|
||||||
}
|
}
|
||||||
}else {
|
} else {
|
||||||
DateTime now = DateUtil.date();
|
DateTime now = DateUtil.date();
|
||||||
// 获取当月第一天
|
// 获取当月第一天
|
||||||
current = DateUtil.beginOfMonth(now).toLocalDateTime().toLocalDate();
|
current = DateUtil.beginOfMonth(now).toLocalDateTime().toLocalDate();
|
||||||
@@ -232,40 +238,84 @@ public class MkBirthdayGiftServiceImpl extends ServiceImpl<MkBirthdayGiftMapper,
|
|||||||
if (birthdayGift == null) {
|
if (birthdayGift == null) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
ShopUser shopUser = shopUserService.getOne(new QueryWrapper().eq(ShopUser::getUserId, userId).eq(ShopUser::getMainShopId, shopId));
|
ShopUser shopUser = shopUserService.getOne(new QueryWrapper()
|
||||||
|
.eq(ShopUser::getUserId, userId).eq(ShopUser::getMainShopId, shopId).eq(ShopUser::getBirthDayRemind, 0));
|
||||||
|
if (shopUser == null) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
if (StrUtil.isBlank(birthdayGift.getConfigList())) {
|
if (StrUtil.isBlank(birthdayGift.getConfigList())) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
//获取当天日期
|
||||||
LocalDate current = DateUtil.date().toLocalDateTime().toLocalDate();
|
LocalDate current = DateUtil.date().toLocalDateTime().toLocalDate();
|
||||||
|
// 解析用户生日(仅取月日)
|
||||||
|
LocalDate userBirthday = DateUtil.parseDate(shopUser.getBirthDay()).toLocalDateTime().toLocalDate();
|
||||||
|
// 构造当前年份的生日日期(用于区间判断)
|
||||||
|
LocalDate thisYearBirthday = LocalDate.of(current.getYear(), userBirthday.getMonth(), userBirthday.getDayOfMonth());
|
||||||
for (MkBirthdayGiftConfig config : JSONArray.parseArray(birthdayGift.getConfigList()).toJavaList(MkBirthdayGiftConfig.class)) {
|
for (MkBirthdayGiftConfig config : JSONArray.parseArray(birthdayGift.getConfigList()).toJavaList(MkBirthdayGiftConfig.class)) {
|
||||||
if ("day".equals(config.getDeliverDate())) {
|
if ("day".equals(config.getDeliverDate())) {
|
||||||
if (config.getDeliverTime() != 1) {
|
// 获取偏移天数,默认为0(偏移天数应为非负数,代表未来的天数)
|
||||||
current = current.plusDays(config.getDeliverTime());
|
int offsetDays = config.getDeliverTime() != null ? Math.max(config.getDeliverTime(), 0) : 0;
|
||||||
|
// 计算偏移后的结束日期(当前日期 + 偏移天数)
|
||||||
|
LocalDate endDate = current.plusDays(offsetDays);
|
||||||
|
// 开始日期固定为当前日期
|
||||||
|
LocalDate startDate = current;
|
||||||
|
|
||||||
|
if (StrUtil.isNotBlank(shopUser.getBirthDay())) {
|
||||||
|
try {
|
||||||
|
boolean isInRange = false;
|
||||||
|
if ((thisYearBirthday.isEqual(startDate) || thisYearBirthday.isAfter(startDate))
|
||||||
|
&& (thisYearBirthday.isEqual(endDate) || thisYearBirthday.isBefore(endDate))) {
|
||||||
|
isInRange = true;
|
||||||
|
}
|
||||||
|
// 如果生日在范围内,返回优惠券列表
|
||||||
|
if (isInRange) {
|
||||||
|
return buildCouponList(config);
|
||||||
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
log.error("解析用户生日失败", e);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
DateTime now = DateUtil.date();
|
// 解析用户生日
|
||||||
// 获取当月第一天
|
if (StrUtil.isNotBlank(shopUser.getBirthDay())) {
|
||||||
current = DateUtil.beginOfMonth(now).toLocalDateTime().toLocalDate();
|
// 判断当前月份是否等于用户生日月份
|
||||||
}
|
if (current.getMonthValue() == thisYearBirthday.getMonthValue()
|
||||||
|
&& (current.isEqual(thisYearBirthday) || current.isBefore(thisYearBirthday))) {
|
||||||
if (StrUtil.isBlank(shopUser.getBirthDay())) {
|
return buildCouponList(config);
|
||||||
return null;
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (DateUtil.parseDate(shopUser.getBirthDay()).toLocalDateTime().toLocalDate().isEqual(current)) {
|
|
||||||
ArrayList<Map<String, Object>> arrayList = new ArrayList<>();
|
|
||||||
config.getCouponInfoList().forEach(item -> {
|
|
||||||
|
|
||||||
ShopCouponDTO shopCoupon = shopCouponService.getCouponById(item.getId());
|
|
||||||
arrayList.add(Map.of(
|
|
||||||
"num", item.getNum(),
|
|
||||||
"couponInfo", shopCoupon
|
|
||||||
));
|
|
||||||
});
|
|
||||||
return arrayList;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private ArrayList<Map<String, Object>> buildCouponList(MkBirthdayGiftConfig config) {
|
||||||
|
ArrayList<Map<String, Object>> resultList = new ArrayList<>();
|
||||||
|
if (config.getCouponInfoList() != null) {
|
||||||
|
config.getCouponInfoList().forEach(item -> {
|
||||||
|
ShopCouponDTO coupon = shopCouponService.getCouponById(item.getId());
|
||||||
|
LocalDateTime start = LocalDateTime.now().with(LocalTime.MIN);
|
||||||
|
LocalDateTime end = null;
|
||||||
|
if ("fixed".equals(coupon.getValidType())) {
|
||||||
|
//固定时间
|
||||||
|
if (coupon.getDaysToTakeEffect() != null && coupon.getDaysToTakeEffect() > 0) {
|
||||||
|
start = LocalDateTimeUtil.offset(start, coupon.getDaysToTakeEffect(), ChronoUnit.DAYS).with(LocalTime.MIN);
|
||||||
|
}
|
||||||
|
end = LocalDateTimeUtil.offset(start, coupon.getValidDays(), ChronoUnit.DAYS).with(LocalTime.MAX).truncatedTo(ChronoUnit.SECONDS);
|
||||||
|
} else if ("custom".equals(coupon.getValidType())) {
|
||||||
|
//自定义时间
|
||||||
|
start = coupon.getValidStartTime();
|
||||||
|
end = coupon.getValidEndTime();
|
||||||
|
}
|
||||||
|
coupon.setValidStartTime(start);
|
||||||
|
coupon.setValidEndTime(end);
|
||||||
|
resultList.add(Map.of(
|
||||||
|
"num", item.getNum(),
|
||||||
|
"couponInfo", coupon
|
||||||
|
));
|
||||||
|
});
|
||||||
|
}
|
||||||
|
return resultList;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,7 +7,14 @@
|
|||||||
<!-- 关联查询店铺短信余额及店铺信息,支持店铺名称模糊搜索 -->
|
<!-- 关联查询店铺短信余额及店铺信息,支持店铺名称模糊搜索 -->
|
||||||
<select id="selectWithShopInfo" parameterType="java.lang.String" resultType="com.czg.market.vo.SmsShopMoneyVO">
|
<select id="selectWithShopInfo" parameterType="java.lang.String" resultType="com.czg.market.vo.SmsShopMoneyVO">
|
||||||
SELECT
|
SELECT
|
||||||
s.*,
|
t.id as shopId,
|
||||||
|
COALESCE(s.money, 0) as money,
|
||||||
|
COALESCE(s.send_total, 0) as sendTotal,
|
||||||
|
COALESCE(s.amount_total, 0) as amountTotal,
|
||||||
|
COALESCE(s.month_send_total, 0) as monthSendTotal,
|
||||||
|
COALESCE(s.month_amount_total, 0) as monthAmountTotal,
|
||||||
|
s.create_time as createTime,
|
||||||
|
s.update_time as updateTime,
|
||||||
t.logo,
|
t.logo,
|
||||||
t.shop_type AS shopType,
|
t.shop_type AS shopType,
|
||||||
t.profiles,
|
t.profiles,
|
||||||
@@ -17,9 +24,9 @@
|
|||||||
t.shop_name AS shopName
|
t.shop_name AS shopName
|
||||||
FROM
|
FROM
|
||||||
sms_shop_money s
|
sms_shop_money s
|
||||||
LEFT JOIN
|
right JOIN
|
||||||
tb_shop_info t ON s.shop_id = t.id
|
tb_shop_info t ON s.shop_id = t.id
|
||||||
LEFT JOIN
|
LEFT join
|
||||||
tb_shop_info main_shop ON t.main_id = main_shop.id
|
tb_shop_info main_shop ON t.main_id = main_shop.id
|
||||||
<where>
|
<where>
|
||||||
<!-- 店铺名称模糊查询条件 -->
|
<!-- 店铺名称模糊查询条件 -->
|
||||||
@@ -27,5 +34,6 @@
|
|||||||
AND t.shop_name LIKE CONCAT('%', #{name}, '%')
|
AND t.shop_name LIKE CONCAT('%', #{name}, '%')
|
||||||
</if>
|
</if>
|
||||||
</where>
|
</where>
|
||||||
|
order by shopId asc
|
||||||
</select>
|
</select>
|
||||||
</mapper>
|
</mapper>
|
||||||
|
|||||||
Reference in New Issue
Block a user