| | |
| | | |
| | | import ( |
| | | "errors" |
| | | "fmt" |
| | | "github.com/spf13/cast" |
| | | "gorm.io/gorm" |
| | | "strings" |
| | |
| | | |
| | | func (slf SystemConfigService) GetInventoryCutOffPoint() (day int, timeStr string, err error) { |
| | | config, err := models.NewSystemConfigSearch().SetConfigType(constvar.SystemConfigTypeInventoryCutOffPoint).First() |
| | | if err != nil { |
| | | err = errors.New("库存结算时间点未配置") |
| | | if err == gorm.ErrRecordNotFound { |
| | | config = &models.SystemConfig{ |
| | | Val: "01-00:01", |
| | | } |
| | | } |
| | | if err != nil && err != gorm.ErrRecordNotFound { |
| | | return |
| | | } |
| | | return slf.CheckInventoryCutOffPoint(config.Val) |
| | | } |
| | | |
| | | func (slf SystemConfigService) GetInventoryCutOffTime() (beginTime, endTime time.Time, err error) { |
| | | day, timeStr, err := slf.GetInventoryCutOffPoint() |
| | | // 假设当前时间 |
| | | currentTime := time.Now() |
| | | // 解析给定的时间字符串为 time 对象 |
| | | parsedTime, err := time.Parse("15:04", timeStr) |
| | | if err != nil { |
| | | fmt.Println("时间解析错误:", err) |
| | | return |
| | | } |
| | | |
| | | // 创建一个日期时间对象,假设在当前月的给定日和时间 |
| | | endTime = time.Date(currentTime.Year(), currentTime.Month(), day, parsedTime.Hour(), parsedTime.Minute(), 0, 0, currentTime.Location()) |
| | | |
| | | // 如果给定的日期时间在当前时间之后,我们需要回到上个月 |
| | | if endTime.After(currentTime) { |
| | | lastMonth := currentTime.AddDate(0, -1, 0) |
| | | endTime = time.Date(lastMonth.Year(), lastMonth.Month(), day, parsedTime.Hour(), parsedTime.Minute(), 0, 0, currentTime.Location()) |
| | | } |
| | | lastMonth := endTime.AddDate(0, -1, 0) |
| | | beginTime = time.Date(lastMonth.Year(), lastMonth.Month(), day, parsedTime.Hour(), parsedTime.Minute(), 0, 0, currentTime.Location()) |
| | | return beginTime, endTime, nil |
| | | } |