cygx_yanxuan_special_message.go 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  1. package models
  2. import (
  3. "github.com/beego/beego/v2/client/orm"
  4. "github.com/rdlucklib/rdluck_tools/paging"
  5. "hongze/hongze_web_mfyx/utils"
  6. "time"
  7. )
  8. type CygxYanxuanSpecialMessage struct {
  9. MessageId int `orm:"column(message_id);pk"`
  10. UserId int `comment:"用户ID"`
  11. Mobile string `comment:"手机号"`
  12. Email string `comment:"邮箱"`
  13. CompanyId int `comment:"公司ID"`
  14. CompanyName string `comment:"公司名称"`
  15. RealName string `comment:"用户实际名称"`
  16. SellerName string `comment:"所属销售"`
  17. RegisterPlatform int `comment:"来源 1小程序,2:网页,5买方研选小程序,6:买方研选网页版"`
  18. YanxuanSpecialId int `comment:"cygx_yanxuan_special 表主键ID"`
  19. Content string `comment:"留言内容"`
  20. PublicTime time.Time `comment:"公开时间"`
  21. Status int `comment:"消息状态,0未公开、1:已公开"`
  22. TopTime int `comment:"置顶时间"`
  23. LikeCount int `comment:"点赞数量"`
  24. ParentId int `comment:"父级ID"`
  25. YanxuanSpecialUserId int `comment:"研选专栏作者对应的用户ID"`
  26. SourceTitle string `comment:"标题"`
  27. CreateTime time.Time `comment:"创建时间"`
  28. ModifyTime time.Time `comment:"修改时间"`
  29. }
  30. type AddCygxYanxuanSpecialMessageReq struct {
  31. YanxuanSpecialId int `comment:"cygx_yanxuan_special 表主键ID"`
  32. Content string `comment:"留言内容"`
  33. ParentId int `comment:"父级ID"`
  34. }
  35. type DeleteCygxYanxuanSpecialMessageReq struct {
  36. MessageId int `comment:"留言消息ID"`
  37. }
  38. type PubliceCygxYanxuanSpecialMessageReq struct {
  39. MessageIds []int `comment:"留言消息ID"`
  40. DoType int `comment:"0取消置顶,1置顶"`
  41. }
  42. type TopCygxYanxuanSpecialMessageReq struct {
  43. MessageId int `comment:"留言消息ID"`
  44. DoType int `comment:"0取消置顶,1置顶"`
  45. }
  46. // 新增
  47. func AddCygxYanxuanSpecialMessage(item *CygxYanxuanSpecialMessage) (newId int64, err error) {
  48. o := orm.NewOrm()
  49. newId, err = o.Insert(item)
  50. return
  51. }
  52. // 删除(软删除)
  53. func DeleteCygxYanxuanSpecialMessage(messageId int) (err error) {
  54. o := orm.NewOrm()
  55. //sql := `DELETE FROM cygx_yanxuan_special_message WHERE message_id = ? `
  56. sql := `UPDATE cygx_yanxuan_special_message SET status = -1 WHERE message_id = ? `
  57. _, err = o.Raw(sql, messageId).Exec()
  58. return
  59. }
  60. // 更新置顶时间
  61. func UpdateCygxYanxuanSpecialMessageTopTime(topTime, messageId int) (err error) {
  62. o := orm.NewOrm()
  63. sql := ``
  64. sql = `UPDATE cygx_yanxuan_special_message SET top_time = ? WHERE message_id = ? `
  65. _, err = o.Raw(sql, topTime, messageId).Exec()
  66. return
  67. }
  68. // 更新是否公开
  69. func UpdateCygxYanxuanSpecialMessageStatus(status int, publicTime string, messageIds []int) (err error) {
  70. o := orm.NewOrm()
  71. sql := ``
  72. sql = `UPDATE cygx_yanxuan_special_message SET top_time = 0 , status = ? ,public_time = ? WHERE message_id IN (` + utils.GetOrmInReplace(len(messageIds)) + `) OR ( parent_id IN (` + utils.GetOrmInReplace(len(messageIds)) + `) AND status != -1 ) `
  73. _, err = o.Raw(sql, status, publicTime, messageIds, messageIds).Exec()
  74. return
  75. }
  76. func GetCygxYanxuanSpecialMessageList(condition string, pars []interface{}, startSize, pageSize int) (items []*CygxYanxuanSpecialMessage, err error) {
  77. o := orm.NewOrm()
  78. sql := `SELECT *
  79. FROM
  80. cygx_yanxuan_special_message
  81. WHERE 1 = 1 ` + condition
  82. sql += ` LIMIT ?,? `
  83. _, err = o.Raw(sql, pars, startSize, pageSize).QueryRows(&items)
  84. return
  85. }
  86. // 根据id获取详情
  87. func GetCygxYanxuanSpecialMessagerDetailById(messageId int) (item *CygxYanxuanSpecialMessage, err error) {
  88. o := orm.NewOrm()
  89. sql := `SELECT * FROM cygx_yanxuan_special_message WHERE message_id = ? `
  90. err = o.Raw(sql, messageId).QueryRow(&item)
  91. return
  92. }
  93. // 获取置顶留言数量数量
  94. func GetCygxYanxuanSpecialMessagerCountTop(yanxuanSpecialId int) (count int, err error) {
  95. o := orm.NewOrm()
  96. sqlCount := ` SELECT COUNT(1) AS count FROM cygx_yanxuan_special_message WHERE top_time > 0 AND yanxuan_special_id = ? `
  97. err = o.Raw(sqlCount, yanxuanSpecialId).QueryRow(&count)
  98. return
  99. }
  100. // 获取数量
  101. func GetCygxYanxuanSpecialMessagerCount(condition string, pars []interface{}) (count int, err error) {
  102. o := orm.NewOrm()
  103. sqlCount := ` SELECT COUNT(1) AS count FROM cygx_yanxuan_special_message WHERE 1= 1 ` + condition
  104. err = o.Raw(sqlCount, pars).QueryRow(&count)
  105. return
  106. }
  107. // 获取留言公开数量
  108. func GetCygxYanxuanSpecialMessagerPublicCount(yanxuanSpecialId int) (count int, err error) {
  109. o := orm.NewOrm()
  110. sqlCount := ` SELECT COUNT(1) AS count FROM cygx_yanxuan_special_message WHERE status = 1 AND yanxuan_special_id = ? `
  111. err = o.Raw(sqlCount, yanxuanSpecialId).QueryRow(&count)
  112. return
  113. }
  114. type CygxYanxuanSpecialMessageManageResp struct {
  115. MessageId int `comment:"留言消息ID"`
  116. RealName string `comment:"用户实际名称"`
  117. Headimgurl string `comment:"用户头像"`
  118. YanxuanSpecialId int `comment:"研选专栏文章ID"`
  119. Content string `comment:"留言内容"`
  120. Status int `comment:"消息状态,0未公开、1:已公开"`
  121. TopTime int `comment:"置顶时间(大于零置顶,等于零未置顶)"`
  122. HaveOtherTop bool `comment:"是否有其它的置顶"`
  123. SourceTitle string `comment:"专栏标题"`
  124. CreateTime string `comment:"创建时间"`
  125. LikeCount int `comment:"点赞数量"`
  126. IsLikeCount bool `comment:"是否点赞"`
  127. IsMySelf bool `comment:"是否属于本人留言"`
  128. CheckIds []int `comment:"空数组前端渲染使用"`
  129. ChildList []*CygxYanxuanSpecialMessageManageChildResp // 留言子集
  130. }
  131. type CygxYanxuanSpecialMessageManageChildResp struct {
  132. UserId int `comment:"用户ID"`
  133. MessageId int `comment:"留言消息ID"`
  134. Content string `comment:"留言内容"`
  135. Headimgurl string `comment:"用户头像"`
  136. LikeCount int `comment:"点赞数量"`
  137. IsLikeCount bool `comment:"是否点赞"`
  138. CreateTime string `comment:"创建时间"`
  139. }
  140. type YanxuanSpecialMessageManageRespListResp struct {
  141. PublicMessageTotal int `comment:"公开留言数量"`
  142. Paging *paging.PagingItem `description:"分页数据"`
  143. List []*CygxYanxuanSpecialMessageManageResp
  144. }