From 90d4b959a1af69b3735541ffbd48d47cd49e178f Mon Sep 17 00:00:00 2001 From: Echo <1711788888@qq.com> Date: Tue, 12 Aug 2025 16:24:11 +0800 Subject: [PATCH] =?UTF-8?q?:art:=20=20=E6=96=B0=E5=A2=9E=E7=94=A8=E6=88=B7?= =?UTF-8?q?=E7=AE=80=E4=BB=8B=E5=AD=97=E6=AE=B5=EF=BC=8C=E6=96=B0=E5=A2=9E?= =?UTF-8?q?=E6=89=8B=E6=9C=BA=E7=AB=AF=E8=AE=B2=E5=B8=88=E7=9B=B8=E5=85=B3?= =?UTF-8?q?=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- api/v1/app/user.go | 28 ++++++++++++++++++++++++++++ model/app/vo/user.go | 7 +++++++ model/user/user.go | 1 + router/app/user.go | 3 ++- service/app/user.go | 23 +++++++++++++++++++++++ 5 files changed, 61 insertions(+), 1 deletion(-) diff --git a/api/v1/app/user.go b/api/v1/app/user.go index 20378e9..529a689 100644 --- a/api/v1/app/user.go +++ b/api/v1/app/user.go @@ -3,6 +3,7 @@ package app import ( "errors" "fmt" + common "git.echol.cn/loser/lckt/model/common/request" "strconv" "time" @@ -361,3 +362,30 @@ func (a *AppUserApi) BindPhone(context *gin.Context) { r.OkWithDetailed(user, "绑定手机号成功", context) } + +// -----------------讲师相关--------------------- + +// GetTeacherList 获取讲师列表 +func (a *AppUserApi) GetTeacherList(context *gin.Context) { + var p common.PageInfo + if err := context.ShouldBind(&p); err != nil { + global.GVA_LOG.Error("参数错误,获取讲师列表失败", zap.Error(err)) + r.FailWithMessage("参数错误,获取讲师列表失败", context) + return + } + + teachers, total, err := appUserService.GetTeacherList(p) + if err != nil { + global.GVA_LOG.Error("获取讲师列表失败", zap.Error(err)) + r.FailWithMessage("获取讲师列表失败", context) + return + } + + r.OkWithDetailed( + r.PageResult{ + List: teachers, + Total: total, + Page: p.Page, + PageSize: p.PageSize, + }, "获取讲师列表成功", context) +} diff --git a/model/app/vo/user.go b/model/app/vo/user.go index 9d9c810..86e660a 100644 --- a/model/app/vo/user.go +++ b/model/app/vo/user.go @@ -15,3 +15,10 @@ type UserInfo struct { IsVip int8 `json:"is_vip" form:"is_vip"` //是否是VIP 0 否 1 是 VipExpireTime string `json:"vip_expire_time" form:"vip_expire_time"` // VIP过期时间 } + +type TeacherInfo struct { + ID uint `json:"id" form:"id"` + NickName string `json:"nick_name" form:"nick_name"` + Avatar string `json:"avatar" form:"avatar"` + Des string `json:"des" form:"des"` +} diff --git a/model/user/user.go b/model/user/user.go index 7b6c716..0591b6b 100644 --- a/model/user/user.go +++ b/model/user/user.go @@ -6,6 +6,7 @@ type User struct { global.GVA_MODEL NickName string `json:"nick_name" form:"nick_name" gorm:"comment:用户昵称"` Phone string `json:"phone" form:"phone" gorm:"comment:用户手机号"` + Des string `json:"des" form:"des" gorm:"comment:用户描述"` UnionId string `json:"union_id" form:"union_id" gorm:"type:varchar(255) comment '微信UnionId'"` OpenId string `gorm:"column:open_id;default:'';comment:'openId'" json:"-"` Password string `json:"password" form:"password" gorm:"comment:用户密码"` diff --git a/router/app/user.go b/router/app/user.go index a8cef60..0946c9a 100644 --- a/router/app/user.go +++ b/router/app/user.go @@ -13,7 +13,8 @@ func (s *UserRouter) InitAppUserRouter(AppAuthGroup, PublicRouter *gin.RouterGro appUserRouter.GET("/info", userApi.GetUserInfo) // 获取用户信息 //申请成为讲师 appUserRouter.POST("/applyTeacher", userApi.ApplyTeacher) // 申请成为讲师 - appUserRouter.GET("/applyTeacher", userApi.GetTeacherApply) // 获取教师列表 + appUserRouter.GET("/applyTeacher", userApi.GetTeacherApply) // 获取教师申请状态 + appUserRouter.GET("/teachers", userApi.GetTeacherList) // 获取讲师列表 } { publicRouter.POST("wxLogin", userApi.WechatLogin) // 微信登录 diff --git a/service/app/user.go b/service/app/user.go index ac74208..16df799 100644 --- a/service/app/user.go +++ b/service/app/user.go @@ -5,6 +5,7 @@ import ( "git.echol.cn/loser/lckt/global" "git.echol.cn/loser/lckt/model/app" "git.echol.cn/loser/lckt/model/app/vo" + common "git.echol.cn/loser/lckt/model/common/request" "git.echol.cn/loser/lckt/model/user" "git.echol.cn/loser/lckt/model/user/request" utils2 "git.echol.cn/loser/lckt/utils" @@ -221,3 +222,25 @@ func (u *AppUserService) BindPhone(p request.BindPhoneReq) (*user.User, error) { return &userInfo, nil } + +func (u *AppUserService) GetTeacherList(p common.PageInfo) (list []vo.TeacherInfo, total int64, err error) { + limit := p.PageSize + offset := (p.Page - 1) * p.PageSize + db := global.GVA_DB.Model(&user.User{}).Where("user_type = ?", 2) + + if p.Keyword != "" { + db = db.Where("nick_name LIKE ?", "%"+p.Keyword+"%") + } + + err = db.Count(&total).Error + if err != nil { + global.GVA_LOG.Error("查询教师总数失败", zap.Error(err)) + return nil, 0, err + } + err = db.Limit(limit).Offset(offset).Select("id, nick_name, avatar,des").Find(&list).Error + if err != nil { + global.GVA_LOG.Error("查询教师列表失败", zap.Error(err)) + return nil, 0, err + } + return +}