瀏覽代碼

留言增加姓名

xiexiaoyuan 2 年之前
父節點
當前提交
e878134f88
共有 3 個文件被更改,包括 56 次插入67 次删除
  1. 3 13
      models/tables/yb_comment/update.go
  2. 22 21
      models/tables/yb_comment/yb_comment.go
  3. 31 33
      services/comment/comment.go

+ 3 - 13
models/tables/yb_comment/update.go

@@ -8,7 +8,7 @@ import "hongze/hongze_yb/global"
 	return
 }*/
 
-// Delete 软删除,隐藏评论
+// Delete 直接删除留言
 func Delete(userId uint64, commentId uint64)(err error) {
 	tx := global.DEFAULT_MYSQL.Begin()
 	defer func() {
@@ -18,23 +18,13 @@ func Delete(userId uint64, commentId uint64)(err error) {
 			tx.Commit()
 		}
 	}()
-	sql1 := ` UPDATE yb_comment
-			SET
-            	enabled = 0,
-				modify_time = NOW(),
-				is_hot = 0,
-				is_top = 0
-			WHERE type = 1 and user_id = ? and comment_id = ?`
+	sql1 := ` Delete from yb_comment WHERE type = 1 and user_id = ? and comment_id = ?`
 	err = tx.Exec(sql1, userId, commentId).Error
 	if err != nil {
 		return
 	}
 	// 删除相关联的回复
-	sql2 := ` UPDATE yb_comment
-			SET
-            	enabled = 0,
-				modify_time = NOW()
-			WHERE reply_comment_id = ? and type = 2`
+	sql2 := `Delete from yb_comment WHERE reply_comment_id = ? and type = 2`
 	err = tx.Exec(sql2, commentId).Error
 	return
 }

+ 22 - 21
models/tables/yb_comment/yb_comment.go

@@ -4,27 +4,28 @@ import "time"
 
 // 研报 用户留言表
 type YbComment struct {
-	CommentId                 uint64 `gorm:"primaryKey;column:comment_id;type:bigint(20) unsigned;not null" ` //留言ID
-	UserId                    uint64 `gorm:"column:user_id"` //用户id
-	AdminId                   uint64 `gorm:"column:admin_id"` //发布留言回复的管理员ID
-	ReportId                  int `gorm:"column:report_id"` //报告ID
-	ReportChapterId           int `gorm:"column:report_chapter_id"` //报告章节ID
-	Content                   string `gorm:"column:content"` //留言内容
-	SysIsRead                 int8 `gorm:"column:sys_is_read"` //管理员是否已读 0-未读,1-已读
-	SysReadTime               time.Time `gorm:"column:sys_read_time"` //管理员已读时间
-	SysReadAdminId            int64 `gorm:"column:sys_read_admin_id"` //已读的管理员id
-	ReplyCommentId            uint64 `gorm:"column:reply_comment_id"` //回复的留言ID
-	IsTop                     int8 `gorm:"column:is_top"` //是否置顶(0-未置顶,1-置顶)
-	IsHot                     int8 `gorm:"column:is_hot"` //是否设置精选(0-未设置,1-已设置)
-	HotTopTime                time.Time `gorm:"column:hot_top_time"` //设置精选或者设置置顶的时间
-	Type                      int8 `gorm:"column:type"` //留言类型 1-评论 2-回复
-	Enabled                   int8 `gorm:"column:enabled"` //是否有效, 0-无效留言 1-有效留言
-	IsShowName                int8 `gorm:"column:is_show_name"` //是否匿名 0-匿名,1-不匿名
-	SourceAgent               int `gorm:"column:source_agent"` //留言入口来源,1:小程序,2:pc
-	CreateTime                time.Time `gorm:"column:create_time"` //创建时间
-	ModifyTime                time.Time `gorm:"column:modify_time"` //修改时间
-	OldReportId               int `gorm:"column:old_report_id"  json:"old_report_id" ` //老报告ID
-	OldReportChapterId        int `gorm:"column:old_report_chapter_id" json:"old_report_chapter_id" ` //老报告章节ID
+	CommentId          uint64    `gorm:"primaryKey;column:comment_id;type:bigint(20) unsigned;not null" ` //留言ID
+	UserId             uint64    `gorm:"column:user_id"`                                                  //用户id
+	AdminId            uint64    `gorm:"column:admin_id"`                                                 //发布留言回复的管理员ID
+	ReportId           int       `gorm:"column:report_id"`                                                //报告ID
+	ReportChapterId    int       `gorm:"column:report_chapter_id"`                                        //报告章节ID
+	Content            string    `gorm:"column:content"`                                                  //留言内容
+	SysIsRead          int8      `gorm:"column:sys_is_read"`                                              //管理员是否已读 0-未读,1-已读
+	SysReadTime        time.Time `gorm:"column:sys_read_time"`                                            //管理员已读时间
+	SysReadAdminId     int64     `gorm:"column:sys_read_admin_id"`                                        //已读的管理员id
+	ReplyCommentId     uint64    `gorm:"column:reply_comment_id"`                                         //回复的留言ID
+	IsTop              int8      `gorm:"column:is_top"`                                                   //是否置顶(0-未置顶,1-置顶)
+	IsHot              int8      `gorm:"column:is_hot"`                                                   //是否设置精选(0-未设置,1-已设置)
+	HotTopTime         time.Time `gorm:"column:hot_top_time"`                                             //设置精选或者设置置顶的时间
+	Type               int8      `gorm:"column:type"`                                                     //留言类型 1-评论 2-回复
+	Enabled            int8      `gorm:"column:enabled"`                                                  //是否有效, 0-无效留言 1-有效留言
+	IsShowName         int8      `gorm:"column:is_show_name"`                                             //是否匿名 0-匿名,1-不匿名
+	SourceAgent        int       `gorm:"column:source_agent"`                                             //留言入口来源,1:小程序,2:pc
+	CreateTime         time.Time `gorm:"column:create_time"`                                              //创建时间
+	ModifyTime         time.Time `gorm:"column:modify_time"`                                              //修改时间
+	OldReportId        int       `gorm:"column:old_report_id"  json:"old_report_id" `                     //老报告ID
+	OldReportChapterId int       `gorm:"column:old_report_chapter_id" json:"old_report_chapter_id" `      //老报告章节ID
+	RealName           string    `gorm:"column:real_name"`                                                //留言内容
 }
 
 func (yc *YbComment) TableName() string {

+ 31 - 33
services/comment/comment.go

@@ -48,24 +48,6 @@ func Comment(user user.UserInfo, req reqComment.ReqComment) (ret response.RespCo
 		err = errors.New("请输入报告ID")
 		return
 	}
-	// 判断是否有留言权限
-	err, errMsg = services.CheckSimpleCompanyProduct(user)
-	if err != nil {
-		return
-	}
-	//处理老报告, 转化成新报告ID
-	if req.ReportChapterId <=0 && req.ReportId <=0 && (req.OldReportId >0 || req.OldReportChapterId > 0) {
-		reportId, reportChapterId, err, errMsg = services.GetReportIdReportChapterIdByOldReportId(uint64(req.OldReportId), uint64(req.OldReportChapterId))
-		if err != nil {
-			return
-		}
-	} else {
-		// 判断报告ID是否正确
-		err, errMsg = services.CheckReportExistByReportIdReportChapterId(reportId, reportChapterId)
-		if err != nil {
-			return
-		}
-	}
 	// 敏感词过滤
 	if user.RecordInfo.OpenID != "" && user.RecordInfo.CreatePlatform == 6 {   //只有小程序的用户才能走敏感词过滤接口
 		checkResult, tErr := wx_app.MsgSecCheck(user.RecordInfo.OpenID, req.Content)
@@ -84,22 +66,40 @@ func Comment(user user.UserInfo, req reqComment.ReqComment) (ret response.RespCo
 			}
 		}
 	}
-
+	// 判断是否有留言权限
+	err, errMsg = services.CheckSimpleCompanyProduct(user)
+	if err != nil {
+		return
+	}
+	//处理老报告, 转化成新报告ID
+	if req.ReportChapterId <=0 && req.ReportId <=0 && (req.OldReportId >0 || req.OldReportChapterId > 0) {
+		reportId, reportChapterId, err, errMsg = services.GetReportIdReportChapterIdByOldReportId(uint64(req.OldReportId), uint64(req.OldReportChapterId))
+		if err != nil {
+			return
+		}
+	} else {
+		// 判断报告ID是否正确
+		err, errMsg = services.CheckReportExistByReportIdReportChapterId(reportId, reportChapterId)
+		if err != nil {
+			return
+		}
+	}
 
 	//新增留言
 	now := time.Now()
 	commentInfo := &yb_comment.YbComment{
-		UserId: user.UserID,
-		Content: req.Content,
-		ReportId: reportId,
-		ReportChapterId: reportChapterId,
-		IsShowName: req.IsShowName,
-		SourceAgent: req.SourceAgent,
-		Type: 1,
-		Enabled: 1,
-		CreateTime: now,
-		ModifyTime: now,
-		OldReportId:    req.OldReportId,
+		UserId:             user.UserID,
+		RealName:           user.RealName,
+		Content:            req.Content,
+		ReportId:           reportId,
+		ReportChapterId:    reportChapterId,
+		IsShowName:         req.IsShowName,
+		SourceAgent:        req.SourceAgent,
+		Type:               1,
+		Enabled:            1,
+		CreateTime:         now,
+		ModifyTime:         now,
+		OldReportId:        req.OldReportId,
 		OldReportChapterId: req.OldReportChapterId,
 	}
 	err = commentInfo.Create()
@@ -143,9 +143,7 @@ func Delete(user user.UserInfo, req *reqComment.ReqDel) (err error) {
 		err = errors.New("不允许删除回复")
 		return
 	}
-	if commentInfo.Enabled == 0 {
-		return
-	}
+
 	err = yb_comment.Delete(user.UserID, commentInfo.CommentId)
 	if err != nil {
 		errMsg = err.Error()