智慧食堂
25'ten fazla konu seçemezsiniz Konular bir harf veya rakamla başlamalı, kısa çizgiler ('-') içerebilir ve en fazla 35 karakter uzunluğunda olabilir.

123 satır
3.1 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. }, nil)
  73. return
  74. }
  75. func UserUpdate(c *gin.Context) {
  76. var req md.UserList
  77. err := c.ShouldBindJSON(&req)
  78. if err != nil {
  79. err = validate.HandleValidateErr(err)
  80. err1 := err.(e.E)
  81. e.OutErr(c, err1.Code, err1.Error())
  82. return
  83. }
  84. err = svc.UserUpdate(req)
  85. if err != nil {
  86. e.OutErr(c, e.ERR_DB_ORM, err.Error())
  87. return
  88. }
  89. e.OutSuc(c, "success", nil)
  90. return
  91. }
  92. func UserDelete(c *gin.Context) {
  93. id := c.Param("id")
  94. //TODO::判断当前用户下是否还绑定了身份
  95. userIdentityDb := db.UserIdentityDb{}
  96. userIdentityDb.Set(utils.StrToInt(id))
  97. identity, err := userIdentityDb.FindUserIdentity()
  98. if err != nil {
  99. e.OutErr(c, e.ERR_DB_ORM, err.Error())
  100. return
  101. }
  102. if len(*identity) > 0 {
  103. e.OutErr(c, e.ERR_DB_ORM, "当前用户下存在未解绑身份")
  104. return
  105. }
  106. userDb := db.UserDb{}
  107. userDb.Set()
  108. _, err = userDb.DeleteUser(utils.StrToInt(id))
  109. if err != nil {
  110. e.OutErr(c, e.ERR_DB_ORM, err.Error())
  111. return
  112. }
  113. e.OutSuc(c, "success", nil)
  114. return
  115. }