2026-08-09 10:43:45 +08:00
|
|
|
package basic
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"context"
|
2026-09-22 21:15:34 +08:00
|
|
|
"errors"
|
|
|
|
|
"time"
|
2026-08-09 10:43:45 +08:00
|
|
|
|
2026-09-22 21:15:34 +08:00
|
|
|
"bsm/full/module/social/group/internal/impl"
|
|
|
|
|
"bsm/full/module/social/group/internal/models"
|
2026-08-10 11:42:45 +08:00
|
|
|
pb "bsm/full/module/social/group/pb"
|
2026-08-09 10:43:45 +08:00
|
|
|
"git.apinb.com/bsm-sdk/core/errcode"
|
2026-09-22 21:15:34 +08:00
|
|
|
"git.apinb.com/bsm-sdk/core/printer"
|
2026-08-09 10:43:45 +08:00
|
|
|
"git.apinb.com/bsm-sdk/core/service"
|
|
|
|
|
"git.apinb.com/bsm-sdk/core/vars"
|
2026-09-22 21:15:34 +08:00
|
|
|
"gorm.io/gorm"
|
2026-08-09 10:43:45 +08:00
|
|
|
)
|
|
|
|
|
|
|
|
|
|
// 解散群组
|
2026-08-09 20:14:57 +08:00
|
|
|
func Disband(ctx context.Context, in *pb.IdentRequest) (reply *pb.DataStatusReply, err error) {
|
2026-08-09 10:43:45 +08:00
|
|
|
// parse authorization meta.
|
2026-09-22 21:15:34 +08:00
|
|
|
auth, err := service.ParseMetaCtx(ctx, nil)
|
2026-08-09 10:43:45 +08:00
|
|
|
if err != nil {
|
|
|
|
|
return nil, err
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// valildate request id,identity.
|
|
|
|
|
if in.Id == 0 && in.Identity == "" {
|
|
|
|
|
return nil, errcode.ErrInvalidArgument
|
|
|
|
|
}
|
2026-09-22 21:15:34 +08:00
|
|
|
if in.Identity == "" {
|
|
|
|
|
return nil, errcode.ErrInvalidArgument
|
|
|
|
|
}
|
2026-08-09 10:43:45 +08:00
|
|
|
|
2026-09-22 21:15:34 +08:00
|
|
|
// 校验群组存在,且仅群主可解散
|
|
|
|
|
var group models.GroupBasic
|
|
|
|
|
if err = impl.DBService.Where("identity=?", in.Identity).First(&group).Error; err != nil {
|
|
|
|
|
printer.Error(err.Error())
|
|
|
|
|
if errors.Is(err, gorm.ErrRecordNotFound) {
|
|
|
|
|
return nil, errcode.ErrRecordNotFound
|
|
|
|
|
}
|
|
|
|
|
return nil, errcode.ErrDB
|
|
|
|
|
}
|
|
|
|
|
if group.PassportID != auth.ID {
|
|
|
|
|
return nil, errcode.ErrPermissionDenied
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 软删除群组及其成员记录
|
|
|
|
|
err = impl.DBService.Transaction(func(tx *gorm.DB) error {
|
|
|
|
|
if e := tx.Where("identity=?", in.Identity).Delete(&models.GroupBasic{}).Error; e != nil {
|
|
|
|
|
return e
|
|
|
|
|
}
|
|
|
|
|
if e := tx.Where("group_identity=?", in.Identity).Delete(&models.GroupMember{}).Error; e != nil {
|
|
|
|
|
return e
|
|
|
|
|
}
|
|
|
|
|
return nil
|
|
|
|
|
})
|
|
|
|
|
if err != nil {
|
|
|
|
|
printer.Error(err.Error())
|
|
|
|
|
return nil, errcode.ErrDB
|
|
|
|
|
}
|
2026-08-09 10:43:45 +08:00
|
|
|
|
2026-08-09 20:14:57 +08:00
|
|
|
return &pb.DataStatusReply{
|
2026-08-09 10:43:45 +08:00
|
|
|
Data: vars.OK,
|
|
|
|
|
Timeseq: time.Now().UnixMilli(),
|
|
|
|
|
}, nil
|
|
|
|
|
|
|
|
|
|
}
|