From 7947739e8e8ceaddcb892a752e341bf8ea8a6dad Mon Sep 17 00:00:00 2001 From: jiangyong Date: Thu, 6 Mar 2025 00:41:45 +0800 Subject: [PATCH] childorder --- common/dao/external_corp_order.go | 27 ++++++++++++-- common/dao/external_corp_user.go | 34 ++++++++++++++++++ ...xternal_corp_order.go => external_corp.go} | 14 ++++++++ ...ternal_unify_data.go => external_unify.go} | 0 .../salary_calculator_1002.go | 35 +++++++++++++++---- 5 files changed, 101 insertions(+), 9 deletions(-) create mode 100644 common/dao/external_corp_user.go rename common/model/{external_corp_order.go => external_corp.go} (68%) rename common/model/{external_unify_data.go => external_unify.go} (100%) diff --git a/common/dao/external_corp_order.go b/common/dao/external_corp_order.go index 68709e6..149816f 100644 --- a/common/dao/external_corp_order.go +++ b/common/dao/external_corp_order.go @@ -30,7 +30,6 @@ func (d *ExternalCorpOrder) QueryOwnerOrder(owner string, startTime, endTime int tx.Where(orderTable+".pay_time <= ?", endTime) tx.Joins(fmt.Sprintf("LEFT JOIN cp_user ON %s.admin_id=cp_user.id", orderTable)) - tx.Where("cp_user.username = ?", owner) tx = tx.Find(&o) if tx.Error == gorm.ErrRecordNotFound { return o, nil @@ -53,9 +52,31 @@ func (d *ExternalCorpOrder) QueryProcessOrder(owner string, startTime, endTime i tx.Where("cp_user.username = ?", owner) tx.Where(orderTable+".pay_time >= ?", startTime) tx.Where(orderTable+".pay_time <= ?", endTime) - tx.Joins(fmt.Sprintf("LEFT JOIN cp_user ON %s.process_id=cp_user.id", orderTable)) - tx.Where("cp_user.username = ?", owner) + tx = tx.Find(&o) + if tx.Error == gorm.ErrRecordNotFound { + return o, nil + } + + if tx.Error != nil { + return nil, tx.Error + } + return o, nil +} + +func (d *ExternalCorpOrder) QueryChildOrder(ownerId int64, startTime, endTime int64) ([]*model.ExternalCorpOrder, error) { + orderTable := d.TableName() + tx := corpDB.Table(orderTable) + + var o []*model.ExternalCorpOrder + + tx.Where(orderTable+".status = ?", 2) + + tx.Where(orderTable+".pay_time >= ?", startTime) + tx.Where(orderTable+".pay_time <= ?", endTime) + + tx.Joins(fmt.Sprintf("LEFT JOIN cp_user ON %s.process_id=cp_user.id", orderTable)) + tx.Where("cp_user.pid = ?", ownerId) tx = tx.Find(&o) if tx.Error == gorm.ErrRecordNotFound { return o, nil diff --git a/common/dao/external_corp_user.go b/common/dao/external_corp_user.go new file mode 100644 index 0000000..bc49e0b --- /dev/null +++ b/common/dao/external_corp_user.go @@ -0,0 +1,34 @@ +package dao + +import ( + "enterprise/common/model" + "gorm.io/gorm" +) + +type ExternalCorpUser struct { +} + +func NewExternalCorpUser() *ExternalCorpUser { + return &ExternalCorpUser{} +} + +func (d *ExternalCorpUser) TableName() string { + return "cp_user" +} + +func (d *ExternalCorpUser) Get(owner string) (*model.ExternalCorpUser, error) { + orderTable := d.TableName() + tx := corpDB.Table(orderTable) + + var o model.ExternalCorpUser + + tx.Where("username = ?", owner) + tx = tx.First(&o) + if tx.Error == gorm.ErrRecordNotFound { + return nil, nil + } + if tx.Error != nil { + return nil, tx.Error + } + return &o, nil +} diff --git a/common/model/external_corp_order.go b/common/model/external_corp.go similarity index 68% rename from common/model/external_corp_order.go rename to common/model/external_corp.go index 8704aab..bd72f40 100644 --- a/common/model/external_corp_order.go +++ b/common/model/external_corp.go @@ -24,3 +24,17 @@ type ExternalCorpOrder struct { Extra string CreateTime int64 } + +type ExternalCorpUser struct { + Id int64 + CorpId int64 + Realname string + Username string + Role int64 + Level int8 + Pid int64 + Config string + Status int8 + CreateTime int64 + UpdateTime int64 +} diff --git a/common/model/external_unify_data.go b/common/model/external_unify.go similarity index 100% rename from common/model/external_unify_data.go rename to common/model/external_unify.go diff --git a/service/salary_calculator/salary_calculator_1002.go b/service/salary_calculator/salary_calculator_1002.go index 341c7c3..5f65ccc 100644 --- a/service/salary_calculator/salary_calculator_1002.go +++ b/service/salary_calculator/salary_calculator_1002.go @@ -30,17 +30,21 @@ func (s *SalaryCalculator1002) Calculate(salary *model.StaffSalary) { return } - if salary.UserName == "luoyi" { - salary.AttendDay = float64(salary.ShouldDay - 3) - } else if strings.ToLower(salary.UserName) == "wangyan" { - salary.AttendDay = float64(salary.ShouldDay) - 3.6 - } else if strings.ToLower(salary.UserName) == "zhouhong" { - salary.AttendDay = float64(salary.ShouldDay) - 3.6 + if salary.Month == "202502" { + salary.ShouldDay = 21 + if salary.UserName == "luoyi" { + salary.AttendDay = float64(salary.ShouldDay - 5) + } else if strings.ToLower(salary.UserName) == "wangyan" { + salary.AttendDay = float64(salary.ShouldDay) - 5.6 + } else if strings.ToLower(salary.UserName) == "zhouhong" { + salary.AttendDay = float64(salary.ShouldDay) - 5.6 + } } salary.AttendSalary = cast.ToFloat64(userSlary.Base) * (salary.AttendDay / float64(salary.ShouldDay)) salary.TargetSalary = cast.ToFloat64(userSlary.Target) + // 1.订单 monthTime, _ := time.ParseInLocation("200601", salary.Month, time.Local) startTime := monthTime.Unix() endTime := monthTime.AddDate(0, 1, 0).Unix() - 1 @@ -52,12 +56,30 @@ func (s *SalaryCalculator1002) Calculate(salary *model.StaffSalary) { orderNum := len(orders) salary.SetExtra("corp_order_num", cast.ToString(orderNum)) + //2.处理的订单 processOrders, err := dao.NewExternalCorpOrder().QueryProcessOrder(s.user.Username, startTime, endTime) if err != nil { log.Errorf("db error:%s", err.Error()) return } + //3.下属订单 + corpUser, err := dao.NewExternalCorpUser().Get(s.user.Username) + if err != nil { + log.Errorf("db error:%s", err.Error()) + return + } + + childOrderNum := 0 + if corpUser != nil { + childOrders, err := dao.NewExternalCorpOrder().QueryChildOrder(corpUser.CorpId, startTime, endTime) + if err != nil { + log.Errorf("db error:%s", err.Error()) + return + } + childOrderNum = len(childOrders) + } + processOrderNum := len(processOrders) salary.SetExtra("corp_process_order_num", cast.ToString(processOrderNum)) salary.AwardSalary = 0 @@ -74,4 +96,5 @@ func (s *SalaryCalculator1002) Calculate(salary *model.StaffSalary) { salary.TargetSalary = float64(60 * orderNum) } salary.AwardSalary += float64(processOrderNum * 5) + salary.AwardSalary += float64(childOrderNum * 5) }