query.go 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. package wx_user
  2. import (
  3. "errors"
  4. "hongze/hongze_yb/global"
  5. "hongze/hongze_yb/services/wechat"
  6. "hongze/hongze_yb/utils"
  7. )
  8. // GetByMobile 根据手机号获取信息
  9. func GetByMobile(mobile string) (wxUser *WxUser, err error) {
  10. err = global.DEFAULT_MYSQL.Where("mobile = ? ", mobile).First(&wxUser).Error
  11. return
  12. }
  13. // GetByEmail 根据邮箱号号获取信息
  14. func GetByEmail(email string) (wxUser *WxUser, err error) {
  15. err = global.DEFAULT_MYSQL.Where("email = ? ", email).First(&wxUser).Error
  16. return
  17. }
  18. // GetByWhereMap 根据查询条件map获取信息
  19. func GetByWhereMap(where map[string]interface{}) (wxUser *WxUser, err error) {
  20. cond, whereVal, buildErr := utils.WhereBuild(where)
  21. if buildErr != nil {
  22. err = errors.New("系统异常,生成查询语句失败")
  23. return
  24. }
  25. err = global.DEFAULT_MYSQL.Where(cond, whereVal...).First(&wxUser).Error
  26. return
  27. }
  28. // GetByUserId 根据user_id获取用户信息
  29. func GetByUserId(userId int) (wxUser *WxUser, err error) {
  30. err = global.DEFAULT_MYSQL.Where("user_id = ? ", userId).First(&wxUser).Error
  31. return
  32. }
  33. // GetByUserIds 根据user_id获取用户信息
  34. func GetByUserIds(userIds []uint64) (list []*WxUser, err error) {
  35. err = global.DEFAULT_MYSQL.Model(WxUser{}).Where("user_id in ? ", userIds).Scan(&list).Error
  36. return
  37. }
  38. func GetOpenIdList() (items []*wechat.OpenIdList, err error) {
  39. sql := `SELECT DISTINCT ur.open_id,wu.user_id FROM wx_user AS wu
  40. INNER JOIN company AS c ON c.company_id = wu.company_id
  41. INNER JOIN company_product AS d ON c.company_id=d.company_id
  42. INNER join user_record as ur on wu.user_id=ur.user_id
  43. WHERE ur.open_id != "" AND ur.subscribe=1 and ur.create_platform=1 AND d.status IN('正式','试用','永续') `
  44. err = global.DEFAULT_MYSQL.Raw(sql).Scan(&items).Error
  45. return
  46. }