feat(bazi): 八字页重构——空态示例排盘+字段术语表+文化声明,生辰档案绑定
- 八字页:未绑定生辰时展示虚构示例排盘(1990-08-08 10:30男)与15条字段说明, 附传统文化声明文案;已绑定时支持多档案切换,排盘增强(十神/藏干/纳音/五行配色/命盘概览) - 个人中心:新增生辰管理卡片,每用户免费绑定3个出生年月;登录改为真实微信登录 - 服务端:新增 BirthProfile 模型与 /api/user/birth-profiles 增删查接口,AutoMigrate 建表 - 前端:新增 birth-profile.js 本地存储优先+登录后云端双向同步 - 修复:个人中心 tabBar 页面入口误用 navigateTo 改为 switchTab
This commit is contained in:
@@ -6,6 +6,7 @@ import (
|
||||
"io"
|
||||
"net/http"
|
||||
"net/url"
|
||||
"strconv"
|
||||
"time"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
@@ -283,6 +284,111 @@ func UpdateUserProfile(c *gin.Context) {
|
||||
})
|
||||
}
|
||||
|
||||
// GetBirthProfiles 获取当前用户的生辰档案列表
|
||||
func GetBirthProfiles(c *gin.Context) {
|
||||
userID, exists := c.Get("userID")
|
||||
if !exists {
|
||||
c.JSON(http.StatusUnauthorized, gin.H{"code": 401, "msg": "未授权"})
|
||||
return
|
||||
}
|
||||
|
||||
userService := service.NewUserService()
|
||||
profiles, err := userService.ListBirthProfiles(userID.(uint))
|
||||
if err != nil {
|
||||
c.JSON(http.StatusInternalServerError, gin.H{"code": 500, "msg": "获取生辰档案失败"})
|
||||
return
|
||||
}
|
||||
|
||||
c.JSON(http.StatusOK, gin.H{
|
||||
"code": 0,
|
||||
"msg": "success",
|
||||
"data": gin.H{
|
||||
"profiles": profiles,
|
||||
"maxFree": model.MaxFreeBirthProfiles,
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
// CreateBirthProfile 新增生辰档案(每用户免费上限 MaxFreeBirthProfiles 个)
|
||||
func CreateBirthProfile(c *gin.Context) {
|
||||
userID, exists := c.Get("userID")
|
||||
if !exists {
|
||||
c.JSON(http.StatusUnauthorized, gin.H{"code": 401, "msg": "未授权"})
|
||||
return
|
||||
}
|
||||
|
||||
var req struct {
|
||||
Name string `json:"name"`
|
||||
Gender int `json:"gender"`
|
||||
Birthday string `json:"birthday" binding:"required"`
|
||||
BirthTime string `json:"birthTime" binding:"required"`
|
||||
}
|
||||
if err := c.ShouldBindJSON(&req); err != nil {
|
||||
c.JSON(http.StatusBadRequest, gin.H{"code": 400, "msg": "参数错误"})
|
||||
return
|
||||
}
|
||||
|
||||
// 简单格式校验
|
||||
if _, err := time.Parse("2006-01-02", req.Birthday); err != nil {
|
||||
c.JSON(http.StatusBadRequest, gin.H{"code": 400, "msg": "出生日期格式错误"})
|
||||
return
|
||||
}
|
||||
if _, err := time.Parse("15:04", req.BirthTime); err != nil {
|
||||
c.JSON(http.StatusBadRequest, gin.H{"code": 400, "msg": "出生时间格式错误"})
|
||||
return
|
||||
}
|
||||
if req.Gender != 1 && req.Gender != 2 {
|
||||
req.Gender = 1
|
||||
}
|
||||
|
||||
profile := &model.BirthProfile{
|
||||
UserID: userID.(uint),
|
||||
Name: req.Name,
|
||||
Gender: req.Gender,
|
||||
Birthday: req.Birthday,
|
||||
BirthTime: req.BirthTime,
|
||||
}
|
||||
|
||||
userService := service.NewUserService()
|
||||
if err := userService.CreateBirthProfile(profile); err != nil {
|
||||
if err == service.ErrBirthProfileLimit {
|
||||
c.JSON(http.StatusForbidden, gin.H{"code": 403, "msg": err.Error()})
|
||||
return
|
||||
}
|
||||
c.JSON(http.StatusInternalServerError, gin.H{"code": 500, "msg": "新增生辰档案失败"})
|
||||
return
|
||||
}
|
||||
|
||||
c.JSON(http.StatusOK, gin.H{
|
||||
"code": 0,
|
||||
"msg": "success",
|
||||
"data": gin.H{"profile": profile},
|
||||
})
|
||||
}
|
||||
|
||||
// DeleteBirthProfile 删除生辰档案(仅限本人)
|
||||
func DeleteBirthProfile(c *gin.Context) {
|
||||
userID, exists := c.Get("userID")
|
||||
if !exists {
|
||||
c.JSON(http.StatusUnauthorized, gin.H{"code": 401, "msg": "未授权"})
|
||||
return
|
||||
}
|
||||
|
||||
id, err := strconv.ParseUint(c.Param("id"), 10, 64)
|
||||
if err != nil {
|
||||
c.JSON(http.StatusBadRequest, gin.H{"code": 400, "msg": "参数错误"})
|
||||
return
|
||||
}
|
||||
|
||||
userService := service.NewUserService()
|
||||
if err := userService.DeleteBirthProfile(uint(id), userID.(uint)); err != nil {
|
||||
c.JSON(http.StatusInternalServerError, gin.H{"code": 500, "msg": "删除生辰档案失败"})
|
||||
return
|
||||
}
|
||||
|
||||
c.JSON(http.StatusOK, gin.H{"code": 0, "msg": "success"})
|
||||
}
|
||||
|
||||
// WechatAuth 微信授权(仅返回 openid,session_key 属敏感凭证不下发)
|
||||
func WechatAuth(c *gin.Context) {
|
||||
var req struct {
|
||||
|
||||
Reference in New Issue
Block a user