Commit 77e2a838 by mushishixian

修复价格获取的问题

parent 9d0b9c9e
...@@ -45,6 +45,7 @@ require ( ...@@ -45,6 +45,7 @@ require (
gopkg.in/mgo.v2 v2.0.0-20190816093944-a6b53ec6cb22 gopkg.in/mgo.v2 v2.0.0-20190816093944-a6b53ec6cb22
gopkg.in/yaml.v2 v2.4.0 // indirect gopkg.in/yaml.v2 v2.4.0 // indirect
sigs.k8s.io/yaml v1.2.0 // indirect sigs.k8s.io/yaml v1.2.0 // indirect
github.com/shopspring/decimal v1.0.1
) )
......
package model package model
type Activity struct { type Activity struct {
Id int64 `json:"id"` Id int64 `json:"id"`
SupplierIds string `json:"supplier_ids"` SupplierIds string `json:"supplier_ids"`
SupplierIdList []string SupplierIdList []string
SupplierType int `json:"supplier_type"` SupplierType int `json:"supplier_type"`
UserScope int `json:"user_scope"` UserScope int `json:"user_scope"`
CanAdminOrder interface{} `json:"can_admin_order"` CanAdminOrder interface{} `json:"can_admin_order"`
SignText string `json:"sign_text"` SignText string `json:"sign_text"`
BrandIds string `json:"brand_ids"` BrandIds string `json:"brand_ids"`
BrandIdList []string BrandIdList []string
ClassIds string `json:"class_ids"` ClassIds string `json:"class_ids"`
ClassIdList []string ClassIdList []string
Canals string `json:"canals"` Canals string `json:"canals"`
CanalList []string CanalList []string
Ratio float64 `json:"ratio"` Ratio float64 `json:"ratio"`
RatioUs float64 `json:"ratio_us"` RatioUs float64 `json:"ratio_us"`
StartTime int `json:"start_time"` StartTime int `json:"start_time"`
EndTime int `json:"end_time"` EndTime int `json:"end_time"`
AddTime int `json:"add_time"` AddTime int `json:"add_time"`
UpdateTime int `json:"update_time"` UpdateTime int `json:"update_time"`
Status int `json:"status"` Status int `json:"status"`
AllowCoupon int `json:"allow_coupon"` AllowCoupon int `json:"allow_coupon"`
ActivityName string `json:"activity_name"` ActivityName string `json:"activity_name"`
ShowName string `json:"show_name"` ShowName string `json:"show_name"`
Sign string `json:"sign"` Sign string `json:"sign"`
ActivityType int `json:"activity_type"` ActivityType int `json:"activity_type"`
GoodsScope int `json:"goods_scope"` GoodsScope int `json:"goods_scope"`
ExcludeBrandIds string `json:"exclude_brand_ids"` ExcludeBrandIds string `json:"exclude_brand_ids"`
ExcludeBrandIdList []string ExcludeBrandIdList []string
ExcludeSkuIds string `json:"exclude_sku_ids"` ExcludeSkuIds string `json:"exclude_sku_ids"`
ExcludeSkuIdList []string ExcludeSkuIdList []string
SkuIds string `json:"sku_ids"` SkuIds string `json:"sku_ids"`
SkuIdList []string SkuIdList []string
AdminId int `json:"admin_id"` AdminId int `json:"admin_id"`
AdminName string `json:"admin_name"` AdminName string `json:"admin_name"`
ActivityId int `json:"activity_id"` ActivityId int `json:"activity_id"`
ItemList []ActivityItem `json:"item_list"` ItemList []ActivityItem `json:"item_list"`
EntireSupplierActivity bool `json:"entire_supplier_activity"` EntireSupplierActivity bool `json:"entire_supplier_activity"`
StandardBrandIds string `json:"standard_brand_ids"`
StandardBrandIdList []string
ExcludeStandardBrandIds string `json:"exclude_standard_brand_ids"`
ExcludeStandardBrandIdList []string
} }
type ActivityItem struct { type ActivityItem struct {
...@@ -54,9 +58,10 @@ type ActivityItem struct { ...@@ -54,9 +58,10 @@ type ActivityItem struct {
//用于检查是否有活动情况的结构体 //用于检查是否有活动情况的结构体
type ActivityCheckData struct { type ActivityCheckData struct {
SupplierId int SupplierId int
BrandId int BrandId int
GoodsId string StandardBrandId int
Canal string GoodsId string
ClassId int Canal string
ClassId int
} }
...@@ -21,21 +21,8 @@ func (as *ActivityService) GetActivityData(checkData model.ActivityCheckData) (p ...@@ -21,21 +21,8 @@ func (as *ActivityService) GetActivityData(checkData model.ActivityCheckData) (p
supplierId := checkData.SupplierId supplierId := checkData.SupplierId
redisCon := gredis.Conn("default_r") redisCon := gredis.Conn("default_r")
defer redisCon.Close() defer redisCon.Close()
//处理满赠活动
activityStr, _ := redis.String(redisCon.Do("hget", "lie_gift_activity", supplierId))
if activityStr != "" {
var activities []model.Activity
err := json.Unmarshal([]byte(activityStr), &activities)
if err != nil {
fmt.Println(err)
}
if len(activities) != 0 {
giftActivity = as.GetGiftActivity(checkData, activities)
}
}
//处理单品促销活动(打折活动) //处理单品促销活动(打折活动)
activityStr, _ = redis.String(redisCon.Do("hget", "lie_price_activity", supplierId)) activityStr, _ := redis.String(redisCon.Do("hget", "lie_price_activity", supplierId))
if activityStr != "" { if activityStr != "" {
var activities []model.Activity var activities []model.Activity
err := json.Unmarshal([]byte(activityStr), &activities) err := json.Unmarshal([]byte(activityStr), &activities)
...@@ -135,7 +122,7 @@ func (as *ActivityService) GetPriceActivity(checkData model.ActivityCheckData, a ...@@ -135,7 +122,7 @@ func (as *ActivityService) GetPriceActivity(checkData model.ActivityCheckData, a
} }
//判断是否是排除的sku或者品牌,如果是的话,直接返回没活动 //判断是否是排除的sku或者品牌,如果是的话,直接返回没活动
if as.CheckExcludeSku(checkData.GoodsId, activity) || as.CheckExcludeBrand(checkData.BrandId, activity) { if as.CheckExcludeSku(checkData.GoodsId, activity) || as.CheckExcludeStandardBrand(checkData.StandardBrandId, activity) {
continue continue
} }
...@@ -145,7 +132,7 @@ func (as *ActivityService) GetPriceActivity(checkData model.ActivityCheckData, a ...@@ -145,7 +132,7 @@ func (as *ActivityService) GetPriceActivity(checkData model.ActivityCheckData, a
//品牌不为空,还要去判断品牌,是同时满足的关系 //品牌不为空,还要去判断品牌,是同时满足的关系
if activity.BrandIds != "" { if activity.BrandIds != "" {
//判断是否是搞活动的品牌 //判断是否是搞活动的品牌
if as.CheckBrand(checkData.BrandId, activity) { if as.CheckStandardBrand(checkData.StandardBrandId, activity) {
hasActivity = true hasActivity = true
goto INFO goto INFO
} }
...@@ -165,7 +152,7 @@ func (as *ActivityService) GetPriceActivity(checkData model.ActivityCheckData, a ...@@ -165,7 +152,7 @@ func (as *ActivityService) GetPriceActivity(checkData model.ActivityCheckData, a
//品牌不为空,还要去判断品牌,是同时满足的关系 //品牌不为空,还要去判断品牌,是同时满足的关系
if activity.BrandIds != "" { if activity.BrandIds != "" {
//判断是否是搞活动的品牌 //判断是否是搞活动的品牌
if as.CheckBrand(checkData.BrandId, activity) { if as.CheckStandardBrand(checkData.StandardBrandId, activity) {
hasActivity = true hasActivity = true
goto INFO goto INFO
} }
...@@ -175,8 +162,9 @@ func (as *ActivityService) GetPriceActivity(checkData model.ActivityCheckData, a ...@@ -175,8 +162,9 @@ func (as *ActivityService) GetPriceActivity(checkData model.ActivityCheckData, a
} }
} }
} else { } else {
fmt.Println(activity)
//判断是否是搞活动的品牌 //判断是否是搞活动的品牌
if as.CheckBrand(checkData.BrandId, activity) { if as.CheckStandardBrand(checkData.StandardBrandId, activity) {
hasActivity = true hasActivity = true
goto INFO goto INFO
} }
...@@ -226,6 +214,21 @@ func (as *ActivityService) CheckExcludeBrand(brandId int, activity model.Activit ...@@ -226,6 +214,21 @@ func (as *ActivityService) CheckExcludeBrand(brandId int, activity model.Activit
return false return false
} }
//检查是否属于被排除的标准品牌
func (as *ActivityService) CheckExcludeStandardBrand(standardBrandId int, activity model.Activity) bool {
if standardBrandId == 0 {
return false
}
//先去判断品牌
activity.ExcludeStandardBrandIdList = strings.Split(activity.ExcludeStandardBrandIds, ",")
standardBrandIdStr := gconv.String(standardBrandId)
//如果存在于有活动价的品牌,就是有折扣活动了
if php2go.InArray(standardBrandIdStr, activity.ExcludeStandardBrandIdList) {
return true
}
return false
}
//检查是否属于被排除的sku //检查是否属于被排除的sku
func (as *ActivityService) CheckExcludeSku(skuId string, activity model.Activity) bool { func (as *ActivityService) CheckExcludeSku(skuId string, activity model.Activity) bool {
if skuId == "" { if skuId == "" {
...@@ -270,6 +273,21 @@ func (as *ActivityService) CheckBrand(brandId int, activity model.Activity) bool ...@@ -270,6 +273,21 @@ func (as *ActivityService) CheckBrand(brandId int, activity model.Activity) bool
return false return false
} }
//检测是否属于活动标准品牌
func (as *ActivityService) CheckStandardBrand(standardBrandId int, activity model.Activity) bool {
if standardBrandId == 0 {
return false
}
//先去判断品牌
activity.StandardBrandIdList = strings.Split(activity.StandardBrandIds, ",")
standardBrandIdStr := gconv.String(standardBrandId)
//如果存在于有活动价的品牌,就是有折扣活动了
if php2go.InArray(standardBrandIdStr, activity.StandardBrandIdList) {
return true
}
return false
}
//检查是否属于供应商渠道 //检查是否属于供应商渠道
func (as *ActivityService) CheckCanal(canal string, activity model.Activity) bool { func (as *ActivityService) CheckCanal(canal string, activity model.Activity) bool {
if canal == "" { if canal == "" {
......
...@@ -205,11 +205,12 @@ func (ls *LyService) LyGoodsDetail(ctx *gin.Context, goodsIds []string, ch chan ...@@ -205,11 +205,12 @@ func (ls *LyService) LyGoodsDetail(ctx *gin.Context, goodsIds []string, ch chan
func (ls *LyService) GetActivity(sku model.LySku) model.LySku { func (ls *LyService) GetActivity(sku model.LySku) model.LySku {
//去判断是否有活动(促销打折活动和满赠活动) //去判断是否有活动(促销打折活动和满赠活动)
checkData := model.ActivityCheckData{ checkData := model.ActivityCheckData{
SupplierId: int(sku.SupplierId), SupplierId: int(sku.SupplierId),
BrandId: int(sku.BrandId), BrandId: int(sku.BrandId),
GoodsId: sku.GoodsId, StandardBrandId: int(sku.StandardBrand.StandardBrandId),
Canal: sku.Canal, GoodsId: sku.GoodsId,
ClassId: sku.ClassID2, Canal: sku.Canal,
ClassId: sku.ClassID2,
} }
var activityService ActivityService var activityService ActivityService
priceActivity, giftActivity := activityService.GetActivityData(checkData) priceActivity, giftActivity := activityService.GetActivityData(checkData)
......
...@@ -278,10 +278,11 @@ func (ls *LyService) GetCoefficientAndPrice(sku model.LySku) model.LySku { ...@@ -278,10 +278,11 @@ func (ls *LyService) GetCoefficientAndPrice(sku model.LySku) model.LySku {
} }
} }
cnDiscountRatio += 1 cnDiscountRatio = common.MyRound(cnDiscountRatio+1, 3)
usDiscountRatio += 1 usDiscountRatio = common.MyRound(usDiscountRatio+1, 3)
sku.DiscountRatio.Ratio = cnDiscountRatio sku.DiscountRatio.Ratio = cnDiscountRatio
sku.DiscountRatio.RatioUsd = usDiscountRatio sku.DiscountRatio.RatioUsd = usDiscountRatio
fmt.Println("折扣系数 : ", cnDiscountRatio, usDiscountRatio)
//再去找售价组系数 //再去找售价组系数
//找一个标志位,因为默认的全局折扣系数的数据格式和非全局的是不一样的 //找一个标志位,因为默认的全局折扣系数的数据格式和非全局的是不一样的
...@@ -362,6 +363,7 @@ func (ls *LyService) GetCoefficientAndPrice(sku model.LySku) model.LySku { ...@@ -362,6 +363,7 @@ func (ls *LyService) GetCoefficientAndPrice(sku model.LySku) model.LySku {
} }
sku.PriceRatio = priceRatioList sku.PriceRatio = priceRatioList
sku.PriceRatioSort = priceRatioSort sku.PriceRatioSort = priceRatioSort
fmt.Println("售价组系数 : ", priceRatioList)
//这里是供应商系数,先保留这块逻辑 //这里是供应商系数,先保留这块逻辑
ratio, _ := redis.String(redisCon.Do("HGET", "pool_supplier_ratio", sku.SupplierId)) ratio, _ := redis.String(redisCon.Do("HGET", "pool_supplier_ratio", sku.SupplierId))
...@@ -414,6 +416,8 @@ func (ls *LyService) GetCoefficientAndPrice(sku model.LySku) model.LySku { ...@@ -414,6 +416,8 @@ func (ls *LyService) GetCoefficientAndPrice(sku model.LySku) model.LySku {
coefficient = defaultCoefficient coefficient = defaultCoefficient
} }
fmt.Println("供应商系数 : ", coefficient)
//下面是计算价格 //下面是计算价格
//价格计算文档 https://docs.qq.com/doc/DR3RJcnNPeUNkWHRk //价格计算文档 https://docs.qq.com/doc/DR3RJcnNPeUNkWHRk
// 为何是固定的1.13,关税基本不会变,有变的话跟产品沟通手动修改即可 // 为何是固定的1.13,关税基本不会变,有变的话跟产品沟通手动修改即可
...@@ -448,7 +452,6 @@ func (ls *LyService) GetCoefficientAndPrice(sku model.LySku) model.LySku { ...@@ -448,7 +452,6 @@ func (ls *LyService) GetCoefficientAndPrice(sku model.LySku) model.LySku {
//处理人民币 //处理人民币
data[key].PriceCn = common.MyRound(priceCn, 4) data[key].PriceCn = common.MyRound(priceCn, 4)
data[key].PriceCostCn = common.MyRound(priceCostCn, 4) data[key].PriceCostCn = common.MyRound(priceCostCn, 4)
fmt.Println(data[key])
//处理mouser的成本价 //处理mouser的成本价
//mouser成本价是什么,斌哥同步过来的成本价 //mouser成本价是什么,斌哥同步过来的成本价
//sku.LadderPrice[key].CostPrice是专门针对贸泽(mouser)的 //sku.LadderPrice[key].CostPrice是专门针对贸泽(mouser)的
...@@ -461,7 +464,6 @@ func (ls *LyService) GetCoefficientAndPrice(sku model.LySku) model.LySku { ...@@ -461,7 +464,6 @@ func (ls *LyService) GetCoefficientAndPrice(sku model.LySku) model.LySku {
} }
continue continue
} }
//处理活动价和原价相同的情况 //处理活动价和原价相同的情况
if (sku.GoodsType == 1 || sku.GoodsType == 2) && sku.AcType > 1 && sku.Ratio > 0 { if (sku.GoodsType == 1 || sku.GoodsType == 2) && sku.AcType > 1 && sku.Ratio > 0 {
priceAc := common.MyRound(data[key].PriceCn*(sku.Ratio/100), 4) priceAc := common.MyRound(data[key].PriceCn*(sku.Ratio/100), 4)
......
...@@ -51,10 +51,11 @@ func (qs *ZiyingService) ActivityPrice(ctx *gin.Context, SkuInfo string) *ordere ...@@ -51,10 +51,11 @@ func (qs *ZiyingService) ActivityPrice(ctx *gin.Context, SkuInfo string) *ordere
func (qs *ZiyingService) GetActivity(skuInfo string) (priceActivity model.PriceActivity, giftActivity model.GiftActivity) { func (qs *ZiyingService) GetActivity(skuInfo string) (priceActivity model.PriceActivity, giftActivity model.GiftActivity) {
//去判断是否有活动(促销打折活动和满赠活动) //去判断是否有活动(促销打折活动和满赠活动)
checkData := model.ActivityCheckData{ checkData := model.ActivityCheckData{
SupplierId: 10000, SupplierId: 10000,
BrandId: int(gjson.Get(skuInfo, "brand_id").Int()), BrandId: int(gjson.Get(skuInfo, "brand_id").Int()),
GoodsId: gjson.Get(skuInfo, "goods_id").String(), StandardBrandId: int(gjson.Get(skuInfo, "standard_brand.standard_brand_id").Int()),
ClassId: int(gjson.Get(skuInfo, "class_id2").Int()), GoodsId: gjson.Get(skuInfo, "goods_id").String(),
ClassId: int(gjson.Get(skuInfo, "class_id2").Int()),
} }
var activityService ActivityService var activityService ActivityService
priceActivity, giftActivity = activityService.GetActivityData(checkData) priceActivity, giftActivity = activityService.GetActivityData(checkData)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment