yanxuan_special_message.go 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701
  1. package controllers
  2. import (
  3. "encoding/json"
  4. "github.com/rdlucklib/rdluck_tools/paging"
  5. "hongze/hongze_mfyx/models"
  6. "hongze/hongze_mfyx/services"
  7. "hongze/hongze_mfyx/utils"
  8. "time"
  9. )
  10. type YanxuanSpecialMessageController struct {
  11. BaseAuthController
  12. }
  13. // @Title 添加留言
  14. // @Description 添加留言接口
  15. // @Param request body models.AddCygxYanxuanSpecialMessageReq true "type json string"
  16. // @Success Ret=200 {object}
  17. // @router /message/add [post]
  18. func (this *YanxuanSpecialMessageController) MessageAdd() {
  19. br := new(models.BaseResponse).Init()
  20. defer func() {
  21. this.Data["json"] = br
  22. this.ServeJSON()
  23. }()
  24. user := this.User
  25. if user == nil {
  26. br.Msg = "请登录"
  27. br.ErrMsg = "请登录,用户信息为空"
  28. br.Ret = 408
  29. return
  30. }
  31. var req models.AddCygxYanxuanSpecialMessageReq
  32. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  33. if err != nil {
  34. br.Msg = "参数解析异常!"
  35. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  36. return
  37. }
  38. yanxuanSpecialId := req.YanxuanSpecialId
  39. content := req.Content
  40. parentId := req.ParentId
  41. if content == "" {
  42. br.Msg = "请输入留言内容!"
  43. return
  44. }
  45. if yanxuanSpecialId == 0 {
  46. br.Msg = "留言失败!"
  47. br.ErrMsg = "专栏信息不能为空"
  48. return
  49. }
  50. // 研选专栏
  51. yanxuanSpecialBySpeciaDetail, err := models.GetYanxuanSpecialBySpecialId(yanxuanSpecialId)
  52. if err != nil {
  53. br.Msg = "获取信息失败"
  54. br.ErrMsg = "获取信息失败,Err:" + err.Error()
  55. return
  56. }
  57. item := new(models.CygxYanxuanSpecialMessage)
  58. item.UserId = user.UserId
  59. item.Mobile = user.Mobile
  60. item.Email = user.Email
  61. item.CompanyId = user.CompanyId
  62. item.CompanyName = user.CompanyName
  63. item.RealName = user.RealName
  64. item.SellerName, _ = services.GetSellerName(user) // 销售姓名
  65. item.YanxuanSpecialId = yanxuanSpecialId
  66. item.Content = content
  67. item.ParentId = parentId
  68. item.YanxuanSpecialUserId = yanxuanSpecialBySpeciaDetail.UserId
  69. item.SourceTitle = yanxuanSpecialBySpeciaDetail.Title
  70. item.CreateTime = time.Now()
  71. item.ModifyTime = time.Now()
  72. item.RegisterPlatform = utils.REGISTER_PLATFORM
  73. messageId, err := models.AddCygxYanxuanSpecialMessage(item)
  74. if err != nil {
  75. br.Msg = "留言失败!"
  76. br.ErrMsg = "留言失败,Err:" + err.Error()
  77. return
  78. }
  79. var msgText string
  80. if parentId == 0 {
  81. msgText = "留言成功"
  82. go services.SendWxCategoryMsgByYanxuanSpecialMassageByAuthor(content, yanxuanSpecialBySpeciaDetail)
  83. } else {
  84. msgText = "回复成功"
  85. go services.SendWxCategoryMsgByYanxuanSpecialMassage(parentId, int(messageId), content, yanxuanSpecialBySpeciaDetail)
  86. }
  87. br.Ret = 200
  88. br.Success = true
  89. br.Msg = msgText
  90. }
  91. // @Title 留言管理列表
  92. // @Description 留言管理列表接口
  93. // @Param PageSize query int true "每页数据条数"
  94. // @Param CurrentIndex query int true "当前页页码,从1开始"
  95. // @Param MessageType query int false "留言类型1:普通留言、2:公开留言"
  96. // @Param WxMessageId query int false "留言ID"
  97. // @Success 200 {object} models.SpecialListResp
  98. // @router /message/manage/list [get]
  99. func (this *YanxuanSpecialMessageController) MessageManageList() {
  100. br := new(models.BaseResponse).Init()
  101. defer func() {
  102. this.Data["json"] = br
  103. this.ServeJSON()
  104. }()
  105. user := this.User
  106. if user == nil {
  107. br.Msg = "请登录"
  108. br.ErrMsg = "请登录,用户信息为空"
  109. br.Ret = 408
  110. return
  111. }
  112. pageSize, _ := this.GetInt("PageSize")
  113. currentIndex, _ := this.GetInt("CurrentIndex")
  114. messageType, _ := this.GetInt("MessageType", 1)
  115. messageId, _ := this.GetInt("WxMessageId") // 前端做区分
  116. resp := new(models.YanxuanSpecialMessageManageRespListResp)
  117. if messageId > 0 {
  118. messagerDetail, err := models.GetCygxYanxuanSpecialMessagerDetailById(messageId)
  119. if err != nil {
  120. br.Msg = "获取失败"
  121. br.ErrMsg = "获取失败, Err:" + err.Error()
  122. return
  123. }
  124. if messagerDetail.Status == -1 {
  125. resp.IsDelete = true
  126. }
  127. }
  128. var startSize int
  129. if pageSize <= 0 {
  130. pageSize = utils.PageSize20
  131. }
  132. if currentIndex <= 0 {
  133. currentIndex = 1
  134. }
  135. startSize = utils.StartIndex(currentIndex, pageSize)
  136. var condition string
  137. var pars []interface{}
  138. userId := user.UserId
  139. if messageType == 1 {
  140. condition += ` AND status = 0 `
  141. } else {
  142. condition += ` AND status = 1 `
  143. }
  144. condition += ` AND yanxuan_special_user_id = ? `
  145. pars = append(pars, userId)
  146. conditionChildren := condition // 子集留言筛选条件
  147. condition += ` AND parent_id = 0 `
  148. total, err := models.GetCygxYanxuanSpecialMessagerCount(condition, pars)
  149. if err != nil {
  150. br.Msg = "获取失败"
  151. br.ErrMsg = "获取失败, Err:" + err.Error()
  152. return
  153. }
  154. condition += ` ORDER BY message_id DESC `
  155. list, err := models.GetCygxYanxuanSpecialMessageList(condition, pars, startSize, pageSize)
  156. if err != nil {
  157. br.Msg = "获取失败"
  158. br.ErrMsg = "获取失败, Err:" + err.Error()
  159. return
  160. }
  161. if len(list) > 0 {
  162. var messageIds []int
  163. var userIds []int
  164. for _, v := range list {
  165. messageIds = append(messageIds, v.MessageId)
  166. userIds = append(userIds, v.UserId)
  167. }
  168. //获取子集评论
  169. conditionChildren += ` AND parent_id IN (` + utils.GetOrmInReplace(len(messageIds)) + `) ORDER BY message_id ASC `
  170. pars = append(pars, messageIds)
  171. listChild, err := models.GetCygxYanxuanSpecialMessageList(conditionChildren, pars, 0, 999)
  172. if err != nil {
  173. br.Msg = "获取失败"
  174. br.ErrMsg = "获取失败, Err:" + err.Error()
  175. return
  176. }
  177. itemChildMap := make(map[int][]*models.CygxYanxuanSpecialMessageManageChildResp)
  178. for _, v := range listChild {
  179. userIds = append(userIds, v.UserId)
  180. itemChild := new(models.CygxYanxuanSpecialMessageManageChildResp)
  181. itemChild.UserId = v.UserId
  182. itemChild.MessageId = v.MessageId
  183. itemChild.Content = v.Content
  184. itemChild.CreateTime = v.CreateTime.Format(utils.FormatDateTime)
  185. itemChildMap[v.ParentId] = append(itemChildMap[v.ParentId], itemChild)
  186. }
  187. //用户头像
  188. listUser, err := models.GetWxUserListByUserIdsArr(userIds)
  189. if err != nil {
  190. br.Msg = "获取失败"
  191. br.ErrMsg = "获取失败, Err:" + err.Error()
  192. return
  193. }
  194. mapUserImg := make(map[int]string)
  195. for _, v := range listUser {
  196. if v.Headimgurl != "" {
  197. mapUserImg[v.UserId] = v.Headimgurl
  198. } else {
  199. mapUserImg[v.UserId] = utils.DefaultHeadimgurl
  200. }
  201. }
  202. for _, v := range userIds {
  203. if mapUserImg[v] == "" {
  204. mapUserImg[v] = utils.DefaultHeadimgurl
  205. }
  206. }
  207. for _, v := range list {
  208. item := new(models.CygxYanxuanSpecialMessageManageResp)
  209. item.MessageId = v.MessageId
  210. item.RealName = v.RealName
  211. item.Headimgurl = mapUserImg[v.UserId]
  212. item.YanxuanSpecialId = v.YanxuanSpecialId
  213. item.Content = v.Content
  214. item.TopTime = v.TopTime
  215. item.SourceTitle = v.SourceTitle
  216. item.CreateTime = v.CreateTime.Format(utils.FormatDateTime)
  217. if len(itemChildMap[v.MessageId]) > 0 {
  218. for _, vm := range itemChildMap[v.MessageId] {
  219. vm.Headimgurl = mapUserImg[vm.UserId]
  220. }
  221. item.ChildList = itemChildMap[v.MessageId]
  222. } else {
  223. item.ChildList = make([]*models.CygxYanxuanSpecialMessageManageChildResp, 0)
  224. }
  225. item.CheckIds = make([]int, 0)
  226. resp.List = append(resp.List, item)
  227. }
  228. } else {
  229. resp.List = make([]*models.CygxYanxuanSpecialMessageManageResp, 0)
  230. }
  231. page := paging.GetPaging(currentIndex, pageSize, total)
  232. resp.Paging = page
  233. br.Data = resp
  234. br.Ret = 200
  235. br.Success = true
  236. br.Msg = "获取成功"
  237. }
  238. // @Title 删除留言
  239. // @Description 删除留言接口
  240. // @Param request body models.DeleteCygxYanxuanSpecialMessageReq true "type json string"
  241. // @Success Ret=200 {object}
  242. // @router /message/delete [post]
  243. func (this *YanxuanSpecialMessageController) MessageDelete() {
  244. br := new(models.BaseResponse).Init()
  245. defer func() {
  246. this.Data["json"] = br
  247. this.ServeJSON()
  248. }()
  249. user := this.User
  250. if user == nil {
  251. br.Msg = "请登录"
  252. br.ErrMsg = "请登录,用户信息为空"
  253. br.Ret = 408
  254. return
  255. }
  256. var req models.DeleteCygxYanxuanSpecialMessageReq
  257. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  258. if err != nil {
  259. br.Msg = "参数解析异常!"
  260. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  261. return
  262. }
  263. messageId := req.MessageId
  264. err = models.DeleteCygxYanxuanSpecialMessage(messageId)
  265. if err != nil {
  266. br.Msg = "删除失败!"
  267. br.ErrMsg = "删除失败,Err:" + err.Error()
  268. return
  269. }
  270. br.Ret = 200
  271. br.Success = true
  272. br.Msg = "删除成功"
  273. }
  274. // @Title 置顶/取消置顶留言
  275. // @Description 置顶/取消置顶留言接口
  276. // @Param request body models.TopCygxYanxuanSpecialMessageReq true "type json string"
  277. // @Success Ret=200 {object}
  278. // @router /message/top [post]
  279. func (this *YanxuanSpecialMessageController) MessageTop() {
  280. br := new(models.BaseResponse).Init()
  281. defer func() {
  282. this.Data["json"] = br
  283. this.ServeJSON()
  284. }()
  285. user := this.User
  286. if user == nil {
  287. br.Msg = "请登录"
  288. br.ErrMsg = "请登录,用户信息为空"
  289. br.Ret = 408
  290. return
  291. }
  292. var req models.TopCygxYanxuanSpecialMessageReq
  293. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  294. if err != nil {
  295. br.Msg = "参数解析异常!"
  296. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  297. return
  298. }
  299. messageId := req.MessageId
  300. doType := req.DoType
  301. messagerDetail, err := models.GetCygxYanxuanSpecialMessagerDetailById(messageId)
  302. if err != nil {
  303. br.Msg = "操作失败!"
  304. br.ErrMsg = "操作失败,Err:" + err.Error()
  305. }
  306. yanxuanSpecialId := messagerDetail.YanxuanSpecialId
  307. var topTime int
  308. var msgContent string
  309. if doType == 1 {
  310. countTop, err := models.GetCygxYanxuanSpecialMessagerCountTop(yanxuanSpecialId)
  311. if err != nil {
  312. br.Msg = "操作失败!"
  313. br.ErrMsg = "操作失败,Err:" + err.Error()
  314. return
  315. }
  316. if countTop > 0 {
  317. br.Msg = "此文章已有置顶留言"
  318. return
  319. }
  320. topTime = int(time.Now().Unix())
  321. msgContent = "已置顶"
  322. } else {
  323. msgContent = "已取消置顶"
  324. }
  325. err = models.UpdateCygxYanxuanSpecialMessageTopTime(topTime, messageId)
  326. if err != nil {
  327. br.Msg = "操作失败!"
  328. br.ErrMsg = "操作失败,Err:" + err.Error()
  329. return
  330. }
  331. br.Ret = 200
  332. br.Success = true
  333. br.Msg = msgContent
  334. }
  335. // @Title 公开/取消公开留言
  336. // @Description 公开/取消公开留言接口
  337. // @Param request body models.TopCygxYanxuanSpecialMessageReq true "type json string"
  338. // @Success Ret=200 {object}
  339. // @router /message/public [post]
  340. func (this *YanxuanSpecialMessageController) MessagePublic() {
  341. br := new(models.BaseResponse).Init()
  342. defer func() {
  343. this.Data["json"] = br
  344. this.ServeJSON()
  345. }()
  346. user := this.User
  347. if user == nil {
  348. br.Msg = "请登录"
  349. br.ErrMsg = "请登录,用户信息为空"
  350. br.Ret = 408
  351. return
  352. }
  353. var req models.PubliceCygxYanxuanSpecialMessageReq
  354. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  355. if err != nil {
  356. br.Msg = "参数解析异常!"
  357. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  358. return
  359. }
  360. messageIds := req.MessageIds
  361. doType := req.DoType
  362. var status int
  363. var publicTime string
  364. var msgContent string
  365. if doType == 1 {
  366. status = 1
  367. publicTime = time.Now().Format(utils.FormatDateTime)
  368. msgContent = "已公开"
  369. } else {
  370. msgContent = "已取消公开"
  371. }
  372. err = models.UpdateCygxYanxuanSpecialMessageStatus(status, publicTime, messageIds)
  373. if err != nil {
  374. br.Msg = "操作失败!"
  375. br.ErrMsg = "操作失败,Err:" + err.Error()
  376. return
  377. }
  378. br.Ret = 200
  379. br.Success = true
  380. br.Msg = msgContent
  381. }
  382. // @Title 点赞/取消点赞
  383. // @Description 点赞/取消点赞接口
  384. // @Param request body models.TopCygxYanxuanSpecialMessageReq true "type json string"
  385. // @Success Ret=200 {object}
  386. // @router /message/like [post]
  387. func (this *YanxuanSpecialMessageController) MessageLike() {
  388. br := new(models.BaseResponse).Init()
  389. defer func() {
  390. this.Data["json"] = br
  391. this.ServeJSON()
  392. }()
  393. user := this.User
  394. if user == nil {
  395. br.Msg = "请登录"
  396. br.ErrMsg = "请登录,用户信息为空"
  397. br.Ret = 408
  398. return
  399. }
  400. var req models.TopCygxYanxuanSpecialMessageReq
  401. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  402. if err != nil {
  403. br.Msg = "参数解析异常!"
  404. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  405. return
  406. }
  407. messageId := req.MessageId
  408. doType := req.DoType
  409. userId := user.UserId
  410. total, err := models.GetCygxYanxuanSpecialMessageLikeCountByUidMid(userId, messageId)
  411. if err != nil {
  412. br.Msg = "操作失败!"
  413. br.ErrMsg = "操作失败,Err:" + err.Error()
  414. return
  415. }
  416. var msgContent string
  417. if doType == 1 {
  418. if total == 0 {
  419. item := new(models.CygxYanxuanSpecialMessageLike)
  420. item.UserId = userId
  421. item.Mobile = user.Mobile
  422. item.Email = user.Email
  423. item.CompanyId = user.CompanyId
  424. item.CompanyName = user.CompanyName
  425. item.RealName = user.RealName
  426. item.MessageId = messageId
  427. item.CreateTime = time.Now()
  428. item.ModifyTime = time.Now()
  429. item.RegisterPlatform = utils.REGISTER_PLATFORM
  430. err = models.AddCygxYanxuanSpecialMessageLike(item)
  431. if err != nil {
  432. br.Msg = "点赞失败!"
  433. br.ErrMsg = "点赞失败,Err:" + err.Error()
  434. return
  435. }
  436. }
  437. msgContent = "已点赞"
  438. } else {
  439. if total > 0 {
  440. err = models.DeleteCygxYanxuanSpecialMessageLike(userId, messageId)
  441. if err != nil {
  442. br.Msg = "点赞失败!"
  443. br.ErrMsg = "点赞失败,Err:" + err.Error()
  444. return
  445. }
  446. }
  447. msgContent = "已取消点赞"
  448. }
  449. br.Ret = 200
  450. br.Success = true
  451. br.Msg = msgContent
  452. }
  453. // @Title 专栏文章留言列表
  454. // @Description 专栏文章留言列表接口
  455. // @Param PageSize query int true "每页数据条数"
  456. // @Param CurrentIndex query int true "当前页页码,从1开始"
  457. // @Param YanxuanSpecialId query int false "研选专栏文章ID"
  458. // @Success 200 {object} models.SpecialListResp
  459. // @router /message/special/list [get]
  460. func (this *YanxuanSpecialMessageController) MessageSpecialList() {
  461. br := new(models.BaseResponse).Init()
  462. defer func() {
  463. this.Data["json"] = br
  464. this.ServeJSON()
  465. }()
  466. user := this.User
  467. if user == nil {
  468. br.Msg = "请登录"
  469. br.ErrMsg = "请登录,用户信息为空"
  470. br.Ret = 408
  471. return
  472. }
  473. pageSize, _ := this.GetInt("PageSize")
  474. currentIndex, _ := this.GetInt("CurrentIndex")
  475. yanxuanSpecialId, _ := this.GetInt("YanxuanSpecialId")
  476. var startSize int
  477. if pageSize <= 0 {
  478. pageSize = utils.PageSize20
  479. }
  480. if currentIndex <= 0 {
  481. currentIndex = 1
  482. }
  483. startSize = utils.StartIndex(currentIndex, pageSize)
  484. userId := user.UserId
  485. resp := new(models.YanxuanSpecialMessageManageRespListResp)
  486. publiccTotal, err := models.GetCygxYanxuanSpecialMessagerPublicCount(yanxuanSpecialId)
  487. if err != nil {
  488. br.Msg = "获取失败"
  489. br.ErrMsg = "获取失败, Err:" + err.Error()
  490. return
  491. }
  492. resp.PublicMessageTotal = publiccTotal
  493. var condition string
  494. var pars []interface{}
  495. var conditionMyself string
  496. var parsMyself []interface{}
  497. conditionMyself += ` AND status = 0 AND parent_id = 0 AND user_id = ? AND yanxuan_special_id = ? ORDER BY message_id DESC `
  498. parsMyself = append(parsMyself, userId, yanxuanSpecialId)
  499. var listMyself []*models.CygxYanxuanSpecialMessage
  500. if currentIndex == 1 {
  501. //获取自己未公开的留言
  502. listMyself, err = models.GetCygxYanxuanSpecialMessageList(conditionMyself, parsMyself, 0, 999)
  503. if err != nil && err.Error() != utils.ErrNoRow() {
  504. br.Msg = "获取失败"
  505. br.ErrMsg = "获取失败, Err:" + err.Error()
  506. return
  507. }
  508. }
  509. condition += ` AND status = 1 `
  510. condition += ` AND yanxuan_special_id = ? `
  511. pars = append(pars, yanxuanSpecialId)
  512. conditionChildren := condition // 子集留言筛选条件
  513. condition += ` AND parent_id = 0 `
  514. total, err := models.GetCygxYanxuanSpecialMessagerCount(condition, pars)
  515. if err != nil {
  516. br.Msg = "获取失败"
  517. br.ErrMsg = "获取失败, Err:" + err.Error()
  518. return
  519. }
  520. condition += ` ORDER BY top_time DESC , message_id DESC `
  521. list, err := models.GetCygxYanxuanSpecialMessageList(condition, pars, startSize, pageSize)
  522. if err != nil {
  523. br.Msg = "获取失败"
  524. br.ErrMsg = "获取失败, Err:" + err.Error()
  525. return
  526. }
  527. for _, v := range list {
  528. listMyself = append(listMyself, v)
  529. }
  530. if len(listMyself) > 0 {
  531. var messageIds []int
  532. var messageIdsAll []int // 所有的留言消息
  533. var userIds []int
  534. for _, v := range list {
  535. messageIds = append(messageIds, v.MessageId)
  536. }
  537. for _, v := range listMyself {
  538. userIds = append(userIds, v.UserId)
  539. }
  540. itemChildMap := make(map[int][]*models.CygxYanxuanSpecialMessageManageChildResp)
  541. if len(messageIds) > 0 {
  542. //获取子集评论
  543. conditionChildren += ` AND parent_id IN (` + utils.GetOrmInReplace(len(messageIds)) + `) ORDER BY message_id ASC `
  544. pars = append(pars, messageIds)
  545. listChild, err := models.GetCygxYanxuanSpecialMessageList(conditionChildren, pars, 0, 999)
  546. if err != nil {
  547. br.Msg = "获取失败"
  548. br.ErrMsg = "获取失败, Err:" + err.Error()
  549. return
  550. }
  551. for _, v := range listChild {
  552. userIds = append(userIds, v.UserId)
  553. messageIdsAll = append(messageIdsAll, v.MessageId)
  554. itemChild := new(models.CygxYanxuanSpecialMessageManageChildResp)
  555. itemChild.UserId = v.UserId
  556. itemChild.MessageId = v.MessageId
  557. itemChild.Content = v.Content
  558. itemChild.LikeCount = v.LikeCount
  559. itemChild.CreateTime = v.CreateTime.Format(utils.FormatDateTime)
  560. itemChildMap[v.ParentId] = append(itemChildMap[v.ParentId], itemChild)
  561. }
  562. }
  563. likeMap := services.GetYanxuanSpecialMessageLikeMap(userId)
  564. //用户头像
  565. listUser, err := models.GetWxUserListByUserIdsArr(userIds)
  566. if err != nil {
  567. br.Msg = "获取失败"
  568. br.ErrMsg = "获取失败, Err:" + err.Error()
  569. return
  570. }
  571. mapUserImg := make(map[int]string)
  572. for _, v := range listUser {
  573. if v.Headimgurl != "" {
  574. mapUserImg[v.UserId] = v.Headimgurl
  575. } else {
  576. mapUserImg[v.UserId] = utils.DefaultHeadimgurl
  577. }
  578. }
  579. for _, v := range listMyself {
  580. item := new(models.CygxYanxuanSpecialMessageManageResp)
  581. item.MessageId = v.MessageId
  582. item.RealName = v.RealName
  583. item.Headimgurl = mapUserImg[v.UserId]
  584. item.YanxuanSpecialId = v.YanxuanSpecialId
  585. item.Content = v.Content
  586. item.TopTime = v.TopTime
  587. item.SourceTitle = v.SourceTitle
  588. item.LikeCount = v.LikeCount
  589. item.IsLikeCount = likeMap[v.MessageId]
  590. item.Status = v.Status
  591. if v.UserId == userId {
  592. item.IsMySelf = true
  593. }
  594. item.CreateTime = v.CreateTime.Format(utils.FormatDateTime)
  595. if len(itemChildMap[v.MessageId]) > 0 {
  596. for _, vm := range itemChildMap[v.MessageId] {
  597. vm.IsLikeCount = likeMap[vm.MessageId]
  598. vm.Headimgurl = mapUserImg[vm.UserId]
  599. }
  600. item.ChildList = itemChildMap[v.MessageId]
  601. } else {
  602. item.ChildList = make([]*models.CygxYanxuanSpecialMessageManageChildResp, 0)
  603. }
  604. item.CheckIds = make([]int, 0)
  605. resp.List = append(resp.List, item)
  606. }
  607. } else {
  608. resp.List = make([]*models.CygxYanxuanSpecialMessageManageResp, 0)
  609. }
  610. page := paging.GetPaging(currentIndex, pageSize, total)
  611. resp.Paging = page
  612. br.Data = resp
  613. br.Ret = 200
  614. br.Success = true
  615. br.Msg = "获取成功"
  616. }
  617. // @Title 通过模版消息查看留言详情
  618. // @Description 通过模版消息查看留言详情接口
  619. // @Param MessageId query int true "留言ID"
  620. // @Success 200 {object} models.SpecialListResp
  621. // @router /message/detail/wxtmp [get]
  622. func (this *YanxuanSpecialMessageController) MessageDetailWxtmp() {
  623. br := new(models.BaseResponse).Init()
  624. defer func() {
  625. this.Data["json"] = br
  626. this.ServeJSON()
  627. }()
  628. user := this.User
  629. if user == nil {
  630. br.Msg = "请登录"
  631. br.ErrMsg = "请登录,用户信息为空"
  632. br.Ret = 408
  633. return
  634. }
  635. messageId, _ := this.GetInt("MessageId")
  636. messagerDetail, err := models.GetCygxYanxuanSpecialMessagerDetailById(messageId)
  637. if err != nil {
  638. br.Msg = "获取失败"
  639. br.ErrMsg = "获取失败, Err:" + err.Error()
  640. return
  641. }
  642. resp := new(models.MessageDetailWxtmpResp)
  643. if messagerDetail.Status == -1 {
  644. resp.IsDelete = true
  645. } else {
  646. resp.Content = messagerDetail.Content
  647. }
  648. resp.YanxuanSpecialId = messagerDetail.YanxuanSpecialId
  649. br.Data = resp
  650. br.Ret = 200
  651. br.Success = true
  652. br.Msg = "获取成功"
  653. }