Commit 2fbe9c7f authored by chenweijian's avatar chenweijian

申请加入家族

parent c2880d32
...@@ -45,3 +45,19 @@ func (gpu *GroupPowerUser) GetBy(model *domain.Model, pageSize, pageIndex int) ( ...@@ -45,3 +45,19 @@ func (gpu *GroupPowerUser) GetBy(model *domain.Model, pageSize, pageIndex int) (
} }
return rows, nil return rows, nil
} }
func (gpu *GroupPowerUser) GetGroupPowerUser(model *domain.Model) (*GroupPowerUser, error) {
rows := make([]*GroupPowerUser, 0)
err := model.Db.Where(gpu).Find(&rows).Error
if err != nil {
return nil, err
}
if len(rows) == 0 {
return nil, nil
}
return rows[0], nil
}
func (gpu *GroupPowerUser) Create(db *gorm.DB) error {
return db.Create(gpu).Error
}
package groupPower_m package groupPower_m
import ( import (
"git.hilo.cn/hilo-common/resource/mysql" "git.hilo.cn/hilo-common/domain"
"gorm.io/gorm" "gorm.io/gorm"
"hilo-group/myerr" "hilo-group/myerr"
"time" "time"
...@@ -16,20 +16,20 @@ type GroupPowerApplyJoin struct { ...@@ -16,20 +16,20 @@ type GroupPowerApplyJoin struct {
IsAccept int8 `json:"is_accept"` IsAccept int8 `json:"is_accept"`
} }
func InsertGroupPowerApplyJoin(userId, familyId uint64) error { func InsertGroupPowerApplyJoin(model *domain.Model, userId, familyId uint64) error {
nowTime := time.Now() nowTime := time.Now()
sql := "insert into group_power_apply_join(user_id,group_power_id,is_accept,created_time,updated_time) " + sql := "insert into group_power_apply_join(user_id,group_power_id,is_accept,created_time,updated_time) " +
"value(?,?,?,?,?) on duplicate key update is_accept=?,created_time=?,updated_time=?" "value(?,?,?,?,?) on duplicate key update is_accept=?,created_time=?,updated_time=?"
err := mysql.Db.Exec(sql, userId, familyId, 0, nowTime, nowTime, 0, nowTime, nowTime).Error err := model.Db.Exec(sql, userId, familyId, 0, nowTime, nowTime, 0, nowTime, nowTime).Error
if err != nil { if err != nil {
return myerr.WrapErr(err) return myerr.WrapErr(err)
} }
return nil return nil
} }
func GetGroupPowerApplyJoin(userId, familyId uint64) (*GroupPowerApplyJoin, error) { func GetGroupPowerApplyJoin(model *domain.Model, userId, familyId uint64) (*GroupPowerApplyJoin, error) {
res := new(GroupPowerApplyJoin) res := new(GroupPowerApplyJoin)
err := mysql.Db.Where(GroupPowerApplyJoin{UserId: userId, GroupPowerId: familyId}).Where("is_accept=0").First(&res).Error err := model.Db.Where(GroupPowerApplyJoin{UserId: userId, GroupPowerId: familyId}).Where("is_accept=0").First(&res).Error
if err != nil { if err != nil {
if err == gorm.ErrRecordNotFound { if err == gorm.ErrRecordNotFound {
return nil, nil return nil, nil
...@@ -40,8 +40,16 @@ func GetGroupPowerApplyJoin(userId, familyId uint64) (*GroupPowerApplyJoin, erro ...@@ -40,8 +40,16 @@ func GetGroupPowerApplyJoin(userId, familyId uint64) (*GroupPowerApplyJoin, erro
return res, nil return res, nil
} }
func AcceptGroupPowerApplyJoin(userId, familyId uint64) error { func AcceptGroupPowerApplyJoinById(model *domain.Model, id uint64) error {
err := mysql.Db.Exec("update group_power_apply_join set is_accept = 1 where user_id=? and group_power_id=?", userId, familyId).Error err := model.Db.Exec("update group_power_apply_join set is_accept = 1 where id=?", id).Error
if err != nil {
return myerr.WrapErr(err)
}
return nil
}
func AcceptGroupPowerApplyJoin(model *domain.Model, userId, familyId uint64) error {
err := model.Db.Exec("update group_power_apply_join set is_accept = 1 where user_id=? and group_power_id=?", userId, familyId).Error
if err != nil { if err != nil {
return myerr.WrapErr(err) return myerr.WrapErr(err)
} }
......
...@@ -81,6 +81,9 @@ var ( ...@@ -81,6 +81,9 @@ var (
GroupPowerDealerCanNotSole = myerr.NewBusinessCode(15008, "This user already has a family agent and cannot sell diamonds", myerr.BusinessData{}) // 代理转账失败-此用户已有家族代理,不能出售钻石 GroupPowerDealerCanNotSole = myerr.NewBusinessCode(15008, "This user already has a family agent and cannot sell diamonds", myerr.BusinessData{}) // 代理转账失败-此用户已有家族代理,不能出售钻石
GroupPowerDealerCanNotBuy = myerr.NewBusinessCode(15009, "Buy diamonds from your family agent", myerr.BusinessData{}) // 请向本家族代理购买钻石 GroupPowerDealerCanNotBuy = myerr.NewBusinessCode(15009, "Buy diamonds from your family agent", myerr.BusinessData{}) // 请向本家族代理购买钻石
GroupPowerDealerNeedJoin = myerr.NewBusinessCode(15010, "Please join the agent's family to purchase", myerr.BusinessData{}) // 请加入代理的家族后进行购买 GroupPowerDealerNeedJoin = myerr.NewBusinessCode(15010, "Please join the agent's family to purchase", myerr.BusinessData{}) // 请加入代理的家族后进行购买
GroupPowerHaveNoJoin = myerr.NewBusinessCode(15011, "You have no joined power", myerr.BusinessData{}) // 还未加入国家势力
GroupPowerHaveNoPower = myerr.NewBusinessCode(15012, "You have no power", myerr.BusinessData{}) // 没有权限
GroupPowerHaveNoApply = myerr.NewBusinessCode(15013, "User have no apply", myerr.BusinessData{}) // 没有找到申请
TaskHasAward = myerr.NewBusinessCode(19001, "task has award", myerr.BusinessData{}) TaskHasAward = myerr.NewBusinessCode(19001, "task has award", myerr.BusinessData{})
......
...@@ -852,7 +852,7 @@ func GroupPowerMembers(c *gin.Context) (*mycontext.MyContext, error) { ...@@ -852,7 +852,7 @@ func GroupPowerMembers(c *gin.Context) (*mycontext.MyContext, error) {
// @Summary 申请加入家族 // @Summary 申请加入家族
// @Param id formData int true "家族id" // @Param id formData int true "家族id"
// @Success 200 // @Success 200
// @Router /v1/groupPower/applyJoin [get] // @Router /v1/groupPower/applyJoin [post]
func GroupPowerApplyJoin(c *gin.Context) (*mycontext.MyContext, error) { func GroupPowerApplyJoin(c *gin.Context) (*mycontext.MyContext, error) {
myContext := mycontext.CreateMyContext(c.Keys) myContext := mycontext.CreateMyContext(c.Keys)
userId, err := req.GetUserId(c) userId, err := req.GetUserId(c)
...@@ -885,7 +885,66 @@ func GroupPowerApplyJoin(c *gin.Context) (*mycontext.MyContext, error) { ...@@ -885,7 +885,66 @@ func GroupPowerApplyJoin(c *gin.Context) (*mycontext.MyContext, error) {
} }
// 插入申请表 // 插入申请表
err = groupPower_m.InsertGroupPowerApplyJoin(userId, gpInfo.ID) err = groupPower_m.InsertGroupPowerApplyJoin(model, userId, gpInfo.ID)
if err != nil {
return myContext, err
}
resp.ResponseOk(c, nil)
return myContext, nil
}
// @Tags 家族
// @Summary 批准加入家族
// @Param userExtId query string false "用户extId"
// @Success 200
// @Router /v1/groupPower/passApply [post]
func GroupPowerApplyPass(c *gin.Context) (*mycontext.MyContext, error) {
myContext := mycontext.CreateMyContext(c.Keys)
userId, err := req.GetUserId(c)
if err != nil {
return myContext, err
}
model := domain.CreateModelContext(myContext)
// 判断是否加入了家族
gpU := groupPower_m.GroupPowerUser{UserId: userId}
myGroupPUser, err := gpU.GetGroupPowerUser(model)
if err != nil {
return myContext, err
}
// 操作者是否加入了家族,是否有操作权限
if myGroupPUser == nil || myGroupPUser.ID == 0 {
return myContext, bizerr.GroupPowerHaveNoJoin
}
if myGroupPUser.Role == 0 || myGroupPUser.Role == groupPower_e.GroupPowerUserRoleUser {
return myContext, bizerr.GroupPowerHaveNoPower
}
// 查找申请记录
apply, err := groupPower_m.GetGroupPowerApplyJoin(model, userId, myGroupPUser.GroupPowerId)
if err != nil {
return myContext, err
}
if apply == nil {
return myContext, bizerr.GroupPowerHaveNoApply
}
err = model.Transaction(func(model *domain.Model) error {
txModel := domain.CreateModel(model.CtxAndDb)
// 插入家族成员表
gpU := groupPower_m.GroupPowerUser{GroupPowerId: apply.GroupPowerId, UserId: apply.UserId, Role: groupPower_e.GroupPowerUserRoleUser}
err := gpU.Create(txModel.Db)
if err != nil {
txModel.Log.Errorf("GroupPowerApplyPass err:%v, info:%v", err, gpU)
return err
}
// 更改申请表状态
err = groupPower_m.AcceptGroupPowerApplyJoinById(model, apply.Id)
if err != nil {
return err
}
return nil
})
if err != nil { if err != nil {
return myContext, err return myContext, err
} }
......
...@@ -130,6 +130,7 @@ func InitRouter() *gin.Engine { ...@@ -130,6 +130,7 @@ func InitRouter() *gin.Engine {
groupPower.GET("/rooms", wrapper(group_power_r.GroupPowerRooms)) groupPower.GET("/rooms", wrapper(group_power_r.GroupPowerRooms))
groupPower.GET("/members", wrapper(group_power_r.GroupPowerMembers)) groupPower.GET("/members", wrapper(group_power_r.GroupPowerMembers))
groupPower.POST("/applyJoin", wrapper(group_power_r.GroupPowerApplyJoin)) groupPower.POST("/applyJoin", wrapper(group_power_r.GroupPowerApplyJoin))
groupPower.POST("/passApply", wrapper(group_power_r.GroupPowerApplyPass))
} }
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