package final import ( "github.com/gin-gonic/gin" "time" "zhiyuan/models" "zhiyuan/pkg/db" ) type WorkerAttendance struct { ID int64 `json:"id" prop:"add:false"` WorkerId int64 `json:"worker_id"` ClockTime int64 `json:"clock_time"` Pictures string `json:"pictures"` CreatedAt int64 `json:"created_at" prop:"add:false"` SiteId int64 `json:"site_id"` RoomType int64 `json:"room_type"` SiteName string `json:"site_name" prop:"select:site.village"` Address string `json:"address" prop:"select:site.address"` Username string `json:"username" prop:"select:site.username"` db.BaseModel } func (WorkerAttendance) TableName() string { return "zy_worker_attendance" } func (o WorkerAttendance) GetOne(where map[string]interface{}, fields []string, retVal interface{}) (*WorkerAttendance, error) { if retVal == nil { var matBidOrder *WorkerAttendance err := db.GetOne(o.TableName(), where, fields, &matBidOrder) return matBidOrder, err } else { err := db.GetOne(o.TableName(), where, fields, retVal) return nil, err } } func (o WorkerAttendance) ListPrivilege(c *gin.Context, data map[string]interface{}, s *db.Select) bool { return true } func (WorkerAttendance) ListAfter(c *gin.Context, data map[string]interface{}, list []map[string]interface{}) []map[string]interface{} { return list } func (WorkerAttendance) OnePrivilege(c *gin.Context, id int64) bool { return true } func (WorkerAttendance) AddPrivilege(c *gin.Context, data map[string]interface{}, post map[string]interface{}) error { return nil } func (WorkerAttendance) EditPrivilege(c *gin.Context, id int64, data map[string]interface{}, post map[string]interface{}) error { return nil } func (WorkerAttendance) DelPrivilege(c *gin.Context, id int64) error { return nil } func (WorkerAttendance) Page() bool { return false } func (WorkerAttendance) Count() bool { return true } func (o WorkerAttendance) LeftJoin(data map[string]interface{}, s *db.Select) []db.JoinModel { return []db.JoinModel{ { Model: models.Worker{}, As: "worker", On: []string{"`worker`.`id` = " + o.TableName() + ".`worker_id`"}, }, { Model: FinalSite{}, As: "site", On: []string{"`site`.`id` = " + o.TableName() + ".`site_id`"}, }, } } // 检查用户当天的打卡次数 func GetTodayAttendanceCount(WorkerID, SiteId, RoomType int) (int64, error) { today := time.Now().Format("2006-01-02") // 获取当天的日期 param := make(map[string]interface{}) param["worker_id"] = WorkerID param["site_id"] = SiteId param["room_type"] = RoomType param["clock_time"] = today 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()" return db.CountRaw(sql, param) }