广告平台(总站长使用)
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.

agent_implement.go 1.2 KiB

4 months ago
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. package implement
  2. import (
  3. "applet/app/db/dao"
  4. "applet/app/db/model"
  5. "applet/app/utils/logx"
  6. "reflect"
  7. "xorm.io/xorm"
  8. )
  9. func NewAgentDb(engine *xorm.Engine) dao.AgentDao {
  10. return &AgentDb{Db: engine}
  11. }
  12. type AgentDb struct {
  13. Db *xorm.Engine
  14. }
  15. func (a AgentDb) GetAgentByUsername(username string) (agent *model.Agent, err error) {
  16. agent = new(model.Agent)
  17. has, err := a.Db.Where("username =?", username).Get(agent)
  18. if err != nil {
  19. return nil, logx.Error(err)
  20. }
  21. if has == false {
  22. return nil, nil
  23. }
  24. return agent, nil
  25. }
  26. func (a AgentDb) AgentInsert(m *model.Agent) (int64, error) {
  27. insertAffected, err := a.Db.InsertOne(m)
  28. if err != nil {
  29. return 0, err
  30. }
  31. return insertAffected, nil
  32. }
  33. func (a AgentDb) AgentDeleteBySession(session *xorm.Session, id interface{}) (int64, error) {
  34. if reflect.TypeOf(id).Kind() == reflect.Slice {
  35. return session.In("id", id).Delete(model.Admin{})
  36. } else {
  37. return session.Where("id = ?", id).Delete(model.Admin{})
  38. }
  39. }
  40. func (a AgentDb) UpdateAgent(m *model.Agent, columns ...string) (int64, error) {
  41. affected, err := a.Db.Where("id =?", m.Id).Cols(columns...).Update(m)
  42. if err != nil {
  43. return 0, err
  44. }
  45. return affected, nil
  46. }