Commit 3bcb57cd authored by chenweijian's avatar chenweijian

退出家族

parent 6de10476
...@@ -16,6 +16,12 @@ type GroupPowerGrade struct { ...@@ -16,6 +16,12 @@ type GroupPowerGrade struct {
ExpireAt time.Time `json:"expire_at"` 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) { func (this *GroupPower) Get(model *domain.Model) (*GroupPower, error) {
group := new(GroupPower) group := new(GroupPower)
err := model.Db.Where(this).First(&group).Error err := model.Db.Where(this).First(&group).Error
...@@ -69,3 +75,13 @@ func (gpu *GroupPowerUser) GetGroupPowerUser(model *domain.Model) (*GroupPowerUs ...@@ -69,3 +75,13 @@ func (gpu *GroupPowerUser) GetGroupPowerUser(model *domain.Model) (*GroupPowerUs
func (gpu *GroupPowerUser) Create(db *gorm.DB) error { func (gpu *GroupPowerUser) Create(db *gorm.DB) error {
return db.Create(gpu).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
}
...@@ -29,4 +29,16 @@ CREATE TABLE `group_power_apply_join` ( ...@@ -29,4 +29,16 @@ CREATE TABLE `group_power_apply_join` (
PRIMARY KEY (`id`), PRIMARY KEY (`id`),
KEY `group_power_id` (`group_power_id`), KEY `group_power_id` (`group_power_id`),
KEY `user_id` (`user_id`) USING BTREE KEY `user_id` (`user_id`) USING BTREE
) ENGINE=InnoDB AUTO_INCREMENT=2 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci COMMENT='申请加入家族'; ) ENGINE=InnoDB AUTO_INCREMENT=2 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci COMMENT='申请加入家族';
\ No newline at end of file
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
...@@ -1066,8 +1066,13 @@ func GroupPowerQuit(c *gin.Context) (*mycontext.MyContext, error) { ...@@ -1066,8 +1066,13 @@ func GroupPowerQuit(c *gin.Context) (*mycontext.MyContext, error) {
if groupPUser == nil { if groupPUser == nil {
return myContext, bizerr.GroupPowerHaveNoJoin 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) resp.ResponseOk(c, nil)
return myContext, nil return myContext, nil
...@@ -1094,16 +1099,23 @@ func GroupPowerQuit(c *gin.Context) (*mycontext.MyContext, error) { ...@@ -1094,16 +1099,23 @@ func GroupPowerQuit(c *gin.Context) (*mycontext.MyContext, error) {
if err != nil { if err != nil {
return myContext, err return myContext, err
} }
groupPUser, err := gpU.GetGroupPowerUser(model) // 被踢者
gpUKick := groupPower_m.GroupPowerUser{UserId: userId}
kickGroupPUser, err := gpUKick.GetGroupPowerUser(model)
if err != nil { if err != nil {
return myContext, err return myContext, err
} }
if groupPUser == nil { if kickGroupPUser == nil {
return myContext, bizerr.GroupPowerHaveNoJoin 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 return myContext, nil
} }
...@@ -132,6 +132,7 @@ func InitRouter() *gin.Engine { ...@@ -132,6 +132,7 @@ func InitRouter() *gin.Engine {
groupPower.POST("/apply", wrapper(group_power_r.GroupPowerApplyJoin)) groupPower.POST("/apply", wrapper(group_power_r.GroupPowerApplyJoin))
groupPower.POST("/apply/pass", wrapper(group_power_r.GroupPowerApplyPass)) groupPower.POST("/apply/pass", wrapper(group_power_r.GroupPowerApplyPass))
groupPower.GET("/apply/list", wrapper(group_power_r.GroupPowerApplyList)) groupPower.GET("/apply/list", wrapper(group_power_r.GroupPowerApplyList))
groupPower.POST("/quit", wrapper(group_power_r.GroupPowerQuit))
} }
charge := v1.Group("/charge") charge := v1.Group("/charge")
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment