fix queryDetailBy
This commit is contained in:
parent
5dc96899e7
commit
ba2a8728cb
@ -6,14 +6,15 @@ import (
|
|||||||
"encoding/hex"
|
"encoding/hex"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
"github.com/jinzhu/copier"
|
|
||||||
"github.com/pkg/errors"
|
|
||||||
"time"
|
"time"
|
||||||
"tydata-server/common/xerr"
|
"tydata-server/common/xerr"
|
||||||
"tydata-server/pkg/lzkit/crypto"
|
"tydata-server/pkg/lzkit/crypto"
|
||||||
"tydata-server/pkg/lzkit/delay"
|
"tydata-server/pkg/lzkit/delay"
|
||||||
"tydata-server/pkg/lzkit/lzUtils"
|
"tydata-server/pkg/lzkit/lzUtils"
|
||||||
|
|
||||||
|
"github.com/jinzhu/copier"
|
||||||
|
"github.com/pkg/errors"
|
||||||
|
|
||||||
"tydata-server/app/user/cmd/api/internal/svc"
|
"tydata-server/app/user/cmd/api/internal/svc"
|
||||||
"tydata-server/app/user/cmd/api/internal/types"
|
"tydata-server/app/user/cmd/api/internal/types"
|
||||||
|
|
||||||
@ -209,25 +210,18 @@ func (l *QueryDetailByOrderIdLogic) UpdateFeatureAndProductFeature(productID int
|
|||||||
|
|
||||||
// 遍历 productFeatures,找到与 feature.ID 关联且 enable == 1 的项
|
// 遍历 productFeatures,找到与 feature.ID 关联且 enable == 1 的项
|
||||||
var featureData map[string]interface{}
|
var featureData map[string]interface{}
|
||||||
foundFeature := false
|
// foundFeature := false
|
||||||
|
sort := 0
|
||||||
for _, pf := range productFeatures {
|
for _, pf := range productFeatures {
|
||||||
if pf.FeatureId == feature.Id { // 确保和 Feature 关联
|
if pf.FeatureId == feature.Id { // 确保和 Feature 关联
|
||||||
foundFeature = true
|
sort = int(pf.Sort)
|
||||||
if pf.Enable == 1 {
|
break // 找到第一个符合条件的就退出循环
|
||||||
featureData = map[string]interface{}{
|
|
||||||
"featureName": feature.Name,
|
|
||||||
"sort": pf.Sort,
|
|
||||||
}
|
|
||||||
break // 找到第一个符合条件的就退出循环
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
featureData = map[string]interface{}{
|
||||||
// 如果没有符合条件的 feature 或者 featureData 为空,则删除当前 queryItem
|
"featureName": feature.Name,
|
||||||
if !foundFeature || featureData == nil {
|
"sort": sort,
|
||||||
*target = append((*target)[:i], (*target)[i+1:]...)
|
|
||||||
continue
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// 更新 queryItem 的 Feature 字段(不是数组)
|
// 更新 queryItem 的 Feature 字段(不是数组)
|
||||||
|
@ -4,12 +4,13 @@ import (
|
|||||||
"context"
|
"context"
|
||||||
"encoding/hex"
|
"encoding/hex"
|
||||||
"fmt"
|
"fmt"
|
||||||
"github.com/jinzhu/copier"
|
|
||||||
"github.com/pkg/errors"
|
|
||||||
"time"
|
"time"
|
||||||
"tydata-server/common/xerr"
|
"tydata-server/common/xerr"
|
||||||
"tydata-server/pkg/lzkit/delay"
|
"tydata-server/pkg/lzkit/delay"
|
||||||
|
|
||||||
|
"github.com/jinzhu/copier"
|
||||||
|
"github.com/pkg/errors"
|
||||||
|
|
||||||
"tydata-server/app/user/cmd/api/internal/svc"
|
"tydata-server/app/user/cmd/api/internal/svc"
|
||||||
"tydata-server/app/user/cmd/api/internal/types"
|
"tydata-server/app/user/cmd/api/internal/types"
|
||||||
|
|
||||||
@ -172,25 +173,18 @@ func (l *QueryDetailByOrderNoLogic) UpdateFeatureAndProductFeature(productID int
|
|||||||
|
|
||||||
// 遍历 productFeatures,找到与 feature.ID 关联且 enable == 1 的项
|
// 遍历 productFeatures,找到与 feature.ID 关联且 enable == 1 的项
|
||||||
var featureData map[string]interface{}
|
var featureData map[string]interface{}
|
||||||
foundFeature := false
|
// foundFeature := false
|
||||||
|
sort := 0
|
||||||
for _, pf := range productFeatures {
|
for _, pf := range productFeatures {
|
||||||
if pf.FeatureId == feature.Id { // 确保和 Feature 关联
|
if pf.FeatureId == feature.Id { // 确保和 Feature 关联
|
||||||
foundFeature = true
|
sort = int(pf.Sort)
|
||||||
if pf.Enable == 1 {
|
break // 找到第一个符合条件的就退出循环
|
||||||
featureData = map[string]interface{}{
|
|
||||||
"featureName": feature.Name,
|
|
||||||
"sort": pf.Sort,
|
|
||||||
}
|
|
||||||
break // 找到第一个符合条件的就退出循环
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
featureData = map[string]interface{}{
|
||||||
// 如果没有符合条件的 feature 或者 featureData 为空,则删除当前 queryItem
|
"featureName": feature.Name,
|
||||||
if !foundFeature || featureData == nil {
|
"sort": sort,
|
||||||
*target = append((*target)[:i], (*target)[i+1:]...)
|
|
||||||
continue
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// 更新 queryItem 的 Feature 字段(不是数组)
|
// 更新 queryItem 的 Feature 字段(不是数组)
|
||||||
|
Loading…
Reference in New Issue
Block a user