worksiteclock.go 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. package work
  2. import (
  3. "zhiyuan/pkg/app"
  4. "zhiyuan/pkg/utils"
  5. "zhiyuan/services/work/worksiteclock"
  6. "github.com/gin-gonic/gin"
  7. )
  8. func WorkSiteClockList(c *gin.Context) {
  9. page := app.HandlePageNums(c)
  10. where := map[string]string{
  11. "where": "`zy_work_site_clock`.`id`>0 AND `zy_work_site_clock`.`deleted_at`=0",
  12. "_order_by": "`zy_work_site_clock`.`id` desc",
  13. }
  14. if page.PageSize != 0 {
  15. where["_page_size"] = utils.ToStr(page.PageSize)
  16. where["_page_num"] = utils.ToStr(page.PageNum)
  17. }
  18. param := make(map[string]interface{})
  19. site_id := utils.ToInt(c.Query("site_id"))
  20. if site_id != 0 {
  21. where["where"] = where["where"] + " AND `zy_work_site_clock`.`site_id`={{site_id}}"
  22. param["site_id"] = site_id
  23. }
  24. site_node_id := utils.ToInt(c.Query("site_node_id"))
  25. if site_node_id != 0 {
  26. where["where"] = where["where"] + " AND `zy_work_site_clock`.`site_node_id`={{site_node_id}}"
  27. param["site_node_id"] = site_node_id
  28. }
  29. staff_type := utils.ToInt(c.Query("staff_type"))
  30. if staff_type != 0 {
  31. where["where"] = where["where"] + " AND `zy_work_site_clock`.`staff_type`={{staff_type}}"
  32. param["staff_type"] = staff_type
  33. }
  34. staff_id := utils.ToInt(c.Query("staff_id"))
  35. if staff_id != 0 {
  36. where["where"] = where["where"] + " AND `zy_work_site_clock`.`staff_id`={{staff_id}}"
  37. param["staff_id"] = staff_id
  38. }
  39. state := utils.ToInt(c.Query("state"))
  40. if state != 0 {
  41. where["where"] = where["where"] + " AND `zy_work_site_clock`.`state`={{state}}"
  42. param["state"] = state
  43. }
  44. starttime := utils.ToInt(c.Query("starttime"))
  45. if starttime != 0 {
  46. where["where"] = where["where"] + " AND `zy_work_site_clock`.`created_at` >= {{starttime}}"
  47. param["starttime"] = starttime
  48. }
  49. endtime := utils.ToInt(c.Query("endtime"))
  50. if endtime != 0 {
  51. where["where"] = where["where"] + " AND `zy_work_site_clock`.`created_at` <= {{endtime}}"
  52. param["endtime"] = endtime
  53. }
  54. total, err := worksiteclock.CountRaw(where["where"], param)
  55. if err != nil {
  56. app.Error(c, err.Error())
  57. return
  58. }
  59. type WorkSiteClockList struct {
  60. ID int `json:"id"`
  61. SiteId int `json:"site_id"`
  62. SiteNodeId int `json:"site_node_id"`
  63. StaffType int `json:"staff_type"`
  64. StaffId int `json:"staff_id"`
  65. Pictures string `json:"pictures"`
  66. Content string `json:"content"`
  67. Type int `json:"type"`
  68. State int `json:"state"`
  69. CreatedAt int `json:"created_at"`
  70. UpdatedAt int `json:"updated_at"`
  71. StaffName string `json:"staff_name"`
  72. StaffPhone string `json:"staff_phone"`
  73. NodeName string `json:"node_name"`
  74. }
  75. workSiteClockList := make([]WorkSiteClockList, 0)
  76. if err = worksiteclock.GetWorkSiteClocksRaw(where, param, &workSiteClockList); err != nil {
  77. app.Error(c, err.Error())
  78. return
  79. }
  80. data := gin.H{
  81. "list": workSiteClockList,
  82. "total": total,
  83. "limit": page.PageSize,
  84. }
  85. app.Success(c, data)
  86. }
  87. func WorkSiteClockVerify(c *gin.Context) {
  88. id := utils.ToInt(c.Param("id"))
  89. if id <= 0 {
  90. app.ErrorMsg(c, "id must be a number", nil)
  91. return
  92. }
  93. err := worksiteclock.VerifyByID(id, c.GetInt("adminID"))
  94. if err != nil {
  95. app.ErrorMsg(c, err.Error(), nil)
  96. return
  97. }
  98. app.Success(c, nil)
  99. }