Browse Source

Merge branch 'aj_qa_avatar' into debug

longyu 2 years ago
parent
commit
044e938ecb

+ 20 - 1
controller/community/comment.go

@@ -6,6 +6,8 @@ import (
 	"hongze/hongze_yb/logic/yb_community_question"
 	"hongze/hongze_yb/models/request"
 	responseModel "hongze/hongze_yb/models/response"
+	"hongze/hongze_yb/models/tables/wx_user"
+	"hongze/hongze_yb/models/tables/yb_community_question_comment"
 	"hongze/hongze_yb/services"
 	userService "hongze/hongze_yb/services/user"
 	"strconv"
@@ -20,11 +22,28 @@ func Comment(c *gin.Context) {
 	}
 	userInfo := userService.GetInfoByClaims(c)
 
+	var qaAvatarUrl string
+	if userInfo.QaAvatarUrl == "" {
+		avatar, err := yb_community_question_comment.GetUserAvatarRandom()
+		if err != nil {
+			response.FailMsg("发布失败", err.Error(), c)
+			return
+		}
+		qaAvatarUrl = avatar.AvatarUrl
+		err = wx_user.ModifyQaAvatarUrl(qaAvatarUrl, userInfo.UserID)
+		if err != nil {
+			response.FailMsg("发布失败", err.Error(), c)
+			return
+		}
+	} else {
+		qaAvatarUrl = userInfo.QaAvatarUrl
+	}
+
 	req.IsShowName = 0
 	if userInfo.NickName != `` { //非空串时为实名
 		req.IsShowName = 1
 	}
-	ybCommunityQuestionComment, err, errMsg := yb_community_question.Comment(userInfo, req.CommunityQuestionID, req.Content, req.SourceAgent, req.IsShowName)
+	ybCommunityQuestionComment, err, errMsg := yb_community_question.Comment(userInfo, req.CommunityQuestionID, req.Content, req.SourceAgent, req.IsShowName,qaAvatarUrl)
 	if err != nil {
 		response.FailMsg(errMsg, err.Error(), c)
 		return

+ 4 - 3
logic/yb_community_question/yb_community_question_comment.go

@@ -23,7 +23,7 @@ import (
 )
 
 // Comment 发布留言
-func Comment(user user.UserInfo, communityQuestionID uint32, content string, sourceAgent, isShowName int8) (ybCommunityQuestionComment *yb_community_question_comment.YbCommunityQuestionComment, err error, errMsg string) {
+func Comment(user user.UserInfo, communityQuestionID uint32, content string, sourceAgent, isShowName int8, qaAvatarUrl string) (ybCommunityQuestionComment *yb_community_question_comment.YbCommunityQuestionComment, err error, errMsg string) {
 	errMsg = "发布留言失败"
 	defer func() {
 		if err != nil {
@@ -92,8 +92,9 @@ func Comment(user user.UserInfo, communityQuestionID uint32, content string, sou
 		SourceAgent: sourceAgent,
 		//TopTime:                    time.Time{},
 		//HotTime:                    time.Time{},
-		ModifyTime: now,
-		CreateTime: now,
+		ModifyTime:  now,
+		CreateTime:  now,
+		QaAvatarUrl: qaAvatarUrl,
 	}
 	err = ybCommunityQuestionComment.Create()
 	if err != nil {

+ 6 - 1
models/tables/wx_user/query.go

@@ -55,4 +55,9 @@ func GetOpenIdList() (items []*OpenIdList, err error) {
 
 	err = global.DEFAULT_MYSQL.Raw(sql).Scan(&items).Error
 	return
-}
+}
+
+func ModifyQaAvatarUrl(qaAvatarUrl string, userId uint64) (err error) {
+	err = global.DEFAULT_MYSQL.Model(WxUser{}).Where("user_id=?", userId).Update("qa_avatar_url", qaAvatarUrl).Error
+	return err
+}

+ 2 - 1
models/tables/wx_user/wx_user.go

@@ -7,7 +7,7 @@ import (
 // WxUser 联系人表
 type WxUser struct {
 	UserID              uint64    `gorm:"primaryKey;column:user_id;type:bigint(20) unsigned;not null" json:"userId"` // 用户id
-	OpenID              string    `gorm:"index:open_id;column:open_id;type:varchar(32)" json:"openId"`          // open_id
+	OpenID              string    `gorm:"index:open_id;column:open_id;type:varchar(32)" json:"openId"`               // open_id
 	UnionID             string    `gorm:"column:union_id;type:varchar(64)" json:"unionId"`
 	Subscribe           int8      `gorm:"column:subscribe;type:tinyint(1)" json:"subscribe"`                                                 // 是否关注
 	CompanyID           int64     `gorm:"index:inx_company_id;column:company_id;type:bigint(20)" json:"companyId"`                           // 客户id
@@ -56,6 +56,7 @@ type WxUser struct {
 	OutboundMobile      string    `gorm:"index:outbound_mobile;column:outbound_mobile;type:varchar(30);default:''" json:"outboundMobile"` // 外呼手机号
 	OutboundCountryCode string    `gorm:"column:outbound_country_code;type:varchar(10);default:''" json:"outboundCountryCode"`            // 外呼手机号区号
 	IsMsgOutboundMobile int8      `gorm:"column:is_msg_outbound_mobile;type:tinyint(1);not null;default:0" json:"isMsgOutboundMobile"`    // 是否弹窗过绑定过外呼手机号
+	QaAvatarUrl         string    `gorm:"column:qa_avatar_url;type:varchar(255);not null;default:''" json:"qaAvatarUrl"`   // 问答社区头像
 }
 
 // TableName get sql table name.获取数据库表名

+ 10 - 0
models/tables/yb_community_question_comment/query.go

@@ -117,3 +117,13 @@ func GetLastMyListByCommunityQuestionIds(userId uint64, communityQuestionIds []u
 		Find(&items).Error
 	return
 }
+
+type UserAvatarRandom struct {
+	AvatarUrl string
+}
+
+func GetUserAvatarRandom() (item *UserAvatarRandom, err error) {
+	sql := ` select * from user_avatar_random order by rand() limit 1 `
+	err = global.DEFAULT_MYSQL.Raw(sql).Scan(&item).Error
+	return
+}

+ 1 - 0
models/tables/yb_community_question_comment/yb_community_question_comment.go

@@ -23,6 +23,7 @@ type YbCommunityQuestionComment struct {
 	HotTime                    time.Time `gorm:"column:hot_time;type:datetime" json:"hotTime"`                                                     // 设置精选的时间
 	ModifyTime                 time.Time `gorm:"column:modify_time;type:datetime;not null;default:CURRENT_TIMESTAMP" json:"modifyTime"`            // 修改时间
 	CreateTime                 time.Time `gorm:"column:create_time;type:datetime;not null;default:CURRENT_TIMESTAMP" json:"createTime"`            // 创建时间
+	QaAvatarUrl                string    `gorm:"column:qa_avatar_url;type:varchar(255)" json:"qaAvatarUrl"`                                        // 头像
 }
 
 // TableName get sql table name.获取数据库表名