|
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135 |
- package hdl
-
- import (
- "applet/app/admin/lib/validate"
- "applet/app/admin/md"
- "applet/app/db"
- "applet/app/db/model"
- "applet/app/e"
- "applet/app/utils"
- "github.com/gin-gonic/gin"
- "time"
- )
-
- func NoticeList(c *gin.Context) {
- noticeDb := db.NoticeDb{}
- noticeDb.Set()
- notices, err := noticeDb.FindNotice(0, 0)
- if err != nil {
- e.OutErr(c, e.ERR_DB_ORM, err.Error())
- return
- }
- e.OutSuc(c, map[string]interface{}{
- "list": notices,
- }, nil)
- return
- }
-
- func NoticeSort(c *gin.Context) {
- var args struct {
- Ids []string `json:"ids" binding:"required"`
- }
- if err := c.ShouldBindJSON(&args); err != nil {
- e.OutErr(c, e.ERR_INVALID_ARGS, err)
- return
- }
- noticeDb := db.NoticeDb{}
- noticeDb.Set()
- notices, err := noticeDb.FindNoticeById(args.Ids)
- if err != nil {
- e.OutErr(c, e.ERR_DB_ORM, err.Error())
- return
- }
- for k, v := range *notices {
- v.Sort = k
- _, err1 := noticeDb.NoticeUpdate(&v, "sort")
- if err1 != nil {
- e.OutErr(c, e.ERR_DB_ORM, err1.Error())
- return
- }
- }
- e.OutSuc(c, "success", nil)
- }
-
- func NoticeAdd(c *gin.Context) {
- var req md.NoticeAddReq
- err := c.ShouldBindJSON(&req)
- if err != nil {
- err = validate.HandleValidateErr(err)
- err1 := err.(e.E)
- e.OutErr(c, err1.Code, err1.Error())
- return
- }
- noticeDb := db.NoticeDb{}
- noticeDb.Set()
- now := time.Now()
- notice := model.Notice{
- Name: req.Name,
- Content: req.Content,
- CreateAt: now.Format("2006-01-02 15:04:05"),
- UpdateAt: now.Format("2006-01-02 15:04:05"),
- }
- _, err = noticeDb.NoticeInsert(¬ice)
- if err != nil {
- e.OutErr(c, e.ERR_DB_ORM, err.Error())
- return
- }
- e.OutSuc(c, "success", nil)
- return
- }
-
- func NoticeUpdate(c *gin.Context) {
- var req md.NoticeUpdateReq
- err := c.ShouldBindJSON(&req)
- if err != nil {
- err = validate.HandleValidateErr(err)
- err1 := err.(e.E)
- e.OutErr(c, err1.Code, err1.Error())
- return
- }
- noticeDb := db.NoticeDb{}
- noticeDb.Set()
- notice, err := noticeDb.GetNotice(req.Id)
- if err != nil {
- e.OutErr(c, e.ERR_DB_ORM, err.Error())
- return
- }
- if notice == nil {
- e.OutErr(c, e.ERR_NO_DATA, "未查询到对应记录")
- return
- }
- now := time.Now()
- notice.Name = req.Name
- notice.Content = req.Content
- notice.UpdateAt = now.Format("2006-01-02 15:04:05")
- _, err = noticeDb.NoticeUpdate(notice, "name", "content", "update_at")
- if err != nil {
- e.OutErr(c, e.ERR_DB_ORM, err.Error())
- return
- }
- e.OutSuc(c, "success", nil)
- return
- }
-
- func NoticeDelete(c *gin.Context) {
- id := c.Param("id")
- noticeDb := db.NoticeDb{}
- noticeDb.Set()
- company, err := noticeDb.GetNotice(utils.StrToInt(id))
- if err != nil {
- e.OutErr(c, e.ERR_DB_ORM, err.Error())
- return
- }
- if company == nil {
- e.OutErr(c, e.ERR_NO_DATA, "未查询到对应记录")
- return
- }
-
- _, err = noticeDb.NoticeDelete(id)
- if err != nil {
- e.OutErr(c, e.ERR_DB_ORM, err.Error())
- return
- }
- e.OutSuc(c, "success", nil)
- return
- }
|