wx_user.go 9.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221
  1. package models
  2. import (
  3. "github.com/beego/beego/v2/client/orm"
  4. "hongze/hongze_web_mfyx/utils"
  5. "time"
  6. )
  7. type WxUser struct {
  8. UserId int `orm:"column(user_id);pk"`
  9. OpenId string `description:"open_id"`
  10. UnionId string `description:"union_id"`
  11. Subscribe string `description:"是否关注"`
  12. CompanyId int `description:"客户id"`
  13. NickName string `description:"用户昵称"`
  14. RealName string `description:"用户实际名称"`
  15. UserCode string `description:"用户编码"`
  16. Mobile string `description:"手机号码"`
  17. BindAccount string `description:"绑定时的账号"`
  18. WxCode string `description:"微信号"`
  19. Profession string `description:"职业"`
  20. Email string `description:"邮箱"`
  21. Telephone string `description:"座机"`
  22. Sex int `description:"普通用户性别,1为男性,2为女性"`
  23. Province string `description:"普通用户个人资料填写的省份"`
  24. City string `description:"普通用户个人资料填写的城市"`
  25. Country string `description:"国家,如中国为CN"`
  26. SubscribeTime int `description:"关注时间"`
  27. Remark string `description:"备注"`
  28. Headimgurl string `description:"用户头像,最后一个数值代表正方形头像大小(有0、46、64、96、132数值可选,0代表640*640正方形头像),用户没有头像时该项为空"`
  29. Privilege string `description:"用户特权信息,json数组,如微信沃卡用户为(chinaunicom)"`
  30. Unionid string `description:"用户统一标识。针对一个微信开放平台帐号下的应用,同一用户的unionid是唯一的。"`
  31. FirstLogin int `description:"是否第一次登陆"`
  32. Enabled int `description:"是否可用"`
  33. CreatedTime time.Time `description:"创建时间"`
  34. LastUpdatedTime time.Time `description:"最新一次修改时间"`
  35. Seller string `description:"销售员"`
  36. Note string `description:"客户备份信息"`
  37. IsNote int `description:"是否备注过信息"`
  38. FromType string `description:"report' COMMENT 'report:研报,teleconference:电话会"`
  39. ApplyMethod int `description:"0:未申请,1:已付费客户申请试用,2:非客户申请试用"`
  40. RegisterTime time.Time `description:"注册时间"`
  41. RegisterPlatform int `description:"注册平台,1:微信端,2:PC网页端"`
  42. IsFreeLogin bool `description:"是否免登陆,true:免登陆,false:非免登陆"`
  43. LoginTime time.Time `description:"最近一次登录时间"`
  44. SessionKey string `description:"微信小程序会话密钥"`
  45. IsRegister int `description:"是否注册:1:已注册,0:未注册"`
  46. Source int `description:"绑定来源,1:微信端,2:pc网页端,3:查研观向小程序,4:每日咨询"`
  47. CountryCode string `description:"区号"`
  48. OutboundMobile string `description:"外呼手机号"`
  49. OutboundCountryCode string `description:"外呼手机号区号"`
  50. }
  51. type WxUserItem struct {
  52. UserId int `description:"用户id"`
  53. OpenId string `description:"open_id"`
  54. UnionId string `description:"union_id"`
  55. CompanyId int `description:"客户id"`
  56. NickName string `description:"用户昵称"`
  57. RealName string `description:"用户实际名称"`
  58. Mobile string `description:"手机号码"`
  59. BindAccount string `description:"绑定时的账号"`
  60. Email string `description:"邮箱"`
  61. Headimgurl string `description:"用户头像,最后一个数值代表正方形头像大小(有0、46、64、96、132数值可选,0代表640*640正方形头像),用户没有头像时该项为空"`
  62. HeadimgurlRecord string `description:"用户头像,最后一个数值代表正方形头像大小(有0、46、64、96、132数值可选,0代表640*640正方形头像),用户没有头像时该项为空"`
  63. ApplyMethod int `description:"0:未申请,1:已付费客户申请试用,2:非客户申请试用"`
  64. FirstLogin int `description:"是否第一次登陆"`
  65. IsFreeLogin int `description:"是否免登陆,true:免登陆,false:非免登陆"`
  66. LoginTime time.Time `description:"登录时间"`
  67. CreatedTime time.Time `description:"创建时间"`
  68. LastUpdatedTime time.Time `description:"最近一次修改时间"`
  69. SessionKey string `description:"微信小程序会话密钥"`
  70. CompanyName string `description:"公司名称"`
  71. IsRegister int `description:"是否注册:1:已注册,0:未注册"`
  72. CountryCode string `description:"手机国家区号"`
  73. OutboundMobile string `description:"外呼手机号"`
  74. OutboundCountryCode string `description:"外呼手机号区号"`
  75. IsMsgOutboundMobile int `description:"是否弹窗过绑定外呼手机号区号"`
  76. Source int
  77. IsMaker int `description:"是否是决策人"`
  78. Position string `description:"职务"`
  79. InviteCompany string `description:"邀请机构 ,LUODING:络町"`
  80. }
  81. func GetWxUserItemByUserId(userId int) (item *WxUserItem, err error) {
  82. o := orm.NewOrmUsingDB("weekly_report")
  83. sql := `SELECT a.*,b.company_name FROM wx_user AS a
  84. LEFT JOIN company AS b on a.company_id=b.company_id
  85. WHERE a.user_id=? `
  86. err = o.Raw(sql, userId).QueryRow(&item)
  87. return
  88. }
  89. func GetWxUserItemByMobile(mobile string) (item *WxUserItem, err error) {
  90. o := orm.NewOrmUsingDB("weekly_report")
  91. sql := `SELECT a.*,b.company_name FROM wx_user AS a
  92. LEFT JOIN company AS b on a.company_id=b.company_id
  93. WHERE a.mobile=? `
  94. err = o.Raw(sql, mobile).QueryRow(&item)
  95. return
  96. }
  97. type WxLoginResp struct {
  98. Authorization string
  99. UserId int
  100. FirstLogin int
  101. Headimgurl string `description:"用户头像"`
  102. Mobile string `description:"手机号"`
  103. Email string `description:"邮箱"`
  104. CompanyName string `description:"客户名称"`
  105. Status string `description:"状态"`
  106. EndDate string `description:"到期日期"`
  107. ProductName string `description:"客户类型名称"`
  108. }
  109. type WxGetUserInfoReq struct {
  110. RawData string `description:"rawData"`
  111. Signature string `description:"signature"`
  112. EncryptedData string `description:"encryptedData"`
  113. Iv string `description:"iv"`
  114. }
  115. func GetWxUserItemByUserUnionId(unionId string) (item *WxUserItem, err error) {
  116. o := orm.NewOrmUsingDB("weekly_report")
  117. sql := `SELECT a.*,r.headimgurl as headimgurl_record, b.company_name FROM wx_user AS a
  118. INNER JOIN company AS b on a.company_id=b.company_id
  119. INNER JOIN user_record as r ON r.user_id = a.user_id
  120. WHERE r.union_id=?
  121. GROUP BY a.user_id`
  122. err = o.Raw(sql, unionId).QueryRow(&item)
  123. return
  124. }
  125. // 根据用户手机号获取相关信息
  126. func GetWxUserItemByUserMobile(mobile string) (item *WxUserItem, err error) {
  127. o := orm.NewOrmUsingDB("weekly_report")
  128. sql := `SELECT
  129. a.user_id,
  130. a.real_name,
  131. a.headimgurl,
  132. a.company_id,
  133. a.mobile,
  134. a.email,
  135. r.union_id,
  136. r.open_id,
  137. b.company_name
  138. FROM
  139. wx_user AS a
  140. INNER JOIN company AS b ON a.company_id = b.company_id
  141. INNER JOIN user_record AS r ON r.bind_account = a.mobile
  142. WHERE
  143. a.mobile = ?
  144. and r.create_platform = 4
  145. GROUP BY
  146. a.mobile `
  147. err = o.Raw(sql, mobile).QueryRow(&item)
  148. return
  149. }
  150. // GetUserCountByMobile 获取数量
  151. func GetUserCountByMobile(mobile string) (count int, err error) {
  152. o := orm.NewOrmUsingDB("weekly_report")
  153. sqlCount := ` SELECT COUNT(1) AS count FROM wx_user WHERE mobile = ? `
  154. err = o.Raw(sqlCount, mobile).QueryRow(&count)
  155. return
  156. }
  157. // 添加用户信息
  158. func AddWxUser(item *WxUser) (lastId int64, err error) {
  159. o := orm.NewOrmUsingDB("weekly_report")
  160. lastId, err = o.Insert(item)
  161. return
  162. }
  163. // 变更联系人是否已注册状态
  164. func ModifyWxUserRegisterStatus(userId int) (err error) {
  165. o := orm.NewOrmUsingDB("weekly_report")
  166. sql := `UPDATE wx_user SET is_register=?,source=3,register_time=NOW() WHERE user_id = ? `
  167. _, err = o.Raw(sql, 1, userId).Exec()
  168. return
  169. }
  170. // 判断这个用户是否被设置消息提醒
  171. func GetUserRemind(uid int) (count int, err error) {
  172. sql := `SELECT COUNT(1) AS count FROM cygx_user_remind WHERE user_id = ? `
  173. err = orm.NewOrm().Raw(sql, uid).QueryRow(&count)
  174. return
  175. }
  176. func ModifyReportLastViewTime(uid int) (err error) {
  177. o := orm.NewOrmUsingDB("weekly_report")
  178. sql := ` UPDATE wx_user SET report_last_view_time=NOW()
  179. WHERE user_id=? `
  180. _, err = o.Raw(sql, uid).Exec()
  181. return
  182. }
  183. // GetWxUserListByUserIds 根据用户ID集合获取用户
  184. func GetWxUserListByUserIds(userIds string) (list []*WxUserItem, err error) {
  185. o := orm.NewOrmUsingDB("weekly_report")
  186. sql := ` SELECT u.*, c.company_name FROM wx_user AS u
  187. INNER JOIN company AS c ON c.company_id = u.company_id
  188. WHERE user_id IN (` + userIds + `) `
  189. _, err = o.Raw(sql).QueryRows(&list)
  190. return
  191. }
  192. // GetWxUserListByUserIdsArr 根据用户ID集合获取用户
  193. func GetWxUserListByUserIdsArr(userIds []int) (list []*WxUserItem, err error) {
  194. lenArr := len(userIds)
  195. if lenArr == 0 {
  196. return
  197. }
  198. o := orm.NewOrmUsingDB("weekly_report")
  199. sql := ` SELECT u.*, c.company_name FROM wx_user AS u
  200. INNER JOIN company AS c ON c.company_id = u.company_id
  201. WHERE user_id IN (` + utils.GetOrmInReplace(lenArr) + `) `
  202. _, err = o.Raw(sql, userIds).QueryRows(&list)
  203. return
  204. }