delete_contact_field_template_logic.go 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. package contact_field_template
  2. import (
  3. "context"
  4. "errors"
  5. "github.com/suyuan32/simple-admin-common/msg/errormsg"
  6. "wechat-api/ent/contactfieldtemplate"
  7. "wechat-api/internal/utils/dberrorhandler"
  8. "wechat-api/internal/svc"
  9. "wechat-api/internal/types"
  10. "github.com/zeromicro/go-zero/core/logx"
  11. )
  12. type DeleteContactFieldTemplateLogic struct {
  13. logx.Logger
  14. ctx context.Context
  15. svcCtx *svc.ServiceContext
  16. }
  17. func NewDeleteContactFieldTemplateLogic(ctx context.Context, svcCtx *svc.ServiceContext) *DeleteContactFieldTemplateLogic {
  18. return &DeleteContactFieldTemplateLogic{
  19. Logger: logx.WithContext(ctx),
  20. ctx: ctx,
  21. svcCtx: svcCtx}
  22. }
  23. func (l *DeleteContactFieldTemplateLogic) DeleteContactFieldTemplate(req *types.IDsReq) (resp *types.BaseMsgResp, err error) {
  24. organizationId := l.ctx.Value("organizationId").(uint64)
  25. if len(req.Ids) == 0 {
  26. return nil, errors.New("ids参数不能为空")
  27. }
  28. _, err = l.svcCtx.DB.ContactFieldTemplate.Delete().Where(contactfieldtemplate.IDIn(req.Ids...), contactfieldtemplate.OrganizationID(organizationId)).Exec(l.ctx)
  29. if err != nil {
  30. return nil, dberrorhandler.DefaultEntError(l.Logger, err, req)
  31. }
  32. return &types.BaseMsgResp{Msg: errormsg.DeleteSuccess}, nil
  33. }