兼容接入订单租期字段

This commit is contained in:
yml
2026-05-24 18:24:39 +08:00
parent e69d08ca9f
commit 778e08a261
9 changed files with 211 additions and 85 deletions
+5 -1
View File
@@ -296,8 +296,12 @@ func (j *Job) handleRenterConfirmTimeout(ctx context.Context, now time.Time, cfg
func (j *Job) handleReturnOverdue(ctx context.Context, now time.Time, cfg thresholds) (int, error) {
var rows []model.RentalOrder
overdueBefore := now.Add(-time.Duration(cfg.ReturnOverdueGraceMinutes) * time.Minute)
err := j.db.WithContext(ctx).
Where("status = ? AND rent_end_at IS NOT NULL AND rent_end_at <= ?", "renting", now.Add(-time.Duration(cfg.ReturnOverdueGraceMinutes)*time.Minute)).
Where(`status = ? AND (
(rented_at IS NOT NULL AND TIMESTAMPADD(HOUR, COALESCE(NULLIF(estimated_duration_hours, 0), 24), rented_at) <= ?)
OR (rented_at IS NULL AND rent_end_at IS NOT NULL AND rent_end_at <= ?)
)`, "renting", overdueBefore, overdueBefore).
Order("id ASC").
Limit(100).
Find(&rows).Error