wx_user.go 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  1. package models
  2. import (
  3. "github.com/beego/beego/v2/client/orm"
  4. "time"
  5. )
  6. type WxUser struct {
  7. UserId int `orm:"column(user_id);pk"`
  8. OpenId string `description:"open_id"`
  9. UnionId string `description:"union_id"`
  10. Subscribe string `description:"是否关注"`
  11. CompanyId int `description:"客户id"`
  12. NickName string `description:"用户昵称"`
  13. RealName string `description:"用户实际名称"`
  14. UserCode string `description:"用户编码"`
  15. Mobile string `description:"手机号码"`
  16. BindAccount string `description:"绑定时的账号"`
  17. WxCode string `description:"微信号"`
  18. Profession string `description:"职业"`
  19. Email string `description:"邮箱"`
  20. Telephone string `description:"座机"`
  21. Sex int `description:"普通用户性别,1为男性,2为女性"`
  22. Province string `description:"普通用户个人资料填写的省份"`
  23. City string `description:"普通用户个人资料填写的城市"`
  24. Country string `description:"国家,如中国为CN"`
  25. SubscribeTime int `description:"关注时间"`
  26. Remark string `description:"备注"`
  27. Headimgurl string `description:"用户头像,最后一个数值代表正方形头像大小(有0、46、64、96、132数值可选,0代表640*640正方形头像),用户没有头像时该项为空"`
  28. Privilege string `description:"用户特权信息,json数组,如微信沃卡用户为(chinaunicom)"`
  29. Unionid string `description:"用户统一标识。针对一个微信开放平台帐号下的应用,同一用户的unionid是唯一的。"`
  30. FirstLogin int `description:"是否第一次登陆"`
  31. Enabled int `description:"是否可用"`
  32. CreatedTime time.Time `description:"创建时间"`
  33. LastUpdatedTime time.Time `description:"最新一次修改时间"`
  34. Seller string `description:"销售员"`
  35. Note string `description:"客户备份信息"`
  36. IsNote int `description:"是否备注过信息"`
  37. FromType string `description:"report' COMMENT 'report:研报,teleconference:电话会"`
  38. ApplyMethod int `description:"0:未申请,1:已付费客户申请试用,2:非客户申请试用"`
  39. RegisterTime time.Time `description:"注册时间"`
  40. RegisterPlatform int `description:"注册平台,1:微信端,2:PC网页端"`
  41. IsFreeLogin bool `description:"是否免登陆,true:免登陆,false:非免登陆"`
  42. LoginTime time.Time `description:"最近一次登录时间"`
  43. SessionKey string `description:"微信小程序会话密钥"`
  44. IsRegister int `description:"是否注册:1:已注册,0:未注册"`
  45. Source int `description:"绑定来源,1:微信端,2:pc网页端,3:查研观向小程序,4:每日咨询"`
  46. CountryCode string `description:"区号"`
  47. OutboundMobile string `description:"外呼手机号"`
  48. OutboundCountryCode string `description:"外呼手机号区号"`
  49. }
  50. type WxUserItem struct {
  51. UserId int `description:"用户id"`
  52. OpenId string `description:"open_id"`
  53. UnionId string `description:"union_id"`
  54. CompanyId int `description:"客户id"`
  55. NickName string `description:"用户昵称"`
  56. RealName string `description:"用户实际名称"`
  57. Mobile string `description:"手机号码"`
  58. BindAccount string `description:"绑定时的账号"`
  59. Email string `description:"邮箱"`
  60. Headimgurl string `description:"用户头像,最后一个数值代表正方形头像大小(有0、46、64、96、132数值可选,0代表640*640正方形头像),用户没有头像时该项为空"`
  61. HeadimgurlRecord string `description:"用户头像,最后一个数值代表正方形头像大小(有0、46、64、96、132数值可选,0代表640*640正方形头像),用户没有头像时该项为空"`
  62. ApplyMethod int `description:"0:未申请,1:已付费客户申请试用,2:非客户申请试用"`
  63. FirstLogin int `description:"是否第一次登陆"`
  64. IsFreeLogin int `description:"是否免登陆,true:免登陆,false:非免登陆"`
  65. LoginTime time.Time `description:"登录时间"`
  66. CreatedTime time.Time `description:"创建时间"`
  67. LastUpdatedTime time.Time `description:"最近一次修改时间"`
  68. SessionKey string `description:"微信小程序会话密钥"`
  69. CompanyName string `description:"公司名称"`
  70. IsRegister int `description:"是否注册:1:已注册,0:未注册"`
  71. CountryCode string `description:"手机国家区号"`
  72. OutboundMobile string `description:"外呼手机号"`
  73. OutboundCountryCode string `description:"外呼手机号区号"`
  74. IsMsgOutboundMobile int `description:"是否弹窗过绑定外呼手机号区号"`
  75. Source int
  76. }
  77. type WxLoginResp struct {
  78. Authorization string
  79. UserId int
  80. FirstLogin int
  81. Headimgurl string `description:"用户头像"`
  82. Mobile string `description:"手机号"`
  83. Email string `description:"邮箱"`
  84. CompanyName string `description:"客户名称"`
  85. Status string `description:"状态"`
  86. EndDate string `description:"到期日期"`
  87. ProductName string `description:"客户类型名称"`
  88. }
  89. type WxGetUserInfoReq struct {
  90. RawData string `description:"rawData"`
  91. Signature string `description:"signature"`
  92. EncryptedData string `description:"encryptedData"`
  93. Iv string `description:"iv"`
  94. }
  95. func GetWxUserItemByUserUnionId(unionId string) (item *WxUserItem, err error) {
  96. sql := `SELECT a.*,r.headimgurl as headimgurl_record, b.company_name FROM wx_user AS a
  97. INNER JOIN company AS b on a.company_id=b.company_id
  98. INNER JOIN user_record as r ON r.user_id = a.user_id
  99. WHERE r.union_id=?
  100. GROUP BY a.user_id`
  101. err = orm.NewOrm().Raw(sql, unionId).QueryRow(&item)
  102. return
  103. }
  104. // 根据用户手机号获取相关信息
  105. func GetWxUserItemByUserMobile(mobile string) (item *WxUserItem, err error) {
  106. sql := `SELECT
  107. a.user_id,
  108. a.real_name,
  109. a.headimgurl,
  110. a.company_id,
  111. a.mobile,
  112. a.email,
  113. b.company_name
  114. FROM
  115. wx_user AS a
  116. INNER JOIN company AS b ON a.company_id = b.company_id
  117. WHERE
  118. a.mobile = ?
  119. GROUP BY
  120. a.mobile `
  121. err = orm.NewOrm().Raw(sql, mobile).QueryRow(&item)
  122. return
  123. }
  124. // 获取这个公司下面所有用户的手机号
  125. func SetUserSubscribeByMobile(mobile string) (err error) {
  126. o := orm.NewOrm()
  127. sql := ` UPDATE wx_user SET cygx_subscribe=1,cygx_subscribe_time=NOW() WHERE mobile=? `
  128. _, err = o.Raw(sql, mobile).Exec()
  129. return
  130. }