Ver código fonte

update

master
dengbiao 2 dias atrás
pai
commit
2365b87a43
5 arquivos alterados com 100 adições e 2 exclusões
  1. +5
    -0
      src/dao/user_dao.go
  2. +3
    -0
      src/dao/user_relate_dao.go
  3. +52
    -0
      src/implement/user_implement.go
  4. +37
    -0
      src/implement/user_relate_implement.go
  5. +3
    -2
      src/model/user.go

+ 5
- 0
src/dao/user_dao.go Ver arquivo

@@ -12,4 +12,9 @@ type UserDao interface {
UserFindAndCount(uid int64, phone string, nickname string, level int, page, limit int) (*[]model.User, int64, error)
UserFindByInviteCodes(codes ...string) (*[]model.User, error)
UserFindByCustomInviteCodes(codes ...string) (*[]model.User, error)
GetUserByCustomInviteCode(inviteCode string) (m *model.User, err error)
GetUserByInviteCode(inviteCode string) (m *model.User, err error)
UserInsert(m *model.User) (int64, error)
UpdateUser(m *model.User, columns ...string) (int64, error)
GetUser(id int64) (m *model.User, err error)
}

+ 3
- 0
src/dao/user_relate_dao.go Ver arquivo

@@ -13,4 +13,7 @@ type UserRelateDao interface {
PageFindUserRelateByParentUid(uid int64, page, pageSize int) (*[]model.UserRelate, int64, error)
PageFindUserRelateByParentUidAndLevel(uid int64, page, limit int, level int) (*[]model.UserRelate, int64, error)
UpdateUserRelateBySession(session *xorm.Session, uid int64, relate *model.UserRelate, forceColumns ...string) (int64, error)
UserRelateInsert(userRelate *model.UserRelate) (int64, error)
UserRelatesByPuIDAndLv(puid, lv interface{}) (*[]model.UserRelate, error)
UserRelatesByPuid(puid interface{}, limit, start int) (*[]model.UserRelate, error)
}

+ 52
- 0
src/implement/user_implement.go Ver arquivo

@@ -18,6 +18,58 @@ type UserDb struct {
Db *xorm.Engine
}

func (u UserDb) GetUser(id int64) (m *model.User, err error) {
m = new(model.User)
has, err := u.Db.Where("id =?", id).Get(m)
if err != nil {
return nil, zhios_order_relate_logx.Error(err)
}
if has == false {
return nil, nil
}
return m, nil
}

func (u UserDb) UpdateUser(m *model.User, columns ...string) (int64, error) {
affected, err := u.Db.Where("id =?", m.Id).Cols(columns...).Update(m)
if err != nil {
return 0, err
}
return affected, nil
}

func (u UserDb) UserInsert(m *model.User) (int64, error) {
_, err := u.Db.InsertOne(m)
if err != nil {
return 0, err
}
return m.Id, nil
}

func (u UserDb) GetUserByInviteCode(inviteCode string) (m *model.User, err error) {
m = new(model.User)
has, err := u.Db.Where("invite_code =?", inviteCode).Get(m)
if err != nil {
return nil, zhios_order_relate_logx.Error(err)
}
if has == false {
return nil, nil
}
return m, nil
}

func (u UserDb) GetUserByCustomInviteCode(inviteCode string) (m *model.User, err error) {
m = new(model.User)
has, err := u.Db.Where("custom_invite_code =?", inviteCode).Get(m)
if err != nil {
return nil, zhios_order_relate_logx.Error(err)
}
if has == false {
return nil, nil
}
return m, nil
}

func (u UserDb) UserFindByInviteCodes(codes ...string) (*[]model.User, error) {
var m []model.User
if err := u.Db.In("custom_invite_code", codes).Find(&m); err != nil {


+ 37
- 0
src/implement/user_relate_implement.go Ver arquivo

@@ -15,6 +15,43 @@ type UserRelateDb struct {
Db *xorm.Engine
}

func (u UserRelateDb) UserRelatesByPuid(puid interface{}, limit, start int) (*[]model.UserRelate, error) {
var m []model.UserRelate
if limit == 0 && start == 0 {
if err := u.Db.Where("parent_uid = ?", puid).
Cols(`id,parent_uid,uid,level,invite_time`).
Find(&m); err != nil {
return nil, zhios_order_relate_logx.Warn(err)
}
return &m, nil
}
if err := u.Db.Where("parent_uid = ?", puid).
Cols(`id,parent_uid,uid,level,invite_time`).Limit(limit, start).
Find(&m); err != nil {
return nil, zhios_order_relate_logx.Warn(err)
}

return &m, nil
}

func (u UserRelateDb) UserRelatesByPuIDAndLv(puid, lv interface{}) (*[]model.UserRelate, error) {
var m []model.UserRelate
if err := u.Db.Where("parent_uid = ? AND level = ?", puid, lv).
Cols(`id,parent_uid,uid,level,invite_time`).
Find(&m); err != nil {
return nil, zhios_order_relate_logx.Warn(err)
}
return &m, nil
}

func (u UserRelateDb) UserRelateInsert(userRelate *model.UserRelate) (int64, error) {
affected, err := u.Db.Insert(userRelate)
if err != nil {
return 0, err
}
return affected, nil
}

func (u UserRelateDb) FindUserRelate(uid int64, level int) (*[]model.UserRelate, error) {
var userRelate []model.UserRelate
sess := u.Db.Where("uid = ?", uid)


+ 3
- 2
src/model/user.go Ver arquivo

@@ -18,8 +18,9 @@ type User struct {
SystemInviteCode string `json:"system_invite_code" xorm:"not null default '' comment('系统邀请码') CHAR(50)"`
CustomInviteCode string `json:"custom_invite_code" xorm:"not null default '' comment('自定义邀请码') CHAR(50)"`
Memo string `json:"memo" xorm:"not null default '' comment('备注信息') VARCHAR(244)"`
IsRealName int `json:"is_real_name" xorm:"not null default 0 comment('0.未知,1.未实名,2.已实名') TINYINT(1)"`
RegisterType int `json:"register_type" xorm:"not null comment('注册类型(0.未知, 1:免验证码手机号注册,2.微信授权)') TINYINT(3)"`
IsRealName int `json:"is_real_name" xorm:"not null default 0 comment('是否实名(0:未实名 1.已实名)') TINYINT(1)"`
RegisterType int `json:"register_type" xorm:"not null comment('注册类型(1:APP注册、2:H5注册)') TINYINT(3)"`
LastLoginAt string `json:"last_login_at" xorm:"not null default 'CURRENT_TIMESTAMP' comment('上次登录时间') DATETIME"`
CreateAt string `json:"create_at" xorm:"not null default 'CURRENT_TIMESTAMP' DATETIME"`
UpdateAt string `json:"update_at" xorm:"not null default 'CURRENT_TIMESTAMP' DATETIME"`
}

Carregando…
Cancelar
Salvar