一物一码
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.
 
 
 
 
 
 

40 lines
743 B

  1. package db
  2. import (
  3. "applet/app/db/model"
  4. "applet/app/utils/logx"
  5. "xorm.io/xorm"
  6. )
  7. type AdminDb struct {
  8. Db *xorm.Engine `json:"db"`
  9. }
  10. func (adminDb *AdminDb) Set() { // set方法
  11. adminDb.Db = Db
  12. }
  13. func (adminDb *AdminDb) GetAdmin(id int) (m *model.Admin, err error) {
  14. m = new(model.Admin)
  15. has, err := adminDb.Db.Where("adm_id =?", id).Get(m)
  16. if err != nil {
  17. return nil, logx.Error(err)
  18. }
  19. if has == false {
  20. return nil, nil
  21. }
  22. return m, nil
  23. }
  24. func (adminDb *AdminDb) GetAdminByUserName(userName string) (m *model.Admin, err error) {
  25. m = new(model.Admin)
  26. has, err := adminDb.Db.Where("username =?", userName).Get(m)
  27. if err != nil {
  28. return nil, logx.Error(err)
  29. }
  30. if has == false {
  31. return nil, nil
  32. }
  33. return m, nil
  34. }