這篇文章主要介紹java怎么實現(xiàn)app簽到功能,文中介紹的非常詳細,具有一定的參考價值,感興趣的小伙伴們一定要看完!
公司主營業(yè)務:成都做網(wǎng)站、成都網(wǎng)站設計、成都外貿(mào)網(wǎng)站建設、移動網(wǎng)站開發(fā)等業(yè)務。幫助企業(yè)客戶真正實現(xiàn)互聯(lián)網(wǎng)宣傳,提高企業(yè)的競爭能力。創(chuàng)新互聯(lián)是一支青春激揚、勤奮敬業(yè)、活力青春激揚、勤奮敬業(yè)、活力澎湃、和諧高效的團隊。公司秉承以“開放、自由、嚴謹、自律”為核心的企業(yè)文化,感謝他們對我們的高要求,感謝他們從不同領域給我們帶來的挑戰(zhàn),讓我們激情的團隊有機會用頭腦與智慧不斷的給客戶帶來驚喜。創(chuàng)新互聯(lián)推出撫順免費做網(wǎng)站回饋大家。
具體內(nèi)容如下
1.首先設計二張表,第一張表sign_calc記錄用戶連續(xù)簽到次數(shù),字段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; }
領取連續(xù)簽到獎勵接口:
/*** * 領取連續(xù)簽到獎勵接口(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", "沒數(shù)據(jù)"); } 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);//累計簽到天數(shù) 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", "數(shù)據(jù)獲取異常"); } return result; }
效果如下:
以上是“java怎么實現(xiàn)app簽到功能”這篇文章的所有內(nèi)容,感謝各位的閱讀!希望分享的內(nèi)容對大家有幫助,更多相關知識,歡迎關注創(chuàng)新互聯(lián)行業(yè)資訊頻道!
當前名稱:java怎么實現(xiàn)app簽到功能
路徑分享:http://muchs.cn/article10/jsopdo.html
成都網(wǎng)站建設公司_創(chuàng)新互聯(lián),為您提供定制開發(fā)、定制網(wǎng)站、靜態(tài)網(wǎng)站、域名注冊、建站公司、動態(tài)網(wǎng)站
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時需注明來源: 創(chuàng)新互聯(lián)