-
Notifications
You must be signed in to change notification settings - Fork 264
/
item_json_util.go
executable file
·91 lines (82 loc) · 1.71 KB
/
item_json_util.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
package item
import (
"fmt"
"github.com/ixre/go2o/core/domain/interface/item"
"github.com/ixre/go2o/core/domain/interface/pro_model"
"strconv"
)
var iJsonUtil = &itemJsonUtil{}
// 规格项
type specJdo struct {
// 规格名称
Name string `json:"name"`
// 规格项
Value []specItemJdo `json:"value"`
}
// 规格值
type specItemJdo struct {
// 名称
Name string `json:"name"`
// 代码
Code string `json:"code"`
// 图片地址
ImageUrl string `json:"imageUrl"`
}
// SKU传输对象
type skuJdo struct {
// SKU编号
SkuId string
// SKU数据
SpecData string
// SKU文本
SpecWord string
// 商品编码
Code string
// 价格
Price int64
// 折扣价
DiscountPrice int64
// 可售数量
CanSalesQuantity int32
// 已售数量
SalesCount int32
// 数量与价格字典
PriceArray []skuPriceJdo
}
type skuPriceJdo struct {
Quantity int32
Price int64
}
type itemJsonUtil struct {
}
// 获取规格JSON数据
func (s *itemJsonUtil) getSpecJdo(spec promodel.SpecList) []specJdo {
arr := make([]specJdo, len(spec))
for i, v := range spec {
arr[i] = specJdo{Name: v.Name}
arr[i].Value = make([]specItemJdo, len(v.Items))
for j, v2 := range v.Items {
arr[i].Value[j] = specItemJdo{
Name: v2.Value,
Code: fmt.Sprintf("%d:%d", v.Id, v2.Id),
ImageUrl: v2.Color,
}
}
}
return arr
}
// 获取SKU的JSON字符串
func (s *itemJsonUtil) getSkuJdo(skuArr []*item.Sku) []skuJdo {
arr := make([]skuJdo, len(skuArr))
for i, v := range skuArr {
arr[i] = skuJdo{
SkuId: strconv.Itoa(int(v.Id)),
SpecData: v.SpecData,
SpecWord: v.SpecWord,
Price: v.Price,
DiscountPrice: v.Price,
PriceArray: []skuPriceJdo{},
}
}
return arr
}