query.go 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. package wx_user
  2. import (
  3. "errors"
  4. "hongze/hongze_yb/global"
  5. "hongze/hongze_yb/utils"
  6. )
  7. // GetByMobile 根据手机号获取信息
  8. func GetByMobile(mobile string) (wxUser *WxUser, err error) {
  9. err = global.DEFAULT_MYSQL.Where("mobile = ? ", mobile).First(&wxUser).Error
  10. return
  11. }
  12. // GetByEmail 根据邮箱号号获取信息
  13. func GetByEmail(email string) (wxUser *WxUser, err error) {
  14. err = global.DEFAULT_MYSQL.Where("email = ? ", email).First(&wxUser).Error
  15. return
  16. }
  17. // GetByWhereMap 根据查询条件map获取信息
  18. func GetByWhereMap(where map[string]interface{}) (wxUser *WxUser, err error) {
  19. cond, whereVal, buildErr := utils.WhereBuild(where)
  20. if buildErr != nil {
  21. err = errors.New("系统异常,生成查询语句失败")
  22. return
  23. }
  24. err = global.DEFAULT_MYSQL.Where(cond, whereVal...).First(&wxUser).Error
  25. return
  26. }
  27. // GetByUserId 根据user_id获取用户信息
  28. func GetByUserId(userId int) (wxUser *WxUser, err error) {
  29. err = global.DEFAULT_MYSQL.Where("user_id = ? ", userId).First(&wxUser).Error
  30. return
  31. }
  32. // GetByUserIds 根据user_id获取用户信息
  33. func GetByUserIds(userIds []uint64) (list []*WxUser, err error) {
  34. err = global.DEFAULT_MYSQL.Model(WxUser{}).Where("user_id in ? ", userIds).Scan(&list).Error
  35. return
  36. }
  37. type OpenIdList struct {
  38. OpenID string
  39. UserID int
  40. }
  41. func GetOpenIdList() (items []*OpenIdList, err error) {
  42. sql := `SELECT DISTINCT ur.open_id,wu.user_id FROM wx_user AS wu
  43. INNER JOIN company AS c ON c.company_id = wu.company_id
  44. INNER JOIN company_product AS d ON c.company_id=d.company_id
  45. INNER join user_record as ur on wu.user_id=ur.user_id
  46. WHERE ur.open_id != "" AND ur.subscribe=1 and ur.create_platform=1 AND d.status IN('正式','试用','永续') `
  47. err = global.DEFAULT_MYSQL.Raw(sql).Scan(&items).Error
  48. return
  49. }
  50. func ModifyQaAvatarUrl(qaAvatarUrl string, userId uint64) (err error) {
  51. err = global.DEFAULT_MYSQL.Model(WxUser{}).Where("user_id=?", userId).Update("qa_avatar_url", qaAvatarUrl).Error
  52. return err
  53. }
  54. func GetOpenIdArrByVarietyTag(varietyTagId int) (items []string, err error) {
  55. sql := ` SELECT DISTINCT ur.open_id FROM wx_user AS wu
  56. INNER JOIN company AS c ON c.company_id = wu.company_id
  57. INNER JOIN company_product AS d ON c.company_id=d.company_id
  58. INNER JOIN user_record AS ur ON wu.user_id=ur.user_id
  59. INNER JOIN company_report_permission AS e ON d.company_id=e.company_id
  60. INNER JOIN chart_permission AS f ON e.chart_permission_id=f.chart_permission_id
  61. INNER JOIN variety_tag AS g ON f.chart_permission_id=g.chart_permission_id
  62. WHERE ur.open_id != "" AND ur.subscribe=1 AND ur.create_platform=1 AND d.status IN('正式','试用','永续') AND e.status IN('正式','试用','永续')
  63. AND g.variety_tag_id=?
  64. ORDER BY FIELD(c.company_id, 16) DESC, ur.user_record_id ASC `
  65. err = global.DEFAULT_MYSQL.Raw(sql, varietyTagId).Scan(&items).Error
  66. return
  67. }