parent
ba78b3368f
commit
a86a2fbdac
|
|
@ -57,6 +57,10 @@ public class ShopUser implements Serializable {
|
|||
* 会员生日
|
||||
*/
|
||||
private String birthDay;
|
||||
/**
|
||||
* 会员生日提醒
|
||||
*/
|
||||
private String birthDayRemind;
|
||||
|
||||
/**
|
||||
* 0-女 1男
|
||||
|
|
|
|||
|
|
@ -1,10 +1,6 @@
|
|||
package com.czg.market.entity;
|
||||
|
||||
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 lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
|
|
@ -13,7 +9,6 @@ import lombok.NoArgsConstructor;
|
|||
|
||||
import java.io.Serial;
|
||||
import java.io.Serializable;
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
|
|
@ -37,9 +32,13 @@ public class MkBirthdayGiftConfig implements Serializable {
|
|||
private String userType;
|
||||
|
||||
/**
|
||||
* 是否开启
|
||||
* 提前天数 负数
|
||||
*/
|
||||
private Integer deliverTime;
|
||||
/**
|
||||
* day 天数偏移
|
||||
* month 月份偏移
|
||||
*/
|
||||
private String deliverDate;
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -3,6 +3,7 @@ package com.czg.service.market.service.impl;
|
|||
import cn.hutool.core.bean.BeanUtil;
|
||||
import cn.hutool.core.date.DateTime;
|
||||
import cn.hutool.core.date.DateUtil;
|
||||
import cn.hutool.core.date.LocalDateTimeUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import com.alibaba.fastjson2.JSONArray;
|
||||
import com.alibaba.fastjson2.JSONObject;
|
||||
|
|
@ -35,7 +36,11 @@ import org.springframework.stereotype.Service;
|
|||
|
||||
import java.time.LocalDate;
|
||||
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.List;
|
||||
import java.util.Map;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
|
|
@ -47,7 +52,7 @@ import java.util.stream.Collectors;
|
|||
*/
|
||||
@Slf4j
|
||||
@Service
|
||||
public class MkBirthdayGiftServiceImpl extends ServiceImpl<MkBirthdayGiftMapper, MkBirthdayGift> implements MkBirthdayGiftService{
|
||||
public class MkBirthdayGiftServiceImpl extends ServiceImpl<MkBirthdayGiftMapper, MkBirthdayGift> implements MkBirthdayGiftService {
|
||||
@Resource
|
||||
private MkBirthdayGiftRecordService birthdayGiftRecordService;
|
||||
@Resource
|
||||
|
|
@ -65,6 +70,7 @@ public class MkBirthdayGiftServiceImpl extends ServiceImpl<MkBirthdayGiftMapper,
|
|||
|
||||
@DubboReference
|
||||
private ShopUserService shopUserService;
|
||||
|
||||
@Override
|
||||
public MkBirthdayGiftVO detail(Long 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 -> {
|
||||
if ("give".equals(info.getType())) {
|
||||
item.getCouponList().add(info);
|
||||
}else {
|
||||
} else {
|
||||
item.getUsedCouponList().add(info);
|
||||
}
|
||||
});
|
||||
|
|
@ -161,7 +167,7 @@ public class MkBirthdayGiftServiceImpl extends ServiceImpl<MkBirthdayGiftMapper,
|
|||
if (config.getDeliverTime() != 1) {
|
||||
current = current.plusDays(config.getDeliverTime());
|
||||
}
|
||||
}else {
|
||||
} else {
|
||||
DateTime now = DateUtil.date();
|
||||
// 获取当月第一天
|
||||
current = DateUtil.beginOfMonth(now).toLocalDateTime().toLocalDate();
|
||||
|
|
@ -232,40 +238,84 @@ public class MkBirthdayGiftServiceImpl extends ServiceImpl<MkBirthdayGiftMapper,
|
|||
if (birthdayGift == 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())) {
|
||||
return null;
|
||||
}
|
||||
//获取当天日期
|
||||
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)) {
|
||||
if ("day".equals(config.getDeliverDate())) {
|
||||
if (config.getDeliverTime() != 1) {
|
||||
current = current.plusDays(config.getDeliverTime());
|
||||
// 获取偏移天数,默认为0(偏移天数应为非负数,代表未来的天数)
|
||||
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 {
|
||||
DateTime now = DateUtil.date();
|
||||
// 获取当月第一天
|
||||
current = DateUtil.beginOfMonth(now).toLocalDateTime().toLocalDate();
|
||||
}
|
||||
|
||||
if (StrUtil.isBlank(shopUser.getBirthDay())) {
|
||||
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;
|
||||
// 解析用户生日
|
||||
if (StrUtil.isNotBlank(shopUser.getBirthDay())) {
|
||||
// 判断当前月份是否等于用户生日月份
|
||||
if (current.getMonthValue() == thisYearBirthday.getMonthValue()
|
||||
&& (current.isEqual(thisYearBirthday) || current.isBefore(thisYearBirthday))) {
|
||||
return buildCouponList(config);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
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
|
||||
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.shop_type AS shopType,
|
||||
t.profiles,
|
||||
|
|
@ -17,9 +24,9 @@
|
|||
t.shop_name AS shopName
|
||||
FROM
|
||||
sms_shop_money s
|
||||
LEFT JOIN
|
||||
right JOIN
|
||||
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
|
||||
<where>
|
||||
<!-- 店铺名称模糊查询条件 -->
|
||||
|
|
@ -27,5 +34,6 @@
|
|||
AND t.shop_name LIKE CONCAT('%', #{name}, '%')
|
||||
</if>
|
||||
</where>
|
||||
order by shopId asc
|
||||
</select>
|
||||
</mapper>
|
||||
|
|
|
|||
Loading…
Reference in New Issue