wx_user.go 3.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. package wx_user
  2. import (
  3. "github.com/beego/beego/v2/client/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. UserId int
  25. }
  26. //获取所有的用户openid列表
  27. func GetOpenIdList(openIdStr string) (items []*OpenIdList, err error) {
  28. sql := `SELECT DISTINCT ur.open_id,wu.user_id FROM wx_user AS wu
  29. INNER JOIN company AS c ON c.company_id = wu.company_id
  30. INNER JOIN company_product AS d ON c.company_id=d.company_id
  31. INNER join user_record as ur on wu.user_id=ur.user_id
  32. WHERE ur.open_id != "" and ur.create_platform=1 AND d.status IN('正式','试用','永续') `
  33. if openIdStr != "" {
  34. sql += ` AND ur.open_id in (` + openIdStr + `) `
  35. }
  36. _, err = orm.NewOrm().Raw(sql).QueryRows(&items)
  37. return
  38. }
  39. //根据手机号获取用户的openid列表
  40. func GetOpenIdListByMobile(mobile string) (items []*OpenIdList, err error) {
  41. sql := `SELECT DISTINCT ur.open_id,wu.user_id FROM wx_user AS wu
  42. INNER JOIN company AS c ON c.company_id = wu.company_id
  43. INNER join user_record as ur on wu.user_id=ur.user_id
  44. WHERE ur.open_id != "" and ur.create_platform=1 AND ur.subscribe = 1 AND wu.mobile=? `
  45. //if openIdStr != "" {
  46. // sql += ` AND ur.open_id in (` + openIdStr + `) `
  47. //}
  48. _, err = orm.NewOrm().Raw(sql, mobile).QueryRows(&items)
  49. return
  50. }
  51. // GetWxUserByCompanyIdAndMobile 根据客户ID及手机号获取用户
  52. func GetWxUserByCompanyIdAndMobile(companyId int, mobile string) (item *WxUser, err error) {
  53. o := orm.NewOrm()
  54. sql := ` SELECT * FROM wx_user WHERE company_id = ? AND mobile = ? LIMIT 1 `
  55. err = o.Raw(sql, companyId, mobile).QueryRow(&item)
  56. return
  57. }
  58. // UserCompanyInfoList 联系人和客户信息表
  59. type UserCompanyInfoList struct {
  60. UserId int `description:"联系人id"`
  61. CompanyId int `description:"客户id"`
  62. RealName string `description:"联系人真实姓名"`
  63. CompanyName string `description:"客户名称"`
  64. CompanyProductStatus string `description:"客户ficc状态"`
  65. }
  66. // GetUserListByUserIds 获取所有的用户openid列表
  67. func GetUserListByUserIds(userIds string) (items []*UserCompanyInfoList, err error) {
  68. sql := `SELECT a.user_id,a.real_name,b.company_name,c.status company_product_status FROM wx_user AS a
  69. INNER JOIN company AS b ON b.company_id = a.company_id
  70. INNER JOIN company_product AS c ON b.company_id=c.company_id
  71. WHERE a.user_id in ( ` + userIds + `) and c.product_id=1 `
  72. _, err = orm.NewOrm().Raw(sql).QueryRows(&items)
  73. return
  74. }