更新投票功能

This commit is contained in:
2025-09-24 01:48:12 +08:00
parent d1de58fe23
commit 6421435022
2 changed files with 87 additions and 41 deletions

View File

@@ -89,14 +89,14 @@ func UserLogin(c *gin.Context) {
// 业务逻辑实现
var user UserInfo
var username string
username := ""
// 查找用户是否存在
result := databaseInit.UserDB.Where("uid = ?", openid).First(&user)
if result.Error != nil {
if errors.Is(result.Error, gorm.ErrRecordNotFound) {
// 用户不存在,创建新用户
username := generateUsername()
username = generateUsername()
now := time.Now()
newUser := UserInfo{
Uid: openid,
@@ -117,7 +117,6 @@ func UserLogin(c *gin.Context) {
})
return
}
username = newUser.Username
} else {
// 数据库查询错误
c.JSON(http.StatusInternalServerError, gin.H{