appIncRate10024
This commit is contained in:
parent
79deaca2ba
commit
c5a006ec66
|
@ -1,14 +1,12 @@
|
||||||
package salary_calculator
|
package salary_calculator
|
||||||
|
|
||||||
import (
|
import (
|
||||||
butil "enterprise/base/util"
|
|
||||||
"enterprise/common/dao"
|
"enterprise/common/dao"
|
||||||
"enterprise/common/model"
|
"enterprise/common/model"
|
||||||
"enterprise/common/registry"
|
"enterprise/common/registry"
|
||||||
log "github.com/sirupsen/logrus"
|
log "github.com/sirupsen/logrus"
|
||||||
"github.com/smbrave/goutil"
|
"github.com/smbrave/goutil"
|
||||||
"github.com/spf13/cast"
|
"github.com/spf13/cast"
|
||||||
"strings"
|
|
||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -30,86 +28,62 @@ func NewSalaryCalculator1000(corp *model.Corp, user *model.StaffUser) registry.S
|
||||||
|
|
||||||
func (s *SalaryCalculator1000) Calculate(salary *model.StaffSalary) map[string]interface{} {
|
func (s *SalaryCalculator1000) Calculate(salary *model.StaffSalary) map[string]interface{} {
|
||||||
|
|
||||||
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 nil
|
|
||||||
}
|
|
||||||
sumProfitAmount := int64(0)
|
|
||||||
for _, data := range datas {
|
|
||||||
sumProfitAmount += data.PayAmount - data.Cost
|
|
||||||
}
|
|
||||||
data := make(map[string]interface{})
|
data := make(map[string]interface{})
|
||||||
totalProfit := cast.ToFloat64(goutil.FormatMoney(sumProfitAmount))
|
data["adProfit"] = s.getAdOwnerProfit(salary)
|
||||||
data["adProfit"] = totalProfit
|
data["appIncRate10024"] = s.getAppIncRate(salary, 10024)
|
||||||
|
|
||||||
return data
|
return data
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *SalaryCalculator1000) CalculateDe(salary *model.StaffSalary) {
|
func (s *SalaryCalculator1000) getAdOwnerProfit(salary *model.StaffSalary) float64 {
|
||||||
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)
|
monthTime, _ := time.ParseInLocation("200601", salary.Month, time.Local)
|
||||||
startDay := monthTime.Format("2006-01-02")
|
startDay := monthTime.Format("2006-01-02")
|
||||||
endDay := monthTime.AddDate(0, 1, -1).Format("2006-01-02")
|
endDay := monthTime.AddDate(0, 1, -1).Format("2006-01-02")
|
||||||
datas, err := dao.NewUnifyAdData().QueryOwnerData(s.user.Username, startDay, endDay)
|
datas, err := dao.NewUnifyAdData().QueryOwnerData(s.user.Username, startDay, endDay)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Errorf("db error :%s", err.Error())
|
log.Errorf("db error :%s", err.Error())
|
||||||
return
|
return 0
|
||||||
}
|
}
|
||||||
sumProfitAmount := int64(0)
|
sumProfitAmount := int64(0)
|
||||||
for _, data := range datas {
|
for _, data := range datas {
|
||||||
sumProfitAmount += data.PayAmount - data.Cost
|
sumProfitAmount += data.PayAmount - data.Cost
|
||||||
}
|
}
|
||||||
totalProfit := cast.ToFloat64(goutil.FormatMoney(sumProfitAmount))
|
|
||||||
salary.SetExtra("totalProfit", cast.ToString(totalProfit))
|
|
||||||
|
|
||||||
//1算提成
|
totalProfit := cast.ToFloat64(goutil.FormatMoney(sumProfitAmount))
|
||||||
userSalary := s.user.GetSalary()
|
return totalProfit
|
||||||
awardSalary := float64(0)
|
}
|
||||||
targetSalary := float64(0)
|
|
||||||
if totalProfit > perfTarget {
|
func (s *SalaryCalculator1000) getAppIncRate(salary *model.StaffSalary, appid int64) float64 {
|
||||||
awardSalary = totalProfit * awardRate
|
|
||||||
if awardSalary < 0 {
|
monthTime, _ := time.ParseInLocation("200601", salary.Month, time.Local)
|
||||||
awardSalary = 0
|
|
||||||
}
|
sumProfitAmount1 := int64(0)
|
||||||
targetSalary = cast.ToFloat64(userSalary.Target)
|
sumProfitAmount2 := int64(0)
|
||||||
}
|
|
||||||
salary.TargetSalary = butil.FloatCut(targetSalary)
|
//本月
|
||||||
salary.AwardSalary = butil.FloatCut(awardSalary)
|
datas, err := dao.NewUnifyKctData().QueryData(monthTime.Format("2006-01-02"), monthTime.AddDate(0, 1, -1).Format("2006-01-02"))
|
||||||
|
if err != nil {
|
||||||
|
log.Errorf("db error :%s", err.Error())
|
||||||
|
return 0
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, data := range datas {
|
||||||
|
sumProfitAmount1 += data.PayAmount - data.RefundAmount - data.Cost
|
||||||
|
}
|
||||||
|
|
||||||
|
//上月
|
||||||
|
datas, err = dao.NewUnifyKctData().QueryData(monthTime.AddDate(0, -1, 0).Format("2006-01-02"),
|
||||||
|
monthTime.AddDate(0, 0, -1).Format("2006-01-02"))
|
||||||
|
if err != nil {
|
||||||
|
log.Errorf("db error :%s", err.Error())
|
||||||
|
return 0
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, data := range datas {
|
||||||
|
sumProfitAmount2 += data.PayAmount - data.RefundAmount - data.Cost
|
||||||
|
}
|
||||||
|
salary.SetExtra("sumProfitAmount1", sumProfitAmount1)
|
||||||
|
salary.SetExtra("sumProfitAmount2", sumProfitAmount2)
|
||||||
|
|
||||||
|
return float64(sumProfitAmount1) / float64(sumProfitAmount2)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue