|
|
|
@@ -247,6 +247,9 @@ public class CouponSendSchedule { |
|
|
|
logger.info("生日发券: {} 用户列表为空 wxCUserBasicInfoList = {}, 任务跳过不执行", mall.getName(), wxCUserBasicInfoList); |
|
|
|
return; |
|
|
|
} |
|
|
|
|
|
|
|
int birthdayScale = CreditUtil.getBirthdayScoreScale(mall.getTenantId(), wxScoreRulesService); |
|
|
|
|
|
|
|
//每人可以发送几张生日券 |
|
|
|
// final int sendCount = 1; |
|
|
|
wxCUserBasicInfoList.forEach(cu -> { |
|
|
|
@@ -269,15 +272,10 @@ public class CouponSendSchedule { |
|
|
|
logger.error("生日发券: 解析conditions异常: {}", e.getMessage()); |
|
|
|
} |
|
|
|
if (Objects.isNull(conditions) || Objects.isNull(configJo)) { |
|
|
|
logger.info("生日发券: 会员生日券配置不存在 conditions = {}, 任务跳过不执行", conditions); |
|
|
|
logger.info("生日发券: 会员生日券配置解析异常 conditions = {}, 任务跳过不执行", conditions); |
|
|
|
return; |
|
|
|
} |
|
|
|
|
|
|
|
boolean couponLimit = pushLimitService.checkCoupon(cu.getTenantId(), cu.getId(), cs.getCouponId()); |
|
|
|
if (!couponLimit) { |
|
|
|
logger.info("生日发券: {}", ErrorCode.PUSH_LIMIT_UP_TO_COUPONLIMIT.getMessage()); |
|
|
|
return; |
|
|
|
} |
|
|
|
//默认生日当天发送 |
|
|
|
int beforeDays = 0; |
|
|
|
if (configJo.containsKey(WxCouponSend.KEY_BEFOREDAYS)) { |
|
|
|
@@ -285,25 +283,32 @@ public class CouponSendSchedule { |
|
|
|
} |
|
|
|
//提前n天发送生日券,不满足跳过不执行,没有发送的进行补发 |
|
|
|
int diffBithday = DateUtils.birthdaysBetween(cu.getBirthdate()); |
|
|
|
if (diffBithday < 0 || diffBithday > beforeDays) { |
|
|
|
if (diffBithday < 0 && Math.abs(diffBithday) > beforeDays || diffBithday > beforeDays) { |
|
|
|
logger.info("生日发券: [会员={},生日={}不满足提前{}天发券]", cu.getNickName(), cu.getBirthdate(), beforeDays); |
|
|
|
return; |
|
|
|
} |
|
|
|
|
|
|
|
boolean couponLimit = pushLimitService.checkCoupon(cu.getTenantId(), cu.getId(), cs.getCouponId()); |
|
|
|
if (!couponLimit) { |
|
|
|
logger.info("生日发券: {}", ErrorCode.PUSH_LIMIT_UP_TO_COUPONLIMIT.getMessage()); |
|
|
|
continue; |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
Calendar now = Calendar.getInstance() ; |
|
|
|
now.set(Calendar.HOUR, now.get(Calendar.HOUR) - 2) ; |
|
|
|
Map<String, Object> params = new HashMap<>(); |
|
|
|
params.put("tenantId", cs.getTenantId()); |
|
|
|
params.put("cUserId", cu.getId()); |
|
|
|
params.put("couponId", cs.getCouponId()); |
|
|
|
params.put("couponId", null); |
|
|
|
params.put("startTime", startTime); |
|
|
|
params.put("endTime", endTime); |
|
|
|
params.put("endTime", now.getTime()); |
|
|
|
params.put("channelType", EnumCouponSendSendType.BIRTHDAY.getCode()); |
|
|
|
int count = wxCouponActionLogMapper.getCountByUserAndCouponAndDate(params); |
|
|
|
logger.info("生日发券:已经给[" + cu.getNickName() + |
|
|
|
"]券[" + cs.getTitle() + "] " + |
|
|
|
count + "张"); |
|
|
|
//判断之前是否发送过会员生日券 |
|
|
|
if (count > 0) { |
|
|
|
logger.info("生日发券: 会员{}已经发送过生日券, 本次不再发送", cu.getNickName()); |
|
|
|
continue; |
|
|
|
logger.info("生日发券: 已经给会员{}发送过生日券, 本次不再发送", cu.getNickName()); |
|
|
|
return; |
|
|
|
} |
|
|
|
|
|
|
|
if (cs.getRemainInventory() <= 0) { |
|
|
|
@@ -327,12 +332,6 @@ public class CouponSendSchedule { |
|
|
|
" id-" + cu.getId()); |
|
|
|
} |
|
|
|
if (couponSent) { |
|
|
|
boolean couponLimit = pushLimitService.checkMsg(cu.getTenantId()); |
|
|
|
if (!couponLimit) { |
|
|
|
logger.info("生日发券: {}", ErrorCode.PUSH_LIMIT_NOT_INRANG.getMessage()); |
|
|
|
return; |
|
|
|
} |
|
|
|
sendSMS(cu, mall); |
|
|
|
// 记录积分倍率日期 |
|
|
|
try { |
|
|
|
WxCUserBasicInfo toUpdate = new WxCUserBasicInfo(); |
|
|
|
@@ -342,6 +341,13 @@ public class CouponSendSchedule { |
|
|
|
} catch (Exception e) { |
|
|
|
logger.error("定时发券:记录积分倍率日期失败 {}", e.getMessage()); |
|
|
|
} |
|
|
|
//短信限制 |
|
|
|
boolean couponLimit = pushLimitService.checkMsg(cu.getTenantId()); |
|
|
|
if (couponLimit) { |
|
|
|
sendSMS(cu, mall, birthdayScale); |
|
|
|
} else { |
|
|
|
logger.info("生日发券: {}", ErrorCode.PUSH_LIMIT_NOT_INRANG.getMessage()); |
|
|
|
} |
|
|
|
} |
|
|
|
}); |
|
|
|
}); |
|
|
|
@@ -364,14 +370,13 @@ public class CouponSendSchedule { |
|
|
|
return false; |
|
|
|
} |
|
|
|
|
|
|
|
private void sendSMS(WxCUserBasicInfo cUserBasicInfo, WxMall mall) { |
|
|
|
private void sendSMS(WxCUserBasicInfo cUserBasicInfo, WxMall mall, int birthdayScale) { |
|
|
|
WxMsgRecord wxMsgRecord = new WxMsgRecord(); |
|
|
|
wxMsgRecord.setMsgType(EnumMsgRecordType.SMS.getCode()); |
|
|
|
wxMsgRecord.setReceiver(cUserBasicInfo.getPhone()); |
|
|
|
wxMsgRecord.setTenantId(cUserBasicInfo.getTenantId()); |
|
|
|
Map<String, String> dynamicContentMap = new HashMap<>(); |
|
|
|
|
|
|
|
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)); |
|
|
|
|