差评补款

This commit is contained in:
苏尹岚
2020-01-06 18:25:14 +08:00
parent e4b8d1da21
commit 103bce68ba
5 changed files with 88 additions and 11 deletions

View File

@@ -2219,7 +2219,7 @@ func GetTopSkusByCityCode(ctx *jxcontext.Context, cityCode, storeID int) (skuNam
JOIN sku b ON a.sku_id = b.id AND b.deleted_at = ?
WHERE a.deleted_at = ?
AND a.store_id = ?
AND a.status = ?)
AND a.status = ?)
`
sqlParams := []interface{}{
utils.DefaultTimeValue,
@@ -2236,11 +2236,21 @@ func GetTopSkusByCityCode(ctx *jxcontext.Context, cityCode, storeID int) (skuNam
for _, v := range skuNameList {
skuNameMap[v.ID] = v
}
store, err := dao.GetStoreDetail(db, storeID, -1)
if err != nil {
return nil, err
}
var payPercentage int
if store.PayPercentage < 50 {
payPercentage = 70
} else {
payPercentage = store.PayPercentage
}
for _, v := range skuNameAndPlace {
if skuNameMap[v.ID] != nil {
priceReferList, _ := dao.GetPriceReferSnapshotNoPage(db, []int{cityCode}, nil, []int{v.ID}, utils.Time2Date(time.Now().AddDate(0, 0, -1)))
if len(priceReferList) > 0 {
v.Price = priceReferList[0].MidUnitPrice
v.Price = priceReferList[0].MidUnitPrice * payPercentage / 100
}
v.Type = skuNameMap[v.ID].BrandID
skuList, _ := dao.GetSkus(db, nil, []int{v.ID}, nil, nil)
@@ -2947,9 +2957,15 @@ func FocusStoreSkusBySku(ctx *jxcontext.Context, skuIDs []int, isAsync, isContin
if len(focusList) > 0 {
price = focusList[0].UnitPrice
} else {
priceReferList, _, _ := dao.GetPriceReferSnapshot(db, []int{store.CityCode}, nil, k, utils.Time2Date(time.Now().AddDate(0, 0, -1)), 0, 9999)
var payPercentage int
if store.PayPercentage < 50 {
payPercentage = 70
} else {
payPercentage = store.PayPercentage
}
priceReferList, _ := dao.GetPriceReferSnapshotNoPage(db, []int{store.CityCode}, nil, []int{k}, utils.Time2Date(time.Now().AddDate(0, 0, -1)))
if len(priceReferList) > 0 {
price = priceReferList[0].MidUnitPrice
price = priceReferList[0].MidUnitPrice * payPercentage / 100
}
}
skuBindInfo := &StoreSkuBindInfo{
@@ -2989,6 +3005,68 @@ func FocusStoreSkusBySku(ctx *jxcontext.Context, skuIDs []int, isAsync, isContin
return hint, err
}
func AutoFocusStoreSkusWithoutFocusForTopSkus(ctx *jxcontext.Context) (err error) {
db := dao.GetDB()
storeList, err := dao.GetStoreList(db, nil, nil, "")
for _, v := range storeList {
var (
skuName []*model.SkuName
skuNameMap = make(map[int]int)
skuBindInfoList []*StoreSkuBindInfo
)
sql := `
SELECT DISTINCT a.name_id id
FROM sku a
LEFT JOIN (SELECT DISTINCT b.name_id
FROM store_sku_bind a
JOIN sku b ON a.sku_id = b.id
WHERE a.deleted_at = ?
AND store_id = ?)b ON a.name_id = b.name_id
WHERE a.status = ?
AND a.deleted_at = ?
AND b.name_id IS NULL
`
sqlParams := []interface{}{
utils.DefaultTimeValue,
v.ID,
model.SkuStatusNormal,
utils.DefaultTimeValue,
}
err = dao.GetRows(db, &skuName, sql, sqlParams...)
for _, v := range skuName {
skuNameMap[v.ID] = v.ID
}
skuNameAndPlaceList, err2 := GetTopSkusByCityCode(ctx, v.CityCode, v.ID)
if err2 != nil {
return err2
}
var payPercentage int
if v.PayPercentage < 50 {
payPercentage = 70
} else {
payPercentage = v.PayPercentage
}
if len(skuNameAndPlaceList) > 0 {
for _, v := range skuNameAndPlaceList {
if skuNameMap[v.ID] != 0 {
priceReferList, err := dao.GetPriceReferSnapshotNoPage(db, []int{v.CityCode}, nil, []int{v.ID}, utils.Time2Date(time.Now().AddDate(0, 0, -1)))
if err == nil && len(priceReferList) > 0 {
storeSkuBindInfo := &StoreSkuBindInfo{
NameID: v.ID,
UnitPrice: priceReferList[0].MidUnitPrice * payPercentage / 100,
IsFocus: 1,
IsSale: 0,
}
skuBindInfoList = append(skuBindInfoList, storeSkuBindInfo)
}
}
}
}
UpdateStoreSkus(ctx, v.ID, skuBindInfoList, true, true)
}
return err
}
func AutoFocusStoreSkusWithoutFocus(ctx *jxcontext.Context, skuIDs []int, isSync bool) (err error) {
var (
nameMap = make(map[int]*StoreSkuBindInfo)