2022-11-24 23:37:34 +08:00
|
|
|
// Package admin
|
|
|
|
// @Link https://github.com/bufanyun/hotgo
|
2023-02-23 17:53:04 +08:00
|
|
|
// @Copyright Copyright (c) 2023 HotGo CLI
|
2022-11-24 23:37:34 +08:00
|
|
|
// @Author Ms <133814250@qq.com>
|
|
|
|
// @License https://github.com/bufanyun/hotgo/blob/master/LICENSE
|
|
|
|
package admin
|
2022-02-25 17:11:17 +08:00
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"github.com/gogf/gf/v2/errors/gerror"
|
2022-11-24 23:37:34 +08:00
|
|
|
"hotgo/internal/consts"
|
|
|
|
"hotgo/internal/dao"
|
|
|
|
"hotgo/internal/model/entity"
|
|
|
|
"hotgo/internal/service"
|
2022-02-25 17:11:17 +08:00
|
|
|
)
|
|
|
|
|
2022-11-24 23:37:34 +08:00
|
|
|
type sAdminMemberPost struct{}
|
2022-02-25 17:11:17 +08:00
|
|
|
|
2022-11-24 23:37:34 +08:00
|
|
|
func NewAdminMemberPost() *sAdminMemberPost {
|
|
|
|
return &sAdminMemberPost{}
|
|
|
|
}
|
2022-02-25 17:11:17 +08:00
|
|
|
|
2022-11-24 23:37:34 +08:00
|
|
|
func init() {
|
|
|
|
service.RegisterAdminMemberPost(NewAdminMemberPost())
|
|
|
|
}
|
|
|
|
|
2023-02-26 14:18:22 +08:00
|
|
|
func (s *sAdminMemberPost) UpdatePostIds(ctx context.Context, memberId int64, postIds []int64) (err error) {
|
|
|
|
_, err = dao.AdminMemberPost.Ctx(ctx).Where("member_id", memberId).Delete()
|
2022-02-25 17:11:17 +08:00
|
|
|
if err != nil {
|
|
|
|
err = gerror.Wrap(err, "删除失败")
|
2023-05-10 23:54:50 +08:00
|
|
|
return
|
2022-02-25 17:11:17 +08:00
|
|
|
}
|
|
|
|
|
2023-02-26 14:18:22 +08:00
|
|
|
for i := 0; i < len(postIds); i++ {
|
2022-02-25 17:11:17 +08:00
|
|
|
_, err = dao.AdminMemberPost.Ctx(ctx).
|
|
|
|
Insert(entity.AdminMemberPost{
|
2023-02-26 14:18:22 +08:00
|
|
|
MemberId: memberId,
|
|
|
|
PostId: postIds[i],
|
2022-02-25 17:11:17 +08:00
|
|
|
})
|
|
|
|
if err != nil {
|
2023-02-08 20:29:34 +08:00
|
|
|
err = gerror.Wrap(err, "插入用户岗位失败")
|
2022-02-25 17:11:17 +08:00
|
|
|
return err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-05-10 23:54:50 +08:00
|
|
|
return
|
2022-02-25 17:11:17 +08:00
|
|
|
}
|
|
|
|
|
2023-02-08 20:29:34 +08:00
|
|
|
// GetMemberByIds 获取指定用户的岗位ids
|
2023-02-26 14:18:22 +08:00
|
|
|
func (s *sAdminMemberPost) GetMemberByIds(ctx context.Context, memberId int64) (postIds []int64, err error) {
|
2022-02-25 17:11:17 +08:00
|
|
|
var list []*entity.AdminMemberPost
|
2023-05-10 23:54:50 +08:00
|
|
|
err = dao.AdminMemberPost.Ctx(ctx).Fields("post_id").Where("member_id", memberId).Scan(&list)
|
2022-02-25 17:11:17 +08:00
|
|
|
if err != nil {
|
|
|
|
err = gerror.Wrap(err, consts.ErrorORM)
|
2023-05-10 23:54:50 +08:00
|
|
|
return
|
2022-02-25 17:11:17 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
for i := 0; i < len(list); i++ {
|
2023-02-26 14:18:22 +08:00
|
|
|
postIds = append(postIds, list[i].PostId)
|
2022-02-25 17:11:17 +08:00
|
|
|
}
|
|
|
|
|
2023-05-10 23:54:50 +08:00
|
|
|
return
|
2022-02-25 17:11:17 +08:00
|
|
|
}
|