diff --git a/.idea/inspectionProfiles/Project_Default.xml b/.idea/inspectionProfiles/Project_Default.xml
new file mode 100644
index 0000000..eff7139
--- /dev/null
+++ b/.idea/inspectionProfiles/Project_Default.xml
@@ -0,0 +1,6 @@
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/jsLinters/jshint.xml b/.idea/jsLinters/jshint.xml
new file mode 100644
index 0000000..a9764b7
--- /dev/null
+++ b/.idea/jsLinters/jshint.xml
@@ -0,0 +1,16 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/letu.iml b/.idea/letu.iml
new file mode 100644
index 0000000..c956989
--- /dev/null
+++ b/.idea/letu.iml
@@ -0,0 +1,8 @@
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/misc.xml b/.idea/misc.xml
new file mode 100644
index 0000000..28a804d
--- /dev/null
+++ b/.idea/misc.xml
@@ -0,0 +1,6 @@
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/modules.xml b/.idea/modules.xml
new file mode 100644
index 0000000..e83c291
--- /dev/null
+++ b/.idea/modules.xml
@@ -0,0 +1,8 @@
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/vcs.xml b/.idea/vcs.xml
new file mode 100644
index 0000000..94a25f7
--- /dev/null
+++ b/.idea/vcs.xml
@@ -0,0 +1,6 @@
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/workspace.xml b/.idea/workspace.xml
new file mode 100644
index 0000000..dcf6355
--- /dev/null
+++ b/.idea/workspace.xml
@@ -0,0 +1,128 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/API/Complaint.go b/API/Complaint.go
index 7573928..cfb2ba6 100644
--- a/API/Complaint.go
+++ b/API/Complaint.go
@@ -59,7 +59,6 @@ func CreateComplaint(c *gin.Context) {
"验证码不正确",
})
return
-
}
var images []string
@@ -74,7 +73,7 @@ func CreateComplaint(c *gin.Context) {
c.PostForm("Sex"),
c.PostForm("Content"),
images,
- "",
+ "未处理",
time.Now().Unix(),
})
@@ -124,7 +123,7 @@ func AllComplaint(c *gin.Context) {
0,
total,
currPage,
- int(math.Ceil(float64(total) / float64(limit))),
+ int64(math.Ceil(float64(total) / float64(limit))),
limit,
aComplaint,
})
diff --git a/API/DealyMessage.go b/API/DealyMessage.go
index b312328..3876a63 100644
--- a/API/DealyMessage.go
+++ b/API/DealyMessage.go
@@ -2,11 +2,13 @@ package Api
import (
"github.com/aarongao/tools"
+ "github.com/aliyun/alibaba-cloud-sdk-go/services/push"
"github.com/gin-gonic/gin"
"go.mongodb.org/mongo-driver/bson"
"go.mongodb.org/mongo-driver/bson/primitive"
+ "letu/Config"
+ "letu/DB"
"letu/Lib/DelayMessage"
- "letu/Lib/Token"
)
// @Title 查询用户的定时提醒
@@ -15,26 +17,19 @@ import (
// @Produce json
// @Param UserId 5dfb03070a9ac17ac7a82054 string true "用户id"
// @Param Token wgergejfwe string true "用户token"
-// @Success 200 {object} tools.ResponseSeccess "DelayTime=执行时间;Type=类型(0请求url地址1发送app通知);Fail失败次数;Title=通知标题;Content=通知内容;UDID=设备id"
+// @Success 200 {object} tools.ResponseSeccess "DelayTime=执行时间;Type=类型(0请求url地址1发送app通知);Fail失败次数;Title=通知标题;Content=通知内容;DeviceToken=设备id"
// @Failure 500 {object} tools.ResponseError "{"errcode":1,"errmsg":"错误原因"}"
// @Router /DealyMessage/Info? [get]
func DealyMessageInfo(c *gin.Context) {
c.Header("Access-Control-Allow-Origin", c.Request.Header.Get("Origin"))
c.Header("Access-Control-Allow-Credentials", "true")
- _, err := primitive.ObjectIDFromHex(c.Query("UserId"))
- if c.Query("Token") == "" || err != nil {
- c.JSON(200, tools.ResponseError{
- 1,
- "Token或者用户id不正确",
- })
- return
- }
-
- if Token.GetToken(c.Query("UserId")) != c.Query("Token") {
+ _user, _ := c.Get("UserInfo")
+ user := _user.(*DB.SMember)
+ if c.Query("UserId") != user.Id.Hex() {
c.JSON(200, tools.ResponseError{
401,
- "token过期",
+ "没有权限",
})
return
}
@@ -46,7 +41,7 @@ func DealyMessageInfo(c *gin.Context) {
for cur.Next(tools.GetContext()) {
var e DelayMessage.Message
cur.Decode(&e)
- aDelayMessage = append(aDelayMessage,e)
+ aDelayMessage = append(aDelayMessage, e)
}
}
@@ -65,7 +60,7 @@ func DealyMessageInfo(c *gin.Context) {
// @Produce json
// @Param UserId 5dfb03070a9ac17ac7a82054 string true "用户id"
// @Param Token wgergejfwe string true "用户token"
-// @Param UDID 5dfb03070a9ac17ac7a82054 string true "设备id"
+// @Param DeviceToken 5dfb03070a9ac17ac7a82054 string true "设备id"
// @Param Title 表演时间提醒 string true "标题"
// @Param Content 5分钟后有表演 string true "内容"
// @Param DelayTime 1579066863 string true "到达这个时间戳就执行"
@@ -76,24 +71,27 @@ func CreateDealyMessage(c *gin.Context) {
c.Header("Access-Control-Allow-Origin", c.Request.Header.Get("Origin"))
c.Header("Access-Control-Allow-Credentials", "true")
- _,err := primitive.ObjectIDFromHex(c.PostForm("UserId"))
- if c.PostForm("Token") == "" || err != nil {
+
+ _user, _ := c.Get("UserInfo")
+ userToken := _user.(*DB.SMember)
+ if c.PostForm("UserId") != userToken.Id.Hex(){
c.JSON(200, tools.ResponseError{
- 1,
- "Token或者用户id不正确",
+ 401,
+ "没有权限",
})
return
}
- if Token.GetToken(c.PostForm("UserId")) != c.PostForm("Token") {
+ _, err := primitive.ObjectIDFromHex(c.PostForm("UserId"))
+ if err != nil {
c.JSON(200, tools.ResponseError{
- 401,
- "token过期",
+ 1,
+ "id不正确",
})
return
}
- err = DelayMessage.GlobalDM.AddTaskForAppMessage(c.PostForm("DelayTime"), c.PostForm("UDID"), c.PostForm("Title"), c.PostForm("Content"), c.PostForm("UserId"))
+ err = DelayMessage.GlobalDM.AddTaskForAppMessage(c.PostForm("DelayTime"), c.PostForm("DeviceToken"), c.PostForm("Title"), c.PostForm("Content"), c.PostForm("UserId"))
if err == nil {
@@ -125,20 +123,21 @@ func RemoveDealyMessage(c *gin.Context) {
c.Header("Access-Control-Allow-Origin", c.Request.Header.Get("Origin"))
c.Header("Access-Control-Allow-Credentials", "true")
-
- _,err := primitive.ObjectIDFromHex(c.PostForm("UserId"))
- if c.PostForm("Token") == "" || err != nil {
+ _user, _ := c.Get("UserInfo")
+ userToken := _user.(*DB.SMember)
+ if c.PostForm("UserId") != userToken.Id.Hex(){
c.JSON(200, tools.ResponseError{
- 1,
- "Token或者用户id不正确",
+ 401,
+ "没有权限",
})
return
}
- if Token.GetToken(c.PostForm("UserId")) != c.PostForm("Token") {
+ _, err := primitive.ObjectIDFromHex(c.PostForm("UserId"))
+ if err != nil {
c.JSON(200, tools.ResponseError{
- 401,
- "token过期",
+ 1,
+ "用户id不正确",
})
return
}
@@ -151,3 +150,34 @@ func RemoveDealyMessage(c *gin.Context) {
})
}
+
+
+func PushNoticeToiOS(c *gin.Context) {
+ c.Header("Access-Control-Allow-Origin", c.Request.Header.Get("Origin"))
+ c.Header("Access-Control-Allow-Credentials", "true")
+
+ // 推送app消息
+ client, err := push.NewClientWithAccessKey("cn-hangzhou", "LTAI4FdQeNMQXRU6u5J3EFQc", "PwvyF5rRNBWLDya41WrCpvENevYZGi")
+
+ request := push.CreatePushNoticeToiOSRequest()
+ request.ApnsEnv = Config.Info.Env
+ request.AppKey = "28332889"
+ request.Scheme = "https"
+ request.Target = "DEVICE"
+ request.TargetValue = "30076ed6fdb740e49d882433931bc34a"
+ request.Title = c.Query("title")
+ request.Body = c.Query("body")
+
+ response, err := client.PushNoticeToiOS(request)
+ if err != nil {
+ c.JSON(200, tools.ResponseError{
+ 1,
+ err.Error(),
+ })
+ return
+ }
+ c.JSON(200, tools.ResponseSeccess{
+ 0,
+ response,
+ })
+}
\ No newline at end of file
diff --git a/API/Icon.go b/API/Icon.go
index 1bebfe7..6d6292d 100644
--- a/API/Icon.go
+++ b/API/Icon.go
@@ -7,6 +7,7 @@ import (
"go.mongodb.org/mongo-driver/bson/primitive"
"go.mongodb.org/mongo-driver/mongo/options"
"letu/DB"
+ "letu/Lib/Auth"
)
// @Title 返回图标基础信息
@@ -45,6 +46,8 @@ func IconInfo(c *gin.Context) {
// @Accept json
// @Produce json
// @Param id 5dfb03070a9ac17ac7a82054 string true "图标id"
+// @Param ScenicId 5e0d504e24e03431008b4567 string true "景区id"
+// @Param Token wgergejfwe string true "用户token"
// @Success 200 {object} tools.ResponseSeccess "Name名称:Picture图片地址:id图标id:ScenicId景区id"
// @Failure 500 {object} tools.ResponseError "{"errcode":1,"errmsg":"错误原因"}"
// @Router /Icon/Update? [post]
@@ -52,11 +55,13 @@ func UpdateIcon(c *gin.Context) {
c.Header("Access-Control-Allow-Origin", c.Request.Header.Get("Origin"))
c.Header("Access-Control-Allow-Credentials", "true")
- ScenicId := c.PostForm("ScenicId")
- if ScenicId == "" || ScenicId == "undefined" {
+ _user, _ := c.Get("UserInfo")
+ user := _user.(*DB.SMember)
+ err := Auth.CheckScenicAuth(c.PostForm("ScenicId"), user)
+ if err != nil {
c.JSON(200, tools.ResponseError{
- 1,
- "缺少ScenicId(景区id)",
+ 401,
+ "没有权限",
})
return
}
@@ -74,7 +79,7 @@ func UpdateIcon(c *gin.Context) {
bson.M{"$set": bson.M{
"Name": c.PostForm("Name"),
"Picture": c.PostForm("Picture"),
- "ScenicId": ScenicId,
+ "ScenicId": c.PostForm("ScenicId"),
}}, &options.FindOneAndUpdateOptions{
Upsert: &upsert,
},
@@ -99,13 +104,9 @@ func AllIcons(c *gin.Context) {
c.Header("Access-Control-Allow-Origin", c.Request.Header.Get("Origin"))
c.Header("Access-Control-Allow-Credentials", "true")
- ScenicId := c.Query("ScenicId")
- if ScenicId == "" || ScenicId == "undefined" {
- c.JSON(200, tools.ResponseError{
- 1,
- "缺少ScenicId(景区id)",
- })
- return
+ var ScenicId string
+ if ScenicId = c.Query("ScenicId"); ScenicId == "" {
+ ScenicId = "5e0d504e24e03431008b4567" // 乐岛
}
var SIcons = []DB.SIcons{}
@@ -115,11 +116,10 @@ func AllIcons(c *gin.Context) {
for cur.Next(tools.GetContext()) {
var e DB.SIcons
cur.Decode(&e)
- SIcons = append(SIcons,e)
+ SIcons = append(SIcons, e)
}
}
-
c.JSON(200, tools.ResponseSeccess{
0,
SIcons,
diff --git a/API/Investigation.go b/API/Investigation.go
index 70f6641..7db9e47 100644
--- a/API/Investigation.go
+++ b/API/Investigation.go
@@ -80,7 +80,7 @@ func AllInvestigation(c *gin.Context) {
0,
total,
currPage,
- int(math.Ceil(float64(total) / float64(limit))),
+ int64(math.Ceil(float64(total) / float64(limit))),
limit,
aInvestigation,
})
diff --git a/API/Item.go b/API/Item.go
index 2684b69..5d74415 100644
--- a/API/Item.go
+++ b/API/Item.go
@@ -8,6 +8,7 @@ import (
"go.mongodb.org/mongo-driver/bson/primitive"
"go.mongodb.org/mongo-driver/mongo/options"
"letu/DB"
+ "letu/Lib/Auth"
"strconv"
"time"
)
@@ -33,8 +34,8 @@ func ItemInfo(c *gin.Context) {
}
var SItem DB.SItem
- objID,_ := primitive.ObjectIDFromHex(c.Query("id"))
- DB.CItem.FindOne(tools.GetContext(),bson.M{"_id": objID}).Decode(&SItem)
+ objID, _ := primitive.ObjectIDFromHex(c.Query("id"))
+ DB.CItem.FindOne(tools.GetContext(), bson.M{"_id": objID}).Decode(&SItem)
c.JSON(200, tools.ResponseSeccess{
0,
@@ -47,6 +48,7 @@ func ItemInfo(c *gin.Context) {
// @Description 设备管理 - 查询所有游玩项目
// @Accept json
// @Produce json
+// @Param ScenicId 5dfb03070a9ac17ac7a82054 string true "景区id"
// @Success 200 {object} tools.ResponseSeccess "Tags所属标签,标签有分类;LimitHeight限高;PlayDuration游玩时长;SceneTime场次时间;Picture照片;Voice音频;AverageConsumption平均消费;Menu菜单, OpenHours开放时间: LocationDescription位置描述; Reminder温馨提示; State运行状态0=正常1=停运"
// @Failure 500 {object} tools.ResponseError "{"errcode":1,"errmsg":"错误原因"}"
// @Router /AllItems? [get]
@@ -54,14 +56,19 @@ func AllItems(c *gin.Context) {
c.Header("Access-Control-Allow-Origin", c.Request.Header.Get("Origin"))
c.Header("Access-Control-Allow-Credentials", "true")
+ var ScenicId string
+ if ScenicId = c.Query("ScenicId");ScenicId == ""{
+ ScenicId = "5e0d504e24e03431008b4567" // 乐岛
+ }
+
var aItems = []DB.SItem{}
- cur, err := DB.CItem.Find(tools.GetContext(), bson.M{})
+ cur, err := DB.CItem.Find(tools.GetContext(), bson.M{"ScenicId": ScenicId})
defer cur.Close(tools.GetContext())
if err == nil {
for cur.Next(tools.GetContext()) {
var e DB.SItem
cur.Decode(&e)
- aItems = append(aItems,e)
+ aItems = append(aItems, e)
}
}
@@ -73,6 +80,9 @@ func AllItems(c *gin.Context) {
// @Description 设备管理 - 更新设施
// @Accept json
// @Produce json
+// @Param id 5dfb03070a9ac17ac7a82054 string true "设备id"
+// @Param ScenicId 5dfb03070a9ac17ac7a82054 string true "景区id"
+// @Param Token wgergejfwe string true "用户token"
// @Success 200 {object} tools.ResponseSeccess "Tags所属标签,标签有分类;LimitHeight限高;PlayDuration游玩时长;SceneTime场次时间;Picture照片;Voice音频;AverageConsumption平均消费;Menu菜单, OpenHours开放时间: LocationDescription位置描述; Reminder温馨提示; State运行状态0=正常1=停运"
// @Failure 500 {object} tools.ResponseError "{"errcode":1,"errmsg":"错误原因"}"
// @Router /UpdateItem? [post]
@@ -80,6 +90,17 @@ func UpdateItem(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
+ }
+
var Location DB.SLocation
json.Unmarshal([]byte(c.PostForm("Location")), &Location)
@@ -93,7 +114,7 @@ func UpdateItem(c *gin.Context) {
if pid := c.PostForm("id"); pid == "null" {
id = primitive.NewObjectID()
} else {
- id,_ = primitive.ObjectIDFromHex(pid)
+ id, _ = primitive.ObjectIDFromHex(pid)
}
poststate, _ := strconv.Atoi(c.PostForm("State"))
@@ -104,6 +125,7 @@ func UpdateItem(c *gin.Context) {
bson.M{"$set": bson.M{
"Name": c.PostForm("Name"),
"SubName": c.PostForm("SubName"),
+ "ScenicId": c.PostForm("ScenicId"),
"Location": Location,
"Icon": c.PostForm("Icon"),
"LimitHeight": c.PostForm("LimitHeight"),
@@ -124,24 +146,21 @@ func UpdateItem(c *gin.Context) {
},
)
-
-
// 更新等待时间
allteim := DB.Redis.Get("AllItemTime")
- jsond,_ := json.Marshal(allteim)
+ jsond, _ := json.Marshal(allteim)
var ItemTime map[string]string
json.Unmarshal([]byte(jsond), &ItemTime)
- if poststate == 1{
+ if poststate == 1 {
ItemTime[c.PostForm("id")] = "--"
}
- if poststate == 0{
+ if poststate == 0 {
ItemTime[c.PostForm("id")] = "0"
}
DB.Redis.Set("AllItemTime", ItemTime, time.Second*60*60*24*30)
-
c.JSON(200, tools.ResponseSeccess{
0,
"ok",
@@ -158,6 +177,8 @@ type ItemTime struct {
// @Description 设备管理 - 更新等待时间
// @Accept json
// @Produce json
+// @Param ScenicId 5dfb03070a9ac17ac7a82054 string true "景区id"
+// @Param Token wgergejfwe string true "用户token"
// @Param item [{"id":"5df864740a9ac17ac7a7feb8","time":"20"},{"id":"5df8660924e03417008b4567","time":"33"}] string true "设备列表"
// @Success 200 {object} tools.ResponseSeccess "{errcode: 0, result: "ok"}"
// @Failure 500 {object} tools.ResponseError "{"errcode":1,"errmsg":"错误原因"}"
@@ -166,6 +187,17 @@ func UpdateItemTime(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
+ }
+
var ItemTime []ItemTime
json.Unmarshal([]byte(c.PostForm("items")), &ItemTime)
@@ -174,7 +206,7 @@ func UpdateItemTime(c *gin.Context) {
RedisData[v.Id] = v.Time
}
- DB.Redis.Set("AllItemTime", RedisData, time.Second*60*60*24*30)
+ DB.Redis.Set("AllItemTime_"+c.PostForm("ScenicId"), RedisData, time.Second*60*60*24*30)
c.JSON(200, tools.ResponseSeccess{
0,
"ok",
@@ -185,6 +217,7 @@ func UpdateItemTime(c *gin.Context) {
// @Description 设备管理 - 获得所有设备的等待时间
// @Accept json
// @Produce json
+// @Param ScenicId 5dfb03070a9ac17ac7a82054 string true "景区id"
// @Success 200 {object} tools.ResponseSeccess "{5df864740a9ac17ac7a7feb8: '20',.....}"
// @Failure 500 {object} tools.ResponseError "{}"
// @Router /AllItemTime? [get]
@@ -192,25 +225,16 @@ func AllItemTime(c *gin.Context) {
c.Header("Access-Control-Allow-Origin", c.Request.Header.Get("Origin"))
c.Header("Access-Control-Allow-Credentials", "true")
+ var ScenicId string
+ if ScenicId = c.Query("ScenicId");ScenicId == ""{
+ ScenicId = "5e0d504e24e03431008b4567" // 乐岛
+ }
- //Device := DB.SDevice{
- // c.Request.Header.Get("DeviceId"),
- // c.Request.Header.Get("Mac"),
- // c.Request.Header.Get("UDID"),
- // c.Request.Header.Get("SystemVersion"),
- // c.Request.Header.Get("SystemModel"),
- // c.Request.Header.Get("AppVersion"),
- // c.Request.Header.Get("AppVersion"),
- // c.Request.Header.Get("DeviceToken"),
- //}
- //spew.Dump(Device)
-
-
- allteim := DB.Redis.Get("AllItemTime")
+ allteim := DB.Redis.Get("AllItemTime_" + ScenicId)
if allteim != nil {
c.JSON(200, allteim)
} else {
c.String(200, "{}")
}
-}
\ No newline at end of file
+}
diff --git a/API/Line.go b/API/Line.go
index 3bbf618..17f24c2 100644
--- a/API/Line.go
+++ b/API/Line.go
@@ -8,6 +8,7 @@ import (
"go.mongodb.org/mongo-driver/bson/primitive"
"go.mongodb.org/mongo-driver/mongo/options"
"letu/DB"
+ "letu/Lib/Auth"
)
// @Title 查询线路信息
@@ -52,14 +53,19 @@ func AllLine(c *gin.Context) {
c.Header("Access-Control-Allow-Origin", c.Request.Header.Get("Origin"))
c.Header("Access-Control-Allow-Credentials", "true")
+ var ScenicId string
+ if ScenicId = c.Query("ScenicId");ScenicId == ""{
+ ScenicId = "5e0d504e24e03431008b4567" // 乐岛
+ }
+
var aLine []DB.SLine
- cur, err := DB.CLine.Find(tools.GetContext(), bson.M{})
+ cur, err := DB.CLine.Find(tools.GetContext(), bson.M{"ScenicId": ScenicId})
defer cur.Close(tools.GetContext())
if err == nil {
for cur.Next(tools.GetContext()) {
var e DB.SLine
cur.Decode(&e)
- aLine = append(aLine,e)
+ aLine = append(aLine, e)
}
}
@@ -71,13 +77,29 @@ func AllLine(c *gin.Context) {
// @Description 更新线路
// @Accept json
// @Produce json
+// @Param id 5dfb03070a9ac17ac7a82054 string true "线路id"
+// @Param ScenicId 5dfb03070a9ac17ac7a82054 string true "景区id"
+// @Param Token wgergejfwe string true "用户token"
// @Success 200 {object} tools.ResponseSeccess ""
// @Failure 500 {object} tools.ResponseError "{"errcode":1,"errmsg":"错误原因"}"
// @Router /UpdateLine? [post]
func UpdateLine(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
+ }
+
+
var Location []DB.SLocation
json.Unmarshal([]byte(c.PostForm("Location")), &Location)
@@ -88,7 +110,7 @@ func UpdateLine(c *gin.Context) {
if pid := c.PostForm("id"); pid == "null" {
id = primitive.NewObjectID()
} else {
- id,_ = primitive.ObjectIDFromHex(pid)
+ id, _ = primitive.ObjectIDFromHex(pid)
}
upsert := true
diff --git a/API/Operator.go b/API/Operator.go
new file mode 100644
index 0000000..670ae86
--- /dev/null
+++ b/API/Operator.go
@@ -0,0 +1,188 @@
+package Api
+
+import (
+ "encoding/json"
+ "github.com/aarongao/tools"
+ "github.com/gin-gonic/gin"
+ "go.mongodb.org/mongo-driver/bson"
+ "go.mongodb.org/mongo-driver/bson/primitive"
+ "letu/DB"
+ "letu/Lib/Auth"
+ "letu/Lib/JWT"
+ "time"
+)
+
+// @Title 登录
+// @Description 操作员管理 - 操作员登录
+// @Accept json
+// @Produce json
+// @Param Username aaron string true "用户名"
+// @Param Password 123 string true "密码"
+// @Success 200 {object} tools.ResponseSeccess "{"errcode":0,"result":{"Id":"5e09c64c1c09c6f0f7ca2fa9","Token":"640bf934e425aba5d3c90998b2641f2f0ca07261d334d9615d1cd4790b5f34e7"}} 调用其它需要登陆的接口时携带token,有过期时间"
+// @Failure 500 {object} tools.ResponseError "{"errcode":1,"errmsg":"错误原因"}"
+// @Router /LoginOperator? [post]
+func LoginOperator(c *gin.Context) {
+ c.Header("Access-Control-Allow-Origin", c.Request.Header.Get("Origin"))
+ c.Header("Access-Control-Allow-Credentials", "true")
+
+ selected := bson.M{}
+ var User *DB.SMember
+ if c.PostForm("Username") != "" && c.PostForm("Password") != "" {
+ selected["Username"] = c.PostForm("Username")
+ selected["Password"] = c.PostForm("Password")
+ DB.CMember.FindOne(tools.GetContext(), selected).Decode(&User)
+
+ if User == nil {
+ c.JSON(200, tools.ResponseError{
+ 1,
+ "用户不存在",
+ })
+ return
+ }
+
+ } else {
+ c.JSON(200, tools.ResponseError{
+ 1,
+ "不能为空",
+ })
+ return
+ }
+
+ // 生成token
+ dd, _ := time.ParseDuration("8760h")
+ User.Token, _ = JWT.CreateToken(User, time.Now().Add(dd).Unix())
+ c.JSON(200, tools.ResponseSeccess{
+ 0,
+ User,
+ })
+
+}
+
+// @Title 操作员管理
+// @Description 操作员管理 - 修改用户信息
+// @Accept json
+// @Produce json
+// @Param id aaron string true "用户id""
+// @Param ScenicId 5e0d504e24e03431008b4567 string true "景区id"
+// @Param Token wgergejfwe string true "用户token"
+// @Param Username aarongao string true "用户名"
+// @Param Remarks 18616619599 string true "备注"
+// @Param Password 12345 string true "密码"
+// @Success 200 {object} tools.ResponseSeccess "{"errcode":0,"result":"ok"}"
+// @Failure 500 {object} tools.ResponseError "{"errcode":1,"errmsg":"错误原因"}"
+// @Router /UpdateOperator? [post]
+func UpdateOperator(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
+ }
+
+ var _auth []string
+ json.Unmarshal([]byte(c.PostForm("Auth")), &_auth)
+
+ objID, err := primitive.ObjectIDFromHex(c.PostForm("id"))
+ if err == nil {
+
+ _, err = DB.CMember.UpdateOne(tools.GetContext(),
+ bson.M{"_id": objID},
+ bson.M{"$set": bson.M{
+ "Auth": _auth,
+ "Username": c.PostForm("Username"),
+ "Password": c.PostForm("Password"),
+ "Remarks": c.PostForm("Remarks"),
+ }},
+ )
+ } else {
+
+ objectID := primitive.NewObjectID()
+ User := &DB.SMember{
+ &objectID,
+ "operator",
+ c.PostForm("ScenicId"),
+ c.PostForm("Username"),
+ c.PostForm("Password"),
+ "",
+ "",
+ "",
+ "",
+ "",
+ "",
+ &DB.SDevice{},
+ _auth,
+ c.PostForm("Remarks"),
+ }
+
+ // 生成token
+ var dd time.Duration
+ dd, err = time.ParseDuration("20m")
+ User.Token, _ = JWT.CreateToken(User, time.Now().Add(dd).Unix())
+
+ DB.CMember.InsertOne(tools.GetContext(), User)
+
+ }
+
+ if err == nil {
+ c.JSON(200, tools.ResponseSeccess{
+ 0,
+ "ok",
+ })
+ } else {
+ c.JSON(200, tools.ResponseError{
+ 1,
+ err.Error(),
+ })
+ }
+
+}
+
+// @Title 操作员管理
+// @Description 操作员管理 - 所有操作员
+// @Accept json
+// @Produce json
+// @Param ScenicId 5dfb03070a9ac17ac7a82054 string true "景区id"
+// @Param Token 5dfb03070a9ac17ac7a82054 string true "用户token"
+// @Success 200 {object} tools.ResponseSeccess ""
+// @Failure 500 {object} tools.ResponseError "{"errcode":1,"errmsg":"错误原因"}"
+// @Router /AllOperator? [get]
+func AllOperator(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.Query("ScenicId"), user)
+ if err != nil {
+ c.JSON(200, tools.ResponseError{
+ 401,
+ "没有权限",
+ })
+ return
+ }
+
+ var aMember []*DB.SMember
+ cur, err := DB.CMember.Find(tools.GetContext(), bson.M{"ScenicId": c.Query("ScenicId"), "UserType": "operator"})
+ defer cur.Close(tools.GetContext())
+ if err == nil {
+ for cur.Next(tools.GetContext()) {
+ var e *DB.SMember
+ cur.Decode(&e)
+ aMember = append(aMember, e)
+ }
+ }
+
+ if aMember == nil {
+ aMember = []*DB.SMember{}
+ }
+ c.JSON(200, tools.ResponseSeccess{
+ 0,
+ aMember,
+ })
+}
diff --git a/API/Scenic.go b/API/Scenic.go
index 4e97680..9972bd5 100644
--- a/API/Scenic.go
+++ b/API/Scenic.go
@@ -8,6 +8,7 @@ import (
"go.mongodb.org/mongo-driver/bson/primitive"
"go.mongodb.org/mongo-driver/mongo/options"
"letu/DB"
+ "letu/Lib/Auth"
)
// @Title 返回景区基础信息
@@ -46,6 +47,7 @@ func ScenicInfo(c *gin.Context) {
// @Accept json
// @Produce json
// @Param id 5dfb03070a9ac17ac7a82054 string true "景区id"
+// @Param Token wgergejfwe string true "用户token"
// @Success 200 {object} tools.ResponseSeccess "Name名称;Describe介绍;OpenHours营业时间;Picture最上面图片;ShopAdPicture商城列表页图片;ItemScenicPicture项目场次照片;ActivityPicture活动照片;VideoList视频(VideoPicture=首桢图片);InvestigationUrl问券调查的url;RangeLocation景区范围(多个坐标点)"
// @Failure 500 {object} tools.ResponseError "{"errcode":1,"errmsg":"错误原因"}"
// @Router /UpdateScenic? [post]
@@ -53,6 +55,18 @@ func UpdateScenic(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("id"), user)
+ if err != nil {
+ c.JSON(200, tools.ResponseError{
+ 401,
+ "没有权限",
+ })
+ return
+ }
+
+
var Location DB.SLocation
json.Unmarshal([]byte(c.PostForm("Location")), &Location)
diff --git a/API/Shop.go b/API/Shop.go
index 73d8e50..b707af4 100644
--- a/API/Shop.go
+++ b/API/Shop.go
@@ -8,6 +8,7 @@ import (
"go.mongodb.org/mongo-driver/bson/primitive"
"go.mongodb.org/mongo-driver/mongo/options"
"letu/DB"
+ "letu/Lib/Auth"
)
// @Title 查询商品信息
@@ -45,6 +46,7 @@ func CommodityInfo(c *gin.Context) {
// @Description 查询所有商品
// @Accept json
// @Produce json
+// @Param ScenicId 5dfb03070a9ac17ac7a82054 string true "景区id"
// @Success 200 {object} tools.ResponseSeccess "Price=价格;ShopName=店铺名称;KvPhoto用于列表页的图片;TopPhoto详情页最上面的轮播图;Images详情页下面的产品详细图"
// @Failure 500 {object} tools.ResponseError "{"errcode":1,"errmsg":"错误原因"}"
// @Router /AllCommodity? [get]
@@ -52,14 +54,19 @@ func AllCommodity(c *gin.Context) {
c.Header("Access-Control-Allow-Origin", c.Request.Header.Get("Origin"))
c.Header("Access-Control-Allow-Credentials", "true")
+ var ScenicId string
+ if ScenicId = c.Query("ScenicId");ScenicId == ""{
+ ScenicId = "5e0d504e24e03431008b4567" // 乐岛
+ }
+
var aCommoditys []DB.SCommodity
- cur, err := DB.CCommodity.Find(tools.GetContext(), bson.M{})
+ cur, err := DB.CCommodity.Find(tools.GetContext(), bson.M{"ScenicId": ScenicId})
defer cur.Close(tools.GetContext())
if err == nil {
for cur.Next(tools.GetContext()) {
var e DB.SCommodity
cur.Decode(&e)
- aCommoditys = append(aCommoditys,e)
+ aCommoditys = append(aCommoditys, e)
}
}
@@ -71,6 +78,8 @@ func AllCommodity(c *gin.Context) {
// @Description 更新商品
// @Accept json
// @Produce json
+// @Param ScenicId 5dfb03070a9ac17ac7a82054 string true "景区id"
+// @Param Token wgergejfwe string true "用户token"
// @Success 200 {object} tools.ResponseSeccess ""
// @Failure 500 {object} tools.ResponseError "{"errcode":1,"errmsg":"错误原因"}"
// @Router /UpdateCommodity? [post]
@@ -78,6 +87,17 @@ func UpdateCommodity(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
+ }
+
var Picture []string
json.Unmarshal([]byte(c.PostForm("Images")), &Picture)
@@ -87,12 +107,11 @@ func UpdateCommodity(c *gin.Context) {
//var Location DB.SLocation
//json.Unmarshal([]byte(c.PostForm("Location")), &Location)
-
var id primitive.ObjectID
if pid := c.PostForm("id"); pid == "null" {
id = primitive.NewObjectID()
} else {
- id,_ = primitive.ObjectIDFromHex(pid)
+ id, _ = primitive.ObjectIDFromHex(pid)
}
upsert := true
diff --git a/API/Tag.go b/API/Tag.go
index dfb01e9..8e1e0df 100644
--- a/API/Tag.go
+++ b/API/Tag.go
@@ -5,6 +5,7 @@ import (
"github.com/gin-gonic/gin"
"go.mongodb.org/mongo-driver/bson"
"letu/DB"
+ "letu/Lib/Auth"
"letu/Lib/LeYouTu"
"time"
)
@@ -23,6 +24,11 @@ func AllTag(c *gin.Context) {
ScenicId, err := LeYouTu.GetScenicId(c)
if err != nil {
+
+ c.JSON(200, tools.ResponseError{
+ 1,
+ "景区id不能为空",
+ })
return
}
@@ -63,6 +69,10 @@ func AllTagGroup(c *gin.Context) {
ScenicId, err := LeYouTu.GetScenicId(c)
if err != nil {
+ c.JSON(200, tools.ResponseError{
+ 1,
+ "景区id不能为空",
+ })
return
}
@@ -119,6 +129,7 @@ func AllTagGroup(c *gin.Context) {
// @Accept json
// @Produce json
// @Param ScenicId 5dfb03070a9ac17ac7a82054 string true "景区id"
+// @Param Token wgergejfwe string true "用户token"
// @Param TagName 广场 string true "标签名称"
// @Param TagGroup location string true "群组名称"
// @Success 200 {object} tools.ResponseSeccess "{"errcode":0,"result":"ok"}"
@@ -128,8 +139,14 @@ func CreateTag(c *gin.Context) {
c.Header("Access-Control-Allow-Origin", c.Request.Header.Get("Origin"))
c.Header("Access-Control-Allow-Credentials", "true")
- ScenicId, err := LeYouTu.GetScenicId(c)
+ _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
}
@@ -160,12 +177,12 @@ func CreateTag(c *gin.Context) {
}
DB.CTags.InsertOne(tools.GetContext(),DB.STag{
- ScenicId,
+ c.PostForm("ScenicId"),
c.PostForm("TagGroup"),
c.PostForm("TagName"),
})
- DB.Redis.Delete("Tags_" + ScenicId)
+ DB.Redis.Delete("Tags_" + c.PostForm("ScenicId"))
println("清楚缓存Tags")
c.JSON(200, tools.ResponseSeccess{
@@ -182,6 +199,7 @@ func CreateTag(c *gin.Context) {
// @Accept json
// @Produce json
// @Param ScenicId 5dfb03070a9ac17ac7a82054 string true "景区id"
+// @Param Token wgergejfwe string true "用户token"
// @Param TagName 广场 string true "标签名称"
// @Param TagGroup location string true "群组名称"
// @Success 200 {object} tools.ResponseSeccess "{"errcode":0,"result":"ok"}"
@@ -191,8 +209,14 @@ func RemoveTag(c *gin.Context) {
c.Header("Access-Control-Allow-Origin", c.Request.Header.Get("Origin"))
c.Header("Access-Control-Allow-Credentials", "true")
- ScenicId, err := LeYouTu.GetScenicId(c)
+ _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
}
@@ -222,9 +246,9 @@ func RemoveTag(c *gin.Context) {
return
}
- DB.CTags.DeleteOne(tools.GetContext(), bson.M{"ScenicId": ScenicId,"Name":c.PostForm("TagName"),"Type":c.PostForm("TagGroup")})
+ DB.CTags.DeleteOne(tools.GetContext(), bson.M{"ScenicId": c.PostForm("ScenicId"),"Name":c.PostForm("TagName"),"Type":c.PostForm("TagGroup")})
- DB.Redis.Delete("Tags_" + ScenicId)
+ DB.Redis.Delete("Tags_" + c.PostForm("ScenicId"))
println("清楚缓存Tags")
c.JSON(200, tools.ResponseSeccess{
diff --git a/API/TopMenus.go b/API/TopMenus.go
index 2707b25..cd1ffff 100644
--- a/API/TopMenus.go
+++ b/API/TopMenus.go
@@ -8,13 +8,15 @@ import (
"go.mongodb.org/mongo-driver/bson/primitive"
"go.mongodb.org/mongo-driver/mongo/options"
"letu/DB"
- "letu/Lib/LeYouTu"
+ "letu/Lib/Auth"
)
// @Title 查询所有菜单
// @Description 菜单管理 - 查询所有菜单
// @Accept json
// @Produce json
+// @Param ScenicId 5e0d504e24e03431008b4567 string true "景区id"
+// @Param Token wgergejfwe string true "用户token"
// @Success 200 {object} tools.ResponseSeccess "{"errcode":0,"result":[{"Id":"","ScenicId":"","Title":"玩水","Tags":["玩水"]},{"Id":"","ScenicId":"","Title":"设施","Tags":["服务设施","游玩项目"]}]}"
// @Failure 500 {object} tools.ResponseError "{"errcode":1,"errmsg":"错误原因"}"
// @Router /TopMenus/All? [get]
@@ -22,13 +24,19 @@ func AllTopMenus(c *gin.Context) {
c.Header("Access-Control-Allow-Origin", c.Request.Header.Get("Origin"))
c.Header("Access-Control-Allow-Credentials", "true")
- ScenicId, err := LeYouTu.GetScenicId(c)
+ _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
}
var STopMenus []DB.STopMenus
- cur, err := DB.CTopMenus.Find(tools.GetContext(), bson.M{"ScenicId": ScenicId})
+ cur, err := DB.CTopMenus.Find(tools.GetContext(), bson.M{"ScenicId": c.PostForm("ScenicId")})
defer cur.Close(tools.GetContext())
if err == nil {
for cur.Next(tools.GetContext()) {
@@ -53,6 +61,8 @@ func AllTopMenus(c *gin.Context) {
// @Description 菜单管理 - 更新菜单
// @Accept json
// @Produce json
+// @Param ScenicId 5e0d504e24e03431008b4567 string true "景区id"
+// @Param Token wgergejfwe string true "用户token"
// @Success 200 {object} tools.ResponseSeccess "{"errcode":0,"result":[{"Id":"","ScenicId":"","Title":"玩水","Tags":["玩水"]},{"Id":"","ScenicId":"","Title":"设施","Tags":["服务设施","游玩项目"]}]}"
// @Failure 500 {object} tools.ResponseError "{"errcode":1,"errmsg":"错误原因"}"
// @Router /TopMenus/Update? [post]
@@ -60,8 +70,15 @@ func UpdateTopMenus(c *gin.Context) {
c.Header("Access-Control-Allow-Origin", c.Request.Header.Get("Origin"))
c.Header("Access-Control-Allow-Credentials", "true")
- ScenicId, err := LeYouTu.GetScenicId(c)
+
+ _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
}
@@ -87,7 +104,7 @@ func UpdateTopMenus(c *gin.Context) {
DB.CTopMenus.FindOneAndUpdate(tools.GetContext(),
bson.M{"_id": id},
bson.M{"$set": bson.M{
- "ScenicId": ScenicId,
+ "ScenicId": c.PostForm("ScenicId"),
"Title": c.PostForm("Title"),
"Tags": Tags,
}}, &options.FindOneAndUpdateOptions{
diff --git a/API/User.go b/API/User.go
index c105311..37fc96d 100644
--- a/API/User.go
+++ b/API/User.go
@@ -1,17 +1,14 @@
package Api
import (
- "crypto/sha256"
- "encoding/hex"
"github.com/aarongao/tools"
"github.com/gin-gonic/gin"
"go.mongodb.org/mongo-driver/bson"
"go.mongodb.org/mongo-driver/bson/primitive"
"go.mongodb.org/mongo-driver/mongo/options"
"letu/DB"
- "letu/Lib/Token"
+ "letu/Lib/JWT"
"regexp"
- "strconv"
"time"
)
@@ -55,10 +52,6 @@ func LoginUser(c *gin.Context) {
return
}
- // 生成token
- tokenunit8 := sha256.Sum256([]byte(c.PostForm("Mobile") + c.PostForm("Code") + strconv.FormatInt(time.Now().UnixNano(), 10)))
- token := hex.EncodeToString(tokenunit8[:32])
-
// 检查验证码
cacheCode := DB.Redis.Get("code_" + c.PostForm("Mobile"))
selected := bson.M{}
@@ -69,9 +62,13 @@ func LoginUser(c *gin.Context) {
// 验证码匹配,但手机号不存在
if User == nil {
+ var auth = []string{"用户管理", "通知管理"}
objectID := primitive.NewObjectID()
- User := DB.SMember{
+ User = &DB.SMember{
&objectID,
+ "visitor",
+ "",
+ "",
"",
"",
"",
@@ -79,7 +76,7 @@ func LoginUser(c *gin.Context) {
"",
"",
"",
- DB.SDevice{
+ &DB.SDevice{
c.Request.Header.Get("DeviceId"),
c.Request.Header.Get("Mac"),
c.Request.Header.Get("UDID"),
@@ -89,8 +86,10 @@ func LoginUser(c *gin.Context) {
c.Request.Header.Get("AppVersion"),
c.Request.Header.Get("DeviceToken"),
},
+ auth,
+ "",
}
- DB.CMember.InsertOne(tools.GetContext(),User)
+ DB.CMember.InsertOne(tools.GetContext(), User)
}
} else {
@@ -101,16 +100,9 @@ func LoginUser(c *gin.Context) {
return
}
- // 更新用户信息
- //DB.CMember.Update(
- // bson.M{"_id": User.Id},
- // bson.M{"$set": bson.M{"Token": token}},
- //)
-
- // 更新token
- Token.SaveToken(User.Id.Hex(), token)
-
- User.Token = token
+ // 生成token
+ dd, _ := time.ParseDuration("8760h")
+ User.Token, _ = JWT.CreateToken(User, time.Now().Add(dd).Unix())
c.JSON(200, tools.ResponseSeccess{
0,
User,
@@ -146,15 +138,15 @@ func RegisterDevice(c *gin.Context) {
upsert := true
DB.CDevice.FindOneAndUpdate(tools.GetContext(),
- bson.M{"DeviceId":c.Request.Header.Get("DeviceId")},
+ bson.M{"DeviceId": c.Request.Header.Get("DeviceId")},
bson.M{"$set": bson.M{
- "Mac":c.Request.Header.Get("Mac"),
- "UDID":c.Request.Header.Get("UDID"),
- "SystemType":c.Request.Header.Get("SystemType"),
- "SystemVersion":c.Request.Header.Get("SystemVersion"),
- "SystemModel":c.Request.Header.Get("SystemModel"),
- "AppVersion":c.Request.Header.Get("AppVersion"),
- "DeviceToken":c.Request.Header.Get("DeviceToken"),
+ "Mac": c.Request.Header.Get("Mac"),
+ "UDID": c.Request.Header.Get("UDID"),
+ "SystemType": c.Request.Header.Get("SystemType"),
+ "SystemVersion": c.Request.Header.Get("SystemVersion"),
+ "SystemModel": c.Request.Header.Get("SystemModel"),
+ "AppVersion": c.Request.Header.Get("AppVersion"),
+ "DeviceToken": c.Request.Header.Get("DeviceToken"),
}}, &options.FindOneAndUpdateOptions{
Upsert: &upsert,
},
@@ -172,7 +164,6 @@ func RegisterDevice(c *gin.Context) {
// @Accept json
// @Produce json
// @Param id aaron string true "用户id"
-// @Param Token wgergejfwe string true "用户token"
// @Success 200 {object} tools.ResponseSeccess "{"errcode":0,"result":{"Id":"5e09c64c1c09c6f0f7ca2fa9","Token":"640bf934e425aba5d3c90998b2641f2f0ca07261d334d9615d1cd4790b5f34e7"}}"
// @Failure 500 {object} tools.ResponseError "{"errcode":1,"errmsg":"错误原因"}"
// @Router /UserInfo? [get]
@@ -180,19 +171,11 @@ func UserInfo(c *gin.Context) {
c.Header("Access-Control-Allow-Origin", c.Request.Header.Get("Origin"))
c.Header("Access-Control-Allow-Credentials", "true")
- objID,err := primitive.ObjectIDFromHex(c.Query("id"))
- if c.Query("Token") == "" || err!=nil {
+ objID, err := primitive.ObjectIDFromHex(c.Query("id"))
+ if err != nil {
c.JSON(200, tools.ResponseError{
1,
- "Token或者用户id不正确",
- })
- return
- }
-
- if Token.GetToken(c.Query("id")) != c.Query("Token") {
- c.JSON(200, tools.ResponseError{
- 401,
- "token过期",
+ "用户id不正确",
})
return
}
@@ -200,7 +183,7 @@ func UserInfo(c *gin.Context) {
var User DB.SMember
DB.CMember.FindOne(tools.GetContext(), bson.M{"_id": objID}).Decode(&User)
- User.Device = DB.SDevice{}
+ User.Device = &DB.SDevice{}
c.JSON(200, tools.ResponseSeccess{
0,
User,
@@ -212,7 +195,6 @@ func UserInfo(c *gin.Context) {
// @Description 用户管理 - 检查Token是否过期
// @Accept json
// @Produce json
-// @Param id aaron string true "用户id"
// @Param Token wgergejfwe string true "用户token"
// @Success 200 {object} tools.ResponseSeccess "{"errcode":0,"result":"ok"}"
// @Failure 500 {object} tools.ResponseError "{"errcode":401,"errmsg":"token过期"}"
@@ -221,26 +203,27 @@ func CheckToken(c *gin.Context) {
c.Header("Access-Control-Allow-Origin", c.Request.Header.Get("Origin"))
c.Header("Access-Control-Allow-Credentials", "true")
- _,err := primitive.ObjectIDFromHex(c.PostForm("id"))
- if c.PostForm("Token") == "" || err != nil {
+ if c.PostForm("Token") == "" {
c.JSON(200, tools.ResponseError{
1,
- "Token或者用户id不正确",
+ "Token不正确",
})
return
}
- if Token.GetToken(c.PostForm("id")) != c.PostForm("Token") {
+ user, err := JWT.ParseToken(c.PostForm("Token"))
+
+ if err != nil {
c.JSON(200, tools.ResponseError{
401,
- "token过期",
+ err.Error(),
})
return
}
c.JSON(200, tools.ResponseSeccess{
0,
- "ok",
+ user,
})
}
@@ -264,19 +247,13 @@ func UpdateUser(c *gin.Context) {
c.Header("Access-Control-Allow-Origin", c.Request.Header.Get("Origin"))
c.Header("Access-Control-Allow-Credentials", "true")
- _,err := primitive.ObjectIDFromHex(c.PostForm("id"))
- if c.PostForm("Token") == "" || err != nil {
- c.JSON(200, tools.ResponseError{
- 1,
- "Token或者用户id不正确",
- })
- return
- }
+ _user, _ := c.Get("UserInfo")
+ user := _user.(*DB.SMember)
- if Token.GetToken(c.PostForm("id")) != c.PostForm("Token") {
+ if c.PostForm("id") != user.Id.Hex() {
c.JSON(200, tools.ResponseError{
401,
- "token过期",
+ "没有权限",
})
return
}
@@ -299,14 +276,6 @@ func UpdateUser(c *gin.Context) {
return
}
- //if c.PostForm("Password") != c.PostForm("ConfirmPassword") {
- // c.JSON(200, tools.ResponseError{
- // 1,
- // "2次密码不一致",
- // })
- // return
- //}
-
// 检查验证码
code := DB.Redis.Get("code_" + c.PostForm("Mobile"))
if code == "" || code != c.PostForm("Code") {
@@ -317,8 +286,8 @@ func UpdateUser(c *gin.Context) {
return
}
- objID,_ := primitive.ObjectIDFromHex(c.PostForm("id"))
- _, err = DB.CMember.UpdateOne(tools.GetContext(),
+ objID, _ := primitive.ObjectIDFromHex(c.PostForm("id"))
+ _, err := DB.CMember.UpdateOne(tools.GetContext(),
bson.M{"_id": objID},
bson.M{"$set": bson.M{
"Birthday": c.PostForm("Birthday"),
@@ -330,9 +299,9 @@ func UpdateUser(c *gin.Context) {
if err == nil {
var User *DB.SMember
- objID,_ := primitive.ObjectIDFromHex(c.PostForm("id"))
+ objID, _ := primitive.ObjectIDFromHex(c.PostForm("id"))
DB.CMember.FindOne(tools.GetContext(), bson.M{"_id": objID}).Decode(&User)
-
+ User.Token = ""
c.JSON(200, tools.ResponseSeccess{
0,
User,
@@ -346,7 +315,6 @@ func UpdateUser(c *gin.Context) {
}
-
// @Title 删除用户
// @Description 用户管理 - 删除用户(注销)
// @Accept json
@@ -360,19 +328,21 @@ func RemoveUser(c *gin.Context) {
c.Header("Access-Control-Allow-Origin", c.Request.Header.Get("Origin"))
c.Header("Access-Control-Allow-Credentials", "true")
- objID,err := primitive.ObjectIDFromHex(c.PostForm("id"))
- if c.PostForm("Token") == "" || err != nil {
+ _user, _ := c.Get("UserInfo")
+ user := _user.(*DB.SMember)
+ if c.PostForm("id") != user.Id.Hex() {
c.JSON(200, tools.ResponseError{
- 1,
- "Token或者用户id不正确",
+ 401,
+ "没有权限",
})
return
}
- if Token.GetToken(c.PostForm("id")) != c.PostForm("Token") {
+ objID, err := primitive.ObjectIDFromHex(c.PostForm("id"))
+ if err != nil {
c.JSON(200, tools.ResponseError{
- 401,
- "token过期",
+ 1,
+ "用户id不正确",
})
return
}
diff --git a/API/UserLog.go b/API/UserLog.go
index f0d6af1..5b1d525 100644
--- a/API/UserLog.go
+++ b/API/UserLog.go
@@ -131,12 +131,11 @@ func AllUserLog(c *gin.Context) {
}
}
-
c.JSON(200, tools.Page{
0,
total,
currPage,
- int(math.Ceil(float64(total) / float64(limit))),
+ int64(math.Ceil(float64(total) / float64(limit))),
limit,
aUserLog,
})
diff --git a/Bin/Monitor.go b/Bin/Monitor.go
index 58ffc93..f2cb398 100644
--- a/Bin/Monitor.go
+++ b/Bin/Monitor.go
@@ -12,7 +12,7 @@ var lastState = 0
func main() {
for {
- time.Sleep(30 * time.Second)
+ time.Sleep(180 * time.Second)
httpState, body, error := tools.GET("http://leyoutu.st-i.com.cn/AllScenic")
if httpState == 200 && error == nil {
diff --git a/Bin/TestiosMeg b/Bin/TestiosMeg
new file mode 100755
index 0000000..38bba47
Binary files /dev/null and b/Bin/TestiosMeg differ
diff --git a/Bin/TestiosMeg.go b/Bin/TestiosMeg.go
new file mode 100644
index 0000000..5901d94
--- /dev/null
+++ b/Bin/TestiosMeg.go
@@ -0,0 +1,29 @@
+package main
+
+import (
+ "fmt"
+ "github.com/aliyun/alibaba-cloud-sdk-go/services/push"
+)
+
+func main() {
+
+ // 推送app消息
+ client, err := push.NewClientWithAccessKey("cn-hangzhou", "LTAI4FdQeNMQXRU6u5J3EFQc", "PwvyF5rRNBWLDya41WrCpvENevYZGi")
+
+
+ request := push.CreatePushNoticeToiOSRequest()
+ request.ApnsEnv = "DEV"
+ request.AppKey = "28332889"
+ request.Scheme = "https"
+ request.Target = "DEVICE"
+ request.TargetValue = "30076ed6fdb740e49d882433931bc34a"
+ request.Title = "消息测试1"
+ request.Body = "消息测试2"
+
+ response, err := client.PushNoticeToiOS(request)
+ if err != nil {
+ fmt.Print(err.Error())
+ }
+ fmt.Printf("response is %#v\n", response)
+
+}
diff --git a/Config/config.go b/Config/config.go
index 130a491..dc2058a 100644
--- a/Config/config.go
+++ b/Config/config.go
@@ -1,10 +1,14 @@
package Config
type Config struct {
- TagType []string
- DbPath string
- DbName string
- DbUser string
- DbPassword string
- RedisPath string
+ TagType []string
+ DbPath string
+ DbName string
+ DbUser string
+ DbPassword string
+ RedisPath string
+ Env string
+ TokenSecret string
}
+
+var Info = Config{}
diff --git a/Config/config.json b/Config/config.json
index eddf812..c831719 100644
--- a/Config/config.json
+++ b/Config/config.json
@@ -4,5 +4,7 @@
"dbName": "LeYouTu",
"dbUser": "leyoutu",
"dbPassword": "leyoutu123456",
- "redisPath": "127.0.0.1:6379"
+ "redisPath": "127.0.0.1:6379",
+ "Env": "DEV",
+ "tokenSecret": "token.secret"
}
diff --git a/DB/db.go b/DB/db.go
index 14987ba..b8ea890 100644
--- a/DB/db.go
+++ b/DB/db.go
@@ -26,6 +26,7 @@ var DB *mongo.Database
type SItem struct {
Id *primitive.ObjectID `bson:"_id" json:"Id" valid:"required"`
+ ScenicId string `bson:"ScenicId" json:"ScenicId"` // 景区id
Name string `bson:"Name" json:"Name"`
SubName string `bson:"SubName" json:"SubName"`
Location SLocation `bson:"Location" json:"Location"`
@@ -45,6 +46,11 @@ type SItem struct {
Reminder string `bson:"Reminder" json:"Reminder"` //温馨提示
State int `bson:"State" json:"State"` // 运行状态0=正常1=停运
}
+
+type SModel struct {
+ Model string `bson:"Model" json:"Model"`
+ Action string `bson:"Action" json:"Action"`
+}
type SIcons struct {
Id *primitive.ObjectID `bson:"_id" json:"Id" valid:"required"`
ScenicId string `bson:"ScenicId" json:"ScenicId"`
@@ -143,6 +149,9 @@ type SInvestigation struct {
}
type SMember struct {
Id *primitive.ObjectID `bson:"_id" json:"Id" valid:"required"`
+ UserType string `bson:"UserType" json:"UserType"` // "root" or "operator" or "visitor"
+ ScenicId string `bson:"ScenicId" json:"ScenicId"`
+ Username string `bson:"Username" json:"Username"`
Password string `bson:"Password" json:"Password"`
Birthday string `bson:"Birthday" json:"Birthday"`
FullName string `bson:"FullName" json:"FullName"`
@@ -150,7 +159,9 @@ type SMember struct {
Openid string `bson:"Openid" json:"Openid"`
Token string `bson:"Token" json:"Token"`
Sex string `bson:"Sex" json:"Sex"`
- Device SDevice `bson:"Device" json:"Device"` //设备信息
+ Device *SDevice `bson:"Device" json:"Device"` //设备信息
+ Auth []string `bson:"Auth" json:"Auth"` //权限信息
+ Remarks string `bson:"Remarks" json:"Remarks"` //说明
}
type STag struct {
diff --git a/Lib/Auth/Auth.go b/Lib/Auth/Auth.go
new file mode 100644
index 0000000..367bdbb
--- /dev/null
+++ b/Lib/Auth/Auth.go
@@ -0,0 +1,98 @@
+package Auth
+
+import (
+ "github.com/aarongao/tools"
+ "github.com/gin-gonic/gin"
+ "github.com/pkg/errors"
+ "letu/DB"
+ "letu/Lib/JWT"
+)
+
+// 系统中所有模块
+var Models = make(map[string][]string)
+
+// @Title 所有模块信息
+// @Description 模块管理 - 所有模块信息
+// @Accept json
+// @Produce json
+// @Success 200 {object} tools.ResponseSeccess ""
+// @Failure 500 {object} tools.ResponseError "{"errcode":1,"errmsg":"错误原因"}"
+// @Router /AllModules? [get]
+func Modules(c *gin.Context) {
+ c.Header("Access-Control-Allow-Origin", c.Request.Header.Get("Origin"))
+ c.Header("Access-Control-Allow-Credentials", "true")
+
+ rs := []string{}
+ for k, _ := range Models {
+ rs = append(rs, k)
+ }
+
+ c.JSON(200, tools.ResponseSeccess{
+ 0,
+ rs,
+ })
+
+}
+
+// 检查基础权限
+func CheckAuthFunc(handFunc func(c *gin.Context), auth *DB.SModel) func(c *gin.Context) {
+ return func(c *gin.Context) {
+
+ if auth.Model == "" {
+ handFunc(c)
+ return
+ }
+
+ token := ""
+ if c.Request.Method == "GET" {
+ token = c.Query("Token")
+ }
+ if c.Request.Method == "POST" {
+ token = c.PostForm("Token")
+ }
+ if token == "" {
+ token = c.Request.Header.Get("Token")
+ }
+
+ // 解析token
+ user, err := JWT.ParseToken(token)
+ if user.UserType == "root" {
+ c.Set("UserInfo", user)
+ handFunc(c)
+ return
+ }
+
+ // 检查权限
+ checkAuth := false
+ for _, v := range user.Auth {
+ if v == auth.Model {
+ checkAuth = true
+ break
+ }
+ }
+
+ if err != nil || checkAuth == false {
+ c.JSON(200, tools.ResponseError{
+ 401,
+ "没有权限",
+ })
+ } else {
+ c.Set("UserInfo", user)
+ handFunc(c)
+ }
+ }
+}
+
+func CheckScenicAuth(ScenicId string, user *DB.SMember) error {
+
+ if ScenicId == "" {
+ return errors.New("景区id不能为空")
+ }
+
+ if user.UserType == "operator" {
+ if user.ScenicId != ScenicId {
+ return errors.New("权限不正确(需要正确的Token和ScenicId)")
+ }
+ }
+ return nil
+}
diff --git a/Lib/DelayMessage/delaymessage.go b/Lib/DelayMessage/delaymessage.go
index c599eae..0930dc6 100644
--- a/Lib/DelayMessage/delaymessage.go
+++ b/Lib/DelayMessage/delaymessage.go
@@ -5,11 +5,13 @@ import (
"encoding/json"
"fmt"
"github.com/aarongao/tools"
+ "github.com/aliyun/alibaba-cloud-sdk-go/services/push"
"github.com/pkg/errors"
+ "go.mongodb.org/mongo-driver/bson"
"go.mongodb.org/mongo-driver/bson/primitive"
"go.mongodb.org/mongo-driver/mongo"
- "go.mongodb.org/mongo-driver/bson"
"io/ioutil"
+ "letu/DB"
"net/http"
"strconv"
"sync"
@@ -31,11 +33,11 @@ type Message struct {
Fail int
// 类型0=geturl;1=发送app消息
- Type int8 `bson:"Type" json:"Type"`
- Title string `bson:"Title" json:"Title"`
- Content string `bson:"Content" json:"Content"`
- UDID string `bson:"UDID" json:"UDID"`
- UserId string `bson:"UserId" json:"UserId"`
+ Type int8 `bson:"Type" json:"Type"`
+ Title string `bson:"Title" json:"Title"`
+ Content string `bson:"Content" json:"Content"`
+ DeviceToken string `bson:"DeviceToken" json:"DeviceToken"`
+ UserId string `bson:"UserId" json:"UserId"`
}
// addTask
@@ -68,7 +70,7 @@ func (dm *DelayMessage) AddTaskForGetUrl(delayTime string, userid string, callba
return nil
}
-func (dm *DelayMessage) AddTaskForAppMessage(delayTime string, udid string, title string, content string, userid string) error {
+func (dm *DelayMessage) AddTaskForAppMessage(delayTime string, deviceToken string, title string, content string, userid string) error {
iTIme, _ := strconv.Atoi(delayTime)
i64Time := int64(iTIme)
@@ -78,8 +80,8 @@ func (dm *DelayMessage) AddTaskForAppMessage(delayTime string, udid string, titl
if i64Time <= nowTimeU {
return errors.New("delayTime error...")
}
- if udid == "" {
- return errors.New("udid error...")
+ if deviceToken == "" {
+ return errors.New("deviceToken error...")
}
if title == "" {
return errors.New("title error...")
@@ -92,7 +94,7 @@ func (dm *DelayMessage) AddTaskForAppMessage(delayTime string, udid string, titl
}
objectID := primitive.NewObjectID()
- _Message := &Message{&objectID, i64Time, "", 0, 1, title, content, udid, userid}
+ _Message := &Message{&objectID, i64Time, "", 0, 1, title, content, deviceToken, userid}
CDelayMessage.InsertOne(tools.GetContext(), _Message)
@@ -147,16 +149,35 @@ func Callback(key *primitive.ObjectID, message *Message) {
} else if message.Type == 1 {
// 推送app消息
- //client, err := push.NewClientWithAccessKey("cn-hangzhou", "28332889", "4c0b32d5fd0822a9de703e177798e8ca")
- //
- //request := push.CreatePushMessageToiOSRequest()
- //request.Scheme = "https"
- //
- //response, err := client.PushMessageToiOS(request)
- //if err != nil {
- // fmt.Print(err.Error())
- //}
- //fmt.Printf("response is %#v\n", response)
+ client, err := push.NewClientWithAccessKey("cn-hangzhou", "LTAI4FdQeNMQXRU6u5J3EFQc", "PwvyF5rRNBWLDya41WrCpvENevYZGi")
+
+ request := push.CreatePushNoticeToiOSRequest()
+ request.ApnsEnv = "DEV"
+ request.AppKey = "28332889"
+ request.Scheme = "https"
+ request.Target = "DEVICE"
+ request.TargetValue = message.DeviceToken
+ request.Title = message.Title
+ request.Body = message.Content
+
+ response, err := client.PushNoticeToiOS(request)
+ if err != nil {
+ fmt.Print(err.Error())
+ }
+
+ res,_ := json.Marshal(response)
+ DB.CSystemLog.InsertOne(tools.GetContext(),DB.SSystemLog{
+ message.UserId,
+ "",
+ "",
+ 6002,
+ "调用阿里接口发送app通知",
+ time.Now().Unix(),
+ DB.SLocation{},
+ string(res),
+ err,
+ })
+
}
json, _ := json.Marshal(message)
diff --git a/Lib/JWT/jwt.go b/Lib/JWT/jwt.go
new file mode 100644
index 0000000..2ad3993
--- /dev/null
+++ b/Lib/JWT/jwt.go
@@ -0,0 +1,72 @@
+package JWT
+
+import (
+ "encoding/json"
+ "errors"
+ "github.com/dgrijalva/jwt-go"
+ "go.mongodb.org/mongo-driver/bson/primitive"
+ "letu/Config"
+ "letu/DB"
+ "time"
+)
+
+func CreateToken(user *DB.SMember, exp int64) (tokenss string, err error) {
+ //自定义claim
+
+
+ auth, _ := json.Marshal(user.Auth)
+ claim := jwt.MapClaims{
+ "id": user.Id,
+ //"mobile": user.Mobile,
+ "userType": user.UserType,
+ "scenicId": user.ScenicId,
+ "auth": string(auth),
+ "nbf": time.Now().Unix(),
+ "iat": time.Now().Unix(),
+ "exp": exp,
+ }
+ token := jwt.NewWithClaims(jwt.SigningMethodHS256, claim)
+ tokenss, err = token.SignedString([]byte(Config.Info.TokenSecret))
+ return
+}
+
+func secret() jwt.Keyfunc {
+ return func(token *jwt.Token) (interface{}, error) {
+ return []byte(Config.Info.TokenSecret), nil
+ }
+}
+
+func CheckToken(tokenss string) (err error) {
+
+ _, err = jwt.Parse(tokenss, secret())
+ return err
+}
+
+func ParseToken(tokenss string) (user *DB.SMember, err error) {
+ user = &DB.SMember{}
+ token, err := jwt.Parse(tokenss, secret())
+ if err != nil {
+ return
+ }
+ claim, ok := token.Claims.(jwt.MapClaims)
+ if !ok {
+ err = errors.New("cannot convert claim to mapclaim")
+ return
+ }
+ //验证token,如果token被修改过则为false
+ if !token.Valid {
+ err = errors.New("token is invalid")
+ return
+ }
+
+ id, _ := primitive.ObjectIDFromHex(claim["id"].(string))
+ user.Id = &id
+ //user.Mobile = claim["mobile"].(string)
+ user.UserType = claim["userType"].(string)
+ user.ScenicId = claim["scenicId"].(string)
+
+ var jsons []string
+ json.Unmarshal([]byte(claim["auth"].(string)),&jsons)
+ user.Auth = jsons
+ return
+}
diff --git a/Lib/LeYouTu/Controllers.go b/Lib/LeYouTu/Controllers.go
deleted file mode 100644
index 598eacd..0000000
--- a/Lib/LeYouTu/Controllers.go
+++ /dev/null
@@ -1,26 +0,0 @@
-package LeYouTu
-
-import (
- "github.com/gin-gonic/gin"
-)
-
-type Controllers struct {
- Layout func(c *gin.Context) bool
-}
-
-func (this *Controllers) POST(handFunc func(c *gin.Context)) func(c *gin.Context) {
- return this.HandleFunc(handFunc, "POST")
-}
-func (this *Controllers) GET(handFunc func(c *gin.Context)) func(c *gin.Context) {
- return this.HandleFunc(handFunc, "GET")
-}
-func (this *Controllers) HandleFunc(handFunc func(c *gin.Context), httpMethod string) func(c *gin.Context) {
- return func(c *gin.Context) {
-
- if c.Request.Method != httpMethod {
- //res.Write([]byte(http.StatusText(http.StatusMethodNotAllowed)))
- return
- }
-
- }
-}
\ No newline at end of file
diff --git a/Lib/LeYouTu/tools.go b/Lib/LeYouTu/tools.go
index c8d40d9..bed14d2 100644
--- a/Lib/LeYouTu/tools.go
+++ b/Lib/LeYouTu/tools.go
@@ -1,7 +1,6 @@
package LeYouTu
import (
- "github.com/aarongao/tools"
"github.com/gin-gonic/gin"
"github.com/pkg/errors"
)
@@ -16,10 +15,6 @@ func GetScenicId(c *gin.Context) (ScenicId string, error error) {
}
if ScenicId == "" || ScenicId == "undefined" {
- c.JSON(200, tools.ResponseError{
- 1,
- "缺少ScenicId(景区id)",
- })
return "", errors.New("缺少ScenicId(景区id)")
} else {
return ScenicId, nil
diff --git a/main.go b/main.go
index 97c7b68..c7b03cc 100644
--- a/main.go
+++ b/main.go
@@ -11,6 +11,7 @@ import (
"letu/Api"
"letu/Config"
"letu/DB"
+ "letu/Lib/Auth"
"letu/Lib/Cache"
"letu/Lib/DelayMessage"
"log"
@@ -21,6 +22,8 @@ import (
// @APIVersion 1.0.0
// @APITitle 乐游图后端接口文档
// @BasePath 正式 leyoutu.st-i.com.cn; 测试 letu.api.imagchina.com
+var Gin *gin.Engine
+
func main() {
// 读取配置文件
@@ -28,13 +31,27 @@ func main() {
file, _ := os.Open(dir + "/Config/config.json")
defer file.Close()
decoder := json.NewDecoder(file)
- conf := Config.Config{}
- err := decoder.Decode(&conf)
+ err := decoder.Decode(&Config.Info)
tools.CheckError(err)
// 连接数据库
// Set client options
- clientOptions := options.Client().ApplyURI("mongodb://" + conf.DbPath)
+ clientOptions := options.Client()
+ if Config.Info.Env == "DEV" {
+ clientOptions.ApplyURI("mongodb://" + Config.Info.DbPath)
+ } else if Config.Info.Env == "PRODUCT" {
+ credential := options.Credential{
+ AuthMechanism: "SCRAM-SHA-1",
+ AuthSource: Config.Info.DbName,
+ Username: Config.Info.DbUser,
+ Password: Config.Info.DbPassword,
+ }
+ clientOptions.ApplyURI("mongodb://" + Config.Info.DbPath).SetAuth(credential)
+ } else {
+ log.Fatal("未知的运行环境 DEV or PRODUCT")
+ return
+ }
+
clientOptions.SetLocalThreshold(3 * time.Second) //只使用与mongo操作耗时小于3秒的
clientOptions.SetMaxConnIdleTime(5 * time.Second) //指定连接可以保持空闲的最大毫秒数
clientOptions.SetMaxPoolSize(4096) //使用最大的连接数
@@ -53,8 +70,7 @@ func main() {
log.Println("Connected to MongoDB!")
//获取文档集
- DB.DB = client.Database("LeYouTu")
- //DB.DB.Login(conf.DbUser, conf.DbPassword)
+ DB.DB = client.Database(Config.Info.DbName)
DB.CItem = DB.DB.Collection("Item")
DB.CComplaint = DB.DB.Collection("Complaint")
@@ -76,7 +92,7 @@ func main() {
// 连接redis
DB.Redis = Cache.NewRedis(&Cache.RedisOpts{
- conf.RedisPath,
+ Config.Info.RedisPath,
"",
0,
200,
@@ -84,59 +100,68 @@ func main() {
0,
})
- r := gin.Default()
+ Gin = gin.Default()
//r.Static("/.well-known", "./.well-known/")
- r.GET("/AllItems", Api.AllItems)
- r.GET("/AllItemTime", Api.AllItemTime)
- r.GET("/AllCommodity", Api.AllCommodity)
- r.GET("/AllLine", Api.AllLine)
- r.GET("/ItemInfo", Api.ItemInfo)
- r.GET("/CommodityInfo", Api.CommodityInfo)
- r.POST("/CreateComplaint", Api.CreateComplaint)
- r.GET("/AllComplaint", Api.AllComplaint)
- //r.POST("/CreateUser", Api.CreateUser)
- r.POST("/LoginUser", Api.LoginUser)
- r.POST("/UpdateUser", Api.UpdateUser)
- r.GET("/UserInfo", Api.UserInfo)
- r.GET("/ScenicInfo", Api.ScenicInfo)
- r.GET("/LineInfo", Api.LineInfo)
- r.GET("/AllTag", Api.AllTag)
- r.GET("/AllTagGroup", Api.AllTagGroup)
- r.POST("/Tag/Create", Api.CreateTag)
- r.POST("/Tag/Remove", Api.RemoveTag)
-
- r.POST("/Upload", Api.Upload)
- r.POST("/UpdateItem", Api.UpdateItem)
- r.POST("/UpdateCommodity", Api.UpdateCommodity)
- r.POST("/UpdateLine", Api.UpdateLine)
- r.POST("/UpdateScenic", Api.UpdateScenic)
- r.POST("/UpdateItemTime", Api.UpdateItemTime)
- r.GET("/AllScenic", Api.AllScenic)
- r.POST("/UserLog", Api.UserLog)
- r.GET("/AllUserLog", Api.AllUserLog)
- r.POST("/Sms/Send", Api.Send)
- r.POST("/Investigation/Save", Api.SaveInvestigation)
- r.GET("/Investigation/List", Api.AllInvestigation)
- r.POST("/Trajectory/Save", Api.SaveTrajectory)
- r.POST("/DealyMessage/Create", Api.CreateDealyMessage)
- r.GET("/DealyMessage/Info", Api.DealyMessageInfo)
- r.POST("/DealyMessage/Remove", Api.RemoveDealyMessage)
- r.POST("/Icon/Update", Api.UpdateIcon)
- r.GET("/Icon/All", Api.AllIcons)
- r.GET("/Icon/Info", Api.IconInfo)
- r.POST("/CheckToken", Api.CheckToken)
- //r.GET("/Tiles", Api.Tiles)
- r.POST("/TopMenus/Update", Api.UpdateTopMenus)
- r.GET("/TopMenus/All", Api.AllTopMenus)
- r.POST("/RegisterDevice", Api.RegisterDevice)
- r.POST("/RemoveUser", Api.RemoveUser)
- //r.GET("/ws", Api.WsPage)
-
- r.Static("/Upload", "./Upload")
- r.Static("/Console", "./Console")
- r.Static("/Policy", dir+"/Policy")
-
- r.GET("MP_verify_R9xuhLXYcVbdDDNk.txt", func(c *gin.Context) {
+
+ InitController("GET", "/AllItems", Api.AllItems, &DB.SModel{})
+ InitController("GET", "/AllItemTime", Api.AllItemTime, &DB.SModel{})
+ InitController("GET", "/AllCommodity", Api.AllCommodity, &DB.SModel{})
+ InitController("GET", "/AllLine", Api.AllLine, &DB.SModel{})
+ InitController("GET", "/ItemInfo", Api.ItemInfo, &DB.SModel{})
+ InitController("GET", "/CommodityInfo", Api.CommodityInfo, &DB.SModel{})
+ InitController("POST", "/CreateComplaint", Api.CreateComplaint, &DB.SModel{})
+ InitController("GET", "/AllComplaint", Api.AllComplaint, &DB.SModel{"投诉建议", "查看所有"})
+ //InitController("/CreateUser", Api.CreateUser)
+ InitController("POST", "/LoginUser", Api.LoginUser, &DB.SModel{})
+ InitController("POST", "/UpdateUser", Api.UpdateUser, &DB.SModel{"用户管理", "修改"})
+ InitController("GET", "/UserInfo", Api.UserInfo, &DB.SModel{})
+ InitController("GET", "/ScenicInfo", Api.ScenicInfo, &DB.SModel{})
+ InitController("GET", "/LineInfo", Api.LineInfo, &DB.SModel{})
+ InitController("GET", "/AllTag", Api.AllTag, &DB.SModel{})
+ InitController("GET", "/AllTagGroup", Api.AllTagGroup, &DB.SModel{})
+ InitController("POST", "/Tag/Create", Api.CreateTag, &DB.SModel{"标签管理", "增加"})
+ InitController("POST", "/Tag/Remove", Api.RemoveTag, &DB.SModel{"标签管理", "删除"})
+
+ InitController("POST", "/Upload", Api.Upload, &DB.SModel{})
+ InitController("POST", "/UpdateItem", Api.UpdateItem, &DB.SModel{"项目管理", "修改"})
+ InitController("POST", "/UpdateCommodity", Api.UpdateCommodity, &DB.SModel{"商品管理", "修改"})
+ InitController("POST", "/UpdateLine", Api.UpdateLine, &DB.SModel{"线路管理", "修改"})
+ InitController("POST", "/UpdateScenic", Api.UpdateScenic, &DB.SModel{"景区管理", "修改"})
+ InitController("POST", "/UpdateItemTime", Api.UpdateItemTime, &DB.SModel{"项目管理", "修改等候时间"})
+ InitController("GET", "/AllScenic", Api.AllScenic, &DB.SModel{})
+ InitController("POST", "/UserLog", Api.UserLog, &DB.SModel{})
+ InitController("GET", "/AllUserLog", Api.AllUserLog, &DB.SModel{})
+ InitController("POST", "/Sms/Send", Api.Send, &DB.SModel{})
+ InitController("POST", "/Investigation/Save", Api.SaveInvestigation, &DB.SModel{})
+ InitController("GET", "/Investigation/List", Api.AllInvestigation, &DB.SModel{})
+ InitController("POST", "/Trajectory/Save", Api.SaveTrajectory, &DB.SModel{})
+ InitController("POST", "/DealyMessage/Create", Api.CreateDealyMessage, &DB.SModel{"通知管理", "增加"})
+ InitController("GET", "/DealyMessage/Info", Api.DealyMessageInfo, &DB.SModel{"通知管理", "查看所有"})
+ InitController("POST", "/DealyMessage/Remove", Api.RemoveDealyMessage, &DB.SModel{"通知管理", "删除"})
+ InitController("POST", "/Icon/Update", Api.UpdateIcon, &DB.SModel{"图标管理", "修改管理"})
+ InitController("GET", "/Icon/All", Api.AllIcons, &DB.SModel{})
+ InitController("GET", "/Icon/Info", Api.IconInfo, &DB.SModel{})
+ InitController("POST", "/CheckToken", Api.CheckToken, &DB.SModel{})
+ //InitController("/Tiles", Api.Tiles)
+ InitController("POST", "/TopMenus/Update", Api.UpdateTopMenus, &DB.SModel{})
+ InitController("GET", "/TopMenus/All", Api.AllTopMenus, &DB.SModel{})
+ InitController("GET", "/RegisterDevice", Api.RegisterDevice, &DB.SModel{})
+ InitController("POST", "/RemoveUser", Api.RemoveUser, &DB.SModel{"用户管理", "删除"})
+
+ InitController("POST", "/LoginOperator", Api.LoginOperator, &DB.SModel{})
+ InitController("POST", "/UpdateOperator", Api.UpdateOperator, &DB.SModel{"操作员管理", "增加和修改"})
+ InitController("GET", "/AllOperator", Api.AllOperator, &DB.SModel{"操作员管理", "查看所有"})
+ Gin.GET("/AllModules", Auth.Modules)
+ //InitController("/ws", Api.WsPage)
+
+ // 用于给赵翔测试通知效果
+ Gin.GET("/PushNoticeToiOS", Api.PushNoticeToiOS)
+
+ Gin.Static("/Upload", "./Upload")
+ Gin.Static("/Console", "./Console")
+ Gin.Static("/Policy", dir+"/Policy")
+
+ Gin.GET("MP_verify_R9xuhLXYcVbdDDNk.txt", func(c *gin.Context) {
c.String(200, "R9xuhLXYcVbdDDNk")
})
//r.Static("/tiles2", dir+"/tiles")
@@ -149,7 +174,7 @@ func main() {
DelayMessage.GlobalDM.Start()
}()
- // -初始化数据
+ // -初始化延迟数据
if cur, err := DelayMessage.CDelayMessage.Find(tools.GetContext(), bson.M{}); err == nil {
defer cur.Close(tools.GetContext())
for cur.Next(tools.GetContext()) {
@@ -170,5 +195,19 @@ func main() {
spew.Dump(err)
}
- r.Run(":8080")
+ Gin.Run(":8080")
+}
+
+func InitController(method string, uri string, handFunc func(c *gin.Context), auth *DB.SModel) {
+
+ if auth.Model != "" {
+ Auth.Models[auth.Model] = append(Auth.Models[auth.Model], auth.Action)
+ }
+
+ if method == "GET" {
+ Gin.GET(uri, Auth.CheckAuthFunc(handFunc, auth))
+ }
+ if method == "POST" {
+ Gin.POST(uri, Auth.CheckAuthFunc(handFunc, auth))
+ }
}
diff --git a/main2.go b/main2.go
deleted file mode 100644
index e204d34..0000000
--- a/main2.go
+++ /dev/null
@@ -1,83 +0,0 @@
-package main
-
-import (
- "context"
- "fmt"
- "github.com/gin-gonic/gin"
- "go.mongodb.org/mongo-driver/mongo"
- "go.mongodb.org/mongo-driver/mongo/options"
- "log"
- "time"
-)
-
-var (
- client *mongo.Client
- err error
- result *mongo.InsertOneResult
- collection *mongo.Collection
-)
-
-// @APIVersion 1.0.0
-// @APITitle 乐游图后端接口文档
-// @BasePath 正式 leyoutu.st-i.com.cn; 测试 letu.api.imagchina.com
-func main() {
-
- // Set client options
- clientOptions := options.Client().ApplyURI("mongodb://localhost:27017")
- clientOptions.SetLocalThreshold(3 * time.Second) //只使用与mongo操作耗时小于3秒的
- clientOptions.SetMaxConnIdleTime(5 * time.Second) //指定连接可以保持空闲的最大毫秒数
- clientOptions.SetMaxPoolSize(4096) //使用最大的连接数
-
- // Connect to MongoDB
- client, err = mongo.Connect(context.TODO(), clientOptions)
-
- if err != nil {
- log.Fatal(err)
- }
-
- // Check the connection
- err = client.Ping(context.TODO(), nil)
-
- if err != nil {
- log.Fatal(err)
- }
-
- fmt.Println("Connected to MongoDB!")
-
- collection = client.Database("LeYouTu").Collection("LogRecord")
-
- r := gin.Default()
- r.GET("/AllScenic", func(c *gin.Context) {
- c.Header("Access-Control-Allow-Origin", c.Request.Header.Get("Origin"))
- c.Header("Access-Control-Allow-Credentials", "true")
-
- //var aItems = DB.SItem{}
- //if err = collection.FindOne(context.TODO(), bson.D{{}}).Decode(&aItems); err != nil {
- // println(err)
- //}
-
- record := &LogRecord{
- JobName: "job10",
- Command: "echo hello",
- Err: "",
- Content: "hello",
- }
-
- if result, err = collection.InsertOne(context.TODO(), record); err != nil {
- fmt.Println(err)
- return
- }
-
- c.JSON(200, "ok")
-
- })
-
- r.Run(":8080")
-}
-
-type LogRecord struct {
- JobName string `bson:"jobName"` // 任务名
- Command string `bson:"command"` // shell命令
- Err string `bson:"err"` // 脚本错误
- Content string `bson:"content"` // 脚本输出
-}
--
libgit2 0.21.0