forked from all_user/stat_center
241 lines
6.9 KiB
Go
241 lines
6.9 KiB
Go
package channelApi
|
|
|
|
import (
|
|
"fmt"
|
|
"net/http"
|
|
"path/filepath"
|
|
"stat/api/proto"
|
|
"stat/common/stdLog"
|
|
"stat/common/utils"
|
|
"stat/models/adminMod"
|
|
"stat/service/channelSer"
|
|
|
|
"github.com/gin-gonic/gin"
|
|
)
|
|
|
|
// @Tags 渠道管理
|
|
// @Summary 分组分页获取渠道管理
|
|
// @Description 分组分页获取渠道管理
|
|
// @Accept json
|
|
// @Produce json
|
|
// @Param param body proto.ChannelInfoSearch true "参数列表"
|
|
// @Success 200 {object} proto.ChannelInfoSearchResp "成功"
|
|
// @Failure 400 {string} string "获取失败的返回结果"
|
|
// @Security ApiKeyAuth
|
|
// @Router /api/stat/channelInfo/list [POST]
|
|
func GetChannelInfo(ctx *gin.Context) {
|
|
var req = &proto.ChannelInfoSearch{}
|
|
if err := ctx.ShouldBind(req); err != nil {
|
|
stdLog.ServerJSON(ctx, stdLog.ParamError, err)
|
|
return
|
|
}
|
|
resp, serr := channelSer.SearchChannelInfo(ctx, req)
|
|
if serr != nil {
|
|
stdLog.ServerJSON(ctx, stdLog.Failure, serr)
|
|
return
|
|
}
|
|
|
|
stdLog.ServerJSON(ctx, stdLog.Success, resp)
|
|
}
|
|
|
|
// @Tags 渠道管理
|
|
// @Summary 分组分页获取渠道列表导出
|
|
// @Description 分组分页获取渠道列表导出
|
|
// @Accept json
|
|
// @Produce json
|
|
// @Param param body proto.ChannelInfoSearch true "参数列表"
|
|
// @Success 200 {object} proto.ChannelInfoSearchResp "成功"
|
|
// @Failure 400 {string} string "获取失败的返回结果"
|
|
// @Security ApiKeyAuth
|
|
// @Router /api/stat/channelInfo/export [POST]
|
|
func GetChannelInfoExport(ctx *gin.Context) {
|
|
var req = &proto.ChannelInfoSearch{}
|
|
if err := ctx.ShouldBind(req); err != nil {
|
|
stdLog.ServerJSON(ctx, stdLog.ParamError, err)
|
|
return
|
|
}
|
|
fPath, serr := channelSer.SearchChannelInfoExport(ctx, req)
|
|
if serr != nil {
|
|
stdLog.ServerJSON(ctx, stdLog.Failure, serr)
|
|
return
|
|
}
|
|
ctx.Writer.WriteHeader(http.StatusOK)
|
|
ctx.Header("Content-Disposition", fmt.Sprintf("attachment; filename=%s", filepath.Base(fPath)))
|
|
ctx.Header("Content-Type", "application/octet-stream")
|
|
ctx.File(fPath)
|
|
}
|
|
|
|
// @Tags 渠道管理
|
|
// @Summary 添加一个渠道管理
|
|
// @Description 添加一个渠道管理
|
|
// @Accept json
|
|
// @Produce json
|
|
// @Param param body proto.ChannelInfoAdd true "参数列表"
|
|
// @Success 200 {string} string "成功"
|
|
// @Failure 400 {string} string "获取失败的返回结果"
|
|
// @Security ApiKeyAuth
|
|
// @Router /api/stat/channelInfo/add [POST]
|
|
func AddOneChannelInfo(ctx *gin.Context) {
|
|
var req = &proto.ChannelInfoAdd{}
|
|
if err := ctx.ShouldBind(req); err != nil {
|
|
stdLog.ServerJSON(ctx, stdLog.ParamError, err)
|
|
return
|
|
}
|
|
account, err := utils.GetAdmin(ctx)
|
|
if err != nil || account == "" {
|
|
stdLog.ServerJSON(ctx, stdLog.NoToken, err)
|
|
return
|
|
}
|
|
|
|
adminInfo, err := adminMod.FindOneByAccount(ctx, account)
|
|
if err != nil || adminInfo.Account == "" {
|
|
stdLog.ServerJSON(ctx, stdLog.AdminAccountNotExists, err)
|
|
return
|
|
}
|
|
|
|
resp, serr := channelSer.AddChannelInfo(ctx, adminInfo.Name, req)
|
|
if serr != nil {
|
|
stdLog.ServerJSON(ctx, stdLog.Failure, serr)
|
|
return
|
|
}
|
|
|
|
stdLog.ServerJSON(ctx, stdLog.Success, resp)
|
|
}
|
|
|
|
// @Tags 渠道管理
|
|
// @Summary 删除一个渠道管理
|
|
// @Description 删除一个渠道管理
|
|
// @Accept json
|
|
// @Produce json
|
|
// @Param param body proto.ChannelInfoDelete true "参数列表"
|
|
// @Failure 400 {string} string "获取失败的返回结果"
|
|
// @Security ApiKeyAuth
|
|
// @Router /api/stat/channelInfo/del [POST]
|
|
func DelOneChannelInfo(ctx *gin.Context) {
|
|
var req = &proto.ChannelInfoDelete{}
|
|
if err := ctx.ShouldBind(req); err != nil {
|
|
stdLog.ServerJSON(ctx, stdLog.ParamError, err)
|
|
return
|
|
}
|
|
serr := channelSer.DelChannelInfo(ctx, req.ID)
|
|
if serr != nil {
|
|
stdLog.ServerJSON(ctx, stdLog.Failure, serr)
|
|
return
|
|
}
|
|
|
|
stdLog.ServerJSON(ctx, stdLog.Success, "")
|
|
}
|
|
|
|
// @Tags 渠道管理
|
|
// @Summary 更新一个渠道管理
|
|
// @Description 更新一个渠道管理
|
|
// @Accept json
|
|
// @Produce json
|
|
// @Param param body proto.ChannelInfoUpdate true "参数列表"
|
|
// @Success 200 {string} string "成功"
|
|
// @Failure 400 {string} string "获取失败的返回结果"
|
|
// @Security ApiKeyAuth
|
|
// @Router /api/stat/channelInfo/update [POST]
|
|
func UpdateOneChannelInfo(ctx *gin.Context) {
|
|
var req = &proto.ChannelInfoUpdate{}
|
|
if err := ctx.ShouldBind(req); err != nil {
|
|
stdLog.ServerJSON(ctx, stdLog.ParamError, nil)
|
|
return
|
|
}
|
|
serr := channelSer.UpdateChannelInfo(ctx, req.ID, *req)
|
|
if serr != nil {
|
|
stdLog.ServerJSON(ctx, stdLog.Failure, serr)
|
|
return
|
|
}
|
|
|
|
stdLog.ServerJSON(ctx, stdLog.Success, "")
|
|
}
|
|
|
|
// @Tags 渠道管理
|
|
// @Summary 获取用户信息
|
|
// @Description 获取用户信息
|
|
// @Accept json
|
|
// @Produce json
|
|
// @Param param body proto.UserInfoSearch true "参数列表"
|
|
// @Success 200 {object} registermod.RegisterMod "成功"
|
|
// @Failure 400 {string} string "获取失败的返回结果"
|
|
// @Security ApiKeyAuth
|
|
// @Router /api/stat/user/info [POST]
|
|
func SearchUserInfo(ctx *gin.Context) {
|
|
var req = &proto.UserInfoSearch{}
|
|
if err := ctx.ShouldBind(req); err != nil {
|
|
stdLog.ServerJSON(ctx, stdLog.ParamError, err)
|
|
return
|
|
}
|
|
resp, serr := channelSer.SearchUserInfo(ctx, req)
|
|
if serr != nil {
|
|
stdLog.ServerJSON(ctx, stdLog.Failure, serr)
|
|
return
|
|
}
|
|
|
|
stdLog.ServerJSON(ctx, stdLog.Success, resp)
|
|
}
|
|
|
|
// @Tags 渠道管理
|
|
// @Summary 更新一个渠道管理的所有者
|
|
// @Description 更新一个渠道管理的所有者
|
|
// @Accept json
|
|
// @Produce json
|
|
// @Param param body proto.ChannelOwnerUpdate true "参数列表"
|
|
// @Success 200 {string} string "成功"
|
|
// @Failure 400 {string} string "获取失败的返回结果"
|
|
// @Security ApiKeyAuth
|
|
// @Router /api/stat/channelInfo/owner/update [POST]
|
|
func UpdateOneChannelOwner(ctx *gin.Context) {
|
|
var req = &proto.ChannelOwnerUpdate{}
|
|
if err := ctx.ShouldBind(req); err != nil {
|
|
stdLog.ServerJSON(ctx, stdLog.ParamError, nil)
|
|
return
|
|
}
|
|
|
|
account, err := utils.GetAdmin(ctx)
|
|
if err != nil || account == "" {
|
|
stdLog.ServerJSON(ctx, stdLog.NoToken, err)
|
|
return
|
|
}
|
|
|
|
adminInfo, err := adminMod.FindOneByAccount(ctx, account)
|
|
if err != nil || adminInfo.Account == "" {
|
|
stdLog.ServerJSON(ctx, stdLog.AdminAccountNotExists, err)
|
|
return
|
|
}
|
|
|
|
serr := channelSer.UpdateOneChannelOwner(ctx, adminInfo.Name, adminInfo.Account, *req)
|
|
if serr != nil {
|
|
stdLog.ServerJSON(ctx, stdLog.Failure, serr.Error())
|
|
return
|
|
}
|
|
|
|
stdLog.ServerJSON(ctx, stdLog.Success, "")
|
|
}
|
|
|
|
// @Tags 渠道管理
|
|
// @Summary 渠道所有者变更信息
|
|
// @Description 渠道所有者变更信息
|
|
// @Accept json
|
|
// @Produce json
|
|
// @Param param body proto.ChannelOwnerChangeInfoSearch true "参数列表"
|
|
// @Success 200 {object} proto.ChannelOwnerChangeInfoSearchResp "成功"
|
|
// @Failure 400 {string} string "获取失败的返回结果"
|
|
// @Security ApiKeyAuth
|
|
// @Router /api/stat/channelInfo/ownerchange/list [POST]
|
|
func SearchChannelOwnerChange(ctx *gin.Context) {
|
|
var req = &proto.ChannelOwnerChangeInfoSearch{}
|
|
if err := ctx.ShouldBind(req); err != nil {
|
|
stdLog.ServerJSON(ctx, stdLog.ParamError, err)
|
|
return
|
|
}
|
|
resp, serr := channelSer.SearchChannelOwnerChangeInfo(ctx, req)
|
|
if serr != nil {
|
|
stdLog.ServerJSON(ctx, stdLog.Failure, serr)
|
|
return
|
|
}
|
|
|
|
stdLog.ServerJSON(ctx, stdLog.Success, resp)
|
|
}
|