接口参数与返回值调整
This commit is contained in:
parent
465ed0fe59
commit
eac96374bd
@ -23,8 +23,8 @@ func NewAppUserInfoController(logger *zap.Logger, q *query.Query) *AppUserInfo {
|
||||
func (ctl *AppUserInfo) SetAppAccount(c *gin.Context) {
|
||||
var req struct {
|
||||
ID uint64 `gorm:"column:id;type:bigint unsigned;primaryKey;autoIncrement:true" json:"id" binding:"required"`
|
||||
Nickname string `gorm:"column:nickname;type:varchar(255);not null;comment:昵称" json:"nickname" binding:"required"` // 昵称
|
||||
ImageURL string `gorm:"column:image_url;type:varchar(255);not null;comment:头像" json:"image_url" binding:"required"` // 头像
|
||||
Nickname string `gorm:"column:nickname;type:varchar(255);not null;comment:昵称" json:"nickname" binding:"required"` // 昵称
|
||||
Avatar string `gorm:"column:avatar;type:varchar(255);not null;comment:头像" json:"avatar" binding:"required"` // 头像
|
||||
}
|
||||
|
||||
if err := c.ShouldBind(&req); err != nil {
|
||||
@ -33,7 +33,7 @@ func (ctl *AppUserInfo) SetAppAccount(c *gin.Context) {
|
||||
return
|
||||
}
|
||||
|
||||
if err := ctl.appUser.UpdateUserNickNameAndImageUrl(c, req.ID, req.Nickname, req.ImageURL); err != nil {
|
||||
if err := ctl.appUser.UpdateUserNickNameAndImageUrl(c, req.ID, req.Nickname, req.Avatar); err != nil {
|
||||
ctl.logger.Sugar().Error(err)
|
||||
ctl.ResponseErr(c, err)
|
||||
return
|
||||
|
@ -72,14 +72,25 @@ func NewDouyinOpenApiController(logger *zap.Logger, q *query.Query) *DouyinOpenA
|
||||
func (ctl *DouyinOpenApiController) GetEcpm(c *gin.Context) {
|
||||
var req struct {
|
||||
AppId string `json:"app_id" form:"app_id"`
|
||||
OpenId string `json:"open_id" form:"open_id"`
|
||||
UserId uint64 `json:"user_id" form:"user_id"`
|
||||
}
|
||||
if err := c.ShouldBind(&req); err != nil {
|
||||
c.JSON(http.StatusOK, false)
|
||||
return
|
||||
}
|
||||
|
||||
res, err := ctl.douyinCli.GetEcpmData(req.AppId, req.OpenId, time.Now().Format(time.DateOnly))
|
||||
userInfo, err := ctl.appUser.GetUserById(c, req.UserId)
|
||||
if err != nil {
|
||||
ctl.logger.Error(err.Error())
|
||||
c.JSON(http.StatusOK, false)
|
||||
}
|
||||
|
||||
if userInfo == nil {
|
||||
c.JSON(http.StatusOK, false)
|
||||
return
|
||||
}
|
||||
|
||||
res, err := ctl.douyinCli.GetEcpmData(req.AppId, userInfo.Openid, time.Now().Format(time.DateOnly))
|
||||
if err != nil {
|
||||
ctl.logger.Sugar().Error("获取ecpm失败", err)
|
||||
c.JSON(http.StatusOK, false)
|
||||
@ -139,17 +150,18 @@ func (ctl *DouyinOpenApiController) Code2OpenId(c *gin.Context) {
|
||||
return
|
||||
}
|
||||
|
||||
err = ctl.appUser.SaveUserInfoByRes(c, &model.AppUserInfo{
|
||||
aui := &model.AppUserInfo{
|
||||
AppAccountID: accountId,
|
||||
Openid: res.Openid,
|
||||
Unionid: res.Unionid,
|
||||
AnonymousOpenid: res.AnonymousOpenid,
|
||||
})
|
||||
}
|
||||
err = ctl.appUser.SaveUserInfoByRes(c, aui)
|
||||
|
||||
if err != nil {
|
||||
ctl.ResponseErr(c, err)
|
||||
return
|
||||
}
|
||||
|
||||
c.String(http.StatusOK, res.Openid)
|
||||
c.JSON(http.StatusOK, gin.H{"userId": aui.ID})
|
||||
}
|
||||
|
@ -89,16 +89,19 @@ func (ctl *WechatOpenApiController) Code2OpenId(c *gin.Context) {
|
||||
return
|
||||
}
|
||||
|
||||
err = ctl.appUser.SaveUserInfoByRes(c, &model.AppUserInfo{
|
||||
aui := &model.AppUserInfo{
|
||||
AppAccountID: accountId,
|
||||
Openid: res.OpenID,
|
||||
Unionid: res.UnionID,
|
||||
})
|
||||
}
|
||||
err = ctl.appUser.SaveUserInfoByRes(c, aui)
|
||||
|
||||
if err != nil {
|
||||
ctl.ResponseErr(c, err)
|
||||
return
|
||||
}
|
||||
|
||||
c.String(http.StatusOK, res.OpenID)
|
||||
c.JSON(http.StatusOK, gin.H{
|
||||
"user_id": aui.ID,
|
||||
})
|
||||
}
|
||||
|
@ -58,12 +58,15 @@ func (s *HttpServer) Run() {
|
||||
}
|
||||
|
||||
func InitRouter(r *gin.Engine, logger *zap.Logger, q *query.Query) {
|
||||
douyinCtl := controller.NewDouyinOpenApiController(logger, q)
|
||||
r.GET("/get-ecpm", douyinCtl.GetEcpm)
|
||||
r.GET("/code2openId", douyinCtl.Code2OpenId)
|
||||
{
|
||||
douyinCtl := controller.NewDouyinOpenApiController(logger, q)
|
||||
g := r.Group("/douyin")
|
||||
g.GET("/get_ecpm", douyinCtl.GetEcpm)
|
||||
g.GET("/code2userId", douyinCtl.Code2OpenId)
|
||||
}
|
||||
|
||||
appUserCtl := controller.NewAppUserInfoController(logger, q)
|
||||
r.POST("/app_user_info/SetAppAccount", appUserCtl.SetAppAccount)
|
||||
r.POST("/app_user_info/set_app_account", appUserCtl.SetAppAccount)
|
||||
|
||||
{
|
||||
rankingCtl := controller.NewRankingList(logger, q)
|
||||
@ -75,7 +78,7 @@ func InitRouter(r *gin.Engine, logger *zap.Logger, q *query.Query) {
|
||||
{
|
||||
wechatCtl := controller.NewWechatOpenApiController(logger, q)
|
||||
g := r.Group("/wechat")
|
||||
g.GET("/code2openId", wechatCtl.Code2OpenId)
|
||||
g.GET("/code2userId", wechatCtl.Code2OpenId)
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -3,6 +3,7 @@ package service
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"github.com/gin-gonic/gin"
|
||||
"gorm.io/gorm"
|
||||
"youtu_ecpm/dao/model"
|
||||
"youtu_ecpm/dao/query"
|
||||
@ -34,3 +35,7 @@ func (a *AppUserInfo) UpdateUserNickNameAndImageUrl(ctx context.Context, id uint
|
||||
_, err = a.q.AppUserInfo.WithContext(ctx).Where(a.q.AppUserInfo.ID.Eq(id)).Updates(&model.AppUserInfo{ID: id, Nickname: nickname, Avatar: url})
|
||||
return
|
||||
}
|
||||
|
||||
func (a *AppUserInfo) GetUserById(c *gin.Context, id uint64) (*model.AppUserInfo, error) {
|
||||
return a.q.AppUserInfo.WithContext(c).Where(a.q.AppUserInfo.ID.Eq(id)).Take()
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user