users_base.go 2.3 KB
package domain

import "time"

// 用户基础
type UsersBase struct {
	// 用户基础数据id
	UsersBaseId int64 `json:"usersBaseId,omitempty"`
	// 用户信息
	UsersInfo *UsersInfo `json:"usersInfo,omitempty"`
	// 手机号码
	Phone string `json:"phone,omitempty"`
	// 密码
	Password string `json:"password,omitempty"`
	// IM信息
	Im *Im `json:"im,omitempty"`
	// 关联的用户 (冗余)
	RelatedUsers []int64 `json:"relatedUsers,omitempty"`
	// 账号状态 1:正常 2.禁用 3:注销
	Status int `json:"status,omitempty"`
	// 创建时间
	CreatedAt time.Time `json:"createdAt,omitempty"`
	// 更新时间
	UpdatedAt time.Time `json:"updatedAt,omitempty"`
}

type UsersBaseRepository interface {
	Save(usersBase *UsersBase) (*UsersBase, error)
	Remove(usersBase *UsersBase) (*UsersBase, error)
	FindOne(queryOptions map[string]interface{}) (*UsersBase, error)
	Find(queryOptions map[string]interface{}) (int64, []*UsersBase, error)
}

func (usersBase *UsersBase) Identify() interface{} {
	if usersBase.UsersBaseId == 0 {
		return nil
	}
	return usersBase.UsersBaseId
}

func (usersBase *UsersBase) Update(data map[string]interface{}) error {
	if usersName, ok := data["usersName"]; ok {
		usersBase.UsersInfo.UsersName = usersName.(string)
	}
	if phone, ok := data["phone"]; ok {
		usersBase.UsersInfo.Phone = phone.(string)
	}
	if avatar, ok := data["avatar"]; ok {
		usersBase.UsersInfo.Avatar = avatar.(string)
	}
	if email, ok := data["email"]; ok {
		usersBase.UsersInfo.Email = email.(string)
	}
	if phone, ok := data["phone"]; ok {
		usersBase.Phone = phone.(string)
	}
	if password, ok := data["password"]; ok {
		usersBase.Password = password.(string)
	}
	if accid, ok := data["accid"]; ok {
		usersBase.Im.Accid = accid.(string)
	}
	if imToken, ok := data["imToken"]; ok {
		usersBase.Im.ImToken = imToken.(string)
	}
	if csAccountId, ok := data["csAccountId"]; ok {
		usersBase.Im.CsAccountId = csAccountId.(string)
	}
	if relatedUsers, ok := data["relatedUsers"]; ok {
		usersBase.RelatedUsers = relatedUsers.([]int64)
	}
	if status, ok := data["status"]; ok {
		usersBase.Status = status.(int)
	}
	if createdAt, ok := data["createdAt"]; ok {
		usersBase.CreatedAt = createdAt.(time.Time)
	}
	if updatedAt, ok := data["updatedAt"]; ok {
		usersBase.UpdatedAt = updatedAt.(time.Time)
	}
	return nil
}