wx_user.go 9.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206
  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. IsMaker int `description:"是否是决策人"`
  77. Position string `description:"职务"`
  78. InviteCompany string `description:"邀请机构 ,LUODING:络町"`
  79. }
  80. func GetWxUserItemByUserId(userId int) (item *WxUserItem, err error) {
  81. o := orm.NewOrmUsingDB("weekly_report")
  82. sql := `SELECT a.*,b.company_name FROM wx_user AS a
  83. LEFT JOIN company AS b on a.company_id=b.company_id
  84. WHERE a.user_id=? `
  85. err = o.Raw(sql, userId).QueryRow(&item)
  86. return
  87. }
  88. func GetWxUserItemByMobile(mobile string) (item *WxUserItem, err error) {
  89. o := orm.NewOrmUsingDB("weekly_report")
  90. sql := `SELECT a.*,b.company_name FROM wx_user AS a
  91. LEFT JOIN company AS b on a.company_id=b.company_id
  92. WHERE a.mobile=? `
  93. err = o.Raw(sql, mobile).QueryRow(&item)
  94. return
  95. }
  96. type WxLoginResp struct {
  97. Authorization string
  98. UserId int
  99. FirstLogin int
  100. Headimgurl string `description:"用户头像"`
  101. Mobile string `description:"手机号"`
  102. Email string `description:"邮箱"`
  103. CompanyName string `description:"客户名称"`
  104. Status string `description:"状态"`
  105. EndDate string `description:"到期日期"`
  106. ProductName string `description:"客户类型名称"`
  107. }
  108. type WxGetUserInfoReq struct {
  109. RawData string `description:"rawData"`
  110. Signature string `description:"signature"`
  111. EncryptedData string `description:"encryptedData"`
  112. Iv string `description:"iv"`
  113. }
  114. func GetWxUserItemByUserUnionId(unionId string) (item *WxUserItem, err error) {
  115. o := orm.NewOrmUsingDB("weekly_report")
  116. sql := `SELECT a.*,r.headimgurl as headimgurl_record, b.company_name FROM wx_user AS a
  117. INNER JOIN company AS b on a.company_id=b.company_id
  118. INNER JOIN user_record as r ON r.user_id = a.user_id
  119. WHERE r.union_id=?
  120. GROUP BY a.user_id`
  121. err = o.Raw(sql, unionId).QueryRow(&item)
  122. return
  123. }
  124. // 根据用户手机号获取相关信息
  125. func GetWxUserItemByUserMobile(mobile string) (item *WxUserItem, err error) {
  126. o := orm.NewOrmUsingDB("weekly_report")
  127. sql := `SELECT
  128. a.user_id,
  129. a.real_name,
  130. a.headimgurl,
  131. a.company_id,
  132. a.mobile,
  133. a.email,
  134. r.union_id,
  135. r.open_id,
  136. b.company_name
  137. FROM
  138. wx_user AS a
  139. INNER JOIN company AS b ON a.company_id = b.company_id
  140. INNER JOIN user_record AS r ON r.bind_account = a.mobile
  141. WHERE
  142. a.mobile = ?
  143. and r.create_platform = 4
  144. GROUP BY
  145. a.mobile `
  146. err = o.Raw(sql, mobile).QueryRow(&item)
  147. return
  148. }
  149. // GetUserCountByMobile 获取数量
  150. func GetUserCountByMobile(mobile string) (count int, err error) {
  151. o := orm.NewOrmUsingDB("weekly_report")
  152. sqlCount := ` SELECT COUNT(1) AS count FROM wx_user WHERE mobile = ? `
  153. err = o.Raw(sqlCount, mobile).QueryRow(&count)
  154. return
  155. }
  156. // 添加用户信息
  157. func AddWxUser(item *WxUser) (lastId int64, err error) {
  158. o := orm.NewOrmUsingDB("weekly_report")
  159. lastId, err = o.Insert(item)
  160. return
  161. }
  162. // 变更联系人是否已注册状态
  163. func ModifyWxUserRegisterStatus(userId int) (err error) {
  164. o := orm.NewOrmUsingDB("weekly_report")
  165. sql := `UPDATE wx_user SET is_register=?,source=3,register_time=NOW() WHERE user_id = ? `
  166. _, err = o.Raw(sql, 1, userId).Exec()
  167. return
  168. }
  169. // 判断这个用户是否被设置消息提醒
  170. func GetUserRemind(uid int) (count int, err error) {
  171. sql := `SELECT COUNT(1) AS count FROM cygx_user_remind WHERE user_id = ? `
  172. err = orm.NewOrm().Raw(sql, uid).QueryRow(&count)
  173. return
  174. }
  175. func ModifyReportLastViewTime(uid int) (err error) {
  176. o := orm.NewOrmUsingDB("weekly_report")
  177. sql := ` UPDATE wx_user SET report_last_view_time=NOW()
  178. WHERE user_id=? `
  179. _, err = o.Raw(sql, uid).Exec()
  180. return
  181. }
  182. // GetWxUserListByUserIds 根据用户ID集合获取用户
  183. func GetWxUserListByUserIds(userIds string) (list []*WxUserItem, err error) {
  184. o := orm.NewOrmUsingDB("weekly_report")
  185. sql := ` SELECT u.*, c.company_name FROM wx_user AS u
  186. INNER JOIN company AS c ON c.company_id = u.company_id
  187. WHERE user_id IN (` + userIds + `) `
  188. _, err = o.Raw(sql).QueryRows(&list)
  189. return
  190. }