Commit 15b2f9239a9765773826ec194f5e7f17249dfe59
1 parent
f56bf95d
Exists in
v1.2
and in
1 other branch
..
Showing
4 changed files
with
213 additions
and
0 deletions
Show diff stats
| @@ -0,0 +1,137 @@ | @@ -0,0 +1,137 @@ | ||
| 1 | +package Api | ||
| 2 | + | ||
| 3 | +import ( | ||
| 4 | + "encoding/json" | ||
| 5 | + "github.com/aarongao/tools" | ||
| 6 | + "github.com/asaskevich/govalidator" | ||
| 7 | + "github.com/gin-gonic/gin" | ||
| 8 | + "go.mongodb.org/mongo-driver/bson" | ||
| 9 | + "go.mongodb.org/mongo-driver/bson/primitive" | ||
| 10 | + "letu/DB" | ||
| 11 | + "letu/Lib/Auth" | ||
| 12 | + "strconv" | ||
| 13 | +) | ||
| 14 | + | ||
| 15 | +// @Title 查询系统广告 | ||
| 16 | +// @Description 查询系统广告-单条 | ||
| 17 | +// @Accept json | ||
| 18 | +// @Produce json | ||
| 19 | +// @Param id 5dfb03070a9ac17ac7a82054 string true "id" | ||
| 20 | +// @Success 200 {object} tools.ResponseSeccess "{"errcode":0,"result":{"Id":"5e82d2539561231535f72958","Title":"系统广告2","Url":"http://www.google.cn","CreateTime":1585631827,"UpdateTime":0,"Expiry":1585670400,"ExpiryString":"今天"}}" | ||
| 21 | +// @Failure 500 {object} tools.ResponseError "{"errcode":1,"errmsg":"错误原因"}" | ||
| 22 | +// @Router /SysAds/Info? [get] | ||
| 23 | +func SysAdsInfo(c *gin.Context) { | ||
| 24 | + c.Header("Access-Control-Allow-Origin", c.Request.Header.Get("Origin")) | ||
| 25 | + c.Header("Access-Control-Allow-Credentials", "true") | ||
| 26 | + | ||
| 27 | + var aSysAds *DB.SSysAds | ||
| 28 | + objId, _ := primitive.ObjectIDFromHex(c.Query("id")) | ||
| 29 | + DB.CSysAds.FindOne(tools.GetContext(), bson.M{"_id": objId}).Decode(&aSysAds) | ||
| 30 | + | ||
| 31 | + c.JSON(200, tools.ResponseSeccess{ | ||
| 32 | + 0, | ||
| 33 | + aSysAds, | ||
| 34 | + }) | ||
| 35 | +} | ||
| 36 | + | ||
| 37 | +// @Title 查询系统广告 | ||
| 38 | +// @Description 查询系统广告-列表 | ||
| 39 | +// @Accept json | ||
| 40 | +// @Produce json | ||
| 41 | +// @Success 200 {object} tools.ResponseSeccess "{"errcode":0,"result":[{"Id":"5e82c27f41914b0fdcac489f","Title":"系统广告","Url":"http://www.google.cn","CreateTime":1585627775,"UpdateTime":0,"Expiry":1585670400,"ExpiryString":"今天"}...]}" | ||
| 42 | +// @Failure 500 {object} tools.ResponseError "{"errcode":1,"errmsg":"错误原因"}" | ||
| 43 | +// @Router /SysAds/List? [get] | ||
| 44 | +func SysAdsList(c *gin.Context) { | ||
| 45 | + c.Header("Access-Control-Allow-Origin", c.Request.Header.Get("Origin")) | ||
| 46 | + c.Header("Access-Control-Allow-Credentials", "true") | ||
| 47 | + | ||
| 48 | + var aSysAds []*DB.SSysAds | ||
| 49 | + | ||
| 50 | + cur, err := DB.CSysAds.Find(tools.GetContext(), bson.M{}) // | ||
| 51 | + defer cur.Close(tools.GetContext()) | ||
| 52 | + if err == nil { | ||
| 53 | + for cur.Next(tools.GetContext()) { | ||
| 54 | + var e *DB.SSysAds | ||
| 55 | + cur.Decode(&e) | ||
| 56 | + aSysAds = append(aSysAds, e) | ||
| 57 | + } | ||
| 58 | + } | ||
| 59 | + | ||
| 60 | + if aSysAds == nil { | ||
| 61 | + aSysAds = []*DB.SSysAds{} | ||
| 62 | + } | ||
| 63 | + c.JSON(200, tools.ResponseSeccess{ | ||
| 64 | + 0, | ||
| 65 | + aSysAds, | ||
| 66 | + }) | ||
| 67 | +} | ||
| 68 | + | ||
| 69 | + | ||
| 70 | +// @Title 修改系统广告 | ||
| 71 | +// @Description 修改系统广告 | ||
| 72 | +// @Accept json | ||
| 73 | +// @Produce json | ||
| 74 | +// @Param id 5dfb03070a9ac17ac7a82054 string true "系统广告id" | ||
| 75 | +// @Param ScenicId wgergejfwe string true "景区id" | ||
| 76 | +// @Param Title 营业时间系统广告 string true "系统广告名称" | ||
| 77 | +// @Param Url http://abc.com string true "系统广告链接" | ||
| 78 | +// @Param ExpiryString http://abc.com string true "有效期(15分钟|1小时|今天|今年)" | ||
| 79 | +// @Param Token wgergejfwe string true "用户token" | ||
| 80 | +// @Success 200 {object} tools.ResponseSeccess "{"errcode":0,"result":"ok"}" | ||
| 81 | +// @Failure 500 {object} tools.ResponseError "{"errcode":1,"errmsg":"错误原因"}" | ||
| 82 | +// @Router /SysAds/Modify? [post] | ||
| 83 | +func ModifySysAds(c *gin.Context) { | ||
| 84 | + c.Header("Access-Control-Allow-Origin", c.Request.Header.Get("Origin")) | ||
| 85 | + c.Header("Access-Control-Allow-Credentials", "true") | ||
| 86 | + | ||
| 87 | + _user, _ := c.Get("UserInfo") | ||
| 88 | + user := _user.(*DB.SMember) | ||
| 89 | + | ||
| 90 | + err := Auth.CheckScenicAuth(c.PostForm("ScenicId"), user) | ||
| 91 | + if err != nil { | ||
| 92 | + c.JSON(200, tools.ResponseError{ | ||
| 93 | + 401, | ||
| 94 | + "没有权限", | ||
| 95 | + }) | ||
| 96 | + return | ||
| 97 | + } | ||
| 98 | + | ||
| 99 | + objectID, _ := primitive.ObjectIDFromHex(c.PostForm("id")) | ||
| 100 | + | ||
| 101 | + width, _ := strconv.ParseInt(c.PostForm("Width"), 0, 64) | ||
| 102 | + height, _ := strconv.ParseInt(c.PostForm("Height"), 0, 64) | ||
| 103 | + | ||
| 104 | + var aPictures []DB.SPicture | ||
| 105 | + json.Unmarshal([]byte(c.PostForm("Picture")), &aPictures) | ||
| 106 | + | ||
| 107 | + var aVideo []DB.SVideo | ||
| 108 | + json.Unmarshal([]byte(c.PostForm("Video")), &aVideo) | ||
| 109 | + | ||
| 110 | + SysAds := &DB.SSysAds{ | ||
| 111 | + &objectID, | ||
| 112 | + c.PostForm("Site"), | ||
| 113 | + DB.SSize{width, height}, | ||
| 114 | + c.PostForm("Type"), | ||
| 115 | + aPictures, | ||
| 116 | + aVideo, | ||
| 117 | + } | ||
| 118 | + _, err = govalidator.ValidateStruct(SysAds); | ||
| 119 | + if err != nil { | ||
| 120 | + c.JSON(200, tools.ResponseError{ | ||
| 121 | + 1, | ||
| 122 | + err.Error(), | ||
| 123 | + }) | ||
| 124 | + return | ||
| 125 | + } | ||
| 126 | + | ||
| 127 | + _, err = DB.CSysAds.UpdateOne(tools.GetContext(), | ||
| 128 | + bson.M{"_id": objectID}, | ||
| 129 | + bson.M{"$set": SysAds}, | ||
| 130 | + ) | ||
| 131 | + | ||
| 132 | + c.JSON(200, tools.ResponseSeccess{ | ||
| 133 | + 0, | ||
| 134 | + "ok", | ||
| 135 | + }) | ||
| 136 | + | ||
| 137 | +} |
DB/db.go
| @@ -24,6 +24,7 @@ var CIcons *mongo.Collection //图标信息 | @@ -24,6 +24,7 @@ var CIcons *mongo.Collection //图标信息 | ||
| 24 | var CDevice *mongo.Collection //设备清单 | 24 | var CDevice *mongo.Collection //设备清单 |
| 25 | var CNotice *mongo.Collection //公告 | 25 | var CNotice *mongo.Collection //公告 |
| 26 | var CTopMenus *mongo.Collection //菜单 | 26 | var CTopMenus *mongo.Collection //菜单 |
| 27 | +var CSysAds *mongo.Collection //平台广告 | ||
| 27 | var DB *mongo.Database | 28 | var DB *mongo.Database |
| 28 | 29 | ||
| 29 | type SItem struct { | 30 | type SItem struct { |
| @@ -204,6 +205,18 @@ type SVideo struct { | @@ -204,6 +205,18 @@ type SVideo struct { | ||
| 204 | VideoPicture string `bson:"VideoPicture" json:"VideoPicture"` // 用于视频的首桢图 | 205 | VideoPicture string `bson:"VideoPicture" json:"VideoPicture"` // 用于视频的首桢图 |
| 205 | Title string `bson:"Title" json:"Title"` // 标题 | 206 | Title string `bson:"Title" json:"Title"` // 标题 |
| 206 | } | 207 | } |
| 208 | +type SSize struct { | ||
| 209 | + Width int64 `bson:"Width" json:"Width"` | ||
| 210 | + Height int64 `bson:"Height" json:"Height"` | ||
| 211 | +} | ||
| 212 | +type SSysAds struct { | ||
| 213 | + Id *primitive.ObjectID `bson:"_id" json:"Id" valid:"required"` | ||
| 214 | + Site string `bson:"Site" json:"Site" valid:"required"` // 位置 | ||
| 215 | + Size SSize `bson:"Size" json:"Size" valid:"required"` // 尺寸 | ||
| 216 | + Type string `bson:"Type" json:"Type" valid:"required,in(轮播|单图|单视频)"` // 类型 | ||
| 217 | + Picture []SPicture `bson:"Picture" json:"Picture"` // 图片 | ||
| 218 | + Video []SVideo `bson:"Video" json:"Video"` // 视频 | ||
| 219 | +} | ||
| 207 | type SScenic struct { | 220 | type SScenic struct { |
| 208 | Id *primitive.ObjectID `bson:"_id" json:"Id" valid:"required"` | 221 | Id *primitive.ObjectID `bson:"_id" json:"Id" valid:"required"` |
| 209 | Name string `bson:"Name" json:"Name"` | 222 | Name string `bson:"Name" json:"Name"` |
README.md
| @@ -43,6 +43,9 @@ | @@ -43,6 +43,9 @@ | ||
| 43 | 1. [用户管理 - 删除用户(注销)](#removeuser-post) | 43 | 1. [用户管理 - 删除用户(注销)](#removeuser-post) |
| 44 | 1. [返回景区基础信息](#scenicinfo-get) | 44 | 1. [返回景区基础信息](#scenicinfo-get) |
| 45 | 1. [发送短信验证码](#sms-send-post) | 45 | 1. [发送短信验证码](#sms-send-post) |
| 46 | +1. [查询系统广告-单条](#sysads-info-get) | ||
| 47 | +1. [查询系统广告-列表](#sysads-list-get) | ||
| 48 | +1. [修改系统广告](#sysads-modify-post) | ||
| 46 | 1. [查询系统信息接口](#systeminfo-get) | 49 | 1. [查询系统信息接口](#systeminfo-get) |
| 47 | 1. [标签 - 增加标签](#tag-create-post) | 50 | 1. [标签 - 增加标签](#tag-create-post) |
| 48 | 1. [标签 - 删除标签](#tag-remove-post) | 51 | 1. [标签 - 删除标签](#tag-remove-post) |
| @@ -761,6 +764,61 @@ | @@ -761,6 +764,61 @@ | ||
| 761 | 764 | ||
| 762 | 765 | ||
| 763 | 766 | ||
| 767 | +<a name="sysads-info-get"></a> | ||
| 768 | + | ||
| 769 | +#### /SysAds/Info (GET) | ||
| 770 | + | ||
| 771 | + | ||
| 772 | +查询系统广告-单条 | ||
| 773 | + | ||
| 774 | +| Param Name | Example | Data Type | Description | Required? | | ||
| 775 | +|-----|-----|-----|-----|-----| | ||
| 776 | +| id | 5dfb03070a9ac17ac7a82054 | string | id | Yes | | ||
| 777 | + | ||
| 778 | + | ||
| 779 | +| Code | Type | Model | Message | | ||
| 780 | +|-----|-----|-----|-----| | ||
| 781 | +| 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":"今天"}} | | ||
| 782 | +| 500 | object | [ResponseError](#github.com.aarongao.tools.ResponseError) | {"errcode":1,"errmsg":"错误原因"} | | ||
| 783 | + | ||
| 784 | + | ||
| 785 | +<a name="sysads-list-get"></a> | ||
| 786 | + | ||
| 787 | +#### /SysAds/List (GET) | ||
| 788 | + | ||
| 789 | + | ||
| 790 | +查询系统广告-列表 | ||
| 791 | + | ||
| 792 | +| Code | Type | Model | Message | | ||
| 793 | +|-----|-----|-----|-----| | ||
| 794 | +| 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":"今天"}...]} | | ||
| 795 | +| 500 | object | [ResponseError](#github.com.aarongao.tools.ResponseError) | {"errcode":1,"errmsg":"错误原因"} | | ||
| 796 | + | ||
| 797 | + | ||
| 798 | +<a name="sysads-modify-post"></a> | ||
| 799 | + | ||
| 800 | +#### /SysAds/Modify (POST) | ||
| 801 | + | ||
| 802 | + | ||
| 803 | +修改系统广告 | ||
| 804 | + | ||
| 805 | +| Param Name | Example | Data Type | Description | Required? | | ||
| 806 | +|-----|-----|-----|-----|-----| | ||
| 807 | +| id | 5dfb03070a9ac17ac7a82054 | string | 系统广告id | Yes | | ||
| 808 | +| ScenicId | wgergejfwe | string | 景区id | Yes | | ||
| 809 | +| Title | 营业时间系统广告 | string | 系统广告名称 | Yes | | ||
| 810 | +| Url | http://abc.com | string | 系统广告链接 | Yes | | ||
| 811 | +| ExpiryString | http://abc.com | string | 有效期(15分钟|1小时|今天|今年) | Yes | | ||
| 812 | +| Token | wgergejfwe | string | 用户token | Yes | | ||
| 813 | + | ||
| 814 | + | ||
| 815 | +| Code | Type | Model | Message | | ||
| 816 | +|-----|-----|-----|-----| | ||
| 817 | +| 200 | object | [ResponseSeccess](#github.com.aarongao.tools.ResponseSeccess) | {"errcode":0,"result":"ok"} | | ||
| 818 | +| 500 | object | [ResponseError](#github.com.aarongao.tools.ResponseError) | {"errcode":1,"errmsg":"错误原因"} | | ||
| 819 | + | ||
| 820 | + | ||
| 821 | + | ||
| 764 | <a name="systeminfo-get"></a> | 822 | <a name="systeminfo-get"></a> |
| 765 | 823 | ||
| 766 | #### /SystemInfo (GET) | 824 | #### /SystemInfo (GET) |
main.go
| @@ -94,6 +94,7 @@ func main() { | @@ -94,6 +94,7 @@ func main() { | ||
| 94 | DB.CIcons = DB.DB.Collection("Icons") | 94 | DB.CIcons = DB.DB.Collection("Icons") |
| 95 | DB.CDevice = DB.DB.Collection("Device") | 95 | DB.CDevice = DB.DB.Collection("Device") |
| 96 | DB.CNotice = DB.DB.Collection("Notice") | 96 | DB.CNotice = DB.DB.Collection("Notice") |
| 97 | + DB.CSysAds = DB.DB.Collection("SysAds") | ||
| 97 | DB.CTopMenus = DB.DB.Collection("TopMenu") | 98 | DB.CTopMenus = DB.DB.Collection("TopMenu") |
| 98 | DB.COperatorLog = DB.DB.Collection("OperatorLog") | 99 | DB.COperatorLog = DB.DB.Collection("OperatorLog") |
| 99 | DelayMessage.CDelayMessage = DB.DB.Collection("DelayMessage") | 100 | DelayMessage.CDelayMessage = DB.DB.Collection("DelayMessage") |
| @@ -172,6 +173,10 @@ func main() { | @@ -172,6 +173,10 @@ func main() { | ||
| 172 | InitController("GET", "/AllOperator", Api.AllOperator, &DB.SModel{"操作员管理", "查看所有"}) | 173 | InitController("GET", "/AllOperator", Api.AllOperator, &DB.SModel{"操作员管理", "查看所有"}) |
| 173 | InitController("GET", "/SystemInfo", Api.SystemInfo, &DB.SModel{}) | 174 | InitController("GET", "/SystemInfo", Api.SystemInfo, &DB.SModel{}) |
| 174 | 175 | ||
| 176 | + // 平台广外位 | ||
| 177 | + InitController("GET", "/SysAds/Info", Api.SysAdsInfo, &DB.SModel{}) | ||
| 178 | + InitController("GET", "/SysAds/List", Api.SysAdsList, &DB.SModel{}) | ||
| 179 | + InitController("POST", "/SysAds/Modify", Api.ModifySysAds, &DB.SModel{"平台广告", "修改"}) | ||
| 175 | 180 | ||
| 176 | Gin.GET("/AllModules", Auth.Modules) | 181 | Gin.GET("/AllModules", Auth.Modules) |
| 177 | //InitController("/ws", Api.WsPage) | 182 | //InitController("/ws", Api.WsPage) |