query.go 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. package admin
  2. import (
  3. "hongze/hongze_yb/global"
  4. )
  5. // GetByAdminId 根据admin_id获取系统用户信息
  6. func GetByAdminId(adminId int) (item *Admin, err error) {
  7. err = global.DEFAULT_MYSQL.Where("admin_id = ? ", adminId).First(&item).Error
  8. return
  9. }
  10. // GetAdminByMobile 通过手机号获取系统用户信息
  11. func GetAdminByMobile(mobile string) (item *Admin, err error) {
  12. err = global.DEFAULT_MYSQL.Model(Admin{}).Where("mobile = ? AND enabled = 1", mobile).First(&item).Error
  13. return
  14. }
  15. // GetAdminByEmail 通过邮箱获取系统用户信息
  16. func GetAdminByEmail(mobile string) (item *Admin, err error) {
  17. err = global.DEFAULT_MYSQL.Model(Admin{}).Where("email = ? AND enabled = 1", mobile).First(&item).Error
  18. return
  19. }
  20. // GetVWangInfo 获取沛总的账户信息
  21. func GetVWangInfo() (item *Admin, err error) {
  22. return GetByAdminId(66)
  23. }
  24. // ResearcherAdminAndUser 研究员admin信息及wx_user信息
  25. type ResearcherAdminAndUser struct {
  26. UserId int `description:"用户ID"`
  27. UserName string `description:"用户名称"`
  28. AdminId int `description:"管理员ID"`
  29. AdminName string `description:"管理员姓名"`
  30. OpenId string `description:"openid"`
  31. }
  32. // GetResearcherAdminAndWxUserByAdminId 通过adminId获取研究员admin及user信息
  33. func GetResearcherAdminAndWxUserByAdminId(adminId int) (item *ResearcherAdminAndUser, err error) {
  34. sql := `SELECT
  35. a.admin_id,
  36. a.real_name AS admin_name,
  37. a.open_id,
  38. b.user_id,
  39. b.real_name AS user_name
  40. FROM
  41. admin AS a
  42. JOIN wx_user AS b ON a.mobile = b.mobile
  43. WHERE
  44. a.admin_id = ? AND a.open_id != ""`
  45. err = global.DEFAULT_MYSQL.Raw(sql, adminId).First(&item).Error
  46. return
  47. }