admin.go 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. package admin
  2. import (
  3. "errors"
  4. "github.com/gin-gonic/gin"
  5. "github.com/go-playground/validator"
  6. "lot_interlligentControl/app/e"
  7. "lot_interlligentControl/app/services"
  8. "lot_interlligentControl/app/services/imp"
  9. "lot_interlligentControl/models"
  10. "lot_interlligentControl/unity"
  11. "lot_interlligentControl/utils"
  12. "strconv"
  13. )
  14. var shop services.Shop = &imp.Shop{}
  15. // AdminGetAudit
  16. // @Tags 管理员
  17. // @Summary 管理员审核状态
  18. // @Success 200 {object} e.R
  19. // @Fail 400 {object} e.R
  20. // @Param id query string true "id"
  21. // @Param state query string true "状态"
  22. // @Accept application/json
  23. // @Router /admin/auditState [put]
  24. func AdminGetAudit(c *gin.Context) {
  25. value := c.Query("id")
  26. value1 := c.Query("state")
  27. validate := validator.New()
  28. err := validate.Var(value, "required,numeric")
  29. err = validate.Var(value1, "required,numeric")
  30. if err != nil {
  31. e.ResponseWithMsg(c, e.TheParameterCannotBeEmpty, e.TheParameterCannotBeEmpty.GetMsg())
  32. return
  33. }
  34. uId := utils.GetUId(c)
  35. id, _ := strconv.Atoi(value)
  36. state, _ := strconv.Atoi(value1)
  37. auditState := shop.AuditState(uId, id, state)
  38. if errors.Is(auditState, e.SUCCESS) {
  39. e.ResponseSuccess(c, "审核成功")
  40. return
  41. }
  42. e.ResponseWithMsg(c, auditState, "参数错误")
  43. }
  44. // GetServiceNodeAll
  45. // @Tags 管理员
  46. // @Summary 管理员查询所有节点
  47. // @Success 200 {object} e.R
  48. // @Fail 400 {object} e.R
  49. // @Param req body unity.PageParams true "分页数据"
  50. // @Accept application/json
  51. // @Router /admin/serviceNode [post]
  52. func GetServiceNodeAll(c *gin.Context) {
  53. var pages unity.PageParams
  54. err := c.ShouldBindJSON(&pages)
  55. if err != nil {
  56. e.ResponseWithMsg(c, e.JSONParsingFailed, e.JSONParsingFailed.GetMsg())
  57. return
  58. }
  59. result, total, err := unity.Paginate(pages, models.ServiceNodes{})
  60. if err != nil {
  61. e.ResponseWithMsg(c, e.PaginationFailed, e.PaginationFailed.GetMsg())
  62. return
  63. }
  64. e.ResPonsePage(c, result, total, pages)
  65. }
  66. // GetAllShop
  67. // @Tags 管理员
  68. // @Summary 管理员查询所有店铺
  69. // @Success 200 {object} e.R
  70. // @Fail 400 {object} e.R
  71. // @Param req body unity.PageParams true "分页数据"
  72. // @Accept application/json
  73. // @Router /admin/shop [get]
  74. func GetAllShop(c *gin.Context) {
  75. var pages unity.PageParams
  76. err := c.ShouldBindJSON(&pages)
  77. if err != nil {
  78. e.ResponseWithMsg(c, e.JSONParsingFailed, e.JSONParsingFailed.GetMsg())
  79. return
  80. }
  81. result, total, err := unity.Paginate(pages, models.Shop{})
  82. if err != nil {
  83. e.ResponseWithMsg(c, e.PaginationFailed, e.PaginationFailed.GetMsg())
  84. return
  85. }
  86. e.ResPonsePage(c, result, total, pages)
  87. }