From 2f678ed714cc28fed07898f99213993b4e250446 Mon Sep 17 00:00:00 2001 From: jiangyong27 Date: Fri, 2 Feb 2024 16:19:30 +0800 Subject: [PATCH] =?UTF-8?q?=E8=BF=9F=E5=88=B0=E8=AE=A1=E7=AE=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- worker/staff.go | 55 ++++++++++++++++++++++++++++++------------------- 1 file changed, 34 insertions(+), 21 deletions(-) diff --git a/worker/staff.go b/worker/staff.go index 646067b..944e83f 100644 --- a/worker/staff.go +++ b/worker/staff.go @@ -100,7 +100,7 @@ func (s *Staff) SyncStaffSalary(month string) { month = time.Now().AddDate(0, -1, 0).Format("2006-01") } month = strings.ReplaceAll(month, "-", "") - totalDays := s.getTotalWordDay(month) + totalDays := s.getTotalWorkDay(month) monthTime, _ := time.ParseInLocation("200601", month, time.Local) startDate := cast.ToInt(monthTime.Format("20060102")) endDate := cast.ToInt(monthTime.AddDate(0, 1, -1).Format("20060102")) @@ -159,27 +159,11 @@ func (s *Staff) SyncStaffSalary(month string) { surplusHoliday := float64(0) for _, vac := range approveVacations { holiday += vac.VacationDuration - surplusHoliday += goutil.If(vac.VacationDuration <= 1, 1-vac.VacationDuration, 0) + surplusHoliday += goutil.If(vac.VacationDuration < 1, 1-vac.VacationDuration, 0) } // 打卡正常天数+补卡天数 为正常出勤天数 - realWorkdays := 0 - userCheckins, err := dao.NewCheckinDao().Query(staff.Username, month, false) - if err != nil { - log.Errorf("db error :%s", err.Error()) - continue - } - for _, checkin := range userCheckins { - if checkin.Exception == "" { - realWorkdays += 1 - continue - } - approvalCheckin, _ := dao.NewApprovalCheckinDao().GetByUsernameDay(staff.Username, checkin.Day) - if approvalCheckin != nil { - realWorkdays += 1 - } - } - + realWorkDays := s.getRealWorkDay(staff.Username, month) extra := make(map[string]interface{}) salary.BaseSalary = cast.ToFloat64(staff.Salary) salary.Holiday = holiday @@ -191,7 +175,7 @@ func (s *Staff) SyncStaffSalary(month string) { discount = discount*float64(officialDate-startDate)/totalMonthDay + 1*float64(endDate-officialDate+1)/totalMonthDay } - realWorkDays := float64(realWorkdays) + surplusHoliday + realWorkDays = realWorkDays + surplusHoliday realSalary := salary.BaseSalary * (realWorkDays / float64(totalDays)) * discount staffSalaryPerDay := cast.ToFloat64(config.Get(model.StaffSalaryPerDay)) if staffSalaryPerDay > 0 { @@ -231,7 +215,36 @@ func (s *Staff) SyncStaffSalary(month string) { } -func (s *Staff) getTotalWordDay(month string) int64 { +func (s *Staff) getRealWorkDay(username, month string) float64 { + realWorkdays := float64(0) + userCheckins, err := dao.NewCheckinDao().Query(username, month, false) + if err != nil { + log.Errorf("db error :%s", err.Error()) + return realWorkdays + } + for _, checkin := range userCheckins { + if checkin.Exception == "" { + realWorkdays += 1 + continue + } + approvalCheckin, _ := dao.NewApprovalCheckinDao().GetByUsernameDay(username, checkin.Day) + if approvalCheckin != nil { + realWorkdays += 1 + continue + } + + // 迟到的按时间折算 + if strings.Contains(checkin.Exception, "上班打卡:时间异常") { + stTime := time.Unix(checkin.StartTime, 0) + later := float64(stTime.Hour() - 8) //迟到小时数,从9点算 + realWorkdays += (8 - later) / 8 + continue + } + } + return realWorkdays +} + +func (s *Staff) getTotalWorkDay(month string) int64 { // 最多人数的应出勤天数 为真正的出勤天数 userCounts, err := dao.NewCheckinDao().CountUsername(month) if err != nil {