Commit bc8f6310 by mushishixian

联营商品服务

parent 756df35c
...@@ -35,6 +35,7 @@ type Activity struct { ...@@ -35,6 +35,7 @@ type Activity struct {
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"`
} }
type ActivityItem struct { type ActivityItem struct {
......
...@@ -32,7 +32,6 @@ type LySku struct { ...@@ -32,7 +32,6 @@ type LySku struct {
SupplierName string `json:"supplier_name"` SupplierName string `json:"supplier_name"`
Attrs interface{} `json:"attrs"` Attrs interface{} `json:"attrs"`
ScmBrand interface{} `json:"scm_brand"` ScmBrand interface{} `json:"scm_brand"`
AcType int `json:"ac_type"`
AllowCoupon int `json:"allow_coupon"` AllowCoupon int `json:"allow_coupon"`
BrandId int64 `json:"brand_id"` BrandId int64 `json:"brand_id"`
//系数相关 //系数相关
...@@ -61,24 +60,32 @@ type LySku struct { ...@@ -61,24 +60,32 @@ type LySku struct {
Ratio float64 `json:"ratio,omitempty"` Ratio float64 `json:"ratio,omitempty"`
SpuDetail string `json:"spu_detail,omitempty"` SpuDetail string `json:"spu_detail,omitempty"`
AcType int `json:"ac_type"`
//活动信息 //活动信息
HasGiftActivity int `json:"has_gift_activity"` HasGiftActivity int `json:"has_gift_activity"`
GiftActivity GiftActivity `json:"gift_activity"` GiftActivity GiftActivity `json:"gift_activity"`
ActivityInfo struct {
ActivityId int `json:"activity_id,omitempty"`
ActivityName string `json:"activity_name,omitempty"`
} `json:"activity_info"`
} }
type PriceActivity struct { type PriceActivity struct {
HasActivity bool `json:"-"` HasActivity bool `json:"-"`
ActivityId int `json:"activity_id,omitempty"` ActivityId int `json:"activity_id,omitempty"`
Ratio float64 `json:"ratio"` ActivityName string `json:"activity_name,omitempty"`
AllowCoupon int `json:"-"`
Ratio float64 `json:"ratio"`
} }
type GiftActivity struct { type GiftActivity struct {
HasActivity bool `json:"-"` HasActivity bool `json:"-"`
ActivityId int `json:"activity_id,omitempty"` ActivityId int `json:"activity_id,omitempty"`
ItemList []ActivityItem `json:"items,omitempty"` ActivityName int `json:"activity_name,omitempty"`
AllowCoupon int `json:"-"`
ItemList []ActivityItem `json:"items,omitempty"`
} }
//为什么不直接映射到结构,而要用gjson,因为redis存的数据结构不一定正常,可能类型不一致 //为什么不直接映射到结构,而要用gjson,因为redis存的数据结构不一定正常,可能类型不一致
func InitSkuData(sku string) (data LySku) { func InitSkuData(sku string) (data LySku) {
goodsSn := gjson.Get(sku, "goods_sn").String() goodsSn := gjson.Get(sku, "goods_sn").String()
......
...@@ -9,6 +9,7 @@ import ( ...@@ -9,6 +9,7 @@ import (
"go_sku_server/model" "go_sku_server/model"
"go_sku_server/pkg/gredis" "go_sku_server/pkg/gredis"
"strings" "strings"
"time"
) )
type ActivityService struct { type ActivityService struct {
...@@ -49,7 +50,21 @@ func (as *ActivityService) GetActivityData(checkData model.ActivityCheckData) (p ...@@ -49,7 +50,21 @@ func (as *ActivityService) GetActivityData(checkData model.ActivityCheckData) (p
//获取满赠活动信息 //获取满赠活动信息
func (as *ActivityService) GetGiftActivity(checkData model.ActivityCheckData, activities []model.Activity) (giftActivity model.GiftActivity) { func (as *ActivityService) GetGiftActivity(checkData model.ActivityCheckData, activities []model.Activity) (giftActivity model.GiftActivity) {
var hasActivity bool var hasActivity bool
nowTimestamp := int(time.Now().Unix())
for _, activity := range activities { for _, activity := range activities {
//判断时间是否过期
if activity.StartTime > nowTimestamp || activity.EndTime < nowTimestamp {
return
}
//如果是整个供应商搞活动,则直接返回系数
if activity.EntireSupplierActivity {
hasActivity = true
giftActivity.ItemList = activity.ItemList
giftActivity.ActivityId = activity.ActivityId
}
//判断是否是排除的sku或者品牌,如果是的话,直接返回没活动 //判断是否是排除的sku或者品牌,如果是的话,直接返回没活动
if as.CheckExcludeSku(checkData.GoodsId, activity) || as.CheckExcludeBrand(checkData.BrandId, activity) { if as.CheckExcludeSku(checkData.GoodsId, activity) || as.CheckExcludeBrand(checkData.BrandId, activity) {
hasActivity = false hasActivity = false
...@@ -77,14 +92,25 @@ func (as *ActivityService) GetGiftActivity(checkData model.ActivityCheckData, ac ...@@ -77,14 +92,25 @@ func (as *ActivityService) GetGiftActivity(checkData model.ActivityCheckData, ac
} }
} }
} }
giftActivity.HasActivity = hasActivity giftActivity.HasActivity = hasActivity
return return
} }
func (as *ActivityService) GetPriceActivity(checkData model.ActivityCheckData, activities []model.Activity) (priceActivity model.PriceActivity) { func (as *ActivityService) GetPriceActivity(checkData model.ActivityCheckData, activities []model.Activity) (priceActivity model.PriceActivity) {
var hasActivity bool var hasActivity bool
nowTimestamp := int(time.Now().Unix())
for _, activity := range activities { for _, activity := range activities {
//判断时间是否过期
if activity.StartTime > nowTimestamp || activity.EndTime < nowTimestamp {
return
}
//如果是整个供应商搞活动,则直接返回系数
if activity.EntireSupplierActivity {
hasActivity = true
priceActivity.Ratio = activity.Ratio
}
//判断是否是排除的sku或者品牌,如果是的话,直接返回没活动 //判断是否是排除的sku或者品牌,如果是的话,直接返回没活动
if as.CheckExcludeSku(checkData.GoodsId, activity) || as.CheckExcludeBrand(checkData.BrandId, activity) { if as.CheckExcludeSku(checkData.GoodsId, activity) || as.CheckExcludeBrand(checkData.BrandId, activity) {
hasActivity = false hasActivity = false
...@@ -108,13 +134,13 @@ func (as *ActivityService) GetPriceActivity(checkData model.ActivityCheckData, a ...@@ -108,13 +134,13 @@ func (as *ActivityService) GetPriceActivity(checkData model.ActivityCheckData, a
priceActivity.Ratio = activity.Ratio priceActivity.Ratio = activity.Ratio
} }
} }
if hasActivity {
//判断是否是搞活动的品牌 priceActivity.AllowCoupon = activity.AllowCoupon
if as.CheckSkuId(checkData.GoodsId, activity) { priceActivity.ActivityName = activity.ActivityName
hasActivity = true priceActivity.ActivityId = activity.ActivityId
priceActivity.Ratio = activity.Ratio
} }
} }
priceActivity.HasActivity = hasActivity priceActivity.HasActivity = hasActivity
return return
} }
...@@ -191,18 +217,3 @@ func (as *ActivityService) CheckCanal(canal string, activity model.Activity) boo ...@@ -191,18 +217,3 @@ func (as *ActivityService) CheckCanal(canal string, activity model.Activity) boo
} }
return false return false
} }
//检查是否属于活动sku_id
func (as *ActivityService) CheckSkuId(skuId string, activity model.Activity) bool {
if skuId == "" {
return false
}
//先去判断品牌
activity.SkuIdList = strings.Split(activity.SkuIds, ",")
skuIdStr := gconv.String(skuId)
//如果存在于有活动价的品牌,就是有折扣活动了
if php2go.InArray(skuIdStr, activity.SkuIdList) {
return true
}
return false
}
...@@ -118,23 +118,7 @@ func (ls *LyService) LyGoodsDetail(ctx *gin.Context, goodsIds []string, ch chan ...@@ -118,23 +118,7 @@ func (ls *LyService) LyGoodsDetail(ctx *gin.Context, goodsIds []string, ch chan
sku.AllowCoupon = 1 sku.AllowCoupon = 1
sku.BrandId = brandId sku.BrandId = brandId
//去判断是否有活动(促销打折活动和满赠活动) sku = ls.GetActivity(sku)
checkData := model.ActivityCheckData{
SupplierId: int(sku.SupplierId),
BrandId: int(sku.BrandId),
GoodsId: sku.GoodsId,
Canal: sku.Canal,
ClassId: sku.ClassID2,
}
var activityService ActivityService
priceActivity, giftActivity := activityService.GetActivityData(checkData)
if priceActivity.HasActivity {
sku.AcType = 9
}
if giftActivity.HasActivity {
sku.HasGiftActivity = gconv.Int(giftActivity.HasActivity)
sku.GiftActivity = giftActivity
}
//处理阶梯价数据 //处理阶梯价数据
if len(sku.LadderPrice) > 0 { if len(sku.LadderPrice) > 0 {
...@@ -188,3 +172,33 @@ func (ls *LyService) LyGoodsDetail(ctx *gin.Context, goodsIds []string, ch chan ...@@ -188,3 +172,33 @@ func (ls *LyService) LyGoodsDetail(ctx *gin.Context, goodsIds []string, ch chan
} }
ch <- GoodsRes ch <- GoodsRes
} }
//获取活动
func (ls *LyService) GetActivity(sku model.LySku) model.LySku {
//去判断是否有活动(促销打折活动和满赠活动)
checkData := model.ActivityCheckData{
SupplierId: int(sku.SupplierId),
BrandId: int(sku.BrandId),
GoodsId: sku.GoodsId,
Canal: sku.Canal,
ClassId: sku.ClassID2,
}
var activityService ActivityService
priceActivity, giftActivity := activityService.GetActivityData(checkData)
if priceActivity.HasActivity {
sku.AcType = 10
sku.Ratio = priceActivity.Ratio
sku.ActivityInfo.ActivityId = priceActivity.ActivityId
sku.ActivityInfo.ActivityName = priceActivity.ActivityName
}
if giftActivity.HasActivity {
sku.HasGiftActivity = gconv.Int(giftActivity.HasActivity)
sku.GiftActivity = giftActivity
}
//获取是否能使用优惠券
if giftActivity.AllowCoupon != 1 || priceActivity.AllowCoupon != 1 {
sku.AllowCoupon = 0
}
return sku
}
...@@ -11,6 +11,9 @@ import ( ...@@ -11,6 +11,9 @@ import (
"time" "time"
) )
type PriceService struct {
}
//获取联营活动价 //获取联营活动价
func (ls *LyService) GetActivityPrice(sku model.LySku, suffix string, power Power) model.LySku { func (ls *LyService) GetActivityPrice(sku model.LySku, suffix string, power Power) model.LySku {
//没价格,直接返回 //没价格,直接返回
......
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