|
@@ -10,11 +10,15 @@ import (
|
|
|
"hongze/hongze_yb/models/tables/company"
|
|
|
"hongze/hongze_yb/models/tables/company_product"
|
|
|
"hongze/hongze_yb/models/tables/research_group"
|
|
|
- "hongze/hongze_yb/models/tables/user_record"
|
|
|
+ "hongze/hongze_yb/models/tables/research_group_relation"
|
|
|
+ "hongze/hongze_yb/models/tables/research_variety_tag_relation"
|
|
|
+ "hongze/hongze_yb/models/tables/variety_classify"
|
|
|
+ "hongze/hongze_yb/models/tables/variety_tag"
|
|
|
"hongze/hongze_yb/models/tables/wx_user"
|
|
|
"hongze/hongze_yb/models/tables/yb_community_audio_listen_log"
|
|
|
"hongze/hongze_yb/models/tables/yb_community_question"
|
|
|
"hongze/hongze_yb/models/tables/yb_community_question_audio"
|
|
|
+ "hongze/hongze_yb/models/tables/yb_community_question_process"
|
|
|
"hongze/hongze_yb/services/alarm_msg"
|
|
|
"hongze/hongze_yb/services/company_approval_message"
|
|
|
"hongze/hongze_yb/services/user"
|
|
@@ -49,6 +53,10 @@ func GetQuestionList(pageIndex, pageSize, onlyMine, varietyTagId, replyStatus, g
|
|
|
} else if replyStatus == 0 { //分配给研究员或者研究员提问的所以问题
|
|
|
condition += " and (replier_user_id=? or user_id=?)"
|
|
|
pars = append(pars, userInfo.UserID, userInfo.UserID)
|
|
|
+ } else if replyStatus == 5 {
|
|
|
+ // 已终止状态
|
|
|
+ condition += " and replier_user_id=? and reply_status = 4"
|
|
|
+ pars = append(pars, userInfo.UserID)
|
|
|
}
|
|
|
} else {
|
|
|
condition += " and user_id=?"
|
|
@@ -140,7 +148,8 @@ func GetQuestionList(pageIndex, pageSize, onlyMine, varietyTagId, replyStatus, g
|
|
|
ReplyTime: v.ReplyTime.Format(utils.FormatDateTime),
|
|
|
//AuthOk: authOk,
|
|
|
//PermissionInfo: permissionInfo,
|
|
|
- AudioList: audios,
|
|
|
+ AudioList: audios,
|
|
|
+ StopReason: v.StopReason,
|
|
|
}
|
|
|
if item.IsRead == 0 && item.UserId == userId {
|
|
|
item.IsTop = 1
|
|
@@ -195,6 +204,7 @@ func GetQuestionDetail(questionId int, userInfo user.UserInfo) (item *response.C
|
|
|
ReplierRealName: detail.ReplierRealName,
|
|
|
ReplierRank: replierRank,
|
|
|
ReplierAvatar: detail.ReplierAvatar,
|
|
|
+ ReplierUserID: detail.ReplierUserID,
|
|
|
VarietyTagId: detail.VarietyTagID,
|
|
|
VarietyTagName: detail.VarietyTagName,
|
|
|
ResearchGroupSecondId: detail.ResearchGroupSecondID,
|
|
@@ -213,33 +223,78 @@ func GetQuestionDetail(questionId int, userInfo user.UserInfo) (item *response.C
|
|
|
}
|
|
|
|
|
|
// CreateQuestion 新增问答
|
|
|
-func CreateQuestion(userId int, mobile, realName, content string) (err error) {
|
|
|
- // 获取用户公众号openid, 获取不到则置空
|
|
|
- userRecord, e := user_record.GetByUserId(userId, utils.USER_RECORD_PLATFORM_RDDP)
|
|
|
- if e != nil && e != utils.ErrNoRow {
|
|
|
- err = errors.New("获取用户公众号openid失败 Err:" + e.Error())
|
|
|
+func CreateQuestion(userId, varietyClassifyId, varietyTagId int, mobile, realName, content string) (err error) {
|
|
|
+ // 获取分类
|
|
|
+ classifyItem, e := variety_classify.GetVarietyClassifyById(varietyClassifyId)
|
|
|
+ if e != nil {
|
|
|
+ err = errors.New("获取问答标签分类失败 Err:" + e.Error())
|
|
|
return
|
|
|
}
|
|
|
- openid := ""
|
|
|
- if userRecord != nil {
|
|
|
- openid = userRecord.OpenID
|
|
|
+
|
|
|
+ // 获取标签
|
|
|
+ tagItem, e := variety_tag.GetVarietyTagById(varietyTagId)
|
|
|
+ if e != nil {
|
|
|
+ err = errors.New("获取问答标签失败 Err:" + e.Error())
|
|
|
+ return
|
|
|
}
|
|
|
+
|
|
|
+ // 获取标签对应的研究方向分组-研究员信息
|
|
|
+ researcher, e := GetFirstResearcherByVarietyTagId(tagItem.VarietyTagID)
|
|
|
+ if e != nil {
|
|
|
+ err = errors.New("获取标签对应研究员信息失败 Err:" + e.Error())
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ nowTime := time.Now().Local()
|
|
|
item := &yb_community_question.YbCommunityQuestion{
|
|
|
- UserID: userId,
|
|
|
- UserOpenid: openid,
|
|
|
- Mobile: mobile,
|
|
|
- RealName: realName,
|
|
|
- QuestionContent: content,
|
|
|
- ReplyStatus: 1,
|
|
|
- IsRead: 1,
|
|
|
- ReplierIsRead: 1,
|
|
|
+ UserID: userId,
|
|
|
+ Mobile: mobile,
|
|
|
+ RealName: realName,
|
|
|
+ QuestionContent: content,
|
|
|
+ ReplyStatus: 2,
|
|
|
+ IsRead: 1,
|
|
|
+ ReplierIsRead: 0,
|
|
|
+ MsgSendStatus: 1,
|
|
|
+ ReplierUserID: researcher.UserId,
|
|
|
+ ReplierAdminID: researcher.AdminId,
|
|
|
+ ReplierRealName: researcher.AdminName,
|
|
|
+ ResearchGroupFirstID: classifyItem.VarietyClassifyID,
|
|
|
+ ResearchGroupFirstName: classifyItem.ClassifyName,
|
|
|
+ ResearchGroupSecondID: tagItem.VarietyTagID,
|
|
|
+ ResearchGroupSecondName: tagItem.TagName,
|
|
|
+ VarietyTagID: tagItem.VarietyTagID,
|
|
|
+ VarietyTagName: tagItem.TagName,
|
|
|
+ CreateTime: nowTime,
|
|
|
}
|
|
|
if e := item.Create(); e != nil {
|
|
|
err = errors.New("新增问题失败 Err:" + e.Error())
|
|
|
+ return
|
|
|
}
|
|
|
|
|
|
- // 新增问答后,消息通知管理员
|
|
|
- go messageToAdmin(userId, item)
|
|
|
+ // 新增问答流程
|
|
|
+ go func() {
|
|
|
+ pro := new(yb_community_question_process.YbCommunityQuestionProcess)
|
|
|
+ pro.CommunityQuestionID = item.CommunityQuestionID
|
|
|
+ pro.ReplierUserID = researcher.UserId
|
|
|
+ pro.ReplierAdminID = researcher.AdminId
|
|
|
+ pro.ReplierAdminName = researcher.AdminName
|
|
|
+ pro.VarietyClassifyID = classifyItem.VarietyClassifyID
|
|
|
+ pro.VarietyTagID = tagItem.VarietyTagID
|
|
|
+ pro.Remark = fmt.Sprintf("自动分配问题给研究员%s", researcher.AdminName)
|
|
|
+ pro.ProcessType = yb_community_question_process.ProcessTypeDistribute
|
|
|
+ pro.CreateTime = nowTime
|
|
|
+ if e = pro.Create(); e != nil {
|
|
|
+ return
|
|
|
+ }
|
|
|
+ }()
|
|
|
+
|
|
|
+ // 推送待回复模板消息给研究员
|
|
|
+ go func() {
|
|
|
+ _ = wechat.SendQuestionToResearcher(item.CommunityQuestionID, researcher.OpenId, item.QuestionContent, "")
|
|
|
+ }()
|
|
|
+
|
|
|
+ // 暂不推送消息给管理员了(其实就是沛总=_=!)
|
|
|
+ //go messageToAdmin(userId, item)
|
|
|
return
|
|
|
}
|
|
|
|
|
@@ -270,7 +325,7 @@ func ReplyUserQuestion(replierId, questionId int, audios []*request.ReplyReqAudi
|
|
|
updateCols := make([]string, 0)
|
|
|
updateCols = append(updateCols, "reply_status", "reply_time", "modify_time", "msg_send_status", "is_read")
|
|
|
nowTime := time.Now().Local()
|
|
|
- item.ReplyStatus = 3
|
|
|
+ item.ReplyStatus = yb_community_question.ReplyStatusDone
|
|
|
item.ReplyTime = nowTime
|
|
|
item.ModifyTime = nowTime
|
|
|
item.MsgSendStatus = 2
|
|
@@ -356,7 +411,7 @@ func GetQuestionListTotal(userInfo user.UserInfo) (resp *response.CommunityQuest
|
|
|
return
|
|
|
}
|
|
|
resp = new(response.CommunityQuestionListTotal)
|
|
|
- var distribute, wait, replied, total int
|
|
|
+ var distribute, wait, replied, stop, total int
|
|
|
for _, v := range countList {
|
|
|
total += v.Total
|
|
|
if isResearcher {
|
|
@@ -371,6 +426,9 @@ func GetQuestionListTotal(userInfo user.UserInfo) (resp *response.CommunityQuest
|
|
|
if v.ReplyStatus == 3 {
|
|
|
replied += v.Total
|
|
|
}
|
|
|
+ if v.ReplyStatus == yb_community_question.ReplyStatusStop {
|
|
|
+ stop += v.Total
|
|
|
+ }
|
|
|
} else {
|
|
|
if v.ReplyStatus == 1 || v.ReplyStatus == 2 { //未分配和未回答的数量
|
|
|
wait += v.Total
|
|
@@ -386,6 +444,7 @@ func GetQuestionListTotal(userInfo user.UserInfo) (resp *response.CommunityQuest
|
|
|
resp.Wait = wait
|
|
|
resp.Replied = replied
|
|
|
resp.Total = total
|
|
|
+ resp.Stop = stop
|
|
|
|
|
|
return
|
|
|
}
|
|
@@ -446,6 +505,24 @@ func GetResearchGroupTree() (respList []*response.ResearchGroupItem, err error)
|
|
|
if len(firstList) == 0 {
|
|
|
return
|
|
|
}
|
|
|
+ // 匹配成员
|
|
|
+ relationList, e := research_group_relation.GetResearchGroupRelationList()
|
|
|
+ if e != nil {
|
|
|
+ err = errors.New("获取研究方向关系失败, Err:" + e.Error())
|
|
|
+ return
|
|
|
+ }
|
|
|
+ for _, v := range secondList {
|
|
|
+ members := make([]*response.ResearchGroupMember, 0)
|
|
|
+ for _, r := range relationList {
|
|
|
+ if v.ResearchGroupId == r.ResearchGroupId {
|
|
|
+ members = append(members, &response.ResearchGroupMember{
|
|
|
+ AdminId: r.AdminId,
|
|
|
+ AdminName: r.AdminName,
|
|
|
+ })
|
|
|
+ }
|
|
|
+ }
|
|
|
+ v.Members = members
|
|
|
+ }
|
|
|
// 匹配子分类
|
|
|
for _, p := range firstList {
|
|
|
children := make([]*response.ResearchGroupItem, 0)
|
|
@@ -598,3 +675,180 @@ func wxMessageToAdmin(adminInfo admin.Admin, ybCommunityQuestion *yb_community_q
|
|
|
err = wechat.SendQuestionToAdmin(ybCommunityQuestion.CommunityQuestionID, int(adminInfo.AdminID), adminInfo.OpenId, ybCommunityQuestion.QuestionContent)
|
|
|
return
|
|
|
}
|
|
|
+
|
|
|
+// GetFirstResearcherByVarietyTagId 通过品种标签ID获取首位研究员admin信息及wx_user信息
|
|
|
+func GetFirstResearcherByVarietyTagId(tagId int) (researcher *admin.ResearcherAdminAndUser, err error) {
|
|
|
+ researcher = new(admin.ResearcherAdminAndUser)
|
|
|
+
|
|
|
+ // 获取标签研究员关系组
|
|
|
+ relationList, e := research_variety_tag_relation.GetResearchVarietyTagRelationList()
|
|
|
+ if e != nil {
|
|
|
+ err = errors.New("获取研究员分组失败, Err: " + e.Error())
|
|
|
+ return
|
|
|
+ }
|
|
|
+ if len(relationList) == 0 {
|
|
|
+ err = errors.New("获取研究员分组有误")
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ // 从当前组取出有效的研究员信息
|
|
|
+ for i := range relationList {
|
|
|
+ if relationList[i].VarietyTagId == tagId {
|
|
|
+ item, e := admin.GetResearcherAdminAndWxUserByAdminId(relationList[i].AdminId)
|
|
|
+ if e != nil && e != utils.ErrNoRow {
|
|
|
+ err = errors.New("获取研究员成员信息失败, Err: " + e.Error())
|
|
|
+ return
|
|
|
+ }
|
|
|
+ if item != nil && item.UserId > 0 && item.AdminId > 0 && item.OpenId != "" {
|
|
|
+ researcher = item
|
|
|
+ break
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ // 未在当前组找到有效的研究员信息, 去其他组找
|
|
|
+ if researcher.UserId == 0 || researcher.AdminId == 0 || researcher.OpenId == "" {
|
|
|
+ for i := range relationList {
|
|
|
+ if relationList[i].VarietyTagId != tagId {
|
|
|
+ item, e := admin.GetResearcherAdminAndWxUserByAdminId(relationList[i].AdminId)
|
|
|
+ if e != nil && e != utils.ErrNoRow {
|
|
|
+ err = errors.New("获取其他组研究员成员信息失败, Err: " + e.Error())
|
|
|
+ return
|
|
|
+ }
|
|
|
+ if item != nil && item.UserId > 0 && item.AdminId > 0 && item.OpenId != "" {
|
|
|
+ researcher = item
|
|
|
+ break
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ // 无有效研究员
|
|
|
+ if researcher.UserId == 0 || researcher.AdminId == 0 || researcher.OpenId == "" {
|
|
|
+ err = errors.New("无有效研究员可分配")
|
|
|
+ }
|
|
|
+ return
|
|
|
+}
|
|
|
+
|
|
|
+// TransferQuestion 转移问答
|
|
|
+func TransferQuestion(questionId, userId, userAdminId, varietyClassifyId, varietyTagId, adminId int, userAdminName string) (errMsg string, err error) {
|
|
|
+ errMsg = "操作失败"
|
|
|
+ item, e := yb_community_question.GetItemById(questionId)
|
|
|
+ if e != nil {
|
|
|
+ err = errors.New("获取提问信息失败 Err:" + e.Error())
|
|
|
+ return
|
|
|
+ }
|
|
|
+ if item.ReplyStatus != yb_community_question.ReplyStatusWait {
|
|
|
+ errMsg = "当前状态不可转移"
|
|
|
+ err = errors.New("回复状态有误")
|
|
|
+ return
|
|
|
+ }
|
|
|
+ if item.ReplierUserID != userId {
|
|
|
+ errMsg = "无权操作"
|
|
|
+ err = errors.New(fmt.Sprintf("回复人与分配人不匹配, 当前回复人ID: %d, 分配的回复人ID: %d", userId, item.ReplierUserID))
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ // 获取分类
|
|
|
+ classifyItem, e := variety_classify.GetVarietyClassifyById(varietyClassifyId)
|
|
|
+ if e != nil {
|
|
|
+ err = errors.New("获取问答标签分类失败 Err:" + e.Error())
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ // 获取标签
|
|
|
+ tagItem, e := variety_tag.GetVarietyTagById(varietyTagId)
|
|
|
+ if e != nil {
|
|
|
+ err = errors.New("获取问答标签失败 Err:" + e.Error())
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ // 获取研究员信息失败
|
|
|
+ researcher, e := admin.GetResearcherAdminAndWxUserByAdminId(adminId)
|
|
|
+ if e != nil {
|
|
|
+ errMsg = "该研究员未关注公众号或无法正确接收模板消息"
|
|
|
+ err = errors.New("获取研究员信息失败 Err:" + e.Error())
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ // 更新问答
|
|
|
+ nowTime := time.Now().Local()
|
|
|
+ updateCols := []string{
|
|
|
+ "ReplierIsRead", "ReplierUserID", "ReplierAdminID", "ReplierRealName", "ResearchGroupFirstID", "ResearchGroupFirstName",
|
|
|
+ "ResearchGroupSecondID", "ResearchGroupSecondName", "VarietyTagID", "VarietyTagName", "ModifyTime",
|
|
|
+ }
|
|
|
+ item.ReplierIsRead = 0
|
|
|
+ item.ReplierUserID = researcher.UserId
|
|
|
+ item.ReplierAdminID = researcher.AdminId
|
|
|
+ item.ReplierRealName = researcher.AdminName
|
|
|
+ item.ResearchGroupFirstID = classifyItem.VarietyClassifyID
|
|
|
+ item.ResearchGroupFirstName = classifyItem.ClassifyName
|
|
|
+ item.ResearchGroupSecondID = tagItem.VarietyTagID
|
|
|
+ item.ResearchGroupSecondName = tagItem.TagName
|
|
|
+ item.VarietyTagID = tagItem.VarietyTagID
|
|
|
+ item.VarietyTagName = tagItem.TagName
|
|
|
+ item.ModifyTime = nowTime
|
|
|
+ if e = item.Update(updateCols); e != nil {
|
|
|
+ err = errors.New("更新问答失败 Err:" + e.Error())
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ // 新增问答流程
|
|
|
+ go func() {
|
|
|
+ pro := new(yb_community_question_process.YbCommunityQuestionProcess)
|
|
|
+ pro.CommunityQuestionID = item.CommunityQuestionID
|
|
|
+ pro.TransferUserID = userId
|
|
|
+ pro.TransferAdminID = userAdminId
|
|
|
+ pro.TransferAdminName = userAdminName
|
|
|
+ pro.ReplierUserID = researcher.UserId
|
|
|
+ pro.ReplierAdminID = researcher.AdminId
|
|
|
+ pro.ReplierAdminName = researcher.AdminName
|
|
|
+ pro.VarietyClassifyID = classifyItem.VarietyClassifyID
|
|
|
+ pro.VarietyTagID = tagItem.VarietyTagID
|
|
|
+ pro.Remark = fmt.Sprintf("转至%s", researcher.AdminName)
|
|
|
+ pro.ProcessType = yb_community_question_process.ProcessTypeTransfer
|
|
|
+ pro.CreateTime = nowTime
|
|
|
+ if e = pro.Create(); e != nil {
|
|
|
+ return
|
|
|
+ }
|
|
|
+ }()
|
|
|
+
|
|
|
+ // 推送转移模板消息给研究员
|
|
|
+ go func() {
|
|
|
+ remark := fmt.Sprintf("%s移交了新的问答给您, 请点击详情尽快处理", userAdminName)
|
|
|
+ _ = wechat.SendQuestionToResearcher(item.CommunityQuestionID, researcher.OpenId, item.QuestionContent, remark)
|
|
|
+ }()
|
|
|
+ return
|
|
|
+}
|
|
|
+
|
|
|
+// StopQuestion 终止问答
|
|
|
+func StopQuestion(questionId, userId int, reason string) (errMsg string, err error) {
|
|
|
+ errMsg = "操作失败"
|
|
|
+ item, e := yb_community_question.GetItemById(questionId)
|
|
|
+ if e != nil {
|
|
|
+ err = errors.New("获取提问信息失败 Err:" + e.Error())
|
|
|
+ return
|
|
|
+ }
|
|
|
+ if item.ReplyStatus != yb_community_question.ReplyStatusWait {
|
|
|
+ errMsg = "当前状态不可终止"
|
|
|
+ err = errors.New("回复状态有误")
|
|
|
+ return
|
|
|
+ }
|
|
|
+ if item.ReplierUserID != userId {
|
|
|
+ errMsg = "无权操作"
|
|
|
+ err = errors.New(fmt.Sprintf("回复人与分配人不匹配, 当前回复人ID: %d, 分配的回复人ID: %d", userId, item.ReplierUserID))
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ // 更新问答
|
|
|
+ nowTime := time.Now().Local()
|
|
|
+ updateCols := []string{
|
|
|
+ "ReplyStatus", "StopReason", "ModifyTime",
|
|
|
+ }
|
|
|
+ item.ReplyStatus = yb_community_question.ReplyStatusStop
|
|
|
+ item.StopReason = reason
|
|
|
+ item.ModifyTime = nowTime
|
|
|
+ if e = item.Update(updateCols); e != nil {
|
|
|
+ err = errors.New("更新问答失败 Err:" + e.Error())
|
|
|
+ return
|
|
|
+ }
|
|
|
+ return
|
|
|
+}
|