From d30667f88dfc16623d10dec206574180dafde030 Mon Sep 17 00:00:00 2001 From: shenjiachi Date: Tue, 19 Nov 2024 14:37:35 +0800 Subject: [PATCH] add membe_center --- src/dao/user_dao.go | 7 +++-- src/dao/user_level_dao.go | 3 ++ src/dao/user_relate_dao.go | 6 +++- src/dao/user_tag_dao.go | 8 ++++- src/dao/user_tag_records_dao.go | 8 +++-- src/implement/user_implement.go | 6 ++-- src/implement/user_level_implement.go | 25 +++++++++++++++ src/implement/user_relate_implement.go | 16 ++++++++++ src/implement/user_tag_implement.go | 34 +++++++++++++++++++++ src/implement/user_tag_records_implement.go | 14 +++++++-- 10 files changed, 115 insertions(+), 12 deletions(-) diff --git a/src/dao/user_dao.go b/src/dao/user_dao.go index 133b114..cb2aad1 100644 --- a/src/dao/user_dao.go +++ b/src/dao/user_dao.go @@ -1,10 +1,13 @@ package dao -import "code.fnuoos.com/EggPlanet/egg_models.git/src/model" +import ( + "code.fnuoos.com/EggPlanet/egg_models.git/src/model" + "xorm.io/xorm" +) type UserDao interface { UserGetOneByParams(params map[string]interface{}) (*model.User, error) UserFindByParams(params map[string]interface{}) ([]model.User, error) - UserUpdate(id interface{}, user *model.User, forceColumns ...string) (int64, error) + UserUpdateBySession(session *xorm.Session, id interface{}, user *model.User, forceColumns ...string) (int64, error) UserFindAndCount(uid int64, phone string, nickname string, level int, page, limit int) (*[]model.User, int64, error) } diff --git a/src/dao/user_level_dao.go b/src/dao/user_level_dao.go index 9e14bf6..673041d 100644 --- a/src/dao/user_level_dao.go +++ b/src/dao/user_level_dao.go @@ -9,4 +9,7 @@ type UserLevelDao interface { UserLevelByID(id interface{}) (*model.UserLevel, error) //UserLevelAllByAsc 获取所有开启等级并且升序返回 UserLevelAllByAsc() ([]*model.UserLevel, error) + // UserLevelAllByAscByPage 获取所有开启等级升序分页返回 + UserLevelAllByAscByPage(page, limit int) ([]*model.UserLevel, int64, error) + UserLevelUpdate(id interface{}, level *model.UserLevel, forceColumns ...string) (int64, error) } diff --git a/src/dao/user_relate_dao.go b/src/dao/user_relate_dao.go index 4be9b20..8d88263 100644 --- a/src/dao/user_relate_dao.go +++ b/src/dao/user_relate_dao.go @@ -1,6 +1,9 @@ package dao -import "code.fnuoos.com/EggPlanet/egg_models.git/src/model" +import ( + "code.fnuoos.com/EggPlanet/egg_models.git/src/model" + "xorm.io/xorm" +) type UserRelateDao interface { FindUserRelate(uid int64, level int) (*[]model.UserRelate, error) @@ -9,4 +12,5 @@ type UserRelateDao interface { SumUserRelateByParentUid(parentUid string) (total int64, userRelate []*model.UserRelate, err error) 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) } diff --git a/src/dao/user_tag_dao.go b/src/dao/user_tag_dao.go index 25c6f98..70337c3 100644 --- a/src/dao/user_tag_dao.go +++ b/src/dao/user_tag_dao.go @@ -1,8 +1,14 @@ package dao -import "code.fnuoos.com/EggPlanet/egg_models.git/src/model" +import ( + "code.fnuoos.com/EggPlanet/egg_models.git/src/model" + "xorm.io/xorm" +) type UserTagDao interface { //TODO:: You can add specific method definitions here UserTagAllByAsc() ([]*model.UserTag, error) + UserTagAllByAscByPage(page, limit int) (*[]model.UserTag, int64, error) + UserTagUpdate(id interface{}, userTag *model.UserTag, forceColumns ...string) (int64, error) + UserTagDeleteBySession(session *xorm.Session, tagID interface{}) (int64, error) } diff --git a/src/dao/user_tag_records_dao.go b/src/dao/user_tag_records_dao.go index cb944f7..e26ef37 100644 --- a/src/dao/user_tag_records_dao.go +++ b/src/dao/user_tag_records_dao.go @@ -1,9 +1,13 @@ package dao -import "code.fnuoos.com/EggPlanet/egg_models.git/src/model" +import ( + "code.fnuoos.com/EggPlanet/egg_models.git/src/model" + "xorm.io/xorm" +) type UserTagRecordsDao interface { //TODO:: You can add specific method definitions here UserTagRecordsGetOneByParams(params map[string]interface{}) (*model.UserTagRecords, error) - UserTagRecordsUpdate(uid interface{}, user *model.UserTagRecords, forceColumns ...string) (int64, error) + UserTagRecordsUpdateBySession(session *xorm.Session, uid interface{}, user *model.UserTagRecords, forceColumns ...string) (int64, error) + UserTagRecordDeleteBySession(session *xorm.Session, tagID int64) (int64, error) } diff --git a/src/implement/user_implement.go b/src/implement/user_implement.go index f9fb997..ac404f5 100644 --- a/src/implement/user_implement.go +++ b/src/implement/user_implement.go @@ -44,15 +44,15 @@ func (u UserDb) UserFindByParams(params map[string]interface{}) ([]model.User, e return m, nil } -func (u UserDb) UserUpdate(id interface{}, user *model.User, forceColumns ...string) (int64, error) { +func (u UserDb) UserUpdateBySession(session *xorm.Session, id interface{}, user *model.User, forceColumns ...string) (int64, error) { var ( affected int64 err error ) if forceColumns != nil { - affected, err = u.Db.Where("id=?", id).MustCols(forceColumns...).Update(user) + affected, err = session.Where("id=?", id).MustCols(forceColumns...).Update(user) } else { - affected, err = u.Db.Where("id=?", id).Update(user) + affected, err = session.Where("id=?", id).Update(user) } if err != nil { return 0, err diff --git a/src/implement/user_level_implement.go b/src/implement/user_level_implement.go index 6e558b5..3420b33 100644 --- a/src/implement/user_level_implement.go +++ b/src/implement/user_level_implement.go @@ -49,3 +49,28 @@ func (u UserLevelDb) UserLevelAllByAsc() ([]*model.UserLevel, error) { } return m, nil } + +func (u UserLevelDb) UserLevelAllByAscByPage(page, limit int) ([]*model.UserLevel, int64, error) { + var m []*model.UserLevel + total, err := u.Db.Where("is_use = ?", 1).Asc("level_weight").FindAndCount(&m) + if err != nil { + return nil, 0, zhios_order_relate_logx.Warn(err) + } + return m, total, nil +} + +func (u UserLevelDb) UserLevelUpdate(id interface{}, userLevel *model.UserLevel, forceColumns ...string) (int64, error) { + var ( + affected int64 + err error + ) + if forceColumns != nil { + affected, err = u.Db.Where("id=?", id).MustCols(forceColumns...).Update(userLevel) + } else { + affected, err = u.Db.Where("id=?", id).Update(userLevel) + } + if err != nil { + return 0, zhios_order_relate_logx.Error(err.Error()) + } + return affected, nil +} diff --git a/src/implement/user_relate_implement.go b/src/implement/user_relate_implement.go index 5ea9944..ef3c2e5 100644 --- a/src/implement/user_relate_implement.go +++ b/src/implement/user_relate_implement.go @@ -85,3 +85,19 @@ func (u UserRelateDb) PageFindUserRelateByParentUidAndLevel(uid int64, page, lim } return &userRelate, total, nil } + +func (u UserRelateDb) UpdateUserRelateBySession(session *xorm.Session, uid int64, relate *model.UserRelate, forceColumns ...string) (int64, error) { + var ( + affected int64 + err error + ) + if forceColumns != nil { + affected, err = session.Where("uid=?", uid).MustCols(forceColumns...).Update(relate) + } else { + affected, err = session.Where("uid=?", uid).Update(relate) + } + if err != nil { + return 0, zhios_order_relate_logx.Error(err.Error()) + } + return affected, nil +} diff --git a/src/implement/user_tag_implement.go b/src/implement/user_tag_implement.go index c60d8e9..62914fc 100644 --- a/src/implement/user_tag_implement.go +++ b/src/implement/user_tag_implement.go @@ -4,6 +4,7 @@ import ( "code.fnuoos.com/EggPlanet/egg_models.git/src/dao" "code.fnuoos.com/EggPlanet/egg_models.git/src/model" zhios_order_relate_logx "code.fnuoos.com/EggPlanet/egg_models.git/utils/logx" + "reflect" "xorm.io/xorm" ) @@ -23,3 +24,36 @@ func (u UserTagDb) UserTagAllByAsc() ([]*model.UserTag, error) { } return m, nil } + +func (u UserTagDb) UserTagAllByAscByPage(page, limit int) (*[]model.UserTag, int64, error) { + var m []model.UserTag + total, err := u.Db.Asc("id").Limit(limit, (page-1)*limit).FindAndCount(&m) + if err != nil { + return nil, 0, zhios_order_relate_logx.Error(err) + } + return &m, total, nil +} + +func (u UserTagDb) UserTagUpdate(id interface{}, userTag *model.UserTag, forceColumns ...string) (int64, error) { + var ( + affected int64 + err error + ) + if forceColumns != nil { + affected, err = u.Db.Where("id=?", id).MustCols(forceColumns...).Update(userTag) + } else { + affected, err = u.Db.Where("id=?", id).Update(userTag) + } + if err != nil { + return 0, zhios_order_relate_logx.Error(err.Error()) + } + return affected, nil +} + +func (u UserTagDb) UserTagDeleteBySession(session *xorm.Session, tagID interface{}) (int64, error) { + if reflect.TypeOf(tagID).Kind() == reflect.Slice { + return session.In("id", tagID).Delete(model.UserTag{}) + } else { + return session.Where("id = ?", tagID).Delete(model.UserTag{}) + } +} diff --git a/src/implement/user_tag_records_implement.go b/src/implement/user_tag_records_implement.go index af8969c..41d8611 100644 --- a/src/implement/user_tag_records_implement.go +++ b/src/implement/user_tag_records_implement.go @@ -25,18 +25,26 @@ func (u UserTagRecordsDb) UserTagRecordsGetOneByParams(params map[string]interfa return &m, nil } -func (u UserTagRecordsDb) UserTagRecordsUpdate(uid interface{}, user *model.UserTagRecords, forceColumns ...string) (int64, error) { +func (u UserTagRecordsDb) UserTagRecordsUpdateBySession(session *xorm.Session, uid interface{}, user *model.UserTagRecords, forceColumns ...string) (int64, error) { var ( affected int64 err error ) if forceColumns != nil { - affected, err = u.Db.Where("uid=?", uid).Cols(forceColumns...).Update(user) + affected, err = session.Where("uid=?", uid).Cols(forceColumns...).Update(user) } else { - affected, err = u.Db.Where("uid=?", uid).Update(user) + affected, err = session.Where("uid=?", uid).Update(user) } if err != nil { return 0, err } return affected, nil } + +func (u UserTagRecordsDb) UserTagRecordDeleteBySession(session *xorm.Session, tagID int64) (int64, error) { + affected, err := session.Where("tag_id = ?", tagID).Delete(model.UserTagRecords{}) + if err != nil { + return 0, zhios_order_relate_logx.Error(err.Error()) + } + return affected, nil +}