worksiteproblemreport.go 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. package work
  2. import (
  3. "zhiyuan/models"
  4. "zhiyuan/pkg/app"
  5. "zhiyuan/pkg/db"
  6. "zhiyuan/pkg/utils"
  7. "zhiyuan/services/form"
  8. "github.com/gin-gonic/gin"
  9. )
  10. func WorkSiteProblemReportCheck(c *gin.Context) {
  11. id := utils.ToInt(c.Param("id"))
  12. if id <= 0 {
  13. app.ErrorMsg(c, "id must be a number", nil)
  14. return
  15. }
  16. var checkForm form.WorkSiteQualityAcceptReportCheckFrom
  17. if app.Bind(c, &checkForm) != nil {
  18. return
  19. }
  20. var model models.WorkSiteProblemReport
  21. db.GetModel(map[string]interface{}{
  22. "id": id,
  23. }, &model)
  24. if model.ID == 0 {
  25. app.ErrorMsg(c, "整改不存在", nil)
  26. return
  27. }
  28. err := db.UpdateModel(db.Type(model), int64(id), map[string]interface{}{
  29. "state": checkForm.State,
  30. "explain": checkForm.Explain,
  31. "check_id": c.GetInt("adminID"),
  32. })
  33. if err != nil {
  34. app.ErrorMsg(c, err.Error(), nil)
  35. return
  36. }
  37. state := 0
  38. if model.Type == 0 {
  39. if checkForm.State == 2 {
  40. state = 2
  41. } else {
  42. state = 0
  43. }
  44. } else if model.Type == 1 {
  45. if checkForm.State == 2 {
  46. state = 4
  47. } else {
  48. state = 2
  49. }
  50. } else {
  51. if checkForm.State == 2 {
  52. state = 6
  53. } else {
  54. state = 4
  55. }
  56. }
  57. if checkForm.State == 3 {
  58. state = 6
  59. }
  60. err = db.UpdateModel(db.Type(models.WorkSiteProblem{}), int64(model.SiteProblemId), map[string]interface{}{
  61. "state": state,
  62. })
  63. if err != nil {
  64. app.ErrorMsg(c, err.Error(), nil)
  65. return
  66. }
  67. app.Success(c, nil)
  68. }