99 lines
2.7 KiB
Go
99 lines
2.7 KiB
Go
package salary_calculator
|
|
|
|
import (
|
|
butil "enterprise/base/util"
|
|
"enterprise/common/dao"
|
|
"enterprise/common/model"
|
|
"enterprise/common/registry"
|
|
log "github.com/sirupsen/logrus"
|
|
"github.com/smbrave/goutil"
|
|
"github.com/spf13/cast"
|
|
"strings"
|
|
"time"
|
|
)
|
|
|
|
const (
|
|
SalaryCalculatorOperation = "operation" //运营计算工资的方法
|
|
)
|
|
|
|
type SalaryCalculator1000 struct {
|
|
corp *model.Corp
|
|
user *model.StaffUser
|
|
}
|
|
|
|
func NewSalaryCalculator1000(corp *model.Corp, user *model.StaffUser) registry.SalaryCalculator {
|
|
return &SalaryCalculator1000{
|
|
corp: corp,
|
|
user: user,
|
|
}
|
|
}
|
|
|
|
func (s *SalaryCalculator1000) Calculate(salary *model.StaffSalary) map[string]interface{} {
|
|
return nil
|
|
}
|
|
|
|
func (s *SalaryCalculator1000) CalculateDe(salary *model.StaffSalary) {
|
|
userSlary := s.user.GetSalary()
|
|
userConfig := s.user.GetConfig()
|
|
if s.user.Status == model.StaffUserStatusAttach { //挂靠直接算工资
|
|
salary.AttendSalary = cast.ToFloat64(userSlary.Base)
|
|
salary.TargetSalary = cast.ToFloat64(userSlary.Target)
|
|
return
|
|
}
|
|
//离职同步不到数据了
|
|
if salary.Username == "wangyuqi" && salary.Month == "202502" {
|
|
salary.AttendDay = 20 - 0.62
|
|
}
|
|
|
|
salary.AttendSalary = cast.ToFloat64(userSlary.Base) * (salary.AttendDay / float64(salary.ShouldDay))
|
|
salary.TargetSalary = cast.ToFloat64(userSlary.Target)
|
|
|
|
if userConfig.SalaryCalcutor == SalaryCalculatorOperation {
|
|
s.operationCalculate(salary)
|
|
}
|
|
|
|
}
|
|
|
|
func (s *SalaryCalculator1000) operationCalculate(salary *model.StaffSalary) {
|
|
userConfig := s.user.GetConfig()
|
|
if userConfig.PerftTarget == "" {
|
|
return
|
|
}
|
|
s.getExtraSalary(salary)
|
|
}
|
|
|
|
func (s *SalaryCalculator1000) getExtraSalary(salary *model.StaffSalary) {
|
|
fields := strings.Split(s.user.GetConfig().PerftTarget, ",")
|
|
perfTarget := cast.ToFloat64(fields[0])
|
|
awardRate := cast.ToFloat64(fields[1])
|
|
|
|
monthTime, _ := time.ParseInLocation("200601", salary.Month, time.Local)
|
|
startDay := monthTime.Format("2006-01-02")
|
|
endDay := monthTime.AddDate(0, 1, -1).Format("2006-01-02")
|
|
datas, err := dao.NewUnifyAdData().QueryOwnerData(s.user.Username, startDay, endDay)
|
|
if err != nil {
|
|
log.Errorf("db error :%s", err.Error())
|
|
return
|
|
}
|
|
sumProfitAmount := int64(0)
|
|
for _, data := range datas {
|
|
sumProfitAmount += data.PayAmount - data.Cost
|
|
}
|
|
totalProfit := cast.ToFloat64(goutil.FormatMoney(sumProfitAmount))
|
|
salary.SetExtra("totalProfit", cast.ToString(totalProfit))
|
|
|
|
//1算提成
|
|
userSalary := s.user.GetSalary()
|
|
awardSalary := float64(0)
|
|
targetSalary := float64(0)
|
|
if totalProfit > perfTarget {
|
|
awardSalary = totalProfit * awardRate
|
|
if awardSalary < 0 {
|
|
awardSalary = 0
|
|
}
|
|
targetSalary = cast.ToFloat64(userSalary.Target)
|
|
}
|
|
salary.TargetSalary = butil.FloatCut(targetSalary)
|
|
salary.AwardSalary = butil.FloatCut(awardSalary)
|
|
}
|