From 15bedcc619b1edb6eb987f9288db7670e5b38c46 Mon Sep 17 00:00:00 2001 From: admin <weikou2014> Date: 星期六, 07 五月 2022 19:42:23 +0800 Subject: [PATCH] bug修复 --- app/src/main/java/com/yeshi/makemoney/app/controller/client/api/UserController.java | 251 ++++++++++++++++++++++++++++++++++++++++---------- 1 files changed, 201 insertions(+), 50 deletions(-) diff --git a/app/src/main/java/com/yeshi/makemoney/app/controller/client/api/UserController.java b/app/src/main/java/com/yeshi/makemoney/app/controller/client/api/UserController.java index 2db8df5..146760e 100644 --- a/app/src/main/java/com/yeshi/makemoney/app/controller/client/api/UserController.java +++ b/app/src/main/java/com/yeshi/makemoney/app/controller/client/api/UserController.java @@ -1,32 +1,52 @@ package com.yeshi.makemoney.app.controller.client.api; import com.yeshi.makemoney.app.dto.user.LoginInfoDTO; +import com.yeshi.makemoney.app.entity.APPPlatform; +import com.yeshi.makemoney.app.entity.user.UserExtraInfo; import com.yeshi.makemoney.app.entity.user.UserInfo; import com.yeshi.makemoney.app.entity.user.UserLoginRecord; +import com.yeshi.makemoney.app.entity.user.WXUserInfo; import com.yeshi.makemoney.app.entity.vip.UserVIPInfo; import com.yeshi.makemoney.app.exception.user.LoginException; +import com.yeshi.makemoney.app.exception.user.UserAccountException; +import com.yeshi.makemoney.app.service.inter.goldcorn.GoldCornGetRecordService; +import com.yeshi.makemoney.app.service.inter.money.UserMoneyService; +import com.yeshi.makemoney.app.service.inter.team.TeamInviteRelationService; import com.yeshi.makemoney.app.service.inter.user.UserAccountService; +import com.yeshi.makemoney.app.service.inter.user.UserExtraInfoService; import com.yeshi.makemoney.app.service.inter.user.UserInfoService; +import com.yeshi.makemoney.app.service.inter.user.WXUserInfoService; import com.yeshi.makemoney.app.service.inter.vip.VIPService; +import com.yeshi.makemoney.app.service.manager.PushManager; import com.yeshi.makemoney.app.service.manager.VerifyCodeManager; import com.yeshi.makemoney.app.utils.ApiCodeConstant; +import com.yeshi.makemoney.app.utils.ImageUtil; import com.yeshi.makemoney.app.utils.annotation.UserLogin; import com.yeshi.makemoney.app.vo.AcceptData; +import com.yeshi.makemoney.app.vo.user.UserAssetsVO; import com.yeshi.makemoney.app.vo.user.UserInfoVO; import com.ks.lib.common.exception.ParamsException; import com.ks.push.exception.BPushDeviceTokenException; import com.ks.push.pojo.DO.BPushDeviceToken; import com.ks.push.pojo.DO.PushPlatform; import com.ks.push.service.BDeviceTokenService; +import org.apache.commons.codec.digest.DigestUtils; import org.apache.dubbo.config.annotation.Reference; +import org.springframework.lang.Nullable; import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.ResponseBody; -import org.yeshi.utils.JsonUtil; -import org.yeshi.utils.StringUtil; -import org.yeshi.utils.ThreadUtil; +import org.springframework.web.multipart.MultipartFile; +import org.yeshi.utils.*; +import org.yeshi.utils.entity.FileUploadResult; +import org.yeshi.utils.tencentcloud.COSManager; import javax.annotation.Resource; +import javax.servlet.http.HttpServletRequest; +import java.io.InputStream; +import java.math.BigDecimal; +import java.util.Date; /** * @author hxh @@ -45,18 +65,31 @@ private UserInfoService userInfoService; @Resource - private VIPService vipService; + private UserExtraInfoService userExtraInfoService; + + @Resource + private WXUserInfoService wxUserInfoService; @Resource private VerifyCodeManager verifyCodeManager; -// @Reference(version = "1.0", check = false) - private BDeviceTokenService bDeviceTokenService; + @Resource + private PushManager pushManager; + + @Resource + private GoldCornGetRecordService goldCornGetRecordService; + + @Resource + private UserMoneyService userMoneyService; + + @Resource + private TeamInviteRelationService teamInviteRelationService; @ResponseBody @RequestMapping("loginPhone") - public String loginPhone(AcceptData acceptData, String phone, String vcode, String token) { + public String loginPhone(AcceptData acceptData, String phone, String vcode, String token, HttpServletRequest request) { LoginInfoDTO loginInfo = new LoginInfoDTO(); + loginInfo.setIpInfo(IPUtil.getRemotIP(request) + ":" + request.getRemotePort()); loginInfo.setLoginType(UserLoginRecord.TYPE_LOGIN_PHONE); if (!StringUtil.isNullOrEmpty(phone)) { if (StringUtil.isNullOrEmpty(vcode)) { @@ -72,6 +105,25 @@ return JsonUtil.loadFalseResult("淇℃伅涓嶅畬鏁�"); } loginInfo.setSystem(acceptData.getSystem()); + return login(loginInfo, acceptData); + } + + + @ResponseBody + @RequestMapping("loginWX") + public String loginWX(AcceptData acceptData, String code, HttpServletRequest request) { + LoginInfoDTO loginInfo = new LoginInfoDTO(); + loginInfo.setIpInfo(IPUtil.getRemotIP(request) + ":" + request.getRemotePort()); + loginInfo.setLoginType(UserLoginRecord.TYPE_LOGIN_WX); + if (StringUtil.isNullOrEmpty(code)) { + return JsonUtil.loadFalseResult("淇℃伅涓嶅畬鏁�"); + } + loginInfo.setWxCode(code); + loginInfo.setSystem(acceptData.getSystem()); + return login(loginInfo, acceptData); + } + + private String login(LoginInfoDTO loginInfo, AcceptData acceptData) { try { UserInfo userInfo = userAccountService.login(loginInfo); ThreadUtil.run(new Runnable() { @@ -79,19 +131,62 @@ public void run() { try { //鐧诲綍鎴愬姛 - bDeviceTokenService.bindUid(acceptData.getSystem().name(), acceptData.getUtdId(), userInfo.getId() + ""); + pushManager.bindUid(acceptData.getSystem(), userInfo.getId(), acceptData.getPlatform() == APPPlatform.ios ? acceptData.getIdfa() : acceptData.getUtdId()); } catch (Exception e) { } } }); - return JsonUtil.loadTrueResult(JsonUtil.getApiCommonGson().toJson(userInfo)); + return outUserInfoForLogin(userInfo); } catch (LoginException e) { return JsonUtil.loadFalseResult(e.getMessage()); } - } + + private String outUserInfoForLogin(UserInfo userInfo) { + UserInfoVO vo = UserInfoVO.create(userInfo, userExtraInfoService.get(userInfo.getId())); + //鏄惁闇�瑕佸~鍐欓個璇风爜 + Long bossId = teamInviteRelationService.getBossUid(userInfo.getId()); + if (bossId != null) { + vo.setHasBoss(true); + } else { + vo.setHasBoss(false); + } + return JsonUtil.loadTrueResult(JsonUtil.getSimpleGson().toJson(vo)); + } + + + @UserLogin(uid = "#uid") + @ResponseBody + @RequestMapping("bindWX") + public String bindWX(AcceptData acceptData, Long uid, String code) { + + try { + userAccountService.bindWX(uid, code); + } catch (UserAccountException e) { + e.printStackTrace(); + return JsonUtil.loadFalseResult(e.getMsg()); + } + + return JsonUtil.loadTrueResult(""); + } + + @UserLogin(uid = "#uid") + @ResponseBody + @RequestMapping("bindPhone") + public String bindPhone(AcceptData acceptData, Long uid, String phone, String vcode, String token) { + + try { + userAccountService.bindPhone(uid, phone, vcode, token); + } catch (UserAccountException e) { + e.printStackTrace(); + return JsonUtil.loadFalseResult(e.getMsg()); + } + + return JsonUtil.loadTrueResult(""); + } + @UserLogin(uid = "#uid") @ResponseBody @@ -99,7 +194,7 @@ public String logout(AcceptData acceptData, Long uid) { try { //瑙g粦UID - bDeviceTokenService.unBindUid(acceptData.getSystem().name(), acceptData.getUtdId()); + pushManager.unBind(acceptData.getSystem(), acceptData.getPlatform() == APPPlatform.ios ? acceptData.getIdfa() : acceptData.getUtdId()); } catch (Exception e) { e.printStackTrace(); } @@ -111,23 +206,23 @@ @UserLogin(uid = "#uid") @ResponseBody @RequestMapping("unRegister") - public String unRegister(AcceptData acceptData, String vcode, String phone) { + public String unRegister(AcceptData acceptData, Long uid) { - if (StringUtil.isNullOrEmpty(vcode)) { - return JsonUtil.loadFalseResult("楠岃瘉鐮佷笉鑳戒负绌�"); - } +// if (StringUtil.isNullOrEmpty(vcode)) { +// return JsonUtil.loadFalseResult("楠岃瘉鐮佷笉鑳戒负绌�"); +// } +// +// if (StringUtil.isNullOrEmpty(phone)) { +// return JsonUtil.loadFalseResult("鎵嬫満鍙蜂笉鑳戒负绌�"); +// } +// +// if (!verifyCodeManager.isPhoneCodeRight(acceptData.getSystem(), phone, vcode)) { +// return JsonUtil.loadFalseResult("楠岃瘉鐮侀敊璇�"); +// } - if (StringUtil.isNullOrEmpty(phone)) { - return JsonUtil.loadFalseResult("鎵嬫満鍙蜂笉鑳戒负绌�"); - } - - if (!verifyCodeManager.isPhoneCodeRight(acceptData.getSystem(), phone, vcode)) { - return JsonUtil.loadFalseResult("楠岃瘉鐮侀敊璇�"); - } - - UserInfo user = userInfoService.selectValidByPhone(acceptData.getSystem(), phone); + UserInfo user = userInfoService.getAvaiableUser(uid); if (user == null) { - return JsonUtil.loadFalseResult("涓嶅瓨鍦ㄧ粦瀹氳鎵嬫満鍙风殑鐢ㄦ埛"); + return JsonUtil.loadFalseResult("鐢ㄦ埛涓嶅瓨鍦ㄦ垨鐢ㄦ埛宸茶灏佺"); } //娉ㄩ攢 userAccountService.unRegister(user.getId()); @@ -144,6 +239,7 @@ if (user == null) { return JsonUtil.loadFalseResult("鐢ㄦ埛涓嶅瓨鍦�"); } + if (user.getStatus() == UserInfo.STATUS_FORBIDDEN) { return JsonUtil.loadFalseResult(ApiCodeConstant.CODE_FAIL_USER_FORBIDDEN, "璐﹀彿琚皝绂�"); } @@ -152,45 +248,100 @@ return JsonUtil.loadFalseResult(ApiCodeConstant.CODE_FAIL_USER_DELETE, "鐢ㄦ埛宸茶鍒犻櫎"); } - UserInfoVO vo = new UserInfoVO(); - vo.setId(user.getId() + ""); - vo.setNickName(user.getNickName()); - vo.setPortrait(user.getPortrait()); - UserVIPInfo userVIPInfo = vipService.getVIPInfo(user.getId()); - if (userVIPInfo != null) { - vo.setVipExpireTime(userVIPInfo.getExpireDate().getTime()); - } - + UserInfoVO vo = UserInfoVO.create(user, userExtraInfoService.get(uid), user.getWxUser() == null ? null : wxUserInfoService.get(user.getWxUser().getId())); return JsonUtil.loadTrueResult(vo); + } + + @UserLogin(uid = "#uid") + @ResponseBody + @RequestMapping("updateUserInfo") + public String updateUserInfo(AcceptData acceptData, Long uid, String nickName, @Nullable @RequestParam("portrait") MultipartFile portrait, String portraitMD5) { + + UserInfo user = userInfoService.get(uid); + + if (user == null) { + return JsonUtil.loadFalseResult("鐢ㄦ埛涓嶅瓨鍦�"); + } + + UserInfo update = new UserInfo(); + update.setId(uid); + + if (!StringUtil.isNullOrEmpty(nickName)) { + update.setNickName(nickName); + } + + if (portrait != null) { + + if (StringUtil.isNullOrEmpty(portraitMD5)) { + return JsonUtil.loadFalseResult("澶村儚鏂囦欢鍔犲瘑鍊间负绌�"); + } + + try { + String md5 = DigestUtils.md5Hex(portrait.getBytes()); + if (!portraitMD5.equalsIgnoreCase(md5)) { + return JsonUtil.loadFalseResult("澶村儚鏂囦欢鍔犲瘑鍊奸敊璇�"); + } + + InputStream inputStream = portrait.getInputStream(); + String contentType = portrait.getContentType(); + String key = String.format("/imgs/portrait/%s_%s.png", uid, md5); + FileUploadResult result = COSManager.getInstance().uploadFile(inputStream, key); + if (result == null) { + return JsonUtil.loadFalseResult("涓婁紶鍑洪敊"); + } + update.setPortrait(ImageUtil.getCOSImageUrl(key)); + } catch (Exception e) { + return JsonUtil.loadFalseResult("澶村儚淇敼鍑洪敊"); + } + } + + userInfoService.update(update); + if (portrait != null) { + //鍒犻櫎鍘熸潵鐨勫ご鍍� + if (!user.getPortrait().contains("default")) { + try { + COSManager.getInstance().deleteFileByKey(ImageUtil.getUrlKey(user.getPortrait())); + } catch (Exception e) { + } + } + } + + return JsonUtil.loadTrueResult(""); } @ResponseBody @RequestMapping("uploadPushRegId") public String uploadPushRegId(AcceptData acceptData, Long uid, String regId) { - - BPushDeviceToken deviceToken = new BPushDeviceToken(); - deviceToken.setAppCode(acceptData.getSystem().name()); - deviceToken.setDeviceId(acceptData.getUtdId()); - deviceToken.setBuildModel(acceptData.getDeviceType()); - deviceToken.setBuildVersion(acceptData.getOsVersion()); - deviceToken.setToken(regId); - deviceToken.setType(PushPlatform.jpush); - if (uid != null) { - deviceToken.setUid(uid + ""); - } - deviceToken.setVersionCode(acceptData.getVersion()); - try { - bDeviceTokenService.save(deviceToken); + pushManager.saveToken(acceptData, uid, regId); return JsonUtil.loadTrueResult(""); } catch (BPushDeviceTokenException e) { - return JsonUtil.loadTrueResult(e.getMessage()); + return JsonUtil.loadFalseResult(e.getCode(), "涓氬姟鍑洪敊"); } catch (ParamsException e) { - return JsonUtil.loadTrueResult(e.getMessage()); + return JsonUtil.loadFalseResult(e.getCode(), "鍙傛暟閿欒"); } + } + /** + * @return java.lang.String + * @author hxh + * @description 鐢ㄦ埛璧勪骇 + * @date 14:36 2022/4/20 + * @param: acceptData + * @param: uid + **/ + @ResponseBody + @RequestMapping("getUserAssets") + public String getUserAssets(AcceptData acceptData, Long uid) { + Long goldCorn = goldCornGetRecordService.getGoldCornByDay(uid, new Date()); + BigDecimal money = userMoneyService.getBalance(uid); + + UserAssetsVO vo = new UserAssetsVO(); + vo.setGoldCorn(goldCorn == null ? 0 : Integer.parseInt(goldCorn + "")); + vo.setBalance(money.setScale(2).toString()); + return JsonUtil.loadTrueResult(vo); } -- Gitblit v1.8.0