From f09c1fcfc15653351e00c151d180cfdce85537d8 Mon Sep 17 00:00:00 2001 From: huangjiajun <582604932@qq.com> Date: Sat, 1 Jun 2024 10:17:58 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9B=B4=E6=96=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/admin/hdl/order/hdl_order_list.go | 9 ++++ app/admin/svc/order/svc_order_list.go | 74 ++++++++++++++++++++++++++- app/bigData/hdl/hdl_notice.go | 10 ++++ app/bigData/svc/svc_notice.go | 19 +++++++ app/db/db_notice.go | 40 +++++++++++++++ app/db/model/notice.go | 12 +++++ app/router/admin_router.go | 3 ++ app/router/big_data_router.go | 2 +- 8 files changed, 167 insertions(+), 2 deletions(-) create mode 100644 app/bigData/hdl/hdl_notice.go create mode 100644 app/bigData/svc/svc_notice.go create mode 100644 app/db/db_notice.go create mode 100644 app/db/model/notice.go diff --git a/app/admin/hdl/order/hdl_order_list.go b/app/admin/hdl/order/hdl_order_list.go index 4dcc7ff..3188575 100644 --- a/app/admin/hdl/order/hdl_order_list.go +++ b/app/admin/hdl/order/hdl_order_list.go @@ -46,3 +46,12 @@ func OrderAddNum(c *gin.Context) { func OrderDeductNum(c *gin.Context) { order.OrderDeductNum(c) } +func NoticeList(c *gin.Context) { + order.NoticeList(c) +} +func NoticeSave(c *gin.Context) { + order.NoticeSave(c) +} +func NoticeDel(c *gin.Context) { + order.NoticeDel(c) +} diff --git a/app/admin/svc/order/svc_order_list.go b/app/admin/svc/order/svc_order_list.go index 51725e9..d53772a 100644 --- a/app/admin/svc/order/svc_order_list.go +++ b/app/admin/svc/order/svc_order_list.go @@ -14,6 +14,7 @@ import ( "github.com/gin-gonic/gin" "github.com/tidwall/gjson" "strconv" + "time" "xorm.io/xorm" ) @@ -82,7 +83,6 @@ func OrderList(c *gin.Context) { e.OutSuc(c, res, nil) return } - func OrderExport(c *gin.Context) { var args map[string]string if err := c.ShouldBindJSON(&args); err != nil { @@ -1184,3 +1184,75 @@ func OrderDeductNum(c *gin.Context) { e.OutSuc(c, "success", 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 + } + eg := db.Db + date := time.Now().Format("2006-01-02") + if args["id"] == "" { + count := db.GetNoticeByDateCount(eg, date) + if count > 0 { + e.OutErr(c, 400, e.NewErr(400, "请到记录列表找到今天记录编辑")) + return + } + data := &model.Notice{ + Date: date, + Content: args["content"], + UpdateAt: time.Now(), + } + eg.InsertOne(data) + } else { + data := db.GetNoticeById(eg, args["id"]) + if data == nil { + e.OutErr(c, 400, e.NewErr(400, "记录不存在")) + return + } + data.Content = args["content"] + data.UpdateAt = time.Now() + } + e.OutSuc(c, "success", nil) + return + +} +func NoticeDel(c *gin.Context) { + var args map[string]string + if err := c.ShouldBindJSON(&args); err != nil { + e.OutErr(c, e.ERR_INVALID_ARGS, err) + return + } + eg := db.Db + eg.Where("id=?", args["id"]).Delete(&model.Notice{}) + e.OutSuc(c, "success", nil) + return + +} +func NoticeList(c *gin.Context) { + var args map[string]string + if err := c.ShouldBindJSON(&args); err != nil { + e.OutErr(c, e.ERR_INVALID_ARGS, err) + return + } + eg := db.Db + list, total := db.GetNotice(eg, args) + data := make([]map[string]interface{}, 0) + if list != nil { + for _, v := range *list { + var tmp = map[string]interface{}{ + "id": utils.IntToStr(v.Id), + "content": v.Content, + "date": v.Date, + "update_at": v.UpdateAt.Format("2006-01-02 15:04:05"), + } + data = append(data, tmp) + } + } + res := map[string]interface{}{ + "total": total, + "list": data, + } + e.OutSuc(c, res, nil) + return +} diff --git a/app/bigData/hdl/hdl_notice.go b/app/bigData/hdl/hdl_notice.go new file mode 100644 index 0000000..6e234ed --- /dev/null +++ b/app/bigData/hdl/hdl_notice.go @@ -0,0 +1,10 @@ +package hdl + +import ( + "applet/app/bigData/svc" + "github.com/gin-gonic/gin" +) + +func Notice(c *gin.Context) { + svc.Notice(c) +} diff --git a/app/bigData/svc/svc_notice.go b/app/bigData/svc/svc_notice.go new file mode 100644 index 0000000..0763b3d --- /dev/null +++ b/app/bigData/svc/svc_notice.go @@ -0,0 +1,19 @@ +package svc + +import ( + "applet/app/db" + "applet/app/e" + "github.com/gin-gonic/gin" + "time" +) + +func Notice(c *gin.Context) { + date := time.Now().Format("2006-01-02") + data := db.GetNoticeByDate(db.Db, date) + var res = make([]string, 0) + if data != nil { + res = append(res, data.Content) + } + e.OutSuc(c, res, nil) + return +} diff --git a/app/db/db_notice.go b/app/db/db_notice.go new file mode 100644 index 0000000..89258a5 --- /dev/null +++ b/app/db/db_notice.go @@ -0,0 +1,40 @@ +package db + +import ( + "applet/app/db/model" + "applet/app/utils" + "xorm.io/xorm" +) + +func GetNotice(eg *xorm.Engine, param map[string]string) (*[]model.Notice, int64) { + var order []model.Notice + sess := eg.Where("1=1") + size := utils.StrToInt(param["limit"]) + start := (utils.StrToInt(param["page"]) - 1) * size + count, err := sess.Limit(size, start).OrderBy("id desc").FindAndCount(&order) + if err != nil { + return nil, count + } + return &order, count +} + +func GetNoticeById(eg *xorm.Engine, id string) *model.Notice { + var data model.Notice + get, err := eg.Where("id=?", id).Get(&data) + if get == false || err != nil { + return nil + } + return &data +} +func GetNoticeByDateCount(eg *xorm.Engine, date string) int64 { + count, _ := eg.Where("date=?", date).Count(&model.Notice{}) + return count +} +func GetNoticeByDate(eg *xorm.Engine, date string) *model.Notice { + var data model.Notice + get, err := eg.Where("date=?", date).Get(&data) + if get == false || err != nil { + return nil + } + return &data +} diff --git a/app/db/model/notice.go b/app/db/model/notice.go new file mode 100644 index 0000000..3f20523 --- /dev/null +++ b/app/db/model/notice.go @@ -0,0 +1,12 @@ +package model + +import ( + "time" +) + +type Notice struct { + Id int `json:"id" xorm:"not null pk autoincr INT(11)"` + Date string `json:"date" xorm:"VARCHAR(1000)"` + Content string `json:"content" xorm:"VARCHAR(1000)"` + UpdateAt time.Time `json:"update_at" xorm:"DATETIME"` +} diff --git a/app/router/admin_router.go b/app/router/admin_router.go index f7a914f..e947e9c 100644 --- a/app/router/admin_router.go +++ b/app/router/admin_router.go @@ -148,6 +148,9 @@ func rOrder(r *gin.RouterGroup) { r.POST("/addNum", orderHdl.OrderAddNum) //用户订单增加数量 r.POST("/deductNum", orderHdl.OrderDeductNum) //用户订单减少数量 r.POST("/makeRecord", orderHdl.MarkRecord) //制作记录 + r.POST("/notice", orderHdl.NoticeList) //公告 + r.POST("/notice_save", orderHdl.NoticeSave) //公告 + r.POST("/notice_del", orderHdl.NoticeDel) //公告 } func rDataStatistics(r *gin.RouterGroup) { diff --git a/app/router/big_data_router.go b/app/router/big_data_router.go index a72ba54..5d45fd6 100644 --- a/app/router/big_data_router.go +++ b/app/router/big_data_router.go @@ -30,5 +30,5 @@ func rData(r *gin.RouterGroup) { r.GET("/new_sorting_goods_cate", hdl.NewSortingGoodsCate) //分拣区 按商品 r.POST("/new_sorting_goods_data", hdl.NewSortingGoodsData) //分拣区 按商品 数据 - + r.POST("/notice", hdl.Notice) }