Commit 2d79a180 by wang

Merge branch 'dev' of http://119.23.72.7/q578953158/go_sku_server into dev

parents 28baefb9 b6d2fd2e
......@@ -35,6 +35,7 @@ type Activity struct {
AdminName string `json:"admin_name"`
ActivityId int `json:"activity_id"`
ItemList []ActivityItem `json:"item_list"`
EntireSupplierActivity bool `json:"entire_supplier_activity"`
}
type ActivityItem struct {
......
......@@ -32,7 +32,6 @@ type LySku struct {
SupplierName string `json:"supplier_name"`
Attrs interface{} `json:"attrs"`
ScmBrand interface{} `json:"scm_brand"`
AcType int `json:"ac_type"`
AllowCoupon int `json:"allow_coupon"`
BrandId int64 `json:"brand_id"`
//系数相关
......@@ -61,23 +60,32 @@ type LySku struct {
Ratio float64 `json:"ratio,omitempty"`
SpuDetail string `json:"spu_detail,omitempty"`
AcType int `json:"ac_type"`
//活动信息
HasGiftActivity int `json:"has_gift_activity"`
GiftActivity GiftActivity `json:"gift_activity"`
ActivityInfo PriceActivity `json:"activity_info"`
}
type PriceActivity struct {
HasActivity bool `json:"-"`
ActivityId int `json:"activity_id,omitempty"`
ActivityCommon
Ratio float64 `json:"ratio"`
}
type GiftActivity struct {
HasActivity bool `json:"-"`
ActivityId int `json:"activity_id,omitempty"`
ActivityCommon
ItemList []ActivityItem `json:"items,omitempty"`
}
type ActivityCommon struct {
HasActivity bool `json:"-"`
ActivityId int `json:"activity_id,omitempty"`
ActivityName string `json:"activity_name,omitempty"`
AllowCoupon int `json:"-"`
SignText string `json:"sign_text"`
Sign string `json:"sign"`
ShowName string `json:"show_name"`
}
//为什么不直接映射到结构,而要用gjson,因为redis存的数据结构不一定正常,可能类型不一致
func InitSkuData(sku string) (data LySku) {
......
......@@ -9,6 +9,7 @@ import (
"go_sku_server/model"
"go_sku_server/pkg/gredis"
"strings"
"time"
)
type ActivityService struct {
......@@ -49,72 +50,142 @@ func (as *ActivityService) GetActivityData(checkData model.ActivityCheckData) (p
//获取满赠活动信息
func (as *ActivityService) GetGiftActivity(checkData model.ActivityCheckData, activities []model.Activity) (giftActivity model.GiftActivity) {
var hasActivity bool
nowTimestamp := int(time.Now().Unix())
for _, activity := range activities {
//判断时间是否过期
if activity.StartTime > nowTimestamp || activity.EndTime < nowTimestamp {
return
}
//如果是整个供应商搞活动,则直接返回系数
if activity.EntireSupplierActivity {
hasActivity = true
goto INFO
}
//判断是否是排除的sku或者品牌,如果是的话,直接返回没活动
if as.CheckExcludeSku(checkData.GoodsId, activity) || as.CheckExcludeBrand(checkData.BrandId, activity) {
hasActivity = false
goto INFO
}
//判断是否是搞活动的品牌
if as.CheckBrand(checkData.BrandId, activity) {
hasActivity = true
giftActivity.ItemList = activity.ItemList
giftActivity.ActivityId = activity.ActivityId
goto INFO
}
//如果是专卖,则要去判断canal,如果是自营,则去判断分类
if checkData.SupplierId == 17 {
if as.CheckCanal(checkData.Canal, activity) {
hasActivity = true
giftActivity.ItemList = activity.ItemList
giftActivity.ActivityId = activity.ActivityId
goto INFO
}
} else {
if as.CheckClass(checkData.ClassId, activity) {
hasActivity = true
giftActivity.ItemList = activity.ItemList
goto INFO
}
}
INFO:
if hasActivity {
giftActivity.ActivityName = activity.ActivityName
giftActivity.ActivityId = activity.ActivityId
giftActivity = model.GiftActivity{
ItemList: activity.ItemList,
ActivityCommon: model.ActivityCommon{
HasActivity: hasActivity,
ActivityId: activity.ActivityId,
ActivityName: activity.ActivityName,
AllowCoupon: activity.AllowCoupon,
SignText: activity.SignText,
Sign: activity.Sign,
ShowName: activity.ShowName,
},
}
}
}
giftActivity.HasActivity = hasActivity
return
}
func (as *ActivityService) GetPriceActivity(checkData model.ActivityCheckData, activities []model.Activity) (priceActivity model.PriceActivity) {
var hasActivity bool
nowTimestamp := int(time.Now().Unix())
for _, activity := range activities {
//判断时间是否过期
if activity.StartTime > nowTimestamp || activity.EndTime < nowTimestamp {
return
}
//如果是整个供应商搞活动,则直接返回系数
if activity.EntireSupplierActivity {
hasActivity = true
goto INFO
}
//判断是否是排除的sku或者品牌,如果是的话,直接返回没活动
if as.CheckExcludeSku(checkData.GoodsId, activity) || as.CheckExcludeBrand(checkData.BrandId, activity) {
hasActivity = false
}
//判断是否是搞活动的品牌
if as.CheckBrand(checkData.BrandId, activity) {
hasActivity = true
priceActivity.Ratio = activity.Ratio
goto INFO
}
//如果是专卖,则要去判断canal,如果是自营,则去判断分类
if checkData.SupplierId == 17 {
if as.CheckCanal(checkData.Canal, activity) {
//品牌不为空,还要去判断品牌,是同时满足的关系
if activity.BrandIds != "" {
//判断是否是搞活动的品牌
if as.CheckBrand(checkData.BrandId, activity) {
hasActivity = true
priceActivity.Ratio = activity.Ratio
goto INFO
}
} else {
hasActivity = true
goto INFO
}
}
} else if checkData.SupplierId == 10000 {
if as.CheckClass(checkData.ClassId, activity) {
//品牌不为空,还要去判断品牌,是同时满足的关系
if activity.BrandIds != "" {
//判断是否是搞活动的品牌
if as.CheckBrand(checkData.BrandId, activity) {
hasActivity = true
goto INFO
}
} else {
hasActivity = true
priceActivity.Ratio = activity.Ratio
goto INFO
}
}
} else {
//判断是否是搞活动的品牌
if as.CheckSkuId(checkData.GoodsId, activity) {
if as.CheckBrand(checkData.BrandId, activity) {
hasActivity = true
priceActivity.Ratio = activity.Ratio
goto INFO
}
}
INFO:
if hasActivity {
priceActivity.ActivityName = activity.ActivityName
priceActivity.ActivityId = activity.ActivityId
priceActivity = model.PriceActivity{
Ratio: activity.Ratio,
ActivityCommon: model.ActivityCommon{
HasActivity: hasActivity,
ActivityId: activity.ActivityId,
ActivityName: activity.ActivityName,
AllowCoupon: activity.AllowCoupon,
SignText: activity.SignText,
Sign: activity.Sign,
ShowName: activity.ShowName,
},
}
}
}
priceActivity.HasActivity = hasActivity
return
}
......@@ -191,18 +262,3 @@ func (as *ActivityService) CheckCanal(canal string, activity model.Activity) boo
}
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
sku.AllowCoupon = 1
sku.BrandId = brandId
//去判断是否有活动(促销打折活动和满赠活动)
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
}
sku = ls.GetActivity(sku)
//处理阶梯价数据
if len(sku.LadderPrice) > 0 {
......@@ -188,3 +172,32 @@ func (ls *LyService) LyGoodsDetail(ctx *gin.Context, goodsIds []string, ch chan
}
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 = priceActivity
}
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 (
"time"
)
type PriceService struct {
}
//获取联营活动价
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