|
|
|
@@ -2,25 +2,36 @@ package com.iformall.service.impl; |
|
|
|
|
|
|
|
import com.github.pagehelper.PageHelper; |
|
|
|
import com.github.pagehelper.PageInfo; |
|
|
|
import com.iformall.common.ErrorCode; |
|
|
|
import com.iformall.common.IdWorker; |
|
|
|
import com.iformall.domain.po.PushLimit; |
|
|
|
import com.iformall.domain.po.WxCUser; |
|
|
|
import com.iformall.domain.po.WxCoupon; |
|
|
|
import com.iformall.exception.MallinkException; |
|
|
|
import com.iformall.mapper.PushLimitMapper; |
|
|
|
import com.iformall.mapper.WxCouponActionLogMapper; |
|
|
|
import com.iformall.service.PushLimitService; |
|
|
|
import com.iformall.utils.DateUtils; |
|
|
|
import org.slf4j.Logger; |
|
|
|
import org.slf4j.LoggerFactory; |
|
|
|
import org.springframework.beans.factory.annotation.Autowired; |
|
|
|
import org.springframework.stereotype.Service; |
|
|
|
|
|
|
|
import java.util.Date; |
|
|
|
import java.util.HashMap; |
|
|
|
import java.util.List; |
|
|
|
import java.util.Map; |
|
|
|
|
|
|
|
@Service |
|
|
|
public class PushLimitServiceImpl implements PushLimitService { |
|
|
|
private final Logger logger = LoggerFactory.getLogger(this.getClass()); |
|
|
|
|
|
|
|
@Autowired |
|
|
|
|
|
|
|
@Autowired |
|
|
|
PushLimitMapper pushLimitMapper; |
|
|
|
|
|
|
|
@Autowired |
|
|
|
WxCouponActionLogMapper wxCouponActionLogMapper; |
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
public PageInfo<PushLimit> listAsPage(PushLimit record, Integer pageIndex, Integer pageSize) { |
|
|
|
@@ -65,4 +76,46 @@ public class PushLimitServiceImpl implements PushLimitService { |
|
|
|
public void deleteById(Long id) { |
|
|
|
pushLimitMapper.deleteByPrimaryKey(id); |
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|
public boolean checkMsg(String tenantId, String phone) { |
|
|
|
Date curDate = new Date(); |
|
|
|
// 1. get tenant limit |
|
|
|
PushLimit pushLimit = getPushLimit(tenantId); |
|
|
|
// 2. check time |
|
|
|
boolean isInDate = DateUtils.isInDate(curDate, pushLimit.getTimeStart(), pushLimit.getTimeEnd()); |
|
|
|
if (!isInDate) { |
|
|
|
throw new MallinkException(ErrorCode.COUPON_SEND_NOT_INRANG); |
|
|
|
} |
|
|
|
// TODO 3. check phone had up to limit |
|
|
|
return true; |
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|
public boolean checkCoupon(WxCUser user, WxCoupon coupon) { |
|
|
|
Date curDate = new Date(); |
|
|
|
// 1. get tenant limit |
|
|
|
PushLimit pushLimit = getPushLimit(user.getTenantId()); |
|
|
|
// 2. check time 是否在给定的时间段内 |
|
|
|
boolean isInDate = DateUtils.isInDate(curDate, pushLimit.getTimeStart(), pushLimit.getTimeEnd()); |
|
|
|
if (!isInDate) { |
|
|
|
throw new MallinkException(ErrorCode.COUPON_SEND_NOT_INRANG); |
|
|
|
} |
|
|
|
// 3. check 每人每天多少张券 |
|
|
|
Map params = new HashMap<String, Object>(); |
|
|
|
params.put("tenantId", user.getTenantId()); |
|
|
|
params.put("c_user_id", user.getId()); |
|
|
|
int countForUser = wxCouponActionLogMapper.getCountByUser(params); |
|
|
|
if (countForUser >= pushLimit.getCouponAmount()) { |
|
|
|
throw new MallinkException(ErrorCode.COUPON_SEND_UP_TO_COUPONLIMIT); |
|
|
|
} |
|
|
|
// 4. check 每人多少天内不会重复收到一张券 |
|
|
|
params.put("dayNum", pushLimit.getCouponDay()); |
|
|
|
int countForUserCoupon = wxCouponActionLogMapper.getCountByUserAndCoupon(params); |
|
|
|
if (countForUserCoupon >= pushLimit.getCouponDay()) { |
|
|
|
throw new MallinkException(ErrorCode.COUPON_SEND_UP_TO_COUPONLIMIT); |
|
|
|
} |
|
|
|
|
|
|
|
return true; |
|
|
|
} |
|
|
|
} |