价格统计

This commit is contained in:
苏尹岚
2020-01-06 08:51:24 +08:00
parent c616808290
commit 36a46455ce
4 changed files with 12 additions and 15 deletions

View File

@@ -2318,31 +2318,32 @@ func RefershStoreSkusMidPrice(ctx *jxcontext.Context, storeIDs []int) (err error
if len(storeIDs) == 0 {
return err
}
var skuBindInfos []*StoreSkuBindInfo
for _, v := range storeIDs {
var skuBindInfos []*StoreSkuBindInfo
store, err := dao.GetStoreDetail(db, v, -1)
if err != nil {
return err
}
var payPercentage int
if payPercentage < 50 {
if store.PayPercentage < 50 {
payPercentage = 70
} else {
payPercentage = store.PayPercentage
}
storeSkuList, err := dao.GetStoresSkusInfo(db, []int{v}, nil)
for _, storeSku := range storeSkuList {
priceReferList, err := dao.GetPriceReferSnapshotNoPage(db, []int{store.CityCode}, nil, []int{storeSku.SkuID}, utils.Time2Date(time.Now().AddDate(0, 0, -1)))
priceReferList, err := dao.GetPriceReferSnapshotNoPage(db, []int{store.CityCode}, []int{storeSku.SkuID}, nil, utils.Time2Date(time.Now().AddDate(0, 0, -1)))
if err != nil {
return err
}
if len(priceReferList) > 0 {
skuBindInfo := &StoreSkuBindInfo{
StoreID: v,
NameID: priceReferList[0].NameID,
UnitPrice: priceReferList[0].MidUnitPrice * payPercentage / 100,
if storeSku.UnitPrice > priceReferList[0].MidUnitPrice*payPercentage/100 {
skuBindInfo := &StoreSkuBindInfo{
NameID: priceReferList[0].NameID,
UnitPrice: priceReferList[0].MidUnitPrice * payPercentage / 100,
}
skuBindInfos = append(skuBindInfos, skuBindInfo)
}
skuBindInfos = append(skuBindInfos, skuBindInfo)
}
}
updateStoresSkusWithoutSync(ctx, db, []int{v}, skuBindInfos, false)

View File

@@ -99,13 +99,13 @@ func BeginSavePriceRefer(ctx *jxcontext.Context, cityCodes, skuIDs []int, isAsyn
var (
citySkuMap = make(map[int]map[int][]int)
resultMap = make(map[int]map[int]*model.PriceReferSnapshot)
tList []*tStoreSkuBindAndSkuName
)
storeList, err := dao.GetStoreList(db, nil, nil, "")
if err != nil {
return result, err
}
for _, v := range storeList {
var tList []*tStoreSkuBindAndSkuName
sql := `
SELECT DISTINCT b.city_code, a.store_id, Round(a.unit_price/IF(b.pay_percentage < 50 , 70, b.pay_percentage) * 100) AS unit_price, c.name_id
FROM store_sku_bind a
@@ -145,9 +145,6 @@ func BeginSavePriceRefer(ctx *jxcontext.Context, cityCodes, skuIDs []int, isAsyn
if len(tList) > 0 {
for _, vv := range tList {
skuNameMap[vv.NameID] = append(skuNameMap[vv.NameID], vv.UnitPrice)
if v.CityCode == 110100 && vv.NameID == 11410 {
fmt.Println(v.ID, vv)
}
}
if citySkuMap[v.CityCode] != nil {
for nameID, unitPriceList := range skuNameMap {
@@ -162,7 +159,6 @@ func BeginSavePriceRefer(ctx *jxcontext.Context, cityCodes, skuIDs []int, isAsyn
}
}
}
fmt.Println(citySkuMap)
for k1, v := range citySkuMap {
skuNameMap := make(map[int]*model.PriceReferSnapshot)
for k2, _ := range v {

View File

@@ -298,7 +298,7 @@ func GetPriceReferSnapshotNoPage(db *DaoDB, cityCodes, skuIDs, skuNameIDs []int,
utils.DefaultTimeValue,
}
if len(skuNameIDs) > 0 {
sql += " AND a.name_id IN (" + GenQuestionMarks(len(skuIDs)) + ")"
sql += " AND a.name_id IN (" + GenQuestionMarks(len(skuNameIDs)) + ")"
sqlParams = append(sqlParams, skuNameIDs)
}
if len(skuIDs) > 0 {

View File

@@ -567,7 +567,7 @@ func GetStorePriceScore(db *DaoDB, storeIDs, vendorIDs []int, fromScore, toScore
func GetStorePriceScoreSnapshot(db *DaoDB, snapDate time.Time) (storePriceScoreSnapshot []*model.StorePriceScoreSnapshot, err error) {
sql := `
SELECT c.store_id,ROUND(count(c.price <= a.mid_price or NULL)/count(*)*100,2) score
SELECT c.store_id,ROUND(count(c.unit_price/IF(d.pay_percentage < 50 , 70, d.pay_percentage) <= a.mid_unit_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 = ? 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 != ?