appIncRate10024
This commit is contained in:
parent
79deaca2ba
commit
c5a006ec66
|
@ -1,14 +1,12 @@
|
|||
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"
|
||||
)
|
||||
|
||||
|
@ -30,86 +28,62 @@ func NewSalaryCalculator1000(corp *model.Corp, user *model.StaffUser) registry.S
|
|||
|
||||
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{})
|
||||
totalProfit := cast.ToFloat64(goutil.FormatMoney(sumProfitAmount))
|
||||
data["adProfit"] = totalProfit
|
||||
data["adProfit"] = s.getAdOwnerProfit(salary)
|
||||
data["appIncRate10024"] = s.getAppIncRate(salary, 10024)
|
||||
|
||||
return data
|
||||
}
|
||||
|
||||
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])
|
||||
|
||||
func (s *SalaryCalculator1000) getAdOwnerProfit(salary *model.StaffSalary) float64 {
|
||||
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
|
||||
return 0
|
||||
}
|
||||
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)
|
||||
totalProfit := cast.ToFloat64(goutil.FormatMoney(sumProfitAmount))
|
||||
return totalProfit
|
||||
}
|
||||
|
||||
func (s *SalaryCalculator1000) getAppIncRate(salary *model.StaffSalary, appid int64) float64 {
|
||||
|
||||
monthTime, _ := time.ParseInLocation("200601", salary.Month, time.Local)
|
||||
|
||||
sumProfitAmount1 := int64(0)
|
||||
sumProfitAmount2 := int64(0)
|
||||
|
||||
//本月
|
||||
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