create messagegroup
This commit is contained in:
@@ -127,17 +127,16 @@ func GetOperateEvents(ctx *jxcontext.Context, name string, apiFunctions []string
|
|||||||
return pageInfo, err
|
return pageInfo, err
|
||||||
}
|
}
|
||||||
|
|
||||||
func CreateMessageGroup(ctx *jxcontext.Context, userID, userID2 string) (messageGroupResult *dao.GetMessageGroupsResult, err error) {
|
func CreateMessageGroup(ctx *jxcontext.Context, userID, userID2, groupName string, dividePercentage int) (messageGroupResult *dao.GetMessageGroupsResult, err error) {
|
||||||
var (
|
var (
|
||||||
db = dao.GetDB()
|
db = dao.GetDB()
|
||||||
groupID int
|
groupID int
|
||||||
)
|
)
|
||||||
if userID2 != "" {
|
if userID2 != "" {
|
||||||
messageGroups, err := dao.GetMessageGroups(db, userID, model.GroupMemberTypeNormal, userID2)
|
messageGroups, err := dao.GetMessageGroups(db, userID, model.GroupTypeSingle, true, userID2)
|
||||||
if len(messageGroups) > 0 && len(messageGroups[0].MessageGroupMembers) == 0 {
|
if len(messageGroups) > 0 && len(messageGroups[0].MessageGroupMembers) > 0 {
|
||||||
return messageGroups[0], err
|
return messageGroups[0], err
|
||||||
}
|
}
|
||||||
fmt.Println(utils.Format4Output(messageGroups, false))
|
|
||||||
user, err := dao.GetUserByID(db, "user_id", userID2)
|
user, err := dao.GetUserByID(db, "user_id", userID2)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
@@ -158,7 +157,7 @@ func CreateMessageGroup(ctx *jxcontext.Context, userID, userID2 string) (message
|
|||||||
messageGroup := &model.MessageGroup{
|
messageGroup := &model.MessageGroup{
|
||||||
GroupID: groupID,
|
GroupID: groupID,
|
||||||
UserID: userID,
|
UserID: userID,
|
||||||
Name: user.Name,
|
// Name: user.Name,
|
||||||
Type: model.GroupTypeSingle,
|
Type: model.GroupTypeSingle,
|
||||||
MaxCount: 2,
|
MaxCount: 2,
|
||||||
}
|
}
|
||||||
@@ -172,9 +171,52 @@ func CreateMessageGroup(ctx *jxcontext.Context, userID, userID2 string) (message
|
|||||||
dao.CreateEntity(db, messageGroup)
|
dao.CreateEntity(db, messageGroup)
|
||||||
dao.CreateEntity(db, messageGroupMember)
|
dao.CreateEntity(db, messageGroupMember)
|
||||||
if data, err := json.Marshal(messageGroup); err == nil {
|
if data, err := json.Marshal(messageGroup); err == nil {
|
||||||
json.Unmarshal(data, &messageGroup)
|
json.Unmarshal(data, &messageGroupResult)
|
||||||
|
messageGroupResult.Name = user.Name
|
||||||
messageGroupResult.MessageGroupMembers = append(messageGroupResult.MessageGroupMembers, messageGroupMember)
|
messageGroupResult.MessageGroupMembers = append(messageGroupResult.MessageGroupMembers, messageGroupMember)
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
userMembers, err := dao.GetUserMember(db, userID, model.MemberTypeNormal)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
if len(userMembers) == 0 {
|
||||||
|
return nil, fmt.Errorf("抱歉,只有会员才能创建群聊!")
|
||||||
|
}
|
||||||
|
messageGroup := &model.MessageGroup{
|
||||||
|
GroupID: groupID,
|
||||||
|
UserID: userID,
|
||||||
|
Name: groupName,
|
||||||
|
Type: model.GroupTypeMulit,
|
||||||
|
MaxCount: 50,
|
||||||
|
DividePercentage: dividePercentage,
|
||||||
|
}
|
||||||
|
dao.WrapAddIDCULDEntity(messageGroup, ctx.GetUserName())
|
||||||
|
dao.CreateEntity(db, messageGroup)
|
||||||
|
messageGroupResult.MessageGroup = *messageGroup
|
||||||
}
|
}
|
||||||
return messageGroupResult, err
|
return messageGroupResult, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func GetMessageGroupByUser(ctx *jxcontext.Context, userID string) (messageGroupResult []*dao.GetMessageGroupsResult, err error) {
|
||||||
|
var (
|
||||||
|
db = dao.GetDB()
|
||||||
|
)
|
||||||
|
messageGroups, err := dao.GetMessageGroups(db, userID, 0, false, "")
|
||||||
|
for _, v := range messageGroups {
|
||||||
|
var messageMemberGroups []*model.MessageGroupMember
|
||||||
|
sql := `
|
||||||
|
SELECT * FROM message_member_group WHERE group_id = ?
|
||||||
|
`
|
||||||
|
sqlParams := []interface{}{v.GroupID}
|
||||||
|
if err = dao.GetRows(db, &messageMemberGroups, sql, sqlParams); err == nil {
|
||||||
|
if v.Type == model.GroupTypeSingle {
|
||||||
|
user, err := dao.GetUserByID(db, "user_id", messageMemberGroups[0].MemberUserID)
|
||||||
|
if err == nil {
|
||||||
|
v.Name = user.Name
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return messageGroups, err
|
||||||
|
}
|
||||||
|
|||||||
@@ -176,7 +176,7 @@ type GetMessageGroupsResult struct {
|
|||||||
MessageGroupMembers []*model.MessageGroupMember `json:"messageGroupMembers"`
|
MessageGroupMembers []*model.MessageGroupMember `json:"messageGroupMembers"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func GetMessageGroups(db *DaoDB, userID string, groupType int, userID2 string) (messageGroupsResult []*GetMessageGroupsResult, err error) {
|
func GetMessageGroups(db *DaoDB, userID string, groupType int, isMember bool, userID2 string) (messageGroupsResult []*GetMessageGroupsResult, err error) {
|
||||||
sql := `
|
sql := `
|
||||||
SELECT *
|
SELECT *
|
||||||
FROM message_group
|
FROM message_group
|
||||||
@@ -192,6 +192,7 @@ func GetMessageGroups(db *DaoDB, userID string, groupType int, userID2 string) (
|
|||||||
sqlParams = append(sqlParams, groupType)
|
sqlParams = append(sqlParams, groupType)
|
||||||
}
|
}
|
||||||
if err = GetRows(db, &messageGroupsResult, sql, sqlParams); err == nil {
|
if err = GetRows(db, &messageGroupsResult, sql, sqlParams); err == nil {
|
||||||
|
if isMember {
|
||||||
for _, v := range messageGroupsResult {
|
for _, v := range messageGroupsResult {
|
||||||
var messageGroupMembers []*model.MessageGroupMember
|
var messageGroupMembers []*model.MessageGroupMember
|
||||||
sql2 := `
|
sql2 := `
|
||||||
@@ -207,5 +208,6 @@ func GetMessageGroups(db *DaoDB, userID string, groupType int, userID2 string) (
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
return messageGroupsResult, err
|
return messageGroupsResult, err
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -79,6 +79,7 @@ type MessageGroup struct {
|
|||||||
Name string `json:"name"` //组名
|
Name string `json:"name"` //组名
|
||||||
Type int `json:"type"` //组类型,1为单聊,2为群聊
|
Type int `json:"type"` //组类型,1为单聊,2为群聊
|
||||||
MaxCount int `json:"maxCount"` //最大人数
|
MaxCount int `json:"maxCount"` //最大人数
|
||||||
|
DividePercentage int `json:"dividePercentage"` //分成比例
|
||||||
}
|
}
|
||||||
|
|
||||||
func (*MessageGroup) TableIndex() [][]string {
|
func (*MessageGroup) TableIndex() [][]string {
|
||||||
|
|||||||
@@ -192,12 +192,28 @@ func (c *EventController) GetImMessageRecord() {
|
|||||||
// @Param token header string true "认证token"
|
// @Param token header string true "认证token"
|
||||||
// @Param userID formData string true "创建者id"
|
// @Param userID formData string true "创建者id"
|
||||||
// @Param userID2 formData string false "被拉的id 如果userID2为空就默认为是创建的群聊"
|
// @Param userID2 formData string false "被拉的id 如果userID2为空就默认为是创建的群聊"
|
||||||
|
// @Param name formData string false "如果是群聊,则要传入群名"
|
||||||
|
// @Param dividePercentage formData int false "如果是群聊,则要传入分成比例"
|
||||||
// @Success 200 {object} controllers.CallResult
|
// @Success 200 {object} controllers.CallResult
|
||||||
// @Failure 200 {object} controllers.CallResult
|
// @Failure 200 {object} controllers.CallResult
|
||||||
// @router /CreateMessageGroup [post]
|
// @router /CreateMessageGroup [post]
|
||||||
func (c *EventController) CreateMessageGroup() {
|
func (c *EventController) CreateMessageGroup() {
|
||||||
c.callCreateMessageGroup(func(params *tEventCreateMessageGroupParams) (retVal interface{}, errCode string, err error) {
|
c.callCreateMessageGroup(func(params *tEventCreateMessageGroupParams) (retVal interface{}, errCode string, err error) {
|
||||||
retVal, err = event.CreateMessageGroup(params.Ctx, params.UserID, params.UserID2)
|
retVal, err = event.CreateMessageGroup(params.Ctx, params.UserID, params.UserID2, params.Name, params.DividePercentage)
|
||||||
|
return retVal, "", err
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// @Title 查询某个用户所有聊天组
|
||||||
|
// @Description 查询某个用户所有聊天组
|
||||||
|
// @Param token header string true "认证token"
|
||||||
|
// @Param userID formData string true "userid"
|
||||||
|
// @Success 200 {object} controllers.CallResult
|
||||||
|
// @Failure 200 {object} controllers.CallResult
|
||||||
|
// @router /GetMessageGroupByUser [get]
|
||||||
|
func (c *EventController) GetMessageGroupByUser() {
|
||||||
|
c.callGetMessageGroupByUser(func(params *tEventGetMessageGroupByUserParams) (retVal interface{}, errCode string, err error) {
|
||||||
|
retVal, err = event.GetMessageGroupByUser(params.Ctx, params.UserID)
|
||||||
return retVal, "", err
|
return retVal, "", err
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|||||||
2
main.go
2
main.go
@@ -13,7 +13,6 @@ import (
|
|||||||
|
|
||||||
// 导入缺省订单调度器
|
// 导入缺省订单调度器
|
||||||
|
|
||||||
"git.rosy.net.cn/jx-callback/business/jxutils/tasks"
|
|
||||||
"git.rosy.net.cn/jx-callback/globals"
|
"git.rosy.net.cn/jx-callback/globals"
|
||||||
"git.rosy.net.cn/jx-callback/globals/beegodb"
|
"git.rosy.net.cn/jx-callback/globals/beegodb"
|
||||||
|
|
||||||
@@ -22,6 +21,7 @@ import (
|
|||||||
_ "git.rosy.net.cn/jx-callback/business/auth2/authprovider/mobile"
|
_ "git.rosy.net.cn/jx-callback/business/auth2/authprovider/mobile"
|
||||||
_ "git.rosy.net.cn/jx-callback/business/auth2/authprovider/password"
|
_ "git.rosy.net.cn/jx-callback/business/auth2/authprovider/password"
|
||||||
_ "git.rosy.net.cn/jx-callback/business/auth2/authprovider/weixin"
|
_ "git.rosy.net.cn/jx-callback/business/auth2/authprovider/weixin"
|
||||||
|
"git.rosy.net.cn/jx-callback/business/jxutils/tasks"
|
||||||
|
|
||||||
_ "git.rosy.net.cn/jx-callback/routers"
|
_ "git.rosy.net.cn/jx-callback/routers"
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -151,6 +151,15 @@ func init() {
|
|||||||
Filters: nil,
|
Filters: nil,
|
||||||
Params: nil})
|
Params: nil})
|
||||||
|
|
||||||
|
beego.GlobalControllerRouter["git.rosy.net.cn/jx-callback/controllers:EventController"] = append(beego.GlobalControllerRouter["git.rosy.net.cn/jx-callback/controllers:EventController"],
|
||||||
|
beego.ControllerComments{
|
||||||
|
Method: "GetMessageGroupByUser",
|
||||||
|
Router: `/GetMessageGroupByUser`,
|
||||||
|
AllowHTTPMethods: []string{"get"},
|
||||||
|
MethodParams: param.Make(),
|
||||||
|
Filters: nil,
|
||||||
|
Params: nil})
|
||||||
|
|
||||||
beego.GlobalControllerRouter["git.rosy.net.cn/jx-callback/controllers:EventController"] = append(beego.GlobalControllerRouter["git.rosy.net.cn/jx-callback/controllers:EventController"],
|
beego.GlobalControllerRouter["git.rosy.net.cn/jx-callback/controllers:EventController"] = append(beego.GlobalControllerRouter["git.rosy.net.cn/jx-callback/controllers:EventController"],
|
||||||
beego.ControllerComments{
|
beego.ControllerComments{
|
||||||
Method: "GetWeixinUnlimited",
|
Method: "GetWeixinUnlimited",
|
||||||
|
|||||||
Reference in New Issue
Block a user