user_feedback.go 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186
  1. package cygx
  2. import (
  3. "fmt"
  4. "github.com/beego/beego/v2/client/orm"
  5. "hongze/hz_crm_api/utils"
  6. "strconv"
  7. "time"
  8. )
  9. //用户交流反馈表
  10. // 权益服务明细表
  11. type CygxUserFeedback struct {
  12. UserFeedbackId int `orm:"column(user_feedback_id);pk";comment:"主键id"`
  13. Content string `comment:"服务内容说明"`
  14. UserId int `comment:"用户ID"`
  15. Mobile string `comment:"手机号"`
  16. Email string `comment:"邮箱"`
  17. CompanyId int `comment:"公司ID"`
  18. CompanyName string `comment:"公司名称"`
  19. RealName string `comment:"用户实际名称"`
  20. AdminId int `comment:"操作人ID"`
  21. CreateTime time.Time `comment:"创建时间"`
  22. }
  23. // 权益服务明细表
  24. type CygxUserFeedbackResp struct {
  25. UserFeedbackId int `comment:"主键id"`
  26. Content string `comment:"服务内容说明"`
  27. CreateTime string `comment:"创建时间"`
  28. }
  29. type AddCygxUserFeedbackReq struct {
  30. Content string `comment:"服务内容说明"`
  31. UserId int `comment:"用户ID"`
  32. }
  33. type CygxUserFeedbackIdReq struct {
  34. UserFeedbackId int `comment:"UserFeedbackId 主键ID"`
  35. }
  36. // 添加
  37. func AddCygxUserFeedback(item *CygxUserFeedback) (newId int64, err error) {
  38. o := orm.NewOrmUsingDB("hz_cygx")
  39. newId, err = o.Insert(item)
  40. return
  41. }
  42. // 删除数据
  43. func DeleteCygxUserFeedback(userFeedbackId int) (err error) {
  44. o := orm.NewOrmUsingDB("hz_cygx")
  45. sql := ` DELETE FROM cygx_user_feedback WHERE user_feedback_id = ? `
  46. _, err = o.Raw(sql, userFeedbackId).Exec()
  47. return
  48. }
  49. // 列表
  50. func GetCygxUserFeedbackListByUserId(userId int) (items []*CygxUserFeedbackResp, err error) {
  51. o := orm.NewOrmUsingDB("hz_cygx")
  52. sql := `SELECT * FROM cygx_user_feedback WHERE user_id = ? `
  53. sql += ` ORDER BY user_feedback_id DESC LIMIT 1000 `
  54. _, err = o.Raw(sql, userId).QueryRows(&items)
  55. return
  56. }
  57. type CygxCygxUserFeedbackResp struct {
  58. List []*CygxUserFeedbackResp
  59. }
  60. func GetCygxUserFeedbackList(condition string, pars []interface{}, startSize, pageSize int) (items []*CygxUserFeedback, err error) {
  61. o := orm.NewOrmUsingDB("hz_cygx")
  62. sql := `SELECT *
  63. FROM
  64. cygx_user_feedback
  65. WHERE 1 = 1 ` + condition
  66. sql += ` LIMIT ?,? `
  67. _, err = o.Raw(sql, pars, startSize, pageSize).QueryRows(&items)
  68. return
  69. }
  70. func GetCygxUserFeedbackListInit() (items []*CygxUserFeedback, err error) {
  71. o := orm.NewOrmUsingDB("hz_cygx")
  72. sql := `SELECT *
  73. FROM
  74. cygx_user_feedback
  75. WHERE 1 = 1 `
  76. _, err = o.Raw(sql).QueryRows(&items)
  77. return
  78. }
  79. // 获取数量
  80. func GetCygxUserFeedbackCount(condition string, pars []interface{}) (count int, err error) {
  81. o := orm.NewOrmUsingDB("hz_cygx")
  82. sqlCount := ` SELECT COUNT(1) AS count FROM cygx_user_feedback WHERE 1= 1 ` + condition
  83. err = o.Raw(sqlCount, pars).QueryRow(&count)
  84. return
  85. }
  86. // 用户交流反馈
  87. func GetCygxUserFeedback(condition string, startSize, pageSize int) (total int, items []*UserInteraction, err error) {
  88. o := orm.NewOrmUsingDB("hz_cygx")
  89. var sql string
  90. sql += `SELECT
  91. r.content as key_word,
  92. r.user_id,
  93. r.mobile,
  94. r.real_name,
  95. r.company_id,
  96. r.company_name,
  97. r.create_time
  98. FROM
  99. cygx_user_feedback AS r
  100. WHERE 1 = 1 ` + condition
  101. totalSql := `SELECT COUNT(1) total FROM (` + sql + `) z `
  102. err = o.Raw(totalSql).QueryRow(&total)
  103. if err != nil {
  104. return
  105. }
  106. sql += ` ORDER BY create_time DESC `
  107. if startSize > 0 || pageSize > 0 {
  108. sql += ` LIMIT ` + strconv.Itoa(startSize) + "," + strconv.Itoa(pageSize)
  109. }
  110. _, err = o.Raw(sql).QueryRows(&items)
  111. return
  112. }
  113. // 用户交流反馈
  114. func GetCygxUserFeedbackWeekly(condition string, startSize, pageSize int) (total int, items []*UserInteraction, err error) {
  115. o := orm.NewOrmUsingDB("hz_cygx")
  116. var sql string
  117. sql += `SELECT
  118. r.content as key_word,
  119. r.user_id,
  120. r.mobile,
  121. r.real_name,
  122. r.company_id,
  123. r.company_name,
  124. r.create_time
  125. FROM
  126. cygx_user_feedback AS r
  127. INNER JOIN %s.user_seller_relation AS us ON us.user_id = r.user_id AND us.product_id = 2
  128. WHERE 1 = 1 ` + condition
  129. databaseName := utils.GetWeeklyDatabase()
  130. sql = fmt.Sprintf(sql, databaseName)
  131. totalSql := `SELECT COUNT(1) total FROM (` + sql + `) z `
  132. err = o.Raw(totalSql).QueryRow(&total)
  133. if err != nil {
  134. return
  135. }
  136. sql += ` ORDER BY create_time DESC `
  137. if startSize > 0 || pageSize > 0 {
  138. sql += ` LIMIT ` + strconv.Itoa(startSize) + "," + strconv.Itoa(pageSize)
  139. }
  140. _, err = o.Raw(sql).QueryRows(&items)
  141. return
  142. }
  143. // 获取数量
  144. func GetCygxUserFeedbackCountByUserModel(condition string, pars []interface{}) (count int, err error) {
  145. o := orm.NewOrmUsingDB("hz_cygx")
  146. sqlCount := ` SELECT COUNT(1) AS count FROM cygx_user_feedback as r
  147. WHERE 1= 1 `
  148. if condition != "" {
  149. sqlCount += condition
  150. }
  151. err = o.Raw(sqlCount, pars).QueryRow(&count)
  152. return
  153. }
  154. // 获取数量
  155. func GetCygxUserFeedbackCountByUserModelWeekly(condition string, pars []interface{}) (count int, err error) {
  156. o := orm.NewOrmUsingDB("hz_cygx")
  157. sqlCount := ` SELECT COUNT(1) AS count FROM cygx_user_feedback AS r
  158. INNER JOIN %s.user_seller_relation AS us ON us.user_id = r.user_id AND us.product_id = 2
  159. WHERE 1 = 1 `
  160. databaseName := utils.GetWeeklyDatabase()
  161. sqlCount = fmt.Sprintf(sqlCount, databaseName)
  162. if condition != "" {
  163. sqlCount += condition
  164. }
  165. err = o.Raw(sqlCount, pars).QueryRow(&count)
  166. return
  167. }