76 lines
2.1 KiB
Go
76 lines
2.1 KiB
Go
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,
|
|
}
|
|
}
|
|
|
|
func (s *SalaryCalculator1000) Calculate(salary *model.StaffSalary) map[string]interface{} {
|
|
monthTime, _ := time.ParseInLocation("200601", salary.Month, time.Local)
|
|
|
|
data := make(map[string]interface{})
|
|
data["adProfit"] = s.getAdOwnerProfit(salary)
|
|
|
|
data["app10024Profit"] = s.getAppProfit(10024, salary.Month)
|
|
data["app10024Profit2"] = s.getAppProfit(10024, monthTime.AddDate(0, -1, 0).Format("200601"))
|
|
return data
|
|
}
|
|
|
|
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 0
|
|
}
|
|
sumProfitAmount := int64(0)
|
|
for _, data := range datas {
|
|
sumProfitAmount += data.PayAmount - data.Cost
|
|
}
|
|
|
|
totalProfit := cast.ToFloat64(goutil.FormatMoney(sumProfitAmount))
|
|
return totalProfit
|
|
}
|
|
|
|
func (s *SalaryCalculator1000) getAppProfit(appid int64, month string) float64 {
|
|
|
|
monthTime, _ := time.ParseInLocation("200601", month, time.Local)
|
|
|
|
sumProfitAmount := 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 {
|
|
sumProfitAmount += data.PayAmount - data.RefundAmount - data.Cost
|
|
}
|
|
return float64(sumProfitAmount) / 100
|
|
}
|