Files
stat_center/api/agentApi/agent.go
T
2026-05-20 16:13:58 +08:00

425 lines
11 KiB
Go

package agentApi
import (
"bytes"
"fmt"
"image/jpeg"
"stat/api/proto"
"stat/common"
"stat/common/stdLog"
"stat/common/utils"
"stat/models/channelmod"
"stat/service/agentSer"
"stat/statg"
"go.mongodb.org/mongo-driver/bson"
"github.com/dchest/captcha"
"github.com/gin-gonic/gin"
)
// @Tags 渠道后台
// @Summary 获取图片验证码
// @Description 获取图片验证码
// @Accept json
// @Produce json
// @Security ApiKeyAuth
// @Success 200 {object} proto.AgentImgVerifyCode "成功"
// @Success 400 {string} string "失败"
// @Router /api/stat/agent/imgVerify [POST]
func AgentImgVerifyCode(ctx *gin.Context) {
codeB := captcha.RandomDigits(4)
id := common.RandStr(8)
statg.VerifyIMGStore.Set(id, codeB)
img := captcha.NewImage(id, codeB, 180, 65)
var buf bytes.Buffer
_ = jpeg.Encode(&buf, img, nil)
resp := proto.AgentImgVerifyCode{
VerifyImg: buf.Bytes(),
ImgId: id,
}
stdLog.ServerJSON(ctx, stdLog.Success, resp)
}
// @Tags 渠道后台
// @Summary 代理商登陆
// @Description 代理商登陆
// @Accept json
// @Produce json
// @Param param body proto.AgentLoginReq true "参数"
// @Success 200 {object} proto.AgentLoginRes "成功"
// @Success 400 {string} string "失败"
// @Router /api/stat/agent/login [POST]
func AgentLogin(ctx *gin.Context) {
param := proto.AgentLoginReq{}
if err := ctx.ShouldBindJSON(&param); err != nil {
stdLog.ServerJSON(ctx, stdLog.ParamError, err)
return
}
ip := ctx.ClientIP()
code, agentInfo := agentSer.AgentLogin(ctx, ip, param)
if code != stdLog.Success {
stdLog.ServerJSON(ctx, code, "")
return
}
detail := &proto.ChannelAgentInfo{
Channel: agentInfo.Channel,
AppIds: agentInfo.AppIds,
UserName: agentInfo.UserName,
ParentAgent: agentInfo.ParentAgent,
ChildCount: agentInfo.ChildCount,
Status: agentInfo.Status,
Mobile: agentInfo.Mobile,
Type: agentInfo.Type,
Remark: agentInfo.Remark,
Lock: agentInfo.Lock,
Wallet: agentInfo.Wallet,
CreatedAt: agentInfo.CreatedAt,
UpdatedAt: agentInfo.UpdatedAt,
ChildShowDivideRate: agentInfo.ChildShowDivideRate,
}
ruleFilter := bson.M{
channelmod.FN.ChannelDeductionRule.Channel: agentInfo.Channel,
}
ruleInfoList, _ := channelmod.FindManyChannelDeductionRule(ctx, ruleFilter)
for _, ruleinfo := range ruleInfoList {
detail.Settlement = ruleinfo.Settlement
detail.CPAPrice = ruleinfo.CPAPrice
detail.CPSRate = ruleinfo.CPSRate
detail.DivideRate = 100 //
}
resp := proto.AgentLoginRes{
Token: agentInfo.Token,
Channel: agentInfo.Channel,
Detail: detail,
}
stdLog.ServerJSON(ctx, stdLog.Success, resp)
}
// @Tags 渠道后台
// @Summary 获取渠道列表
// @Description 获取渠道列表
// @Accept json
// @Produce json
// @Param param body proto.AgentChannelInfoSearch true "参数"
// @Success 200 {object} proto.AgentChannelInfoSearchResp "成功"
// @Success 400 {string} string "失败"
// @Security ApiKeyAuth
// @Router /api/stat/agent/channel/list [POST]
func AgentChannelList(ctx *gin.Context) {
channel, err := utils.GetAdmin(ctx)
if err != nil || channel == "" {
stdLog.ServerJSON(ctx, stdLog.NoToken, err)
return
}
//fmt.Println("channel")
param := proto.AgentChannelInfoSearch{}
if err := ctx.ShouldBindJSON(&param); err != nil {
stdLog.ServerJSON(ctx, stdLog.ParamError, err)
return
}
resp, err := agentSer.AgentChannelListInfo(ctx, channel, &param)
if err != nil {
stdLog.ServerJSON(ctx, stdLog.Failure, err)
return
}
stdLog.ServerJSON(ctx, stdLog.Success, resp)
}
// @Tags 渠道后台
// @Summary 更新渠道规则
// @Description 更新渠道规则
// @Accept json
// @Produce json
// @Param param body proto.AgentChannelRuleUpdate true "参数"
// @Success 200 {string} string "成功"
// @Success 400 {string} string "失败"
// @Security ApiKeyAuth
// @Router /api/stat/agent/channel/rule/update [POST]
func AgentChannelRuleUpdate(ctx *gin.Context) {
channel, err := utils.GetAdmin(ctx)
if err != nil || channel == "" {
stdLog.ServerJSON(ctx, stdLog.NoToken, err)
return
}
param := proto.AgentChannelRuleUpdate{}
if err := ctx.ShouldBindJSON(&param); err != nil {
stdLog.ServerJSON(ctx, stdLog.ParamError, err)
return
}
err = agentSer.AgentChannelRuleUpdate(ctx, channel, &param)
if err != nil {
stdLog.ServerJSON(ctx, stdLog.Failure, err)
return
}
stdLog.ServerJSON(ctx, stdLog.Success, "")
}
// @Tags 渠道后台
// @Summary 更新渠道信息
// @Description 更新渠道信息
// @Accept json
// @Produce json
// @Param param body proto.AgentChannelInfoUpdate true "参数"
// @Success 200 {string} string "成功"
// @Success 400 {string} string "失败"
// @Security ApiKeyAuth
// @Router /api/stat/agent/channel/info/update [POST]
func AgentChannelInfoUpdate(ctx *gin.Context) {
channel, err := utils.GetAdmin(ctx)
if err != nil || channel == "" {
stdLog.ServerJSON(ctx, stdLog.NoToken, err)
return
}
param := proto.AgentChannelInfoUpdate{}
if err := ctx.ShouldBindJSON(&param); err != nil {
stdLog.ServerJSON(ctx, stdLog.ParamError, err)
return
}
err = agentSer.AgentChannelInfoUpdate(ctx, channel, &param)
if err != nil {
stdLog.ServerJSON(ctx, stdLog.Failure, err)
return
}
stdLog.ServerJSON(ctx, stdLog.Success, "")
}
// @Tags 渠道后台
// @Summary 修改渠道密码
// @Description 修改渠道密码
// @Accept json
// @Produce json
// @Param param body proto.AgentChannelPasswordUpdate true "参数"
// @Success 200 {string} string "成功"
// @Success 400 {string} string "失败"
// @Security ApiKeyAuth
// @Router /api/stat/agent/channel/password/update [POST]
func AgentChannelPasswordUpdate(ctx *gin.Context) {
channel, err := utils.GetAdmin(ctx)
if err != nil || channel == "" {
stdLog.ServerJSON(ctx, stdLog.NoToken, err)
return
}
fmt.Println("channel")
param := proto.AgentChannelPasswordUpdate{}
if err := ctx.ShouldBindJSON(&param); err != nil {
stdLog.ServerJSON(ctx, stdLog.ParamError, err)
return
}
err = agentSer.AgentChannelPasswordUpdate(ctx, channel, &param)
if err != nil {
stdLog.ServerJSON(ctx, stdLog.Failure, err)
return
}
stdLog.ServerJSON(ctx, stdLog.Success, "")
}
// @Tags 渠道后台
// @Summary 重置子渠道密码
// @Description 重置子渠道密码
// @Accept json
// @Produce json
// @Param param body proto.AgentChannelPasswordReset true "参数"
// @Success 200 {string} string "成功"
// @Success 400 {string} string "失败"
// @Security ApiKeyAuth
// @Router /api/stat/agent/channel/password/reset [POST]
func AgentChannelPasswordReset(ctx *gin.Context) {
channel, err := utils.GetAdmin(ctx)
if err != nil || channel == "" {
stdLog.ServerJSON(ctx, stdLog.NoToken, err)
return
}
fmt.Println("channel")
param := proto.AgentChannelPasswordReset{}
if err := ctx.ShouldBindJSON(&param); err != nil {
stdLog.ServerJSON(ctx, stdLog.ParamError, err)
return
}
err = agentSer.AgentChannelPasswordReset(ctx, channel, &param)
if err != nil {
stdLog.ServerJSON(ctx, stdLog.Failure, err)
return
}
stdLog.ServerJSON(ctx, stdLog.Success, "")
}
// @Tags 渠道后台
// @Summary 添加一个子渠道
// @Description 添加一个子渠道
// @Accept json
// @Produce json
// @Param param body proto.AgentChannelInfoAdd true "参数"
// @Success 200 {string} string "成功"
// @Success 400 {string} string "失败"
// @Security ApiKeyAuth
// @Router /api/stat/agent/channel/add [POST]
func AddAgentChannel(ctx *gin.Context) {
channel, err := utils.GetAdmin(ctx)
if err != nil || channel == "" {
stdLog.ServerJSON(ctx, stdLog.NoToken, err)
return
}
param := proto.AgentChannelInfoAdd{}
if err := ctx.ShouldBindJSON(&param); err != nil {
stdLog.ServerJSON(ctx, stdLog.ParamError, err)
return
}
err = agentSer.AddAgentChannelInfo(ctx, channel, &param)
if err != nil {
stdLog.ServerJSON(ctx, stdLog.Failure, err)
return
}
stdLog.ServerJSON(ctx, stdLog.Success, "")
}
// @Tags 渠道后台
// @Summary 获取渠道统计Ex
// @Description 获取渠道日常统计Ex
// @Accept json
// @Produce json
// @Param param body proto.AgentChannelStatSearch true "参数"
// @Success 200 {object} proto.AgentChannelStatResp "成功"
// @Success 400 {string} string "失败"
// @Security ApiKeyAuth
// @Router /api/stat/agent/channel/stat [POST]
func GetAgentChannelStat(ctx *gin.Context) {
channel, err := utils.GetAdmin(ctx)
if err != nil || channel == "" {
stdLog.ServerJSON(ctx, stdLog.NoToken, err)
return
}
param := proto.AgentChannelStatSearch{}
if err := ctx.ShouldBindJSON(&param); err != nil {
stdLog.ServerJSON(ctx, stdLog.ParamError, err)
return
}
resp, err := agentSer.GetAgentChannelStat(ctx, channel, &param)
if err != nil {
stdLog.ServerJSON(ctx, stdLog.Failure, err)
return
}
stdLog.ServerJSON(ctx, stdLog.Success, resp)
}
// @Tags 渠道后台
// @Summary 获取首页渠道数据汇总
// @Description 获取首页渠道数据汇总
// @Accept json
// @Produce json
// @Param param body proto.AgentSummaryStatHomeSearch true "参数"
// @Success 200 {object} proto.AgentSummaryStatHomeResp "成功"
// @Success 400 {string} string "失败"
// @Security ApiKeyAuth
// @Router /api/stat/agent/summary/home [POST]
func GetAgentSummaryStatHome(ctx *gin.Context) {
channel, err := utils.GetAdmin(ctx)
if err != nil || channel == "" {
stdLog.ServerJSON(ctx, stdLog.NoToken, err)
return
}
param := proto.AgentSummaryStatHomeSearch{}
if err := ctx.ShouldBindJSON(&param); err != nil {
stdLog.ServerJSON(ctx, stdLog.ParamError, err)
return
}
resp, err := agentSer.GetAgentSummaryStatHome(ctx, channel, &param)
if err != nil {
stdLog.ServerJSON(ctx, stdLog.Failure, err)
return
}
stdLog.ServerJSON(ctx, stdLog.Success, resp)
}
// @Tags 渠道后台
// @Summary 获取子渠道数据汇总
// @Description 获取子渠道数据汇总
// @Accept json
// @Produce json
// @Param param body proto.AgentSummaryStatChildSearch true "参数"
// @Success 200 {object} proto.AgentSummaryStatChildResp "成功"
// @Success 400 {string} string "失败"
// @Security ApiKeyAuth
// @Router /api/stat/agent/summary/child [POST]
func GetAgentSummaryStatChild(ctx *gin.Context) {
channel, err := utils.GetAdmin(ctx)
if err != nil || channel == "" {
stdLog.ServerJSON(ctx, stdLog.NoToken, err)
return
}
param := proto.AgentSummaryStatChildSearch{}
if err := ctx.ShouldBindJSON(&param); err != nil {
stdLog.ServerJSON(ctx, stdLog.ParamError, err)
return
}
resp, err := agentSer.GetAgentSummaryStatChild(ctx, channel, &param)
if err != nil {
stdLog.ServerJSON(ctx, stdLog.Failure, err)
return
}
stdLog.ServerJSON(ctx, stdLog.Success, resp)
}
// @Tags 渠道后台
// @Summary 获取落地页列表
// @Description 获取落地页列表
// @Accept json
// @Produce json
// @Param param body proto.ChannelAppInfoReq true "参数"
// @Success 200 {object} proto.ChannelAppInfoResp "成功"
// @Success 400 {string} string "失败"
// @Security ApiKeyAuth
// @Router /api/stat/agent/channel/landpage [POST]
func ChannelAppInfo(ctx *gin.Context) {
channel, err := utils.GetAdmin(ctx)
if err != nil || channel == "" {
stdLog.ServerJSON(ctx, stdLog.NoToken, err)
return
}
param := proto.ChannelAppInfoReq{}
if err := ctx.ShouldBindJSON(&param); err != nil {
stdLog.ServerJSON(ctx, stdLog.ParamError, err)
return
}
resp, err := agentSer.AgentChannelAppInfo(ctx, param)
if err != nil {
stdLog.ServerJSON(ctx, stdLog.Failure, err)
return
}
stdLog.ServerJSON(ctx, stdLog.Success, resp)
}