根据平台价刷新京西价
This commit is contained in:
@@ -3699,3 +3699,107 @@ func RefreshJxPriceByVendor(ctx *jxcontext.Context, jdStoreSkus []*JdStoreSkus,
|
||||
}
|
||||
return hint, err
|
||||
}
|
||||
|
||||
func RefreshJxPriceByVendor2(ctx *jxcontext.Context, storeIDs []int, vendorID int, isAsync, isContinueWhenError bool) (hint string, err error) {
|
||||
var (
|
||||
db = dao.GetDB()
|
||||
param []*StoreSkuBindInfo
|
||||
)
|
||||
taskSeqFunc := func(task *tasksch.SeqTask, step int, params ...interface{}) (result interface{}, err error) {
|
||||
switch step {
|
||||
case 0:
|
||||
for _, storeID := range storeIDs {
|
||||
var (
|
||||
pricePercentagePack []*model.PricePercentageItem
|
||||
skuNameMap = make(map[int]int64)
|
||||
)
|
||||
storeDetail, _ := dao.GetStoreDetail(db, storeID, vendorID)
|
||||
err = jxutils.Strings2Objs(storeDetail.PricePercentagePackStr, &pricePercentagePack)
|
||||
if partner.IsMultiStore(vendorID) {
|
||||
mulitStoreSkuHandler := partner.GetPurchasePlatformFromVendorID(vendorID).(partner.IPurchasePlatformStoreSkuHandler)
|
||||
skuList, err := dao.GetSkusWithVendor(db, []int{vendorID}, nil, nil, nil, false)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
bareStoreSkuMap := make(map[string][]*partner.StoreSkuInfo)
|
||||
for _, sku := range skuList {
|
||||
bareStoreSkuMap[sku.VendorOrgCode] = append(bareStoreSkuMap[sku.VendorOrgCode], &partner.StoreSkuInfo{
|
||||
SkuID: sku.ID,
|
||||
VendorSkuID: sku.VendorSkuID,
|
||||
})
|
||||
}
|
||||
for _, orgCode := range apimanager.CurAPIManager.GetAppOrgCodeList(vendorID) {
|
||||
outStoreSkuList, _ := mulitStoreSkuHandler.GetStoreSkusBareInfo(ctx, orgCode, task, storeID, storeDetail.VendorStoreID, bareStoreSkuMap[orgCode])
|
||||
for _, sku := range outStoreSkuList {
|
||||
price, nameID := getSkuNamePrice(db, sku.SkuID, sku.VendorPrice)
|
||||
if skuNameMap[nameID] < price {
|
||||
skuNameMap[nameID] = price
|
||||
}
|
||||
}
|
||||
for k, v := range skuNameMap {
|
||||
unitPrice := jxutils.CaculateJxPriceByPricePack(pricePercentagePack, 0, int(v))
|
||||
storeSkuBindInfo := &StoreSkuBindInfo{
|
||||
StoreID: storeID,
|
||||
NameID: k,
|
||||
UnitPrice: unitPrice,
|
||||
}
|
||||
param = append(param, storeSkuBindInfo)
|
||||
}
|
||||
}
|
||||
} else {
|
||||
singleStoreHandler := partner.GetPurchasePlatformFromVendorID(vendorID).(partner.ISingleStoreStoreSkuHandler)
|
||||
outSkuNameList, _ := singleStoreHandler.GetStoreSkusFullInfo(ctx, task, storeID, storeDetail.VendorStoreID, nil)
|
||||
for _, skuName := range outSkuNameList {
|
||||
sku := skuName.SkuList[0]
|
||||
price, nameID := getSkuNamePrice(db, sku.SkuID, sku.VendorPrice)
|
||||
if skuNameMap[nameID] < price {
|
||||
skuNameMap[nameID] = price
|
||||
}
|
||||
}
|
||||
for k, v := range skuNameMap {
|
||||
unitPrice := jxutils.CaculateJxPriceByPricePack(pricePercentagePack, 0, int(v))
|
||||
storeSkuBindInfo := &StoreSkuBindInfo{
|
||||
StoreID: storeID,
|
||||
NameID: k,
|
||||
UnitPrice: unitPrice,
|
||||
}
|
||||
param = append(param, storeSkuBindInfo)
|
||||
}
|
||||
}
|
||||
}
|
||||
case 1:
|
||||
_, err = UpdateStoresSkusByBind(ctx, nil, param, isAsync, isContinueWhenError)
|
||||
}
|
||||
return result, err
|
||||
}
|
||||
taskSeq := tasksch.NewSeqTask2("根据平台价刷新京西平台价", ctx, isContinueWhenError, taskSeqFunc, 2)
|
||||
tasksch.HandleTask(taskSeq, nil, true).Run()
|
||||
if !isAsync {
|
||||
_, err = taskSeq.GetResult(0)
|
||||
hint = "1"
|
||||
} else {
|
||||
hint = taskSeq.GetID()
|
||||
}
|
||||
return hint, err
|
||||
}
|
||||
|
||||
func getSkuNamePrice(db *dao.DaoDB, skuID int, orgPrice int64) (price int64, nameID int) {
|
||||
var (
|
||||
specQuality float64
|
||||
)
|
||||
skuList, _ := dao.GetSkus(db, []int{skuID}, nil, nil, nil)
|
||||
for _, v := range skuList {
|
||||
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)
|
||||
}
|
||||
price = utils.Float64TwoInt64(utils.Int2Float64(model.SpecialSpecQuality) / specQuality * utils.Int2Float64(int(orgPrice)))
|
||||
} else {
|
||||
price = orgPrice
|
||||
}
|
||||
nameID = v.NameID
|
||||
}
|
||||
return price, nameID
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user