package com.ruoyi.web.controller.api; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper; import com.ruoyi.common.core.domain.R; import com.ruoyi.framework.web.service.TokenService; import com.ruoyi.system.dto.UpdatePhoneDto; import com.ruoyi.system.dto.UpdateUserDto; import com.ruoyi.system.model.TAppUser; import com.ruoyi.system.service.TAppUserService; import com.ruoyi.system.service.TCommissionTransactionFlowService; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; import org.springframework.context.annotation.Lazy; import org.springframework.web.bind.annotation.*; /** * 个人中心相关接口 */ @Slf4j @RestController @RequestMapping("/userIndex") @Api(tags = "个人中心") @RequiredArgsConstructor(onConstructor_ = {@Lazy}) public class UserIndexController { private final TAppUserService tAppUserService; private final TokenService tokenService; private final TCommissionTransactionFlowService commissionTransactionFlowService; @ApiOperation(value = "个人中心--用户信息",response = TAppUser.class) @GetMapping(value = "/getUserInfo") public R getUserInfo() { Integer userId = tokenService.getLoginUserApplet().getUserId(); TAppUser appUser = tAppUserService.getById(userId); return R.ok(); } @ApiOperation(value = "个人中心--修改手机号") @PostMapping(value = "/updatePhone") public R getMicroWishDetail(@RequestBody UpdatePhoneDto dto) { Integer userId = tokenService.getLoginUserApplet().getUserId(); long count = tAppUserService.count(new LambdaQueryWrapper().eq(TAppUser::getPhone, dto.getPhone()).ne(TAppUser::getId, userId)); if (count > 0) { return R.fail("手机号已存在"); } tAppUserService.update(new LambdaUpdateWrapper().set(TAppUser::getPhone, dto.getPhone()).eq(TAppUser::getId, userId)); return R.ok(); } @ApiOperation(value = "个人中心--修改信息") @PostMapping(value = "/updateUserInfo") public R updateUserInfo(@RequestBody UpdateUserDto dto) { Integer userId = tokenService.getLoginUserApplet().getUserId(); TAppUser appUser = tAppUserService.getById(userId); if(dto.getAvatar()!=null){ appUser.setProfilePhoto(dto.getAvatar()); } if(dto.getNickName()!=null){ appUser.setName(dto.getNickName()); } if(dto.getGender()!=null){ appUser.setGender(dto.getGender()); } if(dto.getBirthday()!=null){ appUser.setBirthday(dto.getBirthday()); } if(dto.getName()!=null){ appUser.setName(dto.getName()); } if(dto.getPhone()!=null){ long count = tAppUserService.count(new LambdaQueryWrapper().eq(TAppUser::getPhone, dto.getPhone()).ne(TAppUser::getId, userId)); if (count > 0) { return R.fail("手机号已存在"); } appUser.setPhone(dto.getPhone()); } tAppUserService.updateById(appUser); return R.ok(); } }