Commit 0ada3b17 by mushishixian

封装为重要属性

parent 57b8c0d3
...@@ -98,21 +98,20 @@ func searchAttr(bomItem model.BomItem, search *es.MultiSearchService) (result *e ...@@ -98,21 +98,20 @@ func searchAttr(bomItem model.BomItem, search *es.MultiSearchService) (result *e
attrsSlice = append(attrsSlice, attr) attrsSlice = append(attrsSlice, attr)
} }
} }
query := getQuery(attrsSlice)
//单独针对封装进行转换 //单独针对封装进行转换
if bomItem.Encap != "" { if bomItem.Encap != "" {
//先提取出纯数字 //先提取出纯数字
numberR, _ := regexp.Compile(mapping.PureNumberRegular) numberR, _ := regexp.Compile(mapping.PureNumberRegular)
pureNumber := numberR.FindString(bomItem.Encap) pureNumber := numberR.FindString(bomItem.Encap)
//再去找对应属性 //再去找对应属性
attrName, _ := redis.String(gredis.HGet("sku_map2", pureNumber)) attrValue := "封装" + "€" + pureNumber
if attrName != "" { if !php2go.InArray(attrValue, attrsSlice) {
attrValue := attrName + "€" + pureNumber subQuery := es.NewTermQuery("attrs.attr_value", attrValue)
if !php2go.InArray(attrValue, attrsSlice) { nestedQuery := es.NewNestedQuery("attrs", subQuery)
attrsSlice = append(attrsSlice, attrValue) query.Must(nestedQuery)
}
} }
} }
query := getQuery(attrsSlice)
//如果ZyBrandId不为空,则代表匹配到了映射id //如果ZyBrandId不为空,则代表匹配到了映射id
if bomItem.ZyBrandId != "" && len(attrsSlice) > 0 { if bomItem.ZyBrandId != "" && len(attrsSlice) > 0 {
query.Should(es.NewTermQuery("brand_name", bomItem.ZyBrandName)) query.Should(es.NewTermQuery("brand_name", bomItem.ZyBrandName))
...@@ -144,8 +143,17 @@ func searchAttr(bomItem model.BomItem, search *es.MultiSearchService) (result *e ...@@ -144,8 +143,17 @@ func searchAttr(bomItem model.BomItem, search *es.MultiSearchService) (result *e
//切割参数 //切割参数
func splitAttrs(attrs string) (result []string) { func splitAttrs(attrs string) (result []string) {
result = strings.Split(attrs, " ") result = strings.Split(attrs, " ")
if len(result) > 1 {
return
}
result = strings.Split(attrs, ",") result = strings.Split(attrs, ",")
if len(result) > 1 {
return
}
result = strings.Split(attrs, "|") result = strings.Split(attrs, "|")
if len(result) > 1 {
return
}
result = strings.Split(attrs, ",") result = strings.Split(attrs, ",")
if len(result) > 1 { if len(result) > 1 {
return return
...@@ -222,7 +230,6 @@ func getAttrValueByAttr(attr string) (attrValue string) { ...@@ -222,7 +230,6 @@ func getAttrValueByAttr(attr string) (attrValue string) {
attrNumber, _ = strconv.ParseFloat(pureNumber, 64) attrNumber, _ = strconv.ParseFloat(pureNumber, 64)
//找出对应单位需要转换的值 //找出对应单位需要转换的值
var attrName string var attrName string
//再去找没有单位的对应属性
if attrUnit != "" { if attrUnit != "" {
for unit, value := range mapping.UnitValueMapping { for unit, value := range mapping.UnitValueMapping {
//如果不是标准最小单位,则要进行转换 //如果不是标准最小单位,则要进行转换
...@@ -245,6 +252,8 @@ func getAttrValueByAttr(attr string) (attrValue string) { ...@@ -245,6 +252,8 @@ func getAttrValueByAttr(attr string) (attrValue string) {
break break
} }
} }
//就算是提取出所谓的单位,也有可能是封装里面乱写的,比如 C0402R
//所以还是要去判断是否是封装
} else { } else {
//再去找没有单位的对应属性 //再去找没有单位的对应属性
attrName, _ = redis.String(gredis.HGet("sku_map2", attr)) attrName, _ = redis.String(gredis.HGet("sku_map2", attr))
...@@ -266,6 +275,7 @@ func getQuery(attrs []string) (query *es.BoolQuery) { ...@@ -266,6 +275,7 @@ func getQuery(attrs []string) (query *es.BoolQuery) {
var subQuery *es.TermQuery var subQuery *es.TermQuery
var nestedQuery *es.NestedQuery var nestedQuery *es.NestedQuery
query = es.NewBoolQuery() query = es.NewBoolQuery()
hasEncap := false
for _, attr := range attrs { for _, attr := range attrs {
//还要判断是不是一个单位对应多个属性的 //还要判断是不是一个单位对应多个属性的
if strings.Contains(attr, "|") { if strings.Contains(attr, "|") {
...@@ -280,21 +290,30 @@ func getQuery(attrs []string) (query *es.BoolQuery) { ...@@ -280,21 +290,30 @@ func getQuery(attrs []string) (query *es.BoolQuery) {
} else { } else {
subQuery = es.NewTermQuery("attrs.attr_value", attr) subQuery = es.NewTermQuery("attrs.attr_value", attr)
nestedQuery = es.NewNestedQuery("attrs", subQuery) nestedQuery = es.NewNestedQuery("attrs", subQuery)
query.Should(nestedQuery) //封装是必须要完全满足
} if strings.Contains(attr, "封装") {
var shouldMatchNumber int hasEncap = true
if len(attrs) > 3 { query.Must(nestedQuery)
shouldMatchNumber = 3 } else {
} else if len(attrs) >= 2 { query.Should(nestedQuery)
shouldMatchNumber = 2 }
} else if len(attrs) == 1 && strings.Contains(attr, "封装") {
shouldMatchNumber = 2
} else {
shouldMatchNumber = 1
} }
query.MinimumNumberShouldMatch(shouldMatchNumber)
} }
var shouldMatchNumber int
shouldMatchNumber = 2
//判断在封装存在的条件下需要满足的筛选条数
attrsLen := len(attrs)
if hasEncap {
attrsLen = attrsLen - 1
}
if attrsLen > 4 {
shouldMatchNumber = 3
} else if attrsLen > 2 {
shouldMatchNumber = 2
} else {
shouldMatchNumber = 1
}
query.MinimumNumberShouldMatch(shouldMatchNumber)
return query return query
} }
......
...@@ -185,11 +185,9 @@ func MatchGoodsInfo(goods model.ApiGoods, goodsMap GoodsMap) (bomMatching model. ...@@ -185,11 +185,9 @@ func MatchGoodsInfo(goods model.ApiGoods, goodsMap GoodsMap) (bomMatching model.
bomMatching.Number = ((goodsMap.Number / goods.Mpl) + 1) * goods.Mpl bomMatching.Number = ((goodsMap.Number / goods.Mpl) + 1) * goods.Mpl
} }
} }
if goods.GoodsType != 0 || goods.AcType == 6 { }
if bomMatching.Number > goods.Stock { //判断活动系数
bomMatching.Number = goods.Stock if goods.AcType == 6 {
}
}
} }
//阶梯价处理 //阶梯价处理
......
...@@ -56,6 +56,7 @@ var UnitBaseMapping = map[string]string{ ...@@ -56,6 +56,7 @@ var UnitBaseMapping = map[string]string{
"V": "V", "V": "V",
"kV": "V", "kV": "V",
"KV": "V",
"mA": "A", "mA": "A",
"A": "A", "A": "A",
...@@ -88,6 +89,7 @@ var UnitValueMapping = map[string]string{ ...@@ -88,6 +89,7 @@ var UnitValueMapping = map[string]string{
"V": "1", "V": "1",
"kV": "1000", "kV": "1000",
"KV": "1000",
"mA": "1", "mA": "1",
"A": "1000", "A": "1000",
......
...@@ -63,6 +63,7 @@ type ApiGoods struct { ...@@ -63,6 +63,7 @@ type ApiGoods struct {
Pdf string `json:"pdf"` Pdf string `json:"pdf"`
Encap string `json:"encap"` Encap string `json:"encap"`
AcType int `json:"ac_type"` AcType int `json:"ac_type"`
AllowPresale int `json:"allow_presale"`
//ErpTax bool `json:"erp_tax"` //ErpTax bool `json:"erp_tax"`
} }
......
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