Commit 8a882f01f6c1402b11033de14239d3089714d0cb

Authored by aarongao
1 parent c1e54074
Exists in v1.2 and in 2 other branches master, v1.1

1.0

.idea/inspectionProfiles/Project_Default.xml 0 → 100644
... ... @@ -0,0 +1,6 @@
  1 +<component name="InspectionProjectProfileManager">
  2 + <profile version="1.0">
  3 + <option name="myName" value="Project Default" />
  4 + <inspection_tool class="JSHint" enabled="true" level="ERROR" enabled_by_default="true" />
  5 + </profile>
  6 +</component>
0 7 \ No newline at end of file
... ...
.idea/jsLinters/jshint.xml 0 → 100644
... ... @@ -0,0 +1,16 @@
  1 +<?xml version="1.0" encoding="UTF-8"?>
  2 +<project version="4">
  3 + <component name="JSHintConfiguration" version="2.10.2" use-config-file="true" use-custom-config-file="true" custom-config-file-path="$PROJECT_DIR$/Console/html/bootstrap/grunt/.jshintrc">
  4 + <option bitwise="true" />
  5 + <option browser="true" />
  6 + <option curly="true" />
  7 + <option eqeqeq="true" />
  8 + <option forin="true" />
  9 + <option maxerr="50" />
  10 + <option noarg="true" />
  11 + <option noempty="true" />
  12 + <option nonew="true" />
  13 + <option strict="true" />
  14 + <option undef="true" />
  15 + </component>
  16 +</project>
0 17 \ No newline at end of file
... ...
.idea/letu.iml 0 → 100644
... ... @@ -0,0 +1,8 @@
  1 +<?xml version="1.0" encoding="UTF-8"?>
  2 +<module type="WEB_MODULE" version="4">
  3 + <component name="NewModuleRootManager">
  4 + <content url="file://$MODULE_DIR$" />
  5 + <orderEntry type="inheritedJdk" />
  6 + <orderEntry type="sourceFolder" forTests="false" />
  7 + </component>
  8 +</module>
0 9 \ No newline at end of file
... ...
.idea/misc.xml 0 → 100644
... ... @@ -0,0 +1,6 @@
  1 +<?xml version="1.0" encoding="UTF-8"?>
  2 +<project version="4">
  3 + <component name="JavaScriptSettings">
  4 + <option name="languageLevel" value="ES6" />
  5 + </component>
  6 +</project>
0 7 \ No newline at end of file
... ...
.idea/modules.xml 0 → 100644
... ... @@ -0,0 +1,8 @@
  1 +<?xml version="1.0" encoding="UTF-8"?>
  2 +<project version="4">
  3 + <component name="ProjectModuleManager">
  4 + <modules>
  5 + <module fileurl="file://$PROJECT_DIR$/.idea/letu.iml" filepath="$PROJECT_DIR$/.idea/letu.iml" />
  6 + </modules>
  7 + </component>
  8 +</project>
0 9 \ No newline at end of file
... ...
.idea/vcs.xml 0 → 100644
... ... @@ -0,0 +1,6 @@
  1 +<?xml version="1.0" encoding="UTF-8"?>
  2 +<project version="4">
  3 + <component name="VcsDirectoryMappings">
  4 + <mapping directory="$PROJECT_DIR$" vcs="Git" />
  5 + </component>
  6 +</project>
0 7 \ No newline at end of file
... ...
.idea/workspace.xml 0 → 100644
... ... @@ -0,0 +1,128 @@
  1 +<?xml version="1.0" encoding="UTF-8"?>
  2 +<project version="4">
  3 + <component name="ChangeListManager">
  4 + <list default="true" id="4fc60b58-eb6b-4763-99c5-b2201813bdc2" name="Default Changelist" comment="">
  5 + <change beforePath="$PROJECT_DIR$/API/Complaint.go" beforeDir="false" afterPath="$PROJECT_DIR$/API/Complaint.go" afterDir="false" />
  6 + <change beforePath="$PROJECT_DIR$/API/DealyMessage.go" beforeDir="false" afterPath="$PROJECT_DIR$/API/DealyMessage.go" afterDir="false" />
  7 + <change beforePath="$PROJECT_DIR$/API/Investigation.go" beforeDir="false" afterPath="$PROJECT_DIR$/API/Investigation.go" afterDir="false" />
  8 + <change beforePath="$PROJECT_DIR$/API/UserLog.go" beforeDir="false" afterPath="$PROJECT_DIR$/API/UserLog.go" afterDir="false" />
  9 + <change beforePath="$PROJECT_DIR$/Bin/Monitor.go" beforeDir="false" afterPath="$PROJECT_DIR$/Bin/Monitor.go" afterDir="false" />
  10 + <change beforePath="$PROJECT_DIR$/Config/config.go" beforeDir="false" afterPath="$PROJECT_DIR$/Config/config.go" afterDir="false" />
  11 + <change beforePath="$PROJECT_DIR$/Config/config.json" beforeDir="false" afterPath="$PROJECT_DIR$/Config/config.json" afterDir="false" />
  12 + <change beforePath="$PROJECT_DIR$/Lib/DelayMessage/delaymessage.go" beforeDir="false" afterPath="$PROJECT_DIR$/Lib/DelayMessage/delaymessage.go" afterDir="false" />
  13 + <change beforePath="$PROJECT_DIR$/main.go" beforeDir="false" afterPath="$PROJECT_DIR$/main.go" afterDir="false" />
  14 + <change beforePath="$PROJECT_DIR$/main2.go" beforeDir="false" />
  15 + </list>
  16 + <option name="EXCLUDED_CONVERTED_TO_IGNORED" value="true" />
  17 + <option name="SHOW_DIALOG" value="false" />
  18 + <option name="HIGHLIGHT_CONFLICTS" value="true" />
  19 + <option name="HIGHLIGHT_NON_ACTIVE_CHANGELIST" value="false" />
  20 + <option name="LAST_RESOLUTION" value="IGNORE" />
  21 + </component>
  22 + <component name="FileEditorManager">
  23 + <leaf />
  24 + </component>
  25 + <component name="GOROOT" path="/usr/local/go" />
  26 + <component name="Git.Settings">
  27 + <option name="RECENT_GIT_ROOT_PATH" value="$PROJECT_DIR$" />
  28 + </component>
  29 + <component name="ProjectConfigurationFiles">
  30 + <option name="files">
  31 + <list>
  32 + <option value="$PROJECT_DIR$/.idea/letu.iml" />
  33 + <option value="$PROJECT_DIR$/.idea/misc.xml" />
  34 + <option value="$PROJECT_DIR$/.idea/modules.xml" />
  35 + <option value="$PROJECT_DIR$/.idea/vcs.xml" />
  36 + <option value="$PROJECT_DIR$/.idea/inspectionProfiles/Project_Default.xml" />
  37 + <option value="$PROJECT_DIR$/.idea/jsLinters/jshint.xml" />
  38 + </list>
  39 + </option>
  40 + </component>
  41 + <component name="ProjectFrameBounds">
  42 + <option name="x" value="315" />
  43 + <option name="y" value="73" />
  44 + <option name="width" value="1454" />
  45 + <option name="height" value="1010" />
  46 + </component>
  47 + <component name="ProjectView">
  48 + <navigator proportions="" version="1">
  49 + <foldersAlwaysOnTop value="true" />
  50 + </navigator>
  51 + <panes>
  52 + <pane id="ProjectPane">
  53 + <subPane>
  54 + <expand>
  55 + <path>
  56 + <item name="letu" type="b2602c69:ProjectViewProjectNode" />
  57 + <item name="letu" type="462c0819:PsiDirectoryNode" />
  58 + </path>
  59 + <path>
  60 + <item name="letu" type="b2602c69:ProjectViewProjectNode" />
  61 + <item name="letu" type="462c0819:PsiDirectoryNode" />
  62 + <item name="DB" type="462c0819:PsiDirectoryNode" />
  63 + </path>
  64 + </expand>
  65 + <select />
  66 + </subPane>
  67 + </pane>
  68 + <pane id="Scope" />
  69 + </panes>
  70 + </component>
  71 + <component name="PropertiesComponent">
  72 + <property name="WebServerToolWindowFactoryState" value="false" />
  73 + <property name="go.gopath.indexing.explicitly.defined" value="true" />
  74 + <property name="go.import.settings.migrated" value="true" />
  75 + <property name="go.sdk.automatically.set" value="true" />
  76 + <property name="last_opened_file_path" value="$PROJECT_DIR$" />
  77 + <property name="nodejs_interpreter_path.stuck_in_default_project" value="undefined stuck path" />
  78 + <property name="nodejs_npm_path_reset_for_default_project" value="true" />
  79 + </component>
  80 + <component name="RunDashboard">
  81 + <option name="ruleStates">
  82 + <list>
  83 + <RuleState>
  84 + <option name="name" value="ConfigurationTypeDashboardGroupingRule" />
  85 + </RuleState>
  86 + <RuleState>
  87 + <option name="name" value="StatusDashboardGroupingRule" />
  88 + </RuleState>
  89 + </list>
  90 + </option>
  91 + </component>
  92 + <component name="ToolWindowManager">
  93 + <frame x="315" y="73" width="1454" height="1010" extended-state="0" />
  94 + <layout>
  95 + <window_info id="Favorites" side_tool="true" />
  96 + <window_info active="true" content_ui="combo" id="Project" order="0" visible="true" weight="0.25" />
  97 + <window_info id="Structure" order="1" side_tool="true" weight="0.25" />
  98 + <window_info anchor="bottom" id="Docker" show_stripe_button="false" />
  99 + <window_info anchor="bottom" id="Database Changes" />
  100 + <window_info anchor="bottom" id="Version Control" />
  101 + <window_info anchor="bottom" id="Terminal" />
  102 + <window_info anchor="bottom" id="Event Log" side_tool="true" />
  103 + <window_info anchor="bottom" id="Message" order="0" />
  104 + <window_info anchor="bottom" id="Find" order="1" />
  105 + <window_info anchor="bottom" id="Run" order="2" />
  106 + <window_info anchor="bottom" id="Debug" order="3" weight="0.4" />
  107 + <window_info anchor="bottom" id="Cvs" order="4" weight="0.25" />
  108 + <window_info anchor="bottom" id="Inspection" order="5" weight="0.4" />
  109 + <window_info anchor="bottom" id="TODO" order="6" />
  110 + <window_info anchor="right" id="Database" />
  111 + <window_info anchor="right" id="Commander" internal_type="SLIDING" order="0" type="SLIDING" weight="0.4" />
  112 + <window_info anchor="right" id="Ant Build" order="1" weight="0.25" />
  113 + <window_info anchor="right" content_ui="combo" id="Hierarchy" order="2" weight="0.25" />
  114 + </layout>
  115 + </component>
  116 + <component name="TypeScriptGeneratedFilesManager">
  117 + <option name="version" value="1" />
  118 + </component>
  119 + <component name="editorHistoryManager">
  120 + <entry file="file://$PROJECT_DIR$/DB/db.go">
  121 + <provider selected="true" editor-type-id="text-editor">
  122 + <state relative-caret-position="270">
  123 + <caret line="22" column="41" lean-forward="true" selection-start-line="22" selection-start-column="41" selection-end-line="22" selection-end-column="41" />
  124 + </state>
  125 + </provider>
  126 + </entry>
  127 + </component>
  128 +</project>
0 129 \ No newline at end of file
... ...
API/Complaint.go
... ... @@ -59,7 +59,6 @@ func CreateComplaint(c *gin.Context) {
59 59 "验证码不正确",
60 60 })
61 61 return
62   -
63 62 }
64 63  
65 64 var images []string
... ... @@ -74,7 +73,7 @@ func CreateComplaint(c *gin.Context) {
74 73 c.PostForm("Sex"),
75 74 c.PostForm("Content"),
76 75 images,
77   - "",
  76 + "未处理",
78 77 time.Now().Unix(),
79 78 })
80 79  
... ... @@ -124,7 +123,7 @@ func AllComplaint(c *gin.Context) {
124 123 0,
125 124 total,
126 125 currPage,
127   - int(math.Ceil(float64(total) / float64(limit))),
  126 + int64(math.Ceil(float64(total) / float64(limit))),
128 127 limit,
129 128 aComplaint,
130 129 })
... ...
API/DealyMessage.go
... ... @@ -2,11 +2,13 @@ package Api
2 2  
3 3 import (
4 4 "github.com/aarongao/tools"
  5 + "github.com/aliyun/alibaba-cloud-sdk-go/services/push"
5 6 "github.com/gin-gonic/gin"
6 7 "go.mongodb.org/mongo-driver/bson"
7 8 "go.mongodb.org/mongo-driver/bson/primitive"
  9 + "letu/Config"
  10 + "letu/DB"
8 11 "letu/Lib/DelayMessage"
9   - "letu/Lib/Token"
10 12 )
11 13  
12 14 // @Title 查询用户的定时提醒
... ... @@ -15,26 +17,19 @@ import (
15 17 // @Produce json
16 18 // @Param UserId 5dfb03070a9ac17ac7a82054 string true "用户id"
17 19 // @Param Token wgergejfwe string true "用户token"
18   -// @Success 200 {object} tools.ResponseSeccess "DelayTime=执行时间;Type=类型(0请求url地址1发送app通知);Fail失败次数;Title=通知标题;Content=通知内容;UDID=设备id"
  20 +// @Success 200 {object} tools.ResponseSeccess "DelayTime=执行时间;Type=类型(0请求url地址1发送app通知);Fail失败次数;Title=通知标题;Content=通知内容;DeviceToken=设备id"
19 21 // @Failure 500 {object} tools.ResponseError "{"errcode":1,"errmsg":"错误原因"}"
20 22 // @Router /DealyMessage/Info? [get]
21 23 func DealyMessageInfo(c *gin.Context) {
22 24 c.Header("Access-Control-Allow-Origin", c.Request.Header.Get("Origin"))
23 25 c.Header("Access-Control-Allow-Credentials", "true")
24 26  
25   - _, err := primitive.ObjectIDFromHex(c.Query("UserId"))
26   - if c.Query("Token") == "" || err != nil {
27   - c.JSON(200, tools.ResponseError{
28   - 1,
29   - "Token或者用户id不正确",
30   - })
31   - return
32   - }
33   -
34   - if Token.GetToken(c.Query("UserId")) != c.Query("Token") {
  27 + _user, _ := c.Get("UserInfo")
  28 + user := _user.(*DB.SMember)
  29 + if c.Query("UserId") != user.Id.Hex() {
35 30 c.JSON(200, tools.ResponseError{
36 31 401,
37   - "token过期",
  32 + "没有权限",
38 33 })
39 34 return
40 35 }
... ... @@ -46,7 +41,7 @@ func DealyMessageInfo(c *gin.Context) {
46 41 for cur.Next(tools.GetContext()) {
47 42 var e DelayMessage.Message
48 43 cur.Decode(&e)
49   - aDelayMessage = append(aDelayMessage,e)
  44 + aDelayMessage = append(aDelayMessage, e)
50 45 }
51 46 }
52 47  
... ... @@ -65,7 +60,7 @@ func DealyMessageInfo(c *gin.Context) {
65 60 // @Produce json
66 61 // @Param UserId 5dfb03070a9ac17ac7a82054 string true "用户id"
67 62 // @Param Token wgergejfwe string true "用户token"
68   -// @Param UDID 5dfb03070a9ac17ac7a82054 string true "设备id"
  63 +// @Param DeviceToken 5dfb03070a9ac17ac7a82054 string true "设备id"
69 64 // @Param Title 表演时间提醒 string true "标题"
70 65 // @Param Content 5分钟后有表演 string true "内容"
71 66 // @Param DelayTime 1579066863 string true "到达这个时间戳就执行"
... ... @@ -76,24 +71,27 @@ func CreateDealyMessage(c *gin.Context) {
76 71 c.Header("Access-Control-Allow-Origin", c.Request.Header.Get("Origin"))
77 72 c.Header("Access-Control-Allow-Credentials", "true")
78 73  
79   - _,err := primitive.ObjectIDFromHex(c.PostForm("UserId"))
80   - if c.PostForm("Token") == "" || err != nil {
  74 +
  75 + _user, _ := c.Get("UserInfo")
  76 + userToken := _user.(*DB.SMember)
  77 + if c.PostForm("UserId") != userToken.Id.Hex(){
81 78 c.JSON(200, tools.ResponseError{
82   - 1,
83   - "Token或者用户id不正确",
  79 + 401,
  80 + "没有权限",
84 81 })
85 82 return
86 83 }
87 84  
88   - if Token.GetToken(c.PostForm("UserId")) != c.PostForm("Token") {
  85 + _, err := primitive.ObjectIDFromHex(c.PostForm("UserId"))
  86 + if err != nil {
89 87 c.JSON(200, tools.ResponseError{
90   - 401,
91   - "token过期",
  88 + 1,
  89 + "id不正确",
92 90 })
93 91 return
94 92 }
95 93  
96   - err = DelayMessage.GlobalDM.AddTaskForAppMessage(c.PostForm("DelayTime"), c.PostForm("UDID"), c.PostForm("Title"), c.PostForm("Content"), c.PostForm("UserId"))
  94 + err = DelayMessage.GlobalDM.AddTaskForAppMessage(c.PostForm("DelayTime"), c.PostForm("DeviceToken"), c.PostForm("Title"), c.PostForm("Content"), c.PostForm("UserId"))
97 95  
98 96 if err == nil {
99 97  
... ... @@ -125,20 +123,21 @@ func RemoveDealyMessage(c *gin.Context) {
125 123 c.Header("Access-Control-Allow-Origin", c.Request.Header.Get("Origin"))
126 124 c.Header("Access-Control-Allow-Credentials", "true")
127 125  
128   -
129   - _,err := primitive.ObjectIDFromHex(c.PostForm("UserId"))
130   - if c.PostForm("Token") == "" || err != nil {
  126 + _user, _ := c.Get("UserInfo")
  127 + userToken := _user.(*DB.SMember)
  128 + if c.PostForm("UserId") != userToken.Id.Hex(){
131 129 c.JSON(200, tools.ResponseError{
132   - 1,
133   - "Token或者用户id不正确",
  130 + 401,
  131 + "没有权限",
134 132 })
135 133 return
136 134 }
137 135  
138   - if Token.GetToken(c.PostForm("UserId")) != c.PostForm("Token") {
  136 + _, err := primitive.ObjectIDFromHex(c.PostForm("UserId"))
  137 + if err != nil {
139 138 c.JSON(200, tools.ResponseError{
140   - 401,
141   - "token过期",
  139 + 1,
  140 + "用户id不正确",
142 141 })
143 142 return
144 143 }
... ... @@ -151,3 +150,34 @@ func RemoveDealyMessage(c *gin.Context) {
151 150 })
152 151  
153 152 }
  153 +
  154 +
  155 +func PushNoticeToiOS(c *gin.Context) {
  156 + c.Header("Access-Control-Allow-Origin", c.Request.Header.Get("Origin"))
  157 + c.Header("Access-Control-Allow-Credentials", "true")
  158 +
  159 + // 推送app消息
  160 + client, err := push.NewClientWithAccessKey("cn-hangzhou", "LTAI4FdQeNMQXRU6u5J3EFQc", "PwvyF5rRNBWLDya41WrCpvENevYZGi")
  161 +
  162 + request := push.CreatePushNoticeToiOSRequest()
  163 + request.ApnsEnv = Config.Info.Env
  164 + request.AppKey = "28332889"
  165 + request.Scheme = "https"
  166 + request.Target = "DEVICE"
  167 + request.TargetValue = "30076ed6fdb740e49d882433931bc34a"
  168 + request.Title = c.Query("title")
  169 + request.Body = c.Query("body")
  170 +
  171 + response, err := client.PushNoticeToiOS(request)
  172 + if err != nil {
  173 + c.JSON(200, tools.ResponseError{
  174 + 1,
  175 + err.Error(),
  176 + })
  177 + return
  178 + }
  179 + c.JSON(200, tools.ResponseSeccess{
  180 + 0,
  181 + response,
  182 + })
  183 +}
154 184 \ No newline at end of file
... ...
API/Icon.go
... ... @@ -7,6 +7,7 @@ import (
7 7 "go.mongodb.org/mongo-driver/bson/primitive"
8 8 "go.mongodb.org/mongo-driver/mongo/options"
9 9 "letu/DB"
  10 + "letu/Lib/Auth"
10 11 )
11 12  
12 13 // @Title 返回图标基础信息
... ... @@ -45,6 +46,8 @@ func IconInfo(c *gin.Context) {
45 46 // @Accept json
46 47 // @Produce json
47 48 // @Param id 5dfb03070a9ac17ac7a82054 string true "图标id"
  49 +// @Param ScenicId 5e0d504e24e03431008b4567 string true "景区id"
  50 +// @Param Token wgergejfwe string true "用户token"
48 51 // @Success 200 {object} tools.ResponseSeccess "Name名称:Picture图片地址:id图标id:ScenicId景区id"
49 52 // @Failure 500 {object} tools.ResponseError "{"errcode":1,"errmsg":"错误原因"}"
50 53 // @Router /Icon/Update? [post]
... ... @@ -52,11 +55,13 @@ func UpdateIcon(c *gin.Context) {
52 55 c.Header("Access-Control-Allow-Origin", c.Request.Header.Get("Origin"))
53 56 c.Header("Access-Control-Allow-Credentials", "true")
54 57  
55   - ScenicId := c.PostForm("ScenicId")
56   - if ScenicId == "" || ScenicId == "undefined" {
  58 + _user, _ := c.Get("UserInfo")
  59 + user := _user.(*DB.SMember)
  60 + err := Auth.CheckScenicAuth(c.PostForm("ScenicId"), user)
  61 + if err != nil {
57 62 c.JSON(200, tools.ResponseError{
58   - 1,
59   - "缺少ScenicId(景区id)",
  63 + 401,
  64 + "没有权限",
60 65 })
61 66 return
62 67 }
... ... @@ -74,7 +79,7 @@ func UpdateIcon(c *gin.Context) {
74 79 bson.M{"$set": bson.M{
75 80 "Name": c.PostForm("Name"),
76 81 "Picture": c.PostForm("Picture"),
77   - "ScenicId": ScenicId,
  82 + "ScenicId": c.PostForm("ScenicId"),
78 83 }}, &options.FindOneAndUpdateOptions{
79 84 Upsert: &upsert,
80 85 },
... ... @@ -99,13 +104,9 @@ func AllIcons(c *gin.Context) {
99 104 c.Header("Access-Control-Allow-Origin", c.Request.Header.Get("Origin"))
100 105 c.Header("Access-Control-Allow-Credentials", "true")
101 106  
102   - ScenicId := c.Query("ScenicId")
103   - if ScenicId == "" || ScenicId == "undefined" {
104   - c.JSON(200, tools.ResponseError{
105   - 1,
106   - "缺少ScenicId(景区id)",
107   - })
108   - return
  107 + var ScenicId string
  108 + if ScenicId = c.Query("ScenicId"); ScenicId == "" {
  109 + ScenicId = "5e0d504e24e03431008b4567" // 乐岛
109 110 }
110 111  
111 112 var SIcons = []DB.SIcons{}
... ... @@ -115,11 +116,10 @@ func AllIcons(c *gin.Context) {
115 116 for cur.Next(tools.GetContext()) {
116 117 var e DB.SIcons
117 118 cur.Decode(&e)
118   - SIcons = append(SIcons,e)
  119 + SIcons = append(SIcons, e)
119 120 }
120 121 }
121 122  
122   -
123 123 c.JSON(200, tools.ResponseSeccess{
124 124 0,
125 125 SIcons,
... ...
API/Investigation.go
... ... @@ -80,7 +80,7 @@ func AllInvestigation(c *gin.Context) {
80 80 0,
81 81 total,
82 82 currPage,
83   - int(math.Ceil(float64(total) / float64(limit))),
  83 + int64(math.Ceil(float64(total) / float64(limit))),
84 84 limit,
85 85 aInvestigation,
86 86 })
... ...
API/Item.go
... ... @@ -8,6 +8,7 @@ import (
8 8 "go.mongodb.org/mongo-driver/bson/primitive"
9 9 "go.mongodb.org/mongo-driver/mongo/options"
10 10 "letu/DB"
  11 + "letu/Lib/Auth"
11 12 "strconv"
12 13 "time"
13 14 )
... ... @@ -33,8 +34,8 @@ func ItemInfo(c *gin.Context) {
33 34 }
34 35  
35 36 var SItem DB.SItem
36   - objID,_ := primitive.ObjectIDFromHex(c.Query("id"))
37   - DB.CItem.FindOne(tools.GetContext(),bson.M{"_id": objID}).Decode(&SItem)
  37 + objID, _ := primitive.ObjectIDFromHex(c.Query("id"))
  38 + DB.CItem.FindOne(tools.GetContext(), bson.M{"_id": objID}).Decode(&SItem)
38 39  
39 40 c.JSON(200, tools.ResponseSeccess{
40 41 0,
... ... @@ -47,6 +48,7 @@ func ItemInfo(c *gin.Context) {
47 48 // @Description 设备管理 - 查询所有游玩项目
48 49 // @Accept json
49 50 // @Produce json
  51 +// @Param ScenicId 5dfb03070a9ac17ac7a82054 string true "景区id"
50 52 // @Success 200 {object} tools.ResponseSeccess "Tags所属标签,标签有分类;LimitHeight限高;PlayDuration游玩时长;SceneTime场次时间;Picture照片;Voice音频;AverageConsumption平均消费;Menu菜单, OpenHours开放时间: LocationDescription位置描述; Reminder温馨提示; State运行状态0=正常1=停运"
51 53 // @Failure 500 {object} tools.ResponseError "{"errcode":1,"errmsg":"错误原因"}"
52 54 // @Router /AllItems? [get]
... ... @@ -54,14 +56,19 @@ func AllItems(c *gin.Context) {
54 56 c.Header("Access-Control-Allow-Origin", c.Request.Header.Get("Origin"))
55 57 c.Header("Access-Control-Allow-Credentials", "true")
56 58  
  59 + var ScenicId string
  60 + if ScenicId = c.Query("ScenicId");ScenicId == ""{
  61 + ScenicId = "5e0d504e24e03431008b4567" // 乐岛
  62 + }
  63 +
57 64 var aItems = []DB.SItem{}
58   - cur, err := DB.CItem.Find(tools.GetContext(), bson.M{})
  65 + cur, err := DB.CItem.Find(tools.GetContext(), bson.M{"ScenicId": ScenicId})
59 66 defer cur.Close(tools.GetContext())
60 67 if err == nil {
61 68 for cur.Next(tools.GetContext()) {
62 69 var e DB.SItem
63 70 cur.Decode(&e)
64   - aItems = append(aItems,e)
  71 + aItems = append(aItems, e)
65 72 }
66 73 }
67 74  
... ... @@ -73,6 +80,9 @@ func AllItems(c *gin.Context) {
73 80 // @Description 设备管理 - 更新设施
74 81 // @Accept json
75 82 // @Produce json
  83 +// @Param id 5dfb03070a9ac17ac7a82054 string true "设备id"
  84 +// @Param ScenicId 5dfb03070a9ac17ac7a82054 string true "景区id"
  85 +// @Param Token wgergejfwe string true "用户token"
76 86 // @Success 200 {object} tools.ResponseSeccess "Tags所属标签,标签有分类;LimitHeight限高;PlayDuration游玩时长;SceneTime场次时间;Picture照片;Voice音频;AverageConsumption平均消费;Menu菜单, OpenHours开放时间: LocationDescription位置描述; Reminder温馨提示; State运行状态0=正常1=停运"
77 87 // @Failure 500 {object} tools.ResponseError "{"errcode":1,"errmsg":"错误原因"}"
78 88 // @Router /UpdateItem? [post]
... ... @@ -80,6 +90,17 @@ func UpdateItem(c *gin.Context) {
80 90 c.Header("Access-Control-Allow-Origin", c.Request.Header.Get("Origin"))
81 91 c.Header("Access-Control-Allow-Credentials", "true")
82 92  
  93 + _user, _ := c.Get("UserInfo")
  94 + user := _user.(*DB.SMember)
  95 + err := Auth.CheckScenicAuth(c.PostForm("ScenicId"), user)
  96 + if err != nil {
  97 + c.JSON(200, tools.ResponseError{
  98 + 401,
  99 + "没有权限",
  100 + })
  101 + return
  102 + }
  103 +
83 104 var Location DB.SLocation
84 105 json.Unmarshal([]byte(c.PostForm("Location")), &Location)
85 106  
... ... @@ -93,7 +114,7 @@ func UpdateItem(c *gin.Context) {
93 114 if pid := c.PostForm("id"); pid == "null" {
94 115 id = primitive.NewObjectID()
95 116 } else {
96   - id,_ = primitive.ObjectIDFromHex(pid)
  117 + id, _ = primitive.ObjectIDFromHex(pid)
97 118 }
98 119  
99 120 poststate, _ := strconv.Atoi(c.PostForm("State"))
... ... @@ -104,6 +125,7 @@ func UpdateItem(c *gin.Context) {
104 125 bson.M{"$set": bson.M{
105 126 "Name": c.PostForm("Name"),
106 127 "SubName": c.PostForm("SubName"),
  128 + "ScenicId": c.PostForm("ScenicId"),
107 129 "Location": Location,
108 130 "Icon": c.PostForm("Icon"),
109 131 "LimitHeight": c.PostForm("LimitHeight"),
... ... @@ -124,24 +146,21 @@ func UpdateItem(c *gin.Context) {
124 146 },
125 147 )
126 148  
127   -
128   -
129 149 // 更新等待时间
130 150 allteim := DB.Redis.Get("AllItemTime")
131   - jsond,_ := json.Marshal(allteim)
  151 + jsond, _ := json.Marshal(allteim)
132 152  
133 153 var ItemTime map[string]string
134 154 json.Unmarshal([]byte(jsond), &ItemTime)
135 155  
136   - if poststate == 1{
  156 + if poststate == 1 {
137 157 ItemTime[c.PostForm("id")] = "--"
138 158 }
139   - if poststate == 0{
  159 + if poststate == 0 {
140 160 ItemTime[c.PostForm("id")] = "0"
141 161 }
142 162 DB.Redis.Set("AllItemTime", ItemTime, time.Second*60*60*24*30)
143 163  
144   -
145 164 c.JSON(200, tools.ResponseSeccess{
146 165 0,
147 166 "ok",
... ... @@ -158,6 +177,8 @@ type ItemTime struct {
158 177 // @Description 设备管理 - 更新等待时间
159 178 // @Accept json
160 179 // @Produce json
  180 +// @Param ScenicId 5dfb03070a9ac17ac7a82054 string true "景区id"
  181 +// @Param Token wgergejfwe string true "用户token"
161 182 // @Param item [{"id":"5df864740a9ac17ac7a7feb8","time":"20"},{"id":"5df8660924e03417008b4567","time":"33"}] string true "设备列表"
162 183 // @Success 200 {object} tools.ResponseSeccess "{errcode: 0, result: "ok"}"
163 184 // @Failure 500 {object} tools.ResponseError "{"errcode":1,"errmsg":"错误原因"}"
... ... @@ -166,6 +187,17 @@ func UpdateItemTime(c *gin.Context) {
166 187 c.Header("Access-Control-Allow-Origin", c.Request.Header.Get("Origin"))
167 188 c.Header("Access-Control-Allow-Credentials", "true")
168 189  
  190 + _user, _ := c.Get("UserInfo")
  191 + user := _user.(*DB.SMember)
  192 + err := Auth.CheckScenicAuth(c.PostForm("ScenicId"), user)
  193 + if err != nil {
  194 + c.JSON(200, tools.ResponseError{
  195 + 401,
  196 + "没有权限",
  197 + })
  198 + return
  199 + }
  200 +
169 201 var ItemTime []ItemTime
170 202 json.Unmarshal([]byte(c.PostForm("items")), &ItemTime)
171 203  
... ... @@ -174,7 +206,7 @@ func UpdateItemTime(c *gin.Context) {
174 206 RedisData[v.Id] = v.Time
175 207 }
176 208  
177   - DB.Redis.Set("AllItemTime", RedisData, time.Second*60*60*24*30)
  209 + DB.Redis.Set("AllItemTime_"+c.PostForm("ScenicId"), RedisData, time.Second*60*60*24*30)
178 210 c.JSON(200, tools.ResponseSeccess{
179 211 0,
180 212 "ok",
... ... @@ -185,6 +217,7 @@ func UpdateItemTime(c *gin.Context) {
185 217 // @Description 设备管理 - 获得所有设备的等待时间
186 218 // @Accept json
187 219 // @Produce json
  220 +// @Param ScenicId 5dfb03070a9ac17ac7a82054 string true "景区id"
188 221 // @Success 200 {object} tools.ResponseSeccess "{5df864740a9ac17ac7a7feb8: '20',.....}"
189 222 // @Failure 500 {object} tools.ResponseError "{}"
190 223 // @Router /AllItemTime? [get]
... ... @@ -192,25 +225,16 @@ func AllItemTime(c *gin.Context) {
192 225 c.Header("Access-Control-Allow-Origin", c.Request.Header.Get("Origin"))
193 226 c.Header("Access-Control-Allow-Credentials", "true")
194 227  
  228 + var ScenicId string
  229 + if ScenicId = c.Query("ScenicId");ScenicId == ""{
  230 + ScenicId = "5e0d504e24e03431008b4567" // 乐岛
  231 + }
195 232  
196   - //Device := DB.SDevice{
197   - // c.Request.Header.Get("DeviceId"),
198   - // c.Request.Header.Get("Mac"),
199   - // c.Request.Header.Get("UDID"),
200   - // c.Request.Header.Get("SystemVersion"),
201   - // c.Request.Header.Get("SystemModel"),
202   - // c.Request.Header.Get("AppVersion"),
203   - // c.Request.Header.Get("AppVersion"),
204   - // c.Request.Header.Get("DeviceToken"),
205   - //}
206   - //spew.Dump(Device)
207   -
208   -
209   - allteim := DB.Redis.Get("AllItemTime")
  233 + allteim := DB.Redis.Get("AllItemTime_" + ScenicId)
210 234 if allteim != nil {
211 235 c.JSON(200, allteim)
212 236 } else {
213 237 c.String(200, "{}")
214 238 }
215 239  
216   -}
217 240 \ No newline at end of file
  241 +}
... ...
API/Line.go
... ... @@ -8,6 +8,7 @@ import (
8 8 "go.mongodb.org/mongo-driver/bson/primitive"
9 9 "go.mongodb.org/mongo-driver/mongo/options"
10 10 "letu/DB"
  11 + "letu/Lib/Auth"
11 12 )
12 13  
13 14 // @Title 查询线路信息
... ... @@ -52,14 +53,19 @@ func AllLine(c *gin.Context) {
52 53 c.Header("Access-Control-Allow-Origin", c.Request.Header.Get("Origin"))
53 54 c.Header("Access-Control-Allow-Credentials", "true")
54 55  
  56 + var ScenicId string
  57 + if ScenicId = c.Query("ScenicId");ScenicId == ""{
  58 + ScenicId = "5e0d504e24e03431008b4567" // 乐岛
  59 + }
  60 +
55 61 var aLine []DB.SLine
56   - cur, err := DB.CLine.Find(tools.GetContext(), bson.M{})
  62 + cur, err := DB.CLine.Find(tools.GetContext(), bson.M{"ScenicId": ScenicId})
57 63 defer cur.Close(tools.GetContext())
58 64 if err == nil {
59 65 for cur.Next(tools.GetContext()) {
60 66 var e DB.SLine
61 67 cur.Decode(&e)
62   - aLine = append(aLine,e)
  68 + aLine = append(aLine, e)
63 69 }
64 70 }
65 71  
... ... @@ -71,13 +77,29 @@ func AllLine(c *gin.Context) {
71 77 // @Description 更新线路
72 78 // @Accept json
73 79 // @Produce json
  80 +// @Param id 5dfb03070a9ac17ac7a82054 string true "线路id"
  81 +// @Param ScenicId 5dfb03070a9ac17ac7a82054 string true "景区id"
  82 +// @Param Token wgergejfwe string true "用户token"
74 83 // @Success 200 {object} tools.ResponseSeccess ""
75 84 // @Failure 500 {object} tools.ResponseError "{"errcode":1,"errmsg":"错误原因"}"
76 85 // @Router /UpdateLine? [post]
77 86 func UpdateLine(c *gin.Context) {
  87 +
78 88 c.Header("Access-Control-Allow-Origin", c.Request.Header.Get("Origin"))
79 89 c.Header("Access-Control-Allow-Credentials", "true")
80 90  
  91 + _user, _ := c.Get("UserInfo")
  92 + user := _user.(*DB.SMember)
  93 + err := Auth.CheckScenicAuth(c.PostForm("ScenicId"), user)
  94 + if err != nil {
  95 + c.JSON(200, tools.ResponseError{
  96 + 401,
  97 + "没有权限",
  98 + })
  99 + return
  100 + }
  101 +
  102 +
81 103 var Location []DB.SLocation
82 104 json.Unmarshal([]byte(c.PostForm("Location")), &Location)
83 105  
... ... @@ -88,7 +110,7 @@ func UpdateLine(c *gin.Context) {
88 110 if pid := c.PostForm("id"); pid == "null" {
89 111 id = primitive.NewObjectID()
90 112 } else {
91   - id,_ = primitive.ObjectIDFromHex(pid)
  113 + id, _ = primitive.ObjectIDFromHex(pid)
92 114 }
93 115  
94 116 upsert := true
... ...
API/Operator.go 0 → 100644
... ... @@ -0,0 +1,188 @@
  1 +package Api
  2 +
  3 +import (
  4 + "encoding/json"
  5 + "github.com/aarongao/tools"
  6 + "github.com/gin-gonic/gin"
  7 + "go.mongodb.org/mongo-driver/bson"
  8 + "go.mongodb.org/mongo-driver/bson/primitive"
  9 + "letu/DB"
  10 + "letu/Lib/Auth"
  11 + "letu/Lib/JWT"
  12 + "time"
  13 +)
  14 +
  15 +// @Title 登录
  16 +// @Description 操作员管理 - 操作员登录
  17 +// @Accept json
  18 +// @Produce json
  19 +// @Param Username aaron string true "用户名"
  20 +// @Param Password 123 string true "密码"
  21 +// @Success 200 {object} tools.ResponseSeccess "{"errcode":0,"result":{"Id":"5e09c64c1c09c6f0f7ca2fa9","Token":"640bf934e425aba5d3c90998b2641f2f0ca07261d334d9615d1cd4790b5f34e7"}} 调用其它需要登陆的接口时携带token,有过期时间"
  22 +// @Failure 500 {object} tools.ResponseError "{"errcode":1,"errmsg":"错误原因"}"
  23 +// @Router /LoginOperator? [post]
  24 +func LoginOperator(c *gin.Context) {
  25 + c.Header("Access-Control-Allow-Origin", c.Request.Header.Get("Origin"))
  26 + c.Header("Access-Control-Allow-Credentials", "true")
  27 +
  28 + selected := bson.M{}
  29 + var User *DB.SMember
  30 + if c.PostForm("Username") != "" && c.PostForm("Password") != "" {
  31 + selected["Username"] = c.PostForm("Username")
  32 + selected["Password"] = c.PostForm("Password")
  33 + DB.CMember.FindOne(tools.GetContext(), selected).Decode(&User)
  34 +
  35 + if User == nil {
  36 + c.JSON(200, tools.ResponseError{
  37 + 1,
  38 + "用户不存在",
  39 + })
  40 + return
  41 + }
  42 +
  43 + } else {
  44 + c.JSON(200, tools.ResponseError{
  45 + 1,
  46 + "不能为空",
  47 + })
  48 + return
  49 + }
  50 +
  51 + // 生成token
  52 + dd, _ := time.ParseDuration("8760h")
  53 + User.Token, _ = JWT.CreateToken(User, time.Now().Add(dd).Unix())
  54 + c.JSON(200, tools.ResponseSeccess{
  55 + 0,
  56 + User,
  57 + })
  58 +
  59 +}
  60 +
  61 +// @Title 操作员管理
  62 +// @Description 操作员管理 - 修改用户信息
  63 +// @Accept json
  64 +// @Produce json
  65 +// @Param id aaron string true "用户id""
  66 +// @Param ScenicId 5e0d504e24e03431008b4567 string true "景区id"
  67 +// @Param Token wgergejfwe string true "用户token"
  68 +// @Param Username aarongao string true "用户名"
  69 +// @Param Remarks 18616619599 string true "备注"
  70 +// @Param Password 12345 string true "密码"
  71 +// @Success 200 {object} tools.ResponseSeccess "{"errcode":0,"result":"ok"}"
  72 +// @Failure 500 {object} tools.ResponseError "{"errcode":1,"errmsg":"错误原因"}"
  73 +// @Router /UpdateOperator? [post]
  74 +func UpdateOperator(c *gin.Context) {
  75 + c.Header("Access-Control-Allow-Origin", c.Request.Header.Get("Origin"))
  76 + c.Header("Access-Control-Allow-Credentials", "true")
  77 +
  78 + _user, _ := c.Get("UserInfo")
  79 + user := _user.(*DB.SMember)
  80 + err := Auth.CheckScenicAuth(c.PostForm("ScenicId"), user)
  81 + if err != nil {
  82 + c.JSON(200, tools.ResponseError{
  83 + 401,
  84 + "没有权限",
  85 + })
  86 + return
  87 + }
  88 +
  89 + var _auth []string
  90 + json.Unmarshal([]byte(c.PostForm("Auth")), &_auth)
  91 +
  92 + objID, err := primitive.ObjectIDFromHex(c.PostForm("id"))
  93 + if err == nil {
  94 +
  95 + _, err = DB.CMember.UpdateOne(tools.GetContext(),
  96 + bson.M{"_id": objID},
  97 + bson.M{"$set": bson.M{
  98 + "Auth": _auth,
  99 + "Username": c.PostForm("Username"),
  100 + "Password": c.PostForm("Password"),
  101 + "Remarks": c.PostForm("Remarks"),
  102 + }},
  103 + )
  104 + } else {
  105 +
  106 + objectID := primitive.NewObjectID()
  107 + User := &DB.SMember{
  108 + &objectID,
  109 + "operator",
  110 + c.PostForm("ScenicId"),
  111 + c.PostForm("Username"),
  112 + c.PostForm("Password"),
  113 + "",
  114 + "",
  115 + "",
  116 + "",
  117 + "",
  118 + "",
  119 + &DB.SDevice{},
  120 + _auth,
  121 + c.PostForm("Remarks"),
  122 + }
  123 +
  124 + // 生成token
  125 + var dd time.Duration
  126 + dd, err = time.ParseDuration("20m")
  127 + User.Token, _ = JWT.CreateToken(User, time.Now().Add(dd).Unix())
  128 +
  129 + DB.CMember.InsertOne(tools.GetContext(), User)
  130 +
  131 + }
  132 +
  133 + if err == nil {
  134 + c.JSON(200, tools.ResponseSeccess{
  135 + 0,
  136 + "ok",
  137 + })
  138 + } else {
  139 + c.JSON(200, tools.ResponseError{
  140 + 1,
  141 + err.Error(),
  142 + })
  143 + }
  144 +
  145 +}
  146 +
  147 +// @Title 操作员管理
  148 +// @Description 操作员管理 - 所有操作员
  149 +// @Accept json
  150 +// @Produce json
  151 +// @Param ScenicId 5dfb03070a9ac17ac7a82054 string true "景区id"
  152 +// @Param Token 5dfb03070a9ac17ac7a82054 string true "用户token"
  153 +// @Success 200 {object} tools.ResponseSeccess ""
  154 +// @Failure 500 {object} tools.ResponseError "{"errcode":1,"errmsg":"错误原因"}"
  155 +// @Router /AllOperator? [get]
  156 +func AllOperator(c *gin.Context) {
  157 + c.Header("Access-Control-Allow-Origin", c.Request.Header.Get("Origin"))
  158 + c.Header("Access-Control-Allow-Credentials", "true")
  159 + _user, _ := c.Get("UserInfo")
  160 + user := _user.(*DB.SMember)
  161 + err := Auth.CheckScenicAuth(c.Query("ScenicId"), user)
  162 + if err != nil {
  163 + c.JSON(200, tools.ResponseError{
  164 + 401,
  165 + "没有权限",
  166 + })
  167 + return
  168 + }
  169 +
  170 + var aMember []*DB.SMember
  171 + cur, err := DB.CMember.Find(tools.GetContext(), bson.M{"ScenicId": c.Query("ScenicId"), "UserType": "operator"})
  172 + defer cur.Close(tools.GetContext())
  173 + if err == nil {
  174 + for cur.Next(tools.GetContext()) {
  175 + var e *DB.SMember
  176 + cur.Decode(&e)
  177 + aMember = append(aMember, e)
  178 + }
  179 + }
  180 +
  181 + if aMember == nil {
  182 + aMember = []*DB.SMember{}
  183 + }
  184 + c.JSON(200, tools.ResponseSeccess{
  185 + 0,
  186 + aMember,
  187 + })
  188 +}
... ...
API/Scenic.go
... ... @@ -8,6 +8,7 @@ import (
8 8 "go.mongodb.org/mongo-driver/bson/primitive"
9 9 "go.mongodb.org/mongo-driver/mongo/options"
10 10 "letu/DB"
  11 + "letu/Lib/Auth"
11 12 )
12 13  
13 14 // @Title 返回景区基础信息
... ... @@ -46,6 +47,7 @@ func ScenicInfo(c *gin.Context) {
46 47 // @Accept json
47 48 // @Produce json
48 49 // @Param id 5dfb03070a9ac17ac7a82054 string true "景区id"
  50 +// @Param Token wgergejfwe string true "用户token"
49 51 // @Success 200 {object} tools.ResponseSeccess "Name名称;Describe介绍;OpenHours营业时间;Picture最上面图片;ShopAdPicture商城列表页图片;ItemScenicPicture项目场次照片;ActivityPicture活动照片;VideoList视频(VideoPicture=首桢图片);InvestigationUrl问券调查的url;RangeLocation景区范围(多个坐标点)"
50 52 // @Failure 500 {object} tools.ResponseError "{"errcode":1,"errmsg":"错误原因"}"
51 53 // @Router /UpdateScenic? [post]
... ... @@ -53,6 +55,18 @@ func UpdateScenic(c *gin.Context) {
53 55 c.Header("Access-Control-Allow-Origin", c.Request.Header.Get("Origin"))
54 56 c.Header("Access-Control-Allow-Credentials", "true")
55 57  
  58 + _user, _ := c.Get("UserInfo")
  59 + user := _user.(*DB.SMember)
  60 + err := Auth.CheckScenicAuth(c.PostForm("id"), user)
  61 + if err != nil {
  62 + c.JSON(200, tools.ResponseError{
  63 + 401,
  64 + "没有权限",
  65 + })
  66 + return
  67 + }
  68 +
  69 +
56 70 var Location DB.SLocation
57 71 json.Unmarshal([]byte(c.PostForm("Location")), &Location)
58 72  
... ...
API/Shop.go
... ... @@ -8,6 +8,7 @@ import (
8 8 "go.mongodb.org/mongo-driver/bson/primitive"
9 9 "go.mongodb.org/mongo-driver/mongo/options"
10 10 "letu/DB"
  11 + "letu/Lib/Auth"
11 12 )
12 13  
13 14 // @Title 查询商品信息
... ... @@ -45,6 +46,7 @@ func CommodityInfo(c *gin.Context) {
45 46 // @Description 查询所有商品
46 47 // @Accept json
47 48 // @Produce json
  49 +// @Param ScenicId 5dfb03070a9ac17ac7a82054 string true "景区id"
48 50 // @Success 200 {object} tools.ResponseSeccess "Price=价格;ShopName=店铺名称;KvPhoto用于列表页的图片;TopPhoto详情页最上面的轮播图;Images详情页下面的产品详细图"
49 51 // @Failure 500 {object} tools.ResponseError "{"errcode":1,"errmsg":"错误原因"}"
50 52 // @Router /AllCommodity? [get]
... ... @@ -52,14 +54,19 @@ func AllCommodity(c *gin.Context) {
52 54 c.Header("Access-Control-Allow-Origin", c.Request.Header.Get("Origin"))
53 55 c.Header("Access-Control-Allow-Credentials", "true")
54 56  
  57 + var ScenicId string
  58 + if ScenicId = c.Query("ScenicId");ScenicId == ""{
  59 + ScenicId = "5e0d504e24e03431008b4567" // 乐岛
  60 + }
  61 +
55 62 var aCommoditys []DB.SCommodity
56   - cur, err := DB.CCommodity.Find(tools.GetContext(), bson.M{})
  63 + cur, err := DB.CCommodity.Find(tools.GetContext(), bson.M{"ScenicId": ScenicId})
57 64 defer cur.Close(tools.GetContext())
58 65 if err == nil {
59 66 for cur.Next(tools.GetContext()) {
60 67 var e DB.SCommodity
61 68 cur.Decode(&e)
62   - aCommoditys = append(aCommoditys,e)
  69 + aCommoditys = append(aCommoditys, e)
63 70 }
64 71 }
65 72  
... ... @@ -71,6 +78,8 @@ func AllCommodity(c *gin.Context) {
71 78 // @Description 更新商品
72 79 // @Accept json
73 80 // @Produce json
  81 +// @Param ScenicId 5dfb03070a9ac17ac7a82054 string true "景区id"
  82 +// @Param Token wgergejfwe string true "用户token"
74 83 // @Success 200 {object} tools.ResponseSeccess ""
75 84 // @Failure 500 {object} tools.ResponseError "{"errcode":1,"errmsg":"错误原因"}"
76 85 // @Router /UpdateCommodity? [post]
... ... @@ -78,6 +87,17 @@ func UpdateCommodity(c *gin.Context) {
78 87 c.Header("Access-Control-Allow-Origin", c.Request.Header.Get("Origin"))
79 88 c.Header("Access-Control-Allow-Credentials", "true")
80 89  
  90 + _user, _ := c.Get("UserInfo")
  91 + user := _user.(*DB.SMember)
  92 + err := Auth.CheckScenicAuth(c.PostForm("ScenicId"), user)
  93 + if err != nil {
  94 + c.JSON(200, tools.ResponseError{
  95 + 401,
  96 + "没有权限",
  97 + })
  98 + return
  99 + }
  100 +
81 101 var Picture []string
82 102 json.Unmarshal([]byte(c.PostForm("Images")), &Picture)
83 103  
... ... @@ -87,12 +107,11 @@ func UpdateCommodity(c *gin.Context) {
87 107 //var Location DB.SLocation
88 108 //json.Unmarshal([]byte(c.PostForm("Location")), &Location)
89 109  
90   -
91 110 var id primitive.ObjectID
92 111 if pid := c.PostForm("id"); pid == "null" {
93 112 id = primitive.NewObjectID()
94 113 } else {
95   - id,_ = primitive.ObjectIDFromHex(pid)
  114 + id, _ = primitive.ObjectIDFromHex(pid)
96 115 }
97 116  
98 117 upsert := true
... ...
API/Tag.go
... ... @@ -5,6 +5,7 @@ import (
5 5 "github.com/gin-gonic/gin"
6 6 "go.mongodb.org/mongo-driver/bson"
7 7 "letu/DB"
  8 + "letu/Lib/Auth"
8 9 "letu/Lib/LeYouTu"
9 10 "time"
10 11 )
... ... @@ -23,6 +24,11 @@ func AllTag(c *gin.Context) {
23 24  
24 25 ScenicId, err := LeYouTu.GetScenicId(c)
25 26 if err != nil {
  27 +
  28 + c.JSON(200, tools.ResponseError{
  29 + 1,
  30 + "景区id不能为空",
  31 + })
26 32 return
27 33 }
28 34  
... ... @@ -63,6 +69,10 @@ func AllTagGroup(c *gin.Context) {
63 69  
64 70 ScenicId, err := LeYouTu.GetScenicId(c)
65 71 if err != nil {
  72 + c.JSON(200, tools.ResponseError{
  73 + 1,
  74 + "景区id不能为空",
  75 + })
66 76 return
67 77 }
68 78  
... ... @@ -119,6 +129,7 @@ func AllTagGroup(c *gin.Context) {
119 129 // @Accept json
120 130 // @Produce json
121 131 // @Param ScenicId 5dfb03070a9ac17ac7a82054 string true "景区id"
  132 +// @Param Token wgergejfwe string true "用户token"
122 133 // @Param TagName 广场 string true "标签名称"
123 134 // @Param TagGroup location string true "群组名称"
124 135 // @Success 200 {object} tools.ResponseSeccess "{"errcode":0,"result":"ok"}"
... ... @@ -128,8 +139,14 @@ func CreateTag(c *gin.Context) {
128 139 c.Header("Access-Control-Allow-Origin", c.Request.Header.Get("Origin"))
129 140 c.Header("Access-Control-Allow-Credentials", "true")
130 141  
131   - ScenicId, err := LeYouTu.GetScenicId(c)
  142 + _user, _ := c.Get("UserInfo")
  143 + user := _user.(*DB.SMember)
  144 + err := Auth.CheckScenicAuth(c.PostForm("ScenicId"), user)
132 145 if err != nil {
  146 + c.JSON(200, tools.ResponseError{
  147 + 401,
  148 + "没有权限",
  149 + })
133 150 return
134 151 }
135 152  
... ... @@ -160,12 +177,12 @@ func CreateTag(c *gin.Context) {
160 177 }
161 178  
162 179 DB.CTags.InsertOne(tools.GetContext(),DB.STag{
163   - ScenicId,
  180 + c.PostForm("ScenicId"),
164 181 c.PostForm("TagGroup"),
165 182 c.PostForm("TagName"),
166 183 })
167 184  
168   - DB.Redis.Delete("Tags_" + ScenicId)
  185 + DB.Redis.Delete("Tags_" + c.PostForm("ScenicId"))
169 186 println("清楚缓存Tags")
170 187  
171 188 c.JSON(200, tools.ResponseSeccess{
... ... @@ -182,6 +199,7 @@ func CreateTag(c *gin.Context) {
182 199 // @Accept json
183 200 // @Produce json
184 201 // @Param ScenicId 5dfb03070a9ac17ac7a82054 string true "景区id"
  202 +// @Param Token wgergejfwe string true "用户token"
185 203 // @Param TagName 广场 string true "标签名称"
186 204 // @Param TagGroup location string true "群组名称"
187 205 // @Success 200 {object} tools.ResponseSeccess "{"errcode":0,"result":"ok"}"
... ... @@ -191,8 +209,14 @@ func RemoveTag(c *gin.Context) {
191 209 c.Header("Access-Control-Allow-Origin", c.Request.Header.Get("Origin"))
192 210 c.Header("Access-Control-Allow-Credentials", "true")
193 211  
194   - ScenicId, err := LeYouTu.GetScenicId(c)
  212 + _user, _ := c.Get("UserInfo")
  213 + user := _user.(*DB.SMember)
  214 + err := Auth.CheckScenicAuth(c.PostForm("ScenicId"), user)
195 215 if err != nil {
  216 + c.JSON(200, tools.ResponseError{
  217 + 401,
  218 + "没有权限",
  219 + })
196 220 return
197 221 }
198 222  
... ... @@ -222,9 +246,9 @@ func RemoveTag(c *gin.Context) {
222 246 return
223 247 }
224 248  
225   - DB.CTags.DeleteOne(tools.GetContext(), bson.M{"ScenicId": ScenicId,"Name":c.PostForm("TagName"),"Type":c.PostForm("TagGroup")})
  249 + DB.CTags.DeleteOne(tools.GetContext(), bson.M{"ScenicId": c.PostForm("ScenicId"),"Name":c.PostForm("TagName"),"Type":c.PostForm("TagGroup")})
226 250  
227   - DB.Redis.Delete("Tags_" + ScenicId)
  251 + DB.Redis.Delete("Tags_" + c.PostForm("ScenicId"))
228 252 println("清楚缓存Tags")
229 253  
230 254 c.JSON(200, tools.ResponseSeccess{
... ...
API/TopMenus.go
... ... @@ -8,13 +8,15 @@ import (
8 8 "go.mongodb.org/mongo-driver/bson/primitive"
9 9 "go.mongodb.org/mongo-driver/mongo/options"
10 10 "letu/DB"
11   - "letu/Lib/LeYouTu"
  11 + "letu/Lib/Auth"
12 12 )
13 13  
14 14 // @Title 查询所有菜单
15 15 // @Description 菜单管理 - 查询所有菜单
16 16 // @Accept json
17 17 // @Produce json
  18 +// @Param ScenicId 5e0d504e24e03431008b4567 string true "景区id"
  19 +// @Param Token wgergejfwe string true "用户token"
18 20 // @Success 200 {object} tools.ResponseSeccess "{"errcode":0,"result":[{"Id":"","ScenicId":"","Title":"玩水","Tags":["玩水"]},{"Id":"","ScenicId":"","Title":"设施","Tags":["服务设施","游玩项目"]}]}"
19 21 // @Failure 500 {object} tools.ResponseError "{"errcode":1,"errmsg":"错误原因"}"
20 22 // @Router /TopMenus/All? [get]
... ... @@ -22,13 +24,19 @@ func AllTopMenus(c *gin.Context) {
22 24 c.Header("Access-Control-Allow-Origin", c.Request.Header.Get("Origin"))
23 25 c.Header("Access-Control-Allow-Credentials", "true")
24 26  
25   - ScenicId, err := LeYouTu.GetScenicId(c)
  27 + _user, _ := c.Get("UserInfo")
  28 + user := _user.(*DB.SMember)
  29 + err := Auth.CheckScenicAuth(c.PostForm("ScenicId"), user)
26 30 if err != nil {
  31 + c.JSON(200, tools.ResponseError{
  32 + 401,
  33 + "没有权限",
  34 + })
27 35 return
28 36 }
29 37  
30 38 var STopMenus []DB.STopMenus
31   - cur, err := DB.CTopMenus.Find(tools.GetContext(), bson.M{"ScenicId": ScenicId})
  39 + cur, err := DB.CTopMenus.Find(tools.GetContext(), bson.M{"ScenicId": c.PostForm("ScenicId")})
32 40 defer cur.Close(tools.GetContext())
33 41 if err == nil {
34 42 for cur.Next(tools.GetContext()) {
... ... @@ -53,6 +61,8 @@ func AllTopMenus(c *gin.Context) {
53 61 // @Description 菜单管理 - 更新菜单
54 62 // @Accept json
55 63 // @Produce json
  64 +// @Param ScenicId 5e0d504e24e03431008b4567 string true "景区id"
  65 +// @Param Token wgergejfwe string true "用户token"
56 66 // @Success 200 {object} tools.ResponseSeccess "{"errcode":0,"result":[{"Id":"","ScenicId":"","Title":"玩水","Tags":["玩水"]},{"Id":"","ScenicId":"","Title":"设施","Tags":["服务设施","游玩项目"]}]}"
57 67 // @Failure 500 {object} tools.ResponseError "{"errcode":1,"errmsg":"错误原因"}"
58 68 // @Router /TopMenus/Update? [post]
... ... @@ -60,8 +70,15 @@ func UpdateTopMenus(c *gin.Context) {
60 70 c.Header("Access-Control-Allow-Origin", c.Request.Header.Get("Origin"))
61 71 c.Header("Access-Control-Allow-Credentials", "true")
62 72  
63   - ScenicId, err := LeYouTu.GetScenicId(c)
  73 +
  74 + _user, _ := c.Get("UserInfo")
  75 + user := _user.(*DB.SMember)
  76 + err := Auth.CheckScenicAuth(c.PostForm("ScenicId"), user)
64 77 if err != nil {
  78 + c.JSON(200, tools.ResponseError{
  79 + 401,
  80 + "没有权限",
  81 + })
65 82 return
66 83 }
67 84  
... ... @@ -87,7 +104,7 @@ func UpdateTopMenus(c *gin.Context) {
87 104 DB.CTopMenus.FindOneAndUpdate(tools.GetContext(),
88 105 bson.M{"_id": id},
89 106 bson.M{"$set": bson.M{
90   - "ScenicId": ScenicId,
  107 + "ScenicId": c.PostForm("ScenicId"),
91 108 "Title": c.PostForm("Title"),
92 109 "Tags": Tags,
93 110 }}, &options.FindOneAndUpdateOptions{
... ...
API/User.go
1 1 package Api
2 2  
3 3 import (
4   - "crypto/sha256"
5   - "encoding/hex"
6 4 "github.com/aarongao/tools"
7 5 "github.com/gin-gonic/gin"
8 6 "go.mongodb.org/mongo-driver/bson"
9 7 "go.mongodb.org/mongo-driver/bson/primitive"
10 8 "go.mongodb.org/mongo-driver/mongo/options"
11 9 "letu/DB"
12   - "letu/Lib/Token"
  10 + "letu/Lib/JWT"
13 11 "regexp"
14   - "strconv"
15 12 "time"
16 13 )
17 14  
... ... @@ -55,10 +52,6 @@ func LoginUser(c *gin.Context) {
55 52 return
56 53 }
57 54  
58   - // 生成token
59   - tokenunit8 := sha256.Sum256([]byte(c.PostForm("Mobile") + c.PostForm("Code") + strconv.FormatInt(time.Now().UnixNano(), 10)))
60   - token := hex.EncodeToString(tokenunit8[:32])
61   -
62 55 // 检查验证码
63 56 cacheCode := DB.Redis.Get("code_" + c.PostForm("Mobile"))
64 57 selected := bson.M{}
... ... @@ -69,9 +62,13 @@ func LoginUser(c *gin.Context) {
69 62  
70 63 // 验证码匹配,但手机号不存在
71 64 if User == nil {
  65 + var auth = []string{"用户管理", "通知管理"}
72 66 objectID := primitive.NewObjectID()
73   - User := DB.SMember{
  67 + User = &DB.SMember{
74 68 &objectID,
  69 + "visitor",
  70 + "",
  71 + "",
75 72 "",
76 73 "",
77 74 "",
... ... @@ -79,7 +76,7 @@ func LoginUser(c *gin.Context) {
79 76 "",
80 77 "",
81 78 "",
82   - DB.SDevice{
  79 + &DB.SDevice{
83 80 c.Request.Header.Get("DeviceId"),
84 81 c.Request.Header.Get("Mac"),
85 82 c.Request.Header.Get("UDID"),
... ... @@ -89,8 +86,10 @@ func LoginUser(c *gin.Context) {
89 86 c.Request.Header.Get("AppVersion"),
90 87 c.Request.Header.Get("DeviceToken"),
91 88 },
  89 + auth,
  90 + "",
92 91 }
93   - DB.CMember.InsertOne(tools.GetContext(),User)
  92 + DB.CMember.InsertOne(tools.GetContext(), User)
94 93 }
95 94  
96 95 } else {
... ... @@ -101,16 +100,9 @@ func LoginUser(c *gin.Context) {
101 100 return
102 101 }
103 102  
104   - // 更新用户信息
105   - //DB.CMember.Update(
106   - // bson.M{"_id": User.Id},
107   - // bson.M{"$set": bson.M{"Token": token}},
108   - //)
109   -
110   - // 更新token
111   - Token.SaveToken(User.Id.Hex(), token)
112   -
113   - User.Token = token
  103 + // 生成token
  104 + dd, _ := time.ParseDuration("8760h")
  105 + User.Token, _ = JWT.CreateToken(User, time.Now().Add(dd).Unix())
114 106 c.JSON(200, tools.ResponseSeccess{
115 107 0,
116 108 User,
... ... @@ -146,15 +138,15 @@ func RegisterDevice(c *gin.Context) {
146 138  
147 139 upsert := true
148 140 DB.CDevice.FindOneAndUpdate(tools.GetContext(),
149   - bson.M{"DeviceId":c.Request.Header.Get("DeviceId")},
  141 + bson.M{"DeviceId": c.Request.Header.Get("DeviceId")},
150 142 bson.M{"$set": bson.M{
151   - "Mac":c.Request.Header.Get("Mac"),
152   - "UDID":c.Request.Header.Get("UDID"),
153   - "SystemType":c.Request.Header.Get("SystemType"),
154   - "SystemVersion":c.Request.Header.Get("SystemVersion"),
155   - "SystemModel":c.Request.Header.Get("SystemModel"),
156   - "AppVersion":c.Request.Header.Get("AppVersion"),
157   - "DeviceToken":c.Request.Header.Get("DeviceToken"),
  143 + "Mac": c.Request.Header.Get("Mac"),
  144 + "UDID": c.Request.Header.Get("UDID"),
  145 + "SystemType": c.Request.Header.Get("SystemType"),
  146 + "SystemVersion": c.Request.Header.Get("SystemVersion"),
  147 + "SystemModel": c.Request.Header.Get("SystemModel"),
  148 + "AppVersion": c.Request.Header.Get("AppVersion"),
  149 + "DeviceToken": c.Request.Header.Get("DeviceToken"),
158 150 }}, &options.FindOneAndUpdateOptions{
159 151 Upsert: &upsert,
160 152 },
... ... @@ -172,7 +164,6 @@ func RegisterDevice(c *gin.Context) {
172 164 // @Accept json
173 165 // @Produce json
174 166 // @Param id aaron string true "用户id"
175   -// @Param Token wgergejfwe string true "用户token"
176 167 // @Success 200 {object} tools.ResponseSeccess "{"errcode":0,"result":{"Id":"5e09c64c1c09c6f0f7ca2fa9","Token":"640bf934e425aba5d3c90998b2641f2f0ca07261d334d9615d1cd4790b5f34e7"}}"
177 168 // @Failure 500 {object} tools.ResponseError "{"errcode":1,"errmsg":"错误原因"}"
178 169 // @Router /UserInfo? [get]
... ... @@ -180,19 +171,11 @@ func UserInfo(c *gin.Context) {
180 171 c.Header("Access-Control-Allow-Origin", c.Request.Header.Get("Origin"))
181 172 c.Header("Access-Control-Allow-Credentials", "true")
182 173  
183   - objID,err := primitive.ObjectIDFromHex(c.Query("id"))
184   - if c.Query("Token") == "" || err!=nil {
  174 + objID, err := primitive.ObjectIDFromHex(c.Query("id"))
  175 + if err != nil {
185 176 c.JSON(200, tools.ResponseError{
186 177 1,
187   - "Token或者用户id不正确",
188   - })
189   - return
190   - }
191   -
192   - if Token.GetToken(c.Query("id")) != c.Query("Token") {
193   - c.JSON(200, tools.ResponseError{
194   - 401,
195   - "token过期",
  178 + "用户id不正确",
196 179 })
197 180 return
198 181 }
... ... @@ -200,7 +183,7 @@ func UserInfo(c *gin.Context) {
200 183 var User DB.SMember
201 184 DB.CMember.FindOne(tools.GetContext(), bson.M{"_id": objID}).Decode(&User)
202 185  
203   - User.Device = DB.SDevice{}
  186 + User.Device = &DB.SDevice{}
204 187 c.JSON(200, tools.ResponseSeccess{
205 188 0,
206 189 User,
... ... @@ -212,7 +195,6 @@ func UserInfo(c *gin.Context) {
212 195 // @Description 用户管理 - 检查Token是否过期
213 196 // @Accept json
214 197 // @Produce json
215   -// @Param id aaron string true "用户id"
216 198 // @Param Token wgergejfwe string true "用户token"
217 199 // @Success 200 {object} tools.ResponseSeccess "{"errcode":0,"result":"ok"}"
218 200 // @Failure 500 {object} tools.ResponseError "{"errcode":401,"errmsg":"token过期"}"
... ... @@ -221,26 +203,27 @@ func CheckToken(c *gin.Context) {
221 203 c.Header("Access-Control-Allow-Origin", c.Request.Header.Get("Origin"))
222 204 c.Header("Access-Control-Allow-Credentials", "true")
223 205  
224   - _,err := primitive.ObjectIDFromHex(c.PostForm("id"))
225   - if c.PostForm("Token") == "" || err != nil {
  206 + if c.PostForm("Token") == "" {
226 207 c.JSON(200, tools.ResponseError{
227 208 1,
228   - "Token或者用户id不正确",
  209 + "Token不正确",
229 210 })
230 211 return
231 212 }
232 213  
233   - if Token.GetToken(c.PostForm("id")) != c.PostForm("Token") {
  214 + user, err := JWT.ParseToken(c.PostForm("Token"))
  215 +
  216 + if err != nil {
234 217 c.JSON(200, tools.ResponseError{
235 218 401,
236   - "token过期",
  219 + err.Error(),
237 220 })
238 221 return
239 222 }
240 223  
241 224 c.JSON(200, tools.ResponseSeccess{
242 225 0,
243   - "ok",
  226 + user,
244 227 })
245 228  
246 229 }
... ... @@ -264,19 +247,13 @@ func UpdateUser(c *gin.Context) {
264 247 c.Header("Access-Control-Allow-Origin", c.Request.Header.Get("Origin"))
265 248 c.Header("Access-Control-Allow-Credentials", "true")
266 249  
267   - _,err := primitive.ObjectIDFromHex(c.PostForm("id"))
268   - if c.PostForm("Token") == "" || err != nil {
269   - c.JSON(200, tools.ResponseError{
270   - 1,
271   - "Token或者用户id不正确",
272   - })
273   - return
274   - }
  250 + _user, _ := c.Get("UserInfo")
  251 + user := _user.(*DB.SMember)
275 252  
276   - if Token.GetToken(c.PostForm("id")) != c.PostForm("Token") {
  253 + if c.PostForm("id") != user.Id.Hex() {
277 254 c.JSON(200, tools.ResponseError{
278 255 401,
279   - "token过期",
  256 + "没有权限",
280 257 })
281 258 return
282 259 }
... ... @@ -299,14 +276,6 @@ func UpdateUser(c *gin.Context) {
299 276 return
300 277 }
301 278  
302   - //if c.PostForm("Password") != c.PostForm("ConfirmPassword") {
303   - // c.JSON(200, tools.ResponseError{
304   - // 1,
305   - // "2次密码不一致",
306   - // })
307   - // return
308   - //}
309   -
310 279 // 检查验证码
311 280 code := DB.Redis.Get("code_" + c.PostForm("Mobile"))
312 281 if code == "" || code != c.PostForm("Code") {
... ... @@ -317,8 +286,8 @@ func UpdateUser(c *gin.Context) {
317 286 return
318 287 }
319 288  
320   - objID,_ := primitive.ObjectIDFromHex(c.PostForm("id"))
321   - _, err = DB.CMember.UpdateOne(tools.GetContext(),
  289 + objID, _ := primitive.ObjectIDFromHex(c.PostForm("id"))
  290 + _, err := DB.CMember.UpdateOne(tools.GetContext(),
322 291 bson.M{"_id": objID},
323 292 bson.M{"$set": bson.M{
324 293 "Birthday": c.PostForm("Birthday"),
... ... @@ -330,9 +299,9 @@ func UpdateUser(c *gin.Context) {
330 299  
331 300 if err == nil {
332 301 var User *DB.SMember
333   - objID,_ := primitive.ObjectIDFromHex(c.PostForm("id"))
  302 + objID, _ := primitive.ObjectIDFromHex(c.PostForm("id"))
334 303 DB.CMember.FindOne(tools.GetContext(), bson.M{"_id": objID}).Decode(&User)
335   -
  304 + User.Token = ""
336 305 c.JSON(200, tools.ResponseSeccess{
337 306 0,
338 307 User,
... ... @@ -346,7 +315,6 @@ func UpdateUser(c *gin.Context) {
346 315  
347 316 }
348 317  
349   -
350 318 // @Title 删除用户
351 319 // @Description 用户管理 - 删除用户(注销)
352 320 // @Accept json
... ... @@ -360,19 +328,21 @@ func RemoveUser(c *gin.Context) {
360 328 c.Header("Access-Control-Allow-Origin", c.Request.Header.Get("Origin"))
361 329 c.Header("Access-Control-Allow-Credentials", "true")
362 330  
363   - objID,err := primitive.ObjectIDFromHex(c.PostForm("id"))
364   - if c.PostForm("Token") == "" || err != nil {
  331 + _user, _ := c.Get("UserInfo")
  332 + user := _user.(*DB.SMember)
  333 + if c.PostForm("id") != user.Id.Hex() {
365 334 c.JSON(200, tools.ResponseError{
366   - 1,
367   - "Token或者用户id不正确",
  335 + 401,
  336 + "没有权限",
368 337 })
369 338 return
370 339 }
371 340  
372   - if Token.GetToken(c.PostForm("id")) != c.PostForm("Token") {
  341 + objID, err := primitive.ObjectIDFromHex(c.PostForm("id"))
  342 + if err != nil {
373 343 c.JSON(200, tools.ResponseError{
374   - 401,
375   - "token过期",
  344 + 1,
  345 + "用户id不正确",
376 346 })
377 347 return
378 348 }
... ...
API/UserLog.go
... ... @@ -131,12 +131,11 @@ func AllUserLog(c *gin.Context) {
131 131 }
132 132 }
133 133  
134   -
135 134 c.JSON(200, tools.Page{
136 135 0,
137 136 total,
138 137 currPage,
139   - int(math.Ceil(float64(total) / float64(limit))),
  138 + int64(math.Ceil(float64(total) / float64(limit))),
140 139 limit,
141 140 aUserLog,
142 141 })
... ...
Bin/Monitor.go
... ... @@ -12,7 +12,7 @@ var lastState = 0
12 12 func main() {
13 13  
14 14 for {
15   - time.Sleep(30 * time.Second)
  15 + time.Sleep(180 * time.Second)
16 16 httpState, body, error := tools.GET("http://leyoutu.st-i.com.cn/AllScenic")
17 17 if httpState == 200 && error == nil {
18 18  
... ...
Bin/TestiosMeg 0 → 100755
No preview for this file type
Bin/TestiosMeg.go 0 → 100644
... ... @@ -0,0 +1,29 @@
  1 +package main
  2 +
  3 +import (
  4 + "fmt"
  5 + "github.com/aliyun/alibaba-cloud-sdk-go/services/push"
  6 +)
  7 +
  8 +func main() {
  9 +
  10 + // 推送app消息
  11 + client, err := push.NewClientWithAccessKey("cn-hangzhou", "LTAI4FdQeNMQXRU6u5J3EFQc", "PwvyF5rRNBWLDya41WrCpvENevYZGi")
  12 +
  13 +
  14 + request := push.CreatePushNoticeToiOSRequest()
  15 + request.ApnsEnv = "DEV"
  16 + request.AppKey = "28332889"
  17 + request.Scheme = "https"
  18 + request.Target = "DEVICE"
  19 + request.TargetValue = "30076ed6fdb740e49d882433931bc34a"
  20 + request.Title = "消息测试1"
  21 + request.Body = "消息测试2"
  22 +
  23 + response, err := client.PushNoticeToiOS(request)
  24 + if err != nil {
  25 + fmt.Print(err.Error())
  26 + }
  27 + fmt.Printf("response is %#v\n", response)
  28 +
  29 +}
... ...
Config/config.go
1 1 package Config
2 2  
3 3 type Config struct {
4   - TagType []string
5   - DbPath string
6   - DbName string
7   - DbUser string
8   - DbPassword string
9   - RedisPath string
  4 + TagType []string
  5 + DbPath string
  6 + DbName string
  7 + DbUser string
  8 + DbPassword string
  9 + RedisPath string
  10 + Env string
  11 + TokenSecret string
10 12 }
  13 +
  14 +var Info = Config{}
... ...
Config/config.json
... ... @@ -4,5 +4,7 @@
4 4 "dbName": "LeYouTu",
5 5 "dbUser": "leyoutu",
6 6 "dbPassword": "leyoutu123456",
7   - "redisPath": "127.0.0.1:6379"
  7 + "redisPath": "127.0.0.1:6379",
  8 + "Env": "DEV",
  9 + "tokenSecret": "token.secret"
8 10 }
... ...
DB/db.go
... ... @@ -26,6 +26,7 @@ var DB *mongo.Database
26 26  
27 27 type SItem struct {
28 28 Id *primitive.ObjectID `bson:"_id" json:"Id" valid:"required"`
  29 + ScenicId string `bson:"ScenicId" json:"ScenicId"` // 景区id
29 30 Name string `bson:"Name" json:"Name"`
30 31 SubName string `bson:"SubName" json:"SubName"`
31 32 Location SLocation `bson:"Location" json:"Location"`
... ... @@ -45,6 +46,11 @@ type SItem struct {
45 46 Reminder string `bson:"Reminder" json:"Reminder"` //温馨提示
46 47 State int `bson:"State" json:"State"` // 运行状态0=正常1=停运
47 48 }
  49 +
  50 +type SModel struct {
  51 + Model string `bson:"Model" json:"Model"`
  52 + Action string `bson:"Action" json:"Action"`
  53 +}
48 54 type SIcons struct {
49 55 Id *primitive.ObjectID `bson:"_id" json:"Id" valid:"required"`
50 56 ScenicId string `bson:"ScenicId" json:"ScenicId"`
... ... @@ -143,6 +149,9 @@ type SInvestigation struct {
143 149 }
144 150 type SMember struct {
145 151 Id *primitive.ObjectID `bson:"_id" json:"Id" valid:"required"`
  152 + UserType string `bson:"UserType" json:"UserType"` // "root" or "operator" or "visitor"
  153 + ScenicId string `bson:"ScenicId" json:"ScenicId"`
  154 + Username string `bson:"Username" json:"Username"`
146 155 Password string `bson:"Password" json:"Password"`
147 156 Birthday string `bson:"Birthday" json:"Birthday"`
148 157 FullName string `bson:"FullName" json:"FullName"`
... ... @@ -150,7 +159,9 @@ type SMember struct {
150 159 Openid string `bson:"Openid" json:"Openid"`
151 160 Token string `bson:"Token" json:"Token"`
152 161 Sex string `bson:"Sex" json:"Sex"`
153   - Device SDevice `bson:"Device" json:"Device"` //设备信息
  162 + Device *SDevice `bson:"Device" json:"Device"` //设备信息
  163 + Auth []string `bson:"Auth" json:"Auth"` //权限信息
  164 + Remarks string `bson:"Remarks" json:"Remarks"` //说明
154 165 }
155 166  
156 167 type STag struct {
... ...
Lib/Auth/Auth.go 0 → 100644
... ... @@ -0,0 +1,98 @@
  1 +package Auth
  2 +
  3 +import (
  4 + "github.com/aarongao/tools"
  5 + "github.com/gin-gonic/gin"
  6 + "github.com/pkg/errors"
  7 + "letu/DB"
  8 + "letu/Lib/JWT"
  9 +)
  10 +
  11 +// 系统中所有模块
  12 +var Models = make(map[string][]string)
  13 +
  14 +// @Title 所有模块信息
  15 +// @Description 模块管理 - 所有模块信息
  16 +// @Accept json
  17 +// @Produce json
  18 +// @Success 200 {object} tools.ResponseSeccess ""
  19 +// @Failure 500 {object} tools.ResponseError "{"errcode":1,"errmsg":"错误原因"}"
  20 +// @Router /AllModules? [get]
  21 +func Modules(c *gin.Context) {
  22 + c.Header("Access-Control-Allow-Origin", c.Request.Header.Get("Origin"))
  23 + c.Header("Access-Control-Allow-Credentials", "true")
  24 +
  25 + rs := []string{}
  26 + for k, _ := range Models {
  27 + rs = append(rs, k)
  28 + }
  29 +
  30 + c.JSON(200, tools.ResponseSeccess{
  31 + 0,
  32 + rs,
  33 + })
  34 +
  35 +}
  36 +
  37 +// 检查基础权限
  38 +func CheckAuthFunc(handFunc func(c *gin.Context), auth *DB.SModel) func(c *gin.Context) {
  39 + return func(c *gin.Context) {
  40 +
  41 + if auth.Model == "" {
  42 + handFunc(c)
  43 + return
  44 + }
  45 +
  46 + token := ""
  47 + if c.Request.Method == "GET" {
  48 + token = c.Query("Token")
  49 + }
  50 + if c.Request.Method == "POST" {
  51 + token = c.PostForm("Token")
  52 + }
  53 + if token == "" {
  54 + token = c.Request.Header.Get("Token")
  55 + }
  56 +
  57 + // 解析token
  58 + user, err := JWT.ParseToken(token)
  59 + if user.UserType == "root" {
  60 + c.Set("UserInfo", user)
  61 + handFunc(c)
  62 + return
  63 + }
  64 +
  65 + // 检查权限
  66 + checkAuth := false
  67 + for _, v := range user.Auth {
  68 + if v == auth.Model {
  69 + checkAuth = true
  70 + break
  71 + }
  72 + }
  73 +
  74 + if err != nil || checkAuth == false {
  75 + c.JSON(200, tools.ResponseError{
  76 + 401,
  77 + "没有权限",
  78 + })
  79 + } else {
  80 + c.Set("UserInfo", user)
  81 + handFunc(c)
  82 + }
  83 + }
  84 +}
  85 +
  86 +func CheckScenicAuth(ScenicId string, user *DB.SMember) error {
  87 +
  88 + if ScenicId == "" {
  89 + return errors.New("景区id不能为空")
  90 + }
  91 +
  92 + if user.UserType == "operator" {
  93 + if user.ScenicId != ScenicId {
  94 + return errors.New("权限不正确(需要正确的Token和ScenicId)")
  95 + }
  96 + }
  97 + return nil
  98 +}
... ...
Lib/DelayMessage/delaymessage.go
... ... @@ -5,11 +5,13 @@ import (
5 5 "encoding/json"
6 6 "fmt"
7 7 "github.com/aarongao/tools"
  8 + "github.com/aliyun/alibaba-cloud-sdk-go/services/push"
8 9 "github.com/pkg/errors"
  10 + "go.mongodb.org/mongo-driver/bson"
9 11 "go.mongodb.org/mongo-driver/bson/primitive"
10 12 "go.mongodb.org/mongo-driver/mongo"
11   - "go.mongodb.org/mongo-driver/bson"
12 13 "io/ioutil"
  14 + "letu/DB"
13 15 "net/http"
14 16 "strconv"
15 17 "sync"
... ... @@ -31,11 +33,11 @@ type Message struct {
31 33 Fail int
32 34  
33 35 // 类型0=geturl;1=发送app消息
34   - Type int8 `bson:"Type" json:"Type"`
35   - Title string `bson:"Title" json:"Title"`
36   - Content string `bson:"Content" json:"Content"`
37   - UDID string `bson:"UDID" json:"UDID"`
38   - UserId string `bson:"UserId" json:"UserId"`
  36 + Type int8 `bson:"Type" json:"Type"`
  37 + Title string `bson:"Title" json:"Title"`
  38 + Content string `bson:"Content" json:"Content"`
  39 + DeviceToken string `bson:"DeviceToken" json:"DeviceToken"`
  40 + UserId string `bson:"UserId" json:"UserId"`
39 41 }
40 42  
41 43 // addTask
... ... @@ -68,7 +70,7 @@ func (dm *DelayMessage) AddTaskForGetUrl(delayTime string, userid string, callba
68 70 return nil
69 71 }
70 72  
71   -func (dm *DelayMessage) AddTaskForAppMessage(delayTime string, udid string, title string, content string, userid string) error {
  73 +func (dm *DelayMessage) AddTaskForAppMessage(delayTime string, deviceToken string, title string, content string, userid string) error {
72 74  
73 75 iTIme, _ := strconv.Atoi(delayTime)
74 76 i64Time := int64(iTIme)
... ... @@ -78,8 +80,8 @@ func (dm *DelayMessage) AddTaskForAppMessage(delayTime string, udid string, titl
78 80 if i64Time <= nowTimeU {
79 81 return errors.New("delayTime error...")
80 82 }
81   - if udid == "" {
82   - return errors.New("udid error...")
  83 + if deviceToken == "" {
  84 + return errors.New("deviceToken error...")
83 85 }
84 86 if title == "" {
85 87 return errors.New("title error...")
... ... @@ -92,7 +94,7 @@ func (dm *DelayMessage) AddTaskForAppMessage(delayTime string, udid string, titl
92 94 }
93 95  
94 96 objectID := primitive.NewObjectID()
95   - _Message := &Message{&objectID, i64Time, "", 0, 1, title, content, udid, userid}
  97 + _Message := &Message{&objectID, i64Time, "", 0, 1, title, content, deviceToken, userid}
96 98  
97 99 CDelayMessage.InsertOne(tools.GetContext(), _Message)
98 100  
... ... @@ -147,16 +149,35 @@ func Callback(key *primitive.ObjectID, message *Message) {
147 149 } else if message.Type == 1 {
148 150  
149 151 // 推送app消息
150   - //client, err := push.NewClientWithAccessKey("cn-hangzhou", "28332889", "4c0b32d5fd0822a9de703e177798e8ca")
151   - //
152   - //request := push.CreatePushMessageToiOSRequest()
153   - //request.Scheme = "https"
154   - //
155   - //response, err := client.PushMessageToiOS(request)
156   - //if err != nil {
157   - // fmt.Print(err.Error())
158   - //}
159   - //fmt.Printf("response is %#v\n", response)
  152 + client, err := push.NewClientWithAccessKey("cn-hangzhou", "LTAI4FdQeNMQXRU6u5J3EFQc", "PwvyF5rRNBWLDya41WrCpvENevYZGi")
  153 +
  154 + request := push.CreatePushNoticeToiOSRequest()
  155 + request.ApnsEnv = "DEV"
  156 + request.AppKey = "28332889"
  157 + request.Scheme = "https"
  158 + request.Target = "DEVICE"
  159 + request.TargetValue = message.DeviceToken
  160 + request.Title = message.Title
  161 + request.Body = message.Content
  162 +
  163 + response, err := client.PushNoticeToiOS(request)
  164 + if err != nil {
  165 + fmt.Print(err.Error())
  166 + }
  167 +
  168 + res,_ := json.Marshal(response)
  169 + DB.CSystemLog.InsertOne(tools.GetContext(),DB.SSystemLog{
  170 + message.UserId,
  171 + "",
  172 + "",
  173 + 6002,
  174 + "调用阿里接口发送app通知",
  175 + time.Now().Unix(),
  176 + DB.SLocation{},
  177 + string(res),
  178 + err,
  179 + })
  180 +
160 181 }
161 182  
162 183 json, _ := json.Marshal(message)
... ...
Lib/JWT/jwt.go 0 → 100644
... ... @@ -0,0 +1,72 @@
  1 +package JWT
  2 +
  3 +import (
  4 + "encoding/json"
  5 + "errors"
  6 + "github.com/dgrijalva/jwt-go"
  7 + "go.mongodb.org/mongo-driver/bson/primitive"
  8 + "letu/Config"
  9 + "letu/DB"
  10 + "time"
  11 +)
  12 +
  13 +func CreateToken(user *DB.SMember, exp int64) (tokenss string, err error) {
  14 + //自定义claim
  15 +
  16 +
  17 + auth, _ := json.Marshal(user.Auth)
  18 + claim := jwt.MapClaims{
  19 + "id": user.Id,
  20 + //"mobile": user.Mobile,
  21 + "userType": user.UserType,
  22 + "scenicId": user.ScenicId,
  23 + "auth": string(auth),
  24 + "nbf": time.Now().Unix(),
  25 + "iat": time.Now().Unix(),
  26 + "exp": exp,
  27 + }
  28 + token := jwt.NewWithClaims(jwt.SigningMethodHS256, claim)
  29 + tokenss, err = token.SignedString([]byte(Config.Info.TokenSecret))
  30 + return
  31 +}
  32 +
  33 +func secret() jwt.Keyfunc {
  34 + return func(token *jwt.Token) (interface{}, error) {
  35 + return []byte(Config.Info.TokenSecret), nil
  36 + }
  37 +}
  38 +
  39 +func CheckToken(tokenss string) (err error) {
  40 +
  41 + _, err = jwt.Parse(tokenss, secret())
  42 + return err
  43 +}
  44 +
  45 +func ParseToken(tokenss string) (user *DB.SMember, err error) {
  46 + user = &DB.SMember{}
  47 + token, err := jwt.Parse(tokenss, secret())
  48 + if err != nil {
  49 + return
  50 + }
  51 + claim, ok := token.Claims.(jwt.MapClaims)
  52 + if !ok {
  53 + err = errors.New("cannot convert claim to mapclaim")
  54 + return
  55 + }
  56 + //验证token,如果token被修改过则为false
  57 + if !token.Valid {
  58 + err = errors.New("token is invalid")
  59 + return
  60 + }
  61 +
  62 + id, _ := primitive.ObjectIDFromHex(claim["id"].(string))
  63 + user.Id = &id
  64 + //user.Mobile = claim["mobile"].(string)
  65 + user.UserType = claim["userType"].(string)
  66 + user.ScenicId = claim["scenicId"].(string)
  67 +
  68 + var jsons []string
  69 + json.Unmarshal([]byte(claim["auth"].(string)),&jsons)
  70 + user.Auth = jsons
  71 + return
  72 +}
... ...
Lib/LeYouTu/Controllers.go
... ... @@ -1,26 +0,0 @@
1   -package LeYouTu
2   -
3   -import (
4   - "github.com/gin-gonic/gin"
5   -)
6   -
7   -type Controllers struct {
8   - Layout func(c *gin.Context) bool
9   -}
10   -
11   -func (this *Controllers) POST(handFunc func(c *gin.Context)) func(c *gin.Context) {
12   - return this.HandleFunc(handFunc, "POST")
13   -}
14   -func (this *Controllers) GET(handFunc func(c *gin.Context)) func(c *gin.Context) {
15   - return this.HandleFunc(handFunc, "GET")
16   -}
17   -func (this *Controllers) HandleFunc(handFunc func(c *gin.Context), httpMethod string) func(c *gin.Context) {
18   - return func(c *gin.Context) {
19   -
20   - if c.Request.Method != httpMethod {
21   - //res.Write([]byte(http.StatusText(http.StatusMethodNotAllowed)))
22   - return
23   - }
24   -
25   - }
26   -}
27 0 \ No newline at end of file
Lib/LeYouTu/tools.go
1 1 package LeYouTu
2 2  
3 3 import (
4   - "github.com/aarongao/tools"
5 4 "github.com/gin-gonic/gin"
6 5 "github.com/pkg/errors"
7 6 )
... ... @@ -16,10 +15,6 @@ func GetScenicId(c *gin.Context) (ScenicId string, error error) {
16 15 }
17 16  
18 17 if ScenicId == "" || ScenicId == "undefined" {
19   - c.JSON(200, tools.ResponseError{
20   - 1,
21   - "缺少ScenicId(景区id)",
22   - })
23 18 return "", errors.New("缺少ScenicId(景区id)")
24 19 } else {
25 20 return ScenicId, nil
... ...
main.go
... ... @@ -11,6 +11,7 @@ import (
11 11 "letu/Api"
12 12 "letu/Config"
13 13 "letu/DB"
  14 + "letu/Lib/Auth"
14 15 "letu/Lib/Cache"
15 16 "letu/Lib/DelayMessage"
16 17 "log"
... ... @@ -21,6 +22,8 @@ import (
21 22 // @APIVersion 1.0.0
22 23 // @APITitle 乐游图后端接口文档
23 24 // @BasePath 正式 leyoutu.st-i.com.cn; 测试 letu.api.imagchina.com
  25 +var Gin *gin.Engine
  26 +
24 27 func main() {
25 28  
26 29 // 读取配置文件
... ... @@ -28,13 +31,27 @@ func main() {
28 31 file, _ := os.Open(dir + "/Config/config.json")
29 32 defer file.Close()
30 33 decoder := json.NewDecoder(file)
31   - conf := Config.Config{}
32   - err := decoder.Decode(&conf)
  34 + err := decoder.Decode(&Config.Info)
33 35 tools.CheckError(err)
34 36  
35 37 // 连接数据库
36 38 // Set client options
37   - clientOptions := options.Client().ApplyURI("mongodb://" + conf.DbPath)
  39 + clientOptions := options.Client()
  40 + if Config.Info.Env == "DEV" {
  41 + clientOptions.ApplyURI("mongodb://" + Config.Info.DbPath)
  42 + } else if Config.Info.Env == "PRODUCT" {
  43 + credential := options.Credential{
  44 + AuthMechanism: "SCRAM-SHA-1",
  45 + AuthSource: Config.Info.DbName,
  46 + Username: Config.Info.DbUser,
  47 + Password: Config.Info.DbPassword,
  48 + }
  49 + clientOptions.ApplyURI("mongodb://" + Config.Info.DbPath).SetAuth(credential)
  50 + } else {
  51 + log.Fatal("未知的运行环境 DEV or PRODUCT")
  52 + return
  53 + }
  54 +
38 55 clientOptions.SetLocalThreshold(3 * time.Second) //只使用与mongo操作耗时小于3秒的
39 56 clientOptions.SetMaxConnIdleTime(5 * time.Second) //指定连接可以保持空闲的最大毫秒数
40 57 clientOptions.SetMaxPoolSize(4096) //使用最大的连接数
... ... @@ -53,8 +70,7 @@ func main() {
53 70 log.Println("Connected to MongoDB!")
54 71  
55 72 //获取文档集
56   - DB.DB = client.Database("LeYouTu")
57   - //DB.DB.Login(conf.DbUser, conf.DbPassword)
  73 + DB.DB = client.Database(Config.Info.DbName)
58 74  
59 75 DB.CItem = DB.DB.Collection("Item")
60 76 DB.CComplaint = DB.DB.Collection("Complaint")
... ... @@ -76,7 +92,7 @@ func main() {
76 92  
77 93 // 连接redis
78 94 DB.Redis = Cache.NewRedis(&Cache.RedisOpts{
79   - conf.RedisPath,
  95 + Config.Info.RedisPath,
80 96 "",
81 97 0,
82 98 200,
... ... @@ -84,59 +100,68 @@ func main() {
84 100 0,
85 101 })
86 102  
87   - r := gin.Default()
  103 + Gin = gin.Default()
88 104 //r.Static("/.well-known", "./.well-known/")
89   - r.GET("/AllItems", Api.AllItems)
90   - r.GET("/AllItemTime", Api.AllItemTime)
91   - r.GET("/AllCommodity", Api.AllCommodity)
92   - r.GET("/AllLine", Api.AllLine)
93   - r.GET("/ItemInfo", Api.ItemInfo)
94   - r.GET("/CommodityInfo", Api.CommodityInfo)
95   - r.POST("/CreateComplaint", Api.CreateComplaint)
96   - r.GET("/AllComplaint", Api.AllComplaint)
97   - //r.POST("/CreateUser", Api.CreateUser)
98   - r.POST("/LoginUser", Api.LoginUser)
99   - r.POST("/UpdateUser", Api.UpdateUser)
100   - r.GET("/UserInfo", Api.UserInfo)
101   - r.GET("/ScenicInfo", Api.ScenicInfo)
102   - r.GET("/LineInfo", Api.LineInfo)
103   - r.GET("/AllTag", Api.AllTag)
104   - r.GET("/AllTagGroup", Api.AllTagGroup)
105   - r.POST("/Tag/Create", Api.CreateTag)
106   - r.POST("/Tag/Remove", Api.RemoveTag)
107   -
108   - r.POST("/Upload", Api.Upload)
109   - r.POST("/UpdateItem", Api.UpdateItem)
110   - r.POST("/UpdateCommodity", Api.UpdateCommodity)
111   - r.POST("/UpdateLine", Api.UpdateLine)
112   - r.POST("/UpdateScenic", Api.UpdateScenic)
113   - r.POST("/UpdateItemTime", Api.UpdateItemTime)
114   - r.GET("/AllScenic", Api.AllScenic)
115   - r.POST("/UserLog", Api.UserLog)
116   - r.GET("/AllUserLog", Api.AllUserLog)
117   - r.POST("/Sms/Send", Api.Send)
118   - r.POST("/Investigation/Save", Api.SaveInvestigation)
119   - r.GET("/Investigation/List", Api.AllInvestigation)
120   - r.POST("/Trajectory/Save", Api.SaveTrajectory)
121   - r.POST("/DealyMessage/Create", Api.CreateDealyMessage)
122   - r.GET("/DealyMessage/Info", Api.DealyMessageInfo)
123   - r.POST("/DealyMessage/Remove", Api.RemoveDealyMessage)
124   - r.POST("/Icon/Update", Api.UpdateIcon)
125   - r.GET("/Icon/All", Api.AllIcons)
126   - r.GET("/Icon/Info", Api.IconInfo)
127   - r.POST("/CheckToken", Api.CheckToken)
128   - //r.GET("/Tiles", Api.Tiles)
129   - r.POST("/TopMenus/Update", Api.UpdateTopMenus)
130   - r.GET("/TopMenus/All", Api.AllTopMenus)
131   - r.POST("/RegisterDevice", Api.RegisterDevice)
132   - r.POST("/RemoveUser", Api.RemoveUser)
133   - //r.GET("/ws", Api.WsPage)
134   -
135   - r.Static("/Upload", "./Upload")
136   - r.Static("/Console", "./Console")
137   - r.Static("/Policy", dir+"/Policy")
138   -
139   - r.GET("MP_verify_R9xuhLXYcVbdDDNk.txt", func(c *gin.Context) {
  105 +
  106 + InitController("GET", "/AllItems", Api.AllItems, &DB.SModel{})
  107 + InitController("GET", "/AllItemTime", Api.AllItemTime, &DB.SModel{})
  108 + InitController("GET", "/AllCommodity", Api.AllCommodity, &DB.SModel{})
  109 + InitController("GET", "/AllLine", Api.AllLine, &DB.SModel{})
  110 + InitController("GET", "/ItemInfo", Api.ItemInfo, &DB.SModel{})
  111 + InitController("GET", "/CommodityInfo", Api.CommodityInfo, &DB.SModel{})
  112 + InitController("POST", "/CreateComplaint", Api.CreateComplaint, &DB.SModel{})
  113 + InitController("GET", "/AllComplaint", Api.AllComplaint, &DB.SModel{"投诉建议", "查看所有"})
  114 + //InitController("/CreateUser", Api.CreateUser)
  115 + InitController("POST", "/LoginUser", Api.LoginUser, &DB.SModel{})
  116 + InitController("POST", "/UpdateUser", Api.UpdateUser, &DB.SModel{"用户管理", "修改"})
  117 + InitController("GET", "/UserInfo", Api.UserInfo, &DB.SModel{})
  118 + InitController("GET", "/ScenicInfo", Api.ScenicInfo, &DB.SModel{})
  119 + InitController("GET", "/LineInfo", Api.LineInfo, &DB.SModel{})
  120 + InitController("GET", "/AllTag", Api.AllTag, &DB.SModel{})
  121 + InitController("GET", "/AllTagGroup", Api.AllTagGroup, &DB.SModel{})
  122 + InitController("POST", "/Tag/Create", Api.CreateTag, &DB.SModel{"标签管理", "增加"})
  123 + InitController("POST", "/Tag/Remove", Api.RemoveTag, &DB.SModel{"标签管理", "删除"})
  124 +
  125 + InitController("POST", "/Upload", Api.Upload, &DB.SModel{})
  126 + InitController("POST", "/UpdateItem", Api.UpdateItem, &DB.SModel{"项目管理", "修改"})
  127 + InitController("POST", "/UpdateCommodity", Api.UpdateCommodity, &DB.SModel{"商品管理", "修改"})
  128 + InitController("POST", "/UpdateLine", Api.UpdateLine, &DB.SModel{"线路管理", "修改"})
  129 + InitController("POST", "/UpdateScenic", Api.UpdateScenic, &DB.SModel{"景区管理", "修改"})
  130 + InitController("POST", "/UpdateItemTime", Api.UpdateItemTime, &DB.SModel{"项目管理", "修改等候时间"})
  131 + InitController("GET", "/AllScenic", Api.AllScenic, &DB.SModel{})
  132 + InitController("POST", "/UserLog", Api.UserLog, &DB.SModel{})
  133 + InitController("GET", "/AllUserLog", Api.AllUserLog, &DB.SModel{})
  134 + InitController("POST", "/Sms/Send", Api.Send, &DB.SModel{})
  135 + InitController("POST", "/Investigation/Save", Api.SaveInvestigation, &DB.SModel{})
  136 + InitController("GET", "/Investigation/List", Api.AllInvestigation, &DB.SModel{})
  137 + InitController("POST", "/Trajectory/Save", Api.SaveTrajectory, &DB.SModel{})
  138 + InitController("POST", "/DealyMessage/Create", Api.CreateDealyMessage, &DB.SModel{"通知管理", "增加"})
  139 + InitController("GET", "/DealyMessage/Info", Api.DealyMessageInfo, &DB.SModel{"通知管理", "查看所有"})
  140 + InitController("POST", "/DealyMessage/Remove", Api.RemoveDealyMessage, &DB.SModel{"通知管理", "删除"})
  141 + InitController("POST", "/Icon/Update", Api.UpdateIcon, &DB.SModel{"图标管理", "修改管理"})
  142 + InitController("GET", "/Icon/All", Api.AllIcons, &DB.SModel{})
  143 + InitController("GET", "/Icon/Info", Api.IconInfo, &DB.SModel{})
  144 + InitController("POST", "/CheckToken", Api.CheckToken, &DB.SModel{})
  145 + //InitController("/Tiles", Api.Tiles)
  146 + InitController("POST", "/TopMenus/Update", Api.UpdateTopMenus, &DB.SModel{})
  147 + InitController("GET", "/TopMenus/All", Api.AllTopMenus, &DB.SModel{})
  148 + InitController("GET", "/RegisterDevice", Api.RegisterDevice, &DB.SModel{})
  149 + InitController("POST", "/RemoveUser", Api.RemoveUser, &DB.SModel{"用户管理", "删除"})
  150 +
  151 + InitController("POST", "/LoginOperator", Api.LoginOperator, &DB.SModel{})
  152 + InitController("POST", "/UpdateOperator", Api.UpdateOperator, &DB.SModel{"操作员管理", "增加和修改"})
  153 + InitController("GET", "/AllOperator", Api.AllOperator, &DB.SModel{"操作员管理", "查看所有"})
  154 + Gin.GET("/AllModules", Auth.Modules)
  155 + //InitController("/ws", Api.WsPage)
  156 +
  157 + // 用于给赵翔测试通知效果
  158 + Gin.GET("/PushNoticeToiOS", Api.PushNoticeToiOS)
  159 +
  160 + Gin.Static("/Upload", "./Upload")
  161 + Gin.Static("/Console", "./Console")
  162 + Gin.Static("/Policy", dir+"/Policy")
  163 +
  164 + Gin.GET("MP_verify_R9xuhLXYcVbdDDNk.txt", func(c *gin.Context) {
140 165 c.String(200, "R9xuhLXYcVbdDDNk")
141 166 })
142 167 //r.Static("/tiles2", dir+"/tiles")
... ... @@ -149,7 +174,7 @@ func main() {
149 174 DelayMessage.GlobalDM.Start()
150 175 }()
151 176  
152   - // -初始化数据
  177 + // -初始化延迟数据
153 178 if cur, err := DelayMessage.CDelayMessage.Find(tools.GetContext(), bson.M{}); err == nil {
154 179 defer cur.Close(tools.GetContext())
155 180 for cur.Next(tools.GetContext()) {
... ... @@ -170,5 +195,19 @@ func main() {
170 195 spew.Dump(err)
171 196 }
172 197  
173   - r.Run(":8080")
  198 + Gin.Run(":8080")
  199 +}
  200 +
  201 +func InitController(method string, uri string, handFunc func(c *gin.Context), auth *DB.SModel) {
  202 +
  203 + if auth.Model != "" {
  204 + Auth.Models[auth.Model] = append(Auth.Models[auth.Model], auth.Action)
  205 + }
  206 +
  207 + if method == "GET" {
  208 + Gin.GET(uri, Auth.CheckAuthFunc(handFunc, auth))
  209 + }
  210 + if method == "POST" {
  211 + Gin.POST(uri, Auth.CheckAuthFunc(handFunc, auth))
  212 + }
174 213 }
... ...
... ... @@ -1,83 +0,0 @@
1   -package main
2   -
3   -import (
4   - "context"
5   - "fmt"
6   - "github.com/gin-gonic/gin"
7   - "go.mongodb.org/mongo-driver/mongo"
8   - "go.mongodb.org/mongo-driver/mongo/options"
9   - "log"
10   - "time"
11   -)
12   -
13   -var (
14   - client *mongo.Client
15   - err error
16   - result *mongo.InsertOneResult
17   - collection *mongo.Collection
18   -)
19   -
20   -// @APIVersion 1.0.0
21   -// @APITitle 乐游图后端接口文档
22   -// @BasePath 正式 leyoutu.st-i.com.cn; 测试 letu.api.imagchina.com
23   -func main() {
24   -
25   - // Set client options
26   - clientOptions := options.Client().ApplyURI("mongodb://localhost:27017")
27   - clientOptions.SetLocalThreshold(3 * time.Second) //只使用与mongo操作耗时小于3秒的
28   - clientOptions.SetMaxConnIdleTime(5 * time.Second) //指定连接可以保持空闲的最大毫秒数
29   - clientOptions.SetMaxPoolSize(4096) //使用最大的连接数
30   -
31   - // Connect to MongoDB
32   - client, err = mongo.Connect(context.TODO(), clientOptions)
33   -
34   - if err != nil {
35   - log.Fatal(err)
36   - }
37   -
38   - // Check the connection
39   - err = client.Ping(context.TODO(), nil)
40   -
41   - if err != nil {
42   - log.Fatal(err)
43   - }
44   -
45   - fmt.Println("Connected to MongoDB!")
46   -
47   - collection = client.Database("LeYouTu").Collection("LogRecord")
48   -
49   - r := gin.Default()
50   - r.GET("/AllScenic", func(c *gin.Context) {
51   - c.Header("Access-Control-Allow-Origin", c.Request.Header.Get("Origin"))
52   - c.Header("Access-Control-Allow-Credentials", "true")
53   -
54   - //var aItems = DB.SItem{}
55   - //if err = collection.FindOne(context.TODO(), bson.D{{}}).Decode(&aItems); err != nil {
56   - // println(err)
57   - //}
58   -
59   - record := &LogRecord{
60   - JobName: "job10",
61   - Command: "echo hello",
62   - Err: "",
63   - Content: "hello",
64   - }
65   -
66   - if result, err = collection.InsertOne(context.TODO(), record); err != nil {
67   - fmt.Println(err)
68   - return
69   - }
70   -
71   - c.JSON(200, "ok")
72   -
73   - })
74   -
75   - r.Run(":8080")
76   -}
77   -
78   -type LogRecord struct {
79   - JobName string `bson:"jobName"` // 任务名
80   - Command string `bson:"command"` // shell命令
81   - Err string `bson:"err"` // 脚本错误
82   - Content string `bson:"content"` // 脚本输出
83   -}