//查看今天是否签到
@Override
public ResponseVo checkSignToday(Integer uid) {
try {
SignInfo sign = signInfoMapper.selectToDaySign(uid);
if (sign == null) {
return Result.ok(200, “今天暂无签到记录”, 0);
}
//获得最后一次签到时间(0未签到,1已签到)
Date create_time = sign.getCreateTime();
if (!DateUtil.greaterDate(new Date(), create_time)) {
return Result.ok(200, “今天暂无签到记录”, 0);
}
return Result.ok(200, “今天已签到”, 1);
} catch (Exception e) {
e.printStackTrace();
return Result.fail();
}
}
//查询签到信息
@Override
public ResponseVo signMsg(Integer uid) {
Integer integralCount = userInfoMapper.selectById(uid).getIntegralCount();
//最近七天的签到记录列表
List sign = signInfoMapper.findSign(uid);
//最近七天没有签到记录
if (sign.isEmpty()) {
return Result.ok(integralCount, “暂无签到记录”, 0);
}
//获得最后一次签到的时间和连续签到天数
Integer day = sign.get(0).getContinuityDay();
Date create_time = sign.get(0).getCreateTime();
//判断,如果上次签到时间与今日相差大于一天,则是断签状态
//!DateUtil.greaterDate(new Date(), create_time)
if (DateUtil.dayDiffs(create_time) < 0) {
return Result.ok(integralCount, “断签”, 0);
}
//签满第七天则从第一天从新开始
if (day >= 7) {
if (DateUtil.verificationTime(create_time)) {
return Result.ok(integralCount, “已签满七天”, day);
}
return Result.ok(integralCount, “已签满七天”, 0);
}
//如果未签满七天或者相差时间不大于一天则续签
return Result.ok(integralCount, “第” + day + “天签到”, day);
}
//点击签到
@Override
public ResponseVo sign(Integer uid) {
try {
LocalDateTime dateTime = LocalDateTime.now();
//积分记录表
IntegralRecord record = new IntegralRecord();
record.setCreateTime(dateTime);
record.setUserId(uid);
record.setRuleId(1);
record.setActionType(1);
//第一天至第六天签到每天签到获得10积分,第七天签到获得50积分
//查询用户签到信息
Integer day =0;
List list = signInfoMapper.findSign(uid);
if(list.size()<=0){
day=1;
}
if(list.size()>=1){
if(DateUtil.dayDiffs(list.get(0).getCreateTime()) < 0){
//如果上次签到时间与今日相差大于一天,则是断签状态
day=1;
}else if(list.get(0).getContinuityDay() >= 7){
day=1;
}else{
day=list.get(0).getContinuityDay()+1;
}
}
UserInfo userinfo = new UserInfo();
UserInfo user = userInfoMapper.selectById(uid);
//如果没有签到信息,从第一天开始签到
SignInfo msg = new SignInfo();
msg.setTime(day);
msg.setUid(uid);
if (day >= 7) {
msg.setIntegral(100);
} else {
msg.setIntegral(10);
}
msg.setContinuityDay(day);//连续第一天签到
msg.setCreateTime(new Date());
signInfoMapper.insert(msg);
//添加积分至用户积分获得记录表和总积分表
if (day >= 7) {
record.setIntegralCount(100);
} else {
record.setIntegralCount(10);
}
integralRecordMapper.insert(record);
userinfo.setUserId(uid);
if (day >= 7) {
userinfo.setIntegralCount(user.getIntegralCount() + 100);
} else {
userinfo.setIntegralCount(user.getIntegralCount() + 10);
}
userinfo.setUpdateTime(dateTime);
//更新总积分积分msg.getIntegral()
integralInfoMapper.updateIntegralTotal(userinfo);
JSONObject json = new JSONObject();
json.put(“Integral”, msg.getIntegral());
return Result.ok(200, “签到第” + day + “天”, json);
} catch (Exception e) {
e.printStackTrace();
return Result.fail();
}
}