|
@@ -0,0 +1,148 @@
|
|
|
+package com.iamberry.wechat.handles.thanksgiving;
|
|
|
+
|
|
|
+import com.iamberry.wechat.core.entity.ResultMsg;
|
|
|
+import com.iamberry.wechat.core.entity.WechatUtils;
|
|
|
+import com.iamberry.wechat.core.entity.member.Member;
|
|
|
+import com.iamberry.wechat.core.entity.thanksgiving.ThanksGiving;
|
|
|
+import com.iamberry.wechat.face.member.MemberService;
|
|
|
+import com.iamberry.wechat.face.order.CodeService;
|
|
|
+import com.iamberry.wechat.face.thanksgiving.ThanksGivingService;
|
|
|
+import com.iamberry.wechat.service.ImberryConfig;
|
|
|
+import com.iamberry.wechat.tools.NameUtils;
|
|
|
+import com.iamberry.wechat.tools.payUtil.RandomUtil;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.stereotype.Controller;
|
|
|
+import org.springframework.web.bind.annotation.RequestMapping;
|
|
|
+import org.springframework.web.bind.annotation.ResponseBody;
|
|
|
+
|
|
|
+import javax.servlet.http.HttpServletRequest;
|
|
|
+import javax.servlet.http.HttpSession;
|
|
|
+import java.text.MessageFormat;
|
|
|
+import java.util.Calendar;
|
|
|
+import java.util.Date;
|
|
|
+import java.util.List;
|
|
|
+
|
|
|
+/**
|
|
|
+ * 感恩活动
|
|
|
+ */
|
|
|
+@Controller
|
|
|
+@RequestMapping("/wechat/tanksgiv")
|
|
|
+public class ThanksGivingHandler {
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private CodeService codeService;
|
|
|
+ @Autowired
|
|
|
+ private ThanksGivingService thanksGivingService;
|
|
|
+ @Autowired
|
|
|
+ private MemberService memberService;
|
|
|
+
|
|
|
+
|
|
|
+ private final static String SEND_VERIFICATION_PHONE ="";
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 发送验证码
|
|
|
+ * 2016年4月21日
|
|
|
+ * @author 穆再兴
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ @ResponseBody
|
|
|
+ @RequestMapping("/send_veri")
|
|
|
+ public ResultMsg sendPhone(HttpServletRequest request,String phone){
|
|
|
+ ResultMsg rm = new ResultMsg();
|
|
|
+ Member member = WechatUtils.getUserBySession(request);
|
|
|
+
|
|
|
+ if(phone.length() != 11){
|
|
|
+ rm.setMessage(ResultMsg.ERROR);
|
|
|
+ rm.setMessage("电话号码错误!");
|
|
|
+ return rm;
|
|
|
+ }
|
|
|
+//
|
|
|
+ member = memberService.getMemberByUserOpenId(member.getUserOpenid());
|
|
|
+// if(member.get){
|
|
|
+//
|
|
|
+// }
|
|
|
+
|
|
|
+ ThanksGiving thanksGiving = new ThanksGiving();
|
|
|
+ thanksGiving.setThanksGivingPhone(phone);
|
|
|
+ List<ThanksGiving> thanksGivingList = thanksGivingService.getThanksGivingList(thanksGiving);
|
|
|
+ if(thanksGivingList == null || thanksGivingList.size() < 1){
|
|
|
+ return new ResultMsg(false, ResultMsg.ERROR, "改电话号码不能领取!",null);
|
|
|
+ }
|
|
|
+
|
|
|
+ //获取验证码
|
|
|
+ String num = RandomUtil.getRandom();
|
|
|
+ //使用request对象的getSession()获取session,如果session不存在则创建一个
|
|
|
+ HttpSession session = request.getSession();
|
|
|
+ String text = MessageFormat.format(SEND_VERIFICATION_PHONE, num);
|
|
|
+ String result = codeService.sendOtherCMS(phone, text);
|
|
|
+
|
|
|
+ //将数据存储到session中
|
|
|
+ session.setAttribute("verification_code",num );
|
|
|
+ session.setAttribute("verification_tel",phone );
|
|
|
+ session.setAttribute("verification_date",new Date());
|
|
|
+
|
|
|
+ rm.setMessage(ResultMsg.SUCCESS);
|
|
|
+ rm.setStatus(true);
|
|
|
+ return rm;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 领取优惠券
|
|
|
+ * 2016年4月21日
|
|
|
+ * @author 穆再兴
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ @ResponseBody
|
|
|
+ @RequestMapping("/receive_coupon")
|
|
|
+ public ResultMsg receiveCoupon(HttpServletRequest request,String phone,String code){
|
|
|
+ ResultMsg rm = new ResultMsg();
|
|
|
+ Member member = WechatUtils.getUserBySession(request);
|
|
|
+
|
|
|
+ if(phone.length() != 11){
|
|
|
+ rm.setMessage(ResultMsg.ERROR);
|
|
|
+ rm.setMessage("电话号码错误!");
|
|
|
+ return rm;
|
|
|
+ }
|
|
|
+
|
|
|
+ //判断验证码
|
|
|
+ //使用request对象的getSession()获取session,如果session不存在则创建一个
|
|
|
+ HttpSession session = request.getSession();
|
|
|
+ String verificationTel = (String) session.getAttribute("verification_tel");
|
|
|
+ String verificationCode = (String) session.getAttribute("verification_code");
|
|
|
+ Date verificationDate = (Date) session.getAttribute("verification_date");
|
|
|
+ if(code == null || "".equals(code)){
|
|
|
+ return new ResultMsg(false, ResultMsg.ERROR, "验证码为空!",null);
|
|
|
+ }
|
|
|
+ Calendar nowTime = Calendar.getInstance();
|
|
|
+ nowTime.setTime(verificationDate);
|
|
|
+ nowTime.add(Calendar.MINUTE, 5);
|
|
|
+ Date verData = nowTime.getTime();
|
|
|
+ if(!verificationCode.equals(code)){
|
|
|
+ return new ResultMsg(false, ResultMsg.ERROR, "验证码不正确,请重新输入!",null);
|
|
|
+ }
|
|
|
+ if((verData.getTime() < System.currentTimeMillis())){
|
|
|
+ return new ResultMsg(false, ResultMsg.ERROR, "验证码已失效,请重新获取!",null);
|
|
|
+ }
|
|
|
+
|
|
|
+ ThanksGiving thanksGiving = new ThanksGiving();
|
|
|
+ thanksGiving.setThanksGivingPhone(phone);
|
|
|
+ List<ThanksGiving> thanksGivingList = thanksGivingService.getThanksGivingList(thanksGiving);
|
|
|
+ if(thanksGivingList == null || thanksGivingList.size() < 1){
|
|
|
+ return new ResultMsg(false, ResultMsg.ERROR, "该电话号码不能领取!",null);
|
|
|
+ }
|
|
|
+
|
|
|
+ ThanksGiving tg = new ThanksGiving();
|
|
|
+ tg.setThanksGivingPhone(phone);
|
|
|
+ tg.setThanksGivingId(thanksGivingList.get(0).getThanksGivingId());
|
|
|
+ tg.setThanksGivingOpenId(member.getUserOpenid());
|
|
|
+
|
|
|
+ Integer flag = thanksGivingService.update(tg);
|
|
|
+ if(flag < 1){
|
|
|
+ return new ResultMsg(false, ResultMsg.ERROR, "领取失败,请重新领取!",null);
|
|
|
+ }
|
|
|
+ rm.setMessage(ResultMsg.SUCCESS);
|
|
|
+ rm.setStatus(true);
|
|
|
+ return rm;
|
|
|
+ }
|
|
|
+
|
|
|
+}
|