1 Star 0 Fork 1K

高煜涛/福墩

forked from pixel/gin-vue-admin 
加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
user.go 7.83 KB
一键复制 编辑 原始数据 按行查看 历史
高煜涛 提交于 2024-11-25 11:46 +08:00 . 24/11/25
package user
import (
"context"
"fmt"
"gitee.com/g-qs/fudun/server/global"
"gitee.com/g-qs/fudun/server/model/common/response"
userReq "gitee.com/g-qs/fudun/server/model/user/request"
userRes "gitee.com/g-qs/fudun/server/model/user/response"
"gitee.com/g-qs/fudun/server/utils"
"github.com/gin-gonic/gin"
"go.uber.org/zap"
"strconv"
)
type UserApi struct {
}
// GetUserData 获取用户信息
// @Tags User
// @Summary 用id查询用户
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Param data query user.User true "用id查询用户"
// @Success 200 {string} string "{"success":true,"data":{},"msg":"查询成功"}"
// @Router /api/user/getUserDate [get]
func (u *UserApi) GetUserData(c *gin.Context) {
uuid := utils.GetUserUuid(c)
if ResUser, err := UserService.GetUserInfo(uuid); err != nil {
global.GVA_LOG.Error("查询失败!", zap.Error(err))
response.FailWithMessage("查询失败", c)
} else {
response.OkWithDetailed(ResUser, "获取成功", c)
}
}
// UpdateUser 更新User
// @Tags User
// @Summary 更新User
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Param data body user.user true "更新User"
// @Success 200 {string} string "{"success":true,"data":{},"msg":"更新成功"}"
// @Router /api/user/updateUser [put]
func (u *UserApi) UpdateUser(c *gin.Context) {
var us userReq.UpdateUser
id := utils.GetUserID(c)
err := c.ShouldBindJSON(&us)
if err != nil {
response.FailWithMessage(err.Error(), c)
return
}
if us.Avatar != "" {
a := utils.CreateAudit(global.GVA_CONFIG.Audit.Objs)
AvatarStatus, _ := a.AuditImageUrl(us.Avatar)
if AvatarStatus == false {
response.FailWithMessage("图片违规,请重新上传", c)
return
}
}
if err := UserService.UpdateUser(id, us); err != nil {
global.GVA_LOG.Error("更新失败!", zap.Error(err))
response.FailWithMessage("更新失败", c)
} else {
err = UserService.AddPoints(id, 10, 5)
response.OkWithMessage("更新成功", c)
}
}
// GetUserInviteLink 获取邀请链接
// @Tags User
// @Summary 获取邀请链接
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Param data query user.User true "获取邀请链接"
// @Success 200 {string} string "{"success":true,"data":{},"msg":"获取成功"}"
// @Router /api/user/getInviteLink [post]
func (u *UserApi) GetUserInviteLink(c *gin.Context) {
uuid := utils.GetUserUuid(c)
userId := utils.GetUserID(c)
// 获取系统配置参数
config, _ := appConfigService.GetRedisByField([]string{"version_num", "app_url", "customer_service_wechat"})
// 获取统计数据
CountData, _ := appConfigService.GetCountRedis([]string{"users_total", "pv_total"})
usersTotal, _ := strconv.ParseFloat(CountData["users_total"].(string), 64)
heat := fmt.Sprintf("%.2f", usersTotal)
//usersTotal := CountData["users_total"]
pvTotal, _ := strconv.ParseUint(CountData["pv_total"].(string), 10, 0)
// 获取未读消息数
UnReadMessageNumber, _ := MessageService.GetUnReadMessageNumber(userId)
if user, err := UserService.GetUserInfo(uuid); err != nil {
global.GVA_LOG.Error("获取失败!", zap.Error(err))
response.FailWithMessage("获取用户信息失败!", c)
} else {
response.OkWithDetailed(userRes.InviteLinkResponse{
StewardID: user.StewardID,
ID: user.ID,
Heat: heat,
UsersNumber: uint(pvTotal),
UnReadMessageNumber: uint(UnReadMessageNumber),
CustomerServiceWechat: config["customer_service_wechat"],
AppUrl: config["app_url"],
VersionNum: config["version_num"],
}, "获取成功", c)
}
}
// ChangePassword 用户修改密码
// @Tags User
// @Summary 用户修改密码
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Param data query user.User true "用id查询用户"
// @Success 200 {string} string "{"success":true,"data":{},"msg":"查询成功"}"
// @Router /api/user/changePassword [post]
func (u *UserApi) ChangePassword(c *gin.Context) {
var uc userReq.ChangePassword
err := c.ShouldBindJSON(&uc)
if err != nil {
response.FailWithMessage(err.Error(), c)
return
}
// 判断两次密码是否相同
if uc.Password != uc.NewPassword {
response.FailWithMessage("新密码与确认密码不同", c)
return
}
id := utils.GetUserID(c)
userInfo, _ := UserService.FindUserByID(id)
// 判断短信验证码
key := "Sms:Phone:Code:" + userInfo.Phone
captcha, _ := global.GVA_REDIS.Get(context.Background(), key).Result()
if captcha != uc.Code {
response.Result(200, "", "验证码有误,请核实!", c)
return
}
err = UserService.ChangePassword(id, uc.NewPassword)
if err != nil {
global.GVA_LOG.Error("修改失败!", zap.Error(err))
response.FailWithMessage("修改失败", c)
return
}
response.OkWithMessage("修改成功", c)
}
// MyThoughts 我的心得
// @Tags User
// @Summary 我的心得
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Success 200 {string} string "{"success":true,"data":{},"msg":"查询成功"}"
// @Router /user/myThoughts [get]
func (u *UserApi) MyThoughts(c *gin.Context) {
id := utils.GetUserID(c)
if list, err := CircleService.GetCircleInfoListByUid(id); err != nil {
global.GVA_LOG.Error("获取失败!", zap.Error(err))
response.FailWithMessage("获取失败", c)
} else {
response.Result(200, list, "获取成功", c)
}
}
// SubmitOpenVip 提交开通&续费会员
// @Tags User
// @Summary 提交开通&续费会员
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Success 200 {string} string "{"success":true,"data":{},"msg":"查询成功"}"
// @Router /user/submitOpenVip [get]
func (u *UserApi) SubmitOpenVip(c *gin.Context) {
id := utils.GetUserID(c)
// 查询是否存在待审核申请
record, _ := UserService.FindLastRecordByWhere(id)
if int(record.Status) == 1 || int(record.Status) == 3 {
response.Result(200, "", "存在未通过审核的申请,请联系客服!", c)
return
}
if err := UserService.CreateOpenRecord(id); err != nil {
global.GVA_LOG.Error("获取失败!", zap.Error(err))
response.FailWithMessage("申请失败", c)
} else {
response.Result(200, "", "申请成功", c)
}
}
// GetUserByVipLevel 根据会员等级获取用户信息示例
func (u *UserApi) GetUserByVipLevel(c *gin.Context) {
vip_type := c.Query("vip_type")
if err := UserService.GetUserByVipLevel(vip_type); err != nil {
global.GVA_LOG.Error("获取失败!", zap.Error(err))
response.FailWithMessage("申请失败", c)
} else {
response.Result(200, "", "申请成功", c)
}
}
// GetUserDivisionInfo 获取用户成就信息
func (u *UserApi) GetUserDivisionInfo(c *gin.Context) {
id := utils.GetUserID(c)
info, err := UserService.GetUserDivisionInfo(id)
if err != nil {
global.GVA_LOG.Error("获取失败!", zap.Error(err))
response.FailWithMessage("获取失败", c)
} else {
response.Result(200, info, "获取成功", c)
}
}
// GetUserDivisionRank 获取用户段位排行榜
func (u *UserApi) GetUserDivisionRank(c *gin.Context) {
rank, err := UserService.GetUserDivisionRank()
if err != nil {
global.GVA_LOG.Error("获取失败!", zap.Error(err))
response.FailWithMessage("获取失败", c)
} else {
response.Result(200, rank, "获取成功", c)
}
}
// GetCountWeeklyPoints 获取用户一周积分
func (u *UserApi) GetCountWeeklyPoints(c *gin.Context) {
userID := utils.GetUserID(c)
data, err := UserService.GetCountWeeklyPoints(userID)
if err != nil {
global.GVA_LOG.Error("获取失败!", zap.Error(err))
response.FailWithMessage("获取失败", c)
} else {
response.Result(200, data, "获取成功", c)
}
}
// TranslateTable 迁移用户数据
func (u *UserApi) TranslateTable(c *gin.Context) {
go func() {
_ = UserService.TranslateTable()
fmt.Print("携程内运行转移操作")
}()
response.Result(200, "", "携程内运行转移操作", c)
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/g-qs/fudun.git
git@gitee.com:g-qs/fudun.git
g-qs
fudun
福墩
36c3b20778a1

搜索帮助