golang-im聊天
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

master_dao.go 915 B

2 years ago
2 years ago
2 years ago
1234567891011121314151617181920212223242526272829303132333435363738
  1. package repo
  2. import (
  3. "gim/internal/business/domain/user/model"
  4. "gim/pkg/db"
  5. "gim/pkg/gerrors"
  6. "github.com/jinzhu/gorm"
  7. )
  8. type masterDao struct{}
  9. var MasterDao = new(masterDao)
  10. // Get 获取站长信息
  11. func (*masterDao) Get(masterId int64) (*model.Master, error) {
  12. var master = model.Master{}
  13. err := db.DB.Where("master_id = ?", masterId).First(&master).Error
  14. if err != nil && err != gorm.ErrRecordNotFound {
  15. return nil, gerrors.WrapError(err)
  16. }
  17. if err == gorm.ErrRecordNotFound {
  18. return nil, nil
  19. }
  20. return &master, err
  21. }
  22. // GetByPhone 根据手机号获取用户信息
  23. func (*masterDao) GetByPhone(phone string) (*model.Master, error) {
  24. var master model.Master
  25. err := db.DB.First(&master, "phone_number = ?", phone).Error
  26. if err != nil && err != gorm.ErrRecordNotFound {
  27. return nil, gerrors.WrapError(err)
  28. }
  29. if err == gorm.ErrRecordNotFound {
  30. return nil, nil
  31. }
  32. return &master, err
  33. }