- RefreshStoresSkuByVendor

This commit is contained in:
gazebo
2019-05-17 17:09:33 +08:00
parent 40d02beee0
commit 0ed0d40a2d
13 changed files with 362 additions and 12 deletions

View File

@@ -153,19 +153,24 @@ func Int64Map2List(int64Map map[int64]int) []int64 {
return retVal
}
// 计算SKU价格unitPrice为一斤的单价specQuality为质量单位为克
func CaculateSkuPrice(unitPrice int, specQuality float32, specUnit string, skuNameUnit string) int {
if skuNameUnit != "份" {
return unitPrice
}
func RegularizeSkuQuality(specQuality float32, specUnit string) (g int) {
lowerSpecUnit := strings.ToLower(specUnit)
if lowerSpecUnit == "kg" || lowerSpecUnit == "l" {
specQuality *= 1000
}
price := int(math.Round(float64(float32(unitPrice) * specQuality / 500)))
if specQuality < 250 {
return int(specQuality)
}
// 计算SKU价格unitPrice为一斤的单价specQuality为质量单位为克
func CaculateSkuPrice(unitPrice int, specQuality float32, specUnit string, skuNameUnit string) int {
if skuNameUnit != model.SpecialUnit {
return unitPrice
}
specQuality2 := RegularizeSkuQuality(specQuality, specUnit)
price := int(math.Round(float64(unitPrice * specQuality2 / model.SpecialSpecQuality)))
if specQuality2 < 250 {
price = price * 110 / 100
} else if specQuality < 500 {
} else if specQuality2 < 500 {
price = price * 105 / 100
}
if price <= 0 {
@@ -174,6 +179,24 @@ func CaculateSkuPrice(unitPrice int, specQuality float32, specUnit string, skuNa
return price
}
// 计算SKU标准价格CaculateSkuPrice的逆过程
func CaculateUnitPrice(skuPrice int, specQuality float32, specUnit string, skuNameUnit string) (unitPrice int) {
if skuNameUnit != model.SpecialUnit {
return skuPrice
}
specQuality2 := RegularizeSkuQuality(specQuality, specUnit)
unitPrice = skuPrice * model.SpecialSpecQuality / specQuality2
if specQuality2 < 250 {
unitPrice = unitPrice * 100 / 110
} else if specQuality2 < 500 {
unitPrice = unitPrice * 100 / 105
}
if unitPrice <= 0 {
unitPrice = 1
}
return unitPrice
}
func GetSliceLen(list interface{}) int {
return reflect.ValueOf(list).Len()
}
@@ -186,11 +209,30 @@ func CaculateSkuVendorPrice(price, percentage, catPercentage int) int {
catPercentage = 100
}
percentage = percentage * catPercentage / 100
storePrice := int(math.Round(float64(price*percentage) / 100))
if storePrice < 0 {
storePrice = 0
vendorPrice := int(math.Round(float64(price*percentage) / 100))
if vendorPrice < 0 {
vendorPrice = 0
}
return storePrice
return vendorPrice
}
func CaculateSkuPriceFromVendor(vendorPrice, percentage, catPercentage int) int {
if percentage <= 10 || percentage >= 400 {
percentage = 100
}
if catPercentage <= 10 || catPercentage >= 400 {
catPercentage = 100
}
percentage = percentage * catPercentage / 100
price := int(math.Round(float64(vendorPrice * 100 / percentage)))
if price < 0 {
price = 0
}
return price
}
func IsSkuSpecial(specQuality float32, specUnit string) bool {
return int(specQuality) == model.SpecialSpecQuality && (specUnit == model.SpecialSpecUnit || specUnit == model.SpecialSpecUnit2)
}
// 生成一个不重复的临时ID