价格参考
This commit is contained in:
@@ -178,7 +178,82 @@ func GetGetStatisticsReportForAfsOrders(db *DaoDB, storeIDs []int, fromDate time
|
||||
return nil, err
|
||||
}
|
||||
|
||||
func GetStatisticsReportForStoreSkusPrice(db *DaoDB, cityCodes, skuIDs []int) (err error) {
|
||||
|
||||
return err
|
||||
func GetStatisticsReportForStoreSkusPrice(db *DaoDB, cityCodes, skuIDs []int) (priceReferSnapshot []*model.PriceReferSnapshot, err error) {
|
||||
sql := `
|
||||
SELECT b.city_code,a.sku_id,
|
||||
MAX(a.price/100) max_price,
|
||||
MIN(a.price/100) min_price,
|
||||
ROUND(AVG(a.price/100),2) avg_price,
|
||||
ROUND(SUBSTRING_INDEX(SUBSTRING_INDEX(GROUP_CONCAT(a.price/100 ORDER BY a.price/100),',',Count(1)/2),',',-1),2) mid_price,
|
||||
MAX(a.jd_price/100) max_jd_price,
|
||||
MIN(a.jd_price/100) min_jd_price,
|
||||
ROUND(AVG(a.jd_price/100),2) avg_jd_price,
|
||||
ROUND(SUBSTRING_INDEX(SUBSTRING_INDEX(GROUP_CONCAT(a.jd_price/100 ORDER BY a.jd_price/100),',',Count(1)/2),',',-1),2) mid_jd_price,
|
||||
MAX(a.ebai_price/100) max_ebai_price,
|
||||
MIN(a.ebai_price/100) min_ebai_price,
|
||||
ROUND(AVG(a.ebai_price/100),2) avg_ebai_price,
|
||||
ROUND(SUBSTRING_INDEX(SUBSTRING_INDEX(GROUP_CONCAT(a.ebai_price/100 ORDER BY a.ebai_price/100),',',Count(1)/2),',',-1),2) mid_ebai_price,
|
||||
MAX(a.mtwm_price/100) max_mtwm_price,
|
||||
MIN(a.mtwm_price/100) min_mtwm_price,
|
||||
ROUND(AVG(a.mtwm_price/100),2) avg_mtwm_price,
|
||||
ROUND(SUBSTRING_INDEX(SUBSTRING_INDEX(GROUP_CONCAT(a.mtwm_price/100 ORDER BY a.mtwm_price/100),',',Count(1)/2),',',-1),2) mid_mtwm_price,
|
||||
t1.max_sale_price,
|
||||
t1.min_sale_price,
|
||||
t1.avg_sale_price,
|
||||
t1.max_vendor_price,
|
||||
t1.min_vendor_price,
|
||||
t1.avg_vendor_price
|
||||
FROM store_sku_bind a
|
||||
JOIN store b ON a.store_id = b.id AND b.deleted_at = ?
|
||||
JOIN sku d ON a.sku_id = d.id AND d.deleted_at = ?
|
||||
LEFT JOIN (
|
||||
SELECT SUM(t1.count),t1.sku_id,MAX(t1.sale_price/100) max_sale_price,MIN(t1.sale_price/100) min_sale_price,ROUND(AVG(t1.sale_price/100),2) avg_sale_price,MAX(t1.vendor_price/100) max_vendor_price,MIN(t1.vendor_price/100) min_vendor_price,ROUND(AVG(t1.vendor_price/100),2) avg_vendor_price
|
||||
FROM order_sku t1
|
||||
WHERE t1.order_created_at BETWEEN ? AND NOW()
|
||||
GROUP BY 2
|
||||
)t1 ON t1.sku_id = a.sku_id
|
||||
WHERE 1=1
|
||||
`
|
||||
sqlParams := []interface{}{
|
||||
utils.DefaultTimeValue,
|
||||
utils.DefaultTimeValue,
|
||||
time.Now().AddDate(0, -1, 0),
|
||||
}
|
||||
if len(skuIDs) > 0 {
|
||||
sql += " AND a.sku_id IN (" + GenQuestionMarks(len(skuIDs)) + ")"
|
||||
sqlParams = append(sqlParams, skuIDs)
|
||||
}
|
||||
if len(cityCodes) > 0 {
|
||||
sql += " AND b.city_code IN (" + GenQuestionMarks(len(cityCodes)) + ")"
|
||||
sqlParams = append(sqlParams, cityCodes)
|
||||
}
|
||||
sql += " GROUP BY 1,2"
|
||||
if err = GetRows(db, &priceReferSnapshot, sql, sqlParams...); err == nil {
|
||||
return priceReferSnapshot, nil
|
||||
}
|
||||
return nil, err
|
||||
}
|
||||
|
||||
func GetPriceReferSnapshot(db *DaoDB, cityCodes, skuIDs []int) (priceReferSnapshot []*model.PriceReferSnapshot, err error) {
|
||||
sql := `
|
||||
SELECT *
|
||||
FROM price_refer_snapshot
|
||||
WHERE 1=1
|
||||
AND delete_at = ?
|
||||
`
|
||||
sqlParams := []interface{}{
|
||||
utils.DefaultTimeValue,
|
||||
}
|
||||
if len(skuIDs) > 0 {
|
||||
sql += " AND sku_id IN (" + GenQuestionMarks(len(skuIDs)) + ")"
|
||||
sqlParams = append(sqlParams, skuIDs)
|
||||
}
|
||||
if len(cityCodes) > 0 {
|
||||
sql += " AND city_code IN (" + GenQuestionMarks(len(cityCodes)) + ")"
|
||||
sqlParams = append(sqlParams, cityCodes)
|
||||
}
|
||||
if err = GetRows(db, &priceReferSnapshot, sql, sqlParams...); err == nil {
|
||||
return priceReferSnapshot, nil
|
||||
}
|
||||
return nil, err
|
||||
}
|
||||
|
||||
@@ -422,6 +422,47 @@ func (*StoreCourierMap) TableUnique() [][]string {
|
||||
}
|
||||
}
|
||||
|
||||
type PriceReferSnapshot struct {
|
||||
ModelIDCULD
|
||||
SnapshotAt time.Time `orm:"type(datetime)" json:"snapshotAt"` // 这个不同于CreatedAt,SnapshotAt是逻辑上的时间,CreatedAt是实际存储的时间
|
||||
CityCode int `json:"cityCode"`
|
||||
SkuID int `orm:"column(sku_id)" json:"skuId"`
|
||||
MaxPrice float64 `json:"maxPrice"`
|
||||
MinPrice float64 `json:"minPrice"`
|
||||
AvgPrice float64 `json:"avgPrice"`
|
||||
MidPrice float64 `json:"midPrice"`
|
||||
MaxJdPrice float64 `json:"maxJdPrice"`
|
||||
MinJdPrice float64 `json:"minJdPrice"`
|
||||
AvgJdPrice float64 `json:"avgJdPrice"`
|
||||
MidJdPrice float64 `json:"midJdPrice"`
|
||||
MaxEbaiPrice float64 `json:"maxEbaiPrice"`
|
||||
MinEbaiPrice float64 `json:"minEbaiPrice"`
|
||||
AvgEbaiPrice float64 `json:"avgEbaiPrice"`
|
||||
MidEbaiPrice float64 `json:"midEbaiPrice"`
|
||||
MaxMtwmPrice float64 `json:"maxMtwmPrice"`
|
||||
MinMtwmPrice float64 `json:"minMtwmPrice"`
|
||||
AvgMtwmPrice float64 `json:"avgMtwmPrice"`
|
||||
MidMtwmPrice float64 `json:"midMtwmPrice"`
|
||||
MaxSalePrice float64 `json:"maxSalePrice"`
|
||||
MinSalePrice float64 `json:"minSalePrice"`
|
||||
AvgSalePrice float64 `json:"avgSalePrice"`
|
||||
MaxVendorPrice float64 `json:"maxVendorPrice"`
|
||||
MinVendorPrice float64 `json:"minVendorPrice"`
|
||||
AvgVendorPrice float64 `json:"avgVendorPrice"`
|
||||
}
|
||||
|
||||
func (*PriceReferSnapshot) TableUnique() [][]string {
|
||||
return [][]string{
|
||||
[]string{"CityCode", "SkuID", "SnapshotAt"},
|
||||
}
|
||||
}
|
||||
|
||||
func (*PriceReferSnapshot) TableIndex() [][]string {
|
||||
return [][]string{
|
||||
[]string{"SnapshotAt"},
|
||||
}
|
||||
}
|
||||
|
||||
type VendorStoreSnapshot struct {
|
||||
ModelIDCULD
|
||||
|
||||
|
||||
Reference in New Issue
Block a user