enterprise/service/salary_calculator/salary_calculator_1000.go

90 lines
2.4 KiB
Go
Raw Normal View History

2025-03-04 23:14:09 +08:00
package salary_calculator
import (
"enterprise/common/dao"
"enterprise/common/model"
"enterprise/common/registry"
log "github.com/sirupsen/logrus"
"github.com/smbrave/goutil"
"github.com/spf13/cast"
"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,
}
}
2025-03-13 19:19:30 +08:00
func (s *SalaryCalculator1000) Calculate(salary *model.StaffSalary) map[string]interface{} {
2025-03-14 17:56:55 +08:00
2025-03-14 19:30:24 +08:00
data := make(map[string]interface{})
data["adProfit"] = s.getAdOwnerProfit(salary)
data["appIncRate10024"] = s.getAppIncRate(salary, 10024)
return data
}
func (s *SalaryCalculator1000) getAdOwnerProfit(salary *model.StaffSalary) float64 {
2025-03-14 17:56:55 +08:00
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())
2025-03-14 19:30:24 +08:00
return 0
2025-03-14 17:56:55 +08:00
}
sumProfitAmount := int64(0)
for _, data := range datas {
sumProfitAmount += data.PayAmount - data.Cost
}
2025-03-14 19:30:24 +08:00
totalProfit := cast.ToFloat64(goutil.FormatMoney(sumProfitAmount))
return totalProfit
2025-03-13 19:19:30 +08:00
}
2025-03-14 19:30:24 +08:00
func (s *SalaryCalculator1000) getAppIncRate(salary *model.StaffSalary, appid int64) float64 {
2025-03-04 23:14:09 +08:00
2025-03-14 19:30:24 +08:00
monthTime, _ := time.ParseInLocation("200601", salary.Month, time.Local)
2025-03-05 10:11:07 +08:00
2025-03-14 19:30:24 +08:00
sumProfitAmount1 := int64(0)
sumProfitAmount2 := int64(0)
2025-03-04 23:14:09 +08:00
2025-03-14 19:30:24 +08:00
//本月
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
2025-03-04 23:14:09 +08:00
}
2025-03-14 19:30:24 +08:00
for _, data := range datas {
sumProfitAmount1 += data.PayAmount - data.RefundAmount - data.Cost
}
2025-03-04 23:14:09 +08:00
2025-03-14 19:30:24 +08:00
//上月
datas, err = dao.NewUnifyKctData().QueryData(monthTime.AddDate(0, -1, 0).Format("2006-01-02"),
monthTime.AddDate(0, 0, -1).Format("2006-01-02"))
2025-03-04 23:14:09 +08:00
if err != nil {
log.Errorf("db error :%s", err.Error())
2025-03-14 19:30:24 +08:00
return 0
2025-03-04 23:14:09 +08:00
}
2025-03-14 19:30:24 +08:00
2025-03-04 23:14:09 +08:00
for _, data := range datas {
2025-03-14 19:30:24 +08:00
sumProfitAmount2 += data.PayAmount - data.RefundAmount - data.Cost
2025-03-04 23:14:09 +08:00
}
2025-03-14 19:30:24 +08:00
salary.SetExtra("sumProfitAmount1", sumProfitAmount1)
salary.SetExtra("sumProfitAmount2", sumProfitAmount2)
return float64(sumProfitAmount1) / float64(sumProfitAmount2)
2025-03-04 23:14:09 +08:00
}