requestRelate.go 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. package requestRelate
  2. import (
  3. "errors"
  4. "github.com/baiy/Cadmin-server-go/models"
  5. "github.com/doug-martin/goqu/v9"
  6. )
  7. type Model struct {
  8. models.Model
  9. AdminRequestId int `json:"admin_request_id"`
  10. AdminAuthId int `json:"admin_auth_id"`
  11. }
  12. func AuthIds(requestIds []int) []int {
  13. ids := make([]int, 0)
  14. _ = models.Db.From("admin_request_relate").Select("admin_auth_id").Where(goqu.Ex{
  15. "admin_request_id": requestIds,
  16. }).ScanVals(&ids)
  17. return ids
  18. }
  19. func RequestIds(authIds []int) []int {
  20. ids := make([]int, 0)
  21. _ = models.Db.From("admin_request_relate").Select("admin_request_id").Where(goqu.Ex{
  22. "admin_auth_id": authIds,
  23. }).ScanVals(&ids)
  24. return ids
  25. }
  26. func Add(requestId, authId int) error {
  27. _, err := models.Db.Insert("admin_request_relate").Rows(
  28. goqu.Record{"admin_request_id": requestId, "admin_auth_id": authId},
  29. ).Executor().Exec()
  30. return err
  31. }
  32. func Remove(requestId, authId int) error {
  33. if requestId == 0 && authId == 0 {
  34. return errors.New("参数错误")
  35. }
  36. where := make(goqu.Ex)
  37. if requestId != 0 {
  38. where["admin_request_id"] = requestId
  39. }
  40. if authId != 0 {
  41. where["admin_auth_id"] = authId
  42. }
  43. _, err := models.Db.Delete("admin_request_relate").Where(where).Executor().Exec()
  44. return err
  45. }