智盟项目
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.

42 lines
928 B

  1. package db
  2. import (
  3. "applet/app/db/model"
  4. "time"
  5. "xorm.io/xorm"
  6. )
  7. type MasterDb struct {
  8. Db *xorm.Engine `json:"db"`
  9. }
  10. func (masterDb *MasterDb) Set() { // set方法
  11. masterDb.Db = ZhimengDb
  12. }
  13. func (masterDb *MasterDb) GetMaster(mid string) *model.Master {
  14. var data model.Master
  15. get, err := masterDb.Db.Where("master_id=?", mid).Get(&data)
  16. if get == false || err != nil {
  17. data = model.Master{MasterId: mid, CreateTime: time.Now(), UpdateTime: time.Now(), FormWay: "api"}
  18. masterDb.Db.InsertOne(&data)
  19. }
  20. return &data
  21. }
  22. func (masterDb *MasterDb) GetMasterId(id int) *model.Master {
  23. var data model.Master
  24. get, err := masterDb.Db.Where("id=?", id).Get(&data)
  25. if get == false || err != nil {
  26. return nil
  27. }
  28. return &data
  29. }
  30. func (masterDb *MasterDb) MasterUpdate(data *model.Master) bool {
  31. get, err := masterDb.Db.Where("id=?", data.Id).Update(data)
  32. if get == 0 || err != nil {
  33. return false
  34. }
  35. return true
  36. }