wx_user_white.go 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  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 GetWxUserWhiteMobile() (mobileStr string, err error) {
  28. sql := ` SELECT
  29. GROUP_CONCAT( DISTINCT u.mobile SEPARATOR ',' ) AS mobileStr
  30. FROM
  31. wx_user AS u
  32. INNER JOIN company AS c ON c.company_id = u.company_id
  33. INNER JOIN company_report_permission AS p ON p.company_id = u.company_id
  34. INNER JOIN chart_permission AS b ON b.chart_permission_id = p.chart_permission_id
  35. INNER JOIN company_product AS cp ON cp.company_id = u.company_id
  36. WHERE
  37. 1 = 1
  38. AND cp.product_id = 2
  39. AND u.mobile NOT IN ( SELECT mobile FROM wx_user_white )
  40. AND u.mobile != ''
  41. AND cp.status IN ( '正式', '试用' ) `
  42. o := orm.NewOrmUsingDB("weekly_report")
  43. err = o.Raw(sql).QueryRow(&mobileStr)
  44. return
  45. }
  46. // 获取用户外呼手机号白名单
  47. func GetWxUserWhiteOutboundMobile() (mobileStr string, err error) {
  48. sql := ` SELECT
  49. GROUP_CONCAT( DISTINCT u.outbound_mobile SEPARATOR ',' ) AS outboundmobileStr
  50. FROM
  51. wx_user AS u
  52. INNER JOIN company AS c ON c.company_id = u.company_id
  53. INNER JOIN company_report_permission AS p ON p.company_id = u.company_id
  54. INNER JOIN chart_permission AS b ON b.chart_permission_id = p.chart_permission_id
  55. INNER JOIN company_product AS cp ON cp.company_id = u.company_id
  56. WHERE
  57. 1 = 1
  58. AND cp.product_id = 2
  59. AND u.outbound_mobile NOT IN ( SELECT outbound_mobile FROM wx_user_white )
  60. AND u.outbound_mobile NOT IN ( SELECT mobile FROM wx_user_white )
  61. AND cp.status IN ( '正式', '试用' )
  62. AND u.mobile != ''
  63. AND u.mobile != u.outbound_mobile `
  64. o := orm.NewOrmUsingDB("weekly_report")
  65. err = o.Raw(sql).QueryRow(&mobileStr)
  66. return
  67. }
  68. // 获取冻结用户白名单
  69. func GetFrozenUserWhiteList() (items []*WxUserWhite, err error) {
  70. o := orm.NewOrmUsingDB("weekly_report")
  71. sql := `SELECT
  72. *
  73. FROM
  74. wx_user_white AS w
  75. WHERE
  76. w.mobile NOT IN (
  77. SELECT
  78. mobile
  79. FROM
  80. wx_user AS u
  81. INNER JOIN company AS c ON c.company_id = u.company_id
  82. INNER JOIN company_report_permission AS p ON p.company_id = u.company_id
  83. INNER JOIN chart_permission AS b ON b.chart_permission_id = p.chart_permission_id
  84. INNER JOIN company_product AS cp ON cp.company_id = u.company_id
  85. WHERE
  86. 1 = 1
  87. AND cp.product_id = 2
  88. AND cp.STATUS IN ( '正式', '试用' )
  89. AND mobile != ''
  90. )
  91. AND w.outbound_mobile = '' ` //OR w.outbound_mobile NOT IN ( SELECT outbound_mobile FROM wx_user )`
  92. _, err = o.Raw(sql).QueryRows(&items)
  93. return
  94. }
  95. // 获取冻结用户白名单外呼号
  96. func GetFrozenUserWhiteListOutbound() (items []*WxUserWhite, err error) {
  97. o := orm.NewOrmUsingDB("weekly_report")
  98. sql := `SELECT
  99. *
  100. FROM
  101. wx_user_white AS w
  102. WHERE
  103. w.outbound_mobile NOT IN (
  104. SELECT
  105. outbound_mobile
  106. FROM
  107. wx_user AS u
  108. INNER JOIN company AS c ON c.company_id = u.company_id
  109. INNER JOIN company_report_permission AS p ON p.company_id = u.company_id
  110. INNER JOIN chart_permission AS b ON b.chart_permission_id = p.chart_permission_id
  111. INNER JOIN company_product AS cp ON cp.company_id = u.company_id
  112. WHERE
  113. 1 = 1
  114. AND cp.product_id = 2
  115. AND cp.STATUS IN ( '正式', '试用' )
  116. AND outbound_mobile != '')
  117. AND w.mobile = ''`
  118. _, err = o.Raw(sql).QueryRows(&items)
  119. return
  120. }
  121. // 删除数据
  122. func DeleteWxUserWhite(item *WxUserWhite) (err error) {
  123. o := orm.NewOrmUsingDB("weekly_report")
  124. if item.Mobile != "" {
  125. sql := ` DELETE FROM wx_user_white WHERE mobile = ?`
  126. _, err = o.Raw(sql, item.Mobile).Exec()
  127. } else {
  128. sql := ` DELETE FROM wx_user_white WHERE outbound_mobile = ?`
  129. _, err = o.Raw(sql, item.OutboundMobile).Exec()
  130. }
  131. return
  132. }