childorder

This commit is contained in:
jiangyong 2025-03-06 00:41:45 +08:00
parent 7827f5a6ec
commit 7947739e8e
5 changed files with 101 additions and 9 deletions

View File

@ -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

View File

@ -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
}

View File

@ -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
}

View File

@ -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)
}