Просмотр исходного кода

调整会员生日券接口

release_toaliyun_real
Burce 6 лет назад
Родитель
Сommit
ed43b3f78e
3 измененных файлов: 51 добавлений и 69 удалений
  1. +9
    -11
      mallinkAdmin/src/main/java/com/iformall/controller/market/WxCouponSendController.java
  2. +41
    -57
      mallinkSchedule/src/main/java/com/iformall/schedule/CouponSendSchedule.java
  3. +1
    -1
      mallinkService/src/main/java/com/iformall/service/impl/WxOrderServiceImpl.java

+ 9
- 11
mallinkAdmin/src/main/java/com/iformall/controller/market/WxCouponSendController.java Просмотреть файл

@@ -97,19 +97,17 @@ public class WxCouponSendController extends BaseController {
return new ResultData(ErrorCode.SYS_PARAMETER_ERROR);
}

if(!Objects.equals(wxCouponSend.getSendType(),EnumCouponSendSendType.BIRTHDAY.getCode())) {
WxCoupon wxCoupon = wxCouponService.getById(wxCouponSend.getCouponId());
if (!wxCoupon.getStatus().equals(EnumCouponStatus.COUPON_STATUS_THROW_IN.getCode()) ){
return new ResultData(ErrorCode.COUPON_IS_TAKE_OFF);
}

if (!wxCoupon.getSendType().equals(EnumCouponSendType.PASSIVE.getCode())) {
return new ResultData(ErrorCode.COUPON_TYPE_IS_NOT_PASSIVE);
}
wxCouponSend.setTenantId(wxCoupon.getTenantId());
wxCouponSend.setTitle(wxCoupon.getTitle());
WxCoupon wxCoupon = wxCouponService.getById(wxCouponSend.getCouponId());
if (!EnumCouponStatus.COUPON_STATUS_THROW_IN.getCode().equals(wxCoupon.getStatus())) {
return new ResultData(ErrorCode.COUPON_IS_TAKE_OFF);
}

if (!EnumCouponSendType.PASSIVE.getCode().equals(wxCoupon.getSendType())) {
return new ResultData(ErrorCode.COUPON_TYPE_IS_NOT_PASSIVE);
}
wxCouponSend.setTenantId(wxCoupon.getTenantId());
wxCouponSend.setTitle(wxCoupon.getTitle());

wxCouponSend.setCreateDate(new Date());
wxCouponSend.setUpdateDate(new Date());



+ 41
- 57
mallinkSchedule/src/main/java/com/iformall/schedule/CouponSendSchedule.java Просмотреть файл

@@ -241,44 +241,37 @@ public class CouponSendSchedule {
wxCUserBasicInfoDto.setTenantId(mall.getTenantId());
List<WxCUserBasicInfo> wxCUserBasicInfoList = wxCUserBasicInfoMapper.findBirthdayList(wxCUserBasicInfoDto);
if (CollectionUtils.isEmpty(wxCUserBasicInfoList)) {
logger.info("生日发券: {} 用户列表为空 wxCUserBasicInfoList = {}, 任务跳过不执行",mall.getName(),wxCUserBasicInfoList);
logger.info("生日发券: {} 用户列表为空 wxCUserBasicInfoList = {}, 任务跳过不执行", mall.getName(), wxCUserBasicInfoList);
return;
}
//每人可以发送几张生日券
final int sendCount = 1;
// final int sendCount = 1;
wxCUserBasicInfoList.forEach(cu -> {
WxCouponSend wxCouponSend = new WxCouponSend();
wxCouponSend.setTenantId(cu.getTenantId());
wxCouponSend.setSendType(EnumCouponSendSendType.BIRTHDAY.getCode());
wxCouponSend.setStatus(EnumCouponSendStatus.VALID.getCode());
List<WxCouponSendVo> couponSendList = wxCouponSendMapper.findListVo(wxCouponSend);
if(CollectionUtils.isEmpty(couponSendList)) {
if (CollectionUtils.isEmpty(couponSendList)) {
logger.info("生日发券: 会员生日券投放列表为空 couponSendList = {}, 任务跳过不执行", couponSendList);
return;
}

WxCouponSend config = wxCouponSendService.getConfig(EnumCouponSendSendType.BIRTHDAY.getCode(),cu.getTenantId()) ;
if(Objects.isNull(config)||Objects.isNull(config.getConditions())) {
WxCouponSend config = wxCouponSendService.getConfig(EnumCouponSendSendType.BIRTHDAY.getCode(), cu.getTenantId());
if (Objects.isNull(config) || Objects.isNull(config.getConditions())) {
logger.info("生日发券: 会员生日券配置不存在 config = {}, 任务跳过不执行", config);
return;
}
JSONObject configJo = JSONObject.parseObject(config.getConditions()) ;
int beforeDays = configJo.getIntValue(WxCouponSend.KEY_BEFOREDAYS);
int remain = couponSendList.stream().map(cs -> {
int count = cs.getRemainInventory();
logger.info("定时发券:给[" + cu.getNickName() +
"]券[" + cs.getTitle() + "]还剩" +
count + "张");
return count;
}).reduce(Integer::sum).orElse(0);

if (remain < sendCount) {
logger.error("定时发券:库存不足[" + cu.getNickName() + "]应发" + sendCount + "张,总共剩" + remain + "张");
return;
//默认生日当天发送
int beforeDays = 0;
JSONObject configJo = JSONObject.parseObject(config.getConditions());
if (configJo.containsKey(WxCouponSend.KEY_BEFOREDAYS)) {
beforeDays = configJo.getIntValue(WxCouponSend.KEY_BEFOREDAYS);
}

int sentCount = couponSendList.stream().map(cs -> {
Map<String,Object> params = new HashMap<>();
for (WxCouponSendVo cs : couponSendList) {
Map<String, Object> params = new HashMap<>();
params.put("tenantId", cs.getTenantId());
params.put("cUserId", cu.getId());
params.put("couponId", cs.getCouponId());
@@ -289,45 +282,36 @@ public class CouponSendSchedule {
logger.info("生日发券:已经给[" + cu.getNickName() +
"]券[" + cs.getTitle() + "] " +
count + "张");
return count;
}).reduce(Integer::sum).orElse(0);


logger.info("生日发券:给[" + cu.getNickName() +
"]总共已发送券" + sentCount + "张,还需发" + (sendCount - sentCount) + "张");

for (int count = 0; count < sendCount - sentCount; count++) {
boolean sent = false;
for (int couponIndex = 0; couponIndex < couponSendList.size(); couponIndex++) {
WxCouponSendVo cs = couponSendList.get(couponIndex);
//提前n天发送生日券,不满足跳过不执行
if(DateUtils.daysBetween(cu.getBirthdate(), new Date()) == beforeDays) {
continue;
}
if (cs.getRemainInventory() <= 0)
continue;
// 发放免费券
try {
WxCouponOrder couponOrder = wxOrderService.sendFreeCouponToUser(cu.getId(), cs.getCouponId());
sendSMS(cu,mall);
wxCouponActionLogService.addOne(cu.getTenantId(), cs.getCouponId(), couponOrder.getId(), cs.getSendType(), cs.getId());
} catch (Exception e) {
logger.error("定时发券:发券失败 levelId=" + cu.getId() + " couponId=" + cs.getCouponId() + " userId=" + cu.getId() + e.getMessage());
logger.info("定时发券:发券失败 levelId=" + cu.getId() + " couponId=" + cs.getCouponId() + " userId=" + cu.getId() + e.getMessage());
continue;
}

logger.info("定时发券:商场[" + mall.getName() +
"]会员生日[" + cu.getBirthdate().toInstant() +
"]发送券[" + cs.getTitle() +
"]给:" + cu.getNickName() +
" 电话-" + cu.getPhone() +
" id-" + cu.getId());
sent = true;
break;
if (count > 0) {
logger.info("生日发券: 会员{}已经发送过生日券, 本次不再发送", cu.getNickName());
continue;
}
//提前n天发送生日券,不满足跳过不执行
if (DateUtils.daysBetween(cu.getBirthdate(), new Date()) == beforeDays) {
continue;
}
if (!sent)
break;
if (cs.getRemainInventory() <= 0) {
logger.info("生日发券: [title={},id={}]卡券库存不足!", cs.getTitle(), cs.getCouponId());
continue;
}
// 发放免费券
try {
WxCouponOrder couponOrder = wxOrderService.sendFreeCouponToUser(cu.getId(), cs.getCouponId());
sendSMS(cu, mall);
wxCouponActionLogService.addOne(cu.getTenantId(), cs.getCouponId(), couponOrder.getId(), cs.getSendType(), cs.getId());
} catch (Exception e) {
logger.error("定时发券:发券失败 levelId=" + cu.getId() + " couponId=" + cs.getCouponId() + " userId=" + cu.getId() + e.getMessage());
logger.info("定时发券:发券失败 levelId=" + cu.getId() + " couponId=" + cs.getCouponId() + " userId=" + cu.getId() + e.getMessage());
continue;
}

logger.info("定时发券:商场[" + mall.getName() +
"]会员生日[" + cu.getBirthdate().toInstant() +
"]发送券[" + cs.getTitle() +
"]给:" + cu.getNickName() +
" 电话-" + cu.getPhone() +
" id-" + cu.getId());
break;
}
});
});


+ 1
- 1
mallinkService/src/main/java/com/iformall/service/impl/WxOrderServiceImpl.java Просмотреть файл

@@ -340,7 +340,7 @@ public class WxOrderServiceImpl implements WxOrderService {
if (count > 0) {
//解锁
redisLock.unlock(couponIdStr, timeStr);
logger.error("此券购买数量已超限, couponId: " + couponIdStr + ", count: " + count);
logger.error("此券有未支付的订单, couponId: " + couponIdStr + ", count: " + count);
throw new MallinkException(ErrorCode.ORDER_UNPAID);
}
}


Загрузка…
Отмена
Сохранить