fix version 1
This commit is contained in:
@@ -1,6 +1,8 @@
|
||||
package models
|
||||
|
||||
import (
|
||||
"time"
|
||||
|
||||
"bsm/full/module/social/group/internal/impl"
|
||||
pb "bsm/full/module/social/group/pb"
|
||||
"gorm.io/gorm"
|
||||
@@ -11,14 +13,48 @@ func InitData() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func GetMyGroup(passport_id uint) (groups []*pb.GroupItem, err error) {
|
||||
// ToGroupItem 将群组模型转换为对外的 GroupItem
|
||||
func ToGroupItem(group *GroupBasic) *pb.GroupItem {
|
||||
if group == nil {
|
||||
return nil
|
||||
}
|
||||
return &pb.GroupItem{
|
||||
Id: int64(group.ID),
|
||||
Identity: group.Identity,
|
||||
Number: group.Number,
|
||||
Avatar: group.Avatar,
|
||||
Name: group.Name,
|
||||
Introduce: group.Introduce,
|
||||
CreatorId: int64(group.PassportID),
|
||||
CretorIdentity: group.PassportIdentity,
|
||||
MemberLimit: group.MemberLimit,
|
||||
Notice: group.Notice,
|
||||
Background: group.Background,
|
||||
MemberTotal: group.MemberTotal,
|
||||
EnableSearchByNumber: group.EnableSearchByNumber,
|
||||
EnableSearchByName: group.EnableSearchByName,
|
||||
CreatedAt: group.CreatedAt.Format(time.DateTime),
|
||||
}
|
||||
}
|
||||
|
||||
sql := `Select group.*,gm.nickname,gm.remark_name,gm.role
|
||||
From group_member as gm
|
||||
Left join group on group.id=gm.group_id
|
||||
Where passport_id=? and deleted_at is null`
|
||||
err = impl.DBService.Raw(sql, passport_id).Find(&groups).Error
|
||||
return
|
||||
// GetMyGroup 查询用户已加入的群组列表
|
||||
func GetMyGroup(passport_id uint) (groups []*pb.GroupItem, err error) {
|
||||
var ids []uint
|
||||
if err = impl.DBService.Model(&GroupMember{}).Where("passport_id = ?", passport_id).Pluck("group_id", &ids).Error; err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if len(ids) == 0 {
|
||||
return groups, nil
|
||||
}
|
||||
var basics []GroupBasic
|
||||
if err = impl.DBService.Where("id in ?", ids).Find(&basics).Error; err != nil {
|
||||
return nil, err
|
||||
}
|
||||
groups = make([]*pb.GroupItem, 0, len(basics))
|
||||
for i := range basics {
|
||||
groups = append(groups, ToGroupItem(&basics[i]))
|
||||
}
|
||||
return groups, nil
|
||||
}
|
||||
|
||||
func GetMasterGroup(passport_id uint) []uint {
|
||||
@@ -27,19 +63,23 @@ func GetMasterGroup(passport_id uint) []uint {
|
||||
return ids
|
||||
}
|
||||
|
||||
// GetGroupMember 查询群成员列表,成员资料来自外部表 passport_extend
|
||||
func GetGroupMember(group_identity string) (members []*pb.PassportInfoSimpleCard, err error) {
|
||||
sql := `Select pe.identity,pe.nickname,pe.avatar,pe.sex,gm.remark_name,gm.role
|
||||
From group_member as gm
|
||||
From relation_group_member as gm
|
||||
Left join passport_extend as pe on pe.passport_id=gm.passport_id
|
||||
Where group_identity=? and deleted_at is null`
|
||||
Where gm.group_identity=? and gm.deleted_at is null`
|
||||
err = impl.DBService.Raw(sql, group_identity).Find(&members).Error
|
||||
return
|
||||
}
|
||||
|
||||
func GetGroupEnableAnyJoin(passport_id uint, group_identity string) bool {
|
||||
var is bool = false
|
||||
impl.DBService.Model(&GroupBasic{}).Select("enable_any_join").Where("createor_id=? and identity=?", passport_id, group_identity).Scan(&is)
|
||||
return is
|
||||
// GetGroupEnableAnyJoin 查询群组是否开启免验证入群
|
||||
func GetGroupEnableAnyJoin(group_identity string) (bool, error) {
|
||||
var group GroupBasic
|
||||
if err := impl.DBService.Select("enable_any_join").Where("identity=?", group_identity).Take(&group).Error; err != nil {
|
||||
return false, err
|
||||
}
|
||||
return group.EnableAnyJoin, nil
|
||||
}
|
||||
|
||||
func UpsetGroupMemberTotal(group_identity string, op string) {
|
||||
|
||||
Reference in New Issue
Block a user