|
@@ -7,6 +7,10 @@ import (
|
7
|
7
|
"SCRM/service/article_service"
|
8
|
8
|
"SCRM/enums"
|
9
|
9
|
"SCRM/models"
|
|
10
|
+ "time"
|
|
11
|
+ "SCRM/utils"
|
|
12
|
+ "encoding/json"
|
|
13
|
+ "strconv"
|
10
|
14
|
)
|
11
|
15
|
|
12
|
16
|
func ArticleRouters() {
|
|
@@ -14,6 +18,9 @@ func ArticleRouters() {
|
14
|
18
|
beego.Router("/api/acticle/createacticle",&ArticleManage{},"Get:CreateArticle")
|
15
|
19
|
beego.Router("/api/acticle/getArticleType",&ArticleManage{},"Get:GetArticleType")
|
16
|
20
|
beego.Router("/api/acticle/getAllArticles",&ArticleManage{},"Get:GetAllArticles")
|
|
21
|
+ beego.Router("/api/article/addCategory",&ArticleManage{},"Post:AddCategory")
|
|
22
|
+ beego.Router("/api/acticle/getCategorys",&ArticleManage{},"Get:GetCategorys")
|
|
23
|
+ beego.Router("/api/acticle/edit",&ArticleManage{},"Put:EditCategorys")
|
17
|
24
|
}
|
18
|
25
|
|
19
|
26
|
type ArticleManage struct {
|
|
@@ -28,6 +35,7 @@ func (this *ArticleManage) CreateArticle(){
|
28
|
35
|
actcontent := this.GetString("act_content")
|
29
|
36
|
orglogo := this.GetString("org_logo")
|
30
|
37
|
acttype, _ := this.GetInt64("act_type")
|
|
38
|
+ timenow := time.Now().Unix()
|
31
|
39
|
fmt.Println("姓名:",actname,"文章内容",actcontent,"图片",orglogo,"文章类型",acttype,userOrgID)
|
32
|
40
|
articles := models.Articles{
|
33
|
41
|
Title: actname,
|
|
@@ -35,6 +43,8 @@ func (this *ArticleManage) CreateArticle(){
|
35
|
43
|
Imgs: orglogo,
|
36
|
44
|
ClassId: acttype,
|
37
|
45
|
UserOrgId:userOrgID,
|
|
46
|
+ Ctime:timenow,
|
|
47
|
+ Status:1,
|
38
|
48
|
}
|
39
|
49
|
err := article_service.AddAritcle(articles)
|
40
|
50
|
if err !=nil{
|
|
@@ -59,7 +69,7 @@ func (this *ArticleManage) GetArticleType(){
|
59
|
69
|
}
|
60
|
70
|
|
61
|
71
|
func (this *ArticleManage) GetAllArticles() {
|
62
|
|
- page, _ := this.GetInt("page", 1)
|
|
72
|
+ page, _ := this.GetInt64("page", 1)
|
63
|
73
|
limit, _ := this.GetInt64("limit", 10)
|
64
|
74
|
searchKey := this.GetString("search", "")
|
65
|
75
|
classId,_ := this.GetInt64("classid",0)
|
|
@@ -74,16 +84,179 @@ func (this *ArticleManage) GetAllArticles() {
|
74
|
84
|
adminUserInfo := this.GetAdminUserInfo()
|
75
|
85
|
userOrgID := adminUserInfo.CurrentOrgId
|
76
|
86
|
|
77
|
|
- articles, total, err := article_service.FindAllArticle(userOrgID, page,10, searchKey, classId)
|
|
87
|
+ articles, total, err := article_service.FindAllArticle(userOrgID, page,limit, searchKey, classId)
|
78
|
88
|
fmt.Println("文章内容是是么",articles)
|
|
89
|
+ fmt.Println("total",total)
|
|
90
|
+ fmt.Println("err",err)
|
79
|
91
|
if err !=nil{
|
80
|
92
|
this.ServeFailJsonSend(enums.ErrorCodeDataException, "获取文章列表失败")
|
81
|
93
|
return
|
82
|
94
|
}
|
|
95
|
+ category, err := article_service.FindCategoryList(userOrgID)
|
|
96
|
+ fmt.Println("category是傻",category,err)
|
|
97
|
+ if err !=nil{
|
|
98
|
+ this.ServeFailJsonSend(enums.ErrorCodeDataException, "获取文章分类列表失败")
|
|
99
|
+ return
|
|
100
|
+ }
|
83
|
101
|
this.ServeSuccessJSON(map[string]interface{}{
|
84
|
102
|
"articles":articles,
|
85
|
103
|
"total":total,
|
|
104
|
+ "category":category,
|
|
105
|
+ })
|
|
106
|
+ return
|
|
107
|
+}
|
|
108
|
+
|
|
109
|
+func (this *ArticleManage) AddCategory(){
|
|
110
|
+
|
|
111
|
+ dataBody := make(map[string]interface{}, 0)
|
|
112
|
+ err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
|
|
113
|
+ fmt.Println("err是什么呢",err)
|
|
114
|
+ if err != nil {
|
|
115
|
+ utils.ErrorLog(err.Error())
|
|
116
|
+ this.ServeFailJsonSend(enums.ErrorCodeParamWrong, "参数错误")
|
|
117
|
+ return
|
|
118
|
+ }
|
|
119
|
+
|
|
120
|
+ name:= dataBody["name"].(string)
|
|
121
|
+ fmt.Println("name是谁?",name)
|
|
122
|
+ if len(name) == 0 {
|
|
123
|
+ this.ServeFailJsonSend(enums.ErrorCodeParamWrong, "姓名不能为空")
|
|
124
|
+ return
|
|
125
|
+ }
|
|
126
|
+
|
|
127
|
+ content := dataBody["content"].(string)
|
|
128
|
+ fmt.Println("content是谁?",content)
|
|
129
|
+ if len(content) == 0 {
|
|
130
|
+ this.ServeFailJsonSend(enums.ErrorCodeParamWrong,"内容不能为空")
|
|
131
|
+ return
|
|
132
|
+ }
|
|
133
|
+
|
|
134
|
+ sort := dataBody["sort"].(string)
|
|
135
|
+ sors, _ := strconv.ParseInt(sort, 10, 64)
|
|
136
|
+ if sors <=0 {
|
|
137
|
+ this.ServeFailJsonSend(enums.ErrorCodeParamWrong, "排序不能为空")
|
|
138
|
+ return
|
|
139
|
+ }
|
|
140
|
+ fmt.Println("soert是谁?",sort)
|
|
141
|
+ fmt.Println("姓名:",name,"内容",content,"排序",sort)
|
|
142
|
+ timenow := time.Now().Unix()
|
|
143
|
+ adminUserInfo := this.GetAdminUserInfo()
|
|
144
|
+ userOrgID := adminUserInfo.CurrentOrgId
|
|
145
|
+ category := models.ArticleCategory{
|
|
146
|
+ Name: name,
|
|
147
|
+ Summary: content,
|
|
148
|
+ Order: sors,
|
|
149
|
+ UserOrgId:userOrgID,
|
|
150
|
+ Status: 1,
|
|
151
|
+ Ctime: timenow,
|
|
152
|
+ }
|
|
153
|
+ fmt.Println(category)
|
|
154
|
+ err = article_service.AddCategory(category)
|
|
155
|
+ fmt.Println(err)
|
|
156
|
+ if err !=nil{
|
|
157
|
+ this.ServeFailJsonSend(enums.ErrorCodeDataException, "添加分类失败")
|
|
158
|
+ return
|
|
159
|
+ }
|
|
160
|
+
|
|
161
|
+ this.ServeSuccessJSON(map[string]interface{}{
|
|
162
|
+ "category":category,
|
|
163
|
+ })
|
|
164
|
+}
|
|
165
|
+
|
|
166
|
+func (this *ArticleManage) GetCategorys() {
|
|
167
|
+ adminUserInfo := this.GetAdminUserInfo()
|
|
168
|
+ userOrgID := adminUserInfo.CurrentOrgId
|
|
169
|
+ page, _ := this.GetInt64("page", 1)
|
|
170
|
+ limit, _ := this.GetInt64("limit", 10)
|
|
171
|
+ if page <= 0 {
|
|
172
|
+ page = 1
|
|
173
|
+ }
|
|
174
|
+ if limit <= 0 {
|
|
175
|
+ limit = 10
|
|
176
|
+ }
|
|
177
|
+ fmt.Println("机构ID",userOrgID)
|
|
178
|
+ categorys, total, err := article_service.GetCategorys(page, limit, userOrgID)
|
|
179
|
+ fmt.Println("hhe",categorys,total,err)
|
|
180
|
+ if err !=nil{
|
|
181
|
+ this.ServeFailJsonSend(enums.ErrorCodeDataException, "获取文章分类列表失败")
|
|
182
|
+ return
|
|
183
|
+ }
|
|
184
|
+ this.ServeSuccessJSON(map[string]interface{}{
|
|
185
|
+ "category":categorys,
|
|
186
|
+ "total":total,
|
86
|
187
|
})
|
87
|
188
|
return
|
88
|
189
|
}
|
89
|
190
|
|
|
191
|
+func (this *ArticleManage) EditCategorys() {
|
|
192
|
+ id, _ := this.GetInt64("MenuId", 0)
|
|
193
|
+ fmt.Println("ID是多少",id)
|
|
194
|
+ if id <= 0 {
|
|
195
|
+ this.ServeFailJsonSend(enums.ErrorCodeParamWrong, "参数错误:id")
|
|
196
|
+ return
|
|
197
|
+ }
|
|
198
|
+ adminUserInfo := this.GetAdminUserInfo()
|
|
199
|
+ userOrgID := adminUserInfo.CurrentOrgId
|
|
200
|
+ categorys, err := article_service.GetCategorysByID(userOrgID, id)
|
|
201
|
+ fmt.Println("err是设么",err)
|
|
202
|
+ if err != nil {
|
|
203
|
+ this.ServeFailJsonSend(enums.ErrorCodeDBUpdate, "编辑类别失败:("+err.Error()+")")
|
|
204
|
+ return
|
|
205
|
+ }
|
|
206
|
+ if categorys == nil {
|
|
207
|
+ this.ServeFailJsonSend(enums.ErrorCodeDBUpdate, "编辑类别失败:(会员记录不存在)")
|
|
208
|
+ return
|
|
209
|
+ }
|
|
210
|
+
|
|
211
|
+ timenow := time.Now().Unix()
|
|
212
|
+
|
|
213
|
+ dataBody := make(map[string]interface{}, 0)
|
|
214
|
+ err = json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
|
|
215
|
+ if err != nil {
|
|
216
|
+ utils.ErrorLog(err.Error())
|
|
217
|
+ this.ServeFailJsonSend(enums.ErrorCodeParamWrong, "参数错误")
|
|
218
|
+ return
|
|
219
|
+ }
|
|
220
|
+
|
|
221
|
+ name:= dataBody["Name"].(string)
|
|
222
|
+ fmt.Println("name是谁?",name)
|
|
223
|
+ if len(name) == 0 {
|
|
224
|
+ this.ServeFailJsonSend(enums.ErrorCodeParamWrong, "姓名不能为空")
|
|
225
|
+ return
|
|
226
|
+ }
|
|
227
|
+
|
|
228
|
+ content := dataBody["Summary"].(string)
|
|
229
|
+ fmt.Println("content是谁?",content)
|
|
230
|
+ if len(content) == 0 {
|
|
231
|
+ this.ServeFailJsonSend(enums.ErrorCodeParamWrong,"内容不能为空")
|
|
232
|
+ return
|
|
233
|
+ }
|
|
234
|
+
|
|
235
|
+ sort := dataBody["Order"].(string)
|
|
236
|
+ sors, _ := strconv.ParseInt(sort, 10, 64)
|
|
237
|
+ if sors <=0 {
|
|
238
|
+ this.ServeFailJsonSend(enums.ErrorCodeParamWrong, "排序不能为空")
|
|
239
|
+ return
|
|
240
|
+ }
|
|
241
|
+ fmt.Println("soert是谁?",sort)
|
|
242
|
+ fmt.Println("姓名:",name,"内容",content,"排序",sort)
|
|
243
|
+
|
|
244
|
+ category := models.ArticleCategory{
|
|
245
|
+ Name: name,
|
|
246
|
+ Summary: content,
|
|
247
|
+ Order: sors,
|
|
248
|
+ UserOrgId:userOrgID,
|
|
249
|
+ Status: 1,
|
|
250
|
+ Mtime: timenow,
|
|
251
|
+ }
|
|
252
|
+ err = article_service.EditCategory(category)
|
|
253
|
+ fmt.Println("err错误",err)
|
|
254
|
+ if err != nil {
|
|
255
|
+ this.ServeFailJsonSend(enums.ErrorCodeDBUpdate, "编辑类别失败:("+err.Error()+")")
|
|
256
|
+ return
|
|
257
|
+ }
|
|
258
|
+ fmt.Println(category)
|
|
259
|
+ this.ServeSuccessJSON(map[string]interface{}{
|
|
260
|
+ "category":categorys,
|
|
261
|
+ })
|
|
262
|
+}
|