100
This commit is contained in:
parent
53dfa0f257
commit
fd4d6df422
BIN
db5.sqlite3
BIN
db5.sqlite3
Binary file not shown.
@ -1,6 +1,9 @@
|
|||||||
import db_connector/db_sqlite
|
import db_connector/db_sqlite
|
||||||
|
|
||||||
import ../a3pkg/models
|
import
|
||||||
|
strutils,
|
||||||
|
../a3pkg/models,
|
||||||
|
./users
|
||||||
|
|
||||||
proc close*(db: DbConn) =
|
proc close*(db: DbConn) =
|
||||||
db.close()
|
db.close()
|
||||||
@ -31,3 +34,24 @@ proc createOrder*(db: DbConn, order:Orders): int64 =
|
|||||||
|
|
||||||
proc drop*(db: DbConn) =
|
proc drop*(db: DbConn) =
|
||||||
db.exec(sql"DROP TABLE IF EXISTS orders")
|
db.exec(sql"DROP TABLE IF EXISTS orders")
|
||||||
|
|
||||||
|
proc getOrderAdmin*(db: DbConn): seq[User]=
|
||||||
|
var
|
||||||
|
row = db.getAllRows(sql"SELECT DISTINCT user_id FROM orders;")
|
||||||
|
users: seq[User]
|
||||||
|
for a, b in row:
|
||||||
|
var
|
||||||
|
u = db.getRow(sql"SELECT * FROM users WHERE id=?", b[0])
|
||||||
|
user: User
|
||||||
|
c = db.getUserOrdersAmount(parseInt(b[0]))
|
||||||
|
|
||||||
|
user.id = parseInt(u[0])
|
||||||
|
user.firstName = u[1]
|
||||||
|
user.lastName = u[2]
|
||||||
|
user.email = u[3]
|
||||||
|
user.totalQuantity = c[0]
|
||||||
|
user.totalPrice = c[1]
|
||||||
|
|
||||||
|
users.add(user)
|
||||||
|
|
||||||
|
return users
|
||||||
|
@ -58,20 +58,20 @@ proc getUser*(db: DbConn, email, password: string): User =
|
|||||||
|
|
||||||
return user
|
return user
|
||||||
|
|
||||||
proc getUserOrdersAmount*(db: DbConn, userId: int): (int, int)=
|
proc getUserOrdersAmount*(db: DbConn, userId: int): (int, float)=
|
||||||
echo userId
|
echo userId
|
||||||
var
|
var
|
||||||
row = db.getAllRows(sql"SELECT (product_id, quantity) FROM orders WHERE user_id=?", userId)
|
row = db.getAllRows(sql"SELECT * FROM orders WHERE user_id=?", userId)
|
||||||
totalQuantity = 0
|
totalQuantity = 0
|
||||||
totalPrice = 0
|
totalPrice = 0.0
|
||||||
echo row
|
echo row
|
||||||
for b, c in row:
|
for b, c in row:
|
||||||
var
|
var
|
||||||
quantity = c[1]
|
quantity = c[8]
|
||||||
row1 = db.getValue(sql"SELECT price FROM products WHERE id=?", c[0])
|
row1 = db.getValue(sql"SELECT price FROM products WHERE id=?", c[7])
|
||||||
|
|
||||||
totalQuantity = totalQuantity + parseInt(quantity)
|
totalQuantity = totalQuantity + parseInt(quantity)
|
||||||
totalPrice = totalPrice + parseInt(quantity) * parseInt(row1)
|
totalPrice = totalPrice + parseFloat(quantity) * parseFloat(row1)
|
||||||
return (totalQuantity, totalPrice)
|
return (totalQuantity, totalPrice)
|
||||||
|
|
||||||
proc getUserCartTable*(db: DbConn): seq[User]=
|
proc getUserCartTable*(db: DbConn): seq[User]=
|
||||||
|
@ -12,7 +12,7 @@ type
|
|||||||
updatedAt*: DateTime
|
updatedAt*: DateTime
|
||||||
accessLevel*: int
|
accessLevel*: int
|
||||||
totalQuantity*: int
|
totalQuantity*: int
|
||||||
totalPrice* :int
|
totalPrice* : float
|
||||||
|
|
||||||
Products* = object
|
Products* = object
|
||||||
## Product is the product model
|
## Product is the product model
|
||||||
|
@ -2,13 +2,17 @@ import
|
|||||||
mike,
|
mike,
|
||||||
nimja,
|
nimja,
|
||||||
./a3pkg/mics,
|
./a3pkg/mics,
|
||||||
./a3c/users
|
./a3c/[users, orders]
|
||||||
|
|
||||||
proc admin*(ctx: Context): string=
|
proc admin*(ctx: Context): string=
|
||||||
var
|
var
|
||||||
db = newDatabase()
|
db = newDatabase()
|
||||||
users = db.getUserCartTable()
|
users = db.getOrderAdmin()
|
||||||
|
# users = db.getUserCartTable()
|
||||||
|
|
||||||
echo users
|
# echov v
|
||||||
|
# var users = db.getUserCartTable()
|
||||||
|
|
||||||
|
# echo users
|
||||||
|
|
||||||
compileTemplateFile(getScriptDir() / "a3a" / "admin" / "index.html")
|
compileTemplateFile(getScriptDir() / "a3a" / "admin" / "index.html")
|
||||||
|
Loading…
Reference in New Issue
Block a user