wx_user_white.go 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  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.NewOrm()
  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.NewOrm()
  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.NewOrm()
  65. err = o.Raw(sql).QueryRow(&mobileStr)
  66. return
  67. }
  68. //获取冻结用户白名单
  69. func GetFrozenUserWhiteList() (items []*WxUserWhite, err error) {
  70. sql := `SELECT
  71. *
  72. FROM
  73. wx_user_white AS w
  74. WHERE
  75. w.mobile NOT IN (
  76. SELECT
  77. mobile
  78. FROM
  79. wx_user AS u
  80. INNER JOIN company AS c ON c.company_id = u.company_id
  81. INNER JOIN company_report_permission AS p ON p.company_id = u.company_id
  82. INNER JOIN chart_permission AS b ON b.chart_permission_id = p.chart_permission_id
  83. INNER JOIN company_product AS cp ON cp.company_id = u.company_id
  84. WHERE
  85. 1 = 1
  86. AND cp.product_id = 2
  87. AND cp.STATUS IN ( '正式', '试用' )
  88. AND mobile != ''
  89. )
  90. AND w.outbound_mobile = '' ` //OR w.outbound_mobile NOT IN ( SELECT outbound_mobile FROM wx_user )`
  91. _, err = orm.NewOrm().Raw(sql).QueryRows(&items)
  92. return
  93. }
  94. //获取冻结用户白名单外呼号
  95. func GetFrozenUserWhiteListOutbound() (items []*WxUserWhite, err error) {
  96. sql := `SELECT
  97. *
  98. FROM
  99. wx_user_white AS w
  100. WHERE
  101. w.outbound_mobile NOT IN (
  102. SELECT
  103. outbound_mobile
  104. FROM
  105. wx_user AS u
  106. INNER JOIN company AS c ON c.company_id = u.company_id
  107. INNER JOIN company_report_permission AS p ON p.company_id = u.company_id
  108. INNER JOIN chart_permission AS b ON b.chart_permission_id = p.chart_permission_id
  109. INNER JOIN company_product AS cp ON cp.company_id = u.company_id
  110. WHERE
  111. 1 = 1
  112. AND cp.product_id = 2
  113. AND cp.STATUS IN ( '正式', '试用' )
  114. AND outbound_mobile != '')
  115. AND w.mobile = ''`
  116. _, err = orm.NewOrm().Raw(sql).QueryRows(&items)
  117. return
  118. }
  119. //删除数据
  120. func DeleteWxUserWhite(item *WxUserWhite) (err error) {
  121. o := orm.NewOrm()
  122. if item.Mobile != "" {
  123. sql := ` DELETE FROM wx_user_white WHERE mobile = ?`
  124. _, err = o.Raw(sql, item.Mobile).Exec()
  125. } else {
  126. sql := ` DELETE FROM wx_user_white WHERE outbound_mobile = ?`
  127. _, err = o.Raw(sql, item.OutboundMobile).Exec()
  128. }
  129. return
  130. }