|
|
package com.yoho.activity.service.impl;
|
|
|
|
|
|
import java.util.ArrayList;
|
|
|
import java.util.List;
|
|
|
import java.util.Map;
|
|
|
import java.util.*;
|
|
|
|
|
|
import javax.annotation.Resource;
|
|
|
|
|
|
import com.yoho.activity.common.bo.DrawPrizeBo;
|
|
|
import com.yoho.activity.common.redis.CacheKeyEnum;
|
|
|
import com.yoho.activity.common.redis.RedisValueCache;
|
|
|
import org.apache.commons.collections.CollectionUtils;
|
...
|
...
|
@@ -14,7 +13,6 @@ import org.slf4j.LoggerFactory; |
|
|
import org.springframework.beans.BeanUtils;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.beans.factory.annotation.Value;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
import com.yoho.activity.common.utils.DateUtils;
|
|
|
import com.yoho.activity.service.IUserdayDrawPrizeService;
|
...
|
...
|
@@ -28,7 +26,6 @@ import com.yoho.userday.dal.model.UserdayPrizeLog; |
|
|
/**
|
|
|
* 会员日,中奖记录
|
|
|
*/
|
|
|
@Service
|
|
|
public class UserdayPrizeLogServiceImpl implements IUserdayPrizeLogService {
|
|
|
|
|
|
private static final Logger log = LoggerFactory.getLogger(UserdayPrizeLogServiceImpl.class);
|
...
|
...
|
@@ -43,6 +40,8 @@ public class UserdayPrizeLogServiceImpl implements IUserdayPrizeLogService { |
|
|
@Value("${userday.open.day}")
|
|
|
String userdayOpenDay;
|
|
|
|
|
|
private Map<Integer,String> errMsg;
|
|
|
|
|
|
@Override
|
|
|
public UserdayPrizeLog queryPrizeLogForLeaveWords(int uid) throws Exception {
|
|
|
log.info("enter queryPrizeLogForLeaveWords. param uid={}", uid);
|
...
|
...
|
@@ -52,18 +51,18 @@ public class UserdayPrizeLogServiceImpl implements IUserdayPrizeLogService { |
|
|
throw new ServiceException(401, "参数不合法");
|
|
|
}
|
|
|
|
|
|
return userdayPrizeLogDAO.selectByUidForLeaveWords(uid);
|
|
|
return userdayPrizeLogDAO.selectByUidForLeaveWords(uid,getTodyTime());
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
public int addPrizeLog(int uid, int prize_type) throws Exception {
|
|
|
log.info("enter addPrizeLog. param uid={}, prize_type={}", uid, prize_type);
|
|
|
public int addPrizeLog(int uid, int draw_type) throws Exception {
|
|
|
log.info("enter addPrizeLog. param uid={}, prize_type={}", uid, draw_type);
|
|
|
|
|
|
// (1)校验uid, prize_type
|
|
|
if (1 > uid || 1 > prize_type) {
|
|
|
if (1 > uid || 1 > draw_type) {
|
|
|
throw new ServiceException(401, "参数不合法");
|
|
|
}
|
|
|
IUserdayDrawPrizeService userdayDrawPrizeService = userdayDrawPrizeServiceMap.get(prize_type);
|
|
|
IUserdayDrawPrizeService userdayDrawPrizeService = userdayDrawPrizeServiceMap.get(draw_type);
|
|
|
if (null == userdayDrawPrizeService) {
|
|
|
throw new ServiceException(401, "参数不合法");
|
|
|
}
|
...
|
...
|
@@ -74,22 +73,23 @@ public class UserdayPrizeLogServiceImpl implements IUserdayPrizeLogService { |
|
|
throw new ServiceException(403, "非会员日,不允许抽奖");
|
|
|
}
|
|
|
|
|
|
// (3)是否参加过疯狂大转盘
|
|
|
if (2 == prize_type) {
|
|
|
List<UserdayPrizeLog> userdayPrizeLogList = userdayPrizeLogDAO.selectByUidAndPrizeType(uid, prize_type);
|
|
|
// (3)是否参加过疯狂大转盘 或 3学生专享优惠抽奖
|
|
|
if (2 == draw_type || 3 == draw_type) {
|
|
|
List<UserdayPrizeLog> userdayPrizeLogList = userdayPrizeLogDAO.selectByUidAndPrizeType(uid, draw_type,getTodyTime());
|
|
|
if (null != userdayPrizeLogList && 0 < userdayPrizeLogList.size()) {
|
|
|
throw new ServiceException(406, "您今天已经参加过疯狂大转盘");
|
|
|
throw new ServiceException(406, errMsg.get(draw_type));
|
|
|
}
|
|
|
}
|
|
|
|
|
|
// (4)获取奖品值
|
|
|
int prize_value = userdayDrawPrizeService.drawPrize(uid);
|
|
|
// (4)获取奖品返回对象
|
|
|
DrawPrizeBo drawPrize = userdayDrawPrizeService.drawPrize(uid);
|
|
|
|
|
|
// (5)保存抽奖日志
|
|
|
UserdayPrizeLog userdayPrizeLog = new UserdayPrizeLog(uid, prize_type, prize_value, DateUtil.currentTimeSeconds());
|
|
|
UserdayPrizeLog userdayPrizeLog = new UserdayPrizeLog(uid, draw_type,drawPrize.getPrizeType(),
|
|
|
drawPrize.getPrizeValue(),getTodyTime(), DateUtil.currentTimeSeconds());
|
|
|
userdayPrizeLogDAO.insertLog(userdayPrizeLog);
|
|
|
|
|
|
return prize_value;
|
|
|
return drawPrize.getDrawResult();
|
|
|
}
|
|
|
|
|
|
@Override
|
...
|
...
|
@@ -106,7 +106,7 @@ public class UserdayPrizeLogServiceImpl implements IUserdayPrizeLogService { |
|
|
}
|
|
|
|
|
|
// (2)查询当天中奖日志
|
|
|
List<UserdayPrizeLog> userdayPrizeLogList = userdayPrizeLogDAO.selectByUidAndPrizeType(uid, prize_type);
|
|
|
List<UserdayPrizeLog> userdayPrizeLogList = userdayPrizeLogDAO.selectByUidAndPrizeType(uid, prize_type,getTodyTime());
|
|
|
|
|
|
// (3)返回
|
|
|
return userdayDrawPrizeService.existsPrizeLog(userdayPrizeLogList);
|
...
|
...
|
@@ -122,7 +122,7 @@ public class UserdayPrizeLogServiceImpl implements IUserdayPrizeLogService { |
|
|
}
|
|
|
|
|
|
// (2)查询当天中奖日志
|
|
|
List<UserdayPrizeLog> userdayPrizeLogList = userdayPrizeLogDAO.selectByUidAndPrizeType(uid, prize_type);
|
|
|
List<UserdayPrizeLog> userdayPrizeLogList = userdayPrizeLogDAO.selectByUidAndPrizeType(uid, prize_type,getTodyTime());
|
|
|
if (CollectionUtils.isEmpty(userdayPrizeLogList)) {
|
|
|
return null;
|
|
|
}
|
...
|
...
|
@@ -140,11 +140,24 @@ public class UserdayPrizeLogServiceImpl implements IUserdayPrizeLogService { |
|
|
}
|
|
|
|
|
|
@Override
|
|
|
public int queryPrizeLogNum(int prize_type) {
|
|
|
log.info("enter queryPrizeLogNum. param prize_type={}", prize_type);
|
|
|
int realNum = userdayPrizeLogDAO.selectNumByPrizeType(prize_type);
|
|
|
public int queryPrizeLogNum(int draw_type) {
|
|
|
log.info("enter queryPrizeLogNum. param draw_type={}", draw_type);
|
|
|
int realNum = userdayPrizeLogDAO.selectNumByPrizeType(draw_type);
|
|
|
Integer virtualNum = redisValueCache.get(CacheKeyEnum.USERDAY_DRAWPRIZENUM, "", Integer.class);
|
|
|
return realNum + (null == virtualNum ? 0 : virtualNum);
|
|
|
}
|
|
|
|
|
|
public void setErrMsg(Map<Integer, String> errMsg) {
|
|
|
this.errMsg = errMsg;
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 获取当天时间
|
|
|
* @return
|
|
|
*/
|
|
|
private int getTodyTime(){
|
|
|
long current=System.currentTimeMillis();//当前时间毫秒数
|
|
|
long zero = current / (1000 * 3600 * 24) * (1000 * 3600 * 24) - TimeZone.getDefault().getRawOffset();
|
|
|
return (int) (zero/1000);
|
|
|
}
|
|
|
} |
...
|
...
|
|