| | |
| | | package com.yeshi.makemoney.app.controller.client.api; |
| | | |
| | | import com.yeshi.makemoney.app.dto.user.LoginInfoDTO; |
| | | 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.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.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 |
| | |
| | | private UserInfoService userInfoService; |
| | | |
| | | @Resource |
| | | private VIPService vipService; |
| | | private UserExtraInfoService userExtraInfoService; |
| | | |
| | | @Resource |
| | | private WXUserInfoService wxUserInfoService; |
| | | |
| | | @Resource |
| | | private VerifyCodeManager verifyCodeManager; |
| | | |
| | | // @Reference(version = "1.0", check = false) |
| | | // @Reference(version = "1.0", check = false) |
| | | private BDeviceTokenService bDeviceTokenService; |
| | | |
| | | @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)) { |
| | |
| | | } |
| | | }); |
| | | |
| | | 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") |
| | |
| | | if (user == null) { |
| | | return JsonUtil.loadFalseResult("用户不存在"); |
| | | } |
| | | |
| | | if (user.getStatus() == UserInfo.STATUS_FORBIDDEN) { |
| | | return JsonUtil.loadFalseResult(ApiCodeConstant.CODE_FAIL_USER_FORBIDDEN, "账号被封禁"); |
| | | } |
| | |
| | | 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), wxUserInfoService.selectByUid(uid)); |
| | | |
| | | 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 |
| | |
| | | return JsonUtil.loadTrueResult(e.getMessage()); |
| | | } |
| | | |
| | | } |
| | | |
| | | /** |
| | | * @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); |
| | | |
| | | } |
| | | |