Browse Source

修复查询时间

kobe6258 6 months ago
parent
commit
61f55e7f02
1 changed files with 4 additions and 3 deletions
  1. 4 3
      models/report/report.go

+ 4 - 3
models/report/report.go

@@ -163,9 +163,10 @@ func DoSql(sql string, result interface{}, values ...interface{}) (err error) {
 func GetListOrderByCondition(week bool, column string, limit int, order models.Order) (reports []Report, err error) {
 	db := models.Main()
 	if week {
-		end := time.Now()
-		begin := date.GetBeginOfTheWeek(end, time.Monday)
-		err = db.Select(CommonColumns).Where("status = ?", StatusPublish).Where("DATE(published_time) BETWEEN ? AND ?", begin, end).Order(fmt.Sprintf("%s %s", column, order)).Limit(limit).Find(&reports).Error
+		current := time.Now()
+		begin := date.GetBeginOfTheWeek(current, time.Monday).Format(time.DateOnly)
+		end := current.Format(time.DateOnly)
+		err = db.Select(CommonColumns).Where("status = ?", StatusPublish).Where(" STR_TO_DATE(published_time,'%Y-%m-%d') BETWEEN ? AND ?", begin, end).Order(fmt.Sprintf("%s %s", column, order)).Limit(limit).Find(&reports).Error
 	} else {
 		err = db.Select(CommonColumns).Where("status = ?", StatusPublish).Order(fmt.Sprintf("%s %s", column, order)).Limit(limit).Find(&reports).Error
 	}