del_email.go 836 B

123456789101112131415161718192021222324252627282930313233
  1. package del_email
  2. import (
  3. "fmt"
  4. "pmail/db"
  5. "pmail/models"
  6. "pmail/services/auth"
  7. "pmail/utils/array"
  8. "pmail/utils/context"
  9. "pmail/utils/errors"
  10. )
  11. func DelEmail(ctx *context.Context, ids []int) error {
  12. var emails []*models.Email
  13. db.Instance.Select(&emails, db.WithContext(ctx, fmt.Sprintf("select * from email where id in (%s)", array.Join(ids, ","))))
  14. for _, email := range emails {
  15. // 检查是否有权限
  16. hasAuth := auth.HasAuth(ctx, email)
  17. if !hasAuth {
  18. return errors.New("No Auth!")
  19. }
  20. }
  21. //_, err := db.Instance.Exec(db.WithContext(ctx, fmt.Sprintf("delete from email where id in (%s)", array.Join(ids, ","))))
  22. _, err := db.Instance.Exec(db.WithContext(ctx, fmt.Sprintf("update email set status = 3 where id in (%s)", array.Join(ids, ","))))
  23. if err != nil {
  24. return errors.Wrap(err)
  25. }
  26. return nil
  27. }