feat: 增加规格匹配建议与决策审计 (#90)
This commit is contained in:
+36
-22
@@ -12,6 +12,7 @@ package service
|
||||
|
||||
import (
|
||||
"context"
|
||||
"crypto/sha256"
|
||||
"database/sql"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
@@ -28,6 +29,13 @@ import (
|
||||
"cmautobuy/admin/syb"
|
||||
)
|
||||
|
||||
func mappingContextVersion(c repository.SybOrderContext) string {
|
||||
payload, _ := json.Marshal([]string{c.Order.SybID, c.Order.SpecKey, c.Order.UpdatedAt,
|
||||
c.Order.ProductSpec, strconv.Itoa(c.Order.Quantity), c.PddGoodsID, c.PddUpdatedAt,
|
||||
c.PddSkusJSON, SpecMatchRulesVersion})
|
||||
return fmt.Sprintf("%x", sha256.Sum256(payload))
|
||||
}
|
||||
|
||||
const (
|
||||
dateLayout = "2006-01-02"
|
||||
maxSpecifiedSyncDays = 31
|
||||
@@ -1138,25 +1146,27 @@ func defaultMaxPrice(context repository.SybOrderContext) string {
|
||||
|
||||
// SybProcessingDetail 是顺运宝“下一步”弹窗第一阶段需要的上下文。
|
||||
type SybProcessingDetail struct {
|
||||
SybID string
|
||||
OrderNo string
|
||||
Title string
|
||||
ProductSpec string
|
||||
ShopeeGoodsID string
|
||||
Quantity int
|
||||
Stage string
|
||||
StageText string
|
||||
StageHelp string
|
||||
ShopeeExists bool
|
||||
PddGoodsID string
|
||||
PddURL string
|
||||
CollectStatus string
|
||||
CollectMsg string
|
||||
CanCollect bool
|
||||
PddDimensionNames []string
|
||||
PddChoices []PddOptionChoice
|
||||
MappingValid bool
|
||||
HasActiveTask bool
|
||||
SybID string
|
||||
OrderNo string
|
||||
Title string
|
||||
ProductSpec string
|
||||
ShopeeGoodsID string
|
||||
Quantity int
|
||||
Stage string
|
||||
StageText string
|
||||
StageHelp string
|
||||
ShopeeExists bool
|
||||
PddGoodsID string
|
||||
PddURL string
|
||||
CollectStatus string
|
||||
CollectMsg string
|
||||
CanCollect bool
|
||||
PddDimensionNames []string
|
||||
PddChoices []PddOptionChoice
|
||||
ContextVersion string
|
||||
RecommendationNotice string
|
||||
MappingValid bool
|
||||
HasActiveTask bool
|
||||
}
|
||||
|
||||
func GetSybProcessingDetail(db *sql.DB, sybID string) (*SybProcessingDetail, error) {
|
||||
@@ -1177,18 +1187,22 @@ func GetSybProcessingDetail(db *sql.DB, sybID string) (*SybProcessingDetail, err
|
||||
context.PddCollectStatus == string(model.CollectFailed))
|
||||
d.HasActiveTask = context.HasActiveTask
|
||||
if context.PddCollectStatus == string(model.CollectCollected) && context.PddSkusJSON != "" {
|
||||
choices, names, parseErr := pddOptionChoices(context.PddSkusJSON)
|
||||
choices, keys, names, parseErr := pddOptionChoices(context.PddSkusJSON)
|
||||
if parseErr == nil {
|
||||
d.PddDimensionNames = names
|
||||
d.PddChoices = choices
|
||||
match := rankSpecChoices(o.ProductSpec, choices, keys, names)
|
||||
d.PddChoices = match.Choices
|
||||
d.RecommendationNotice = match.Notice
|
||||
for i := range d.PddChoices {
|
||||
d.PddChoices[i].Selected = d.PddChoices[i].Key == context.MappingOptionKey
|
||||
d.PddChoices[i].Selected = d.PddChoices[i].Key == context.MappingOptionKey ||
|
||||
(context.MappingOptionKey == "" && d.PddChoices[i].Key == match.PreselectOptionKey)
|
||||
if d.PddChoices[i].Selected {
|
||||
d.MappingValid = true
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
d.ContextVersion = mappingContextVersion(*context)
|
||||
d.Stage, d.StageText, d.StageHelp, _ = sybStageFor(*context)
|
||||
return d, nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user