wx_user_white.go 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  1. package models
  2. import (
  3. "github.com/beego/beego/v2/client/orm"
  4. "time"
  5. )
  6. type WxUserWhite struct {
  7. Id int `orm:"column(id);pk"`
  8. Mobile string
  9. CreatedTime time.Time
  10. UserCreatedTime time.Time
  11. OutboundMobile string `description:"外呼手机号"`
  12. Status string `description:"客户状态'试用','永续','冻结','流失','正式','潜在'"`
  13. CountryCode string `description:"区号"`
  14. OutboundCountryCode string `description:"外呼手机号区号"`
  15. CompanyName string `description:"公司名称"`
  16. PermissionName string `description:"拥有权限分类"`
  17. RealName string `description:"姓名"`
  18. SellerName string `description:"销售"`
  19. }
  20. // 添加
  21. func AddWxUserWhite(item *WxUserWhite) (lastId int64, err error) {
  22. o := orm.NewOrmUsingDB("weekly_report")
  23. lastId, err = o.Insert(item)
  24. return
  25. }
  26. // 批量添加
  27. func AddAddWxUserWhiteMulti(items []*WxUserWhite) (err error) {
  28. o := orm.NewOrmUsingDB("weekly_report")
  29. if len(items) > 0 {
  30. //批量添加新的关注记录
  31. _, err = o.InsertMulti(len(items), items)
  32. }
  33. return
  34. }
  35. // 获取用户手机号白名单
  36. func GetWxUserWhiteMobile() (mobileStr string, err error) {
  37. sql := ` SELECT
  38. GROUP_CONCAT( DISTINCT u.mobile SEPARATOR ',' ) AS mobileStr
  39. FROM
  40. wx_user AS u
  41. INNER JOIN company AS c ON c.company_id = u.company_id
  42. INNER JOIN company_report_permission AS p ON p.company_id = u.company_id
  43. INNER JOIN chart_permission AS b ON b.chart_permission_id = p.chart_permission_id
  44. INNER JOIN company_product AS cp ON cp.company_id = u.company_id
  45. WHERE
  46. 1 = 1
  47. AND cp.product_id = 2
  48. AND u.mobile NOT IN ( SELECT mobile FROM wx_user_white )
  49. AND u.mobile != ''
  50. AND cp.status IN ( '正式', '试用' ) `
  51. o := orm.NewOrmUsingDB("weekly_report")
  52. err = o.Raw(sql).QueryRow(&mobileStr)
  53. return
  54. }
  55. // 获取用户外呼手机号白名单
  56. func GetWxUserWhiteOutboundMobile() (mobileStr string, err error) {
  57. o := orm.NewOrmUsingDB("weekly_report")
  58. sql := ` SELECT
  59. GROUP_CONCAT( DISTINCT u.outbound_mobile SEPARATOR ',' ) AS outboundmobileStr
  60. FROM
  61. wx_user AS u
  62. INNER JOIN company AS c ON c.company_id = u.company_id
  63. INNER JOIN company_report_permission AS p ON p.company_id = u.company_id
  64. INNER JOIN chart_permission AS b ON b.chart_permission_id = p.chart_permission_id
  65. INNER JOIN company_product AS cp ON cp.company_id = u.company_id
  66. WHERE
  67. 1 = 1
  68. AND cp.product_id = 2
  69. AND u.outbound_mobile NOT IN ( SELECT outbound_mobile FROM wx_user_white )
  70. AND u.outbound_mobile NOT IN ( SELECT mobile FROM wx_user_white )
  71. AND cp.status IN ( '正式', '试用' )
  72. AND u.mobile != ''
  73. AND u.mobile != u.outbound_mobile `
  74. err = o.Raw(sql).QueryRow(&mobileStr)
  75. return
  76. }
  77. // 获取冻结用户白名单
  78. func GetFrozenUserWhiteList() (items []*WxUserWhite, err error) {
  79. o := orm.NewOrmUsingDB("weekly_report")
  80. sql := `SELECT
  81. *
  82. FROM
  83. wx_user_white AS w
  84. WHERE
  85. w.mobile NOT IN (
  86. SELECT
  87. mobile
  88. FROM
  89. wx_user AS u
  90. INNER JOIN company AS c ON c.company_id = u.company_id
  91. INNER JOIN company_report_permission AS p ON p.company_id = u.company_id
  92. INNER JOIN chart_permission AS b ON b.chart_permission_id = p.chart_permission_id
  93. INNER JOIN company_product AS cp ON cp.company_id = u.company_id
  94. WHERE
  95. 1 = 1
  96. AND cp.product_id = 2
  97. AND cp.STATUS IN ( '正式', '试用' )
  98. AND mobile != ''
  99. )
  100. AND w.outbound_mobile = '' ` //OR w.outbound_mobile NOT IN ( SELECT outbound_mobile FROM wx_user )`
  101. _, err = o.Raw(sql).QueryRows(&items)
  102. return
  103. }
  104. // 获取冻结用户白名单外呼号
  105. func GetFrozenUserWhiteListOutbound() (items []*WxUserWhite, err error) {
  106. o := orm.NewOrmUsingDB("weekly_report")
  107. sql := `SELECT
  108. *
  109. FROM
  110. wx_user_white AS w
  111. WHERE
  112. w.outbound_mobile NOT IN (
  113. SELECT
  114. outbound_mobile
  115. FROM
  116. wx_user AS u
  117. INNER JOIN company AS c ON c.company_id = u.company_id
  118. INNER JOIN company_report_permission AS p ON p.company_id = u.company_id
  119. INNER JOIN chart_permission AS b ON b.chart_permission_id = p.chart_permission_id
  120. INNER JOIN company_product AS cp ON cp.company_id = u.company_id
  121. WHERE
  122. 1 = 1
  123. AND cp.product_id = 2
  124. AND cp.STATUS IN ( '正式', '试用' )
  125. AND outbound_mobile != '')
  126. AND w.mobile = ''`
  127. _, err = o.Raw(sql).QueryRows(&items)
  128. return
  129. }
  130. // 删除数据
  131. func DeleteWxUserWhite(item *WxUserWhite) (err error) {
  132. o := orm.NewOrmUsingDB("weekly_report")
  133. if item.Mobile != "" {
  134. sql := ` DELETE FROM wx_user_white WHERE mobile = ?`
  135. _, err = o.Raw(sql, item.Mobile).Exec()
  136. } else if item.OutboundMobile != "" {
  137. sql := ` DELETE FROM wx_user_white WHERE outbound_mobile = ?`
  138. _, err = o.Raw(sql, item.OutboundMobile).Exec()
  139. }
  140. return
  141. }