/** * 广告位-控制器 * @author * @since 2021/11/15 * @File : adsort */ package controller import ( "easygoadmin/app/dto" "easygoadmin/app/model" "easygoadmin/app/service" "easygoadmin/utils" "easygoadmin/utils/common" "easygoadmin/utils/gconv" "easygoadmin/utils/response" "github.com/gin-gonic/gin" "net/http" ) var AdSort = new(adSortCtl) type adSortCtl struct{} func (c *adSortCtl) Index(ctx *gin.Context) { // 渲染模板 response.BuildTpl(ctx, "adsort_index.html").WriteTpl() } func (c *adSortCtl) List(ctx *gin.Context) { // 参数 var req *dto.AdSortPageReq if err := ctx.ShouldBind(&req); err != nil { ctx.JSON(http.StatusOK, common.JsonResult{ Code: -1, Msg: err.Error(), }) return } // 调用查询分页方法 list, count, err := service.AdSort.GetList(req) if err != nil { ctx.JSON(http.StatusOK, common.JsonResult{ Code: -1, Msg: err.Error(), }) return } // 返回结果 ctx.JSON(http.StatusOK, common.JsonResult{ Code: 0, Msg: "查询成功", Data: list, Count: count, }) } func (c *adSortCtl) Edit(ctx *gin.Context) { id := gconv.Int(ctx.Query("id")) if id > 0 { // 编辑 info := &model.AdSort{Id: id} has, err := info.Get() if !has || err != nil { ctx.JSON(http.StatusOK, common.JsonResult{ Code: -1, Msg: err.Error(), }) return } // 渲染模板 response.BuildTpl(ctx, "adsort_edit.html").WriteTpl(gin.H{ "info": info, "platformList": common.ADSORT_PLATFORM_LIST, }) } else { // 添加 // 渲染模板 response.BuildTpl(ctx, "adsort_edit.html").WriteTpl(gin.H{ "platformList": common.ADSORT_PLATFORM_LIST, }) } } func (c *adSortCtl) Add(ctx *gin.Context) { // 参数 var req *dto.AdSortAddReq if err := ctx.ShouldBind(&req); err != nil { ctx.JSON(http.StatusOK, common.JsonResult{ Code: -1, Msg: err.Error(), }) return } // 调用添加方法 rows, err := service.AdSort.Add(req, utils.Uid(ctx)) if err != nil || rows == 0 { ctx.JSON(http.StatusOK, common.JsonResult{ Code: -1, Msg: err.Error(), }) return } // 返回结果 ctx.JSON(http.StatusOK, common.JsonResult{ Code: 0, Msg: "添加成功", }) } func (c *adSortCtl) Update(ctx *gin.Context) { // 参数 var req *dto.AdSortUpdateReq if err := ctx.ShouldBind(&req); err != nil { ctx.JSON(http.StatusOK, common.JsonResult{ Code: -1, Msg: err.Error(), }) return } // 调用更新方法 rows, err := service.AdSort.Update(req, utils.Uid(ctx)) if err != nil || rows == 0 { ctx.JSON(http.StatusOK, common.JsonResult{ Code: -1, Msg: err.Error(), }) return } // 返回结果 ctx.JSON(http.StatusOK, common.JsonResult{ Code: 0, Msg: "更新成功", }) } func (c *adSortCtl) Delete(ctx *gin.Context) { // 记录ID ids := ctx.Param("ids") if ids == "" { ctx.JSON(http.StatusOK, common.JsonResult{ Code: -1, Msg: "记录ID不能为空", }) return } // 调用删除方法 rows, err := service.AdSort.Delete(ids) if err != nil || rows == 0 { ctx.JSON(http.StatusOK, common.JsonResult{ Code: -1, Msg: err.Error(), }) return } // 返回结果 ctx.JSON(http.StatusOK, common.JsonResult{ Code: 0, Msg: "删除成功", }) } func (c *adSortCtl) GetAdSortList(ctx *gin.Context) { // 调用查询列表方法 list := service.AdSort.GetAdSortList() // 返回结果 ctx.JSON(http.StatusOK, common.JsonResult{ Code: 0, Msg: "查询成功", Data: list, }) }