fix:首页日期选择器报错

This commit is contained in:
huwenhao 2022-09-27 15:06:13 +08:00
parent 9898e85186
commit 45e658f07b

View File

@ -55,14 +55,19 @@ func (s *Statistics) DateRangeStatistics() (statisticsData map[string][]interfac
for i := 0; i < TimeDifference; i++ {
if i == 0 {
sqlDataValue += "SELECT curdate() AS click_date UNION ALL"
sqlDataValue += fmt.Sprintf("SELECT date_sub(date_format( '%s', '%%Y%%m%%d'), INTERVAL 0 DAY ) AS click_date UNION ALL", endTime)
} else if i == TimeDifference-1 {
sqlDataValue += fmt.Sprintf(` SELECT date_sub( curdate(), INTERVAL %d DAY ) AS click_date`, i)
sqlDataValue += fmt.Sprintf(` SELECT date_sub(date_format( '%s', '%%Y%%m%%d'), INTERVAL %d DAY ) AS click_date UNION ALL`, endTime, i)
sqlDataValue += fmt.Sprintf(` SELECT date_sub(date_format( '%s', '%%Y%%m%%d'), INTERVAL %d DAY ) AS click_date`, endTime, i + 1)
} else {
sqlDataValue += fmt.Sprintf(` SELECT date_sub( curdate(), INTERVAL %d DAY ) AS click_date UNION ALL`, i)
sqlDataValue += fmt.Sprintf(` SELECT date_sub(date_format( '%s', '%%Y%%m%%d'), INTERVAL %d DAY ) AS click_date UNION ALL`, endTime, i)
}
}
if TimeDifference == 1 {
sqlDataValue += fmt.Sprintf(" SELECT date_sub(date_format( '%s', '%%Y%%m%%d'), INTERVAL 1 DAY ) AS click_date",endTime)
}
sqlValue = fmt.Sprintf(`SELECT
a.click_date,
ifnull( b.total, 0 ) AS total,