Commit 932a1cb0 by hcy

Merge branch 'master' into hcy/2025.9.10-香港自营

parents c36855c9 b4759a26
...@@ -5,3 +5,10 @@ username = "ichunt" ...@@ -5,3 +5,10 @@ username = "ichunt"
password = "huntmon6699" password = "huntmon6699"
database = ichunt database = ichunt
maxPoolSize=8000 maxPoolSize=8000
[pre_sku_mongo]
host = 192.168.1.237:27017
username = "ichunt"
password = "huntmon6699"
database = ichunt
maxPoolSize=8000
\ No newline at end of file
...@@ -46,6 +46,8 @@ type Activity struct { ...@@ -46,6 +46,8 @@ type Activity struct {
CurrencyUs int `json:"currency_us"` CurrencyUs int `json:"currency_us"`
UseType int `json:"use_type"` UseType int `json:"use_type"`
SignUrl string `json:"sign_url"` SignUrl string `json:"sign_url"`
Source string `json:"source"`
SourceList []string `json:"source_list"`
} }
type ActivityItem struct { type ActivityItem struct {
...@@ -70,4 +72,5 @@ type ActivityCheckData struct { ...@@ -70,4 +72,5 @@ type ActivityCheckData struct {
Canal string Canal string
ClassId int ClassId int
OrgId int OrgId int
Source int
} }
...@@ -243,7 +243,7 @@ func InitSkuData(sku string) (data LySku) { ...@@ -243,7 +243,7 @@ func InitSkuData(sku string) (data LySku) {
isExpire := gjson.Get(sku, "is_expire").Int() isExpire := gjson.Get(sku, "is_expire").Int()
data.IsExpire = int(isExpire) data.IsExpire = int(isExpire)
data.IsExpire = 0 //data.IsExpire = 0
hkDeliveryTime := gjson.Get(sku, "hk_delivery_time").String() hkDeliveryTime := gjson.Get(sku, "hk_delivery_time").String()
data.HkDeliveryTime = hkDeliveryTime data.HkDeliveryTime = hkDeliveryTime
......
package model
import "gopkg.in/mgo.v2/bson"
// PrevSku 对应prev_sku集合的数据结构
type PrevSku struct {
ID bson.ObjectId `bson:"_id"`
SkuId int64 `bson:"sku_id"`
SpuId int64 `bson:"spu_id"`
SupplierId int64 `bson:"supplier_id"`
}
package config package config
type MongoDbDatabase struct { type MongoDbDatabase struct {
Host string Host string
UserName string UserName string
...@@ -9,17 +8,21 @@ type MongoDbDatabase struct { ...@@ -9,17 +8,21 @@ type MongoDbDatabase struct {
MaxPoolSize string MaxPoolSize string
} }
func BuildMongoDbConfgs() map[string]MongoDbDatabase {
func BuildMongoDbConfgs () map[string]MongoDbDatabase{
return map[string]MongoDbDatabase{ return map[string]MongoDbDatabase{
"default" : { "default": {
Host:Get("mongo.host").String(), Host: Get("mongo.host").String(),
UserName:Get("mongo.username").String(), UserName: Get("mongo.username").String(),
Password:Get("mongo.password").String(), Password: Get("mongo.password").String(),
Database:Get("mongo.database").String(), Database: Get("mongo.database").String(),
MaxPoolSize:Get("mongo.maxPoolSize").String(), MaxPoolSize: Get("mongo.maxPoolSize").String(),
},
"pre_sku": {
Host: Get("pre_sku_mongo.host").String(),
UserName: Get("pre_sku_mongo.username").String(),
Password: Get("pre_sku_mongo.password").String(),
Database: Get("pre_sku_mongo.database").String(),
MaxPoolSize: Get("pre_sku_mongo.maxPoolSize").String(),
}, },
} }
} }
...@@ -49,74 +49,6 @@ func (as *ActivityService) GetActivityData(checkData model.ActivityCheckData) (p ...@@ -49,74 +49,6 @@ func (as *ActivityService) GetActivityData(checkData model.ActivityCheckData) (p
return return
} }
// 获取满赠活动信息
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.Status != 1 {
continue
}
//判断时间是否过期
if activity.StartTime > nowTimestamp || activity.EndTime < nowTimestamp {
continue
}
//如果是整个供应商搞活动,则直接返回系数
if activity.EntireSupplierActivity {
hasActivity = true
goto INFO
}
//判断是否是排除的sku或者品牌,如果是的话,直接返回没活动
if as.CheckExcludeSku(checkData.GoodsId, activity) || as.CheckExcludeBrand(checkData.BrandId, activity) {
continue
}
//判断是否是搞活动的品牌
if as.CheckBrand(checkData.BrandId, activity) {
hasActivity = true
goto INFO
}
//如果是专卖,则要去判断canal,如果是自营,则去判断分类
if checkData.SupplierId == 17 {
if as.CheckCanal(checkData.Canal, activity) {
hasActivity = true
goto INFO
}
} else {
if as.CheckClass(checkData.ClassId, activity) {
hasActivity = true
goto INFO
}
}
INFO:
if hasActivity {
for key, item := range activity.ItemList {
activity.ItemList[key].Content = "订单满" + gconv.String(item.Amount) + "元赠" +
gconv.String(item.ItemName) + "X" + gconv.String(item.Num) + "" + item.Remark
}
giftActivity.ActivityName = activity.ActivityName
giftActivity.ActivityId = activity.ActivityId
giftActivity = model.GiftActivity{
CanAdminOrder: activity.CanAdminOrder,
ItemList: activity.ItemList,
ActivityCommon: model.ActivityCommon{
HasActivity: hasActivity,
ActivityId: activity.ActivityId,
ActivityName: activity.ActivityName,
AllowCoupon: activity.AllowCoupon,
UserScope: activity.UserScope,
},
}
break
}
}
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) {
redisConn := gredis.Conn("default_r") redisConn := gredis.Conn("default_r")
defer redisConn.Close() defer redisConn.Close()
...@@ -140,6 +72,10 @@ func (as *ActivityService) GetPriceActivity(checkData model.ActivityCheckData, a ...@@ -140,6 +72,10 @@ func (as *ActivityService) GetPriceActivity(checkData model.ActivityCheckData, a
if as.CheckExcludeSku(checkData.GoodsId, activity) || as.CheckExcludeStandardBrand(checkData.StandardBrandId, activity) { if as.CheckExcludeSku(checkData.GoodsId, activity) || as.CheckExcludeStandardBrand(checkData.StandardBrandId, activity) {
continue continue
} }
//checkSource
if !as.CheckSource(checkData.Source, activity) {
continue
}
//如果是专卖,则要去判断canal,如果是自营,则去判断分类 //如果是专卖,则要去判断canal,如果是自营,则去判断分类
if checkData.SupplierId == 17 { if checkData.SupplierId == 17 {
...@@ -175,8 +111,6 @@ func (as *ActivityService) GetPriceActivity(checkData model.ActivityCheckData, a ...@@ -175,8 +111,6 @@ func (as *ActivityService) GetPriceActivity(checkData model.ActivityCheckData, a
} else if checkData.SupplierId == 10000 { } else if checkData.SupplierId == 10000 {
//自营活动特殊判断 //自营活动特殊判断
//fmt.Println(activity.ClassIds)
//fmt.Println(activity.UseType)
if activity.ClassIds != "" { if activity.ClassIds != "" {
if !as.CheckClass(checkData.ClassId, activity) { if !as.CheckClass(checkData.ClassId, activity) {
continue continue
...@@ -275,10 +209,7 @@ func (as *ActivityService) CheckExcludeBrand(brandId int, activity model.Activit ...@@ -275,10 +209,7 @@ func (as *ActivityService) CheckExcludeBrand(brandId int, activity model.Activit
activity.ExcludeBrandIdList = strings.Split(activity.ExcludeBrandIds, ",") activity.ExcludeBrandIdList = strings.Split(activity.ExcludeBrandIds, ",")
brandIdStr := gconv.String(brandId) brandIdStr := gconv.String(brandId)
//如果存在于有活动价的品牌,就是有折扣活动了 //如果存在于有活动价的品牌,就是有折扣活动了
if php2go.InArray(brandIdStr, activity.ExcludeBrandIdList) { return php2go.InArray(brandIdStr, activity.ExcludeBrandIdList)
return true
}
return false
} }
// 检查是否属于被排除的标准品牌 // 检查是否属于被排除的标准品牌
...@@ -290,10 +221,7 @@ func (as *ActivityService) CheckExcludeStandardBrand(standardBrandId int, activi ...@@ -290,10 +221,7 @@ func (as *ActivityService) CheckExcludeStandardBrand(standardBrandId int, activi
activity.ExcludeStandardBrandIdList = strings.Split(activity.ExcludeStandardBrandIds, ",") activity.ExcludeStandardBrandIdList = strings.Split(activity.ExcludeStandardBrandIds, ",")
standardBrandIdStr := gconv.String(standardBrandId) standardBrandIdStr := gconv.String(standardBrandId)
//如果存在于有活动价的品牌,就是有折扣活动了 //如果存在于有活动价的品牌,就是有折扣活动了
if php2go.InArray(standardBrandIdStr, activity.ExcludeStandardBrandIdList) { return php2go.InArray(standardBrandIdStr, activity.ExcludeStandardBrandIdList)
return true
}
return false
} }
// 检查是否属于被排除的sku // 检查是否属于被排除的sku
...@@ -304,10 +232,7 @@ func (as *ActivityService) CheckExcludeSku(skuId string, activity model.Activity ...@@ -304,10 +232,7 @@ func (as *ActivityService) CheckExcludeSku(skuId string, activity model.Activity
//先去判断品牌 //先去判断品牌
activity.ExcludeSkuIdList = strings.Split(activity.ExcludeSkuIds, ",") activity.ExcludeSkuIdList = strings.Split(activity.ExcludeSkuIds, ",")
//如果存在于有活动价的品牌,就是有折扣活动了 //如果存在于有活动价的品牌,就是有折扣活动了
if php2go.InArray(skuId, activity.ExcludeSkuIdList) { return php2go.InArray(skuId, activity.ExcludeSkuIdList)
return true
}
return false
} }
// 检查是否属于活动分类(只有自营需要判断) // 检查是否属于活动分类(只有自营需要判断)
...@@ -319,10 +244,7 @@ func (as *ActivityService) CheckClass(classId int, activity model.Activity) bool ...@@ -319,10 +244,7 @@ func (as *ActivityService) CheckClass(classId int, activity model.Activity) bool
activity.ClassIdList = strings.Split(activity.ClassIds, ",") activity.ClassIdList = strings.Split(activity.ClassIds, ",")
classIdStr := gconv.String(classId) classIdStr := gconv.String(classId)
//如果存在于有活动价的品牌,就是有折扣活动了 //如果存在于有活动价的品牌,就是有折扣活动了
if php2go.InArray(classIdStr, activity.ClassIdList) { return php2go.InArray(classIdStr, activity.ClassIdList)
return true
}
return false
} }
// 检查是否属于活动品牌 // 检查是否属于活动品牌
...@@ -334,10 +256,7 @@ func (as *ActivityService) CheckBrand(brandId int, activity model.Activity) bool ...@@ -334,10 +256,7 @@ func (as *ActivityService) CheckBrand(brandId int, activity model.Activity) bool
activity.BrandIdList = strings.Split(activity.BrandIds, ",") activity.BrandIdList = strings.Split(activity.BrandIds, ",")
brandIdStr := gconv.String(brandId) brandIdStr := gconv.String(brandId)
//如果存在于有活动价的品牌,就是有折扣活动了 //如果存在于有活动价的品牌,就是有折扣活动了
if php2go.InArray(brandIdStr, activity.BrandIdList) { return php2go.InArray(brandIdStr, activity.BrandIdList)
return true
}
return false
} }
// 检测是否属于活动标准品牌 // 检测是否属于活动标准品牌
...@@ -349,10 +268,7 @@ func (as *ActivityService) CheckStandardBrand(standardBrandId int, activity mode ...@@ -349,10 +268,7 @@ func (as *ActivityService) CheckStandardBrand(standardBrandId int, activity mode
activity.StandardBrandIdList = strings.Split(activity.StandardBrandIds, ",") activity.StandardBrandIdList = strings.Split(activity.StandardBrandIds, ",")
standardBrandIdStr := gconv.String(standardBrandId) standardBrandIdStr := gconv.String(standardBrandId)
//如果存在于有活动价的品牌,就是有折扣活动了 //如果存在于有活动价的品牌,就是有折扣活动了
if php2go.InArray(standardBrandIdStr, activity.StandardBrandIdList) { return php2go.InArray(standardBrandIdStr, activity.StandardBrandIdList)
return true
}
return false
} }
// 检查是否属于供应商渠道 // 检查是否属于供应商渠道
...@@ -363,8 +279,23 @@ func (as *ActivityService) CheckCanal(canal string, activity model.Activity) boo ...@@ -363,8 +279,23 @@ func (as *ActivityService) CheckCanal(canal string, activity model.Activity) boo
//先去判断品牌 //先去判断品牌
activity.CanalList = strings.Split(activity.Canals, ",") activity.CanalList = strings.Split(activity.Canals, ",")
//如果存在于有活动价的品牌,就是有折扣活动了 //如果存在于有活动价的品牌,就是有折扣活动了
if php2go.InArray(canal, activity.CanalList) { return php2go.InArray(canal, activity.CanalList)
}
// 检查来源是否有配置,有配置的话是否符合
func (as *ActivityService) CheckSource(source int, activity model.Activity) bool {
if source == 0 {
source = 1
}
//如果source为空,则默认为所有来源
if activity.Source == "" {
return true return true
} }
return false //先去判断品牌
activity.SourceList = strings.Split(activity.Source, ",")
sourceStr := gconv.String(source)
// fmt.Println(sourceStr)
// fmt.Println(activity.SourceList)
//如果存在于有活动价的品牌,就是有折扣活动了
return php2go.InArray(sourceStr, activity.SourceList)
} }
...@@ -2,15 +2,17 @@ package service ...@@ -2,15 +2,17 @@ package service
import ( import (
"encoding/json" "encoding/json"
"github.com/iancoleman/orderedmap"
"go_sku_server/pkg/logger" "go_sku_server/pkg/logger"
"go_sku_server/pkg/mongo" "go_sku_server/pkg/mongo"
"strconv"
"strings"
"github.com/iancoleman/orderedmap"
"gopkg.in/mgo.v2" "gopkg.in/mgo.v2"
"gopkg.in/mgo.v2/bson" "gopkg.in/mgo.v2/bson"
"strconv"
) )
//获取Spu的属性 // 获取Spu的属性
func (ls *LyService) GetSpuAttr(spuId string) (attrsResult interface{}) { func (ls *LyService) GetSpuAttr(spuId string) (attrsResult interface{}) {
var spuAttr SpuAttr var spuAttr SpuAttr
var attrsList []interface{} var attrsList []interface{}
...@@ -26,7 +28,17 @@ func (ls *LyService) GetSpuAttr(spuId string) (attrsResult interface{}) { ...@@ -26,7 +28,17 @@ func (ls *LyService) GetSpuAttr(spuId string) (attrsResult interface{}) {
//fmt.Println(spuAttr.AttrsExtend) //fmt.Println(spuAttr.AttrsExtend)
//如果有attrs_extend,就去取attrs_extend //如果有attrs_extend,就去取attrs_extend
if len(spuAttr.AttrsExtend) != 0 { if len(spuAttr.AttrsExtend) != 0 {
return spuAttr.AttrsExtend //便利AttrsExtend的值
for _, value := range spuAttr.AttrsExtend {
data := make(map[string]interface{})
data["attr_name"] = value.AttrName
//€符号全部替换为逗号
data["attr_value"] = strings.ReplaceAll(value.AttrValue, "€", ",")
data["attr_unit"] = value.AttrUnit
attrsList = append(attrsList, data)
attrsResult = attrsList
}
return attrsResult
} else if spuAttr.Attrs != "" { } else if spuAttr.Attrs != "" {
o := orderedmap.New() o := orderedmap.New()
err := json.Unmarshal([]byte(spuAttr.Attrs), &o) err := json.Unmarshal([]byte(spuAttr.Attrs), &o)
......
...@@ -8,6 +8,7 @@ import ( ...@@ -8,6 +8,7 @@ import (
"go_sku_server/pkg/mongo" "go_sku_server/pkg/mongo"
"go_sku_server/service/sorter" "go_sku_server/service/sorter"
"sort" "sort"
"strconv"
"sync" "sync"
"gopkg.in/mgo.v2" "gopkg.in/mgo.v2"
...@@ -38,7 +39,10 @@ type Power struct { ...@@ -38,7 +39,10 @@ type Power struct {
func (ls *LyService) LyGoodsDetail(ctx *gin.Context, goodsIds []string, ch chan sync.Map) { func (ls *LyService) LyGoodsDetail(ctx *gin.Context, goodsIds []string, ch chan sync.Map) {
redisConn := gredis.Conn("search_r") redisConn := gredis.Conn("search_r")
redisConnSpu := gredis.Conn("spu") redisConnSpu := gredis.Conn("spu")
// 连接prev_sku MongoDB
prevSkuMongo := mongo.Conn("pre_sku")
defer func() { defer func() {
prevSkuMongo.Close()
redisConn.Close() redisConn.Close()
redisConnSpu.Close() redisConnSpu.Close()
}() }()
...@@ -63,14 +67,40 @@ func (ls *LyService) LyGoodsDetail(ctx *gin.Context, goodsIds []string, ch chan ...@@ -63,14 +67,40 @@ func (ls *LyService) LyGoodsDetail(ctx *gin.Context, goodsIds []string, ch chan
GoodsRes := sync.Map{} GoodsRes := sync.Map{}
for goodsId, skuStr := range skuArr { for goodsId, skuStr := range skuArr {
//初始化有序map,拼接data数据,就是从redis取出初始数据
sku := model.InitSkuData(skuStr)
var spu string
if skuStr == "" { if skuStr == "" {
// 如果redis中找不到sku数据,尝试从prev_sku MongoDB中查找
skuId, err := strconv.ParseInt(goodsId, 10, 64)
if err != nil {
GoodsRes.Store(goodsId, false) GoodsRes.Store(goodsId, false)
continue continue
} }
//初始化有序map,拼接data数据,就是从redis取出初始数据 var prevSku model.PrevSku
sku := model.InitSkuData(skuStr) err = prevSkuMongo.DB("ichunt").C("prev_sku").Find(bson.M{"sku_id": skuId}).One(&prevSku)
if err != nil {
// 如果在prev_sku中也找不到,则保持默认值
GoodsRes.Store(goodsId, false)
continue
}
// 根据找到的spu_id去spu的redis中查找
spuIdStr := strconv.FormatInt(prevSku.SpuId, 10)
spuStr, _ := redis.String(redisConnSpu.Do("HGET", "spu", spuIdStr))
if spuStr == "" {
// 如果spu缓存也没有,保持默认值
GoodsRes.Store(goodsId, false)
continue
}
sku.SupplierId = prevSku.SupplierId
sku.SpuId = spuIdStr
spu = spuStr
} else {
spu = spuList[sku.SpuId]
}
sku.GoodsId = goodsId sku.GoodsId = goodsId
spu := spuList[sku.SpuId]
//读取包装字段的缓存(分别是DGK,avnet,mro) //读取包装字段的缓存(分别是DGK,avnet,mro)
if sku.SupplierId == 7 || sku.SupplierId == 13 || sku.SupplierId == 1688 || sku.SupplierId == 17 { if sku.SupplierId == 7 || sku.SupplierId == 13 || sku.SupplierId == 1688 || sku.SupplierId == 17 {
//sku_raw_map哪里写入(成意写的) //sku_raw_map哪里写入(成意写的)
...@@ -79,12 +109,12 @@ func (ls *LyService) LyGoodsDetail(ctx *gin.Context, goodsIds []string, ch chan ...@@ -79,12 +109,12 @@ func (ls *LyService) LyGoodsDetail(ctx *gin.Context, goodsIds []string, ch chan
} }
sku = ls.GetGoodsImages(sku, spu) sku = ls.GetGoodsImages(sku, spu)
sku = ls.GetPdf(sku, spu) sku = ls.GetPdf(sku, spu)
//用spuInfo补全信息
sku = ls.CombineSup(sku, spu)
// 2023.11.20 DGK商品的包装若为“Tape & Reel (TR)”,则递增量=起订量 // 2023.11.20 DGK商品的包装若为“Tape & Reel (TR)”,则递增量=起订量
if sku.SupplierId == 7 && sku.Packing == "Tape & Reel (TR)" { if sku.SupplierId == 7 && sku.Packing == "Tape & Reel (TR)" {
sku.Multiple = sku.Moq sku.Multiple = sku.Moq
} }
//获取商品名称 //获取商品名称
//1688就是mro的sku spuName和GoodsName不是一个东西,不能公用 //1688就是mro的sku spuName和GoodsName不是一个东西,不能公用
if sku.GoodsName != "" && (sku.SupplierId == 1688 || sku.OrgId == 3) { if sku.GoodsName != "" && (sku.SupplierId == 1688 || sku.OrgId == 3) {
...@@ -182,16 +212,13 @@ func (ls *LyService) LyGoodsDetail(ctx *gin.Context, goodsIds []string, ch chan ...@@ -182,16 +212,13 @@ func (ls *LyService) LyGoodsDetail(ctx *gin.Context, goodsIds []string, ch chan
//case为0是为了兼容价格体系之前的价格 //case为0是为了兼容价格体系之前的价格
case 0: case 0:
case 1: case 1:
//如果是寄售的,也不走价格体系 //这里猎芯和寄售都是走同一套的价格体系了
if sku.Source != 12 {
//这里猎芯和华云都是走同一套的价格体系了
//获取系数和价格 //获取系数和价格
sku = ls.GetCoefficientAndPrice(sku) sku = ls.GetCoefficientAndPrice(sku)
//获取自定义价格后的阶梯价 //获取自定义价格后的阶梯价
customPriceService := CustomPrice{} customPriceService := CustomPrice{}
sku.CustomPriceList, _ = customPriceService.getCustomPriceList(sku) sku.CustomPriceList, _ = customPriceService.getCustomPriceList(sku)
sku = priceService.GetActivityPrice(sku) sku = priceService.GetActivityPrice(sku)
}
case 3: case 3:
//如果是寄售的,不走价格体系 //如果是寄售的,不走价格体系
if sku.Source == 12 { if sku.Source == 12 {
...@@ -240,6 +267,11 @@ func (ls *LyService) LyGoodsDetail(ctx *gin.Context, goodsIds []string, ch chan ...@@ -240,6 +267,11 @@ func (ls *LyService) LyGoodsDetail(ctx *gin.Context, goodsIds []string, ch chan
sku.HkDeliveryTime = delivery["hk_delivery"] sku.HkDeliveryTime = delivery["hk_delivery"]
} }
//只要是寄售的,大陆交期都是0.5工作日
if sku.Source == 12 {
sku.CnDeliveryTime = "0.5工作日"
}
} }
//处理是否可以购买 //处理是否可以购买
...@@ -255,8 +287,8 @@ func (ls *LyService) LyGoodsDetail(ctx *gin.Context, goodsIds []string, ch chan ...@@ -255,8 +287,8 @@ func (ls *LyService) LyGoodsDetail(ctx *gin.Context, goodsIds []string, ch chan
//判断是否可以购买 //判断是否可以购买
sku.IsBuy = ls.GetIsBuy(sku) sku.IsBuy = ls.GetIsBuy(sku)
if sku.IsBuy ==0 && sku.OrgId != 1 { if sku.IsBuy == 0 && sku.OrgId != 1 {
sku.AcType = 0; sku.AcType = 0
} }
sku.Stock = ls.GetStock(sku) sku.Stock = ls.GetStock(sku)
...@@ -268,8 +300,6 @@ func (ls *LyService) LyGoodsDetail(ctx *gin.Context, goodsIds []string, ch chan ...@@ -268,8 +300,6 @@ func (ls *LyService) LyGoodsDetail(ctx *gin.Context, goodsIds []string, ch chan
//获取关税以及价格转换 //获取关税以及价格转换
sku = ls.GetTariffAndPrice(sku) sku = ls.GetTariffAndPrice(sku)
//用spuInfo补全信息
sku = ls.CombineSup(sku, spu)
//最后一步,将sku的全部信息放到有序map里面 //最后一步,将sku的全部信息放到有序map里面
GoodsRes.Store(goodsId, sku) GoodsRes.Store(goodsId, sku)
//(*goodsRes)[goodsId] = A //(*goodsRes)[goodsId] = A
...@@ -290,6 +320,7 @@ func (ls *LyService) GetActivity(sku model.LySku) model.LySku { ...@@ -290,6 +320,7 @@ func (ls *LyService) GetActivity(sku model.LySku) model.LySku {
GoodsName: sku.GoodsName, GoodsName: sku.GoodsName,
ClassId: sku.ClassID2, ClassId: sku.ClassID2,
OrgId: sku.OrgId, OrgId: sku.OrgId,
Source: sku.Source,
} }
var activityService ActivityService var activityService ActivityService
priceActivity, giftActivity := activityService.GetActivityData(checkData) priceActivity, giftActivity := activityService.GetActivityData(checkData)
......
...@@ -61,14 +61,13 @@ func (ps *PriceService) GenerateLadderPrice(sku model.LySku) model.LySku { ...@@ -61,14 +61,13 @@ func (ps *PriceService) GenerateLadderPrice(sku model.LySku) model.LySku {
//拿出里面的所有排序 //拿出里面的所有排序
priceRatioSortMap := gjson.Get(priceRatioCache, ratioDataKey).Map() priceRatioSortMap := gjson.Get(priceRatioCache, ratioDataKey).Map()
var sortNumbers []int var sortNumbers []int
for sortNumberString, _ := range priceRatioSortMap { for sortNumberString := range priceRatioSortMap {
sortNumber, _ := strconv.Atoi(sortNumberString) sortNumber, _ := strconv.Atoi(sortNumberString)
sortNumbers = append(sortNumbers, sortNumber) sortNumbers = append(sortNumbers, sortNumber)
} }
//然后确定排序 //然后确定排序
sortNumbers = sorter.IntSliceSortDesc(sortNumbers) sortNumbers = sorter.IntSliceSortDesc(sortNumbers)
//确定排序以后,就可以进行按排序(从大到小)取系数 //确定排序以后,就可以进行按排序(从大到小)取系数
outerLoop:
for _, sortNumber := range sortNumbers { for _, sortNumber := range sortNumbers {
priceRatioSort = sortNumber priceRatioSort = sortNumber
priceRatioList = nil priceRatioList = nil
...@@ -84,15 +83,15 @@ func (ps *PriceService) GenerateLadderPrice(sku model.LySku) model.LySku { ...@@ -84,15 +83,15 @@ func (ps *PriceService) GenerateLadderPrice(sku model.LySku) model.LySku {
} }
//是否满足特定条件的判断 //是否满足特定条件的判断
var hasSpecialCheck = false var hasSpecialCheck = false
conditionsMet := true
//判断是否有符合的商品名称 //判断是否有符合的商品名称
goodsNames := gjson.Get(priceRatioCache, "goods_name."+sortString).String() goodsNames := gjson.Get(priceRatioCache, "goods_name."+sortString).String()
if goodsNames != "" { if goodsNames != "" {
hasSpecialCheck = true hasSpecialCheck = true
goodsNameList := strings.Split(goodsNames, "@€@") goodsNameList := strings.Split(goodsNames, "@€@")
//找到有对应的商品名称,那么优先级肯定是最高的了 if !php2go.InArray(sku.GoodsName, goodsNameList) {
if php2go.InArray(sku.GoodsName, goodsNameList) { conditionsMet = false
foundRatio = true
break
} }
} }
...@@ -101,12 +100,20 @@ func (ps *PriceService) GenerateLadderPrice(sku model.LySku) model.LySku { ...@@ -101,12 +100,20 @@ func (ps *PriceService) GenerateLadderPrice(sku model.LySku) model.LySku {
if brandIds != "" { if brandIds != "" {
hasSpecialCheck = true hasSpecialCheck = true
standardBrandIdList := strings.Split(brandIds, ",") standardBrandIdList := strings.Split(brandIds, ",")
//fmt.Println(standardBrandIdList)
standardBrandId := strconv.Itoa(sku.StandardBrand.StandardBrandId) standardBrandId := strconv.Itoa(sku.StandardBrand.StandardBrandId)
//找到有对应的品牌,那么优先级肯定是最高的了 if !php2go.InArray(standardBrandId, standardBrandIdList) {
if php2go.InArray(standardBrandId, standardBrandIdList) { conditionsMet = false
foundRatio = true }
break }
//判断是否有符合的分类ID
classIds := gjson.Get(priceRatioCache, "class_ids."+sortString).String()
if classIds != "" {
hasSpecialCheck = true
classIdList := strings.Split(classIds, ",")
classId := strconv.Itoa(sku.ClassID2)
if !php2go.InArray(classId, classIdList) {
conditionsMet = false
} }
} }
...@@ -114,11 +121,9 @@ func (ps *PriceService) GenerateLadderPrice(sku model.LySku) model.LySku { ...@@ -114,11 +121,9 @@ func (ps *PriceService) GenerateLadderPrice(sku model.LySku) model.LySku {
eccns := gjson.Get(priceRatioCache, "eccn."+sortString).String() eccns := gjson.Get(priceRatioCache, "eccn."+sortString).String()
if eccns != "" { if eccns != "" {
hasSpecialCheck = true hasSpecialCheck = true
eccnMatched := false
eccnList := strings.Split(eccns, ",") eccnList := strings.Split(eccns, ",")
//找到有对应的eccn,那么优先级肯定是最高的了
for _, eccn := range eccnList { for _, eccn := range eccnList {
//判断是否有百分号匹配
//如果是纯%,那就是不对的,要跳过
if strings.Replace(eccn, "%", "", 10) == "" { if strings.Replace(eccn, "%", "", 10) == "" {
continue continue
} }
...@@ -128,36 +133,44 @@ func (ps *PriceService) GenerateLadderPrice(sku model.LySku) model.LySku { ...@@ -128,36 +133,44 @@ func (ps *PriceService) GenerateLadderPrice(sku model.LySku) model.LySku {
if hasPrefix && hasSuffix { if hasPrefix && hasSuffix {
eccn = strings.Replace(eccn, "%", "", 10) eccn = strings.Replace(eccn, "%", "", 10)
if strings.Contains(sku.Eccn, eccn) { if strings.Contains(sku.Eccn, eccn) {
foundRatio = true eccnMatched = true
break outerLoop break
}
} }
if hasPrefix && !hasSuffix { } else if hasPrefix {
eccn = strings.Replace(eccn, "%", "", 10) eccn = strings.Replace(eccn, "%", "", 10)
if strings.HasSuffix(sku.Eccn, eccn) { if strings.HasSuffix(sku.Eccn, eccn) {
foundRatio = true eccnMatched = true
break outerLoop break
}
} }
if !hasPrefix && hasSuffix { } else if hasSuffix {
eccn = strings.Replace(eccn, "%", "", 10) eccn = strings.Replace(eccn, "%", "", 10)
if strings.HasPrefix(sku.Eccn, eccn) { if strings.HasPrefix(sku.Eccn, eccn) {
foundRatio = true eccnMatched = true
break outerLoop break
} }
} }
} else { } else {
if sku.Eccn == eccn { if sku.Eccn == eccn {
foundRatio = true eccnMatched = true
break outerLoop break
} }
} }
} }
if !eccnMatched {
conditionsMet = false
} }
//如果没有设置品牌和商品,那么这个优先级高的就会覆盖下面的了,不需要再去判断品牌和型号了 }
if hasSpecialCheck { if hasSpecialCheck {
if conditionsMet {
foundRatio = true
break
} else {
continue continue
} }
}
// 如果没有设置任何特殊条件,则默认匹配
foundRatio = true foundRatio = true
break break
} }
...@@ -535,14 +548,13 @@ func (ps PriceService) GetPriceRatio(sku model.LySku) (model.LySku, []model.Pric ...@@ -535,14 +548,13 @@ func (ps PriceService) GetPriceRatio(sku model.LySku) (model.LySku, []model.Pric
//拿出里面的所有排序 //拿出里面的所有排序
priceRatioSortMap := gjson.Get(priceRatioCache, "ladder_price").Map() priceRatioSortMap := gjson.Get(priceRatioCache, "ladder_price").Map()
var sortNumbers []int var sortNumbers []int
for sortNumberString, _ := range priceRatioSortMap { for sortNumberString := range priceRatioSortMap {
sortNumber, _ := strconv.Atoi(sortNumberString) sortNumber, _ := strconv.Atoi(sortNumberString)
sortNumbers = append(sortNumbers, sortNumber) sortNumbers = append(sortNumbers, sortNumber)
} }
//然后确定排序 //然后确定排序
sortNumbers = sorter.IntSliceSortDesc(sortNumbers) sortNumbers = sorter.IntSliceSortDesc(sortNumbers)
//确定排序以后,就可以进行按排序(从大到小)取系数 //确定排序以后,就可以进行按排序(从大到小)取系数
outerLoop:
for _, sortNumber := range sortNumbers { for _, sortNumber := range sortNumbers {
priceRatioSort = sortNumber priceRatioSort = sortNumber
priceRatioList = nil priceRatioList = nil
...@@ -556,16 +568,15 @@ func (ps PriceService) GetPriceRatio(sku model.LySku) (model.LySku, []model.Pric ...@@ -556,16 +568,15 @@ func (ps PriceService) GetPriceRatio(sku model.LySku) (model.LySku, []model.Pric
} }
var hasSpecialCheck = false var hasSpecialCheck = false
conditionsMet := true
//判断是否有符合的商品名称 //判断是否有符合的商品名称
goodsNames := gjson.Get(priceRatioCache, "goods_name."+sortString).String() goodsNames := gjson.Get(priceRatioCache, "goods_name."+sortString).String()
if goodsNames != "" { if goodsNames != "" {
hasSpecialCheck = true hasSpecialCheck = true
goodsNameList := strings.Split(goodsNames, "@€@") goodsNameList := strings.Split(goodsNames, "@€@")
//找到有对应的商品名称,那么优先级肯定是最高的了 if !php2go.InArray(sku.GoodsName, goodsNameList) {
if php2go.InArray(sku.GoodsName, goodsNameList) { conditionsMet = false
foundRatio = true
break
} }
} }
...@@ -575,10 +586,19 @@ func (ps PriceService) GetPriceRatio(sku model.LySku) (model.LySku, []model.Pric ...@@ -575,10 +586,19 @@ func (ps PriceService) GetPriceRatio(sku model.LySku) (model.LySku, []model.Pric
hasSpecialCheck = true hasSpecialCheck = true
standardBrandIdList := strings.Split(brandIds, ",") standardBrandIdList := strings.Split(brandIds, ",")
standardBrandId := strconv.Itoa(sku.StandardBrand.StandardBrandId) standardBrandId := strconv.Itoa(sku.StandardBrand.StandardBrandId)
//找到有对应的品牌,那么优先级肯定是最高的了 if !php2go.InArray(standardBrandId, standardBrandIdList) {
if php2go.InArray(standardBrandId, standardBrandIdList) { conditionsMet = false
foundRatio = true }
break }
//判断是否有符合的分类ID
classIds := gjson.Get(priceRatioCache, "class_ids."+sortString).String()
if classIds != "" {
hasSpecialCheck = true
classIdList := strings.Split(classIds, ",")
classId := strconv.Itoa(sku.ClassID2)
if !php2go.InArray(classId, classIdList) {
conditionsMet = false
} }
} }
...@@ -586,11 +606,9 @@ func (ps PriceService) GetPriceRatio(sku model.LySku) (model.LySku, []model.Pric ...@@ -586,11 +606,9 @@ func (ps PriceService) GetPriceRatio(sku model.LySku) (model.LySku, []model.Pric
eccns := gjson.Get(priceRatioCache, "eccn."+sortString).String() eccns := gjson.Get(priceRatioCache, "eccn."+sortString).String()
if eccns != "" { if eccns != "" {
hasSpecialCheck = true hasSpecialCheck = true
eccnMatched := false
eccnList := strings.Split(eccns, ",") eccnList := strings.Split(eccns, ",")
//找到有对应的eccn,那么优先级肯定是最高的了
for _, eccn := range eccnList { for _, eccn := range eccnList {
//判断是否有百分号匹配
//如果是纯%,那就是不对的,要跳过
if strings.Replace(eccn, "%", "", 10) == "" { if strings.Replace(eccn, "%", "", 10) == "" {
continue continue
} }
...@@ -600,36 +618,44 @@ func (ps PriceService) GetPriceRatio(sku model.LySku) (model.LySku, []model.Pric ...@@ -600,36 +618,44 @@ func (ps PriceService) GetPriceRatio(sku model.LySku) (model.LySku, []model.Pric
if hasPrefix && hasSuffix { if hasPrefix && hasSuffix {
eccn = strings.Replace(eccn, "%", "", 10) eccn = strings.Replace(eccn, "%", "", 10)
if strings.Contains(sku.Eccn, eccn) { if strings.Contains(sku.Eccn, eccn) {
foundRatio = true eccnMatched = true
break outerLoop break
}
} }
if hasPrefix && !hasSuffix { } else if hasPrefix {
eccn = strings.Replace(eccn, "%", "", 10) eccn = strings.Replace(eccn, "%", "", 10)
if strings.HasSuffix(sku.Eccn, eccn) { if strings.HasSuffix(sku.Eccn, eccn) {
foundRatio = true eccnMatched = true
break outerLoop break
}
} }
if !hasPrefix && hasSuffix { } else if hasSuffix {
eccn = strings.Replace(eccn, "%", "", 10) eccn = strings.Replace(eccn, "%", "", 10)
if strings.HasPrefix(sku.Eccn, eccn) { if strings.HasPrefix(sku.Eccn, eccn) {
foundRatio = true eccnMatched = true
break outerLoop break
} }
} }
} else { } else {
if sku.Eccn == eccn { if sku.Eccn == eccn {
foundRatio = true eccnMatched = true
break outerLoop break
} }
} }
} }
if !eccnMatched {
conditionsMet = false
} }
//如果没有设置品牌和商品,那么这个优先级高的就会覆盖下面的了,不需要再去判断品牌和型号了 }
if hasSpecialCheck { if hasSpecialCheck {
if conditionsMet {
foundRatio = true
break
} else {
continue continue
} }
}
// 如果没有设置任何特殊条件,则默认匹配
foundRatio = true foundRatio = true
break break
} }
......
...@@ -98,7 +98,38 @@ func (ts *TagsService) GetLyTags(sku model.LySku) (goodsTags model.GoodsTag) { ...@@ -98,7 +98,38 @@ func (ts *TagsService) GetLyTags(sku model.LySku) (goodsTags model.GoodsTag) {
} }
} }
//还要判断source的标签
sourceTagsStr, _ := redis.String(redisCon.Do("HGET", "goods_source_tags", sku.Source))
if sourceTagsStr != "" {
systemTags := gjson.Get(sourceTagsStr, "system_tags").Array()
for _, tag := range systemTags {
tagNames = append(tagNames, tag.String())
}
}
//判断goods_label的标签
labelTagsStr, _ := redis.String(redisCon.Do("HGET", "goods_label_tags", sku.GoodsTag.GoodsLabel))
if labelTagsStr != "" {
labelTags := gjson.Get(labelTagsStr, "system_tags").Array()
for _, tag := range labelTags {
tagNames = append(tagNames, tag.String())
}
}
//去重tagNames
tagNames = removeDuplicateString(tagNames)
goodsTags.GoodsTagNames = tagNames goodsTags.GoodsTagNames = tagNames
goodsTags.GoodsTag = tags goodsTags.GoodsTag = tags
return goodsTags return goodsTags
} }
func removeDuplicateString(s []string) []string {
result := []string{}
temp := map[string]struct{}{}
for _, item := range s {
if _, ok := temp[item]; !ok {
temp[item] = struct{}{}
result = append(result, item)
}
}
return result
}
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