欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

APP轉(zhuǎn)盤抽獎(jiǎng)Java服務(wù)端接口詳解

 更新時(shí)間:2019年01月22日 09:34:49   作者:若冇記憶  
這篇文章主要為大家詳細(xì)介紹了APP轉(zhuǎn)盤抽獎(jiǎng)Java服務(wù)端接口,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下

應(yīng)公司需求開(kāi)發(fā)一個(gè)微信公眾號(hào)中抽獎(jiǎng)活動(dòng)

功能:獎(jiǎng)品及中獎(jiǎng)概率可在后臺(tái)配置,滾動(dòng)刷新中獎(jiǎng)名單,控制用戶每日抽獎(jiǎng)次數(shù)等。

規(guī)則:在活動(dòng)期間,每日可抽獎(jiǎng)一次,中獎(jiǎng)后填寫個(gè)人信息以便獎(jiǎng)品的配送。

1.獲取抽獎(jiǎng)頁(yè)面數(shù)據(jù)

/**
 * 獲取抽獎(jiǎng)頁(yè)面數(shù)據(jù)
 * @param request
 * @param response
 * @return
 * @throws ServletException
 * @throws IOException
 */
@RequestMapping(value="/queryLotteryActivity")
@ResponseBody
public AppIntReturn queryLotteryActivity(HttpServletRequest request, HttpServletResponse response)
 throws ServletException, IOException {
 AppIntReturn res = new AppIntReturn();
 
 // 用戶同意授權(quán)后,能獲取到code
 String code = request.getParameter("code");
 
 // 用戶同意授權(quán)
 if (!"authdeny".equals(code)) {
 // 獲取網(wǎng)頁(yè)授權(quán)access_token
 WeixinOauth2Token weixinOauth2Token = CommonUtil
 .getOauth2AccessToken(ConfigUtil.APPID, ConfigUtil.APP_SECRECT, code);
 // 用戶標(biāo)識(shí)
 String openId = weixinOauth2Token.getOpenId();
 
 if(!StringUtil.isEmpty(openId)){
 
 // 查詢用戶信息
 List<CxhWechatMember> memberList = appLotteryService.getMemberList(openId);
 // 操作次數(shù)
 int operNum = 1; // 可寫成后臺(tái)可配置的
 if(memberList != null && memberList.size() > 0){
 operNum = operNum - memberList.size();
 /*// 獲取用戶信息
 String accessToken = CommonUtil.getAccessToken(ConfigUtil.APPID, ConfigUtil.APP_SECRECT).getToken();
 cxhWechatMember = CommonUtil.getWeChatMemberInfo(accessToken, openId);
 // 保存用戶信息
 appLotteryService.saveMemberInfo(cxhWechatMember);*/
 }
 
 if (null == request.getParameter("activityId") || "".equals(request.getParameter("activityId"))){
 res.setResult("-2");
 res.setMsg("參數(shù)錯(cuò)誤");
 return res;
 }
 // 查詢活動(dòng)信息
 CxhVoteActivity cxhVoteActivity = appLotteryService.getActivityInfo(request.getParameter("activityId"));
 if (null == cxhVoteActivity){
 res.setResult("-3");
 res.setMsg("暫無(wú)該類活動(dòng)");
 return res;
 }
 CxhVoteAward cxhVoteAward = new CxhVoteAward();
 cxhVoteAward.setCxhVoteActivity(cxhVoteActivity);
 // 查詢獎(jiǎng)品列表
 List<CxhVoteAward> awardList = appLotteryService.findAwardList(cxhVoteAward);
 
 // 返回Map
 Map<String, Object> rtnMap = new HashMap<String, Object>();
 rtnMap.put("activity", cxhVoteActivity);
 rtnMap.put("awardList", awardList);
 rtnMap.put("operNum", operNum);
 rtnMap.put("openId", openId);
 
 res.setResult("0");
 res.setMsg("請(qǐng)求成功");
 res.setData(rtnMap);
 }else{
 res.setResult("-1");
 res.setMsg("授權(quán)失敗");
 }
 
 }else{
 res.setResult("-1");
 res.setMsg("授權(quán)失敗");
 }
 return res;
}

2.中獎(jiǎng)名單接口

/**
 * 中獎(jiǎng)名單接口
 * @author lee
 * @return
 */
@ResponseBody
@RequestMapping(value = "/winningMemberList")
public Object queryWinningMemberList(HttpServletRequest request, HttpServletResponse response) {
 AppListReturn appResult = new AppListReturn();
 try {
 CxhWechatMember cxhWechatMember = new CxhWechatMember();
 cxhWechatMember.setIswinning("1"); // 中獎(jiǎng)
 // 查詢中獎(jiǎng)用戶名單(分頁(yè))
 Page<CxhWechatMember> pageList = appLotteryService.findPage(new Page<CxhWechatMember>(request, response), cxhWechatMember);
 appResult.setData(pageList.getList());
 appResult.setPageNumber(pageList.getPageNo());
 appResult.setPageSize(pageList.getPageSize());
 appResult.setTotal((int) pageList.getCount());
 appResult.setTotalPages(pageList.getTotalPage());
 appResult.setResult(0);
 appResult.setMsg("成功");
 } catch (Exception e) {
 appResult.setResult(-9);
 appResult.setMsg("系統(tǒng)異常");
 logger.info(e.toString(), e);
 }
 return appResult;
}

3.抽獎(jiǎng)接口

/**
 * 抽獎(jiǎng)接口
 * @author lee
 * @return
 */
@ResponseBody
@RequestMapping(value = "/doLottery")
public Object doLottery(HttpServletRequest request, HttpServletResponse response) {
 AppListReturn appResult = new AppListReturn();
 // 返回Map
 Map<String, Object> rtnMap = new HashMap<String, Object>();
 String activityId = request.getParameter("activityId");
 String openId = request.getParameter("openId");
 try {
 
 if (null == activityId || "".equals(activityId) || null == openId || "".equals(openId)){
 appResult.setResult(-2);
 appResult.setMsg("參數(shù)錯(cuò)誤");
 return appResult;
 }
 // 查詢活動(dòng)信息
 CxhVoteActivity cxhVoteActivity = appLotteryService.getActivityInfo(request.getParameter("activityId"));
 if (null == cxhVoteActivity){
 appResult.setResult(-3);
 appResult.setMsg("暫無(wú)該類活動(dòng)");
 return appResult;
 }
 CxhVoteAward cxhVoteAward = new CxhVoteAward();
 cxhVoteAward.setCxhVoteActivity(cxhVoteActivity);
 // 查詢獎(jiǎng)品列表
 List<CxhVoteAward> awardList = appLotteryService.findAwardList(cxhVoteAward);
 
 Random rd = new Random();
 double dd = rd.nextDouble();
 double before = 0;
 double end = 0;
 cxhVoteAward.setLevel("5"); // 5-未中獎(jiǎng)
 
 // 計(jì)算中獎(jiǎng)概率
 for (int i = 0; i < awardList.size(); i++) {
 if(i > 0){
 before += awardList.get(i-1).getRate().doubleValue();
 }
 end += awardList.get(i).getRate().doubleValue();
 if(dd >= before && dd < end){
 if(awardList.get(i).getLeftnum() > 0){
  // 中獎(jiǎng)獎(jiǎng)品
  cxhVoteAward = awardList.get(i);
  // 修改獎(jiǎng)品剩余數(shù)量
  cxhVoteAward.setLeftnum(cxhVoteAward.getLeftnum() - 1);
  appLotteryService.updateAwardNumber(cxhVoteAward);
 }
 break;
 }
 }
 
 // 新增用戶操作記錄
 String accessToken = CommonUtil.getAccessToken(ConfigUtil.APPID, ConfigUtil.APP_SECRECT).getToken();
 CxhWechatMember cxhWechatMember = CommonUtil.getWeChatMemberInfo(accessToken, openId);
 cxhWechatMember.setId(IdGen.uuid());
 cxhWechatMember.setJoindate(new Date());
 cxhWechatMember.setDelFlag("0");
 // 保存用戶信息
 appLotteryService.saveMemberInfo(cxhWechatMember);
 
 rtnMap.put("awardLevel", cxhVoteAward.getLevel());
 rtnMap.put("awardId", cxhVoteAward.getId());
 appResult.setData(rtnMap);
 appResult.setResult(0);
 appResult.setMsg("成功");
 } catch (Exception e) {
 appResult.setResult(-9);
 appResult.setMsg("系統(tǒng)異常");
 logger.info(e.toString(), e);
 }
 return appResult;
}

4.保存中獎(jiǎng)用戶信息的接口

/**
 * 保存中獎(jiǎng)用戶信息的接口
 * @author lee
 * @return
 */
@ResponseBody
@RequestMapping(value = "/saveMemberInfo")
public Object saveMemberInfo(HttpServletRequest request, HttpServletResponse response) {
 AppListReturn appResult = new AppListReturn();
 try {
 
 // 用戶同意授權(quán)后,能獲取到code
 String openId = request.getParameter("openId");
 String username = request.getParameter("username");
 String phone = request.getParameter("phone");
 String address = request.getParameter("address");
 String awardLevel = request.getParameter("awardLevel");
 String awardId = request.getParameter("awardId");
 
 if (null == username || "".equals(username)
 || null == phone || "".equals(phone)
 || null == address || "".equals(address)
 || null == openId || "".equals(openId)
 || null == awardLevel || "".equals(awardLevel)
 || null == awardId || "".equals(awardId)){
 appResult.setResult(-2);
 appResult.setMsg("參數(shù)錯(cuò)誤");
 return appResult;
 }
 
 // 查詢用戶信息
 List<CxhWechatMember> memberList = appLotteryService.getMemberList(openId);
 CxhWechatMember cxhWechatMember = memberList.get(0);
 cxhWechatMember.setUsername(username);
 cxhWechatMember.setPhone(phone);
 cxhWechatMember.setAddress(address);
 cxhWechatMember.setIswinning(awardLevel == "5" ? "0" : "1");
 cxhWechatMember.setAwardid(awardId);
 appLotteryService.update(cxhWechatMember);
 
 appResult.setResult(0);
 appResult.setMsg("成功");
 
 } catch (Exception e) {
 appResult.setResult(-9);
 appResult.setMsg("系統(tǒng)異常");
 logger.info(e.toString(), e);
 }
 return appResult;
}

以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。

相關(guān)文章

最新評(píng)論