1234567891011121314151617181920212223242526272829303132333435 |
- package mysql
- import orm "duoduo/database"
- type User struct {
- CreateTime string `gorm:"column:create_time" json:"createTime"`
- OpenID string `gorm:"column:open_id" json:"openId"`
- Phone string `gorm:"column:phone" json:"phone"`
- Pid string `gorm:"column:pid" json:"pid"`
- UpdateTime string `gorm:"column:update_time" json:"updateTime"`
- }
- // TableName sets the insert table name for this struct type
- func (u *User) TableName() string {
- return "user"
- }
- func (u *User) GetNum() int {
- var count int
- tableCount := orm.Eloquent.Table(u.TableName()).Where("open_id = ? ", u.OpenID)
- tableCount.Count(&count)
- return count
- }
- func (u *User) Create() (User, error) {
- var doc User
- result := orm.Eloquent.Table(u.TableName()).Create(&u)
- if result.Error != nil {
- err := result.Error
- return doc, err
- }
- doc = *u
- return doc, nil
- }
|