价格统计
This commit is contained in:
@@ -132,6 +132,7 @@ type StoreSkuNameExt struct {
|
||||
|
||||
PendingOpType int8 `json:"pendingOpType"` // 取值同 StoreOpRequest.Type
|
||||
PendingUnitPrice int `json:"pendingUnitPrice"` // 这个是待审核的价格申请
|
||||
Status int
|
||||
}
|
||||
|
||||
// GetStoreSkus用
|
||||
@@ -1369,17 +1370,13 @@ func GetStoreSkuBindByNameID(db *DaoDB, storeID, nameID, status int) (storeSkuBi
|
||||
return storeSkuBind, err
|
||||
}
|
||||
|
||||
func GetPriceReferUnitPrice(db *DaoDB, cityCode int, nameID int, snapDate time.Time) (result *PriceReferSnapshotExt, err error) {
|
||||
func GetPriceReferPrice(db *DaoDB, cityCode int, skuID int, snapDate time.Time) (result *PriceReferSnapshotExt, err error) {
|
||||
var (
|
||||
pRefer []*PriceReferSnapshotExt
|
||||
priceRefer = &PriceReferSnapshotExt{}
|
||||
minUnitPrice int
|
||||
maxUnitPrice int
|
||||
midUnitPrice int
|
||||
avgUnitPrice int
|
||||
pRefer *PriceReferSnapshotExt
|
||||
priceRefer *PriceReferSnapshotExt
|
||||
)
|
||||
sql := `
|
||||
SELECT a.max_price, a.min_price, a.avg_price, a.mid_price, a.sku_id id, b.spec_quality, c.unit, b.spec_unit
|
||||
SELECT a.max_unit_price, a.min_unit_price, a.avg_unit_price, a.mid_unit_price, a.sku_id id, b.spec_quality, c.unit, b.spec_unit
|
||||
FROM price_refer_snapshot a
|
||||
JOIN sku b ON a.sku_id = b.id
|
||||
JOIN sku_name c ON c.id = b.name_id
|
||||
@@ -1391,53 +1388,39 @@ func GetPriceReferUnitPrice(db *DaoDB, cityCode int, nameID int, snapDate time.T
|
||||
snapDate,
|
||||
cityCode,
|
||||
}
|
||||
if nameID > 0 {
|
||||
sql += " AND a.name_id = ?"
|
||||
sqlParams = append(sqlParams, nameID)
|
||||
if skuID > 0 {
|
||||
sql += " AND a.sku_id = ?"
|
||||
sqlParams = append(sqlParams, skuID)
|
||||
}
|
||||
err = GetRows(db, &pRefer, sql, sqlParams...)
|
||||
err = GetRow(db, &pRefer, sql, sqlParams...)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if len(pRefer) > 0 {
|
||||
for _, v := range pRefer {
|
||||
var (
|
||||
minPrice int
|
||||
maxPrice int
|
||||
midPrice int
|
||||
avgPrice int
|
||||
specQuality float64
|
||||
)
|
||||
if v.Unit == model.SpecialUnit {
|
||||
if v.SpecUnit == model.SpecUnitNames[1] || v.SpecUnit == model.SpecUnitNames[2] {
|
||||
specQuality = float64(v.SpecQuality) * 1000
|
||||
} else {
|
||||
specQuality = float64(v.SpecQuality)
|
||||
}
|
||||
maxPrice = int(utils.Float64TwoInt64(utils.Int2Float64(model.SpecialSpecQuality) / specQuality * utils.Int2Float64(v.MaxPrice)))
|
||||
minPrice = int(utils.Float64TwoInt64(utils.Int2Float64(model.SpecialSpecQuality) / specQuality * utils.Int2Float64(v.MinPrice)))
|
||||
avgPrice = int(utils.Float64TwoInt64(utils.Int2Float64(model.SpecialSpecQuality) / specQuality * utils.Int2Float64(v.AvgPrice)))
|
||||
midPrice = int(utils.Float64TwoInt64(utils.Int2Float64(model.SpecialSpecQuality) / specQuality * utils.Int2Float64(v.MidPrice)))
|
||||
if pRefer != nil {
|
||||
var (
|
||||
specQuality float64
|
||||
)
|
||||
if pRefer.Unit == model.SpecialUnit {
|
||||
if pRefer.SpecUnit == model.SpecUnitNames[1] || pRefer.SpecUnit == model.SpecUnitNames[2] {
|
||||
specQuality = float64(pRefer.SpecQuality) * 1000
|
||||
} else {
|
||||
maxPrice = v.MaxPrice
|
||||
minPrice = v.MinPrice
|
||||
avgPrice = v.AvgPrice
|
||||
midPrice = v.MidPrice
|
||||
specQuality = float64(pRefer.SpecQuality)
|
||||
}
|
||||
minUnitPrice += minPrice
|
||||
maxUnitPrice += maxPrice
|
||||
midUnitPrice += midPrice
|
||||
avgUnitPrice += avgPrice
|
||||
priceRefer.MaxPrice = int(utils.Float64TwoInt64(specQuality / utils.Int2Float64(model.SpecialSpecQuality) * utils.Int2Float64(pRefer.MaxUnitPrice)))
|
||||
priceRefer.MinPrice = int(utils.Float64TwoInt64(specQuality / utils.Int2Float64(model.SpecialSpecQuality) * utils.Int2Float64(pRefer.MinUnitPrice)))
|
||||
priceRefer.AvgPrice = int(utils.Float64TwoInt64(specQuality / utils.Int2Float64(model.SpecialSpecQuality) * utils.Int2Float64(pRefer.AvgUnitPrice)))
|
||||
priceRefer.MidPrice = int(utils.Float64TwoInt64(specQuality / utils.Int2Float64(model.SpecialSpecQuality) * utils.Int2Float64(pRefer.MidUnitPrice)))
|
||||
} else {
|
||||
priceRefer.MaxPrice = pRefer.MaxUnitPrice
|
||||
priceRefer.MinPrice = pRefer.MinUnitPrice
|
||||
priceRefer.AvgPrice = pRefer.AvgUnitPrice
|
||||
priceRefer.MidPrice = pRefer.MidUnitPrice
|
||||
}
|
||||
priceRefer.MinUnitPrice = minUnitPrice / len(pRefer)
|
||||
priceRefer.MaxUnitPrice = maxUnitPrice / len(pRefer)
|
||||
priceRefer.AvgUnitPrice = avgUnitPrice / len(pRefer)
|
||||
priceRefer.MidUnitPrice = midUnitPrice / len(pRefer)
|
||||
}
|
||||
return priceRefer, err
|
||||
}
|
||||
|
||||
func GetStoreSkusAndSkuName(db *DaoDB, storeIDs, skuIDs []int) (storeSkuNameExt []*StoreSkuNameExt, err error) {
|
||||
func GetStoreSkusAndSkuName(db *DaoDB, storeIDs, skuIDs, nameIDs []int) (storeSkuNameExt []*StoreSkuNameExt, err error) {
|
||||
sql := `
|
||||
SELECT a.*,c.id
|
||||
FROM store_sku_bind a
|
||||
@@ -1458,6 +1441,10 @@ func GetStoreSkusAndSkuName(db *DaoDB, storeIDs, skuIDs []int) (storeSkuNameExt
|
||||
sql += " AND a.sku_id IN (" + GenQuestionMarks(len(skuIDs)) + ")"
|
||||
sqlParams = append(sqlParams, skuIDs)
|
||||
}
|
||||
if len(nameIDs) > 0 {
|
||||
sql += " AND b.name_id IN (" + GenQuestionMarks(len(nameIDs)) + ")"
|
||||
sqlParams = append(sqlParams, nameIDs)
|
||||
}
|
||||
err = GetRows(db, &storeSkuNameExt, sql, sqlParams...)
|
||||
return storeSkuNameExt, err
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user