|
@@ -1,9 +1,11 @@
|
1
|
1
|
package wechatmenu
|
2
|
2
|
|
3
|
3
|
import (
|
|
4
|
+ "encoding/json"
|
4
|
5
|
"strings"
|
5
|
6
|
"wechat-conf/controllers"
|
6
|
7
|
"wechat-conf/models/model"
|
|
8
|
+ "wechat-conf/service/keyvalue"
|
7
|
9
|
"wechat-conf/service/sysuser"
|
8
|
10
|
"wechat-conf/service/wechatmenu"
|
9
|
11
|
"wechat-conf/utils"
|
|
@@ -15,6 +17,7 @@ import (
|
15
|
17
|
type MenuController struct {
|
16
|
18
|
dao *wechatmenu.WechatmenuServ
|
17
|
19
|
sdao *sysuser.SysuserServ
|
|
20
|
+ kdao *keyvalue.KeyvalueServ
|
18
|
21
|
controllers.BaseController
|
19
|
22
|
}
|
20
|
23
|
|
|
@@ -24,6 +27,34 @@ type MenuController struct {
|
24
|
27
|
func (c *MenuController) Constructor() {
|
25
|
28
|
c.dao = wechatmenu.NewWechatmenuServ(c.Context)
|
26
|
29
|
c.sdao = sysuser.NewSysuserServ(c.Context)
|
|
30
|
+ c.kdao = keyvalue.NewKeyvalueServ(c.Context)
|
|
31
|
+}
|
|
32
|
+
|
|
33
|
+type Wehchatmenu struct {
|
|
34
|
+ WechatJson string
|
|
35
|
+}
|
|
36
|
+type WechatMenuDetailSub struct {
|
|
37
|
+ Name string
|
|
38
|
+ Type string
|
|
39
|
+ Value string `json:"value,omitempty"`
|
|
40
|
+ Url string `json:"url,omitempty"`
|
|
41
|
+ Media_Id string `json:"media_id,omitempty"`
|
|
42
|
+ Key string `json:"key,omitempty"`
|
|
43
|
+}
|
|
44
|
+type WechatMenuDetail struct {
|
|
45
|
+ Name string
|
|
46
|
+ Type string
|
|
47
|
+ Value string `json:"value,omitempty"`
|
|
48
|
+ Url string `json:"url,omitempty"`
|
|
49
|
+ Media_Id string `json:"media_id,omitempty"`
|
|
50
|
+ Key string `json:"key,omitempty"`
|
|
51
|
+ Sub_Button []WechatMenuDetailSub
|
|
52
|
+}
|
|
53
|
+type WechatMenu struct {
|
|
54
|
+ Button []WechatMenuDetail
|
|
55
|
+}
|
|
56
|
+type Wechat struct {
|
|
57
|
+ Menu WechatMenu
|
27
|
58
|
}
|
28
|
59
|
|
29
|
60
|
func (c *MenuController) GetMenuList() {
|
|
@@ -38,6 +69,32 @@ func (c *MenuController) GetMenuList() {
|
38
|
69
|
c.ResponseError(err)
|
39
|
70
|
}
|
40
|
71
|
menu, err := client.GetMenu()
|
|
72
|
+ wechatmenu := menu["button"].([]WechatMenuDetail)
|
|
73
|
+ beego.Error("___________wechatmenulist____________")
|
|
74
|
+ beego.Error(wechatmenu)
|
|
75
|
+ beego.Error("_________________________________")
|
|
76
|
+ var keyList []*model.TaWechatKeyValue
|
|
77
|
+ for i := 0; i < len(wechatmenu); i++ {
|
|
78
|
+ if wechatmenu[i].Type == "click" {
|
|
79
|
+ key, err := c.kdao.GetValueByKey(wechatmenu[i].Key)
|
|
80
|
+ if err != nil {
|
|
81
|
+ c.ResponseError(err)
|
|
82
|
+ }
|
|
83
|
+ keyList = append(keyList, key)
|
|
84
|
+ }
|
|
85
|
+ for j := 0; j < len(wechatmenu[i].Sub_Button); j++ {
|
|
86
|
+ if wechatmenu[i].Sub_Button[j].Type == "click" {
|
|
87
|
+ key, err := c.kdao.GetValueByKey(wechatmenu[i].Key)
|
|
88
|
+ if err != nil {
|
|
89
|
+ c.ResponseError(err)
|
|
90
|
+ }
|
|
91
|
+ keyList = append(keyList, key)
|
|
92
|
+ }
|
|
93
|
+ }
|
|
94
|
+ }
|
|
95
|
+ beego.Error("___________keylist____________")
|
|
96
|
+ beego.Error(keyList)
|
|
97
|
+ beego.Error("_________________________________")
|
41
|
98
|
var code string = err.Error()
|
42
|
99
|
if err != nil {
|
43
|
100
|
if strings.Contains(code, "46003") {
|
|
@@ -46,11 +103,10 @@ func (c *MenuController) GetMenuList() {
|
46
|
103
|
c.ResponseError(err)
|
47
|
104
|
}
|
48
|
105
|
}
|
49
|
|
- c.ResponseJSON(menu)
|
50
|
|
-}
|
51
|
|
-
|
52
|
|
-type Wehchatmenu struct {
|
53
|
|
- WechatJson string
|
|
106
|
+ c.ResponseJSON(map[string]interface{}{
|
|
107
|
+ "menu": menu,
|
|
108
|
+ "keyList": keyList,
|
|
109
|
+ })
|
54
|
110
|
}
|
55
|
111
|
|
56
|
112
|
func (c *MenuController) RefreshMenu() {
|
|
@@ -60,8 +116,58 @@ func (c *MenuController) RefreshMenu() {
|
60
|
116
|
c.ResponseError(err)
|
61
|
117
|
}
|
62
|
118
|
str := wechatJson.WechatJson
|
63
|
|
- var data []byte = []byte(str)
|
64
|
|
- err := c.dao.UpdateWechatMenu(str, user.OrgId)
|
|
119
|
+ beego.Error("____________str___________")
|
|
120
|
+ beego.Error(str)
|
|
121
|
+ beego.Error("__________________________")
|
|
122
|
+ var menu Wechat
|
|
123
|
+ err := json.Unmarshal([]byte(str), &menu)
|
|
124
|
+ //var data []byte = []byte(str)
|
|
125
|
+ if err != nil {
|
|
126
|
+ c.ResponseError(err)
|
|
127
|
+ }
|
|
128
|
+ wechatmenu := menu.Menu.Button
|
|
129
|
+ beego.Error("___________wechatmenu____________")
|
|
130
|
+ beego.Error(wechatmenu)
|
|
131
|
+ beego.Error("_________________________________")
|
|
132
|
+ for i := 0; i < len(wechatmenu); i++ {
|
|
133
|
+ if wechatmenu[i].Type == "text" {
|
|
134
|
+ wechatmenu[i].Type = "click"
|
|
135
|
+ var keyvalue = model.TaWechatKeyValue{
|
|
136
|
+ KeyId: utils.GetGUID(),
|
|
137
|
+ Value: wechatmenu[i].Value,
|
|
138
|
+ }
|
|
139
|
+ err := c.kdao.AddKeyvalue(keyvalue)
|
|
140
|
+ if err != nil {
|
|
141
|
+ c.ResponseError(err)
|
|
142
|
+ }
|
|
143
|
+ wechatmenu[i].Key = keyvalue.KeyId
|
|
144
|
+ wechatmenu[i].Value = ""
|
|
145
|
+ }
|
|
146
|
+ for j := 0; j < len(wechatmenu[i].Sub_Button); j++ {
|
|
147
|
+ if wechatmenu[i].Sub_Button[j].Type == "text" {
|
|
148
|
+ wechatmenu[i].Sub_Button[j].Type = "click"
|
|
149
|
+ var keyvalue = model.TaWechatKeyValue{
|
|
150
|
+ KeyId: utils.GetGUID(),
|
|
151
|
+ Value: wechatmenu[i].Sub_Button[j].Value,
|
|
152
|
+ }
|
|
153
|
+ err := c.kdao.AddKeyvalue(keyvalue)
|
|
154
|
+ if err != nil {
|
|
155
|
+ c.ResponseError(err)
|
|
156
|
+ }
|
|
157
|
+ wechatmenu[i].Sub_Button[j].Key = keyvalue.KeyId
|
|
158
|
+ wechatmenu[i].Sub_Button[j].Value = ""
|
|
159
|
+ }
|
|
160
|
+ }
|
|
161
|
+ }
|
|
162
|
+ beego.Error("___________wechatmenuData____________")
|
|
163
|
+ beego.Error(wechatmenu)
|
|
164
|
+ beego.Error("_________________________________")
|
|
165
|
+ menuData, err := json.Marshal(wechatmenu)
|
|
166
|
+ if err != nil {
|
|
167
|
+ c.ResponseError(err)
|
|
168
|
+ }
|
|
169
|
+
|
|
170
|
+ err = c.dao.UpdateWechatMenu(string(menuData), user.OrgId)
|
65
|
171
|
if err != nil {
|
66
|
172
|
c.ResponseError(err)
|
67
|
173
|
}
|
|
@@ -73,7 +179,7 @@ func (c *MenuController) RefreshMenu() {
|
73
|
179
|
if err != nil {
|
74
|
180
|
c.ResponseError(err)
|
75
|
181
|
}
|
76
|
|
- err = client.RefreshMenu(data)
|
|
182
|
+ err = client.RefreshMenu(menuData)
|
77
|
183
|
if err != nil {
|
78
|
184
|
c.ResponseError(err)
|
79
|
185
|
}
|