门店价格插叙
This commit is contained in:
@@ -57,7 +57,7 @@ type CityBrankBranch struct {
|
||||
}
|
||||
|
||||
type StorePriceScore struct {
|
||||
StoreID int `json:"storeID"`
|
||||
StoreID int `orm:"column(store_id)" json:"storeID"`
|
||||
StoreName string `json:"storeName"`
|
||||
StoreScore float64 `json:"storeScore"`
|
||||
CityName string `json:"cityName"`
|
||||
@@ -475,20 +475,18 @@ func GetStoreMapsListWithoutDisabled(db *DaoDB, vendorIDs []int, status int) (st
|
||||
return storeMapList, err
|
||||
}
|
||||
|
||||
func GetStorePriceScore(db *DaoDB, storeIDs []int, snapDate time.Time, offset, pageSize int) (StorePriceScore []*StorePriceScore, totalCount int, err error) {
|
||||
func GetStorePriceScore(db *DaoDB, storeIDs []int, fromScore, toScore, sort int, snapDate time.Time, offset, pageSize int) (StorePriceScore []*StorePriceScore, totalCount int, err error) {
|
||||
sql := `
|
||||
SELECT SQL_CALC_FOUND_ROWS
|
||||
t1.* FROM(
|
||||
SELECT c.store_id,d.name store_name,e.name city_name,ROUND(count(c.price/100 <= a.mid_price or NULL)/count(*)*100,2) store_score
|
||||
FROM price_refer_snapshot a
|
||||
JOIN store_sku_bind c ON c.sku_id = a.sku_id AND c.status = 1 AND c.deleted_at = ?
|
||||
JOIN store d ON c.store_id = d.id AND d.city_code = a.city_code AND d.deleted_at = ? AND d.status !=-2
|
||||
JOIN place e ON e.code = d.city_code
|
||||
SELECT SQL_CALC_FOUND_ROWS a.store_id,score store_score,e.name city_name,b.name store_name
|
||||
FROM store_price_score_snapshot a
|
||||
JOIN store b ON b.id = a.store_id
|
||||
JOIN place e ON e.code = b.city_code
|
||||
WHERE 1=1
|
||||
`
|
||||
AND a.score BETWEEN ? AND ?
|
||||
`
|
||||
sqlParams := []interface{}{
|
||||
utils.DefaultTimeValue,
|
||||
utils.DefaultTimeValue,
|
||||
fromScore,
|
||||
toScore,
|
||||
}
|
||||
if len(storeIDs) > 0 {
|
||||
sql += " AND c.store_id IN(" + GenQuestionMarks(len(storeIDs)) + ")"
|
||||
@@ -498,11 +496,12 @@ func GetStorePriceScore(db *DaoDB, storeIDs []int, snapDate time.Time, offset, p
|
||||
sql += " AND a.snapshot_at = ?"
|
||||
sqlParams = append(sqlParams, snapDate)
|
||||
}
|
||||
sql += `
|
||||
GROUP BY c.store_id)t1
|
||||
ORDER BY t1.store_score
|
||||
LIMIT ? OFFSET ?
|
||||
`
|
||||
if sort == 0 {
|
||||
sql += " ORDER BY a.score"
|
||||
} else {
|
||||
sql += " ORDER BY a.score DESC"
|
||||
}
|
||||
sql += " LIMIT ? OFFSET ?"
|
||||
sqlParams = append(sqlParams, pageSize, offset)
|
||||
Begin(db)
|
||||
defer Commit(db)
|
||||
@@ -511,3 +510,27 @@ func GetStorePriceScore(db *DaoDB, storeIDs []int, snapDate time.Time, offset, p
|
||||
}
|
||||
return StorePriceScore, totalCount, err
|
||||
}
|
||||
|
||||
func GetStorePriceScoreSnapshot(db *DaoDB, snapDate time.Time) (storePriceScoreSnapshot []*model.StorePriceScoreSnapshot, err error) {
|
||||
sql := `
|
||||
SELECT c.store_id,ROUND(count(c.price/100 <= a.mid_price or NULL)/count(*)*100,2) score
|
||||
FROM price_refer_snapshot a
|
||||
JOIN store_sku_bind c ON c.sku_id = a.sku_id AND c.status = 1 AND c.deleted_at = ?
|
||||
JOIN store d ON c.store_id = d.id AND d.city_code = a.city_code AND d.deleted_at = ? AND d.status != ?
|
||||
WHERE 1=1
|
||||
`
|
||||
sqlParams := []interface{}{
|
||||
utils.DefaultTimeValue,
|
||||
utils.DefaultTimeValue,
|
||||
model.StoreStatusDisabled,
|
||||
}
|
||||
if !utils.IsTimeZero(snapDate) {
|
||||
sql += " AND a.snapshot_at = ?"
|
||||
sqlParams = append(sqlParams, snapDate)
|
||||
}
|
||||
sql += `
|
||||
GROUP BY c.store_id
|
||||
`
|
||||
err = GetRows(db, &storePriceScoreSnapshot, sql, sqlParams...)
|
||||
return storePriceScoreSnapshot, err
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user