//累計登陸天數 @RequestMapping(value = "/loginDays",method = {RequestMethod.POST, RequestMethod.GET}) @ApiOperation(value = "登陸記錄接口",notes = "登陸記錄接口") @ResponseBody public Object loginDays(@ApiParam(value="user_id")String user_id) throws Exception{ Users users = usersService.getUsers(user_id); if(users!=null) { Sign sign = signService.getSignByUserId(user_id); // 計算登陸時間 int lianxucishu=sign.getLianxuNumber(); int day = lianxucishu % 7 ; if(day==0) { day=7; } int [] arr = new int[day]; for(int i= 0;i time = new ArrayList(); List newtimes = new ArrayList(); int number = sign.getLianxuNumber()%7; // 連續登陸的次數 if(number==0) { number=7; } Date oldtime = sign.getSign_time(); // 上次登陸的時間 Date newtime = new Date(); SimpleDateFormat formatter = new SimpleDateFormat ("MM.dd"); Date oldtimes = sign.getSign_time(); time.add(oldtime); // 將最後一次的登陸時間放入集合 for(int i=0;i map=new HashMap(); map.put("linaxuNumber", arr); map.put("dateTime", newtimes); return Msg.OK(map); } return Msg.OK(); }app
@RequestMapping(value = "/sign",method = {RequestMethod.POST, RequestMethod.GET})
@ApiOperation(value = "登陸簽到",notes = "登陸簽到")
@ResponseBody
public Object sign(@ApiParam(value="user_id")String user_id) throws Exception{
Users users = usersService.getUsers(user_id);
if(users!=null){ // 有這個用戶
Sign sign = signService.getSignByUserId(users.getId());
if(sign == null){ // 還歷來沒有登陸
Sign s = new Sign(users.getId());
s.setLianxuNumber(1);//用戶第一次登錄,將連續登錄次數設置爲1
signService.insertSign(s);
int integral = users.getIntegral();//獲得用戶現有的U幣
users.setIntegral(integral+s.getLianxuNumber()); // 第一次登錄加1U幣
usersService.updateUsers(users);
Users_jifen_history users_jifen_history = new Users_jifen_history(users.getId(),(double)integral,(double)(integral+s.getLianxuNumber()),(double)s.getLianxuNumber(),"每日登陸");
users_jifen_history.setIs_jifen_state("1");
users_jifen_history.setIs_success("1");
users_jifen_historyService.insertUsers_jifen_history(users_jifen_history);
return Msg.OK(users);
}
boolean checkSign = DateUtil.checkSignTime(sign.getSign_time()); // 爲false時當天登陸完畢 true時當天尚未登陸
if(checkSign){ // 當天尚未登陸
Date oldtime = sign.getSign_time(); // 上次登陸的時間
Date newtime = new Date(); // 當前的時間
int day1=daysBetween(oldtime, newtime);
if(day1 == 1){ // 爲連續的一次登陸
if(sign.getLianxuNumber()<10) {
int num = sign.getLianxuNumber() + 1;
sign.setLianxuNumber(num);
sign.setSign_time(new Date());
signService.updateSign(sign);
int old_jifen = users.getIntegral();
users.setIntegral(old_jifen + num);
usersService.updateUsers(users);
Users_jifen_history users_jifen_history = new Users_jifen_history(users.getId(),(double)old_jifen,(double)users.getIntegral(),(double)num ,"連續登陸"+num+"次");
users_jifen_history.setIs_jifen_state("1");
users_jifen_history.setIs_success("1");
users_jifen_historyService.insertUsers_jifen_history(users_jifen_history);
return Msg.OK(sign.getLianxuNumber());
}else if(sign.getLianxuNumber()>=10) {
int num=sign.getLianxuNumber()+1;
sign.setLianxuNumber(num);
sign.setSign_time(new Date());
signService.updateSign(sign);
int old_jifen=users.getIntegral();
users.setIntegral(old_jifen+10);
usersService.updateUsers(users);
Users_jifen_history users_jifen_history = new Users_jifen_history(users.getId(),(double)old_jifen,(double)users.getIntegral(),(double)10 ,"連續登陸"+num+"次");
users_jifen_history.setIs_jifen_state("1");
users_jifen_history.setIs_success("1");
users_jifen_historyService.insertUsers_jifen_history(users_jifen_history);
return Msg.OK(10);
}
}else{
int old_jifen = users.getIntegral();
users.setIntegral(old_jifen + 1);
usersService.updateUsers(users);
Users_jifen_history users_jifen_history = new Users_jifen_history(users.getId(),(double)old_jifen,(double)users.getIntegral(),(double)1 ,"每日登錄");
users_jifen_history.setIs_jifen_state("1");
users_jifen_history.setIs_success("1");
users_jifen_historyService.insertUsers_jifen_history(users_jifen_history);
sign.setLianxuNumber(1);
sign.setSign_time(new Date());
signService.updateSign(sign);
return Msg.OK(1);
}
}
}
return Msg.ERROR(Code.Sign_Error);
}orm