merchant.go 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. package merchant_model
  2. import (
  3. "time"
  4. "github.com/astaxie/beego"
  5. "github.com/astaxie/beego/orm"
  6. )
  7. const (
  8. merchants_tablename = "merchants"
  9. )
  10. //2018/6/5 商家与用户一对一,修改成商家与用户一对多。新增商家-用户对应关系的表结构。
  11. type Merchant struct {
  12. Id int64 `orm:"column(id);pk" json:"id"`
  13. //UserId int64 `orm:"column(user_id);null" json:"user_id"`
  14. Name string `orm:"column(name)" json:"name"`
  15. Contact string `orm:"column(contact)" json:"contact"`
  16. Tel string `orm:"column(tel)" json:"tel"`
  17. CreatedAt time.Time `orm:"column(created_at);null;auto_now_add;type(datetime)" json:"-"`
  18. UpdatedAt time.Time `orm:"column(updated_at);null;auto_now;type(datetime)" json:"-"`
  19. }
  20. func (self *Merchant) TableName() string {
  21. return merchants_tablename
  22. }
  23. /*func GetMerchantByUserId(userId int64) *Merchant {
  24. merchant := new(Merchant)
  25. if err := orm.NewOrm().QueryTable(merchant).Filter("user_id", userId).One(merchant); err != nil {
  26. beego.BeeLogger.Info("GetMerchantByUserId(%d) err=[%s]", userId, err)
  27. return nil
  28. }
  29. return merchant
  30. }*/
  31. func GetMerchantById(id int64) *Merchant {
  32. merchant := new(Merchant)
  33. if err := orm.NewOrm().QueryTable(merchant).Filter("id", id).One(merchant); err != nil {
  34. beego.BeeLogger.Error("GetMerchantById(%d) err=[%s]", id, err)
  35. return nil
  36. }
  37. return merchant
  38. }