优化输入框和表单样式,确保在小程序和管理端开发中使用容器包裹输入框以避免布局问题。更新个人资料页,增加VIP用户的字段展示与编辑逻辑,确保用户体验一致性。调整相关文档以反映最新开发进展,提升功能可用性与用户体验。

This commit is contained in:
Alex-larget
2026-02-28 17:26:03 +08:00
parent 41e5b1258b
commit 8e2ea9b7c1
14 changed files with 195 additions and 114 deletions

View File

@@ -196,37 +196,35 @@ func UserProfileGet(c *gin.Context) {
}
db := database.DB()
var user model.User
q := db.Select("id", "open_id", "nickname", "avatar", "phone", "wechat_id", "referral_code",
"has_full_book", "earnings", "pending_earnings", "referral_count", "created_at",
"mbti", "region", "industry", "position", "business_scale", "skills",
"story_best_month", "story_achievement", "story_turning", "help_offer", "help_need", "project_intro")
if userId != "" {
db = db.Where("id = ?", userId)
q = q.Where("id = ?", userId)
} else {
db = db.Where("open_id = ?", openId)
q = q.Where("open_id = ?", openId)
}
if err := db.First(&user).Error; err != nil {
if err := q.First(&user).Error; err != nil {
c.JSON(http.StatusNotFound, gin.H{"success": false, "error": "用户不存在"})
return
}
profileComplete := (user.Phone != nil && *user.Phone != "") || (user.WechatID != nil && *user.WechatID != "")
hasAvatar := user.Avatar != nil && *user.Avatar != "" && len(*user.Avatar) > 0
str := func(p *string) interface{} { if p != nil { return *p }; return "" }
resp := gin.H{
"id": user.ID, "openId": user.OpenID, "nickname": user.Nickname, "avatar": user.Avatar,
"phone": user.Phone, "wechatId": user.WechatID, "referralCode": user.ReferralCode,
"id": user.ID, "openId": user.OpenID, "nickname": str(user.Nickname), "avatar": str(user.Avatar),
"phone": str(user.Phone), "wechatId": str(user.WechatID), "referralCode": user.ReferralCode,
"hasFullBook": user.HasFullBook, "earnings": user.Earnings, "pendingEarnings": user.PendingEarnings,
"referralCount": user.ReferralCount, "profileComplete": profileComplete, "hasAvatar": hasAvatar,
"createdAt": user.CreatedAt,
// P3 资料扩展:统一返回所有表单字段,空值用 "" 便于前端回显
"mbti": str(user.Mbti), "region": str(user.Region), "industry": str(user.Industry),
"position": str(user.Position), "businessScale": str(user.BusinessScale), "skills": str(user.Skills),
"storyBestMonth": str(user.StoryBestMonth), "storyAchievement": str(user.StoryAchievement),
"storyTurning": str(user.StoryTurning), "helpOffer": str(user.HelpOffer), "helpNeed": str(user.HelpNeed),
"projectIntro": str(user.ProjectIntro),
}
// P3 资料扩展
if user.Mbti != nil { resp["mbti"] = user.Mbti }
if user.Region != nil { resp["region"] = user.Region }
if user.Industry != nil { resp["industry"] = user.Industry }
if user.Position != nil { resp["position"] = user.Position }
if user.BusinessScale != nil { resp["businessScale"] = user.BusinessScale }
if user.Skills != nil { resp["skills"] = user.Skills }
if user.StoryBestMonth != nil { resp["storyBestMonth"] = user.StoryBestMonth }
if user.StoryAchievement != nil { resp["storyAchievement"] = user.StoryAchievement }
if user.StoryTurning != nil { resp["storyTurning"] = user.StoryTurning }
if user.HelpOffer != nil { resp["helpOffer"] = user.HelpOffer }
if user.HelpNeed != nil { resp["helpNeed"] = user.HelpNeed }
if user.ProjectIntro != nil { resp["projectIntro"] = user.ProjectIntro }
c.JSON(http.StatusOK, gin.H{"success": true, "data": resp})
}
@@ -308,9 +306,28 @@ func UserProfilePost(c *gin.Context) {
}
updates["updated_at"] = time.Now()
db.Model(&user).Updates(updates)
c.JSON(http.StatusOK, gin.H{"success": true, "message": "资料更新成功", "data": gin.H{
"id": user.ID, "nickname": body.Nickname, "avatar": body.Avatar, "phone": body.Phone, "wechatId": body.WechatID, "referralCode": user.ReferralCode,
}})
// 重新查询并返回与 GET 一致的完整资料结构,空值统一为 ""
profileCols := []string{"id", "open_id", "nickname", "avatar", "phone", "wechat_id", "referral_code", "created_at",
"mbti", "region", "industry", "position", "business_scale", "skills",
"story_best_month", "story_achievement", "story_turning", "help_offer", "help_need", "project_intro"}
if err := database.DB().Select(profileCols).Where("id = ?", user.ID).First(&user).Error; err == nil {
str := func(p *string) interface{} { if p != nil { return *p }; return "" }
resp := gin.H{
"id": user.ID, "openId": user.OpenID, "nickname": str(user.Nickname), "avatar": str(user.Avatar),
"phone": str(user.Phone), "wechatId": str(user.WechatID), "referralCode": user.ReferralCode,
"createdAt": user.CreatedAt,
"mbti": str(user.Mbti), "region": str(user.Region), "industry": str(user.Industry),
"position": str(user.Position), "businessScale": str(user.BusinessScale), "skills": str(user.Skills),
"storyBestMonth": str(user.StoryBestMonth), "storyAchievement": str(user.StoryAchievement),
"storyTurning": str(user.StoryTurning), "helpOffer": str(user.HelpOffer), "helpNeed": str(user.HelpNeed),
"projectIntro": str(user.ProjectIntro),
}
c.JSON(http.StatusOK, gin.H{"success": true, "message": "资料更新成功", "data": resp})
} else {
c.JSON(http.StatusOK, gin.H{"success": true, "message": "资料更新成功", "data": gin.H{
"id": user.ID, "nickname": body.Nickname, "avatar": body.Avatar, "phone": body.Phone, "wechatId": body.WechatID, "referralCode": user.ReferralCode,
}})
}
}
// UserPurchaseStatus GET /api/user/purchase-status?userId=