|
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126 |
- package article
-
- import (
- "applet/app/db"
- "applet/app/e"
- "applet/app/md"
- "applet/app/svc"
- "applet/app/utils"
- "code.fnuoos.com/EggPlanet/egg_models.git/src/implement"
- "code.fnuoos.com/EggPlanet/egg_models.git/src/model"
- "fmt"
- "github.com/gin-gonic/gin"
- "time"
- )
-
- func List(c *gin.Context) {
- var req *md.ArticleListReq
- if err := c.ShouldBindJSON(&req); err != nil {
- e.OutErr(c, e.ERR_INVALID_ARGS, err)
- return
- }
- var resp md.ArticleListResp
- noticeList := make([]md.ArticleList, 0)
- NewArticleDb := implement.NewArticleDb(db.Db)
- notice, total, _ := NewArticleDb.FindArticleAndTotal(req.Page, req.Limit, "", "")
- resp.Total = total
- resp.SelectData = make([]map[string]interface{}, 0)
- NewArticleCateDb := implement.NewArticleCateDb(db.Db)
- pid, _ := NewArticleCateDb.FindArticleCate("1", "100", "0")
- if pid != nil {
- for _, v := range *pid {
- list := make([]map[string]string, 0)
- tmp := map[string]interface{}{
- "name": v.Name, "value": utils.IntToStr(v.Id), "list": list,
- }
- cate, _ := NewArticleCateDb.FindArticleCate("1", "1000", utils.IntToStr(v.Id))
- if cate != nil {
- for _, v1 := range *cate {
- tmp1 := map[string]string{
- "name": v1.Name, "value": utils.IntToStr(v1.Id),
- }
- list = append(list, tmp1)
- }
- tmp["list"] = list
- }
- resp.SelectData = append(resp.SelectData, tmp)
- }
- }
- resp.CateData = make([]map[string]interface{}, 0)
- cate, _, _ := NewArticleCateDb.FindArticleCateAndTotalPid("1", "100")
- if cate != nil {
- for _, v := range *cate {
- list := make([]map[string]string, 0)
- tmp := map[string]interface{}{
- "name": v.Name, "value": utils.IntToStr(v.Id), "list": list,
- }
- resp.CateData = append(resp.CateData, tmp)
- }
- }
- if notice != nil {
- for _, v := range *notice {
- isHide := "1"
- if v.Pid == 4 {
- isHide = "0"
- }
- tmp := md.ArticleList{
- CateId: utils.IntToStr(v.CateId),
- Title: v.Title,
- Content: v.Content,
- Cover: v.Cover,
- CoverUrl: svc.GetOssUrl(v.Cover),
- Id: utils.IntToStr(v.Id),
- Sort: utils.IntToStr(v.Sort),
- IsShow: utils.IntToStr(v.IsShow),
- Pid: utils.IntToStr(v.Pid),
- Url: fmt.Sprintf("%s%s?id=%s&is_hide=%s", svc.GetSysCfgStr("wap_host"), "/#/pages/course-detail-page/course-detail-page", utils.AnyToString(v.Id), isHide),
- }
- noticeList = append(noticeList, tmp)
- }
- }
- resp.List = noticeList
- e.OutSuc(c, resp, nil)
- return
- }
- func Save(c *gin.Context) {
- var req *md.ArticleSaveReq
- if err := c.ShouldBindJSON(&req); err != nil {
- e.OutErr(c, e.ERR_INVALID_ARGS, err)
- return
- }
- var data = new(model.Article)
- if utils.StrToInt(req.Id) > 0 {
- NewArticleDb := implement.NewArticleDb(db.Db)
- notice, _ := NewArticleDb.GetArticle(req.Id)
- if notice == nil {
- e.OutErr(c, 400, e.NewErr(400, "记录不存在"))
- return
- }
- data = notice
- } else {
- data.CreatedAt = int(time.Now().Unix())
- db.Db.Insert(data)
- }
- data.UpdatedAt = int(time.Now().Unix())
- data.Title = req.Title
- data.Cover = req.Cover
- data.Content = req.Content
- data.TypeId = utils.StrToInt(req.Pid)
- data.CateId = utils.StrToInt(req.CateId)
- data.Sort = utils.StrToInt(req.Sort)
- data.Pid = utils.StrToInt(req.Pid)
- data.IsShow = utils.StrToInt(req.IsShow)
- db.Db.Where("id=?", data.Id).AllCols().Update(data)
- e.OutSuc(c, "success", nil)
- return
- }
- func Del(c *gin.Context) {
- var req *md.ArticleDelReq
- if err := c.ShouldBindJSON(&req); err != nil {
- e.OutErr(c, e.ERR_INVALID_ARGS, err)
- return
- }
- db.Db.In("id", req.Ids).Delete(&model.Article{})
- e.OutSuc(c, "success", nil)
- return
- }
|