智慧食堂
No puede seleccionar más de 25 temas Los temas deben comenzar con una letra o número, pueden incluir guiones ('-') y pueden tener hasta 35 caracteres de largo.

127 líneas
3.2 KiB

  1. package hdl
  2. import (
  3. "applet/app/admin/lib/validate"
  4. "applet/app/admin/md"
  5. "applet/app/admin/svc"
  6. "applet/app/db"
  7. "applet/app/e"
  8. "applet/app/enum"
  9. "applet/app/utils"
  10. "github.com/gin-gonic/gin"
  11. )
  12. func UserList(c *gin.Context) {
  13. var req md.UserListReq
  14. err := c.ShouldBindJSON(&req)
  15. if err != nil {
  16. err = validate.HandleValidateErr(err)
  17. err1 := err.(e.E)
  18. e.OutErr(c, err1.Code, err1.Error())
  19. return
  20. }
  21. list, err := svc.UserList(req)
  22. if err != nil {
  23. e.OutErr(c, e.ERR_DB_ORM, err.Error())
  24. return
  25. }
  26. e.OutSuc(c, map[string]interface{}{
  27. "list": list,
  28. "user_identity_kind_list": []map[string]interface{}{
  29. {
  30. "name": enum.UserIdentity.String(enum.UserIdentityForCentralKitchenForStudent),
  31. "value": enum.UserIdentityForCentralKitchenForStudent,
  32. },
  33. {
  34. "name": enum.UserIdentity.String(enum.UserIdentityForCentralKitchenForTeacher),
  35. "value": enum.UserIdentityForCentralKitchenForTeacher,
  36. },
  37. {
  38. "name": enum.UserIdentity.String(enum.UserIdentityForCentralKitchenForWorker),
  39. "value": enum.UserIdentityForCentralKitchenForWorker,
  40. },
  41. {
  42. "name": enum.UserIdentity.String(enum.UserIdentityForSelfSupportForStudent),
  43. "value": enum.UserIdentityForSelfSupportForStudent,
  44. },
  45. {
  46. "name": enum.UserIdentity.String(enum.UserIdentityForSelfSupportForTeacher),
  47. "value": enum.UserIdentityForSelfSupportForTeacher,
  48. },
  49. {
  50. "name": enum.UserIdentity.String(enum.UserIdentityForSelfSupportForWorker),
  51. "value": enum.UserIdentityForSelfSupportForWorker,
  52. },
  53. },
  54. "enterprise_kind_list": []map[string]interface{}{
  55. {
  56. "name": enum.EnterprisePvd.String(enum.EnterprisePvdByCentralKitchenForSchool),
  57. "value": enum.EnterprisePvdByCentralKitchenForSchool,
  58. },
  59. {
  60. "name": enum.EnterprisePvd.String(enum.EnterprisePvdByCentralKitchenForFactory),
  61. "value": enum.EnterprisePvdByCentralKitchenForFactory,
  62. },
  63. {
  64. "name": enum.EnterprisePvd.String(enum.EnterprisePvdBySelfSupportForSchool),
  65. "value": enum.EnterprisePvdBySelfSupportForSchool,
  66. },
  67. {
  68. "name": enum.EnterprisePvd.String(enum.EnterprisePvdBySelfSupportForFactory),
  69. "value": enum.EnterprisePvdBySelfSupportForFactory,
  70. },
  71. {
  72. "name": enum.EnterprisePvd.String(enum.EnterprisePvdByNursingHome),
  73. "value": enum.EnterprisePvdByNursingHome,
  74. },
  75. },
  76. }, nil)
  77. return
  78. }
  79. func UserUpdate(c *gin.Context) {
  80. var req md.UserList
  81. err := c.ShouldBindJSON(&req)
  82. if err != nil {
  83. err = validate.HandleValidateErr(err)
  84. err1 := err.(e.E)
  85. e.OutErr(c, err1.Code, err1.Error())
  86. return
  87. }
  88. err = svc.UserUpdate(req)
  89. if err != nil {
  90. e.OutErr(c, e.ERR_DB_ORM, err.Error())
  91. return
  92. }
  93. e.OutSuc(c, "success", nil)
  94. return
  95. }
  96. func UserDelete(c *gin.Context) {
  97. id := c.Param("id")
  98. //TODO::判断当前用户下是否还绑定了身份
  99. userIdentityDb := db.UserIdentityDb{}
  100. userIdentityDb.Set(utils.StrToInt(id))
  101. identity, err := userIdentityDb.FindUserIdentity()
  102. if err != nil {
  103. e.OutErr(c, e.ERR_DB_ORM, err.Error())
  104. return
  105. }
  106. if len(*identity) > 0 {
  107. e.OutErr(c, e.ERR_DB_ORM, "当前用户下存在未解绑身份")
  108. return
  109. }
  110. userDb := db.UserDb{}
  111. userDb.Set()
  112. _, err = userDb.DeleteUser(utils.StrToInt(id))
  113. if err != nil {
  114. e.OutErr(c, e.ERR_DB_ORM, err.Error())
  115. return
  116. }
  117. e.OutSuc(c, "success", nil)
  118. return
  119. }