user_feedback.go 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207
  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. SellerId int `comment:"操作人ID"`
  22. CreateTime time.Time `comment:"创建时间"`
  23. }
  24. // 权益服务明细表
  25. type CygxUserFeedbackResp struct {
  26. UserFeedbackId int `comment:"主键id"`
  27. Content string `comment:"服务内容说明"`
  28. CreateTime string `comment:"创建时间"`
  29. }
  30. type AddCygxUserFeedbackReq struct {
  31. Content string `comment:"服务内容说明"`
  32. UserId int `comment:"用户ID"`
  33. }
  34. type CygxUserFeedbackIdReq struct {
  35. UserFeedbackId int `comment:"UserFeedbackId 主键ID"`
  36. }
  37. // 添加
  38. func AddCygxUserFeedback(item *CygxUserFeedback) (newId int64, err error) {
  39. o := orm.NewOrmUsingDB("hz_cygx")
  40. newId, err = o.Insert(item)
  41. return
  42. }
  43. // 删除数据
  44. func DeleteCygxUserFeedback(userFeedbackId int) (err error) {
  45. o := orm.NewOrmUsingDB("hz_cygx")
  46. sql := ` DELETE FROM cygx_user_feedback WHERE user_feedback_id = ? `
  47. _, err = o.Raw(sql, userFeedbackId).Exec()
  48. return
  49. }
  50. // 列表
  51. func GetCygxUserFeedbackListByUserId(userId int) (items []*CygxUserFeedbackResp, err error) {
  52. o := orm.NewOrmUsingDB("hz_cygx")
  53. sql := `SELECT * FROM cygx_user_feedback WHERE user_id = ? `
  54. sql += ` ORDER BY user_feedback_id DESC LIMIT 1000 `
  55. _, err = o.Raw(sql, userId).QueryRows(&items)
  56. return
  57. }
  58. type CygxCygxUserFeedbackResp struct {
  59. List []*CygxUserFeedbackResp
  60. }
  61. func GetCygxUserFeedbackList(condition string, pars []interface{}, startSize, pageSize int) (items []*CygxUserFeedback, err error) {
  62. o := orm.NewOrmUsingDB("hz_cygx")
  63. sql := `SELECT *
  64. FROM
  65. cygx_user_feedback
  66. WHERE 1 = 1 ` + condition
  67. sql += ` LIMIT ?,? `
  68. _, err = o.Raw(sql, pars, startSize, pageSize).QueryRows(&items)
  69. return
  70. }
  71. func GetCygxUserFeedbackListInit() (items []*CygxUserFeedback, err error) {
  72. o := orm.NewOrmUsingDB("hz_cygx")
  73. sql := `SELECT *
  74. FROM
  75. cygx_user_feedback
  76. WHERE 1 = 1 `
  77. _, err = o.Raw(sql).QueryRows(&items)
  78. return
  79. }
  80. func GetCygxUserFeedbackListIni2t() (items []*CygxUserFeedback, err error) {
  81. o := orm.NewOrmUsingDB("hz_cygx")
  82. sql := `SELECT
  83. f.*,
  84. p.seller_id
  85. FROM
  86. cygx_user_feedback AS f
  87. INNER JOIN weekly_report.company_product AS p ON p.company_id = f.company_id
  88. AND p.product_id = 2
  89. WHERE
  90. admin_id IN ( SELECT admin_id FROM weekly_report.admin WHERE group_id IN ( 68, 72 ) )
  91. AND user_id IN ( SELECT user_id FROM weekly_report.wx_user WHERE is_maker = 1 )
  92. AND f.create_time > '2024-07-01'
  93. AND f.create_time < '2024-10-01'
  94. ORDER BY
  95. f.create_time DESC `
  96. _, err = o.Raw(sql).QueryRows(&items)
  97. return
  98. }
  99. // 获取数量
  100. func GetCygxUserFeedbackCount(condition string, pars []interface{}) (count int, err error) {
  101. o := orm.NewOrmUsingDB("hz_cygx")
  102. sqlCount := ` SELECT COUNT(1) AS count FROM cygx_user_feedback WHERE 1= 1 ` + condition
  103. err = o.Raw(sqlCount, pars).QueryRow(&count)
  104. return
  105. }
  106. // 用户交流反馈
  107. func GetCygxUserFeedback(condition string, startSize, pageSize int) (total int, items []*UserInteraction, err error) {
  108. o := orm.NewOrmUsingDB("hz_cygx")
  109. var sql string
  110. sql += `SELECT
  111. r.content as key_word,
  112. r.user_id,
  113. r.mobile,
  114. r.real_name,
  115. r.company_id,
  116. r.company_name,
  117. r.create_time
  118. FROM
  119. cygx_user_feedback AS r
  120. WHERE 1 = 1 ` + condition
  121. totalSql := `SELECT COUNT(1) total FROM (` + sql + `) z `
  122. err = o.Raw(totalSql).QueryRow(&total)
  123. if err != nil {
  124. return
  125. }
  126. sql += ` ORDER BY create_time DESC `
  127. if startSize > 0 || pageSize > 0 {
  128. sql += ` LIMIT ` + strconv.Itoa(startSize) + "," + strconv.Itoa(pageSize)
  129. }
  130. _, err = o.Raw(sql).QueryRows(&items)
  131. return
  132. }
  133. // 用户交流反馈
  134. func GetCygxUserFeedbackWeekly(condition string, startSize, pageSize int) (total int, items []*UserInteraction, err error) {
  135. o := orm.NewOrmUsingDB("hz_cygx")
  136. var sql string
  137. sql += `SELECT
  138. r.content as key_word,
  139. r.user_id,
  140. r.mobile,
  141. r.real_name,
  142. r.company_id,
  143. r.company_name,
  144. r.create_time
  145. FROM
  146. cygx_user_feedback AS r
  147. INNER JOIN %s.user_seller_relation AS us ON us.user_id = r.user_id AND us.product_id = 2
  148. WHERE 1 = 1 ` + condition
  149. databaseName := utils.GetWeeklyDatabase()
  150. sql = fmt.Sprintf(sql, databaseName)
  151. totalSql := `SELECT COUNT(1) total FROM (` + sql + `) z `
  152. err = o.Raw(totalSql).QueryRow(&total)
  153. if err != nil {
  154. return
  155. }
  156. sql += ` ORDER BY create_time DESC `
  157. if startSize > 0 || pageSize > 0 {
  158. sql += ` LIMIT ` + strconv.Itoa(startSize) + "," + strconv.Itoa(pageSize)
  159. }
  160. _, err = o.Raw(sql).QueryRows(&items)
  161. return
  162. }
  163. // 获取数量
  164. func GetCygxUserFeedbackCountByUserModel(condition string, pars []interface{}) (count int, err error) {
  165. o := orm.NewOrmUsingDB("hz_cygx")
  166. sqlCount := ` SELECT COUNT(1) AS count FROM cygx_user_feedback as r
  167. WHERE 1= 1 `
  168. if condition != "" {
  169. sqlCount += condition
  170. }
  171. err = o.Raw(sqlCount, pars).QueryRow(&count)
  172. return
  173. }
  174. // 获取数量
  175. func GetCygxUserFeedbackCountByUserModelWeekly(condition string, pars []interface{}) (count int, err error) {
  176. o := orm.NewOrmUsingDB("hz_cygx")
  177. sqlCount := ` SELECT COUNT(1) AS count FROM cygx_user_feedback AS r
  178. INNER JOIN %s.user_seller_relation AS us ON us.user_id = r.user_id AND us.product_id = 2
  179. WHERE 1 = 1 `
  180. databaseName := utils.GetWeeklyDatabase()
  181. sqlCount = fmt.Sprintf(sqlCount, databaseName)
  182. if condition != "" {
  183. sqlCount += condition
  184. }
  185. err = o.Raw(sqlCount, pars).QueryRow(&count)
  186. return
  187. }