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

34 lines
724 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) MasterUpdate(data *model.Master) bool {
  23. get, err := masterDb.Db.Where("id=?", data.Id).Update(data)
  24. if get == 0 || err != nil {
  25. return false
  26. }
  27. return true
  28. }