Merge branch 'yongxu-dev' into devlop
# Conflicts: # miniprogram/pages/profile-edit/profile-edit.js # miniprogram/pages/profile-edit/profile-edit.wxml # miniprogram/pages/settings/settings.js # miniprogram/utils/ruleEngine.js # soul-admin/src/pages/distribution/DistributionPage.tsx # soul-admin/src/pages/users/UsersPage.tsx # soul-api/.env.production # soul-api/.gitignore # soul-api/internal/handler/db_ckb_leads.go # soul-api/internal/handler/miniprogram.go # soul-api/internal/handler/referral.go # 开发文档/1、需求/archive/链接人与事-存客宝同步-需求规划.md # 开发文档/1、需求/archive/链接人与事-实现方案.md
This commit is contained in:
@@ -5,14 +5,59 @@ import (
|
||||
"fmt"
|
||||
"net/http"
|
||||
"strconv"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"soul-api/internal/config"
|
||||
"soul-api/internal/database"
|
||||
"soul-api/internal/model"
|
||||
"soul-api/internal/oss"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
)
|
||||
|
||||
// avatarToPath 从头像 URL 提取路径(不含域名),用于保存到 DB
|
||||
func avatarToPath(s string) string {
|
||||
s = strings.TrimSpace(s)
|
||||
if s == "" {
|
||||
return s
|
||||
}
|
||||
if idx := strings.Index(s, "/uploads/"); idx >= 0 {
|
||||
return s[idx:]
|
||||
}
|
||||
if strings.HasPrefix(s, "/") {
|
||||
return s
|
||||
}
|
||||
return s
|
||||
}
|
||||
|
||||
// resolveAvatarURL 将路径解析为完整可访问 URL(返回时使用)
|
||||
func resolveAvatarURL(s string) string {
|
||||
s = strings.TrimSpace(s)
|
||||
if s == "" {
|
||||
return s
|
||||
}
|
||||
// 已是完整 URL,直接返回
|
||||
if strings.HasPrefix(s, "http://") || strings.HasPrefix(s, "https://") {
|
||||
return s
|
||||
}
|
||||
path := s
|
||||
if !strings.HasPrefix(path, "/") {
|
||||
path = "/" + path
|
||||
}
|
||||
// OSS 存储:用 OSS 公网 URL
|
||||
if oss.IsEnabled() {
|
||||
if u := oss.PublicURL(path); u != "" {
|
||||
return u
|
||||
}
|
||||
}
|
||||
// 本地存储:用 BaseURL 拼接
|
||||
if cfg := config.Get(); cfg != nil && cfg.BaseURL != "" {
|
||||
return cfg.BaseURLJoin(path)
|
||||
}
|
||||
return path
|
||||
}
|
||||
|
||||
// UserAddressesGet GET /api/user/addresses?userId=
|
||||
func UserAddressesGet(c *gin.Context) {
|
||||
userId := c.Query("userId")
|
||||
@@ -243,8 +288,9 @@ func UserProfileGet(c *gin.Context) {
|
||||
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 "" }
|
||||
avatarVal := resolveAvatarURL(str(user.Avatar).(string))
|
||||
resp := gin.H{
|
||||
"id": user.ID, "openId": user.OpenID, "nickname": str(user.Nickname), "avatar": str(user.Avatar),
|
||||
"id": user.ID, "openId": user.OpenID, "nickname": str(user.Nickname), "avatar": avatarVal,
|
||||
"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,
|
||||
@@ -311,7 +357,7 @@ func UserProfilePost(c *gin.Context) {
|
||||
updates["nickname"] = *body.Nickname
|
||||
}
|
||||
if body.Avatar != nil {
|
||||
updates["avatar"] = *body.Avatar
|
||||
updates["avatar"] = avatarToPath(*body.Avatar)
|
||||
}
|
||||
if body.Phone != nil {
|
||||
updates["phone"] = *body.Phone
|
||||
@@ -343,8 +389,9 @@ func UserProfilePost(c *gin.Context) {
|
||||
"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 "" }
|
||||
avatarVal := resolveAvatarURL(str(user.Avatar).(string))
|
||||
resp := gin.H{
|
||||
"id": user.ID, "openId": user.OpenID, "nickname": str(user.Nickname), "avatar": str(user.Avatar),
|
||||
"id": user.ID, "openId": user.OpenID, "nickname": str(user.Nickname), "avatar": avatarVal,
|
||||
"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),
|
||||
@@ -355,8 +402,12 @@ func UserProfilePost(c *gin.Context) {
|
||||
}
|
||||
c.JSON(http.StatusOK, gin.H{"success": true, "message": "资料更新成功", "data": resp})
|
||||
} else {
|
||||
avatarVal := ""
|
||||
if body.Avatar != nil {
|
||||
avatarVal = resolveAvatarURL(avatarToPath(*body.Avatar))
|
||||
}
|
||||
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,
|
||||
"id": user.ID, "nickname": body.Nickname, "avatar": avatarVal, "phone": body.Phone, "wechatId": body.WechatID, "referralCode": user.ReferralCode,
|
||||
}})
|
||||
}
|
||||
}
|
||||
@@ -694,7 +745,7 @@ func UserUpdate(c *gin.Context) {
|
||||
updates["nickname"] = *body.Nickname
|
||||
}
|
||||
if body.Avatar != nil {
|
||||
updates["avatar"] = *body.Avatar
|
||||
updates["avatar"] = avatarToPath(*body.Avatar)
|
||||
}
|
||||
if body.Phone != nil {
|
||||
updates["phone"] = *body.Phone
|
||||
|
||||
Reference in New Issue
Block a user