package merchant_model import ( "time" "github.com/astaxie/beego" "github.com/astaxie/beego/orm" ) const ( merchants_tablename = "merchants" ) //2018/6/5 商家与用户一对一,修改成商家与用户一对多。新增商家-用户对应关系的表结构。 type Merchant struct { Id int64 `orm:"column(id);pk" json:"id"` //UserId int64 `orm:"column(user_id);null" json:"user_id"` Name string `orm:"column(name)" json:"name"` Contact string `orm:"column(contact)" json:"contact"` Tel string `orm:"column(tel)" json:"tel"` CreatedAt time.Time `orm:"column(created_at);null;auto_now_add;type(datetime)" json:"-"` UpdatedAt time.Time `orm:"column(updated_at);null;auto_now;type(datetime)" json:"-"` } func (self *Merchant) TableName() string { return merchants_tablename } /*func GetMerchantByUserId(userId int64) *Merchant { merchant := new(Merchant) if err := orm.NewOrm().QueryTable(merchant).Filter("user_id", userId).One(merchant); err != nil { beego.BeeLogger.Info("GetMerchantByUserId(%d) err=[%s]", userId, err) return nil } return merchant }*/ func GetMerchantById(id int64) *Merchant { merchant := new(Merchant) if err := orm.NewOrm().QueryTable(merchant).Filter("id", id).One(merchant); err != nil { beego.BeeLogger.Error("GetMerchantById(%d) err=[%s]", id, err) return nil } return merchant }