| @@ -208,7 +208,7 @@ public class CouponSendSchedule { | |||
| /** | |||
| * 生日券发放 | |||
| */ | |||
| @Scheduled(cron = "0 0 11 * * ?") // 测试每天6点发券 | |||
| @Scheduled(cron = "0 0 15 * * ?") // 测试每天6点发券 | |||
| public void birthdayCouponSendSchedule() { | |||
| logger.info("生日发券: 任务开始"); | |||
| List<WxMall> mallList = wxMallMapper.findList(new WxMall()); | |||
| @@ -274,6 +274,13 @@ public class CouponSendSchedule { | |||
| if (configJo.containsKey(WxCouponSend.KEY_BEFOREDAYS)) { | |||
| beforeDays = configJo.getIntValue(WxCouponSend.KEY_BEFOREDAYS); | |||
| } | |||
| //提前n天发送生日券,不满足跳过不执行,没有发送的进行补发 | |||
| int diffBithday = DateUtils.birthdaysBetween(cu.getBirthdate()); | |||
| if (diffBithday < 0 || diffBithday > beforeDays) { | |||
| logger.info("生日发券: [会员={},生日={}不满足提前{}天发券]", cu.getNickName(), cu.getBirthdate(), beforeDays); | |||
| continue; | |||
| } | |||
| Map<String, Object> params = new HashMap<>(); | |||
| params.put("tenantId", cs.getTenantId()); | |||
| params.put("cUserId", cu.getId()); | |||
| @@ -289,12 +296,7 @@ public class CouponSendSchedule { | |||
| logger.info("生日发券: 会员{}已经发送过生日券, 本次不再发送", cu.getNickName()); | |||
| continue; | |||
| } | |||
| //提前n天发送生日券,不满足跳过不执行,没有发送的进行补发 | |||
| int diffBithday = DateUtils.birthdaysBetween(cu.getBirthdate()); | |||
| if (diffBithday < 0 || diffBithday > beforeDays) { | |||
| logger.info("生日发券: [会员={},生日={}不满足提前{}天发券]", cu.getNickName(), cu.getBirthdate(), beforeDays); | |||
| continue; | |||
| } | |||
| if (cs.getRemainInventory() <= 0) { | |||
| logger.info("生日发券: [title={},id={}]卡券库存不足!", cs.getTitle(), cs.getCouponId()); | |||
| continue; | |||
| @@ -319,8 +321,10 @@ public class CouponSendSchedule { | |||
| sendSMS(cu, mall); | |||
| // 记录积分倍率日期 | |||
| try { | |||
| cu.setScoreDate(cu.getBirthdate()); | |||
| wxCUserBasicInfoMapper.updateByPrimaryKeySelective(cu); | |||
| WxCUserBasicInfo toUpdate = new WxCUserBasicInfo() ; | |||
| toUpdate.setId(cu.getId()); | |||
| toUpdate.setScoreDate(cu.getBirthdate()); | |||
| wxCUserBasicInfoMapper.updateByPrimaryKeySelective(toUpdate); | |||
| } catch (Exception e) { | |||
| logger.error("定时发券:记录积分倍率日期失败 {}", e.getMessage()); | |||
| } | |||
| @@ -353,7 +357,7 @@ public class CouponSendSchedule { | |||
| wxMsgRecord.setTenantId(cUserBasicInfo.getTenantId()); | |||
| Map<String, String> dynamicContentMap = new HashMap<>(); | |||
| int birthdayScale = CreditUtil.getScoreScale(cUserBasicInfo.getTenantId(), wxScoreRulesService); | |||
| int birthdayScale = CreditUtil.getBirthdayScoreScale(cUserBasicInfo.getTenantId(), wxScoreRulesService); | |||
| if (birthdayScale > WxScoreRules.DEFAULT_SCALE) { | |||
| float creditScale = new BigDecimal(birthdayScale).divide(new BigDecimal(WxScoreRules.DEFAULT_SCALE)).floatValue(); | |||
| dynamicContentMap.put("creditScale", String.valueOf(creditScale)); | |||
| @@ -2,6 +2,7 @@ package com.iformall.domain.po; | |||
| import cn.afterturn.easypoi.excel.annotation.Excel; | |||
| import com.alibaba.fastjson.JSONObject; | |||
| import com.fasterxml.jackson.annotation.JsonIgnore; | |||
| import lombok.Data; | |||
| import lombok.EqualsAndHashCode; | |||
| import lombok.ToString; | |||
| @@ -23,7 +24,7 @@ public class WxCUserBasicInfo extends BaseEntity { | |||
| @Id | |||
| protected Long id; | |||
| @Transient | |||
| @JsonIgnore | |||
| protected Date scoreDate; | |||
| @Transient | |||
| @@ -1,14 +1,10 @@ | |||
| package com.iformall.utils; | |||
| import com.iformall.domain.po.*; | |||
| import com.iformall.mapper.WxLevelConfigMapper; | |||
| import com.iformall.service.WxCouponActionLogService; | |||
| import com.iformall.service.WxCouponOrderService; | |||
| import com.iformall.service.WxScoreRulesService; | |||
| import lombok.extern.slf4j.Slf4j; | |||
| import java.math.BigDecimal; | |||
| import java.util.Date; | |||
| import java.util.Objects; | |||
| @Slf4j | |||
| @@ -29,10 +25,10 @@ public class CreditUtil { | |||
| return 0; | |||
| } | |||
| // 获取等级积分倍率:默认为1.0, | |||
| int levelScale = calLevelScale(wxCUser, scaleFromDb); | |||
| int levelScale = getLevelScale(wxCUser, scaleFromDb); | |||
| // 获取生日积分倍率: | |||
| int birthdayScale = calBirthdayScale(wxCUserBasicInfo, wxScoreRulesService); | |||
| int birthdayScale = getBirthdayScale(wxCUserBasicInfo, wxScoreRulesService); | |||
| int creditNew = new BigDecimal(creditOrigin) | |||
| .multiply(new BigDecimal(levelScale)) | |||
| @@ -44,7 +40,13 @@ public class CreditUtil { | |||
| return creditNew; | |||
| } | |||
| public static int calLevelScale(WxCUser wxCUser, Integer scaleFromDb) { | |||
| /** | |||
| * 根据会员信息获取等级积分倍率 | |||
| * @param wxCUser | |||
| * @param scaleFromDb | |||
| * @return | |||
| */ | |||
| private static int getLevelScale(WxCUser wxCUser, Integer scaleFromDb) { | |||
| int levelScale = WxLevelConfig.DEFAULT_SCALE; | |||
| Integer score = wxCUser.getScore(); | |||
| //积分不为空时进行计算 | |||
| @@ -60,18 +62,34 @@ public class CreditUtil { | |||
| return levelScale; | |||
| } | |||
| public static int calBirthdayScale(WxCUserBasicInfo wxCUserBasicInfo, WxScoreRulesService wxScoreRulesService) { | |||
| /** | |||
| * 根据会员信息获取倍率 | |||
| * @param wxCUserBasicInfo | |||
| * @param wxScoreRulesService | |||
| * @return | |||
| */ | |||
| private static int getBirthdayScale(WxCUserBasicInfo wxCUserBasicInfo, WxScoreRulesService wxScoreRulesService) { | |||
| int birthdayScale = WxScoreRules.DEFAULT_SCALE; | |||
| //判断是否生日当天,一年一天有效 | |||
| //发过生日券的用户 | |||
| if (Objects.nonNull(wxCUserBasicInfo.getScoreDate()) && DateUtils.birthdaysBetween(wxCUserBasicInfo.getScoreDate()) == 0) { | |||
| birthdayScale = getScoreScale(wxCUserBasicInfo.getTenantId(), wxScoreRulesService); | |||
| birthdayScale = getBirthdayScoreScale(wxCUserBasicInfo.getTenantId(), wxScoreRulesService); | |||
| //没有发过生日券的用户 | |||
| } else if(Objects.nonNull(wxCUserBasicInfo.getBirthdate()) && DateUtils.birthdaysBetween(wxCUserBasicInfo.getBirthdate()) == 0) { | |||
| birthdayScale = getBirthdayScoreScale(wxCUserBasicInfo.getTenantId(), wxScoreRulesService); | |||
| } else { | |||
| log.info("积分倍率计算:未设置生日或生日条件未匹配={}", wxCUserBasicInfo.getScoreDate()); | |||
| } | |||
| return birthdayScale; | |||
| return birthdayScale ; | |||
| } | |||
| public static int getScoreScale(String tenantId, WxScoreRulesService wxScoreRulesService) { | |||
| /** | |||
| * 获取生日积分倍率 | |||
| * @param tenantId | |||
| * @param wxScoreRulesService | |||
| * @return | |||
| */ | |||
| public static int getBirthdayScoreScale(String tenantId, WxScoreRulesService wxScoreRulesService) { | |||
| int birthdayScale = WxScoreRules.DEFAULT_SCALE; | |||
| WxScoreRules rules = wxScoreRulesService.getCreditRules(tenantId); | |||
| if (Objects.nonNull(rules) && Objects.nonNull(rules.getScale())) { | |||