diff --git a/app/db/db_notice.go b/app/db/db_notice.go index 7dbdf24..db7cf23 100644 --- a/app/db/db_notice.go +++ b/app/db/db_notice.go @@ -16,3 +16,25 @@ func GetBankNotice(eg *xorm.Engine, args map[string]string) *[]model.CommunityTe } return &data } +func GetBankNoticeAll(eg *xorm.Engine, args map[string]string) (*[]model.CommunityTeamStoreNotice, int64) { + var data []model.CommunityTeamStoreNotice + size := utils.StrToInt(args["size"]) + start := (utils.StrToInt(args["p"]) - 1) * size + sess := eg.Where("uid=?", args["uid"]) + if args["title"] != "" { + sess.And("title like ?", "%"+args["title"]+"%") + } + count, err := sess.Limit(size, start).OrderBy("id desc").FindAndCount(&data) + if err != nil { + return nil, count + } + return &data, count +} +func GetNotice(eg *xorm.Engine, id string) *model.CommunityTeamStoreNotice { + var data model.CommunityTeamStoreNotice + get, err := eg.Where("id=?", id).Get(&data) + if get == false || err != nil { + return nil + } + return &data +} diff --git a/app/router/router.go b/app/router/router.go index 5e06180..d4dfda2 100644 --- a/app/router/router.go +++ b/app/router/router.go @@ -134,6 +134,9 @@ func routeCommunityTeamOwnStore(r *gin.RouterGroup) { r.POST("/agent/goods/list", storeHdl.AgentGoods) r.POST("/agent/goods/detail", storeHdl.AgentGoodsDetail) r.POST("/agent/goods/copy", storeHdl.AgentGoodsCopy) + r.POST("/notice/list", storeHdl.Notice) + r.POST("/notice/save", storeHdl.NoticeSave) + r.POST("/notice/del", storeHdl.NoticeDel) } func routeCommunityTeam(r *gin.RouterGroup) { r.Use(mw.DB) // 下面接口再根据mid 获取数据库名 diff --git a/app/store/hdl/hdl_notice.go b/app/store/hdl/hdl_notice.go new file mode 100644 index 0000000..dd52b17 --- /dev/null +++ b/app/store/hdl/hdl_notice.go @@ -0,0 +1,16 @@ +package hdl + +import ( + "applet/app/store/svc" + "github.com/gin-gonic/gin" +) + +func Notice(c *gin.Context) { + svc.Notice(c) +} +func NoticeSave(c *gin.Context) { + svc.NoticeSave(c) +} +func NoticeDel(c *gin.Context) { + svc.NoticeDel(c) +} diff --git a/app/store/svc/svc_notice.go b/app/store/svc/svc_notice.go new file mode 100644 index 0000000..83ed636 --- /dev/null +++ b/app/store/svc/svc_notice.go @@ -0,0 +1,78 @@ +package svc + +import ( + "applet/app/db" + "applet/app/db/model" + "applet/app/e" + "applet/app/svc" + "applet/app/utils" + "github.com/gin-gonic/gin" + "strings" + "time" +) + +func Notice(c *gin.Context) { + var args map[string]string + if err := c.ShouldBindJSON(&args); err != nil { + e.OutErr(c, e.ERR_INVALID_ARGS, err) + return + } + user := svc.GetUser(c) + args["uid"] = utils.IntToStr(user.Info.Uid) + data, total := db.GetBankNoticeAll(svc.MasterDb(c), args) + list := make([]map[string]string, 0) + if data != nil { + for _, v := range *data { + tmp := map[string]string{ + "id": utils.IntToStr(v.Id), + "title": v.Title, + "content": v.Content, + "create_time": v.CreateTime.Format("2006-01-02 15:04"), + } + list = append(list, tmp) + } + } + res := map[string]interface{}{ + "list": list, "total": total, + } + e.OutSuc(c, res, nil) + return +} +func NoticeSave(c *gin.Context) { + var args map[string]string + if err := c.ShouldBindJSON(&args); err != nil { + e.OutErr(c, e.ERR_INVALID_ARGS, err) + return + } + user := svc.GetUser(c) + eg := svc.MasterDb(c) + if args["id"] != "" { + notice := db.GetNotice(eg, args["id"]) + notice.UpdateTime = time.Now() + notice.Title = args["title"] + notice.Content = args["content"] + } else { + notice := &model.CommunityTeamStoreNotice{ + Uid: user.Info.Uid, + CreateTime: time.Now(), + UpdateTime: time.Now(), + Title: args["title"], + Content: args["content"], + } + eg.Insert(notice) + } + e.OutSuc(c, "success", nil) + return + +} + +func NoticeDel(c *gin.Context) { + var arg map[string]string + if err := c.ShouldBindJSON(&arg); err != nil { + e.OutErr(c, e.ERR_INVALID_ARGS, err) + return + } + svc.MasterDb(c).In("id", strings.Split(arg["ids"], ",")).Delete(&model.CommunityTeamStoreNotice{}) + e.OutSuc(c, "success", nil) + return +}