12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970 |
- package shanghu
- import (
- orm "duoduo/database"
- "time"
- )
- type MerchantClientUser struct {
- ID int64 `gorm:"column:id;type:bigint(20);primary_key;AUTO_INCREMENT" json:"id"` // 主键
- Code string `gorm:"column:code;type:varchar(255)" json:"code"`
- ClientOpenID string `gorm:"column:client_open_id;type:varchar(255)" json:"client_open_id"` // open_id 唯一索引
- Phone string `gorm:"column:phone;type:varchar(24)" json:"phone"` // 手机号
- NickName string `gorm:"column:nick_name;type:varchar(255)" json:"nick_name"` // 微信用户名
- AvatarUrl string `gorm:"column:avatar_url;type:varchar(255)" json:"avatar_url"` // 头像url
- Admin int `gorm:"column:admin;type:int(11)" json:"admin"` // 1-管理员
- CreateBy int64 `gorm:"column:create_by;type:bigint(20)" json:"create_by"` // 创建者
- UpdateBy int64 `gorm:"column:update_by;type:bigint(20)" json:"update_by"` // 更新者
- CreatedAt time.Time `gorm:"column:created_at;type:datetime(3)" json:"created_at"` // 创建时间
- UpdatedAt time.Time `gorm:"column:updated_at;type:datetime(3)" json:"updated_at"` // 最后更新时间
- DeletedAt time.Time `gorm:"column:deleted_at;type:datetime(3);default:null" json:"deleted_at"` // 删除时间
- }
- func (m *MerchantClientUser) TableName() string {
- return "merchant_client_user"
- }
- func (m *MerchantClientUser) GetNum() int {
- var count int
- tableCount := orm.ShMysql.Table(m.TableName()).Where("client_open_id = ? ", m.ClientOpenID)
- tableCount.Count(&count)
- return count
- }
- func (m *MerchantClientUser) GetCodeNum() int {
- var count int
- tableCount := orm.ShMysql.Table(m.TableName()).Where("code = ? ", m.Code)
- tableCount.Count(&count)
- return count
- }
- func (m *MerchantClientUser) GetUserInfo() (MerchantClientUser, error) {
- var doc MerchantClientUser
- table := orm.ShMysql.Table(m.TableName())
- table = table.Where("client_open_id = ? ", m.ClientOpenID)
- if err := table.Select("*").First(&doc).Error; err != nil {
- return doc, err
- }
- return doc, nil
- }
- func (u *MerchantClientUser) Create() (MerchantClientUser, error) {
- var doc MerchantClientUser
- var err error
- doc = *u
- err = orm.ShMysql.Table(u.TableName()).Create(&doc).Error
- if err != nil {
- return doc, err
- }
- return doc, nil
- }
|