fix: incorrect SQL to calculate the cost

This commit is contained in:
snsd0805 2023-06-12 23:43:35 +08:00
parent 4d24824d48
commit a1c4421448
Signed by: snsd0805
GPG Key ID: 569349933C77A854
4 changed files with 9 additions and 3 deletions

View File

@ -69,5 +69,5 @@ Once the page is loaded, you can connect your MetaMask wallet and proceed to reg
## Some Demo Screenshots
![](img/Screenshot_20230612_225920.png)
![](img/Screenshot_20230612_230551.png)
![](img/Screenshot_20230612_234213.png)
![](img/Screenshot_20230612_230948.png)

View File

@ -43,12 +43,18 @@ def process_data():
filter_str = ', '.join(filter)
query = "SELECT id, price FROM products WHERE id IN ({})".format(filter_str)
cursor.execute(query, params)
prices = cursor.fetchall()
result = cursor.fetchall()
prices = {}
for id, price in result:
prices[id] = price
amount = 0
for index, product in enumerate(data['products']):
id = product['product_id']
count = int(product['count'])
amount += count * int(prices[index][1])
print(count * int(prices[id]))
amount += (count * int(prices[id]))
cursor.execute('INSERT INTO "orders"("id","shop_id","client_addr","amount") VALUES (NULL,?,NULL,?);', (shop_id, amount))
order_id = cursor.lastrowid

Binary file not shown.

Before

Width:  |  Height:  |  Size: 140 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 138 KiB