@RequestMapping(value = { "/auto" }, method = { RequestMethod.POST })
@ResponseBody
public Response signup(@RequestBody SignupRequest signupReq,
HttpServletRequest request, HttpServletResponse response,
HttpSession session) {
Setting setting = SettingUtils.get();
String mobile = signupReq.getMobile();
String checkcode = signupReq.getCheckcode();
String storeCode = this.codeMap.get("smscode-" + mobile);
if (!StringUtils.equals(checkcode, storeCode)) {
return new Response(new Status(2, "对不起,您输入的验证码不正确!"));
}
String name = signupReq.getUsername();
List<Member> members = this.memberService.findListByMobile(mobile);
if(members.size() > 0){
return new Response(new Status(2, "对不起,电话号码已经被注册!"));
}else{
//存入xx_member表
Member newMember = new Member();
String password = RandomStringUtils.randomNumeric(6);
newMember.setRegisterStatus(registerStatusType.registerPass);
newMember.setName(name);
newMember.setUsername("pkb" + mobile);
newMember.setPassword(DigestUtils.md5Hex(password));
newMember.setMobile(mobile);
newMember.setPoint(setting.getRegisterPoint());
newMember.setAmount(new BigDecimal(0));
newMember.setBalance(new BigDecimal(0));
// 注册后默认是启用状态
newMember.setIsLocked(Boolean.valueOf(false));
newMember.setIsEnabled(Boolean.valueOf(true));
newMember.setLoginFailureCount(Integer.valueOf(0));
newMember.setLockedDate(null);
newMember.setRegisterIp(request.getRemoteAddr());
newMember.setLoginIp(request.getRemoteAddr());
newMember.setLoginDate(new Date());
newMember.setSafeKey(null);
newMember.setMemberRank(this.memberRankService.findDefault());
newMember.setGender(Member.Gender.male);
newMember.setRecommendServiceNumber(0L);
newMember.setFavoriteProducts(null);
newMember.setEmail(" ");
newMember.setSalesAmount(new BigDecimal(0));
//绑定老的经纪人
Member member = this.memberService.find(Long.valueOf(signupReq.getMemberId()));
// Member member = this.memberService.getCurrent(signupReq.getMemberId());
Member memberParent = null;
if(!"".equals(member) && member != null){
memberParent = member.getMemberParent();//null
newMember.setBrand(member.getBrand());
}
newMember.setMemberParent(member);//member表中存入独立经纪人
this.memberService.save(newMember);
//存入xx_recommend表
//把邀请注册的经纪人存入Recommend表,并把独立经纪人存入Recommend表
Recommend recommend = new Recommend();
if(memberParent != null){//表示该经纪人是老的独立经纪人
recommend.setName(name);
recommend.setMobile(mobile);
//表示是老经纪人邀请注册是经纪人
recommend.setMember(member);
recommend.setMemberParent(memberParent);
this.recommendService.save(recommend);
}
// 发送注册成功短信和密码到手机
String userinfoMsg = "您的账户{0}已开通,密码{1},app下载点击http://t.cn/R4280TT";
userinfoMsg = StringUtils.replace(userinfoMsg, "{0}", mobile);
userinfoMsg = StringUtils.replace(userinfoMsg, "{1}", password);
smsService.send(mobile, userinfoMsg);
return new Response(Status.OK);
}
}
private Map<String, String> codeMap = new HashMap<String, String>();
/**
* 获取验证码
*
* @param request
* @return
*/
@RequestMapping(value = { "/checkcode" }, method = { RequestMethod.POST })
@ResponseBody
public Response getCheckcode(@RequestBody SignupRequest request) {
String mobile = request.getMobile();
if (StringUtils.isBlank(mobile)) {
return new Response(new Status(3, "请输入手机号码!"));// 手机号为空
}
List<Member> list = this.memberService.findListByMobile(mobile);
// if (list != null && list.size() > 0) {
// return new Response(new Status(2, "您输入的手机号码已注册,请确认!"));// 手机号已注册
// }
if (list != null && list.size() > 0) {
Member newMember = list.get(0);
if (newMember.getRegisterStatus() == null
|| (newMember.getRegisterStatus() != null && newMember
.getRegisterStatus() != registerStatusType.registerNoPass)) {
return new Response(new Status(2, "您输入的手机号码已注册,请确认!"));
}
}
String smscode = RandomStringUtils.randomNumeric(6);
codeMap.put("smscode-" + mobile, smscode);
Tools.mySystemOutPrintln(mobile + ":" + smscode,
WechatCodeController.class);
String msg = SettingUtils.get().getRegisterMsgTpl1();
smsService.send(request.getMobile(),
StringUtils.replace(msg, "{0}", smscode));
return new Response(Status.OK);
}
/**
* 扫描二维码进入注册页面
*/
@RequestMapping(value = { "/auto/{id}" }, method = { org.springframework.web.bind.annotation.RequestMethod.GET })
public String register(@PathVariable Long id, ModelMap model) {
Member member = memberService.find(id);
if (member == null) {
throw new ResourceNotFoundException();
}
Pageable pageable = new Pageable();
// pageable.addFilter("brand", Operator.eq, brand);
// pageable.addFilter("isDelete", Operator.eq, 0);
// List<Gateway> gateways = gatewayService.findList(pageable, "Gateway");
// model.addAttribute("name", brand.getName());
model.addAttribute("id", id);
// model.addAttribute("gateways", gateways);
Setting setting = SettingUtils.get();
model.addAttribute("qrcode", setting.getSiteUrl()
-
"/upload/wechatCode/auto/" + member.getId() + ".png");
return "/shop/wechatCode/auto";
}@RequestMapping(value = { "/autoGateway/{id}" }, method = { org.springframework.web.bind.annotation.RequestMethod.GET })
public String registerGateway(@PathVariable Long id, ModelMap model) {
Gateway gateway = gatewayService.find(id);
if (gateway == null) {
throw new ResourceNotFoundException();
}
model.addAttribute("name", gateway.getBrand().getName());
model.addAttribute("gatewayName", gateway.getName());
model.addAttribute("id", gateway.getBrand().getId());
model.addAttribute("gatewayId", gateway.getId());
Setting setting = SettingUtils.get();
model.addAttribute("qrcode", setting.getSiteUrl() - "/upload/wechatCode/autoGateway/" + gateway.getId() + ".png");
return "/shop/wechatCode/auto";
}
共同学习,写下你的评论
评论加载中...
作者其他优质文章