Authored by bblu

会员日签到增加校验

@@ -2,11 +2,16 @@ package com.yoho.activity.service.impl; @@ -2,11 +2,16 @@ package com.yoho.activity.service.impl;
2 2
3 import com.yoho.activity.common.helper.SendCouponHelper; 3 import com.yoho.activity.common.helper.SendCouponHelper;
4 import com.yoho.activity.service.IUserdaySigninService; 4 import com.yoho.activity.service.IUserdaySigninService;
  5 +import com.yoho.core.common.utils.DateUtil;
  6 +import com.yoho.core.redis.YHValueOperations;
5 import org.slf4j.Logger; 7 import org.slf4j.Logger;
6 import org.slf4j.LoggerFactory; 8 import org.slf4j.LoggerFactory;
7 import org.springframework.beans.factory.annotation.Autowired; 9 import org.springframework.beans.factory.annotation.Autowired;
8 import org.springframework.stereotype.Service; 10 import org.springframework.stereotype.Service;
9 11
  12 +import javax.annotation.Resource;
  13 +import java.util.concurrent.TimeUnit;
  14 +
10 /** 15 /**
11 * 会员日,签到 16 * 会员日,签到
12 */ 17 */
@@ -18,6 +23,9 @@ public class UserdaySigninServiceImpl implements IUserdaySigninService { @@ -18,6 +23,9 @@ public class UserdaySigninServiceImpl implements IUserdaySigninService {
18 @Autowired 23 @Autowired
19 private SendCouponHelper sendCouponHelper; 24 private SendCouponHelper sendCouponHelper;
20 25
  26 + @Resource(name = "yhValueOperations")
  27 + YHValueOperations<String, String> yhValueOperations;
  28 +
21 @Override 29 @Override
22 public void signin(int uid) throws Exception { 30 public void signin(int uid) throws Exception {
23 log.info("enter signin. param uid={}", uid); 31 log.info("enter signin. param uid={}", uid);
@@ -27,7 +35,24 @@ public class UserdaySigninServiceImpl implements IUserdaySigninService { @@ -27,7 +35,24 @@ public class UserdaySigninServiceImpl implements IUserdaySigninService {
27 throw new Exception("参数不合法"); 35 throw new Exception("参数不合法");
28 } 36 }
29 37
30 - // (2)发送有货币,完成签到 38 + // (2)校验当天是否是会员日
  39 + String dateStr = DateUtil.getcurrentDate();
  40 + if (!"28".equals(dateStr.substring(8, 10))) {
  41 + throw new Exception("非会员日,不允许签到");
  42 + }
  43 +
  44 + // (3)校验用户是否已经签到
  45 + String key = "yh:activity:userday:" + uid + "_" + dateStr;
  46 + String s = yhValueOperations.get(key);
  47 + if ("1".equals(s)) {
  48 + throw new Exception("您已签过到");
  49 + }
  50 +
  51 + // (4)发送有货币,完成签到
31 sendCouponHelper.sendYOHOBi(uid, 100, 5); 52 sendCouponHelper.sendYOHOBi(uid, 100, 5);
  53 +
  54 + // (5)redis记录用户签到记录
  55 + yhValueOperations.set(key, "1", 31, TimeUnit.DAYS);
32 } 56 }
  57 +
33 } 58 }