Commit 499520f5 by 杨树贤

Merge branch 'ysx-魔方活动价判断优先级-20230928' into dev

parents c74b426d 69fd239d
......@@ -5,6 +5,8 @@ import (
"fmt"
"go_sku_server/model"
"go_sku_server/pkg/gredis"
"go_sku_server/service/sorter"
"sort"
"strconv"
"strings"
"time"
......@@ -30,6 +32,8 @@ func (as *ActivityService) GetActivityData(checkData model.ActivityCheckData) (p
if err != nil {
fmt.Println(err)
}
//对活动进行创建时间逆序排序,因为要以创建时间靠后的优先级最高
sort.Sort(sorter.ActivitySorter(activities))
if len(activities) != 0 {
priceActivity = as.GetPriceActivity(checkData, activities)
}
......@@ -140,6 +144,8 @@ func (as *ActivityService) GetPriceActivity(checkData model.ActivityCheckData, a
//判断商品名称是否在redis
redisKey := "lie_activity_and_coupon_sku_" + strconv.Itoa(activity.ActivityId)
exists, _ := redis.Bool(redisConn.Do("hexists", redisKey, checkData.GoodsName))
//fmt.Println(checkData.GoodsName)
//fmt.Println(exists)
if exists {
hasActivity = true
goto INFO
......@@ -161,12 +167,23 @@ func (as *ActivityService) GetPriceActivity(checkData model.ActivityCheckData, a
} else if checkData.SupplierId == 10000 {
//自营活动特殊判断
//判断活动指定的渠道编码,品牌,分类id,如果都为空,那么这个活动可以理解为整个供应商了,上面的排除已经会提前去判断了
if activity.StandardBrandIds == "" && activity.ClassIds == "" {
//fmt.Println(activity.ClassIds)
//fmt.Println(activity.UseType)
if activity.ClassIds != "" {
if !as.CheckClass(checkData.ClassId, activity) {
continue
}
}
if activity.UseType == 2 {
//判断商品名称是否在redis
redisKey := "lie_activity_and_coupon_sku_" + strconv.Itoa(activity.ActivityId)
exists, _ := redis.Bool(redisConn.Do("hexists", redisKey, checkData.GoodsName))
if exists {
hasActivity = true
goto INFO
}
if as.CheckClass(checkData.ClassId, activity) {
} else {
//不等于2都是根据品牌来,因为老数据以前也只有品牌,0和1都是品牌
//品牌不为空,还要去判断品牌,是同时满足的关系
if activity.StandardBrandIds != "" {
//判断是否是搞活动的品牌
......
......@@ -266,7 +266,7 @@ func (ls *LyService) GetCoefficientAndPrice(sku model.LySku) model.LySku {
return sku
}
priceService := PriceService{}
flag := 0
//flag := 0
var data []model.LadderPrice
var originalPrice []model.OriginPrice
sort.Sort(sorter.OriginPriceSorter(sku.OriginalPrice))
......@@ -316,19 +316,20 @@ func (ls *LyService) GetCoefficientAndPrice(sku model.LySku) model.LySku {
if (sku.GoodsType == 1 || sku.GoodsType == 2 || sku.GoodsType == 6) && sku.AcType > 1 && sku.Ratio > 0 {
tempAcPrice := c.MyRound(c.MulFloat(price.PriceCn, sku.Ratio/100), 4)
data[key].PriceAc = tempAcPrice
data[key].PriceAcUs = c.MyRound(c.MulFloat(price.PriceUs, sku.RatioUs/100), 4)
priceAcUs := c.MyRound(c.MulFloat(price.PriceUs, sku.RatioUs/100), 4)
data[key].PriceAcUs = priceAcUs
//优惠价后等于0,就代表没有搞活动
if tempAcPrice <= 0 {
if tempAcPrice <= 0 && priceAcUs <= 0 {
sku.AcType = 0
}
//价格与原价一样
if data[key].PriceCn == tempAcPrice && key < 2 {
flag++
if flag >= 2 || (len(ladderPrice) < 2) {
sku.AcType = 0
}
}
//if data[key].PriceCn == tempAcPrice && key < 2 {
// flag++
// if flag >= 2 || (len(ladderPrice) < 2) {
// sku.AcType = 0
// }
//}
}
}
} else {
......@@ -465,12 +466,13 @@ func (ls *LyService) GetCoefficientAndPrice(sku model.LySku) model.LySku {
if (sku.GoodsType == 1 || sku.GoodsType == 2 || sku.GoodsType == 6) && sku.AcType > 1 && sku.Ratio > 0 {
priceAc := c.MyRound(c.MulFloat(data[key].PriceCn, (sku.Ratio/100)), 4)
data[key].PriceAc = priceAc
var priceAcUs float64
if sku.RatioUs > 0 {
priceAcUs := c.MyRound(c.MulFloat(data[key].PriceUs, (sku.RatioUs/100)), 4)
priceAcUs = c.MyRound(c.MulFloat(data[key].PriceUs, (sku.RatioUs/100)), 4)
data[key].PriceAcUs = priceAcUs
}
if priceAc <= 0 {
if priceAc <= 0 && priceAcUs <= 0 {
sku.AcType = 0
break
} else {
......@@ -481,17 +483,17 @@ func (ls *LyService) GetCoefficientAndPrice(sku model.LySku) model.LySku {
}
//为什么$kp < 2,如果第一阶梯或第二阶梯价格和活动价一样,就不输出活动价了
//活动价都是有样式的和平时不一样,如果价格一样,但是样子是活动价,客户会迷惑,所以不输出即可,保持原来的样式
if data[key].PriceCn == priceAc && key < 2 {
flag++
if flag >= 2 {
sku.AcType = 0
}
if len(data) > 1 {
if data[1].PriceCn == 0 {
sku.AcType = 0
}
}
}
//if data[key].PriceCn == priceAc && key < 2 {
// flag++
// if flag >= 2 {
// sku.AcType = 0
// }
// if len(data) > 1 {
// if data[1].PriceCn == 0 {
// sku.AcType = 0
// }
// }
//}
}
}
//判断原始价格有变化,那就要覆盖
......
package service
import (
"fmt"
"github.com/gomodule/redigo/redis"
"github.com/syyongx/php2go"
"github.com/tidwall/gjson"
......@@ -94,7 +93,7 @@ func (ps *PriceService) GenerateLadderPrice(sku model.LySku) model.LySku {
if brandIds != "" {
hasSpecialCheck = true
standardBrandIdList := strings.Split(brandIds, ",")
fmt.Println(standardBrandIdList)
//fmt.Println(standardBrandIdList)
standardBrandId := strconv.Itoa(sku.StandardBrand.StandardBrandId)
//找到有对应的品牌,那么优先级肯定是最高的了
if php2go.InArray(standardBrandId, standardBrandIdList) {
......
package sorter
import "go_sku_server/model"
// 阶梯价格排序算法
type ActivitySorter []model.Activity
func (a ActivitySorter) Len() int {
return len(a)
}
func (a ActivitySorter) Swap(i, j int) {
a[i], a[j] = a[j], a[i]
}
func (a ActivitySorter) Less(i, j int) bool {
return a[j].AddTime < a[i].AddTime
}
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