门店评分
This commit is contained in:
@@ -11,3 +11,48 @@ func InsertStoreScore(storeScore *model.StoreScore) error {
|
||||
storeScore.CreatedAt = time.Now()
|
||||
return CreateEntity(nil, storeScore)
|
||||
}
|
||||
|
||||
func GetLatestWeeklyStoreScoreList(db *DaoDB, storeID, weekNum int) (storeScoreList []*model.StoreScore, err error) {
|
||||
// sql := `
|
||||
// SET @dayInWeek = IF(DAYOFWEEK(CURDATE()) - 1 = 0, 7, DAYOFWEEK(CURDATE()) - 1);
|
||||
// SET @endDate = DATE_SUB(CURDATE(), INTERVAL @dayInWeek DAY);
|
||||
// SET @beginData = DATE_SUB(@endDate, INTERVAL ? DAY);
|
||||
// SELECT * FROM store_score
|
||||
// WHERE store_id = ? AND DATE(created_at) >= @beginData AND DATE(created_at) <= @endDate ORDER BY created_at DESC
|
||||
// `
|
||||
sql := `
|
||||
SELECT * FROM store_score WHERE store_id = ?
|
||||
AND DATE(created_at) >= DATE_SUB(
|
||||
DATE_SUB(
|
||||
CURDATE(),
|
||||
INTERVAL
|
||||
IF (
|
||||
DAYOFWEEK(CURDATE()) - 1 = 0,
|
||||
7,
|
||||
DAYOFWEEK(CURDATE()) - 1
|
||||
) DAY
|
||||
),
|
||||
INTERVAL ? DAY
|
||||
)
|
||||
AND DATE(created_at) <= DATE_SUB(
|
||||
CURDATE(),
|
||||
INTERVAL
|
||||
IF (
|
||||
DAYOFWEEK(CURDATE()) - 1 = 0,
|
||||
7,
|
||||
DAYOFWEEK(CURDATE()) - 1
|
||||
) DAY
|
||||
)
|
||||
ORDER BY created_at DESC
|
||||
`
|
||||
if weekNum <= 0 {
|
||||
weekNum = 1
|
||||
}
|
||||
diffDays := weekNum*7 - 1
|
||||
sqlParams := []interface{}{
|
||||
storeID,
|
||||
diffDays,
|
||||
}
|
||||
err = GetRows(db, &storeScoreList, sql, sqlParams)
|
||||
return storeScoreList, err
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user