work.go 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205
  1. package user
  2. import (
  3. "zhiyuan/pkg/app"
  4. "zhiyuan/pkg/utils"
  5. "zhiyuan/services/user"
  6. "zhiyuan/services/work/worksite"
  7. "zhiyuan/services/work/worksiteclock"
  8. "github.com/gin-gonic/gin"
  9. )
  10. func WorkSiteList(c *gin.Context) {
  11. page := app.HandlePageNums(c)
  12. where := map[string]string{
  13. "where": "`zy_work_site`.`id`>0 AND `zy_work_site`.`deleted_at`=0",
  14. "_group_by": "`zy_work_site`.`id`",
  15. "_order_by": "`zy_work_site`.`id` desc",
  16. }
  17. if page.PageSize != 0 {
  18. where["_page_size"] = utils.ToStr(page.PageSize)
  19. where["_page_num"] = utils.ToStr(page.PageNum)
  20. }
  21. param := make(map[string]interface{})
  22. username := c.Query("username")
  23. if username != "" {
  24. where["where"] = where["where"] + " AND `zy_work_site`.`username` LIKE {{username}}"
  25. param["username"] = "%" + username + "%"
  26. }
  27. phone := c.Query("phone")
  28. if phone != "" {
  29. where["where"] = where["where"] + " AND `zy_work_site`.`phone` LIKE {{phone}}"
  30. param["phone"] = "%" + phone + "%"
  31. }
  32. village := c.Query("village")
  33. if village != "" {
  34. where["where"] = where["where"] + " AND `zy_work_site`.`village` LIKE {{village}}"
  35. param["village"] = "%" + village + "%"
  36. }
  37. address := c.Query("address")
  38. if address != "" {
  39. where["where"] = where["where"] + " AND `zy_work_site`.`address` LIKE {{address}}"
  40. param["address"] = "%" + address + "%"
  41. }
  42. room_no := c.Query("room_no")
  43. if room_no != "" {
  44. where["where"] = where["where"] + " AND `zy_work_site`.`room_no` LIKE {{room_no}}"
  45. param["room_no"] = "%" + room_no + "%"
  46. }
  47. area := c.Query("area")
  48. if area != "" {
  49. where["where"] = where["where"] + " AND `zy_work_site`.`area` LIKE {{area}}"
  50. param["area"] = "%" + area + "%"
  51. }
  52. state := utils.ToInt(c.Query("state"))
  53. if state != 0 {
  54. where["where"] = where["where"] + " AND `zy_work_site`.`state`={{state}}"
  55. param["state"] = state
  56. }
  57. userInfo, err := user.GetInfoByID(c.GetInt("userID"), nil, nil)
  58. if userInfo == nil || err != nil {
  59. app.ErrorMsg(c, err.Error(), nil)
  60. return
  61. }
  62. where["where"] = where["where"] + " AND `zy_work_site`.`phone` = {{phone}}"
  63. param["phone"] = userInfo.Phone
  64. total, err := worksite.CountRaw(where["where"], param)
  65. if err != nil {
  66. app.Error(c, err.Error())
  67. return
  68. }
  69. type WorksiteList struct {
  70. ID int `json:"id"`
  71. Username string `json:"username"`
  72. Phone string `json:"phone"`
  73. Village string `json:"village"`
  74. Address string `json:"address"`
  75. RoomNo string `json:"room_no"`
  76. Area string `json:"area"`
  77. Longitude string `json:"longitude"`
  78. Latitude string `json:"latitude"`
  79. ManagerId int `json:"manager_id"`
  80. DesignerId int `json:"designer_id"`
  81. CreatedId int `json:"created_id"`
  82. AdminIds string `json:"admin_ids"`
  83. StartTime int `json:"starttime"`
  84. EndTime int `json:"endtime"`
  85. State int `json:"state"`
  86. CreatedAt int `json:"created_at"`
  87. UpdatedAt int `json:"updated_at"`
  88. ManagerName string `json:"manager_name"`
  89. ManagerPhone string `json:"manager_phone"`
  90. DesignerName string `json:"designer_name"`
  91. DesignerPhone string `json:"designer_phone"`
  92. CreatedName string `json:"created_name"`
  93. AdminNames string `json:"admin_names"`
  94. }
  95. worksiteList := make([]WorksiteList, 0)
  96. if err = worksite.GetWorkSitesRaw(where, param, &worksiteList); err != nil {
  97. app.Error(c, err.Error())
  98. return
  99. }
  100. data := gin.H{
  101. "list": worksiteList,
  102. "total": total,
  103. "limit": page.PageSize,
  104. }
  105. app.Success(c, data)
  106. }
  107. func WorkSiteClockList(c *gin.Context) {
  108. page := app.HandlePageNum(c)
  109. where := map[string]string{
  110. "where": "`zy_work_site_clock`.`id`>0 AND `zy_work_site_clock`.`deleted_at`=0 AND `zy_work_site_clock`.`state`=1",
  111. "_order_by": "`zy_work_site_clock`.`id` desc",
  112. }
  113. if page.PageSize != 0 {
  114. where["_page_size"] = utils.ToStr(page.PageSize)
  115. where["_page_num"] = utils.ToStr(page.PageNum)
  116. }
  117. param := make(map[string]interface{})
  118. site_id := utils.ToInt(c.Query("site_id"))
  119. if site_id != 0 {
  120. where["where"] = where["where"] + " AND `zy_work_site_clock`.`site_id`={{site_id}}"
  121. param["site_id"] = site_id
  122. }
  123. site_node_id := utils.ToInt(c.Query("site_node_id"))
  124. if site_node_id != 0 {
  125. where["where"] = where["where"] + " AND `zy_work_site_clock`.`site_node_id`={{site_node_id}}"
  126. param["site_node_id"] = site_node_id
  127. }
  128. staff_type := utils.ToInt(c.Query("staff_type"))
  129. if staff_type != 0 {
  130. where["where"] = where["where"] + " AND `zy_work_site_clock`.`staff_type`={{staff_type}}"
  131. param["staff_type"] = staff_type
  132. }
  133. staff_id := utils.ToInt(c.Query("staff_id"))
  134. if staff_id != 0 {
  135. where["where"] = where["where"] + " AND `zy_work_site_clock`.`staff_id`={{staff_id}}"
  136. param["staff_id"] = staff_id
  137. }
  138. starttime := utils.ToInt(c.Query("starttime"))
  139. if starttime != 0 {
  140. where["where"] = where["where"] + " AND `zy_work_site_clock`.`created_at` >= {{starttime}}"
  141. param["starttime"] = starttime
  142. }
  143. endtime := utils.ToInt(c.Query("endtime"))
  144. if endtime != 0 {
  145. where["where"] = where["where"] + " AND `zy_work_site_clock`.`created_at` <= {{endtime}}"
  146. param["endtime"] = endtime
  147. }
  148. total, err := worksiteclock.CountRaw(where["where"], param)
  149. if err != nil {
  150. app.Error(c, err.Error())
  151. return
  152. }
  153. type WorkSiteClockList struct {
  154. ID int `json:"id"`
  155. SiteId int `json:"site_id"`
  156. SiteNodeId int `json:"site_node_id"`
  157. StaffType int `json:"staff_type"`
  158. StaffId int `json:"staff_id"`
  159. Pictures string `json:"pictures"`
  160. Content string `json:"content"`
  161. Type int `json:"type"`
  162. State int `json:"state"`
  163. CreatedAt int `json:"created_at"`
  164. UpdatedAt int `json:"updated_at"`
  165. StaffName string `json:"staff_name"`
  166. StaffPhone string `json:"staff_phone"`
  167. NodeName string `json:"node_name"`
  168. }
  169. workSiteClockList := make([]WorkSiteClockList, 0)
  170. if err = worksiteclock.GetWorkSiteClocksRaw(where, param, &workSiteClockList); err != nil {
  171. app.Error(c, err.Error())
  172. return
  173. }
  174. data := gin.H{
  175. "list": workSiteClockList,
  176. "total": total,
  177. "limit": page.PageSize,
  178. }
  179. app.Success(c, data)
  180. }