-
Notifications
You must be signed in to change notification settings - Fork 2
/
order.go
307 lines (289 loc) · 9.39 KB
/
order.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
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
package six910mysql
import (
"strconv"
"time"
mdb "github.com/Ulbora/six910-database-interface"
)
/*
Six910 is a shopping cart and E-commerce system.
Copyright (C) 2020 Ulbora Labs LLC. (www.ulboralabs.com)
All rights reserved.
Copyright (C) 2020 Ken Williamson
All rights reserved.
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
//Orders
//AddOrder AddOrder
func (d *Six910Mysql) AddOrder(o *mdb.Order) (bool, int64) {
if !d.testConnection() {
d.DB.Connect()
}
var a []interface{}
a = append(a, time.Now(), o.Status, o.Subtotal, o.ShippingHandling, o.Insurance, o.Taxes, o.Total,
o.CustomerID, o.BillingAddressID, o.ShippingAddressID, o.CustomerName, o.BillingAddress,
o.ShippingAddress, o.StoreID, o.OrderNumber, o.OrderType, o.Pickup, o.Username,
o.ShippingMethodID, o.ShippingMethodName, o.FFLShippingAddressID, o.FFLShippingAddress,
o.FFLName, o.FFLLic, o.FFLExpDate, o.FFLPhone)
suc, id := d.DB.Insert(insertOrder, a...)
d.Log.Debug("suc in add Order", suc)
d.Log.Debug("id in add Order", id)
return suc, id
}
//UpdateOrder UpdateOrder
func (d *Six910Mysql) UpdateOrder(o *mdb.Order) bool {
if !d.testConnection() {
d.DB.Connect()
}
var a []interface{}
a = append(a, time.Now(), o.Status, o.Subtotal, o.ShippingHandling, o.Insurance, o.Taxes, o.Total,
o.BillingAddressID, o.ShippingAddressID, o.CustomerName, o.BillingAddress,
o.ShippingAddress, o.OrderType, o.Pickup, o.Username, o.ShippingMethodID, o.ShippingMethodName,
o.Refunded, o.FFLShippingAddressID, o.FFLShippingAddress,
o.FFLName, o.FFLLic, o.FFLExpDate, o.FFLPhone, o.ID)
suc := d.DB.Update(updateOrder, a...)
return suc
}
//GetOrder GetOrder
func (d *Six910Mysql) GetOrder(id int64) *mdb.Order {
if !d.testConnection() {
d.DB.Connect()
}
var a []interface{}
a = append(a, id)
row := d.DB.Get(getOrder, a...)
rtn := d.parseOrderRow(&row.Row)
return rtn
}
//GetOrderList GetOrderList
func (d *Six910Mysql) GetOrderList(cid int64, storeID int64) *[]mdb.Order {
if !d.testConnection() {
d.DB.Connect()
}
var rtn = []mdb.Order{}
var a []interface{}
a = append(a, cid, storeID)
rows := d.DB.GetList(getOrderByCid, a...)
if rows != nil && len(rows.Rows) != 0 {
foundRows := rows.Rows
for r := range foundRows {
foundRow := foundRows[r]
rowContent := d.parseOrderRow(&foundRow)
rtn = append(rtn, *rowContent)
}
}
return &rtn
}
//GetStoreOrderList GetStoreOrderList
func (d *Six910Mysql) GetStoreOrderList(storeID int64) *[]mdb.Order {
if !d.testConnection() {
d.DB.Connect()
}
var rtn = []mdb.Order{}
var a []interface{}
a = append(a, storeID)
rows := d.DB.GetList(getOrderForStore, a...)
if rows != nil && len(rows.Rows) != 0 {
foundRows := rows.Rows
for r := range foundRows {
foundRow := foundRows[r]
rowContent := d.parseOrderRow(&foundRow)
rtn = append(rtn, *rowContent)
}
}
return &rtn
}
//GetStoreOrderListByStatus GetStoreOrderListByStatus
func (d *Six910Mysql) GetStoreOrderListByStatus(status string, storeID int64) *[]mdb.Order {
if !d.testConnection() {
d.DB.Connect()
}
var rtn = []mdb.Order{}
var a []interface{}
a = append(a, storeID, status)
rows := d.DB.GetList(getOrderForStoreByStatus, a...)
if rows != nil && len(rows.Rows) != 0 {
foundRows := rows.Rows
for r := range foundRows {
foundRow := foundRows[r]
rowContent := d.parseOrderRow(&foundRow)
rtn = append(rtn, *rowContent)
}
}
return &rtn
}
//GetOrderCountData GetOrderCountData
func (d *Six910Mysql) GetOrderCountData(storeID int64) *[]mdb.OrderCountData {
if !d.testConnection() {
d.DB.Connect()
}
var rtn = []mdb.OrderCountData{}
var a []interface{}
a = append(a, storeID)
rows := d.DB.GetList(getOrderCountData, a...)
//d.Log.Debug("rows Order count", *rows)
if rows != nil && len(rows.Rows) != 0 {
foundRows := rows.Rows
for r := range foundRows {
foundRow := foundRows[r]
var oct mdb.OrderCountData
if len(foundRow) > 0 {
dt, err := time.Parse(dateOnlyFormat, foundRow[0])
d.Log.Debug("dt err in get Order count", err)
if err == nil {
cnt, err := strconv.ParseInt(foundRow[1], 10, 64)
d.Log.Debug("cnt err in get Order count", err)
if err == nil {
oct.OrderDate = dt
oct.OrderCount = cnt
rtn = append(rtn, oct)
}
}
}
}
}
return &rtn
}
//GetOrderSalesData GetOrderSalesData
func (d *Six910Mysql) GetOrderSalesData(storeID int64) *[]mdb.OrderSalesData {
if !d.testConnection() {
d.DB.Connect()
}
var rtn = []mdb.OrderSalesData{}
var a []interface{}
a = append(a, storeID)
rows := d.DB.GetList(getOrderSalesData, a...)
//d.Log.Debug("rows Order sales", *rows)
if rows != nil && len(rows.Rows) != 0 {
foundRows := rows.Rows
for r := range foundRows {
foundRow := foundRows[r]
var osl mdb.OrderSalesData
if len(foundRow) > 0 {
dt, err := time.Parse(dateOnlyFormat, foundRow[0])
d.Log.Debug("dt err in get Order sales", err)
if err == nil {
tot, err := strconv.ParseFloat(foundRow[1], 64)
d.Log.Debug("cnt err in get Order sales", err)
if err == nil {
osl.OrderDate = dt
osl.OrderTotal = tot
rtn = append(rtn, osl)
}
}
}
}
}
return &rtn
}
//DeleteOrder DeleteOrder
func (d *Six910Mysql) DeleteOrder(id int64) bool {
if !d.testConnection() {
d.DB.Connect()
}
var a []interface{}
a = append(a, id)
return d.DB.Delete(deleteOrder, a...)
}
func (d *Six910Mysql) parseOrderRow(foundRow *[]string) *mdb.Order {
d.Log.Debug("foundRow in get Order", *foundRow)
var rtn mdb.Order
if len(*foundRow) > 0 {
id, err := strconv.ParseInt((*foundRow)[0], 10, 64)
d.Log.Debug("id err in get Order", err)
if err == nil {
cid, oerr := strconv.ParseInt((*foundRow)[9], 10, 64)
d.Log.Debug("cid err in get Order", oerr)
if oerr == nil {
oTime, eerr := time.Parse(timeFormat, (*foundRow)[1])
d.Log.Debug("oTime err in get Order", eerr)
if eerr == nil {
uTime, _ := time.Parse(timeFormat, (*foundRow)[2])
pickup, enerr := strconv.ParseBool((*foundRow)[18])
if enerr == nil {
baid, err := strconv.ParseInt((*foundRow)[10], 10, 64)
d.Log.Debug("baid err in get Order", err)
if err == nil {
said, err := strconv.ParseInt((*foundRow)[11], 10, 64)
d.Log.Debug("said err in get Order", err)
if err == nil {
sid, err := strconv.ParseInt((*foundRow)[15], 10, 64)
d.Log.Debug("sid err in get Order", err)
if err == nil {
subtot, err := strconv.ParseFloat((*foundRow)[4], 64)
d.Log.Debug("subtot err in get Order", err)
if err == nil {
sandh, err := strconv.ParseFloat((*foundRow)[5], 64)
d.Log.Debug("sandh err in get Order", err)
if err == nil {
ins, err := strconv.ParseFloat((*foundRow)[6], 64)
d.Log.Debug("ins err in get Order", err)
if err == nil {
tax, err := strconv.ParseFloat((*foundRow)[7], 64)
d.Log.Debug("tax err in get Order", err)
if err == nil {
tot, err := strconv.ParseFloat((*foundRow)[8], 64)
d.Log.Debug("tot err in get Order", err)
if err == nil {
smid, err := strconv.ParseInt((*foundRow)[20], 10, 64)
d.Log.Debug("smid err in get Order", err)
if err == nil {
refunded, err := strconv.ParseFloat((*foundRow)[22], 64)
d.Log.Debug("refunded err in get Order", err)
if err == nil {
fflid, _ := strconv.ParseInt((*foundRow)[23], 10, 64)
d.Log.Debug("smid err in get Order", err)
rtn.ID = id
rtn.CustomerID = cid
rtn.OrderDate = oTime
rtn.Updated = uTime
rtn.Pickup = pickup
rtn.BillingAddressID = baid
rtn.ShippingAddressID = said
rtn.StoreID = sid
rtn.Subtotal = subtot
rtn.ShippingHandling = sandh
rtn.Insurance = ins
rtn.Taxes = tax
rtn.Total = tot
rtn.Refunded = refunded
rtn.FFLShippingAddressID = fflid
rtn.Status = (*foundRow)[3]
rtn.CustomerName = (*foundRow)[12]
rtn.BillingAddress = (*foundRow)[13]
rtn.ShippingAddress = (*foundRow)[14]
rtn.OrderNumber = (*foundRow)[16]
rtn.OrderType = (*foundRow)[17]
rtn.Username = (*foundRow)[19]
rtn.ShippingMethodID = smid
rtn.ShippingMethodName = (*foundRow)[21]
rtn.FFLShippingAddress = (*foundRow)[24]
rtn.FFLName = (*foundRow)[25]
rtn.FFLLic = (*foundRow)[26]
rtn.FFLExpDate = (*foundRow)[27]
rtn.FFLPhone = (*foundRow)[28]
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
return &rtn
}