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 19:48:49 +08:00
|
|
|
monthTime, _ := time.ParseInLocation("200601", salary.Month, time.Local)
|
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)
|
|
|
|
|
2025-03-14 23:49:21 +08:00
|
|
|
data["app10024Profit"] = s.getAppProfit(10024, salary.Month)
|
|
|
|
data["app10024Profit2"] = s.getAppProfit(10024, monthTime.AddDate(0, -1, 0).Format("200601"))
|
2025-03-14 19:30:24 +08:00
|
|
|
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:48:49 +08:00
|
|
|
func (s *SalaryCalculator1000) getAppProfit(appid int64, month string) float64 {
|
2025-03-04 23:14:09 +08:00
|
|
|
|
2025-03-14 19:48:49 +08:00
|
|
|
monthTime, _ := time.ParseInLocation("200601", month, time.Local)
|
2025-03-05 10:11:07 +08:00
|
|
|
|
2025-03-14 19:48:49 +08:00
|
|
|
sumProfitAmount := 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 {
|
2025-03-14 19:48:49 +08:00
|
|
|
sumProfitAmount += data.PayAmount - data.RefundAmount - data.Cost
|
2025-03-04 23:14:09 +08:00
|
|
|
}
|
2025-03-14 19:48:49 +08:00
|
|
|
return float64(sumProfitAmount) / 100
|
2025-03-04 23:14:09 +08:00
|
|
|
}
|