Commit 982b8d0f authored by chenweijian's avatar chenweijian

家族成员

parent bd5b7076
package groupPower_m
import (
"git.hilo.cn/hilo-common/resource/mysql"
"gorm.io/gorm"
"hilo-group/myerr"
"time"
)
type GroupPowerApplyJoin struct {
Id uint64 `json:"id"`
UserId uint64 `json:"user_id"`
GroupPowerId uint64 `json:"group_power_id"`
CreatedTime time.Time `json:"created_time"`
UpdatedTime time.Time `json:"updated_time"`
IsAccept int8 `json:"is_accept"`
}
func InsertGroupPowerApplyJoin(userId, familyId uint64) error {
nowTime := time.Now()
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=?"
err := mysql.Db.Exec(sql, userId, familyId, 0, nowTime, nowTime, 0, nowTime, nowTime).Error
if err != nil {
return myerr.WrapErr(err)
}
return nil
}
func GetGroupPowerApplyJoin(userId, familyId uint64) (*GroupPowerApplyJoin, error) {
res := new(GroupPowerApplyJoin)
err := mysql.Db.Where(GroupPowerApplyJoin{UserId: userId, GroupPowerId: familyId}).Where("is_accept=0").First(&res).Error
if err != nil {
if err == gorm.ErrRecordNotFound {
return nil, nil
} else {
return nil, myerr.WrapErr(err)
}
}
return res, nil
}
func AcceptGroupPowerApplyJoin(userId, familyId 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
if err != nil {
return myerr.WrapErr(err)
}
return nil
}
...@@ -17,3 +17,17 @@ CREATE TABLE `group_power_invite_join` ( ...@@ -17,3 +17,17 @@ CREATE TABLE `group_power_invite_join` (
KEY `group_power_id` (`group_power_id`), KEY `group_power_id` (`group_power_id`),
KEY `invite_user_id` (`invite_user_id`) KEY `invite_user_id` (`invite_user_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci COMMENT='邀请加入家族'; ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci COMMENT='邀请加入家族';
CREATE TABLE `group_power_apply_join` (
`id` bigint unsigned NOT NULL AUTO_INCREMENT COMMENT 'id',
`user_id` bigint unsigned NOT NULL COMMENT '申请者id',
`group_power_id` bigint unsigned NOT NULL,
`created_time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
`updated_time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
`is_accept` tinyint NOT NULL DEFAULT '0' COMMENT '是否已经接受',
PRIMARY KEY (`id`),
UNIQUE KEY `user_group` (`user_id`,`group_power_id`),
UNIQUE KEY `u_apply` (`user_id`,`group_power_id`,`is_accept`) USING BTREE,
KEY `group_power_id` (`group_power_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci COMMENT='申请加入家族';
\ No newline at end of file
...@@ -847,3 +847,40 @@ func GroupPowerMembers(c *gin.Context) (*mycontext.MyContext, error) { ...@@ -847,3 +847,40 @@ func GroupPowerMembers(c *gin.Context) (*mycontext.MyContext, error) {
resp.ResponseOk(c, result) resp.ResponseOk(c, result)
return myContext, nil return myContext, nil
} }
// @Tags 家族
// @Summary 申请加入家族
// @Param id formData int true "家族id"
// @Success 200
// @Router /v1/groupPower/applyJoin [get]
func GroupPowerApplyJoin(c *gin.Context) (*mycontext.MyContext, error) {
myContext := mycontext.CreateMyContext(c.Keys)
userId, err := req.GetUserId(c)
if err != nil {
return myContext, err
}
familyId, err := strconv.ParseUint(c.PostForm("id"), 10, 64)
if err != nil {
return myContext, myerr.WrapErr(err)
}
model := domain.CreateModelContext(myContext)
// 判断家族是否存在
gp := &groupPower_m.GroupPower{Entity: mysql.Entity{ID: familyId}}
gpInfo, err := gp.Get(model)
if err != nil {
return myContext, err
}
if gpInfo == nil || gpInfo.ID <= 0 {
return myContext, bizerr.InvalidParameter
}
// 插入申请表
err = groupPower_m.InsertGroupPowerApplyJoin(userId, gpInfo.ID)
if err != nil {
return myContext, err
}
resp.ResponseOk(c, nil)
return myContext, nil
}
...@@ -129,6 +129,7 @@ func InitRouter() *gin.Engine { ...@@ -129,6 +129,7 @@ func InitRouter() *gin.Engine {
groupPower.GET("/info", wrapper(group_power_r.GroupPowerInfo)) groupPower.GET("/info", wrapper(group_power_r.GroupPowerInfo))
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))
} }
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