diff --git a/src/main/java/com/xkrs/controller/SysUserController.java b/src/main/java/com/xkrs/controller/SysUserController.java index 8bc0534..f563bee 100644 --- a/src/main/java/com/xkrs/controller/SysUserController.java +++ b/src/main/java/com/xkrs/controller/SysUserController.java @@ -11,6 +11,7 @@ import com.xkrs.model.vo.SysUserVo; import com.xkrs.service.SysUserService; import org.springframework.context.i18n.LocaleContextHolder; import org.springframework.security.access.prepost.PreAuthorize; +import org.springframework.transaction.annotation.Transactional; import org.springframework.validation.BindingResult; import org.springframework.validation.annotation.Validated; import org.springframework.web.bind.annotation.*; @@ -251,4 +252,19 @@ public class SysUserController { return sysUserService.findUserByOpenId(openId); } + /** + * 绑定网站账号 + * @param map + * @return + */ + @Transactional(rollbackFor=Exception.class) + @PostMapping("/updateOpenIdByPhone") + public String updateOpenIdByPhone(@RequestBody Map map){ + Locale locale = LocaleContextHolder.getLocale(); + String openId = (String) map.get("openId"); + String phone = (String) map.get("phone"); + sysUserDao.updateOpenIdByPhone(phone,openId); + return outputEncapsulationObject(PromptMessageEnum.SUCCESS,"绑定成功!",locale); + } + } diff --git a/src/main/java/com/xkrs/dao/SysUserDao.java b/src/main/java/com/xkrs/dao/SysUserDao.java index 673b6d1..c13a953 100644 --- a/src/main/java/com/xkrs/dao/SysUserDao.java +++ b/src/main/java/com/xkrs/dao/SysUserDao.java @@ -134,4 +134,13 @@ public interface SysUserDao extends JpaRepository { * @return */ SysUserEntity findByOpenId(String openId); + + /** + * 根据用户名(手机号),修改openid + * @param userName + * @param openId + */ + @Query(value = "update sys_user set open_id = ?2 where user_name = ?1",nativeQuery = true) + @Modifying(clearAutomatically=true) + void updateOpenIdByPhone(String userName,String openId); }