package article import ( "applet/app/db" "applet/app/e" "applet/app/md" "applet/app/utils" "code.fnuoos.com/EggPlanet/egg_models.git/src/implement" "code.fnuoos.com/EggPlanet/egg_models.git/src/model" "github.com/gin-gonic/gin" ) func CateList(c *gin.Context) { var req *md.ArticleCateListReq if err := c.ShouldBindJSON(&req); err != nil { e.OutErr(c, e.ERR_INVALID_ARGS, err) return } var resp md.ArticleCateListResp noticeList := make([]md.ArticleCateList, 0) NewJpushNoticeDb := implement.NewArticleCateDb(db.Db) notice, total, _ := NewJpushNoticeDb.FindArticleCateAndTotalPid(req.Page, req.Limit) resp.Total = total resp.SelectData = []map[string]string{} pid, _ := NewJpushNoticeDb.FindArticleCate("1", "100", "0") if pid != nil { for _, v := range *pid { tmp := map[string]string{ "name": v.Name, "value": utils.IntToStr(v.Id), } resp.SelectData = append(resp.SelectData, tmp) } } if notice != nil { for _, v := range *notice { tmp := md.ArticleCateList{ Id: utils.IntToStr(v.Id), Sort: utils.IntToStr(v.Sort), IsShow: utils.IntToStr(v.IsShow), Pid: utils.IntToStr(v.Pid), Name: v.Name, } noticeList = append(noticeList, tmp) } } resp.List = noticeList e.OutSuc(c, resp, nil) return } func CateSave(c *gin.Context) { var req *md.ArticleCateSaveReq if err := c.ShouldBindJSON(&req); err != nil { e.OutErr(c, e.ERR_INVALID_ARGS, err) return } var data = new(model.ArticleCate) if utils.StrToInt(req.Id) > 0 { NewArticleCateDb := implement.NewArticleCateDb(db.Db) notice, _ := NewArticleCateDb.GetArticleCate(req.Id) if notice == nil { e.OutErr(c, 400, e.NewErr(400, "记录不存在")) return } data = notice } else { db.Db.Insert(data) } data.Name = req.Name data.Sort = utils.StrToInt(req.Sort) data.Pid = utils.StrToInt(req.Pid) data.IsShow = utils.StrToInt(req.IsShow) db.Db.Where("id=?", data.Id).Update(data) e.OutSuc(c, "success", nil) return } func CateDel(c *gin.Context) { var req *md.ArticleCateDelReq if err := c.ShouldBindJSON(&req); err != nil { e.OutErr(c, e.ERR_INVALID_ARGS, err) return } db.Db.In("id", req.Id).Delete(&model.ArticleCate{}) e.OutSuc(c, "success", nil) return }