Commit b6fc36a2 by mushishixian

活动判断优化

parent 17642664
...@@ -155,8 +155,12 @@ func (as *ActivityService) GetPriceActivity(checkData model.ActivityCheckData, a ...@@ -155,8 +155,12 @@ func (as *ActivityService) GetPriceActivity(checkData model.ActivityCheckData, a
} }
} }
} else if checkData.SupplierId == 10000 { } else if checkData.SupplierId == 10000 {
//自营活动特殊判断
//判断活动指定的渠道编码,品牌,分类id,如果都为空,那么这个活动可以理解为整个供应商了,上面的排除已经会提前去判断了 //判断活动指定的渠道编码,品牌,分类id,如果都为空,那么这个活动可以理解为整个供应商了,上面的排除已经会提前去判断了
if len(activity.BrandIdList) == 0 && len(activity.ClassIdList) == 0 { fmt.Println(activity.BrandIds)
fmt.Println(activity.ClassIds)
if activity.BrandIds == "" && activity.ClassIds == "" {
hasActivity = true
goto INFO goto INFO
} }
if as.CheckClass(checkData.ClassId, activity) { if as.CheckClass(checkData.ClassId, activity) {
......
package service package service
import ( import (
"github.com/gin-gonic/gin" "go_sku_server/model"
"github.com/gomodule/redigo/redis" "go_sku_server/pkg/common"
"github.com/iancoleman/orderedmap"
"github.com/syyongx/php2go" "github.com/gin-gonic/gin"
"github.com/tidwall/gjson" "github.com/gomodule/redigo/redis"
"go_sku_server/model" "github.com/iancoleman/orderedmap"
"go_sku_server/pkg/common" "github.com/syyongx/php2go"
) "github.com/tidwall/gjson"
)
//自营公共函数类
/* //自营公共函数类
计算单个sku总锁库数量 /*
*/ 计算单个sku总锁库数量
func (qs *ZiyingService) skuLockNum(c *redis.Conn, goodsId string) int64 { */
reply, err := redis.Values((*c).Do("hvals", "Self_StockLock"+goodsId)) func (qs *ZiyingService) skuLockNum(c *redis.Conn, goodsId string) int64 {
if err != nil { reply, err := redis.Values((*c).Do("hvals", "Self_StockLock"+goodsId))
return 0 if err != nil {
} return 0
}
var albums []int64
if err := redis.ScanSlice(reply, &albums); err != nil { var albums []int64
return 0 if err := redis.ScanSlice(reply, &albums); err != nil {
} return 0
if len(albums) == 0 { }
return 0 if len(albums) == 0 {
} else { return 0
var all int64 = 0 } else {
for _, n := range albums { var all int64 = 0
all = all + n for _, n := range albums {
} all = all + n
return all }
} return all
} }
}
/*
获取自营活动价 /*
*/ 获取自营活动价
func (qs *ZiyingService) ActivityPrice(ctx *gin.Context, SkuInfo string) *orderedmap.OrderedMap { */
data := qs.HDActivityPrice(SkuInfo) func (qs *ZiyingService) ActivityPrice(ctx *gin.Context, SkuInfo string) *orderedmap.OrderedMap {
if data != nil { data := qs.HDActivityPrice(SkuInfo)
return data if data != nil {
} return data
return nil }
} return nil
}
//获取活动相关信息
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{ //去判断是否有活动(促销打折活动和满赠活动)
SupplierId: 10000, checkData := model.ActivityCheckData{
BrandId: int(gjson.Get(skuInfo, "brand_id").Int()), SupplierId: 10000,
ClassId: int(gjson.Get(skuInfo, "class_id2").Int()), BrandId: int(gjson.Get(skuInfo, "brand_id").Int()),
} GoodsId: gjson.Get(skuInfo, "goods_id").String(),
var activityService ActivityService ClassId: int(gjson.Get(skuInfo, "class_id2").Int()),
priceActivity, giftActivity = activityService.GetActivityData(checkData) }
return var activityService ActivityService
} priceActivity, giftActivity = activityService.GetActivityData(checkData)
return
/* }
计算活动价
/*
ac_type说明: 0 没有活动 计算活动价
活动名称 ac_type 类型
自营系数 6 自营 ac_type说明: 0 没有活动
折扣(系数)活动 10 自营/联营 活动名称 ac_type 类型
自营系数 6 自营
*/ 折扣(系数)活动 10 自营/联营
func (qs *ZiyingService) HDActivityPrice(SkuInfo string) *orderedmap.OrderedMap {
priceActivity, giftActivity := qs.GetActivity(SkuInfo) */
ladderPriceArr := gjson.Get(SkuInfo, "ladder_price").Array() func (qs *ZiyingService) HDActivityPrice(SkuInfo string) *orderedmap.OrderedMap {
A := orderedmap.New() priceActivity, giftActivity := qs.GetActivity(SkuInfo)
//先去判断价格活动 ladderPriceArr := gjson.Get(SkuInfo, "ladder_price").Array()
if priceActivity.HasActivity && len(ladderPriceArr) > 0 { A := orderedmap.New()
ratio := priceActivity.Ratio //先去判断价格活动
ladderType := make([]model.LadderPrice, 0) if priceActivity.HasActivity && len(ladderPriceArr) > 0 {
for _, v := range ladderPriceArr { ratio := priceActivity.Ratio
priceCn := v.Get("price_cn").Float() ladderType := make([]model.LadderPrice, 0)
priceAc := php2go.Round(priceCn*ratio/100*10000) / 10000 for _, v := range ladderPriceArr {
ladderType = append(ladderType, model.LadderPrice{ priceCn := v.Get("price_cn").Float()
Purchases: v.Get("purchases").Int(), priceAc := php2go.Round(priceCn*ratio/100*10000) / 10000
PriceUs: v.Get("price_us").Float(), ladderType = append(ladderType, model.LadderPrice{
PriceCn: priceCn, Purchases: v.Get("purchases").Int(),
PriceAc: priceAc, PriceUs: v.Get("price_us").Float(),
}) PriceCn: priceCn,
} PriceAc: priceAc,
})
A.Set("activity_info", priceActivity) }
A.Set("ladder_price", ladderType) A.Set("activity_info", priceActivity)
A.Set("ratio", ratio)
A.Set("ac_type", 10) A.Set("ladder_price", ladderType)
} A.Set("ratio", ratio)
A.Set("ac_type", 10)
//再去判断满赠活动 }
if giftActivity.HasActivity {
A.Set("has_gift_activity", 1) //再去判断满赠活动
A.Set("gift_activity", giftActivity) if giftActivity.HasActivity {
} A.Set("has_gift_activity", 1)
//其中一类活动不允许优惠券,这个商品就不允许使用优惠券 A.Set("gift_activity", giftActivity)
var allowCoupon int }
if priceActivity.HasActivity && priceActivity.AllowCoupon == 2 { //其中一类活动不允许优惠券,这个商品就不允许使用优惠券
allowCoupon = 2 var allowCoupon int
A.Set("allow_coupon", allowCoupon) if priceActivity.HasActivity && priceActivity.AllowCoupon == 2 {
} allowCoupon = 2
if giftActivity.HasActivity && giftActivity.AllowCoupon == 2 { A.Set("allow_coupon", allowCoupon)
allowCoupon = 2 }
A.Set("allow_coupon", allowCoupon) if giftActivity.HasActivity && giftActivity.AllowCoupon == 2 {
} allowCoupon = 2
return A A.Set("allow_coupon", allowCoupon)
} }
return A
/* }
获取当前锁住的库存
*/ /*
func (qs *ZiyingService) HDGoodsLimit(SkuID string, Stock string, c *redis.Conn) *orderedmap.OrderedMap { 获取当前锁住的库存
*/
GoodsLimit, _ := redis.String((*c).Do("get", "Self_GoodsLimit_"+SkuID)) func (qs *ZiyingService) HDGoodsLimit(SkuID string, Stock string, c *redis.Conn) *orderedmap.OrderedMap {
if GoodsLimit == "" {
return nil GoodsLimit, _ := redis.String((*c).Do("get", "Self_GoodsLimit_"+SkuID))
} if GoodsLimit == "" {
start_time := gjson.Get(GoodsLimit, "start_time").Int() return nil
end_time := gjson.Get(GoodsLimit, "end_time").Int() }
buy_stock := gjson.Get(GoodsLimit, "buy_stock").Float() start_time := gjson.Get(GoodsLimit, "start_time").Int()
ac_stock := gjson.Get(GoodsLimit, "ac_stock").Float() end_time := gjson.Get(GoodsLimit, "end_time").Int()
schedule := gjson.Get(GoodsLimit, "schedule").Float() buy_stock := gjson.Get(GoodsLimit, "buy_stock").Float()
allow_coupon := gjson.Get(GoodsLimit, "allow_coupon").Int() ac_stock := gjson.Get(GoodsLimit, "ac_stock").Float()
schedule := gjson.Get(GoodsLimit, "schedule").Float()
if start_time < php2go.Time() && end_time > php2go.Time() { allow_coupon := gjson.Get(GoodsLimit, "allow_coupon").Int()
buy := buy_stock / ac_stock * 100
schedule := common.MyRound(buy+schedule, 2) if start_time < php2go.Time() && end_time > php2go.Time() {
if schedule < 100 { buy := buy_stock / ac_stock * 100
A := orderedmap.New() schedule := common.MyRound(buy+schedule, 2)
//拼接梯度价格 if schedule < 100 {
ladder_price_arr := gjson.Get(GoodsLimit, "ac_price").Array() A := orderedmap.New()
ladderType := make([]model.LadderPrice, 0) //拼接梯度价格
for _, v := range ladder_price_arr { ladder_price_arr := gjson.Get(GoodsLimit, "ac_price").Array()
ladderType = append(ladderType, model.LadderPrice{ ladderType := make([]model.LadderPrice, 0)
Purchases: v.Get("purchases").Int(), for _, v := range ladder_price_arr {
PriceCn: v.Get("price_cn").Float(), ladderType = append(ladderType, model.LadderPrice{
PriceAc: v.Get("price_ac").Float(), Purchases: v.Get("purchases").Int(),
}) PriceCn: v.Get("price_cn").Float(),
} PriceAc: v.Get("price_ac").Float(),
})
now_stock := ac_stock * ((100 - schedule) / 100) }
A.Set("ac_type", 1) now_stock := ac_stock * ((100 - schedule) / 100)
A.Set("ac_id", gjson.Get(GoodsLimit, "id").Int())
A.Set("ladder_price", ladderType) A.Set("ac_type", 1)
A.Set("ac_stock", ac_stock) A.Set("ac_id", gjson.Get(GoodsLimit, "id").Int())
A.Set("stock", now_stock) A.Set("ladder_price", ladderType)
A.Set("schedule", schedule) A.Set("ac_stock", ac_stock)
A.Set("activity_end_time", end_time) A.Set("stock", now_stock)
if allow_coupon > 0 { A.Set("schedule", schedule)
A.Set("allow_coupon", allow_coupon) A.Set("activity_end_time", end_time)
} else { if allow_coupon > 0 {
A.Set("allow_coupon", 1) A.Set("allow_coupon", allow_coupon)
} } else {
//活动库存大于当前可售库存,强制结束活动 A.Set("allow_coupon", 1)
if now_stock > common.MyFloat64(Stock) || now_stock == 0 { }
return nil //活动库存大于当前可售库存,强制结束活动
} if now_stock > common.MyFloat64(Stock) || now_stock == 0 {
return A return nil
} }
return A
} }
return nil
} }
return nil
}
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