enterprise/service/salary_calculator/salary_calculator_1002.go

78 lines
2.3 KiB
Go
Raw Normal View History

2025-03-05 10:11:07 +08:00
package salary_calculator
import (
2025-03-05 16:44:20 +08:00
"enterprise/common/dao"
2025-03-05 10:11:07 +08:00
"enterprise/common/model"
"enterprise/common/registry"
2025-03-05 16:44:20 +08:00
log "github.com/sirupsen/logrus"
2025-03-05 10:11:07 +08:00
"github.com/spf13/cast"
2025-03-05 23:41:21 +08:00
"strings"
2025-03-05 16:44:20 +08:00
"time"
2025-03-05 10:11:07 +08:00
)
type SalaryCalculator1002 struct {
corp *model.Corp
user *model.StaffUser
}
func NewSalaryCalculator1002(corp *model.Corp, user *model.StaffUser) registry.SalaryCalculator {
return &SalaryCalculator1002{
corp: corp,
user: user,
}
}
func (s *SalaryCalculator1002) Calculate(salary *model.StaffSalary) {
userSlary := s.user.GetSalary()
if s.user.Status == model.StaffUserStatusAttach { //挂靠直接算工资
salary.AttendSalary = cast.ToFloat64(userSlary.Base)
salary.TargetSalary = cast.ToFloat64(userSlary.Target)
return
}
2025-03-05 23:41:21 +08:00
if salary.UserName == "luoyi" {
salary.AttendDay = float64(salary.ShouldDay - 3)
} else if strings.ToLower(salary.UserName) == "wangyan" {
2025-03-05 23:48:45 +08:00
salary.AttendDay = float64(salary.ShouldDay) - 3.6
2025-03-05 23:41:21 +08:00
} else if strings.ToLower(salary.UserName) == "zhouhong" {
2025-03-05 23:48:45 +08:00
salary.AttendDay = float64(salary.ShouldDay) - 3.6
2025-03-05 23:41:21 +08:00
}
2025-03-05 10:11:07 +08:00
salary.AttendSalary = cast.ToFloat64(userSlary.Base) * (salary.AttendDay / float64(salary.ShouldDay))
salary.TargetSalary = cast.ToFloat64(userSlary.Target)
2025-03-05 16:44:20 +08:00
monthTime, _ := time.ParseInLocation("200601", salary.Month, time.Local)
startTime := monthTime.Unix()
endTime := monthTime.AddDate(0, 1, 0).Unix() - 1
2025-03-05 23:38:56 +08:00
orders, err := dao.NewExternalCorpOrder().QueryOwnerOrder(s.user.Username, startTime, endTime)
2025-03-05 16:44:20 +08:00
if err != nil {
log.Errorf("db error:%s", err.Error())
return
}
orderNum := len(orders)
2025-03-05 23:38:56 +08:00
salary.SetExtra("corp_order_num", cast.ToString(orderNum))
processOrders, err := dao.NewExternalCorpOrder().QueryProcessOrder(s.user.Username, startTime, endTime)
if err != nil {
log.Errorf("db error:%s", err.Error())
return
}
processOrderNum := len(processOrders)
salary.SetExtra("corp_process_order_num", cast.ToString(processOrderNum))
2025-03-05 16:44:20 +08:00
if orderNum >= 40 {
salary.TargetSalary = cast.ToFloat64(userSlary.Target)
if orderNum <= 60 {
salary.AwardSalary = float64((orderNum - 40) * 80)
} else if orderNum <= 80 {
salary.AwardSalary = 1600 + float64((orderNum-60)*100)
} else {
salary.AwardSalary = 3600 + float64((orderNum-80)*120)
}
} else {
salary.TargetSalary = float64(60 * orderNum)
}
2025-03-05 23:38:56 +08:00
salary.AwardSalary += float64(processOrderNum * 5)
2025-03-05 10:11:07 +08:00
}