package advertiseApi import ( "net/http" "stat/api/proto" "stat/common/stdLog" "stat/common/utils" "stat/service/advertiseSer" "stat/service/opLogSer" "github.com/gin-gonic/gin" ) // @Tags 广告管理 // @Summary 广告列表 // @Description 广告列表 // @Accept json // @Produce json // @Security ApiKeyAuth // @Param param body proto.ListAdsReq true "参数" // @Success 200 {object} proto.ListAdsRes "成功" // @Success 400 {string} string "失败" // @Security ApiKeyAuth // @Router /api/stat/ads/list [POST] func ListAds(ctx *gin.Context) { param := proto.ListAdsReq{} if err := ctx.ShouldBindJSON(¶m); err != nil { stdLog.ServerJSON(ctx, stdLog.ParamError, err) return } code, data, err := advertiseSer.ListAds(ctx, param) if err != nil { stdLog.ServerJSON(ctx, code, err) return } stdLog.ServerJSON(ctx, code, data) } // @Tags 广告管理 // @Summary 新增广告信息 // @Description 新增广告信息 // @Accept json // @Produce json // @Security ApiKeyAuth // @Param param body proto.AddAdsReq true "参数" // @Success 200 {string} string "成功" // @Success 400 {string} string "失败" // @Security ApiKeyAuth // @Router /api/stat/ads/add [POST] func AddAds(ctx *gin.Context) { account, err := utils.GetAdmin(ctx) if err != nil { stdLog.ServerJSON(ctx, stdLog.NoToken, err.Error()) return } param := proto.AddAdsReq{} if err := ctx.ShouldBindJSON(¶m); err != nil { stdLog.ServerJSON(ctx, stdLog.ParamError, err) return } code, data, err := advertiseSer.AddAds(ctx, param, account) if err != nil { stdLog.ServerJSON(ctx, code, err) return } // 增加操作日志 opLogSer.AddOpLog(ctx, account, true, param) stdLog.ServerJSON(ctx, code, data) } // @Tags 广告管理 // @Summary 修改广告信息 // @Description 修改广告信息 // @Accept json // @Produce json // @Security ApiKeyAuth // @Param param body proto.UpdateAdsReq true "参数列表" // @Success 200 {string} string "成功" // @Failure 400 {string} string "失败" // @Security ApiKeyAuth // @Router /api/stat/ads/update [POST] func UpdateAds(ctx *gin.Context) { account, err := utils.GetAdmin(ctx) if err != nil { stdLog.ServerJSON(ctx, stdLog.NoToken, err.Error()) return } param := proto.UpdateAdsReq{} if err := ctx.ShouldBindJSON(¶m); err != nil { stdLog.ServerJSON(ctx, stdLog.ParamError, err) return } code, data, err := advertiseSer.UpdateAds(ctx, param, account) if err != nil { stdLog.ServerJSON(ctx, code, err) return } // 增加操作日志 opLogSer.AddOpLog(ctx, account, true, param) stdLog.ServerJSON(ctx, code, data) } // @Tags 广告管理 // @Summary 删除广告信息 // @Description 删除广告信息 // @Accept json // @Produce json // @Security ApiKeyAuth // @Param param body proto.DelAdsReq true "参数" // @Success 200 {string} string "成功" // @Success 400 {string} string "失败" // @Security ApiKeyAuth // @Router /api/stat/ads/del [POST] func DelAds(ctx *gin.Context) { account, err := utils.GetAdmin(ctx) if err != nil { stdLog.ServerJSON(ctx, stdLog.NoToken, err.Error()) return } param := proto.DelAdsReq{} if err := ctx.ShouldBindJSON(¶m); err != nil { stdLog.ServerJSON(ctx, stdLog.ParamError, err) return } code, data, err := advertiseSer.DelAds(ctx, param, account) if err != nil { stdLog.ServerJSON(ctx, code, err) return } // 增加操作日志 opLogSer.AddOpLog(ctx, account, true, param) stdLog.ServerJSON(ctx, code, data) } // @Tags 广告管理 // @Summary 外部获取广告信息 // @Description 外部获取广告信息 // @Accept json // @Produce json // @Param param body proto.AdvertiseReq true "参数" // @Success 200 {object} proto.AdvertiseRes "成功" // @Success 400 {string} string "失败" // @Router /api/stat/ads/get [POST] func GetAds(ctx *gin.Context) { param := proto.AdvertiseReq{} if err := ctx.ShouldBindJSON(¶m); err != nil { stdLog.ServerJSON(ctx, stdLog.ParamError, err) return } code, data, err := advertiseSer.GetAdvertise(ctx, param) if err != nil { stdLog.ServerJSON(ctx, code, err) return } ctx.JSON(http.StatusOK, data) } // @Tags 广告管理 // @Summary 广告点击 // @Description 广告点击 // @Accept json // @Produce json // @Param param body proto.AdsClickReq true "参数" // @Success 200 {string} string "成功" // @Success 400 {string} string "失败" // @Router /api/stat/ads/click [POST] func ClickAds(ctx *gin.Context) { param := proto.AdsClickReq{} if err := ctx.ShouldBindJSON(¶m); err != nil { stdLog.ServerJSON(ctx, stdLog.ParamError, err) return } code, data, err := advertiseSer.IncAdsClickCount(ctx, param) if err != nil { stdLog.ServerJSON(ctx, code, err) return } stdLog.ServerJSON(ctx, code, data) }