Explorar el Código

评论模块修改

xiaoming_global hace 5 años
padre
commit
9995facd45

+ 101 - 0
controllers/article/article_controller.go Ver fichero

@@ -38,6 +38,11 @@ func ArticleRouters() {
38 38
 	beego.Router("/api/article/deleteArticle",&ArticleManage{},"Get:DeleteArticles")
39 39
 	beego.Router("/api/acticle/send",&ArticleManage{},"Get:SendReplycontent")
40 40
 	beego.Router("/api/acticle/getReplyAllComents",&ArticleManage{},"Get:GetReplyAllComents")
41
+	beego.Router("/api/article/sendInformation",&ArticleManage{},"Get:GetSendInformation")
42
+	beego.Router("/api/article/spreadReplay",&ArticleManage{},"Get:GetSpreadReplay")
43
+	beego.Router("/api/article/clearRelyInfo",&ArticleManage{},"Delete:ClearReplyInfo")
44
+	beego.Router("/api/article/deleteReply",&ArticleManage{},"Delete:DeleteReply")
45
+	beego.Router("/api/article/spread",&ArticleManage{},"Get:GetSpreadInfo")
41 46
 }
42 47
 
43 48
 type ArticleManage struct {
@@ -972,3 +977,99 @@ func (this * ArticleManage) GetReplyAllComents()  {
972 977
 	    "total":total,
973 978
 	})
974 979
 }
980
+
981
+func  (this * ArticleManage) GetSendInformation()  {
982
+	artilcid, _ := this.GetInt64("artilcid")
983
+	fmt.Println("文章id",artilcid)
984
+	parentid, _ := this.GetInt64("parentid")
985
+	fmt.Println("父类id",parentid)
986
+	content := this.GetString("content")
987
+	fmt.Println("文章内容",content)
988
+	adminUserInfo := this.GetAdminUserInfo()
989
+	userOrgID := adminUserInfo.CurrentOrgId
990
+	org := adminUserInfo.Orgs[adminUserInfo.CurrentOrgId]
991
+	orgName := org.OrgName
992
+	orgLogo := org.OrgLogo
993
+	fmt.Println("logo",orgLogo)
994
+	comment := models.Comment{
995
+		Content: content,
996
+		ParentId: parentid,
997
+		ArticleId: artilcid,
998
+		Ctime: time.Now().Unix(),
999
+		CommentUserId:userOrgID,
1000
+		Status:1,
1001
+		CommentUserAvater: orgLogo,
1002
+		CommentUserName:orgName,
1003
+	}
1004
+	err := article_service.AddComment(&comment)
1005
+	fmt.Println("错误是什么",err)
1006
+	if err !=nil{
1007
+		this.ServeFailJsonSend(enums.ErrorCodeDataException, "添加回复内容失败")
1008
+		return
1009
+	}
1010
+	this.ServeSuccessJSON(map[string]interface{}{
1011
+		"comment":comment,
1012
+	})
1013
+}
1014
+
1015
+func  (this * ArticleManage) GetSpreadReplay()  {
1016
+	artilcid, _ := this.GetInt64("artilcid")
1017
+	fmt.Println("文章id",artilcid)
1018
+	parentid, _ := this.GetInt64("parentid")
1019
+	fmt.Println("父类id",parentid)
1020
+
1021
+	comments, err := article_service.GetAllReplyFormId(artilcid, parentid)
1022
+	if err !=nil{
1023
+		this.ServeFailJsonSend(enums.ErrorCodeDataException, "查询回复内容失败")
1024
+		return
1025
+	}
1026
+	this.ServeSuccessJSON(map[string]interface{}{
1027
+		"comments":comments,
1028
+	})
1029
+}
1030
+
1031
+func (this * ArticleManage) ClearReplyInfo()  {
1032
+	id, _ := this.GetInt64("id")
1033
+	fmt.Println("id为",id)
1034
+	err := article_service.ClearReplyInfo(id)
1035
+	fmt.Println("错误为",err)
1036
+	if err !=nil{
1037
+		this.ServeFailJsonSend(enums.ErrorCodeDataException, "删除回复成功")
1038
+		return
1039
+	}
1040
+
1041
+	returnData := make(map[string]interface{}, 0)
1042
+	returnData["msg"] = "ok"
1043
+	this.ServeSuccessJSON(returnData)
1044
+	return
1045
+}
1046
+
1047
+func (this * ArticleManage) DeleteReply()  {
1048
+	id, _ := this.GetInt64("id")
1049
+	fmt.Println("id为",id)
1050
+	err := article_service.DeleteReply(id)
1051
+	if err !=nil{
1052
+		this.ServeFailJsonSend(enums.ErrorCodeDataException, "删除回复成功")
1053
+		return
1054
+	}
1055
+
1056
+	returnData := make(map[string]interface{}, 0)
1057
+	returnData["msg"] = "ok"
1058
+	this.ServeSuccessJSON(returnData)
1059
+	return
1060
+}
1061
+
1062
+func (this * ArticleManage) GetSpreadInfo()  {
1063
+	parentid, _ := this.GetInt64("parentid")
1064
+	acticlid, _ := this.GetInt64("acticlid")
1065
+	fmt.Println("父类id",parentid)
1066
+	fmt.Println("文章id",acticlid)
1067
+	comments, err := article_service.GetQueryReplyInfo(parentid, acticlid)
1068
+	if err !=nil{
1069
+		this.ServeFailJsonSend(enums.ErrorCodeDataException, "查询回复内容失败")
1070
+		return
1071
+	}
1072
+	this.ServeSuccessJSON(map[string]interface{}{
1073
+		"comments":comments,
1074
+	})
1075
+}

+ 22 - 1
service/article_service/article_category_service.go Ver fichero

@@ -268,7 +268,7 @@ func AddComment(comment *models.Comment)(error)  {
268 268
 func GetReplyAllComents(page int64,limit int64)(comment []*models.Comment,total int64,err error)  {
269 269
 	db := service.PatientReadDB().Table("sgj_patient_articles_comment as a").Where("a.status = 1")
270 270
 	offset := (page - 1) * limit
271
-	err = db.Count(&total).Order("a.ctime desc").Offset(offset).Limit(limit).
271
+	err = db.Where("parent_id = ?",0).Count(&total).Order("a.ctime desc").Offset(offset).Limit(limit).
272 272
 		Select("a.id,a.article_id,a.comment_user_id,a.parent_id,a.content,a.ctime,a.status,a.star_num,a.comment_num,a.comment_id,a.comment_user_name,a.comment_user_avater,a.source,a.ttid,a.tuser_id,a.taid,a.tpid,a.tcid").Find(&comment).Error
273 273
 	fmt.Println("err是啥呢?",err)
274 274
 	if err != nil {
@@ -277,6 +277,27 @@ func GetReplyAllComents(page int64,limit int64)(comment []*models.Comment,total
277 277
 	return
278 278
 }
279 279
 
280
+func GetAllReplyFormId(articleID int64, commentId int64)([]models.Comment, error)  {
281
+	var comments []models.Comment
282
+	errs := service.PatientReadDB().Model(&models.Comment{}).
283
+		Where("article_id = ? AND parent_id = ? AND status = ?", articleID, commentId, 1).
284
+		Find(&comments).Error
280 285
 
286
+	return comments, errs
287
+}
281 288
 
289
+func ClearReplyInfo(id int64)(error){
290
+	err := service.PatientWriteDB().Model(&models.Comment{}).Where("id = ?", id).Update(map[string]interface{}{"status": 0, "mtime": time.Now().Unix()}).Error
291
+	return  err
292
+}
282 293
 
294
+func DeleteReply(id int64)(error){
295
+	err := service.PatientWriteDB().Model(&models.Comment{}).Where("id = ?", id).Update(map[string]interface{}{"status": 0, "mtime": time.Now().Unix()}).Error
296
+	 return  err
297
+	}
298
+func GetQueryReplyInfo(parentid int64,articleID int64)([]models.Comment,error)  {
299
+	var comments []models.Comment
300
+	errs := service.PatientWriteDB().Model(&models.Comment{}).
301
+		Where("article_id = ? AND parent_id = ? AND status = ?", articleID, parentid, 1).Find(&comments).Error
302
+		return  comments,errs
303
+}