价格统计
This commit is contained in:
@@ -2315,7 +2315,38 @@ func GetTopCategoriesByStoreIDs(ctx *jxcontext.Context, storeIDs []int) (skuCate
|
||||
|
||||
func RefershStoreSkusMidPrice(ctx *jxcontext.Context, storeIDs []int) (err error) {
|
||||
db := dao.GetDB()
|
||||
_, err = dao.RefershStoreSkusMidPrice(db, storeIDs)
|
||||
if len(storeIDs) == 0 {
|
||||
return err
|
||||
}
|
||||
var skuBindInfos []*StoreSkuBindInfo
|
||||
for _, v := range storeIDs {
|
||||
store, err := dao.GetStoreDetail(db, v, -1)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
var payPercentage int
|
||||
if 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)))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if len(priceReferList) > 0 {
|
||||
skuBindInfo := &StoreSkuBindInfo{
|
||||
StoreID: v,
|
||||
NameID: priceReferList[0].NameID,
|
||||
UnitPrice: priceReferList[0].MidUnitPrice * payPercentage / 100,
|
||||
}
|
||||
skuBindInfos = append(skuBindInfos, skuBindInfo)
|
||||
}
|
||||
}
|
||||
updateStoresSkusWithoutSync(ctx, db, []int{v}, skuBindInfos, false)
|
||||
}
|
||||
if err == nil {
|
||||
CreateStorePriceScore(ctx)
|
||||
}
|
||||
|
||||
@@ -107,7 +107,7 @@ func BeginSavePriceRefer(ctx *jxcontext.Context, cityCodes, skuIDs []int, isAsyn
|
||||
}
|
||||
for _, v := range storeList {
|
||||
sql := `
|
||||
SELECT DISTINCT b.city_code,a.store_id,a.unit_price,c.name_id
|
||||
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
|
||||
JOIN store b ON b.id = a.store_id AND b.deleted_at = ? AND b.status != ?
|
||||
JOIN sku c ON c.id = a.sku_id
|
||||
@@ -142,19 +142,27 @@ func BeginSavePriceRefer(ctx *jxcontext.Context, cityCodes, skuIDs []int, isAsyn
|
||||
}
|
||||
dao.GetRows(db, &tList, sql, sqlParams...)
|
||||
skuNameMap := make(map[int][]int)
|
||||
for _, vv := range tList {
|
||||
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 {
|
||||
if citySkuMap[v.CityCode][vv.NameID] != nil {
|
||||
citySkuMap[v.CityCode][vv.NameID] = append(citySkuMap[v.CityCode][vv.NameID], vv.UnitPrice)
|
||||
} else {
|
||||
citySkuMap[v.CityCode][vv.NameID] = []int{vv.UnitPrice}
|
||||
for nameID, unitPriceList := range skuNameMap {
|
||||
if citySkuMap[v.CityCode][nameID] != nil {
|
||||
citySkuMap[v.CityCode][nameID] = append(citySkuMap[v.CityCode][nameID], unitPriceList...)
|
||||
} else {
|
||||
citySkuMap[v.CityCode][nameID] = unitPriceList
|
||||
}
|
||||
}
|
||||
} else {
|
||||
skuNameMap[vv.NameID] = append(skuNameMap[vv.NameID], vv.UnitPrice)
|
||||
citySkuMap[v.CityCode] = skuNameMap
|
||||
}
|
||||
}
|
||||
}
|
||||
fmt.Println(citySkuMap)
|
||||
for k1, v := range citySkuMap {
|
||||
skuNameMap := make(map[int]*model.PriceReferSnapshot)
|
||||
for k2, _ := range v {
|
||||
@@ -193,7 +201,7 @@ func BeginSavePriceRefer(ctx *jxcontext.Context, cityCodes, skuIDs []int, isAsyn
|
||||
v.MidUnitPrice = resultMap[v.CityCode][v.NameID].MidUnitPrice
|
||||
v.MaxUnitPrice = resultMap[v.CityCode][v.NameID].MaxUnitPrice
|
||||
v.AvgUnitPrice = resultMap[v.CityCode][v.NameID].AvgUnitPrice
|
||||
v.MaxUnitPrice = resultMap[v.CityCode][v.NameID].MaxUnitPrice
|
||||
v.MinUnitPrice = resultMap[v.CityCode][v.NameID].MinUnitPrice
|
||||
dao.UpdateEntity(db, v, "MidUnitPrice", "MaxUnitPrice", "MinUnitPrice", "AvgUnitPrice")
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user