feat 微信登录
This commit is contained in:
@@ -15,13 +15,15 @@ const TableNameUser = "users"
|
||||
|
||||
// User mapped from table <users>
|
||||
type User struct {
|
||||
ID uint64 `gorm:"column:id;primaryKey;autoIncrement:true" json:"id"`
|
||||
Sn string `gorm:"column:sn;not null;comment:业务唯一编号" json:"sn"` // 业务唯一编号
|
||||
Name string `gorm:"column:name;not null" json:"name"`
|
||||
Phone string `gorm:"column:phone;not null" json:"phone"`
|
||||
CreatedAt time.Time `gorm:"column:created_at;not null" json:"created_at"`
|
||||
UpdatedAt time.Time `gorm:"column:updated_at;not null" json:"updated_at"`
|
||||
DeletedAt gorm.DeletedAt `gorm:"column:deleted_at" json:"deleted_at"`
|
||||
ID uint64 `gorm:"column:id;primaryKey;autoIncrement:true" json:"id"`
|
||||
Sn string `gorm:"column:sn;not null;comment:业务唯一编号" json:"sn"` // 业务唯一编号
|
||||
Name string `gorm:"column:name;not null" json:"name"`
|
||||
Phone string `gorm:"column:phone" json:"phone"`
|
||||
WxUnionID string `gorm:"column:wx_union_id;comment:微信用户唯一标识" json:"wx_union_id"` // 微信用户唯一标识
|
||||
WxMiniOpenID string `gorm:"column:wx_mini_open_id;comment:微信小程序的openID" json:"wx_mini_open_id"` // 微信小程序的openID
|
||||
CreatedAt time.Time `gorm:"column:created_at;not null" json:"created_at"`
|
||||
UpdatedAt time.Time `gorm:"column:updated_at;not null" json:"updated_at"`
|
||||
DeletedAt gorm.DeletedAt `gorm:"column:deleted_at" json:"deleted_at"`
|
||||
}
|
||||
|
||||
// TableName User's table name
|
||||
|
||||
@@ -31,6 +31,8 @@ func newUser(db *gorm.DB, opts ...gen.DOOption) user {
|
||||
_user.Sn = field.NewString(tableName, "sn")
|
||||
_user.Name = field.NewString(tableName, "name")
|
||||
_user.Phone = field.NewString(tableName, "phone")
|
||||
_user.WxUnionID = field.NewString(tableName, "wx_union_id")
|
||||
_user.WxMiniOpenID = field.NewString(tableName, "wx_mini_open_id")
|
||||
_user.CreatedAt = field.NewTime(tableName, "created_at")
|
||||
_user.UpdatedAt = field.NewTime(tableName, "updated_at")
|
||||
_user.DeletedAt = field.NewField(tableName, "deleted_at")
|
||||
@@ -43,14 +45,16 @@ func newUser(db *gorm.DB, opts ...gen.DOOption) user {
|
||||
type user struct {
|
||||
userDo userDo
|
||||
|
||||
ALL field.Asterisk
|
||||
ID field.Uint64
|
||||
Sn field.String // 业务唯一编号
|
||||
Name field.String
|
||||
Phone field.String
|
||||
CreatedAt field.Time
|
||||
UpdatedAt field.Time
|
||||
DeletedAt field.Field
|
||||
ALL field.Asterisk
|
||||
ID field.Uint64
|
||||
Sn field.String // 业务唯一编号
|
||||
Name field.String
|
||||
Phone field.String
|
||||
WxUnionID field.String // 微信用户唯一标识
|
||||
WxMiniOpenID field.String // 微信小程序的openID
|
||||
CreatedAt field.Time
|
||||
UpdatedAt field.Time
|
||||
DeletedAt field.Field
|
||||
|
||||
fieldMap map[string]field.Expr
|
||||
}
|
||||
@@ -71,6 +75,8 @@ func (u *user) updateTableName(table string) *user {
|
||||
u.Sn = field.NewString(table, "sn")
|
||||
u.Name = field.NewString(table, "name")
|
||||
u.Phone = field.NewString(table, "phone")
|
||||
u.WxUnionID = field.NewString(table, "wx_union_id")
|
||||
u.WxMiniOpenID = field.NewString(table, "wx_mini_open_id")
|
||||
u.CreatedAt = field.NewTime(table, "created_at")
|
||||
u.UpdatedAt = field.NewTime(table, "updated_at")
|
||||
u.DeletedAt = field.NewField(table, "deleted_at")
|
||||
@@ -98,11 +104,13 @@ func (u *user) GetFieldByName(fieldName string) (field.OrderExpr, bool) {
|
||||
}
|
||||
|
||||
func (u *user) fillFieldMap() {
|
||||
u.fieldMap = make(map[string]field.Expr, 7)
|
||||
u.fieldMap = make(map[string]field.Expr, 9)
|
||||
u.fieldMap["id"] = u.ID
|
||||
u.fieldMap["sn"] = u.Sn
|
||||
u.fieldMap["name"] = u.Name
|
||||
u.fieldMap["phone"] = u.Phone
|
||||
u.fieldMap["wx_union_id"] = u.WxUnionID
|
||||
u.fieldMap["wx_mini_open_id"] = u.WxMiniOpenID
|
||||
u.fieldMap["created_at"] = u.CreatedAt
|
||||
u.fieldMap["updated_at"] = u.UpdatedAt
|
||||
u.fieldMap["deleted_at"] = u.DeletedAt
|
||||
|
||||
@@ -82,3 +82,18 @@ func (d *UserDao) FindByPhone(phone string) (*model.User, error) {
|
||||
}
|
||||
return first, nil
|
||||
}
|
||||
|
||||
// FindByWxUnionIDOrOpenID 通过微信unionID或openID查找用户
|
||||
func (d *UserDao) FindByWxUnionIDOrOpenID(unionID, openID string) (*model.User, error) {
|
||||
q := d.query.User.WithContext(d.ctx)
|
||||
if unionID != "" {
|
||||
q = q.Where(d.query.User.WxUnionID.Eq(unionID))
|
||||
} else {
|
||||
q = q.Where(d.query.User.WxMiniOpenID.Eq(openID))
|
||||
}
|
||||
first, err := q.First()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return first, nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user