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())
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *sAdminMemberPost) UpdatePostIds(ctx context.Context, member_id int64, post_ids []int64) (err error) {
|
|
|
|
_, err = dao.AdminMemberPost.Ctx(ctx).Where("member_id", member_id).Delete()
|
2022-02-25 17:11:17 +08:00
|
|
|
if err != nil {
|
|
|
|
err = gerror.Wrap(err, "删除失败")
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
for i := 0; i < len(post_ids); i++ {
|
|
|
|
_, err = dao.AdminMemberPost.Ctx(ctx).
|
|
|
|
Insert(entity.AdminMemberPost{
|
|
|
|
MemberId: member_id,
|
|
|
|
PostId: post_ids[i],
|
|
|
|
})
|
|
|
|
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
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2023-02-08 20:29:34 +08:00
|
|
|
// GetMemberByIds 获取指定用户的岗位ids
|
2022-11-24 23:37:34 +08:00
|
|
|
func (s *sAdminMemberPost) GetMemberByIds(ctx context.Context, member_id int64) (post_ids []int64, err error) {
|
2022-02-25 17:11:17 +08:00
|
|
|
var list []*entity.AdminMemberPost
|
|
|
|
err = dao.AdminMemberPost.Ctx(ctx).
|
|
|
|
Fields("post_id").
|
|
|
|
Where("member_id", member_id).
|
|
|
|
Scan(&list)
|
|
|
|
if err != nil {
|
|
|
|
err = gerror.Wrap(err, consts.ErrorORM)
|
|
|
|
return post_ids, err
|
|
|
|
}
|
|
|
|
|
|
|
|
for i := 0; i < len(list); i++ {
|
|
|
|
post_ids = append(post_ids, list[i].PostId)
|
|
|
|
}
|
|
|
|
|
|
|
|
return post_ids, nil
|
|
|
|
}
|