用java语言设计app签到功能

源码下载:https://download.csdn.net/download/haibo8023/12780219
1.首先设计二张表,第一张表sign_calc记录用户连续签到次数,字段id,user_id,continue_days,第二张表sign_detail签到详情表id,user_id,sign_date。
2.app端用户点击签到接口controller如下:

/***
     * app签到接口
     * @author xuhaibo
     * @param accid
     * @return
     */
    @ResponseBody
    @RequestMapping(value = "/doSign")
    public JSONObject doSign(Integer accid) {
        JSONObject result = new JSONObject();
        Map<String, Object> data = new HashMap<>();
        if (!CinemaConstants.ACCID_MAP.contains(accid)) {
            Integer previousId = CinemaConstants.ACCID_MAP.put(accid, accid);
            if (previousId == null) {
                try {
                    /****
                     * 查询用户今日的签到
                     */
                    SignDetail signToday = signService.todayDetail(accid);//
                    System.out.println(signToday);
                    if (signToday == null) {//今天未签到 1:查询本月昨日签到情况
                        SignDetail signDetail_yesterday = signService.yesterdayDetail(accid);
                        SignCalc signCalcGet = signService.getSignCalc(accid);
                        if (signDetail_yesterday == null) {
                            SignDetail signDetail = new SignDetail();
                            signDetail.setUser_id(accid);
                            signDetail.setSign_date(new Date());
                            signService.addSignDetail(signDetail);
                            if (signCalcGet == null) {
                                SignCalc signCalc = new SignCalc();
                                signCalc.setUser_id(accid);
                                signCalc.setContinue_days(1);
                                signService.addSignCalc(signCalc);
                            } else {
                                SignCalc signCalc = new SignCalc();
                                signCalc.setUser_id(accid);
                                signCalc.setContinue_days(1);
                                signService.updateSignCalc(signCalc);
                            }
                            Integral integral = new Integral();
                            integral.setSourceId(0);
                            integral.setUserId(accid);
                            integral.setScore(CinemaConstants.INTEGRAL_TYPE_SIGN_SCORES);
                            integral.setCreateTime(new Date());
                            integral.setNote(CinemaConstants.INTEGRAL_TYPE_SIGN_DESCRIBE);
                            integral.setSourceType(CinemaConstants.INTEGRAL_TYPE_SIGN);
                            integralService.add(integral);
                            accountService.addIntegralByUserId(accid, CinemaConstants.INTEGRAL_TYPE_SIGN_SCORES);
                            result.put(Constants.RESULT_CODE, "00");
                            data.put("data", "签到成功");
                        } else {//昨日已签到
                            SignDetail signDetail = new SignDetail();
                            SignCalc signCalc = new SignCalc();
                            signDetail.setUser_id(accid);
                            signDetail.setSign_date(new Date());
                            signService.addSignDetail(signDetail);
                            signCalc.setUser_id(accid);
                            signCalc.setContinue_days(signCalcGet.getContinue_days() + 1);
                            signService.updateSignCalc(signCalc);
                            Integral integral = new Integral();
                            integral.setUserId(accid);
                            integral.setSourceId(0);
                            integral.setScore(CinemaConstants.INTEGRAL_TYPE_SIGN_SCORES);
                            integral.setNote(CinemaConstants.INTEGRAL_TYPE_SIGN_DESCRIBE);
                            integral.setCreateTime(new Date());
                            integral.setSourceType(CinemaConstants.INTEGRAL_TYPE_SIGN);
                            integralService.add(integral);
                            accountService.addIntegralByUserId(accid, CinemaConstants.INTEGRAL_TYPE_SIGN_SCORES);
                            result.put(Constants.RESULT_CODE, "00");
                            data.put("data", "签到成功");
                        }
                    } else {//当日已签到
                        result.put(Constants.RESULT_CODE, "-1");
                        data.put("data", "当日已签到");
                    }
                    result.put("data", data);
                } catch (Exception e) {
                    e.printStackTrace();
                    result.put(Constants.RESULT_CODE, "-1");
                    result.put("data", "服务器错误");
                }
                CinemaConstants.ACCID_MAP.remove(accid);
            } else {
                result.put(Constants.RESULT_CODE, "-1");
                result.put("data", "操作正在进行,请重试");
            }
        } else {
            result.put(Constants.RESULT_CODE, "-1");
            result.put("data", "操作正在进行,请重试");
        }
        return result;
    }

领取连续签到奖励接口:

/***
     * 领取连续签到奖励接口(7天,15天,30天)
     * @param accid
     * @param signType
     * @return
     */
    @ResponseBody
    @RequestMapping(value = "/getSignGift")
    public JSONObject getSeven(Integer accid, Integer signType) {
        Calendar a = Calendar.getInstance();
        a.set(Calendar.DATE, 1);//把日期设置为当月第一天
        a.roll(Calendar.DATE, -1);//日期回滚一天,也就是最后一天
        int maxDate = a.get(Calendar.DATE);
        System.out.print(maxDate);
        JSONObject result = new JSONObject();
        Map<String, Object> data = new HashMap<>();
        if (!CinemaConstants.ACCID_MAP.contains(accid)) {
            Integer previousId = CinemaConstants.ACCID_MAP.put(accid, accid);
            if (previousId == null) {
                try {
                    SignCalc signCalc = signService.getSignCalc(accid);
                    int signServen = integralService.signQuery(accid, CinemaConstants.INTEGRAL_TYPE_SIGN_7);
                    int signFifteen = integralService.signQuery(accid,  CinemaConstants.INTEGRAL_TYPE_SIGN_15);
                    int signThirty = integralService.signQuery(accid, CinemaConstants.INTEGRAL_TYPE_SIGN_30);
                    if (signServen==0&&signType == 7 && signCalc.getContinue_days() >= 7) {
                        Integral integral = new Integral();
                        integral.setUserId(accid);
                        integral.setNote(CinemaConstants.INTEGRAL_TYPE_SIGN_7_DESCRIBE);
                        integral.setScore(CinemaConstants.INTEGRAL_TYPE_SIGN_7_SCORES);
                        integral.setCreateTime(new Date());
                        integral.setSourceType(CinemaConstants.INTEGRAL_TYPE_SIGN_7);
                        integralService.add(integral);
                        accountService.addIntegralByUserId(accid, CinemaConstants.INTEGRAL_TYPE_SIGN_7_SCORES);
                        result.put(Constants.RESULT_CODE, "00");
                        data.put("data", "领取成功");
                    } //
                    else if (signFifteen==0&&signType == 15 && signCalc.getContinue_days() >= 15) {
                        Integral integral = new Integral();
                        integral.setUserId(accid);
                        integral.setNote(CinemaConstants.INTEGRAL_TYPE_SIGN_15_DESCRIBE);
                        integral.setScore(CinemaConstants.INTEGRAL_TYPE_SIGN_15_SCORES);
                        integral.setCreateTime(new Date());
                        integral.setSourceType(CinemaConstants.INTEGRAL_TYPE_SIGN_15);
                        integralService.add(integral);
                        accountService.addIntegralByUserId(accid, CinemaConstants.INTEGRAL_TYPE_SIGN_15_SCORES);
                        result.put(Constants.RESULT_CODE, "00");
                        data.put("data", "领取成功");
                    } else if (signThirty==0&&signType == 30 && signCalc.getContinue_days() >= maxDate) {
                        Integral integral = new Integral();
                        integral.setUserId(accid);
                        integral.setNote(CinemaConstants.INTEGRAL_TYPE_SIGN_30_DESCRIBE);
                        integral.setScore(CinemaConstants.INTEGRAL_TYPE_SIGN_30_SCORES);
                        integral.setCreateTime(new Date());
                        integral.setSourceType(CinemaConstants.INTEGRAL_TYPE_SIGN_30);
                        integralService.add(integral);
                        accountService.addIntegralByUserId(accid, CinemaConstants.INTEGRAL_TYPE_SIGN_30_SCORES);
                        result.put(Constants.RESULT_CODE, "00");
                        data.put("data", "领取成功");
                    } else {
                        result.put(Constants.RESULT_CODE, "-1");
                        data.put("msg", "已领取或未到标");
                    }
                    result.put("data", data);
                } catch (Exception e) {
                    e.printStackTrace();
                    result.put(Constants.RESULT_CODE, "-1");
                    result.put("data", "服务器错误");
                }
                CinemaConstants.ACCID_MAP.remove(accid);
            } else {
                result.put(Constants.RESULT_CODE, "-1");
                result.put("data", "操作正在进行,请重试");
            }
        } else {
            result.put(Constants.RESULT_CODE, "-1");
            result.put("data", "操作正在进行,请重试");
        }
        return result;
    }

签到页面的接口:

/***
     * 签到页面app端接口
     * @param accid
     * @return
     */
    @RequestMapping(value = "/signGift")
    @ResponseBody
    public Map<String, Object> signGift(Integer accid) {
        HashMap result = new HashMap();
        JSONObject data = new JSONObject();
        String signDetail = "";
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
        try {
            Account account = accountService.getAccount(accid);
            SignCalc signCalc = signService.getSignCalc(accid);
            List<Map<String, String>> list = signService.getDetailById(accid);
            System.out.println(list);
            String countDate = signService.countDate(accid);
            if (account == null) {
                result.put(Constants.RESULT_CODE, "-1");
                result.put("data", "没数据");
            } else {
                String[] strings = account.getAvatar().split(".png");
                data.put("nick_name", account.getNick_name());//昵称
                data.put("avatar", strings[0]);
                data.put("integral", account.getIntegral());//总积分
                data.put("count_date", countDate);//累计签到天数
                if (list.size() > 0) {
                    for (Map<String, String> map : list) {
                        for (Map.Entry<String, String> entry : map.entrySet()) {
                            String value = sdf.format(entry.getValue());
                            signDetail += value + ",";
                        }
                    }
                }
                int j = signDetail.lastIndexOf(",");
                signDetail = signDetail.substring(0, j);
                data.put("sign_date", signDetail);//签到明细
            }
            data.put("sign_today", true);
            int signServen = integralService.signQuery(accid,  CinemaConstants.INTEGRAL_TYPE_SIGN_7);
            if (signCalc.getContinue_days() < 7) {
                data.put("sign_seven", "0");//未达标
            } else if (signServen>0) {
                data.put("sign_seven", "2");//已领取
            } else {
                data.put("sign_seven", "1");//未领取
            }
            int signFifteen = integralService.signQuery(accid, CinemaConstants.INTEGRAL_TYPE_SIGN_15);
            if (signCalc.getContinue_days() < 15) {
                data.put("sign_fifteen", "0");//未达标
            } else if (signFifteen > 0) {
                data.put("sign_fifteen", "2");//已领取
            } else {
                data.put("sign_fifteen", "1");//未领取
            }
            int signThirty = integralService.signQuery(accid, CinemaConstants.INTEGRAL_TYPE_SIGN_30);
            if (signCalc.getContinue_days() < 30 ) {
                data.put("sign_thirty", "0");//未达标
            } else if (signThirty>0) {
                data.put("sign_thirty", "2");//已领取
            } else {
                data.put("sign_thirty", "1");//未领取
            }
            result.put(Constants.RESULT_CODE, "00");
            result.put("data", data);
        } catch (Exception e) {
            e.printStackTrace();
            result.put(Constants.RESULT_CODE, "-1");
            result.put("data", "数据获取异常");
        }
        return result;
    }

效果如下:
签到效果展示

评论 26
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

haibo8023

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值