package crontab import ( "hepa-calc-api/api/dao" "hepa-calc-api/api/model" "hepa-calc-api/utils" "time" ) // SystemCouponExpire 系统优惠卷过期 func SystemCouponExpire() { // 获取今日过期优惠卷 coupons := getSystemExecCoupon() if len(coupons) == 0 { return } for _, coupon := range coupons { // 计算过期时间 validEndTime := time.Time(coupon.ValidEndTime) diffTime := validEndTime.Sub(time.Now()) if diffTime < 5*time.Second { diffTime = 5 * time.Second } // 添加处理优惠卷过期队列 } } // 获取今日过期优惠卷 func getSystemExecCoupon() (coupon []*model.Coupon) { now := time.Now() // 今天开始时间 year, month, day := now.Date() location := now.Location() startTime := time.Date(year, month, day, 00, 00, 00, 0, location).Format("2006-01-02 15:04:05") // 今天结束时间 endTime := time.Date(year, month, day, 23, 59, 59, 0, location).Format("2006-01-02 15:04:05") maps := make(map[string]interface{}) maps["coupon_status"] = 1 maps["valid_type"] = 1 couponDao := dao.CouponDao{} coupons, err := couponDao.GetCouponListByValidTime(maps, startTime, endTime) if err != nil { utils.LogJsonErr("系统优惠卷过期:", err.Error()) return nil } return coupons }