wx_user.go 3.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. package wx_user
  2. import (
  3. "github.com/rdlucklib/rdluck_tools/orm"
  4. "time"
  5. )
  6. type WxUser struct {
  7. UserId int64 `orm:"column(user_id);pk"`
  8. Mobile string
  9. Email string
  10. CompanyId int
  11. RealName string `description:"姓名"`
  12. CreatedTime time.Time
  13. MobileTwo string `description:"备用手机号"`
  14. BusinessCardUrl string `description:"名片"`
  15. IsMaker int `description:"是否决策人,1:是,0:否"`
  16. Position string `description:"职位"`
  17. Sex int `description:"普通用户性别,1为男性,2为女性"`
  18. DepartmentName string `description:"联系人部门"`
  19. RegisterTime time.Time
  20. RegisterPlatform int
  21. }
  22. type OpenIdList struct {
  23. OpenId string
  24. }
  25. //获取所有的用户openid列表
  26. func GetOpenIdList(openIdStr string) (items []*OpenIdList, err error) {
  27. sql := `SELECT DISTINCT ur.open_id FROM wx_user AS wu
  28. INNER JOIN company AS c ON c.company_id = wu.company_id
  29. INNER JOIN company_product AS d ON c.company_id=d.company_id
  30. INNER join user_record as ur on wu.user_id=ur.user_id
  31. WHERE ur.open_id != "" and ur.create_platform=1 AND d.status IN('正式','试用','永续') `
  32. if openIdStr != "" {
  33. sql += ` AND ur.open_id in (` + openIdStr + `) `
  34. }
  35. _, err = orm.NewOrm().Raw(sql).QueryRows(&items)
  36. return
  37. }
  38. //根据手机号获取用户的openid列表
  39. func GetOpenIdListByMobile(mobile, openIdStr string) (items []*OpenIdList, err error) {
  40. sql := `SELECT DISTINCT ur.open_id FROM wx_user AS wu
  41. INNER JOIN company AS c ON c.company_id = wu.company_id
  42. INNER join user_record as ur on wu.user_id=ur.user_id
  43. WHERE ur.open_id != "" and ur.create_platform=1 AND wu.mobile=? `
  44. if openIdStr != "" {
  45. sql += ` AND ur.open_id in (` + openIdStr + `) `
  46. }
  47. _, err = orm.NewOrm().Raw(sql, mobile).QueryRows(&items)
  48. return
  49. }
  50. type WxUserItem struct {
  51. UserId int
  52. RealName string
  53. Mobile string
  54. Email string
  55. CompanyName string
  56. }
  57. // GetWxUserByMobile 根据手机号获取用户信息
  58. func GetWxUserByMobile(mobile string) (item *WxUserItem, err error) {
  59. sql := `SELECT a.user_id,a.real_name,a.mobile,b.company_name FROM wx_user AS a
  60. INNER JOIN company AS b ON a.company_id = b.company_id
  61. WHERE a.mobile=? `
  62. err = orm.NewOrm().Raw(sql, mobile).QueryRow(&item)
  63. return
  64. }
  65. // GetWxUserByEmail 根据邮箱获取用户信息
  66. func GetWxUserByEmail(email string) (item *WxUserItem, err error) {
  67. sql := `SELECT a.user_id,a.real_name,a.mobile,b.company_name FROM wx_user AS a
  68. INNER JOIN company AS b ON a.company_id = b.company_id
  69. WHERE a.email=? `
  70. err = orm.NewOrm().Raw(sql, email).QueryRow(&item)
  71. return
  72. }
  73. // GetWxUserByMobile 根据手机号获取用户信息
  74. func GetWxUserByMobileStr(mobile string) (item *WxUserItem, err error) {
  75. sql := `SELECT a.user_id,a.real_name,a.mobile,b.company_name FROM wx_user AS a
  76. INNER JOIN company AS b ON a.company_id = b.company_id
  77. WHERE a.mobile IN (` + mobile + `) LIMIT 1 `
  78. err = orm.NewOrm().Raw(sql).QueryRow(&item)
  79. return
  80. }