Files
lckt-server/task/clearOrder.go

25 lines
736 B
Go
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

package task
import (
"git.echol.cn/loser/lckt/global"
"git.echol.cn/loser/lckt/model/app"
"go.uber.org/zap"
"gorm.io/gorm"
"time"
)
// ClearExpiredOrders 定时清理超时订单5分钟过期
func ClearExpiredOrders(db *gorm.DB) error {
global.GVA_LOG.Info("开始清理超时订单...")
fiveMinutesAgo := time.Now().Add(-5 * time.Minute)
result := db.Model(&app.Order{}).
Where("status = 1 AND created_at < ?", fiveMinutesAgo).
Updates(map[string]interface{}{"status": 3})
if result.Error != nil {
global.GVA_LOG.Error("清理超时订单失败", zap.Error(result.Error))
return result.Error
}
global.GVA_LOG.Info("清理超时订单成功", zap.Int64("处理订单数", result.RowsAffected))
return nil
}