package salary_calculator import ( "enterprise/common/dao" "enterprise/common/model" "enterprise/common/registry" log "github.com/sirupsen/logrus" "time" ) type SalaryCalculator1002 struct { corp *model.Corp user *model.StaffUser } func NewSalaryCalculator1002(corp *model.Corp, user *model.StaffUser) registry.SalaryCalculator { return &SalaryCalculator1002{ corp: corp, user: user, } } func (s *SalaryCalculator1002) Calculate(salary *model.StaffSalary) map[string]interface{} { data := make(map[string]interface{}) //离职人员考勤异常 if salary.Username == "yuanxuehua" && salary.Month == "202503" { salary.AttendSalary = 12 } // 1.订单 monthTime, _ := time.ParseInLocation("200601", salary.Month, time.Local) startTime := monthTime.Unix() endTime := monthTime.AddDate(0, 1, 0).Unix() - 1 orders, err := dao.NewExternalCorpOrder().QueryOwnerOrder(s.user.Username, startTime, endTime) if err != nil { log.Errorf("db error:%s", err.Error()) } totalOrders, err := dao.NewExternalCorpOrder().QueryOwnerOrder("", startTime, endTime) if err != nil { log.Errorf("db error:%s", err.Error()) } data["orderNum"] = len(orders) data["totalOrderNum"] = len(totalOrders) //2.处理的订单 processOrders, err := dao.NewExternalCorpOrder().QueryProcessOrder(s.user.Username, startTime, endTime) if err != nil { log.Errorf("db error:%s", err.Error()) } more400ProcessNum := int64(0) less400ProcessNum := int64(0) for _, o := range processOrders { if o.TotalFee-o.RefundFee >= 40000 { more400ProcessNum += 1 } else { less400ProcessNum += 1 } } data["processNum"] = len(processOrders) data["processMore400Num"] = more400ProcessNum data["processLess400Num"] = less400ProcessNum //3.下属订单 corpUser, err := dao.NewExternalCorpUser().Get(s.user.Username) if err != nil { log.Errorf("db error:%s", err.Error()) } data["childOrderNum"] = 0 if corpUser != nil { childOrders, err := dao.NewExternalCorpOrder().QueryChildOrder(corpUser.Id, startTime, endTime) if err != nil { log.Errorf("db error:%s", err.Error()) } data["childOrderNum"] = len(childOrders) } return data }