From 26fb5fdb6f0e530c6a03c95ff18532221abcac61 Mon Sep 17 00:00:00 2001 From: jiangyong27 Date: Tue, 5 Nov 2024 12:44:09 +0800 Subject: [PATCH] slave salary --- common/dao/staff_salary.go | 6 ++- .../model/{user_config.go => staff_config.go} | 0 common/model/staff_info.go | 1 + common/model/staff_salary.go | 12 +++++- server/service/staff_salary.go | 35 +++++++++++----- service/staff.go | 28 +++++++++++++ worker/staff.go | 42 +++++++++++++------ 7 files changed, 98 insertions(+), 26 deletions(-) rename common/model/{user_config.go => staff_config.go} (100%) diff --git a/common/dao/staff_salary.go b/common/dao/staff_salary.go index 5e83dbe..3d7c802 100644 --- a/common/dao/staff_salary.go +++ b/common/dao/staff_salary.go @@ -66,7 +66,7 @@ func (d *StaffSalaryDao) GetBy(username, month string) (*model.StaffSalary, erro return &u, nil } -func (d *StaffSalaryDao) Query(month, username string) ([]*model.StaffSalary, error) { +func (d *StaffSalaryDao) Query(month, username string, master *string) ([]*model.StaffSalary, error) { var u []*model.StaffSalary tx := GetDB().Table(d.TableName()) if month != "" { @@ -75,6 +75,10 @@ func (d *StaffSalaryDao) Query(month, username string) ([]*model.StaffSalary, er if username != "" { tx.Where("username = ?", username) } + if master != nil { + tx.Where("master = ?", *master) + } + tx.Order("month DESC") res := tx.Find(&u) diff --git a/common/model/user_config.go b/common/model/staff_config.go similarity index 100% rename from common/model/user_config.go rename to common/model/staff_config.go diff --git a/common/model/staff_info.go b/common/model/staff_info.go index 505f396..0dedbed 100644 --- a/common/model/staff_info.go +++ b/common/model/staff_info.go @@ -9,6 +9,7 @@ type StaffInfo struct { Id int64 Username string Realname string + Master string AlipayUid string StaffType string Phone string diff --git a/common/model/staff_salary.go b/common/model/staff_salary.go index 8d7c54f..2857a98 100644 --- a/common/model/staff_salary.go +++ b/common/model/staff_salary.go @@ -15,6 +15,7 @@ var ( type StaffSalary struct { Id int64 Username string + Master string Month string BaseSalary float64 PerfSalary float64 @@ -33,11 +34,18 @@ type StaffSalary struct { } func (s *StaffSalary) GetRealSalary() float64 { - return butil.FloatCut(s.AttendSalary + s.PerfSalary + s.AwardSalary - s.SocialInsurence - s.PersonalTax - s.HouseFund) + if s.Master == "" { + return butil.FloatCut(s.AttendSalary + s.PerfSalary + s.AwardSalary - s.SocialInsurence - s.PersonalTax - s.HouseFund) + } + + return butil.FloatCut(s.BaseSalary) } func (s *StaffSalary) GetShouldSalary() float64 { - return butil.FloatCut(s.AttendSalary + s.PerfSalary + s.AwardSalary) + if s.Master == "" { + return butil.FloatCut(s.AttendSalary + s.PerfSalary + s.AwardSalary) + } + return butil.FloatCut(s.BaseSalary) } type StaffSalarySort []*StaffSalary diff --git a/server/service/staff_salary.go b/server/service/staff_salary.go index be0c248..a1f744e 100644 --- a/server/service/staff_salary.go +++ b/server/service/staff_salary.go @@ -6,6 +6,7 @@ import ( "enterprise/common/config" "enterprise/common/dao" "enterprise/common/model" + "enterprise/service" "fmt" "github.com/gin-gonic/gin" log "github.com/sirupsen/logrus" @@ -29,7 +30,7 @@ type StaffSalary struct { func (s *StaffSalary) History(ctx *gin.Context) { username := ctx.Query("username") - staffSalarys, err := dao.NewStaffSalaryDao().Query("", username) + staffSalarys, err := dao.NewStaffSalaryDao().Query("", username, nil) if err != nil { panic(config.ErrDb.New().Append(err)) } @@ -77,7 +78,7 @@ func (s *StaffSalary) History(ctx *gin.Context) { func (s *StaffSalary) Agent(month string, ctx *gin.Context) { xls := ctx.Query("xls") - staffSalarys, err := dao.NewStaffSalaryDao().Query(month, "") + staffSalarys, err := dao.NewStaffSalaryDao().Query(month, "", nil) if err != nil { panic(config.ErrDb.New().Append(err)) } @@ -139,7 +140,7 @@ func (s *StaffSalary) Agent(month string, ctx *gin.Context) { func (s *StaffSalary) Bank(month string, ctx *gin.Context) { xls := ctx.Query("xls") - staffSalarys, err := dao.NewStaffSalaryDao().Query(month, "") + staffSalarys, err := dao.NewStaffSalaryDao().Query(month, "", nil) if err != nil { panic(config.ErrDb.New().Append(err)) } @@ -197,15 +198,18 @@ func (s *StaffSalary) Bank(month string, ctx *gin.Context) { func (s *StaffSalary) Summary(month string, ctx *gin.Context) { xls := ctx.Query("xls") - staffSalarys, err := dao.NewStaffSalaryDao().Query(month, "") + masterBank := "" + staffSalarys, err := dao.NewStaffSalaryDao().Query(month, "", &masterBank) if err != nil { panic(config.ErrDb.New().Append(err)) } sort.Sort(model.StaffSalarySort(staffSalarys)) - header := []string{"姓名", "身份证号", "入职日期", "转正日期", "基本工资", "绩效工资", "出勤工资", "奖金", "社保扣除", "公积金扣除", "个税扣除", "应出勤天数", "实际出勤天数", "出勤率", "补卡天数", "请假天数", "实发工资", "状态"} + header := []string{"姓名", "身份证号", "入职日期", "转正日期", "基本工资", "绩效工资", "出勤工资", "附属工资", "奖金", "社保扣除", "公积金扣除", "个税扣除", "应出勤天数", "实际出勤天数", "出勤率", "补卡天数", "请假天数", "实发工资", "状态"} datas := make([][]string, 0) summary := new(model.StaffSalary) + totalCount := 0 + totalSlaveSalary := float64(0) for _, staff := range staffSalarys { baseInfo, err := dao.NewStaffInfoDao().GetByUsername(staff.Username) if err != nil { @@ -225,6 +229,14 @@ func (s *StaffSalary) Summary(month string, ctx *gin.Context) { item = append(item, cast.ToString(staff.BaseSalary)) item = append(item, cast.ToString(butil.FloatCut(staff.PerfSalary))) item = append(item, cast.ToString(butil.FloatCut(staff.AttendSalary))) + + slaveSalary := float64(0) + info, _ := dao.NewStaffInfoDao().GetByUsername(staff.Username) + if info != nil { + slaveSalary = service.NewStaff(info, nil).GetSlaveSalary(month) + } + + item = append(item, cast.ToString(butil.FloatCut(slaveSalary))) item = append(item, cast.ToString(butil.FloatCut(staff.AwardSalary))) item = append(item, cast.ToString(staff.SocialInsurence)) item = append(item, cast.ToString(staff.HouseFund)) @@ -234,14 +246,15 @@ func (s *StaffSalary) Summary(month string, ctx *gin.Context) { item = append(item, fmt.Sprintf("%d%%", int(100*staff.RealDay/staff.TotalDay))) item = append(item, cast.ToString(extra["approvalCheckinDay"])) item = append(item, cast.ToString(staff.Holiday)) - item = append(item, cast.ToString(staff.GetRealSalary())) + item = append(item, cast.ToString(staff.GetRealSalary()+slaveSalary)) if staff.TotalDay != cast.ToFloat64(staff.RealDay)+cast.ToFloat64(staff.Holiday) { item = append(item, "【异常】") } else { item = append(item, "") } //item = append(item, fmt.Sprintf("https://e.batiao8.com/staff/salary/history?username=%s", baseInfo.Username)) - + totalCount += 1 + totalSlaveSalary += slaveSalary datas = append(datas, item) summary.BaseSalary += staff.BaseSalary summary.PerfSalary += staff.PerfSalary @@ -260,11 +273,11 @@ func (s *StaffSalary) Summary(month string, ctx *gin.Context) { summary.SocialInsurence = butil.FloatCut(summary.SocialInsurence) summary.HouseFund = butil.FloatCut(summary.HouseFund) summary.PersonalTax = butil.FloatCut(summary.PersonalTax) - datas = append(datas, []string{"合计", "-", "-", "-", - cast.ToString(summary.BaseSalary), cast.ToString(summary.PerfSalary), cast.ToString(summary.AttendSalary), cast.ToString(summary.AwardSalary), cast.ToString(summary.SocialInsurence), - cast.ToString(summary.HouseFund), + datas = append(datas, []string{"合计", cast.ToString(totalCount), "-", "-", + cast.ToString(summary.BaseSalary), cast.ToString(summary.PerfSalary), cast.ToString(summary.AttendSalary), cast.ToString(totalSlaveSalary), + cast.ToString(summary.AwardSalary), cast.ToString(summary.SocialInsurence), cast.ToString(summary.HouseFund), cast.ToString(summary.PersonalTax), "-", "-", "-", "-", cast.ToString(summary.Holiday), - cast.ToString(butil.FloatCut(summary.GetRealSalary())), "-"}) + cast.ToString(butil.FloatCut(summary.GetRealSalary() + totalSlaveSalary)), "-"}) if xls != "" { filename := fmt.Sprintf("summary_%s.xlsx", time.Now().Format("20060102_150405")) diff --git a/service/staff.go b/service/staff.go index 7787349..3dcd067 100644 --- a/service/staff.go +++ b/service/staff.go @@ -25,6 +25,34 @@ func NewStaff(info *model.StaffInfo, config *model.StaffConfig) *Staff { } } +func (s *Staff) GetSlaveSalary(month string) float64 { + slaveSalarys, err := dao.NewStaffSalaryDao().Query(month, "", &s.info.Username) + if err != nil { + log.Errorf("db error :%s", err.Error()) + return 0 + } + + totalSumSalary := float64(0) + if len(slaveSalarys) != 0 { + for _, slaveSalary := range slaveSalarys { + totalSumSalary += slaveSalary.BaseSalary + } + } + return totalSumSalary +} + +func (s *Staff) CalcSlaveSalary(salary *model.StaffSalary, month string) (*model.StaffSalary, error) { + if salary == nil { + salary = new(model.StaffSalary) + salary.Month = month + salary.Username = s.info.Username + } + salary.BaseSalary = cast.ToFloat64(s.info.BaseSalary) + salary.Master = s.info.Master + + return salary, nil +} + func (s *Staff) CalcSalary(salary *model.StaffSalary, month string) (*model.StaffSalary, error) { staff := s.info if salary == nil { diff --git a/worker/staff.go b/worker/staff.go index f602a9f..005b91c 100644 --- a/worker/staff.go +++ b/worker/staff.go @@ -55,7 +55,8 @@ func (s *Staff) MontorWorkAge() { } func (s *Staff) SendStaffSalaryBill(month string) { - staffSalarys, err := dao.NewStaffSalaryDao().Query(month, "") + masterBlank := "" + staffSalarys, err := dao.NewStaffSalaryDao().Query(month, "", &masterBlank) if err != nil { log.Errorf("db error :%s", err.Error()) return @@ -76,9 +77,20 @@ func (s *Staff) SendStaffSalaryBill(month string) { if staffSalary.AwardSalary >= 0.1 { message = append(message, fmt.Sprintf("额外工资:%.2f", staffSalary.AwardSalary)) } + + //附属工资 + var slaveSalary float64 = 0 + staff, _ := dao.NewStaffInfoDao().GetByUsername(staffSalary.Username) + if staff != nil { + slaveSalary = service.NewStaff(staff, nil).GetSlaveSalary(month) + if slaveSalary > 0.1 { + message = append(message, fmt.Sprintf("附属工资:%.2f", slaveSalary)) + } + } + message = append(message, fmt.Sprintf("社保扣除:%.2f", staffSalary.SocialInsurence)) message = append(message, fmt.Sprintf("个税扣除:%.2f", staffSalary.PersonalTax)) - message = append(message, fmt.Sprintf("实发工资:%.2f", staffSalary.GetRealSalary())) + message = append(message, fmt.Sprintf("实发工资:%.2f", staffSalary.GetRealSalary()+slaveSalary)) if err := global.SendMessage([]string{"jiangyong"}, strings.Join(message, "\n")); err != nil { log.Errorf("send message error :%s", err.Error()) @@ -165,22 +177,28 @@ func (s *Staff) SyncStaffSalary(month string) { } } - config, err := dao.NewUserConfigDao().GetByUsername(staff.Username) - if err != nil || config == nil { - log.Errorf("username[%s] not config,skip!!", staff.Username) - continue - } salary, err := dao.NewStaffSalaryDao().GetBy(staff.Username, month) if err != nil { log.Errorf("db error :%s", err.Error()) continue } - staffService := service.NewStaff(staff, config) - salary, err = staffService.CalcSalary(salary, month) - if err != nil { - log.Errorf("username[%s] staffService.CalcSalary error :%s", staff.Username, err.Error()) - continue + //附属员工直接生成工资单 + if staff.Master != "" { + staffService := service.NewStaff(staff, nil) + salary, err = staffService.CalcSlaveSalary(salary, month) + } else { + config, err := dao.NewUserConfigDao().GetByUsername(staff.Username) + if err != nil || config == nil { + log.Errorf("username[%s] not config,skip!!", staff.Username) + continue + } + staffService := service.NewStaff(staff, config) + salary, err = staffService.CalcSalary(salary, month) + if err != nil { + log.Errorf("username[%s] staffService.CalcSalary error :%s", staff.Username, err.Error()) + continue + } } if salary.Id == 0 {