Blame view

API/SysAds.go 4.3 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":"5e858c09b1d67b2d117e2e58","Site":"景区选择页","Size":{"Width":100,"Height":100},"Type":"轮播","Picture":[{"Src":"/Upload/1585820891339307000.png","Link":"222"}],"Video":[]}}"
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":"5e858c09b1d67b2d117e2e58","Site":"景区选择页","Size":{"Width":100,"Height":100},"Type":"轮播","Picture":[{"Src":"/Upload/1585820891339307000.png","Link":"222"}],"Video":[]}]}"
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   Site     Height    string     true        "位置"
// @Param   Height     100    string     true        "尺寸"
// @Param   Width     100    string     true        "尺寸"
// @Param   Type     单视频    string     true        "类型(轮播|单图|单视频)"
// @Param   Picture     [{"Src":"/Upload/1585820891339307000.png","Link":"222"}]    string     true        "图片"
// @Param   Video     [{"Src":"../plugins/images/defaultpic.png","Link":"22","Title":"22","VideoPicture":"/Upload/1585821569540095000.png"}]    string     true        "视频"
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
138
139
// @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",
	})

}