Blame view

API/SysAds.go 4.07 KB
15b2f923   aarongao   ..
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
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"
d631c7b6   aarongao   ..
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":"今天"}}"
15b2f923   aarongao   ..
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
// @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
d631c7b6   aarongao   ..
41
// @Success 200 {object} tools.ResponseSeccess "{"errcode":0,"result":[{"Id":"5e82c27f41914b0fdcac489f","Title":"系统广告","Url":"http://www.google.cn","CreateTime":1585627775,"UpdateTime":0,"Expiry":1585670400,"ExpiryString":"今天"}...]}"
15b2f923   aarongao   ..
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
// @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,
	})
}


d631c7b6   aarongao   ..
70
71
// @Title 修改系统广告
// @Description 修改系统广告
15b2f923   aarongao   ..
72
73
// @Accept  json
// @Produce  json
d631c7b6   aarongao   ..
74
75
76
77
78
79
80
// @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"}"
15b2f923   aarongao   ..
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
// @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",
	})

}