puzhibing
2023-08-03 7558a21c1ae1b48b0888f3e3906eb4ba6a68b06f
UserIGOTravel/guns-admin/src/main/java/com/stylefeng/guns/modular/api/UserInfoController.java
@@ -1,21 +1,18 @@
package com.stylefeng.guns.modular.api;
import com.alibaba.fastjson.JSONObject;
import com.alibaba.fastjson.serializer.BigDecimalCodec;
import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.google.code.kaptcha.Constants;
import com.stylefeng.guns.core.common.constant.JwtConstants;
import com.stylefeng.guns.core.common.exception.InvalidKaptchaException;
import com.stylefeng.guns.core.support.HttpKit;
import com.stylefeng.guns.core.util.ToolUtil;
import com.stylefeng.guns.modular.system.model.BankCard;
import com.stylefeng.guns.modular.system.model.UserInfo;
import com.stylefeng.guns.modular.system.service.IReportLossService;
import com.stylefeng.guns.modular.system.service.ISmsrecordService;
import com.stylefeng.guns.modular.system.service.IUserInfoService;
import com.stylefeng.guns.modular.system.service.IVerifiedService;
import com.stylefeng.guns.modular.system.service.*;
import com.stylefeng.guns.modular.system.util.*;
import com.stylefeng.guns.modular.system.warpper.LoginWarpper;
import com.stylefeng.guns.modular.system.warpper.UserInfoWarpper;
import com.stylefeng.guns.modular.system.warpper.UserInviteInfoWarpper;
import com.stylefeng.guns.modular.system.warpper.VerifiedWarpper;
import com.stylefeng.guns.modular.system.warpper.*;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
@@ -30,6 +27,7 @@
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import java.io.File;
import java.math.BigDecimal;
import java.util.*;
/**
@@ -55,6 +53,9 @@
    @Autowired
    private IReportLossService reportLossService;
    @Autowired
    private IBankCardService bankCardService;
    @Value("${spring.mail.template-path}")
    private String templatePath;
@@ -123,12 +124,19 @@
            try {
               /* HttpSession session = request.getSession();
                String code = (String)session.getAttribute(Constants.KAPTCHA_SESSION_KEY);*/
                String substring = phone.substring(0, 1);
                if("0".equals(substring)){
                    phone = "233" + phone.substring(1);
                }
                if(phone.indexOf("233") < 0){
                    phone = "233" + phone;
                }
                String code = redisUtil.getValue(phone+"_Code");
                System.out.println("缓存中验证码为:"+code);
                if (ToolUtil.isEmpty(kaptcha) || !kaptcha.equalsIgnoreCase(code)) {
                    return ResultUtil.error(language == 1 ? "图形验证码错误" : language == 2 ? "The graphic verification code is incorrect" : "Code de vérification graphique incorrect");
                }
                return userInfoService.queryCaptcha(phone, type);
                return userInfoService.queryCaptcha(phone, type, language);
            }catch (Exception e){
                e.printStackTrace();
                return ResultUtil.runErr();
@@ -147,10 +155,17 @@
            @ApiImplicitParam(value = "手机号码", name = "phone", required = true, dataType = "String"),
            @ApiImplicitParam(value = "场景类型(1=身份验证,2=登录确认,3=用户注册,4=修改密码)", name = "type", required = true, dataType = "String")
    })
    public ResultUtil queryCaptcha1(String phone, Integer type){
    public ResultUtil queryCaptcha1(String phone, Integer type, Integer language){
        if(ToolUtil.isNotEmpty(phone)){
            try {
                return userInfoService.queryCaptcha(phone, type);
                String substring = phone.substring(0, 1);
                if("0".equals(substring)){
                    phone = "233" + phone.substring(1);
                }
                if(phone.indexOf("233") < 0){
                    phone = "233" + phone;
                }
                return userInfoService.queryCaptcha(phone, type, language);
            }catch (Exception e){
                e.printStackTrace();
                return ResultUtil.runErr();
@@ -194,24 +209,24 @@
                String path = templatePath +  "user/mainbox.html";
                Document document = Jsoup.parse(new File(path), "UTF-8");
                if(1 == language){
                    document.getElementById("english").attr("style", "display: none;");
                    document.getElementById("french").attr("style", "display: none;");
                    document.getElementById("english").remove();
                    document.getElementById("french").remove();
                    Element user_chinese = document.getElementById("user_chinese");
                    user_chinese.text("您好 " + nickName + ",");
                    Element content_chinese = document.getElementById("content_chinese");
                    content_chinese.text(authCode);
                }
                if(2 == language){
                    document.getElementById("chinese").attr("style", "display: none;");
                    document.getElementById("french").attr("style", "display: none;");
                    document.getElementById("chinese").remove();
                    document.getElementById("french").remove();
                    Element user_chinese = document.getElementById("user_english");
                    user_chinese.text("Hello " + nickName + ",");
                    Element content_chinese = document.getElementById("content_english");
                    content_chinese.text(authCode);
                }
                if(3 == language){
                    document.getElementById("chinese").attr("style", "display: none;");
                    document.getElementById("english").attr("style", "display: none;");
                    document.getElementById("chinese").remove();
                    document.getElementById("english").remove();
                    Element user_french = document.getElementById("user_french");
                    user_french.text("Bonjour " + nickName + ",");
                    Element content_french = document.getElementById("content_french");
@@ -239,17 +254,25 @@
     */
    @ResponseBody
    @PostMapping("/base/user/captchaLogin")
    @ApiOperation(value = "手机验证码登录", tags = {"用户端-登录"}, notes = "")
    @ApiOperation(value = "手机验证码登录【1.1】", tags = {"用户端-登录"}, notes = "")
    @ApiImplicitParams({
            @ApiImplicitParam(value = "手机号运营商(GH-MTN-B2C、GH-TIGO-B2C、GH-VODAFONE-B2C、GH-AIRTEL-B2C)", name = "phoneOperator", required = true, dataType = "String"),
            @ApiImplicitParam(value = "手机号码", name = "phone", required = true, dataType = "String"),
            @ApiImplicitParam(value = "短信验证码", name = "code", required = true, dataType = "String"),
            @ApiImplicitParam(value = "ip地址", name = "registIp", required = false, dataType = "String"),
            @ApiImplicitParam(value = "纬度", name = "lat", required = false, dataType = "double"),
            @ApiImplicitParam(value = "经度", name = "lng", required = false, dataType = "double")
    })
    public ResultUtil<LoginWarpper> captchaLogin(String phone, String code, String registIp, Double lat, Double lng, Integer language){
    public ResultUtil<LoginWarpper> captchaLogin(String phoneOperator, String phone, String code, String registIp, Double lat, Double lng, Integer language){
        try {
            return userInfoService.captchaLogin(phone, code, registIp, lat, lng,null,null,null,language);
            String substring = phone.substring(0, 1);
            if("0".equals(substring)){
                phone = "233" + phone.substring(1);
            }
            if(phone.indexOf("233") < 0){
                phone = "233" + phone;
            }
            return userInfoService.captchaLogin(phoneOperator, phone, code, registIp, lat, lng,null,null,null,language);
        }catch (Exception e){
            e.printStackTrace();
            return ResultUtil.runErr();
@@ -266,17 +289,25 @@
     */
    @ResponseBody
    @PostMapping("/base/user/captchaLogin_")
    @ApiOperation(value = "手机验证码登录", tags = {"分享专用"}, notes = "")
    @ApiOperation(value = "手机验证码登录【1.1】", tags = {"分享专用"}, notes = "")
    @ApiImplicitParams({
            @ApiImplicitParam(value = "手机号运营商(GH-MTN-B2C、GH-TIGO-B2C、GH-VODAFONE-B2C、GH-AIRTEL-B2C)", name = "phoneOperator", required = true, dataType = "String"),
            @ApiImplicitParam(value = "手机号码", name = "phone", required = true, dataType = "String"),
            @ApiImplicitParam(value = "短信验证码", name = "code", required = true, dataType = "String"),
            @ApiImplicitParam(value = "分享的用户id", name = "uid", required = true, dataType = "int"),
            @ApiImplicitParam(value = "用户类型(1=用户,2=司机)", name = "type", required = true, dataType = "int"),
            @ApiImplicitParam(value = "注册类型(1=司机注册,2=用户注册)", name = "userType", required = true, dataType = "int")
    })
    public ResultUtil<LoginWarpper> captchaLogin_(String phone, String code, Integer uid, Integer type, Integer userType, Integer language){
    public ResultUtil<LoginWarpper> captchaLogin_(String phoneOperator, String phone, String code, Integer uid, Integer type, Integer userType, Integer language){
        try {
            return userInfoService.captchaLogin(phone, code, uid, type, userType, language);
            String substring = phone.substring(0, 1);
            if("0".equals(substring)){
                phone = "233" + phone.substring(1);
            }
            if(phone.indexOf("233") < 0){
                phone = "233" + phone;
            }
            return userInfoService.captchaLogin(phoneOperator, phone, code, uid, type, userType, language);
        }catch (Exception e){
            e.printStackTrace();
            return ResultUtil.runErr();
@@ -303,6 +334,13 @@
    public ResultUtil<LoginWarpper> userLogin(String phone, String password, Integer language){
        if(ToolUtil.isNotEmpty(phone) && ToolUtil.isNotEmpty(password)){
            try {
                String substring = phone.substring(0, 1);
                if("0".equals(substring)){
                    phone = "233" + phone.substring(1);
                }
                if(phone.indexOf("233") < 0){
                    phone = "233" + phone;
                }
                return userInfoService.userLogin(phone, password, language);
            }catch (Exception e){
                e.printStackTrace();
@@ -332,6 +370,13 @@
    public ResultUtil forgetPassword(String phone, String code, String password, Integer language){
        if(ToolUtil.isNotEmpty(phone) && ToolUtil.isNotEmpty(code) && ToolUtil.isNotEmpty(password)){
            try {
                String substring = phone.substring(0, 1);
                if("0".equals(substring)){
                    phone = "233" + phone.substring(1);
                }
                if(phone.indexOf("233") < 0){
                    phone = "233" + phone;
                }
                return userInfoService.forgetPassword(phone, code, password, language);
            }catch (Exception e){
                e.printStackTrace();
@@ -431,19 +476,27 @@
     */
    @ResponseBody
    @PostMapping("/api/user/bindingPhone")
    @ApiOperation(value = "设置电话号码", tags = {"用户端-登录"}, notes = "")
    @ApiOperation(value = "设置电话号码【1.1】", tags = {"用户端-登录"}, notes = "")
    @ApiImplicitParams({
            @ApiImplicitParam(value = "手机号运营商(GH-MTN-B2C、GH-TIGO-B2C、GH-VODAFONE-B2C、GH-AIRTEL-B2C)", name = "phoneOperator", required = true, dataType = "String"),
            @ApiImplicitParam(value = "电话号码", name = "phone", required = true, dataType = "String"),
            @ApiImplicitParam(value = "验证码", name = "code", required = false, dataType = "String"),
            @ApiImplicitParam(name = "Authorization", value = "Bearer +token", required = true, dataType = "String", paramType = "header", defaultValue = "Bearer eyJhbGciOiJIUzUxMiJ9.....")
    })
    public ResultUtil<LoginWarpper> bindingPhone(String phone, String code, Integer language, HttpServletRequest request){
    public ResultUtil<LoginWarpper> bindingPhone(String phoneOperator, String phone, String code, Integer language, HttpServletRequest request){
        try {
            Integer uid = userInfoService.getUserIdFormRedis(request);
            if(null == uid){
                return ResultUtil.tokenErr();
            }
            return userInfoService.bindingPhone(uid, phone, code, language);
            String substring = phone.substring(0, 1);
            if("0".equals(substring)){
                phone = "233" + phone.substring(1);
            }
            if(phone.indexOf("233") < 0){
                phone = "233" + phone;
            }
            return userInfoService.bindingPhone(uid, phoneOperator, phone, code, language);
        }catch (Exception e){
            e.printStackTrace();
            return ResultUtil.runErr();
@@ -481,7 +534,7 @@
     */
    @ResponseBody
    @PostMapping("/api/user/queryUserInfo")
    @ApiOperation(value = "获取用户详情【1.0】", tags = {"用户端-个人中心"}, notes = "")
    @ApiOperation(value = "获取用户详情【1.1】", tags = {"用户端-个人中心"}, notes = "")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "Authorization", value = "Bearer +token", required = true, dataType = "String", paramType = "header", defaultValue = "Bearer eyJhbGciOiJIUzUxMiJ9.....")
    })
@@ -514,6 +567,13 @@
    })
    public ResultUtil<Object> queryUser(String phone){
        try {
            String substring = phone.substring(0, 1);
            if("0".equals(substring)){
                phone = "233" + phone.substring(1);
            }
            if(phone.indexOf("233") < 0){
                phone = "233" + phone;
            }
            Map<String, Object> map = userInfoService.queryUser(phone);
            if(null != map){
                return ResultUtil.success(UserInfoWarpper.getUserInfoWarpper(map));
@@ -573,6 +633,13 @@
            if(null == uid){
                return ResultUtil.tokenErr();
            }
            String substring = phone.substring(0, 1);
            if("0".equals(substring)){
                phone = "233" + phone.substring(1);
            }
            if(phone.indexOf("233") < 0){
                phone = "233" + phone;
            }
            userInfoService.setUrgentUser(name, phone, uid);
            return ResultUtil.success();
        }catch (Exception e){
@@ -591,20 +658,21 @@
     */
    @ResponseBody
    @PostMapping("/api/user/depositBalance")
    @ApiOperation(value = "余额充值", tags = {"用户端-个人中心"}, notes = "")
    @ApiOperation(value = "余额充值【1.1】", tags = {"用户端-个人中心"}, notes = "")
    @ApiImplicitParams({
            @ApiImplicitParam(value = "支付方式(1=线上支付)", name = "payType", required = true, dataType = "int"),
            @ApiImplicitParam(value = "支付方式(1=手机充值,2=银行卡充值)", name = "payType", required = true, dataType = "int"),
            @ApiImplicitParam(value = "银行卡id", name = "bankCardId", required = false, dataType = "int"),
            @ApiImplicitParam(value = "充值金额", name = "money", required = true, dataType = "double"),
            @ApiImplicitParam(value = "支付端(1=用户APP端,2=司机APP端,3=用户小程序端)", name = "type", required = false, dataType = "int"),
            @ApiImplicitParam(name = "Authorization", value = "Bearer +token", required = true, dataType = "String", paramType = "header", defaultValue = "Bearer eyJhbGciOiJIUzUxMiJ9.....")
    })
    public ResultUtil depositBalance(Integer payType, Double money, Integer type, Integer language, HttpServletRequest request){
    public ResultUtil depositBalance(Integer payType, String bankCardId, Double money, Integer type, Integer language, HttpServletRequest request){
        try {
            Integer uid = userInfoService.getUserIdFormRedis(request);
            if(null == uid){
                return ResultUtil.tokenErr();
            }
            return userInfoService.depositBalance(payType, "user_" + uid, money, uid, type, language);
            return userInfoService.depositBalance(payType, bankCardId, money, uid, type, language);
        }catch (Exception e){
            e.printStackTrace();
            return ResultUtil.runErr();
@@ -621,19 +689,27 @@
     */
    @ResponseBody
    @PostMapping("/api/user/updatePhone")
    @ApiOperation(value = "修改手机号码", tags = {"用户端-个人中心"}, notes = "")
    @ApiOperation(value = "修改手机号码【1.1】", tags = {"用户端-个人中心"}, notes = "")
    @ApiImplicitParams({
            @ApiImplicitParam(value = "验证码", name = "code", required = true, dataType = "string"),
            @ApiImplicitParam(value = "手机号运营商(GH-MTN-B2C、GH-TIGO-B2C、GH-VODAFONE-B2C、GH-AIRTEL-B2C)", name = "phoneOperator", required = true, dataType = "String"),
            @ApiImplicitParam(value = "新手机号", name = "phone", required = true, dataType = "string"),
            @ApiImplicitParam(name = "Authorization", value = "Bearer +token", required = true, dataType = "String", paramType = "header", defaultValue = "Bearer eyJhbGciOiJIUzUxMiJ9.....")
    })
    public ResultUtil updatePhone(String code, String phone, Integer language, HttpServletRequest request){
    public ResultUtil updatePhone(String code, String phoneOperator, String phone, Integer language, HttpServletRequest request){
        try {
            Integer uid = userInfoService.getUserIdFormRedis(request);
            if(null == uid){
                return ResultUtil.tokenErr();
            }
            return userInfoService.updatePhone(code, phone, uid, language);
            String substring = phone.substring(0, 1);
            if("0".equals(substring)){
                phone = "233" + phone.substring(1);
            }
            if(phone.indexOf("233") < 0){
                phone = "233" + phone;
            }
            return userInfoService.updatePhone(code, phoneOperator, phone, uid, language);
        }catch (Exception e){
            e.printStackTrace();
            return ResultUtil.runErr();
@@ -653,6 +729,13 @@
            Integer uid = userInfoService.getUserIdFormRedis(request);
            if(null == uid){
                return ResultUtil.tokenErr();
            }
            String substring = phone.substring(0, 1);
            if("0".equals(substring)){
                phone = "233" + phone.substring(1);
            }
            if(phone.indexOf("233") < 0){
                phone = "233" + phone;
            }
            UserInfo userInfo = userInfoService.selectById(uid);
            smsrecordService.saveData(4, userInfo.getPhone(), code, "短信验证码【" + code + "】已发到您的手机,验证码将在5分钟后失效,请及时登录!");
@@ -706,25 +789,25 @@
     */
    @ResponseBody
    @PostMapping("/api/user/updateInfo")
    @ApiOperation(value = "修改个人信息", tags = {"用户端-个人中心"}, notes = "")
    @ApiOperation(value = "修改个人信息【1.1】", tags = {"用户端-个人中心"}, notes = "")
    @ApiImplicitParams({
            @ApiImplicitParam(value = "头像", name = "avatar", required = false, dataType = "string"),
            @ApiImplicitParam(value = "昵称", name = "nickname", required = false, dataType = "string"),
            @ApiImplicitParam(value = "性别(1=男,2=女)", name = "sex", required = false, dataType = "int"),
            @ApiImplicitParam(value = "生日(2020-06-15)", name = "birthday", required = false, dataType = "string"),
            @ApiImplicitParam(value = "邮箱", name = "email", required = false, dataType = "string"),
            @ApiImplicitParam(value = "邮箱验证码", name = "code", required = false, dataType = "string"),
            @ApiImplicitParam(value = "姓氏", name = "lastName", required = false, dataType = "string"),
            @ApiImplicitParam(value = "名字", name = "firstName", required = false, dataType = "string"),
            @ApiImplicitParam(name = "Authorization", value = "Bearer +token", required = true, dataType = "String", paramType = "header", defaultValue = "Bearer eyJhbGciOiJIUzUxMiJ9.....")
    })
    public ResultUtil updateInfo(String avatar, String nickname, Integer sex, Date birthday, String email, String lastName, String firstName, HttpServletRequest request){
    public ResultUtil updateInfo(String avatar, String nickname, Integer sex, Date birthday, String email, String code, String lastName, String firstName, Integer language, HttpServletRequest request){
        try {
            Integer uid = userInfoService.getUserIdFormRedis(request);
            if(null == uid){
                return ResultUtil.tokenErr();
            }
            userInfoService.updateInfo(avatar, nickname, sex, birthday, email, lastName, firstName, uid);
            return ResultUtil.success();
            return userInfoService.updateInfo(avatar, nickname, sex, birthday, email, code, lastName, firstName, uid, language);
        }catch (Exception e){
            e.printStackTrace();
            return ResultUtil.runErr();
@@ -906,4 +989,96 @@
            return ResultUtil.runErr();
        }
    }
    @ResponseBody
    @PostMapping("/api/user/queryBankCardList")
    @ApiOperation(value = "获取银行卡列表【1.1】", tags = {"用户端-个人中心"}, notes = "")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "Authorization", value = "Bearer +token", required = true, dataType = "String", paramType = "header", defaultValue = "Bearer eyJhbGciOiJIUzUxMiJ9.....")
    })
    public ResultUtil<List<BankCardWarpper>> queryBankCardList(HttpServletRequest request){
        try {
            Integer uid = userInfoService.getUserIdFormRedis(request);
            if(null == uid){
                return ResultUtil.tokenErr();
            }
            List<BankCard> bankCards = bankCardService.selectList(new EntityWrapper<BankCard>().eq("userType", 1).eq("userId", uid));
            List<BankCardWarpper> list = new ArrayList<>();
            for (BankCard bankCard : bankCards) {
                BankCardWarpper bankCardWarpper = new BankCardWarpper();
                bankCardWarpper.setId(bankCard.getId());
                bankCardWarpper.setBankName(bankCard.getBank());
                bankCardWarpper.setCode(bankCard.getCode());
                list.add(bankCardWarpper);
            }
            return ResultUtil.success(list);
        }catch (Exception e){
            e.printStackTrace();
            return ResultUtil.runErr();
        }
    }
    @ResponseBody
    @PostMapping("/api/user/addBankCard")
    @ApiOperation(value = "添加银行卡【1.1】", tags = {"用户端-个人中心"}, notes = "")
    @ApiImplicitParams({
            @ApiImplicitParam(value = "银行", name = "bank", required = true, dataType = "string"),
            @ApiImplicitParam(value = "姓", name = "lastName", required = true, dataType = "string"),
            @ApiImplicitParam(value = "名", name = "firstName", required = true, dataType = "string"),
            @ApiImplicitParam(value = "卡号", name = "code", required = true, dataType = "string"),
            @ApiImplicitParam(value = "1=中文,2=英文,3=法语", name = "language", required = true, dataType = "int"),
            @ApiImplicitParam(name = "Authorization", value = "Bearer +token", required = true, dataType = "String", paramType = "header", defaultValue = "Bearer eyJhbGciOiJIUzUxMiJ9.....")
    })
    public ResultUtil addBankCard(String bank, String lastName, String firstName, String code, Integer language, HttpServletRequest request) {
        try {
            Integer uid = userInfoService.getUserIdFormRedis(request);
            if(null == uid){
                return ResultUtil.tokenErr();
            }
            BigDecimal bigDecimal = new BigDecimal(code);
            long max = Long.MAX_VALUE;
            if(bigDecimal.compareTo(new BigDecimal(max)) >= 0){
                return ResultUtil.error(language == 1 ? "银行卡号格式错误" : language == 2 ? "The format of bank card number is incorrect" : "Format incorrect du numéro de carte bancaire");
            }
            BankCard bankCard = bankCardService.selectOne(new EntityWrapper<BankCard>().eq("code", code));
            if(null != bankCard){
                return ResultUtil.error(language == 1 ? "银行卡重复" : language == 2 ? "Duplicate bank card" : "Double carte bancaire");
            }
            bankCard = new BankCard();
            bankCard.setUserId(uid);
            bankCard.setUserType(1);
            bankCard.setCode(code);
            bankCard.setBank(bank);
            bankCard.setFirstName(firstName);
            bankCard.setLastName(lastName);
            bankCard.setInsertTime(new Date());
            bankCardService.insert(bankCard);
            return ResultUtil.success();
        }catch (Exception e){
            e.printStackTrace();
            return ResultUtil.runErr();
        }
    }
    @ResponseBody
    @PostMapping("/api/user/delBankCard")
    @ApiOperation(value = "删除银行卡【1.1】", tags = {"用户端-个人中心"}, notes = "")
    @ApiImplicitParams({
            @ApiImplicitParam(value = "银行卡id", name = "id", required = true, dataType = "int"),
            @ApiImplicitParam(name = "Authorization", value = "Bearer +token", required = true, dataType = "String", paramType = "header", defaultValue = "Bearer eyJhbGciOiJIUzUxMiJ9.....")
    })
    public ResultUtil delBankCard(Integer id){
        try {
            bankCardService.deleteById(id);
            return ResultUtil.success();
        }catch (Exception e){
            e.printStackTrace();
            return ResultUtil.runErr();
        }
    }
}