wx_user.go 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165
  1. package models
  2. import (
  3. "github.com/beego/beego/v2/client/orm"
  4. "github.com/rdlucklib/rdluck_tools/paging"
  5. "time"
  6. )
  7. type WxUser struct {
  8. UserId int64 `orm:"column(user_id);pk"`
  9. Mobile string
  10. Email string
  11. CompanyId int
  12. RealName string `description:"姓名"`
  13. NickName string `description:"昵称"`
  14. CreatedTime time.Time
  15. MobileTwo string `description:"备用手机号"`
  16. BusinessCardUrl string `description:"名片"`
  17. IsMaker int `description:"是否决策人,1:是,0:否"`
  18. Position string `description:"职位"`
  19. Sex int `description:"普通用户性别,1为男性,2为女性"`
  20. DepartmentName string `description:"联系人部门"`
  21. RegisterTime time.Time
  22. RegisterPlatform int
  23. Remark string `description:"备注"`
  24. CountryCode string `description:"区号,86、852、886等"`
  25. OutboundMobile string `description:"外呼手机号"`
  26. OutboundCountryCode string `description:"外呼手机号区号,86、852、886等"`
  27. LastUpdatedTime time.Time `description:"最近一次更新时间"`
  28. IsDeal int `description:"是否标记处理 0-未处理 1-已处理"`
  29. OpenId string `orm:"column(open_id)" description:"微信openid"`
  30. Headimgurl string `description:"用户头像,最后一个数值代表正方形头像大小(有0、46、64、96、132数值可选,0代表640*640正方形头像),用户没有头像时该项为空"`
  31. UserLabel string `description:"查研观向用户标签"`
  32. }
  33. func AddWxUser(item *WxUser) (lastId int64, err error) {
  34. o := orm.NewOrmUsingDB("weekly")
  35. lastId, err = o.Insert(item)
  36. return
  37. }
  38. func GetWxUserByMobile(mobile string) (item *WxUser, err error) {
  39. o := orm.NewOrmUsingDB("weekly")
  40. sql := `SELECT * FROM wx_user WHERE mobile = ? LIMIT 1`
  41. err = o.Raw(sql, mobile).QueryRow(&item)
  42. return
  43. }
  44. // GetWxUserByMobileCountryCode 根据手机号和区号获取用户信息
  45. func GetWxUserByMobileCountryCode(mobile, countryCode string) (item *WxUser, err error) {
  46. o := orm.NewOrmUsingDB("weekly")
  47. sql := `SELECT * FROM wx_user WHERE mobile = ? `
  48. sql += ` and country_code in ("","` + countryCode + `") `
  49. sql += ` LIMIT 1 `
  50. err = o.Raw(sql, mobile).QueryRow(&item)
  51. return
  52. }
  53. func GetWxUserByUserId(userId int) (item *WxUser, err error) {
  54. o := orm.NewOrmUsingDB("weekly")
  55. sql := `SELECT * FROM wx_user WHERE user_id=? `
  56. err = o.Raw(sql, userId).QueryRow(&item)
  57. return
  58. }
  59. // 更新wxUser信息
  60. func (wxUser *WxUser) Update(cols []string) (err error) {
  61. o := orm.NewOrmUsingDB("weekly")
  62. _, err = o.Update(wxUser, cols...)
  63. return
  64. }
  65. type PotentialUserItem struct {
  66. UserId int `description:"用户id"`
  67. RealName string `description:"姓名"`
  68. CountryCode string `description:"区号,86、852、886等"`
  69. Mobile string `description:"手机号"`
  70. Email string `description:"邮箱"`
  71. CreatedTime string `description:"注册时间"`
  72. ApplyMethod int `description:"0:未申请,1:已付费客户申请试用,2:非客户申请试用"`
  73. CompanyName string `description:"客户名称"`
  74. ViewTotal int `description:"累计阅读次数"`
  75. LastViewTime time.Time `json:"-" description:"最后一次阅读时间"`
  76. LastViewTimeStr string `description:"最后一次阅读时间"`
  77. FromType string `description:"report:研报,teleconference:电话会"`
  78. BusinessCardUrl string `description:"名片"`
  79. Source int `description:"来源,1:微信端,2:pc网页端,3:查研观向小程序,4:每日咨询,5:电话会"`
  80. IsDeal int `description:"是否标记处理,0是未处理,1是已处理"`
  81. }
  82. type PotentialUserListResp struct {
  83. List []*PotentialUserItem
  84. Paging *paging.PagingItem `description:"分页数据"`
  85. }
  86. // GetWxUserByCompanyIdAndMobile 根据客户ID及手机号获取用户
  87. func GetWxUserByCompanyIdAndMobile(companyId int, mobile string) (item *WxUser, err error) {
  88. o := orm.NewOrmUsingDB("weekly")
  89. sql := ` SELECT * FROM wx_user WHERE company_id = ? AND mobile = ? LIMIT 1 `
  90. err = o.Raw(sql, companyId, mobile).QueryRow(&item)
  91. return
  92. }
  93. // DeleteWxUserAndRecordByUserId 删除用户及第三方信息
  94. func DeleteWxUserAndRecordByUserId(userId int) (err error) {
  95. o := orm.NewOrmUsingDB("weekly")
  96. to, err := o.Begin()
  97. if err != nil {
  98. return
  99. }
  100. defer func() {
  101. if err != nil {
  102. _ = to.Rollback()
  103. } else {
  104. _ = to.Commit()
  105. }
  106. }()
  107. // 删除wx_user
  108. userSql := ` DELETE FROM wx_user WHERE user_id = ? LIMIT 1 `
  109. _, err = to.Raw(userSql, userId).Exec()
  110. // 删除user_record
  111. if err == nil {
  112. recordSql := ` DELETE FROM user_record WHERE user_id = ? `
  113. _, err = to.Raw(recordSql, userId).Exec()
  114. }
  115. return
  116. }
  117. // 获取这个公司下面所有用户的手机号
  118. func SetUserSubscribe(openId string) (err error) {
  119. o := orm.NewOrmUsingDB("weekly")
  120. sql := ` UPDATE user_record SET subscribe=1,subscribe_time=NOW() WHERE open_id=? `
  121. _, err = o.Raw(sql, openId).Exec()
  122. return
  123. }
  124. type WxUserItem struct {
  125. UserId int `description:"用户id"`
  126. OpenId string `description:"open_id"`
  127. UnionId string `description:"union_id"`
  128. CompanyId int `description:"客户id"`
  129. NickName string `description:"用户昵称"`
  130. RealName string `description:"用户实际名称"`
  131. Mobile string `description:"手机号码"`
  132. BindAccount string `description:"绑定时的账号"`
  133. Email string `description:"邮箱"`
  134. Headimgurl string `description:"用户头像,最后一个数值代表正方形头像大小(有0、46、64、96、132数值可选,0代表640*640正方形头像),用户没有头像时该项为空"`
  135. ApplyMethod int `description:"0:未申请,1:已付费客户申请试用,2:非客户申请试用"`
  136. FirstLogin int `description:"是否第一次登陆"`
  137. IsFreeLogin int `description:"是否免登陆,true:免登陆,false:非免登陆"`
  138. LoginTime time.Time `description:"登录时间"`
  139. CreatedTime time.Time `description:"创建时间"`
  140. LastUpdatedTime time.Time `description:"最近一次修改时间"`
  141. SessionKey string `description:"微信小程序会话密钥"`
  142. CompanyName string `description:"公司名称"`
  143. IsRegister int `description:"是否注册:1:已注册,0:未注册"`
  144. CountryCode string `description:"手机国家区号"`
  145. OutboundMobile string `description:"外呼手机号"`
  146. OutboundCountryCode string `description:"外呼手机号区号"`
  147. IsMsgOutboundMobile int `description:"是否弹窗过绑定外呼手机号区号"`
  148. IsMaker int `description:"是否是决策人"`
  149. Source int
  150. }