community_question.go 29 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084
  1. package yb
  2. import (
  3. "encoding/json"
  4. "fmt"
  5. "github.com/rdlucklib/rdluck_tools/paging"
  6. "hongze/hz_crm_api/controllers"
  7. "hongze/hz_crm_api/models"
  8. "hongze/hz_crm_api/models/company"
  9. ybModels "hongze/hz_crm_api/models/yb"
  10. "hongze/hz_crm_api/models/yb/request"
  11. ybResp "hongze/hz_crm_api/models/yb/response"
  12. "hongze/hz_crm_api/services/yb"
  13. "hongze/hz_crm_api/utils"
  14. "strconv"
  15. "strings"
  16. )
  17. type CommunityQuestionController struct {
  18. controllers.BaseAuthController
  19. }
  20. // QuestionList
  21. // @Title 获取问答列表
  22. // @Description 获取问答列表
  23. // @Param ReplyStatus query int false "提问状态 1-待分配 2-待回答 3-已回答"
  24. // @Param ReplierIds query string false "回复人ID,多个用英文逗号分割"
  25. // @Param SortParam query string false "排序字段参数,用来排序的字段, 枚举值:'ClickNum':点击量"
  26. // @Param SortType query string true "如何排序,是正序还是倒序,枚举值:`asc 正序`,`desc 倒叙`"
  27. // @Success 200 {object} response.CommunityQuestionListResp
  28. // @router /community/question/list [get]
  29. func (this *CommunityQuestionController) QuestionList() {
  30. br := new(models.BaseResponse).Init()
  31. br.IsSendEmail = false
  32. defer func() {
  33. this.Data["json"] = br
  34. this.ServeJSON()
  35. }()
  36. sysUser := this.SysUser
  37. if sysUser == nil {
  38. br.Msg = "请登录"
  39. br.ErrMsg = "请登录,SysUser Is Empty"
  40. br.Ret = 408
  41. return
  42. }
  43. // 权限校验
  44. msg, err := yb.CheckCommunityQuestionPermission(sysUser.AdminId)
  45. if err != nil {
  46. br.Msg = msg
  47. br.ErrMsg = err.Error()
  48. return
  49. }
  50. condition := ""
  51. pars := make([]interface{}, 0)
  52. replyStatus, _ := this.GetInt("ReplyStatus", 0)
  53. if replyStatus > 0 {
  54. condition += ` AND q.reply_status = ?`
  55. pars = append(pars, replyStatus)
  56. }
  57. replierIds := this.GetString("ReplierIds", "")
  58. if replierIds != "" {
  59. condition += ` AND q.replier_admin_id IN (` + replierIds + `)`
  60. }
  61. // 排序相关
  62. sortParam := this.GetString("SortParam")
  63. sortType := this.GetString("SortType")
  64. orderStr := ""
  65. if sortType != "" && strings.ToLower(sortType) != "desc" && strings.ToLower(sortType) != "asc" {
  66. br.Msg = "请输入正确的排序类型"
  67. return
  68. }
  69. if sortParam == "ClickNum" {
  70. orderStr = " ORDER BY l.click_num"
  71. if sortType != "" {
  72. orderStr += " " + sortType
  73. } else {
  74. orderStr += " DESC"
  75. }
  76. orderStr += ", q.create_time DESC"
  77. }
  78. var startSize int
  79. pageSize, _ := this.GetInt("PageSize")
  80. currentIndex, _ := this.GetInt("CurrentIndex")
  81. if pageSize <= 0 {
  82. pageSize = utils.PageSize20
  83. }
  84. if currentIndex <= 0 {
  85. currentIndex = 1
  86. }
  87. startSize = paging.StartIndex(currentIndex, pageSize)
  88. total, resp, err := yb.GetQuestionList(condition, pars, orderStr, startSize, pageSize)
  89. if err != nil {
  90. br.Msg = "获取问答列表失败"
  91. br.ErrMsg = "QuestionList ErrMsg:" + err.Error()
  92. return
  93. }
  94. page := paging.GetPaging(currentIndex, pageSize, total)
  95. resp.Paging = page
  96. br.Ret = 200
  97. br.Success = true
  98. br.Msg = "获取成功"
  99. br.Data = resp
  100. }
  101. // QuestionDistribute
  102. // @Title 分配回复人
  103. // @Description 获取问答列表
  104. // @Param ReplyStatus query int false "提问状态 1-待分配 2-待回答 3-已回答"
  105. // @Param ReplierIds query string false "回复人ID,多个用英文逗号分割"
  106. // @Success 200 string "操作成功"
  107. // @router /community/question/distribute [post]
  108. func (this *CommunityQuestionController) QuestionDistribute() {
  109. br := new(models.BaseResponse).Init()
  110. br.IsSendEmail = false
  111. defer func() {
  112. this.Data["json"] = br
  113. this.ServeJSON()
  114. }()
  115. sysUser := this.SysUser
  116. if sysUser == nil {
  117. br.Msg = "请登录"
  118. br.ErrMsg = "请登录,SysUser Is Empty"
  119. br.Ret = 408
  120. return
  121. }
  122. // 权限校验
  123. msg, err := yb.CheckCommunityQuestionPermission(sysUser.AdminId)
  124. if err != nil {
  125. br.Msg = msg
  126. br.ErrMsg = err.Error()
  127. return
  128. }
  129. var req request.QuestionDistributeReq
  130. if err := json.Unmarshal(this.Ctx.Input.RequestBody, &req); err != nil {
  131. br.Msg = "参数解析异常!"
  132. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  133. return
  134. }
  135. errMsg, err := yb.DistributeQuestion(req.QuestionId, req.AdminId, req.ResearchGroupFirstId, req.ResearchGroupSecondId, sysUser.AdminId)
  136. if err != nil {
  137. br.Msg = errMsg
  138. br.ErrMsg = "DistributeQuestion ErrMsg:" + err.Error()
  139. return
  140. }
  141. br.Ret = 200
  142. br.Success = true
  143. br.Msg = errMsg
  144. }
  145. // QuestionDelete
  146. // @Title 删除提问
  147. // @Description 删除提问
  148. // @Param QuestionId query int false "问题ID"
  149. // @Success 200 string "操作成功"
  150. // @router /community/question/delete [post]
  151. func (this *CommunityQuestionController) QuestionDelete() {
  152. br := new(models.BaseResponse).Init()
  153. br.IsSendEmail = false
  154. defer func() {
  155. this.Data["json"] = br
  156. this.ServeJSON()
  157. }()
  158. sysUser := this.SysUser
  159. if sysUser == nil {
  160. br.Msg = "请登录"
  161. br.ErrMsg = "请登录,SysUser Is Empty"
  162. br.Ret = 408
  163. return
  164. }
  165. // 权限校验
  166. msg, err := yb.CheckCommunityQuestionPermission(sysUser.AdminId)
  167. if err != nil {
  168. br.Msg = msg
  169. br.ErrMsg = err.Error()
  170. return
  171. }
  172. var req request.QuestionDeleteReq
  173. if err := json.Unmarshal(this.Ctx.Input.RequestBody, &req); err != nil {
  174. br.Msg = "参数解析异常!"
  175. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  176. return
  177. }
  178. if err := yb.SoftDeleteQuestion(req.QuestionId); err != nil {
  179. br.Msg = "删除提问失败"
  180. br.ErrMsg = "DeleteQuestion ErrMsg:" + err.Error()
  181. return
  182. }
  183. br.Ret = 200
  184. br.Success = true
  185. br.Msg = "操作成功"
  186. }
  187. // SendTemplateMsg
  188. // @Title 推送模板消息给回复人
  189. // @Description 推送模板消息给回复人
  190. // @Param QuestionId query int false "问题ID"
  191. // @Success 200 string "操作成功"
  192. // @router /community/question/send_template_msg [post]
  193. func (this *CommunityQuestionController) SendDistributeTemplateMsg() {
  194. br := new(models.BaseResponse).Init()
  195. br.IsSendEmail = false
  196. defer func() {
  197. this.Data["json"] = br
  198. this.ServeJSON()
  199. }()
  200. sysUser := this.SysUser
  201. if sysUser == nil {
  202. br.Msg = "请登录"
  203. br.ErrMsg = "请登录,SysUser Is Empty"
  204. br.Ret = 408
  205. return
  206. }
  207. // 权限校验
  208. msg, err := yb.CheckCommunityQuestionPermission(sysUser.AdminId)
  209. if err != nil {
  210. br.Msg = msg
  211. br.ErrMsg = err.Error()
  212. return
  213. }
  214. var req request.QuestionMsgSendReq
  215. if err := json.Unmarshal(this.Ctx.Input.RequestBody, &req); err != nil {
  216. br.Msg = "参数解析异常!"
  217. br.ErrMsg = "SendDistributeTemplateMsg 参数解析异常:" + err.Error()
  218. return
  219. }
  220. errMsg, err := yb.SendMsgToReplier(req.QuestionId)
  221. if err != nil {
  222. br.Msg = errMsg
  223. br.ErrMsg = "SendDistributeTemplateMsg ErrMsg:" + err.Error()
  224. return
  225. }
  226. br.Ret = 200
  227. br.Success = true
  228. br.Msg = "操作成功"
  229. }
  230. // QuestionEdit
  231. // @Title 编辑问题
  232. // @Description 编辑问题
  233. // @Param QuestionId query int true "问题ID"
  234. // @Param QuestionContent query string true "问题内容"
  235. // @Success 200 string "操作成功"
  236. // @router /community/question/edit [post]
  237. func (this *CommunityQuestionController) QuestionEdit() {
  238. br := new(models.BaseResponse).Init()
  239. br.IsSendEmail = false
  240. defer func() {
  241. this.Data["json"] = br
  242. this.ServeJSON()
  243. }()
  244. sysUser := this.SysUser
  245. if sysUser == nil {
  246. br.Msg = "请登录"
  247. br.ErrMsg = "请登录,SysUser Is Empty"
  248. br.Ret = 408
  249. return
  250. }
  251. // 权限校验
  252. msg, err := yb.CheckCommunityQuestionPermission(sysUser.AdminId)
  253. if err != nil {
  254. br.Msg = msg
  255. br.ErrMsg = err.Error()
  256. return
  257. }
  258. var req request.QuestionEditReq
  259. if err := json.Unmarshal(this.Ctx.Input.RequestBody, &req); err != nil {
  260. br.Msg = "参数解析异常!"
  261. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  262. return
  263. }
  264. if req.QuestionId <= 0 {
  265. br.Msg = "问题ID有误"
  266. return
  267. }
  268. if req.QuestionContent == "" {
  269. br.Msg = "内容不可为空"
  270. return
  271. }
  272. contentRune := []rune(req.QuestionContent)
  273. if len(contentRune) > 28 {
  274. br.Msg = "问题字数不可超过28个字符"
  275. return
  276. }
  277. errMsg, err := yb.EditQuestion(req.QuestionId, req.QuestionContent)
  278. if err != nil {
  279. br.Msg = errMsg
  280. br.ErrMsg = "QuestionEdit ErrMsg:" + err.Error()
  281. return
  282. }
  283. br.Ret = 200
  284. br.Success = true
  285. br.Msg = "操作成功"
  286. }
  287. // QuestionClickLogList
  288. // @Title 获取点击量列表
  289. // @Description 获取点击量列表
  290. // @Param QuestionId query int false "问题ID"
  291. // @Success 200 {object} response.QuestionClickLogListResp
  292. // @router /community/question/click/logs [get]
  293. func (this *CommunityQuestionController) QuestionClickLogList() {
  294. br := new(models.BaseResponse).Init()
  295. defer func() {
  296. this.Data["json"] = br
  297. this.ServeJSON()
  298. }()
  299. sysUser := this.SysUser
  300. if sysUser == nil {
  301. br.Msg = "请登录"
  302. br.ErrMsg = "请登录,SysUser Is Empty"
  303. br.Ret = 408
  304. return
  305. }
  306. questionId, _ := this.GetInt("QuestionId")
  307. if questionId <= 0 {
  308. br.Msg = "请输入正确的提问ID"
  309. return
  310. }
  311. var startSize int
  312. pageSize, _ := this.GetInt("PageSize")
  313. currentIndex, _ := this.GetInt("CurrentIndex")
  314. if pageSize <= 0 {
  315. pageSize = utils.PageSize20
  316. }
  317. if currentIndex <= 0 {
  318. currentIndex = 1
  319. }
  320. startSize = paging.StartIndex(currentIndex, pageSize)
  321. total, resp, err := yb.GetQuestionClickLogList(questionId, startSize, pageSize)
  322. if err != nil {
  323. br.Msg = "获取问答列表失败"
  324. br.ErrMsg = "QuestionList ErrMsg:" + err.Error()
  325. return
  326. }
  327. page := paging.GetPaging(currentIndex, pageSize, int(total))
  328. resp.Paging = page
  329. br.Ret = 200
  330. br.Success = true
  331. br.Msg = "获取成功"
  332. br.Data = resp
  333. }
  334. // UserInfo
  335. // @Title 获取提问者基本信息
  336. // @Description 获取提问者基本信息
  337. // @Param UserId query int false "用户ID"
  338. // @Success 200 {object} response.CommunityQuestionListResp
  339. // @router /community/question/user [get]
  340. func (this *CommunityQuestionController) UserInfo() {
  341. br := new(models.BaseResponse).Init()
  342. defer func() {
  343. this.Data["json"] = br
  344. this.ServeJSON()
  345. }()
  346. sysUser := this.SysUser
  347. if sysUser == nil {
  348. br.Msg = "请登录"
  349. br.ErrMsg = "请登录,SysUser Is Empty"
  350. br.Ret = 408
  351. return
  352. }
  353. questionId, _ := this.GetInt("QuestionId")
  354. if questionId <= 0 {
  355. br.Msg = "请输入正确的提问ID"
  356. return
  357. }
  358. resp, err := yb.GetQuestionCompanyUser(questionId)
  359. if err != nil {
  360. br.Msg = "用户不存在或者查询出错"
  361. br.ErrMsg = "UserInfo ErrMsg:" + err.Error()
  362. return
  363. }
  364. br.Ret = 200
  365. br.Success = true
  366. br.Msg = "获取成功"
  367. br.Data = resp
  368. return
  369. }
  370. // LikeTeaseListWithQuestion
  371. // @Title 获取已被点赞/吐槽的问答列表
  372. // @Description 获取已被点赞/吐槽的问答列表
  373. // @Param SortParam query string false "排序关键词:Num"
  374. // @Param SortType query string false "排序顺序:asc、desc"
  375. // @Param DataType query string false "类型:like、tease"
  376. // @Param PageSize query string false "每页展示的记录数"
  377. // @param CurrentIndex query string false "页码"
  378. // @param Source query int false "来源:1-问答社区; 2-视频社区"
  379. // @Success 200 {object} ybResp.LikeReportListResp
  380. // @router /community/question/like_tease_question_list [get]
  381. func (this *CommunityQuestionController) LikeTeaseListWithQuestion() {
  382. br := new(models.BaseResponse).Init()
  383. defer func() {
  384. this.Data["json"] = br
  385. this.ServeJSON()
  386. }()
  387. sysUser := this.SysUser
  388. if sysUser == nil {
  389. br.Msg = "请登录"
  390. br.ErrMsg = "请登录,SysUser is Empty"
  391. br.Ret = 408
  392. return
  393. }
  394. // 来源(默认问答社区)
  395. source, _ := this.GetInt("Source")
  396. if source <= 0 {
  397. source = 1
  398. }
  399. pageSize, _ := this.GetInt("PageSize")
  400. currentIndex, _ := this.GetInt("CurrentIndex")
  401. var startSize int
  402. if pageSize <= 0 {
  403. pageSize = utils.PageSize20
  404. }
  405. if currentIndex <= 0 {
  406. currentIndex = 1
  407. }
  408. startSize = paging.StartIndex(currentIndex, pageSize)
  409. // 判断查询权限
  410. brMsg, brErrMsg := yb.CheckCommentPermission(sysUser.AdminId)
  411. if brMsg != "" {
  412. br.Msg = brMsg
  413. br.ErrMsg = brErrMsg
  414. return
  415. }
  416. // 数据类型,默认是点赞列表
  417. reqDataType := this.GetString("DataType")
  418. if reqDataType == `` {
  419. reqDataType = "like"
  420. }
  421. var opType int8 //类型. 1-点赞 2-吐槽
  422. switch reqDataType {
  423. case "like":
  424. opType = 1
  425. case "tease":
  426. opType = 2
  427. default:
  428. br.Msg = "错误的数据类型:" + reqDataType
  429. br.ErrMsg = "错误的数据类型:" + reqDataType
  430. return
  431. }
  432. //排序
  433. orderStr := ""
  434. reqSortParam := this.GetString("SortParam", "")
  435. switch reqSortParam {
  436. case "Num":
  437. orderStr = ` num `
  438. default:
  439. orderStr = ` community_question_id ` // 默认问答倒序
  440. }
  441. reqSortType := this.GetString("SortType")
  442. if reqSortType == `` {
  443. reqSortType = "desc"
  444. }
  445. orderStr = orderStr + " " + reqSortType
  446. total := 0
  447. list := make([]*ybModels.StatCommunityQuestionLikeTeaseItem, 0)
  448. // 问答社区
  449. if source == 1 {
  450. qaTotal, e := ybModels.GetYbCommunityQuestionLikeTeaseTotal(opType)
  451. if e != nil {
  452. br.Msg = "获取数据汇总数失败!"
  453. br.ErrMsg = "获取数据汇总数失败,Err:" + e.Error()
  454. return
  455. }
  456. total = int(qaTotal)
  457. qaList, e := ybModels.GetYbCommunityQuestionLikeTeaseQuestion(opType, orderStr, startSize, pageSize)
  458. if e != nil {
  459. br.Msg = "获取问答数据列表失败!"
  460. br.ErrMsg = "获取问答数据列表失败,Err:" + e.Error()
  461. return
  462. }
  463. list = qaList
  464. }
  465. // 视频社区
  466. if source == 2 {
  467. vdTotal, e := ybModels.GetYbCommunityVideoLikeTeaseTotal(opType)
  468. if e != nil {
  469. br.Msg = "获取视频数据汇总数失败!"
  470. br.ErrMsg = "获取视频数据汇总数失败,Err:" + e.Error()
  471. return
  472. }
  473. total = int(vdTotal)
  474. vdList, e := ybModels.GetYbCommunityVideoLikeTeaseList(opType, orderStr, startSize, pageSize)
  475. if e != nil {
  476. br.Msg = "获取视频数据列表失败!"
  477. br.ErrMsg = "获取视频数据列表失败,Err:" + e.Error()
  478. return
  479. }
  480. // 标签分类及名称
  481. tagList, e := models.GetVarietyTagList()
  482. if e != nil {
  483. br.Msg = "获取视频标签列表失败"
  484. br.ErrMsg = "获取视频标签列表失败, Err:" + e.Error()
  485. return
  486. }
  487. tagMap := make(map[int]*models.VarietyTag, 0)
  488. for i := range tagList {
  489. tagMap[tagList[i].VarietyTagId] = tagList[i]
  490. }
  491. for i := range vdList {
  492. t := tagMap[vdList[i].VarietyTagId]
  493. if t != nil {
  494. vdList[i].VarietyClassifyTag = fmt.Sprintf("%s-%s", t.VarietyClassifyName, t.TagName)
  495. }
  496. }
  497. list = vdList
  498. }
  499. // 线上路演
  500. if source == 3 {
  501. rvTotal, e := ybModels.GetYbRoadVideoLikeTeaseTotal(opType)
  502. if e != nil {
  503. br.Msg = "获取线上路演数据汇总数失败!"
  504. br.ErrMsg = "获取线上路演数据汇总数失败,Err:" + e.Error()
  505. return
  506. }
  507. total = int(rvTotal)
  508. rvList, e := ybModels.GetYbRoadVideoLikeTeaseList(opType, orderStr, startSize, pageSize)
  509. if e != nil {
  510. br.Msg = "获取线上路演点赞吐槽列表失败!"
  511. br.ErrMsg = "获取线上路演点赞吐槽列表失败,Err:" + e.Error()
  512. return
  513. }
  514. // 线上路演品种
  515. cpList, e := models.GetChartPermissionList()
  516. if e != nil {
  517. br.Msg = "获取路演视频品种失败!"
  518. br.ErrMsg = "获取路演视频品种失败,Err:" + e.Error()
  519. return
  520. }
  521. cpMap := make(map[int]string, 0)
  522. for i := range cpList {
  523. cpMap[cpList[i].ChartPermissionId] = cpList[i].PermissionName
  524. }
  525. for i := range rvList {
  526. if rvList[i].VarietyClassifyTag == "" {
  527. continue
  528. }
  529. ids := utils.JoinStr2IntArr(strings.ReplaceAll(rvList[i].VarietyClassifyTag, `'`, ``), ",")
  530. if len(ids) == 0 {
  531. continue
  532. }
  533. cpArr := make([]string, 0)
  534. for s := range ids {
  535. if cpMap[ids[s]] != "" {
  536. cpArr = append(cpArr, cpMap[ids[s]])
  537. }
  538. }
  539. rvList[i].VarietyClassifyTag = strings.Join(cpArr, ",")
  540. }
  541. list = rvList
  542. }
  543. page := paging.GetPaging(currentIndex, pageSize, int(total))
  544. data := &ybResp.LikeTeaseListWithQuestionResp{
  545. List: list,
  546. Paging: page,
  547. }
  548. br.Ret = 200
  549. br.Success = true
  550. br.Msg = "操作成功"
  551. br.Data = data
  552. return
  553. }
  554. // LikeTeaseList
  555. // @Title 获取某个问答的点赞/吐槽列表
  556. // @Description 获取某个问答的点赞/吐槽列表
  557. // @Param CommunityQuestionId query string true "问答ID"
  558. // @Param DataType query string false "类型:like、tease"
  559. // @Param PageSize query string false "页码"
  560. // @param CurrentIndex query string false "每页展示的记录数"
  561. // @param Source query int false "来源:1-问答社区; 2-视频社区"
  562. // @Success 200 {object} ybResp.LikeListResp
  563. // @router /community/question/like_tease_list [get]
  564. func (this *CommunityQuestionController) LikeTeaseList() {
  565. br := new(models.BaseResponse).Init()
  566. defer func() {
  567. this.Data["json"] = br
  568. this.ServeJSON()
  569. }()
  570. sysUser := this.SysUser
  571. if sysUser == nil {
  572. br.Msg = "请登录"
  573. br.ErrMsg = "请登录,SysUser is Empty"
  574. br.Ret = 408
  575. return
  576. }
  577. // 来源(默认问答社区)
  578. source, _ := this.GetInt("Source")
  579. if source <= 0 {
  580. source = 1
  581. }
  582. pageSize, _ := this.GetInt("PageSize")
  583. currentIndex, _ := this.GetInt("CurrentIndex")
  584. var startSize int
  585. if pageSize <= 0 {
  586. pageSize = utils.PageSize20
  587. }
  588. if currentIndex <= 0 {
  589. currentIndex = 1
  590. }
  591. startSize = paging.StartIndex(currentIndex, pageSize)
  592. //判断查询权限
  593. brMsg, brErrMsg := yb.CheckCommentPermission(sysUser.AdminId)
  594. if brMsg != "" {
  595. br.Msg = brMsg
  596. br.ErrMsg = brErrMsg
  597. return
  598. }
  599. //根据搜索条件查询留言列表
  600. var (
  601. err error
  602. communityQuestionId int
  603. )
  604. reqCommunityQuestionId := this.GetString("CommunityQuestionId", "")
  605. if reqCommunityQuestionId == "" {
  606. br.Msg = "请输入问答ID"
  607. br.ErrMsg = "请输入问答ID"
  608. return
  609. }
  610. communityQuestionId, err = strconv.Atoi(reqCommunityQuestionId)
  611. if err != nil {
  612. br.Msg = "请输入问答ID"
  613. br.ErrMsg = "请输入问答ID:" + err.Error()
  614. return
  615. }
  616. // 数据类型,默认是点赞列表
  617. reqDataType := this.GetString("DataType")
  618. if reqDataType == `` {
  619. reqDataType = "like"
  620. }
  621. var opType int //类型. 1-点赞 2-吐槽
  622. switch reqDataType {
  623. case "like":
  624. opType = 1
  625. case "tease":
  626. opType = 2
  627. default:
  628. br.Msg = "错误的数据类型:" + reqDataType
  629. br.ErrMsg = "错误的数据类型:" + reqDataType
  630. return
  631. }
  632. // 获取数据列表
  633. total, list, err := ybModels.GetYbCommunityQuestionLikeTeaseQuestionListById(communityQuestionId, opType, source, startSize, pageSize)
  634. if err != nil {
  635. br.Msg = "获取点赞列表失败!"
  636. br.ErrMsg = "获取点赞列表失败,Err:" + err.Error()
  637. return
  638. }
  639. var userIds string
  640. companyIdList := make([]int, 0)
  641. for _, v := range list {
  642. userIds += "," + strconv.Itoa(int(v.UserId))
  643. }
  644. // 查询点赞/吐槽相关的用户
  645. var userOthers []*models.WxUser
  646. if len(userIds) > 0 {
  647. userOthers, err = models.GetWxUserListByUserIds(strings.Trim(userIds, ","))
  648. if err != nil {
  649. br.Msg = "查询用户出错"
  650. br.ErrMsg = "查询用户出错,Err:" + err.Error()
  651. return
  652. }
  653. }
  654. usersMap := make(map[uint64]*models.WxUser)
  655. companyIdMap := make(map[int]int)
  656. for _, v := range userOthers {
  657. usersMap[uint64(v.UserId)] = v
  658. if _, ok := companyIdMap[v.CompanyId]; !ok { //避免company_id重复append
  659. companyIdList = append(companyIdList, v.CompanyId)
  660. companyIdMap[v.CompanyId] = v.CompanyId
  661. }
  662. }
  663. // 查询点赞/吐槽相关用户的公司
  664. companyProductMap := make(map[int]*company.CompanyProduct)
  665. {
  666. if len(companyIdList) > 0 {
  667. var companyProductOthers []*company.CompanyProduct
  668. companyProductOthers, err = company.GetCompanyProductsByCompanyIdsAndProductId(companyIdList, 1)
  669. if err != nil {
  670. br.Msg = "查询客户出错"
  671. br.ErrMsg = "查询客户出错,Err:" + err.Error()
  672. return
  673. }
  674. for _, v := range companyProductOthers {
  675. companyProductMap[v.CompanyId] = v
  676. }
  677. }
  678. }
  679. for _, v := range list {
  680. if info, ok := usersMap[v.UserId]; ok {
  681. v.NickName = info.NickName
  682. //v.RealName = utils.DealRealName(info.RealName)
  683. v.RealName = info.RealName
  684. //客户信息
  685. if companyProductInfo, ok := companyProductMap[info.CompanyId]; ok {
  686. v.CompanyId = companyProductInfo.CompanyId
  687. v.CompanyName = companyProductInfo.CompanyName
  688. v.CompanyFiccStatus = companyProductInfo.Status
  689. }
  690. }
  691. }
  692. page := paging.GetPaging(currentIndex, pageSize, int(total))
  693. resp := ybResp.LikeTeaseListListResp{
  694. List: list,
  695. Paging: page,
  696. }
  697. br.Ret = 200
  698. br.Success = true
  699. br.Msg = "获取成功"
  700. br.Data = resp
  701. return
  702. }
  703. // CommentList
  704. // @Title 获取社区问答评论列表
  705. // @Description 获取社区问答评论列表
  706. // @Param CommunityQuestionId query string true "问答ID"
  707. // @Param HotStatus query string false "精选状态,全部:-1;未精选:0;精选:1"
  708. // @Param PageSize query string false "页码"
  709. // @param CurrentIndex query string false "每页展示的记录数"
  710. // @Success 200 {object} ybResp.LikeListResp
  711. // @router /community/question/comment/list [get]
  712. func (this *CommunityQuestionController) CommentList() {
  713. br := new(models.BaseResponse).Init()
  714. defer func() {
  715. this.Data["json"] = br
  716. this.ServeJSON()
  717. }()
  718. sysUser := this.SysUser
  719. if sysUser == nil {
  720. br.Msg = "请登录"
  721. br.ErrMsg = "请登录,SysUser is Empty"
  722. br.Ret = 408
  723. return
  724. }
  725. pageSize, _ := this.GetInt("PageSize")
  726. currentIndex, _ := this.GetInt("CurrentIndex")
  727. var startSize int
  728. if pageSize <= 0 {
  729. pageSize = utils.PageSize20
  730. }
  731. if currentIndex <= 0 {
  732. currentIndex = 1
  733. }
  734. startSize = paging.StartIndex(currentIndex, pageSize)
  735. //// 判断查询权限
  736. //brMsg, brErrMsg := yb.CheckCommentPermission(sysUser.AdminId)
  737. //if brMsg != "" {
  738. // br.Msg = brMsg
  739. // br.ErrMsg = brErrMsg
  740. // return
  741. //}
  742. condition := ""
  743. pars := make([]interface{}, 0)
  744. //精选状态
  745. hotStatus := this.GetString("HotStatus", "") //精选状态,全部:-1;未精选:0;精选:1
  746. switch hotStatus {
  747. case "0":
  748. condition += ` AND is_hot = ? `
  749. pars = append(pars, 0)
  750. //is = 1
  751. case "1":
  752. condition += ` AND is_hot = ? `
  753. pars = append(pars, 1)
  754. }
  755. // 获取数据列表
  756. total, list, err := ybModels.GetCommunityQuestionCommentList(condition, pars, startSize, pageSize)
  757. if err != nil {
  758. br.Msg = "获取点赞列表失败!"
  759. br.ErrMsg = "获取点赞列表失败,Err:" + err.Error()
  760. return
  761. }
  762. var userIds string
  763. companyIdList := make([]int, 0)
  764. for _, v := range list {
  765. userIds += "," + strconv.Itoa(int(v.UserId))
  766. }
  767. // 查询点赞/吐槽相关的用户
  768. var userOthers []*models.WxUser
  769. if len(userIds) > 0 {
  770. userOthers, err = models.GetWxUserListByUserIds(strings.Trim(userIds, ","))
  771. if err != nil {
  772. br.Msg = "查询用户出错"
  773. br.ErrMsg = "查询用户出错,Err:" + err.Error()
  774. return
  775. }
  776. }
  777. usersMap := make(map[uint64]*models.WxUser)
  778. companyIdMap := make(map[int]int)
  779. for _, v := range userOthers {
  780. usersMap[uint64(v.UserId)] = v
  781. if _, ok := companyIdMap[v.CompanyId]; !ok { //避免company_id重复append
  782. companyIdList = append(companyIdList, v.CompanyId)
  783. companyIdMap[v.CompanyId] = v.CompanyId
  784. }
  785. }
  786. // 查询点赞/吐槽相关用户的公司
  787. companyProductMap := make(map[int]*company.CompanyProduct)
  788. {
  789. if len(companyIdList) > 0 {
  790. var companyProductOthers []*company.CompanyProduct
  791. companyProductOthers, err = company.GetCompanyProductsByCompanyIdsAndProductId(companyIdList, 1)
  792. if err != nil {
  793. br.Msg = "查询客户出错"
  794. br.ErrMsg = "查询客户出错,Err:" + err.Error()
  795. return
  796. }
  797. for _, v := range companyProductOthers {
  798. companyProductMap[v.CompanyId] = v
  799. }
  800. }
  801. }
  802. for _, v := range list {
  803. if info, ok := usersMap[v.UserId]; ok {
  804. v.NickName = info.NickName
  805. //v.RealName = utils.DealRealName(info.RealName)
  806. v.RealName = info.RealName
  807. //客户信息
  808. if companyProductInfo, ok := companyProductMap[info.CompanyId]; ok {
  809. v.CompanyId = companyProductInfo.CompanyId
  810. v.CompanyName = companyProductInfo.CompanyName
  811. v.CompanyFiccStatus = companyProductInfo.Status
  812. }
  813. }
  814. }
  815. page := paging.GetPaging(currentIndex, pageSize, int(total))
  816. resp := ybResp.CommunityQuestionCommentResp{
  817. List: list,
  818. Paging: page,
  819. }
  820. br.Ret = 200
  821. br.Success = true
  822. br.Msg = "获取成功"
  823. br.Data = resp
  824. return
  825. }
  826. // CommentDelete
  827. // @Title 删除评论
  828. // @Description 删除评论
  829. // @Param QuestionId query int false "问题ID"
  830. // @Success 200 string "操作成功"
  831. // @router /community/question/comment/delete [post]
  832. func (this *CommunityQuestionController) CommentDelete() {
  833. br := new(models.BaseResponse).Init()
  834. defer func() {
  835. this.Data["json"] = br
  836. this.ServeJSON()
  837. }()
  838. sysUser := this.SysUser
  839. if sysUser == nil {
  840. br.Msg = "请登录"
  841. br.ErrMsg = "请登录,SysUser is Empty"
  842. br.Ret = 408
  843. return
  844. }
  845. // 判断查询权限
  846. //brMsg, brErrMsg := yb.CheckCommentPermission(sysUser.AdminId)
  847. //if brMsg != "" {
  848. // br.Msg = brMsg
  849. // br.ErrMsg = brErrMsg
  850. // return
  851. //}
  852. var req request.QuestionCommentDeleteReq
  853. if err := json.Unmarshal(this.Ctx.Input.RequestBody, &req); err != nil {
  854. br.Msg = "参数解析异常!"
  855. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  856. return
  857. }
  858. if err, errMsg := yb.SoftDeleteQuestionComment(req.CommunityQuestionCommentId); err != nil {
  859. br.Msg = errMsg
  860. br.ErrMsg = "DeleteQuestion,Err:" + err.Error()
  861. return
  862. }
  863. br.Ret = 200
  864. br.Success = true
  865. br.Msg = "删除成功"
  866. }
  867. // CommentHot
  868. // @Title 设置/取消 问题评论精选
  869. // @Description 设置/取消 问题评论精选
  870. // @Success 200 string "操作成功"
  871. // @router /community/question/comment/hot [post]
  872. func (this *CommunityQuestionController) CommentHot() {
  873. br := new(models.BaseResponse).Init()
  874. defer func() {
  875. this.Data["json"] = br
  876. this.ServeJSON()
  877. }()
  878. sysUser := this.SysUser
  879. if sysUser == nil {
  880. br.Msg = "请登录"
  881. br.ErrMsg = "请登录,SysUser is Empty"
  882. br.Ret = 408
  883. return
  884. }
  885. // 判断查询权限
  886. //brMsg, brErrMsg := yb.CheckCommentPermission(sysUser.AdminId)
  887. //if brMsg != "" {
  888. // br.Msg = brMsg
  889. // br.ErrMsg = brErrMsg
  890. // return
  891. //}
  892. var req request.QuestionCommentHotReq
  893. if err := json.Unmarshal(this.Ctx.Input.RequestBody, &req); err != nil {
  894. br.Msg = "参数解析异常!"
  895. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  896. return
  897. }
  898. if err, errMsg := yb.SetHotQuestionComment(req.CommunityQuestionCommentId); err != nil {
  899. br.Msg = errMsg
  900. br.ErrMsg = "CommentHot,Err:" + err.Error()
  901. return
  902. }
  903. br.Ret = 200
  904. br.Success = true
  905. br.Msg = "操作成功"
  906. }
  907. // QuestionDetail
  908. // @Title 问答详情
  909. // @Description 问答详情
  910. // @Param QuestionId query int false "问答ID"
  911. // @Success 200 {object} response.CommunityQuestionListResp
  912. // @router /community/question/detail [get]
  913. func (this *CommunityQuestionController) QuestionDetail() {
  914. br := new(models.BaseResponse).Init()
  915. br.IsSendEmail = false
  916. defer func() {
  917. this.Data["json"] = br
  918. this.ServeJSON()
  919. }()
  920. sysUser := this.SysUser
  921. if sysUser == nil {
  922. br.Msg = "请登录"
  923. br.ErrMsg = "请登录,SysUser Is Empty"
  924. br.Ret = 408
  925. return
  926. }
  927. questionId, _ := this.GetInt("QuestionId", 0)
  928. if questionId <= 0 {
  929. br.Msg = "参数有误"
  930. return
  931. }
  932. // 权限校验
  933. msg, err := yb.CheckCommunityQuestionPermission(sysUser.AdminId)
  934. if err != nil {
  935. br.Msg = msg
  936. br.ErrMsg = err.Error()
  937. return
  938. }
  939. // 获取问答
  940. item, e := ybModels.GetQuestionById(questionId)
  941. if e != nil {
  942. br.Msg = "获取失败"
  943. br.ErrMsg = "获取问答信息失败, Err: " + e.Error()
  944. return
  945. }
  946. // 获取问答流程
  947. processes, e := ybModels.GetCommunityQuestionProcessItemList(questionId)
  948. if e != nil {
  949. br.Msg = "获取失败"
  950. br.ErrMsg = "获取问答流程失败, Err: " + e.Error()
  951. return
  952. }
  953. resp := new(ybModels.CommunityQuestionDetail)
  954. resp.CommunityQuestionId = item.CommunityQuestionId
  955. resp.Mobile = item.Mobile
  956. resp.RealName = item.RealName
  957. resp.QuestionContent = item.QuestionContent
  958. resp.ResearchGroupFirstName = item.ResearchGroupFirstName
  959. resp.ResearchGroupSecondName = item.ResearchGroupSecondName
  960. resp.VarietyTagName = item.VarietyTagName
  961. resp.ReplyStatus = item.ReplyStatus
  962. resp.MsgSendStatus = item.MsgSendStatus
  963. resp.ReplyTime = item.ReplyTime.Format(utils.FormatDateTime)
  964. resp.CreateTime = item.CreateTime.Format(utils.FormatDateTime)
  965. resp.StopReason = item.StopReason
  966. resp.ProcessList = processes
  967. br.Ret = 200
  968. br.Success = true
  969. br.Msg = "获取成功"
  970. br.Data = resp
  971. }
  972. // QuestionTransfer
  973. // @Title 转移并通知
  974. // @Description 转移并通知
  975. // @Param request body request.QuestionTransferReq true "type json string"
  976. // @Success 200 string "操作成功"
  977. // @router /community/question/transfer [post]
  978. func (this *CommunityQuestionController) QuestionTransfer() {
  979. br := new(models.BaseResponse).Init()
  980. br.IsSendEmail = false
  981. defer func() {
  982. this.Data["json"] = br
  983. this.ServeJSON()
  984. }()
  985. sysUser := this.SysUser
  986. if sysUser == nil {
  987. br.Msg = "请登录"
  988. br.ErrMsg = "请登录,SysUser Is Empty"
  989. br.Ret = 408
  990. return
  991. }
  992. // 权限校验
  993. msg, err := yb.CheckCommunityQuestionPermission(sysUser.AdminId)
  994. if err != nil {
  995. br.Msg = msg
  996. br.ErrMsg = err.Error()
  997. return
  998. }
  999. var req request.QuestionTransferReq
  1000. if err := json.Unmarshal(this.Ctx.Input.RequestBody, &req); err != nil {
  1001. br.Msg = "参数解析异常!"
  1002. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  1003. return
  1004. }
  1005. errMsg, err := yb.TransferQuestion(req.QuestionId, req.AdminId, req.ResearchGroupFirstId, req.ResearchGroupSecondId, sysUser.AdminId, sysUser.RealName)
  1006. if err != nil {
  1007. br.Msg = errMsg
  1008. br.ErrMsg = "DistributeQuestion ErrMsg:" + err.Error()
  1009. return
  1010. }
  1011. br.Ret = 200
  1012. br.Success = true
  1013. br.Msg = "操作成功"
  1014. }