huangjiajun hace 1 mes
padre
commit
b6395f220f
Se han modificado 4 ficheros con 119 adiciones y 0 borrados
  1. +22
    -0
      app/db/db_notice.go
  2. +3
    -0
      app/router/router.go
  3. +16
    -0
      app/store/hdl/hdl_notice.go
  4. +78
    -0
      app/store/svc/svc_notice.go

+ 22
- 0
app/db/db_notice.go Ver fichero

@@ -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
}

+ 3
- 0
app/router/router.go Ver fichero

@@ -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 获取数据库名


+ 16
- 0
app/store/hdl/hdl_notice.go Ver fichero

@@ -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)
}

+ 78
- 0
app/store/svc/svc_notice.go Ver fichero

@@ -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
}

Cargando…
Cancelar
Guardar