Commit 72e3ae27 by 杨树贤

Use BatchSn for SKU batch format and remove Batch

Populate LySku.BatchFormat from BatchSn (JSON or fallback items).
Add fourDigitRegex to handle 4-digit ziying batch codes as "XX+".
Remove the unused Batch field and its initialization.
parent 9ea9d127
......@@ -105,7 +105,6 @@ type LySku struct {
Cost float64 `json:"cost"`
CostUs float64 `json:"cost_us"`
IsZiying int `json:"is_ziying"`
Batch string `json:"-"`
BatchFormat interface{} `json:"batch_format"`
}
......@@ -313,8 +312,6 @@ func InitSkuData(sku string) (data LySku) {
data.AbilityLevel = int(gjson.Get(sku, "ability_level").Int())
data.Batch = gjson.Get(sku, "batch").String()
return
}
......
......@@ -265,7 +265,6 @@ func (ls *LyService) GetIsBuy(sku model.LySku) (isBuy int) {
if len(sku.LadderPrice) == 0 {
return
}
//L0016691 L0015730 L0015835 L0016793 L0016887 L0016886 L0016784
if sku.AbilityLevel == 0 && sku.OrgId == 1 && (sku.Canal != "L0015730" && sku.Canal != "L0015835" && sku.Canal != "L0016691" && sku.Canal != "L0016793" && sku.Canal != "L0016887" && sku.Canal != "L0016886" && sku.Canal != "L0016784") {
return
......
......@@ -4,6 +4,7 @@ import (
"encoding/json"
"go_sku_server/model"
"go_sku_server/pkg/gredis"
"regexp"
"strconv"
"strings"
......@@ -11,6 +12,8 @@ import (
"github.com/tidwall/gjson"
)
var fourDigitRegex = regexp.MustCompile(`^\d{4}$`)
var batchCodeMap = map[int]string{
-1: "无法指定",
1: "任意批次",
......@@ -22,17 +25,24 @@ var batchCodeMap = map[int]string{
}
func (ls *LyService) GetSkuBatchFormat(sku *model.LySku) {
if sku.Batch != "" {
if sku.BatchSn != "" {
var items []model.BatchFormatItem
var batchObj map[string]interface{}
if err := json.Unmarshal([]byte(sku.Batch), &batchObj); err == nil {
var items []model.BatchFormatItem
if err := json.Unmarshal([]byte(sku.BatchSn), &batchObj); err == nil {
for k, v := range batchObj {
items = append(items, model.BatchFormatItem{Name: k, Value: v})
}
sku.BatchFormat = items
} else if sku.IsZiying == 1 && fourDigitRegex.MatchString(sku.BatchSn) {
items = append(items, model.BatchFormatItem{
Name: sku.BatchSn[:2] + "+",
Value: sku.BatchSn,
})
} else {
sku.BatchFormat = sku.Batch
items = append(items, model.BatchFormatItem{Value: sku.BatchSn})
}
sku.BatchFormat = items
return
}
......
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