-
Notifications
You must be signed in to change notification settings - Fork 0
/
fields_core_options.go
268 lines (241 loc) · 7.18 KB
/
fields_core_options.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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
package MallCore
import (
"database/sql/driver"
"encoding/json"
"errors"
CoreFilter "github.com/fotomxq/weeekj_core/v5/core/filter"
"github.com/lib/pq"
"time"
)
// FieldsOtherOption 附加选项
type FieldsOtherOption struct {
//分类1
Sort1 FieldsOtherOptionSort `db:"sort1" json:"sort1"`
//分类2
Sort2 FieldsOtherOptionSort `db:"sort2" json:"sort2"`
//数据集合
DataList FieldsOtherOptionChildList `db:"data_list" json:"dataList"`
}
// Value sql底层处理器
func (t FieldsOtherOption) Value() (driver.Value, error) {
return json.Marshal(t)
}
func (t *FieldsOtherOption) Scan(value interface{}) error {
b, ok := value.([]byte)
if !ok {
return errors.New("type assertion to []byte failed")
}
return json.Unmarshal(b, &t)
}
// FieldsOtherOptionSort 分类数据集合
type FieldsOtherOptionSort struct {
//名称
Name string `db:"name" json:"name" check:"name"`
//选项组
Options pq.StringArray `db:"options" json:"options"`
}
// Value sql底层处理器
func (t FieldsOtherOptionSort) Value() (driver.Value, error) {
return json.Marshal(t)
}
func (t *FieldsOtherOptionSort) Scan(value interface{}) error {
b, ok := value.([]byte)
if !ok {
return errors.New("type assertion to []byte failed")
}
return json.Unmarshal(b, &t)
}
type FieldsOtherOptionChildList []FieldsOtherOptionChild
// Value sql底层处理器
func (t FieldsOtherOptionChildList) Value() (driver.Value, error) {
return json.Marshal(t)
}
func (t *FieldsOtherOptionChildList) Scan(value interface{}) error {
b, ok := value.([]byte)
if !ok {
return errors.New("type assertion to []byte failed")
}
return json.Unmarshal(b, &t)
}
type FieldsOtherOptionChild struct {
//分类1的选项key
Sort1 int `db:"sort1" json:"sort1" check:"intThan0" empty:"true"`
//分类2的选项key
Sort2 int `db:"sort2" json:"sort2" check:"intThan0" empty:"true"`
//商品ID
// 可以给0,则必须声明其他项目内容
ProductID int64 `db:"product_id" json:"productID" check:"id" empty:"true"`
//选项key
Key string `db:"key" json:"key" check:"mark"`
//实际费用
PriceReal int64 `db:"price_real" json:"priceReal" check:"price" empty:"true"`
//折扣截止
PriceExpireAt time.Time `db:"price_expire_at" json:"priceExpireAt" check:"isoTime" empty:"true"`
//折扣前费用
Price int64 `db:"price" json:"price" check:"price" empty:"true"`
//封面ID
CoverFileID int64 `db:"cover_file_id" json:"coverFileID" check:"id" empty:"true"`
//总库存
Count int `db:"count" json:"count" check:"intThan0" empty:"true"`
//商品条形码编码
Code string `db:"code" json:"code"`
}
// Value sql底层处理器
func (t FieldsOtherOptionChild) Value() (driver.Value, error) {
return json.Marshal(t)
}
func (t *FieldsOtherOptionChild) Scan(value interface{}) error {
b, ok := value.([]byte)
if !ok {
return errors.New("type assertion to []byte failed")
}
return json.Unmarshal(b, &t)
}
// GetData 转化数据为数据表结构
func (t FieldsOtherOption) GetData() (DataOtherOptions, error) {
var data DataOtherOptions
data.Sort1 = DataOtherOptionSort{
Name: t.Sort1.Name,
Options: t.Sort1.Options,
}
data.Sort2 = DataOtherOptionSort{
Name: t.Sort2.Name,
Options: t.Sort2.Options,
}
for _, v := range t.DataList {
data.DataList = append(data.DataList, DataOtherOptionChild{
Sort1: v.Sort1,
Sort2: v.Sort2,
ProductID: v.ProductID,
Key: v.Key,
PriceReal: v.PriceReal,
PriceExpireAt: CoreFilter.GetISOByTime(v.PriceExpireAt),
Price: v.Price,
CoverFileID: v.CoverFileID,
Count: v.Count,
Code: v.Code,
})
}
return data, nil
}
// DataOtherOptions 附加选项
type DataOtherOptions struct {
//分类1
Sort1 DataOtherOptionSort `db:"sort1" json:"sort1"`
//分类2
Sort2 DataOtherOptionSort `db:"sort2" json:"sort2"`
//数据集合
DataList DataOtherOptionChildList `db:"data_list" json:"dataList"`
}
// Value sql底层处理器
func (t DataOtherOptions) Value() (driver.Value, error) {
return json.Marshal(t)
}
func (t *DataOtherOptions) Scan(value interface{}) error {
b, ok := value.([]byte)
if !ok {
return errors.New("type assertion to []byte failed")
}
return json.Unmarshal(b, &t)
}
// DataOtherOptionSort 分类数据集合
type DataOtherOptionSort struct {
//名称
Name string `db:"name" json:"name" check:"name"`
//选项组
Options pq.StringArray `db:"options" json:"options"`
}
// Value sql底层处理器
func (t DataOtherOptionSort) Value() (driver.Value, error) {
return json.Marshal(t)
}
func (t *DataOtherOptionSort) Scan(value interface{}) error {
b, ok := value.([]byte)
if !ok {
return errors.New("type assertion to []byte failed")
}
return json.Unmarshal(b, &t)
}
// GetFields 转化数据为数据表结构
func (t DataOtherOptions) GetFields() (FieldsOtherOption, error) {
var data FieldsOtherOption
var err error
data.Sort1 = FieldsOtherOptionSort{
Name: t.Sort1.Name,
Options: t.Sort1.Options,
}
data.Sort2 = FieldsOtherOptionSort{
Name: t.Sort2.Name,
Options: t.Sort2.Options,
}
for _, v := range t.DataList {
var vExpire time.Time
if v.PriceExpireAt != "" {
vExpire, err = CoreFilter.GetTimeByISO(v.PriceExpireAt)
if err != nil {
return FieldsOtherOption{}, err
}
}
data.DataList = append(data.DataList, FieldsOtherOptionChild{
Sort1: v.Sort1,
Sort2: v.Sort2,
ProductID: v.ProductID,
Key: v.Key,
PriceReal: v.PriceReal,
PriceExpireAt: vExpire,
Price: v.Price,
CoverFileID: v.CoverFileID,
Count: v.Count,
Code: v.Code,
})
}
return data, nil
}
type DataOtherOptionChildList []DataOtherOptionChild
// Value sql底层处理器
func (t DataOtherOptionChildList) Value() (driver.Value, error) {
return json.Marshal(t)
}
func (t *DataOtherOptionChildList) Scan(value interface{}) error {
b, ok := value.([]byte)
if !ok {
return errors.New("type assertion to []byte failed")
}
return json.Unmarshal(b, &t)
}
type DataOtherOptionChild struct {
//分类1的选项key
Sort1 int `db:"sort1" json:"sort1" check:"intThan0" empty:"true"`
//分类2的选项key
Sort2 int `db:"sort2" json:"sort2" check:"intThan0" empty:"true"`
//选项名称
Name string `db:"name" json:"name" check:"name"`
//商品ID
// 可以给0,则必须声明其他项目内容
ProductID int64 `db:"product_id" json:"productID" check:"id" empty:"true"`
//选项key
Key string `db:"key" json:"key" check:"mark"`
//实际费用
PriceReal int64 `db:"price_real" json:"priceReal" check:"price" empty:"true"`
//折扣截止
PriceExpireAt string `db:"price_expire_at" json:"priceExpireAt" check:"isoTime" empty:"true"`
//折扣前费用
Price int64 `db:"price" json:"price" check:"price" empty:"true"`
//封面ID
CoverFileID int64 `db:"cover_file_id" json:"coverFileID" check:"id" empty:"true"`
//总库存
Count int `db:"count" json:"count" check:"intThan0" empty:"true"`
//商品条形码编码
Code string `db:"code" json:"code"`
}
// Value sql底层处理器
func (t DataOtherOptionChild) Value() (driver.Value, error) {
return json.Marshal(t)
}
func (t *DataOtherOptionChild) Scan(value interface{}) error {
b, ok := value.([]byte)
if !ok {
return errors.New("type assertion to []byte failed")
}
return json.Unmarshal(b, &t)
}