App的登录注册相关接口

我用的是MybatisPuls

package com.zldev.controller.api.seller;
import java.util.Arrays;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;
import java.util.UUID;

import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import com.alibaba.fastjson.JSON;
import com.aliyuncs.exceptions.ClientException;
import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.zldev.entity.RegionEntity;
import com.zldev.entity.SellEntity;
import com.zldev.entity.SmsCodeEntity;
import com.zldev.framework.BusinessRuntimeException;
import com.zldev.framework.Constant;
import com.zldev.framework.common.NoAuthCheck;
import com.zldev.framework.common.PageUtils;
import com.zldev.framework.common.R;
import com.zldev.framework.util.SmsUtils;
import com.zldev.framework.util.SubjectContextHolder;
import com.zldev.framework.util.VerifyCodeUtil;
import com.zldev.framework.validata.Assert;
import com.zldev.framework.wxpay.util.MD5;
import com.zldev.framework.wxpay.util.MD5Util;
import com.zldev.service.RegionService;
import com.zldev.service.SellService;
import com.zldev.service.SmsCodeService;



/**
* 商家表
*
* @author fs
* @email startsuper
* @date 2019-01-18 15:45:24
*/
@RestController
@RequestMapping("/api/seller/sell")
public class SellController
{
@Autowired
private SellService sellService;
@Autowired
private SmsCodeService smsCodeService;
@Autowired
private RegionService regionService;

/**
* 绑定微信并且注册
* @throws ClientException
*/
@RequestMapping("/registerBindWechat")
@NoAuthCheck
@ResponseBody
public R registerBindWechat( String phone,String smsCode,String openId,String imgHead ,String nickName) throws ClientException
{
Assert.isBlank(phone, "手机号码不能为空");
Assert.isBlank(smsCode, "验证码不能为空");
Assert.isBlank(openId, "openId不能为空");
Assert.isNull(smsCodeService.validateSmsCode(smsCode, phone),"验证码不正确或已失效");
SellEntity condition=new SellEntity();
condition.setSPhone(phone);
EntityWrapper<SellEntity> entityWrapper=new EntityWrapper<SellEntity>(condition);
SellEntity reponseData=sellService.selectOne(entityWrapper);
String uuid = UUID.randomUUID().toString().replaceAll("-", "");
if(reponseData==null)
{
condition.setSWxAppid(openId);
entityWrapper=new EntityWrapper<SellEntity>(condition);
reponseData=sellService.selectOne(entityWrapper);
if(reponseData==null) {
String pwd="xndx123";
PageUtils papgeUtil=sellService.queryPage(new HashMap<>());
String cqNumber="1"+ String.format("%06d", papgeUtil!=null?papgeUtil.getTotalCount():1);
reponseData=new SellEntity();
reponseData.setSPhone(phone);
reponseData.setSFlag(Constant.VISIABLE);
reponseData.setSPassword(MD5.MD5Encode(pwd));
reponseData.setToken(uuid);
reponseData.setSWxAppid(openId);
reponseData.setSHead(imgHead);
reponseData.setSNickname(nickName!=null?nickName:"商户"+cqNumber);
sellService.insert(reponseData);
//发送短信
Map<String, String> paramMap=new HashMap<>();
paramMap.put("phone",VerifyCodeUtil.mobileEncrypt(phone));
paramMap.put("password", pwd);
SmsUtils.sendSms(phone, JSON.toJSONString(paramMap),SmsUtils.registerTemplateId);
}else {
return R.error("您的微信已绑定已绑定其他商户账号,不能重复绑定多个商户,如有疑问请联系客服!");
}
}else {
if(StringUtils.isNotBlank(reponseData.getSWxAppid())&&!openId.equals(reponseData.getSWxAppid()))
{
Map<String, Object> resultMap=new HashMap<>();
SmsCodeEntity smsCondition=new SmsCodeEntity();
smsCondition.setSmsPhone(phone);
EntityWrapper<SmsCodeEntity> smsEntityWrapper=new EntityWrapper<SmsCodeEntity>(smsCondition);
SmsCodeEntity smsReponseData=smsCodeService.selectOne(smsEntityWrapper);
String code=VerifyCodeUtil.getPhoneCode();
if(reponseData!=null)
{
smsReponseData.setSmsCode(code);
smsReponseData.setSmsTime(new Date());
smsReponseData.setSmsId(null);
smsReponseData.setSmsFlag(null);
smsCodeService.update(smsReponseData, smsEntityWrapper);
}
resultMap.put("phone", phone);
resultMap.put("smsCode", code);
return R.error("1001","该手机号已绑定过其他微信账号").put("data",resultMap);
}else if(StringUtils.isBlank(reponseData.getSWxAppid())) {
reponseData.setSWxAppid(openId);
reponseData.setSHead(imgHead);
reponseData.setSNickname(nickName!=null?nickName:reponseData.getSNickname());
sellService.update(reponseData, entityWrapper);
}
}
return R.ok();
}

/**
* 绑定微信更换
* @throws ClientException
*/
@RequestMapping("/modiftyBindWechat")
@NoAuthCheck
@ResponseBody
public R modiftyBindWechat(String phone,String smsCode,String openId,String imgHead ,String nickName) throws ClientException
{
Assert.isBlank(phone, "手机号码不能为空");
Assert.isBlank(smsCode, "验证码不能为空");
Assert.isBlank(openId, "openId不能为空");
Assert.isNull(smsCodeService.validateSmsCode(smsCode, phone),"验证码不正确或已失效");
SellEntity condition=new SellEntity();
condition.setSPhone(phone);
EntityWrapper<SellEntity> entityWrapper=new EntityWrapper<SellEntity>(condition);
SellEntity reponseData=sellService.selectOne(entityWrapper);
if(reponseData!=null) {
reponseData.setSWxAppid(openId);
reponseData.setSHead(imgHead);
reponseData.setSNickname(nickName!=null?nickName:reponseData.getSNickname());
sellService.update(reponseData, entityWrapper);
}else {
return R.error("商户账号不存在!");
}
return R.ok();
}

/**
* 注册
*/
@RequestMapping("/register")
@NoAuthCheck
@ResponseBody
public R register( String phone,String smsCode,String passwd)
{
Assert.isBlank(phone, "手机号码不能为空");
Assert.isBlank(smsCode, "验证码不能为空");
Assert.isBlank(passwd, "密码不能为空");
if(!VerifyCodeUtil.isLetterDigit(passwd)) {
throw new BusinessRuntimeException("密码格式不正确,应包含大小写字母及数字且在6-18位");
}
Assert.isNull(smsCodeService.validateSmsCode(smsCode, phone),"验证码不正确或已失效");

SellEntity condition=new SellEntity();
condition.setSPhone(phone);
EntityWrapper<SellEntity> entityWrapper=new EntityWrapper<SellEntity>(condition);
SellEntity reponseData=sellService.selectOne(entityWrapper);
String uuid = UUID.randomUUID().toString().replaceAll("-", "");
Map<String, Object> resMap=new HashMap<>();
if(reponseData==null)
{
PageUtils papgeUtil=sellService.queryPage(new HashMap<>());
String cqNumber="1"+ String.format("%06d", papgeUtil!=null?papgeUtil.getTotalCount():1);
reponseData=new SellEntity();
reponseData.setSPhone(phone);
reponseData.setSFlag(Constant.VISIABLE);
reponseData.setSPassword(MD5.MD5Encode(passwd));
reponseData.setToken(uuid);
reponseData.setSNickname("商户"+cqNumber);
sellService.insert(reponseData);
}else {
return R.error("您的手机号已注册使用,无法重复注册,如有疑问请联系客服!");
}
return R.ok(resMap);
}

/**
*找回密码
*/
@RequestMapping("/findPwd")
@NoAuthCheck
@ResponseBody
public R findPwd( String phone,String smsCode,String passwd)
{
Assert.isBlank(phone, "手机号码不能为空");
Assert.isBlank(smsCode, "验证码不能为空");
Assert.isBlank(passwd, "密码不能为空");
if(!VerifyCodeUtil.isLetterDigit(passwd)) {
throw new BusinessRuntimeException("密码格式不正确,应包含大小写字母及数字且在6-18位");
}
Assert.isNull(smsCodeService.validateSmsCode(smsCode, phone),"验证码不正确或已失效");

SellEntity condition=new SellEntity();
condition.setSPhone(phone);
EntityWrapper<SellEntity> entityWrapper=new EntityWrapper<SellEntity>(condition);
SellEntity reponseData=sellService.selectOne(entityWrapper);
String uuid = UUID.randomUUID().toString().replaceAll("-", "");
Map<String, Object> resMap=new HashMap<>();
if(reponseData!=null)
{
SellEntity changeSell=new SellEntity();
changeSell.setSPassword(MD5.MD5Encode(passwd));
//changeSell.setToken(" ");
sellService.update(changeSell, entityWrapper);
}else {
return R.error("您的手机号未注册使用,无法找回密码!");
}
return R.ok(resMap);
}

/**
*修改手机号
*/
@RequestMapping("/modifyPhone")
@ResponseBody
public R modifyPhone( String phone,String smsCode)
{
Assert.isBlank(phone, "手机号码不能为空");
Assert.isBlank(smsCode, "验证码不能为空");
Assert.isNull(smsCodeService.validateSmsCode(smsCode, phone),"验证码不正确或已失效");
if(phone.equals(SubjectContextHolder.getSubject().getPhone())) {
throw new BusinessRuntimeException("新手机号和当前使用手机号相同,不能修改");
}
SellEntity condition=new SellEntity();
condition.setSPhone(phone);
EntityWrapper<SellEntity> entityWrapper=new EntityWrapper<SellEntity>(condition);
SellEntity reponseData=sellService.selectOne(entityWrapper);
if(reponseData==null) {
condition=new SellEntity();
condition.setToken(SubjectContextHolder.getSubject().getToken());
entityWrapper=new EntityWrapper<SellEntity>(condition);
reponseData=sellService.selectOne(entityWrapper);
if(reponseData!=null)
{
SellEntity changeSell=new SellEntity();
changeSell.setSPhone(phone);
sellService.update(changeSell, entityWrapper);
}
}else {
return R.error("该手机号已被注册使用,不能修改!");
}
return R.ok();
}


/**
*查询电话号码是否注册
*/
@RequestMapping("/queryPhone")
@NoAuthCheck
@ResponseBody
public R queryPhone( String phone)
{
Assert.isBlank(phone, "手机号码不能为空");
SellEntity condition=new SellEntity();
condition.setSPhone(phone);
EntityWrapper<SellEntity> entityWrapper=new EntityWrapper<SellEntity>(condition);
SellEntity reponseData=sellService.selectOne(entityWrapper);
Map<String, Object> resMap=new HashMap<>();
if(reponseData!=null)
{
resMap.put("state", "1");
}else {
resMap.put("state", "0");
}
return R.ok(resMap);
}

/**
*登录
*/
@RequestMapping("/login")
@NoAuthCheck
@ResponseBody
public R login( String phone,String passwd)
{
Assert.isBlank(phone, "手机号码不能为空");
Assert.isBlank(passwd, "密码不能为空");
SellEntity condition=new SellEntity();
condition.setSPhone(phone);
EntityWrapper<SellEntity> entityWrapper=new EntityWrapper<SellEntity>(condition);
SellEntity reponseData=sellService.selectOne(entityWrapper);
Map<String, Object> resMap=new HashMap<>();
if(reponseData!=null)
{
if(!reponseData.getSForbidden().equals(Constant.HIDE)) {

String myPwd=MD5.MD5Encode(passwd);
if(myPwd.equals(reponseData.getSPassword())) {
String uuid = UUID.randomUUID().toString().replaceAll("-", "");
SellEntity changeSell=new SellEntity();
changeSell.setToken(uuid);
sellService.update(changeSell, entityWrapper);
resMap.put("sshkey",uuid);
}else {
return R.error("您的密码不正确,请重新输入!如忘记密码,请找回密码");
}
}else {
return R.error("1001","您的账号已被禁用,如有疑问请联系客服");
}
}else {
return R.error("您的手机号尚未注册,请先注册!");
}
return R.ok(resMap);
}

/**
*短信登录
*/
@RequestMapping("/smsLogin")
@NoAuthCheck
@ResponseBody
public R smsLogin( String phone,String smsCode)
{
Assert.isBlank(phone, "手机号码不能为空");
Assert.isBlank(smsCode, "验证码不能为空");
Assert.isNull(smsCodeService.validateSmsCode(smsCode, phone),"验证码不正确或已失效");
SellEntity condition=new SellEntity();
condition.setSPhone(phone);
EntityWrapper<SellEntity> entityWrapper=new EntityWrapper<SellEntity>(condition);
SellEntity reponseData=sellService.selectOne(entityWrapper);
Map<String, Object> resMap=new HashMap<>();
if(reponseData!=null)
{

if(!reponseData.getSForbidden().equals(Constant.HIDE)) {

String uuid = UUID.randomUUID().toString().replaceAll("-", "");
SellEntity changeSell=new SellEntity();
changeSell.setToken(uuid);
sellService.update(changeSell, entityWrapper);
resMap.put("sshkey",uuid);
}else {
return R.error("1001","您的账号已被禁用,如有疑问请联系客服");
}


}else {
return R.error("您的手机号尚未注册,请先注册!");
}
return R.ok(resMap);
}

/**
*退出登录
*/
@RequestMapping("/loginOut")
@ResponseBody
public R LoginOut()
{
SellEntity condition=new SellEntity();
condition.setToken(SubjectContextHolder.getSubject().getToken());
EntityWrapper<SellEntity> entityWrapper=new EntityWrapper<SellEntity>(condition);
SellEntity reponseData=sellService.selectOne(entityWrapper);
Map<String, Object> resMap=new HashMap<>();
if(reponseData!=null)
{
SellEntity changeSell=new SellEntity();
changeSell.setToken(" ");
sellService.update(changeSell, entityWrapper);
}
return R.ok(resMap);
}

/**
*微信账号登录
*/
@RequestMapping("/findSellByChat")
@NoAuthCheck
@ResponseBody
public R findSellByChat( String openId)
{
Assert.isBlank(openId, "openId不能为空");
SellEntity condition=new SellEntity();
condition.setSWxAppid(openId);
EntityWrapper<SellEntity> entityWrapper=new EntityWrapper<SellEntity>(condition);
SellEntity reponseData=sellService.selectOne(entityWrapper);
Map<String, Object> resMap=new HashMap<>();
if(reponseData!=null)
{
if(!reponseData.getSForbidden().equals(Constant.HIDE)) {
String uuid = UUID.randomUUID().toString().replaceAll("-", "");
SellEntity changeSell=new SellEntity();
changeSell.setToken(uuid);
sellService.update(changeSell, entityWrapper);
resMap.put("bindYn","1");
resMap.put("sshkey",uuid);
}else {
return R.error("1001","您的账号已被禁用,如有疑问请联系客服");
}
}else {
resMap.put("bindYn","0");
}
return R.ok(resMap);
}

/**
*商家详情查询
*/
@RequestMapping("/sellDetail")
@ResponseBody
public R sellDetail()
{
SellEntity condition=new SellEntity();
condition.setToken(SubjectContextHolder.getSubject().getToken());
EntityWrapper<SellEntity> entityWrapper=new EntityWrapper<SellEntity>(condition);
SellEntity reponseData=sellService.selectOne(entityWrapper);
if(reponseData==null)
{
return R.error("not find data");
}else {
reponseData.setSPassword(null);
reponseData.setToken(null);
RegionEntity regionEntity=null;
RegionEntity condt=new RegionEntity();
reponseData.setSPhone(VerifyCodeUtil.mobileEncrypt(reponseData.getSPhone()));



if(StringUtils.isNotBlank(reponseData.getSProvinceCode())) {
regionEntity=regionService.selectById(reponseData.getSProvinceCode());
reponseData.setsProvinceName(regionEntity!=null?regionEntity.getName():"");
}
if(StringUtils.isNotBlank(reponseData.getSCityCode())) {
regionEntity=regionService.selectById(reponseData.getSCityCode());
reponseData.setsCityName(regionEntity!=null?regionEntity.getName():"");
}
if(StringUtils.isNotBlank(reponseData.getSAreaCode())) {
regionEntity=regionService.selectById(reponseData.getSAreaCode());
reponseData.setsAreaName(regionEntity!=null?regionEntity.getName():"");
}
}
return R.ok(reponseData);
}

/**
*商家实名认证
*/
@RequestMapping("/authedSeller")
@ResponseBody
public R authedSeller(SellEntity sellDto)
{
Assert.isNull(sellDto.getSType(), "店铺类型不能为空");
Assert.isNull(sellDto.getSRealName(), "真实姓名不能为空");
Assert.isNull(sellDto.getSIdCard(), "身份证号不能为空");
Assert.isNull(sellDto.getSPic1(), "身份证正面照片不能为空");
Assert.isNull(sellDto.getSPic2(), "身份证反面照片不能为空");
Assert.isNull(sellDto.getSPic3(), "手持身份证照片不能为空");
Assert.isNull(sellDto.getSPic4(), "土地证/林地证照片不能为空");
Assert.isNull(sellDto.getSPic5(), "土地承包合同照片不能为空");
Assert.isNull(sellDto.getSPic6(), "合作社资质照片不能为空");

if(!VerifyCodeUtil.IDCardValidate(sellDto.getSIdCard())) {
throw new BusinessRuntimeException("证件号不正确");
}
SellEntity condition=new SellEntity();
condition.setToken(SubjectContextHolder.getSubject().getToken());
EntityWrapper<SellEntity> entityWrapper=new EntityWrapper<SellEntity>(condition);
SellEntity reponseData=sellService.selectOne(entityWrapper);
if(reponseData==null)
{
return R.error("not find data");
}else {
SellEntity changeSell=new SellEntity();
changeSell.setSType(sellDto.getSType());
changeSell.setSRealName(sellDto.getSRealName());
changeSell.setSIdCard(sellDto.getSIdCard());
changeSell.setSPic1(sellDto.getSPic1());
changeSell.setSPic2(sellDto.getSPic2());
changeSell.setSPic3(sellDto.getSPic3());
changeSell.setSPic4(sellDto.getSPic4());
changeSell.setSPic5(sellDto.getSPic5());
changeSell.setSPic6(sellDto.getSPic6());
sellService.update(changeSell, entityWrapper);
}
return R.ok(reponseData);
}

/**
*完善个人信息
*/
@RequestMapping("/fillPerfect")
@ResponseBody
public R fillPerfect(SellEntity sellDto)
{
Assert.isNull(sellDto.getShopName(), "店铺名称不能为空");
Assert.isNull(sellDto.getSProvinceCode(), "发货地址省份不能为空");
Assert.isNull(sellDto.getSCityCode(), "发货地址市区不能为空");
Assert.isNull(sellDto.getSAreaCode(), "发货地址区域不能为空");
Assert.isNull(sellDto.getSDetailAddress(), "发货地址详细地址不能为空");


Assert.isNull(sellDto.getSBackName(), "退货联系人不能为空");
Assert.isNull(sellDto.getSBackPhone(), "退货联系电话不能为空");
Assert.isNull(sellDto.getShopDesc(), "商家介绍不能为空");
Assert.isNull(sellDto.getSHourExpress(), "发货时长不能为空");

if(!VerifyCodeUtil.isPhone(sellDto.getSBackPhone()))
{
throw new BusinessRuntimeException("退货联系电话格式不正确");
}
SellEntity condition=new SellEntity();
condition.setToken(SubjectContextHolder.getSubject().getToken());
EntityWrapper<SellEntity> entityWrapper=new EntityWrapper<SellEntity>(condition);
SellEntity reponseData=sellService.selectOne(entityWrapper);
if(reponseData==null)
{
return R.error("not find data");
}else {
SellEntity changeSell=new SellEntity();
changeSell.setShopName(sellDto.getShopName());
changeSell.setSProvinceCode(sellDto.getSProvinceCode());
changeSell.setSCityCode(sellDto.getSCityCode());
changeSell.setSAreaCode(sellDto.getSAreaCode());
changeSell.setSDetailAddress(sellDto.getSDetailAddress());
changeSell.setSHourExpress(sellDto.getSHourExpress());
changeSell.setSHead(sellDto.getSHead());
changeSell.setSBackName(sellDto.getSBackName());
changeSell.setSBackPhone(sellDto.getSBackPhone());
changeSell.setShopDesc(sellDto.getShopDesc());
changeSell.setSAduitState(1);
changeSell.setSAttestation(2);//审核通过将该状态设置为 3已认证
sellService.update(changeSell, entityWrapper);
}
return R.ok(reponseData);
}
}
posted @ 2019-02-20 11:57  不忘﹑  阅读(1173)  评论(0编辑  收藏  举报