diff --git a/API/SysAds.go b/API/SysAds.go
new file mode 100644
index 0000000..4d6f00f
--- /dev/null
+++ b/API/SysAds.go
@@ -0,0 +1,137 @@
+package Api
+
+import (
+ "encoding/json"
+ "github.com/aarongao/tools"
+ "github.com/asaskevich/govalidator"
+ "github.com/gin-gonic/gin"
+ "go.mongodb.org/mongo-driver/bson"
+ "go.mongodb.org/mongo-driver/bson/primitive"
+ "letu/DB"
+ "letu/Lib/Auth"
+ "strconv"
+)
+
+// @Title 查询系统广告
+// @Description 查询系统广告-单条
+// @Accept json
+// @Produce json
+// @Param id 5dfb03070a9ac17ac7a82054 string true "id"
+// @Success 200 {object} tools.ResponseSeccess "{"errcode":0,"result":{"Id":"5e82d2539561231535f72958","Title":"系统广告2","Url":"http://www.google.cn","CreateTime":1585631827,"UpdateTime":0,"Expiry":1585670400,"ExpiryString":"今天"}}"
+// @Failure 500 {object} tools.ResponseError "{"errcode":1,"errmsg":"错误原因"}"
+// @Router /SysAds/Info? [get]
+func SysAdsInfo(c *gin.Context) {
+ c.Header("Access-Control-Allow-Origin", c.Request.Header.Get("Origin"))
+ c.Header("Access-Control-Allow-Credentials", "true")
+
+ var aSysAds *DB.SSysAds
+ objId, _ := primitive.ObjectIDFromHex(c.Query("id"))
+ DB.CSysAds.FindOne(tools.GetContext(), bson.M{"_id": objId}).Decode(&aSysAds)
+
+ c.JSON(200, tools.ResponseSeccess{
+ 0,
+ aSysAds,
+ })
+}
+
+// @Title 查询系统广告
+// @Description 查询系统广告-列表
+// @Accept json
+// @Produce json
+// @Success 200 {object} tools.ResponseSeccess "{"errcode":0,"result":[{"Id":"5e82c27f41914b0fdcac489f","Title":"系统广告","Url":"http://www.google.cn","CreateTime":1585627775,"UpdateTime":0,"Expiry":1585670400,"ExpiryString":"今天"}...]}"
+// @Failure 500 {object} tools.ResponseError "{"errcode":1,"errmsg":"错误原因"}"
+// @Router /SysAds/List? [get]
+func SysAdsList(c *gin.Context) {
+ c.Header("Access-Control-Allow-Origin", c.Request.Header.Get("Origin"))
+ c.Header("Access-Control-Allow-Credentials", "true")
+
+ var aSysAds []*DB.SSysAds
+
+ cur, err := DB.CSysAds.Find(tools.GetContext(), bson.M{}) //
+ defer cur.Close(tools.GetContext())
+ if err == nil {
+ for cur.Next(tools.GetContext()) {
+ var e *DB.SSysAds
+ cur.Decode(&e)
+ aSysAds = append(aSysAds, e)
+ }
+ }
+
+ if aSysAds == nil {
+ aSysAds = []*DB.SSysAds{}
+ }
+ c.JSON(200, tools.ResponseSeccess{
+ 0,
+ aSysAds,
+ })
+}
+
+
+// @Title 修改系统广告
+// @Description 修改系统广告
+// @Accept json
+// @Produce json
+// @Param id 5dfb03070a9ac17ac7a82054 string true "系统广告id"
+// @Param ScenicId wgergejfwe string true "景区id"
+// @Param Title 营业时间系统广告 string true "系统广告名称"
+// @Param Url http://abc.com string true "系统广告链接"
+// @Param ExpiryString http://abc.com string true "有效期(15分钟|1小时|今天|今年)"
+// @Param Token wgergejfwe string true "用户token"
+// @Success 200 {object} tools.ResponseSeccess "{"errcode":0,"result":"ok"}"
+// @Failure 500 {object} tools.ResponseError "{"errcode":1,"errmsg":"错误原因"}"
+// @Router /SysAds/Modify? [post]
+func ModifySysAds(c *gin.Context) {
+ c.Header("Access-Control-Allow-Origin", c.Request.Header.Get("Origin"))
+ c.Header("Access-Control-Allow-Credentials", "true")
+
+ _user, _ := c.Get("UserInfo")
+ user := _user.(*DB.SMember)
+
+ err := Auth.CheckScenicAuth(c.PostForm("ScenicId"), user)
+ if err != nil {
+ c.JSON(200, tools.ResponseError{
+ 401,
+ "没有权限",
+ })
+ return
+ }
+
+ objectID, _ := primitive.ObjectIDFromHex(c.PostForm("id"))
+
+ width, _ := strconv.ParseInt(c.PostForm("Width"), 0, 64)
+ height, _ := strconv.ParseInt(c.PostForm("Height"), 0, 64)
+
+ var aPictures []DB.SPicture
+ json.Unmarshal([]byte(c.PostForm("Picture")), &aPictures)
+
+ var aVideo []DB.SVideo
+ json.Unmarshal([]byte(c.PostForm("Video")), &aVideo)
+
+ SysAds := &DB.SSysAds{
+ &objectID,
+ c.PostForm("Site"),
+ DB.SSize{width, height},
+ c.PostForm("Type"),
+ aPictures,
+ aVideo,
+ }
+ _, err = govalidator.ValidateStruct(SysAds);
+ if err != nil {
+ c.JSON(200, tools.ResponseError{
+ 1,
+ err.Error(),
+ })
+ return
+ }
+
+ _, err = DB.CSysAds.UpdateOne(tools.GetContext(),
+ bson.M{"_id": objectID},
+ bson.M{"$set": SysAds},
+ )
+
+ c.JSON(200, tools.ResponseSeccess{
+ 0,
+ "ok",
+ })
+
+}
diff --git a/DB/db.go b/DB/db.go
index 52cac7c..d0d9d66 100644
--- a/DB/db.go
+++ b/DB/db.go
@@ -24,6 +24,7 @@ var CIcons *mongo.Collection //图标信息
var CDevice *mongo.Collection //设备清单
var CNotice *mongo.Collection //公告
var CTopMenus *mongo.Collection //菜单
+var CSysAds *mongo.Collection //平台广告
var DB *mongo.Database
type SItem struct {
@@ -204,6 +205,18 @@ type SVideo struct {
VideoPicture string `bson:"VideoPicture" json:"VideoPicture"` // 用于视频的首桢图
Title string `bson:"Title" json:"Title"` // 标题
}
+type SSize struct {
+ Width int64 `bson:"Width" json:"Width"`
+ Height int64 `bson:"Height" json:"Height"`
+}
+type SSysAds struct {
+ Id *primitive.ObjectID `bson:"_id" json:"Id" valid:"required"`
+ Site string `bson:"Site" json:"Site" valid:"required"` // 位置
+ Size SSize `bson:"Size" json:"Size" valid:"required"` // 尺寸
+ Type string `bson:"Type" json:"Type" valid:"required,in(轮播|单图|单视频)"` // 类型
+ Picture []SPicture `bson:"Picture" json:"Picture"` // 图片
+ Video []SVideo `bson:"Video" json:"Video"` // 视频
+}
type SScenic struct {
Id *primitive.ObjectID `bson:"_id" json:"Id" valid:"required"`
Name string `bson:"Name" json:"Name"`
diff --git a/README.md b/README.md
index 2e64818..899d329 100644
--- a/README.md
+++ b/README.md
@@ -43,6 +43,9 @@
1. [用户管理 - 删除用户(注销)](#removeuser-post)
1. [返回景区基础信息](#scenicinfo-get)
1. [发送短信验证码](#sms-send-post)
+1. [查询系统广告-单条](#sysads-info-get)
+1. [查询系统广告-列表](#sysads-list-get)
+1. [修改系统广告](#sysads-modify-post)
1. [查询系统信息接口](#systeminfo-get)
1. [标签 - 增加标签](#tag-create-post)
1. [标签 - 删除标签](#tag-remove-post)
@@ -761,6 +764,61 @@
+
+
+#### /SysAds/Info (GET)
+
+
+查询系统广告-单条
+
+| Param Name | Example | Data Type | Description | Required? |
+|-----|-----|-----|-----|-----|
+| id | 5dfb03070a9ac17ac7a82054 | string | id | Yes |
+
+
+| Code | Type | Model | Message |
+|-----|-----|-----|-----|
+| 200 | object | [ResponseSeccess](#github.com.aarongao.tools.ResponseSeccess) | {"errcode":0,"result":{"Id":"5e82d2539561231535f72958","Title":"系统广告2","Url":"http://www.google.cn","CreateTime":1585631827,"UpdateTime":0,"Expiry":1585670400,"ExpiryString":"今天"}} |
+| 500 | object | [ResponseError](#github.com.aarongao.tools.ResponseError) | {"errcode":1,"errmsg":"错误原因"} |
+
+
+
+
+#### /SysAds/List (GET)
+
+
+查询系统广告-列表
+
+| Code | Type | Model | Message |
+|-----|-----|-----|-----|
+| 200 | object | [ResponseSeccess](#github.com.aarongao.tools.ResponseSeccess) | {"errcode":0,"result":[{"Id":"5e82c27f41914b0fdcac489f","Title":"系统广告","Url":"http://www.google.cn","CreateTime":1585627775,"UpdateTime":0,"Expiry":1585670400,"ExpiryString":"今天"}...]} |
+| 500 | object | [ResponseError](#github.com.aarongao.tools.ResponseError) | {"errcode":1,"errmsg":"错误原因"} |
+
+
+
+
+#### /SysAds/Modify (POST)
+
+
+修改系统广告
+
+| Param Name | Example | Data Type | Description | Required? |
+|-----|-----|-----|-----|-----|
+| id | 5dfb03070a9ac17ac7a82054 | string | 系统广告id | Yes |
+| ScenicId | wgergejfwe | string | 景区id | Yes |
+| Title | 营业时间系统广告 | string | 系统广告名称 | Yes |
+| Url | http://abc.com | string | 系统广告链接 | Yes |
+| ExpiryString | http://abc.com | string | 有效期(15分钟|1小时|今天|今年) | Yes |
+| Token | wgergejfwe | string | 用户token | Yes |
+
+
+| Code | Type | Model | Message |
+|-----|-----|-----|-----|
+| 200 | object | [ResponseSeccess](#github.com.aarongao.tools.ResponseSeccess) | {"errcode":0,"result":"ok"} |
+| 500 | object | [ResponseError](#github.com.aarongao.tools.ResponseError) | {"errcode":1,"errmsg":"错误原因"} |
+
+
+
#### /SystemInfo (GET)
diff --git a/main.go b/main.go
index 8d1aea0..595b4d1 100644
--- a/main.go
+++ b/main.go
@@ -94,6 +94,7 @@ func main() {
DB.CIcons = DB.DB.Collection("Icons")
DB.CDevice = DB.DB.Collection("Device")
DB.CNotice = DB.DB.Collection("Notice")
+ DB.CSysAds = DB.DB.Collection("SysAds")
DB.CTopMenus = DB.DB.Collection("TopMenu")
DB.COperatorLog = DB.DB.Collection("OperatorLog")
DelayMessage.CDelayMessage = DB.DB.Collection("DelayMessage")
@@ -172,6 +173,10 @@ func main() {
InitController("GET", "/AllOperator", Api.AllOperator, &DB.SModel{"操作员管理", "查看所有"})
InitController("GET", "/SystemInfo", Api.SystemInfo, &DB.SModel{})
+ // 平台广外位
+ InitController("GET", "/SysAds/Info", Api.SysAdsInfo, &DB.SModel{})
+ InitController("GET", "/SysAds/List", Api.SysAdsList, &DB.SModel{})
+ InitController("POST", "/SysAds/Modify", Api.ModifySysAds, &DB.SModel{"平台广告", "修改"})
Gin.GET("/AllModules", Auth.Modules)
//InitController("/ws", Api.WsPage)
--
libgit2 0.21.0