diff --git a/domain/model/groupPower_m/family.go b/domain/model/groupPower_m/family.go index bdcf6dcb4cdb0cd796d772155eeedd535b5e1440..9a3e16135a4b984845183b7907e4cf8b88e2308e 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 baa8a18219d6fe1d801aeafb588c2008f4b370bc..e23d879585580110690f9f0b99d7163db878f022 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 d74e4bdc4d1c6d8c1293f77725c78aa776183c88..ad6524bd932a70f7184cab6f0d565e05ba24f125 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 323333888d36bcabb09425e5e24327ab0fc11776..a8e2aec2567e339a8be5d0b7695506f6bb2814d7 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")