From 3bcb57cd1012829382c4b46d5eb72fca5488993e Mon Sep 17 00:00:00 2001 From: chenweijian <820961417@qq.com> Date: Mon, 13 Mar 2023 15:40:00 +0800 Subject: [PATCH] =?UTF-8?q?=E9=80=80=E5=87=BA=E5=AE=B6=E6=97=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- domain/model/groupPower_m/family.go | 16 ++++++++++++++++ mysql/3.5.0.sql | 14 +++++++++++++- route/group_power_r/group_power.go | 26 +++++++++++++++++++------- route/router.go | 1 + 4 files changed, 49 insertions(+), 8 deletions(-) diff --git a/domain/model/groupPower_m/family.go b/domain/model/groupPower_m/family.go index bdcf6dc..9a3e161 100644 --- a/domain/model/groupPower_m/family.go +++ b/domain/model/groupPower_m/family.go @@ -16,6 +16,12 @@ type GroupPowerGrade struct { ExpireAt time.Time `json:"expire_at"` } +type GroupPowerQuitLog struct { + Id uint64 `json:"id"` + UserId uint64 `json:"user_id"` + MgrId uint64 `json:"mgr_id"` +} + func (this *GroupPower) Get(model *domain.Model) (*GroupPower, error) { group := new(GroupPower) err := model.Db.Where(this).First(&group).Error @@ -69,3 +75,13 @@ func (gpu *GroupPowerUser) GetGroupPowerUser(model *domain.Model) (*GroupPowerUs func (gpu *GroupPowerUser) Create(db *gorm.DB) error { return db.Create(gpu).Error } + +func QuitFamily(model *domain.Model, userId, mgrId, familyId uint64) error { + err := model.Db.Exec("delete from group_power_user where group_power_id = ? and user_id = ?", familyId, userId).Error + if err != nil { + return err + } + // log + log := &GroupPowerQuitLog{UserId: userId, MgrId: mgrId} + return model.Db.Create(log).Error +} diff --git a/mysql/3.5.0.sql b/mysql/3.5.0.sql index baa8a18..e23d879 100644 --- a/mysql/3.5.0.sql +++ b/mysql/3.5.0.sql @@ -29,4 +29,16 @@ CREATE TABLE `group_power_apply_join` ( PRIMARY KEY (`id`), KEY `group_power_id` (`group_power_id`), KEY `user_id` (`user_id`) USING BTREE -) ENGINE=InnoDB AUTO_INCREMENT=2 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci COMMENT='申请加入家族'; \ No newline at end of file +) ENGINE=InnoDB AUTO_INCREMENT=2 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci COMMENT='申请加入家族'; + +CREATE TABLE `group_power_quit_log` ( + `id` bigint NOT NULL AUTO_INCREMENT COMMENT 'id', + `user_id` bigint NOT NULL COMMENT '用户id', + `mgr_id` bigint NOT NULL COMMENT '操作人id', + `created_time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, + `updated_time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, + PRIMARY KEY (`id`), + KEY `user_id` (`user_id`) USING BTREE, + KEY `created_time` (`created_time`) USING BTREE, + KEY `mgr_id` (`mgr_id`) USING BTREE +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci; \ No newline at end of file diff --git a/route/group_power_r/group_power.go b/route/group_power_r/group_power.go index d74e4bd..ad6524b 100644 --- a/route/group_power_r/group_power.go +++ b/route/group_power_r/group_power.go @@ -1066,8 +1066,13 @@ func GroupPowerQuit(c *gin.Context) (*mycontext.MyContext, error) { if groupPUser == nil { return myContext, bizerr.GroupPowerHaveNoJoin } - // 退出家族 - // log + // 退出家族、log + err = model.Transaction(func(model *domain.Model) error { + return groupPower_m.QuitFamily(model, userId, userId, groupPUser.GroupPowerId) + }) + if err != nil { + return myContext, err + } resp.ResponseOk(c, nil) return myContext, nil @@ -1094,16 +1099,23 @@ func GroupPowerQuit(c *gin.Context) (*mycontext.MyContext, error) { if err != nil { return myContext, err } - groupPUser, err := gpU.GetGroupPowerUser(model) + // 被踢者 + gpUKick := groupPower_m.GroupPowerUser{UserId: userId} + kickGroupPUser, err := gpUKick.GetGroupPowerUser(model) if err != nil { return myContext, err } - if groupPUser == nil { + if kickGroupPUser == nil { return myContext, bizerr.GroupPowerHaveNoJoin } - // 退出家族 - // log + // 退出家族、log + err = model.Transaction(func(model *domain.Model) error { + return groupPower_m.QuitFamily(model, u.ID, userId, kickGroupPUser.GroupPowerId) + }) + if err != nil { + return myContext, err + } - resp.ResponseOk(c, u) + resp.ResponseOk(c, nil) return myContext, nil } diff --git a/route/router.go b/route/router.go index 3233338..a8e2aec 100644 --- a/route/router.go +++ b/route/router.go @@ -132,6 +132,7 @@ func InitRouter() *gin.Engine { groupPower.POST("/apply", wrapper(group_power_r.GroupPowerApplyJoin)) groupPower.POST("/apply/pass", wrapper(group_power_r.GroupPowerApplyPass)) groupPower.GET("/apply/list", wrapper(group_power_r.GroupPowerApplyList)) + groupPower.POST("/quit", wrapper(group_power_r.GroupPowerQuit)) } charge := v1.Group("/charge") -- 2.22.0