final_worker_attendance.go 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. package final
  2. import (
  3. "github.com/gin-gonic/gin"
  4. "time"
  5. "zhiyuan/models"
  6. "zhiyuan/pkg/db"
  7. )
  8. type WorkerAttendance struct {
  9. ID int64 `json:"id" prop:"add:false"`
  10. WorkerId int64 `json:"worker_id"`
  11. ClockTime int64 `json:"clock_time"`
  12. Pictures string `json:"pictures"`
  13. CreatedAt int64 `json:"created_at" prop:"add:false"`
  14. SiteId int64 `json:"site_id"`
  15. RoomType int64 `json:"room_type"`
  16. SiteName string `json:"site_name" prop:"select:site.village"`
  17. Address string `json:"address" prop:"select:site.address"`
  18. Username string `json:"username" prop:"select:site.username"`
  19. db.BaseModel
  20. }
  21. func (WorkerAttendance) TableName() string {
  22. return "zy_worker_attendance"
  23. }
  24. func (o WorkerAttendance) GetOne(where map[string]interface{}, fields []string, retVal interface{}) (*WorkerAttendance, error) {
  25. if retVal == nil {
  26. var matBidOrder *WorkerAttendance
  27. err := db.GetOne(o.TableName(), where, fields, &matBidOrder)
  28. return matBidOrder, err
  29. } else {
  30. err := db.GetOne(o.TableName(), where, fields, retVal)
  31. return nil, err
  32. }
  33. }
  34. func (o WorkerAttendance) ListPrivilege(c *gin.Context, data map[string]interface{}, s *db.Select) bool {
  35. return true
  36. }
  37. func (WorkerAttendance) ListAfter(c *gin.Context, data map[string]interface{}, list []map[string]interface{}) []map[string]interface{} {
  38. return list
  39. }
  40. func (WorkerAttendance) OnePrivilege(c *gin.Context, id int64) bool {
  41. return true
  42. }
  43. func (WorkerAttendance) AddPrivilege(c *gin.Context, data map[string]interface{}, post map[string]interface{}) error {
  44. return nil
  45. }
  46. func (WorkerAttendance) EditPrivilege(c *gin.Context, id int64, data map[string]interface{}, post map[string]interface{}) error {
  47. return nil
  48. }
  49. func (WorkerAttendance) DelPrivilege(c *gin.Context, id int64) error {
  50. return nil
  51. }
  52. func (WorkerAttendance) Page() bool {
  53. return false
  54. }
  55. func (WorkerAttendance) Count() bool {
  56. return true
  57. }
  58. func (o WorkerAttendance) LeftJoin(data map[string]interface{}, s *db.Select) []db.JoinModel {
  59. return []db.JoinModel{
  60. {
  61. Model: models.Worker{},
  62. As: "worker",
  63. On: []string{"`worker`.`id` = " + o.TableName() + ".`worker_id`"},
  64. },
  65. {
  66. Model: FinalSite{},
  67. As: "site",
  68. On: []string{"`site`.`id` = " + o.TableName() + ".`site_id`"},
  69. },
  70. }
  71. }
  72. // 检查用户当天的打卡次数
  73. func GetTodayAttendanceCount(WorkerID, SiteId, RoomType int) (int64, error) {
  74. today := time.Now().Format("2006-01-02") // 获取当天的日期
  75. param := make(map[string]interface{})
  76. param["worker_id"] = WorkerID
  77. param["site_id"] = SiteId
  78. param["room_type"] = RoomType
  79. param["clock_time"] = today
  80. sql := "zy_worker_attendance WHERE worker_id= {{worker_id}} and site_id = {{site_id}} and room_type={{room_type}} and DATE(FROM_UNIXTIME(clock_time)) = CURDATE()"
  81. return db.CountRaw(sql, param)
  82. }