From aba40a5445c26f40308741757f501d4fb2d59a96 Mon Sep 17 00:00:00 2001 From: snsd0805 Date: Mon, 12 Jun 2023 16:25:56 +0800 Subject: [PATCH] feat: shop log fix: update client address when paying --- backend/main.py | 21 +++++++- src/router/index.js | 12 +++++ src/views/OrderView.vue | 109 ++++++++++++++++++++++++++++++++++++++ src/views/PaymentView.vue | 7 +++ src/views/ShopLogView.vue | 92 ++++++++++++++++++++++++++++++++ 5 files changed, 240 insertions(+), 1 deletion(-) create mode 100644 src/views/OrderView.vue create mode 100644 src/views/ShopLogView.vue diff --git a/backend/main.py b/backend/main.py index d282ca4..5550d25 100644 --- a/backend/main.py +++ b/backend/main.py @@ -84,16 +84,35 @@ def get_order(id): }) # shop name - cursor.execute("SELECT `address`, `name`, `amount` FROM `shops`, `orders` WHERE `orders`.`shop_id`=`shops`.`id` and `orders`.`id`= ?", (id, )) + cursor.execute("SELECT `address`, `name`, `amount`, `client_addr` FROM `shops`, `orders` WHERE `orders`.`shop_id`=`shops`.`id` and `orders`.`id`= ?", (id, )) result = cursor.fetchone() ans['shop'] = { 'name': result[1], 'address': result[0] } ans['amount'] = str(result[2]) + ans['client'] = result[3] return jsonify(ans) +@app.route('/order/', methods=['PATCH']) +def update_client(id): + client = request.get_json()['client'] + + db = sqlite3.connect(DATABASE) + cursor = db.cursor() + + ans = {} + + # products + cursor.execute("UPDATE `orders` SET `client_addr`=? WHERE `id`=?", (client, id )) + + db.commit() + db.close() + + return jsonify({'status': 'OK'}) + + @app.route('/shop/check', methods=['POST']) def shop_check(): address = request.get_json()['address'] diff --git a/src/router/index.js b/src/router/index.js index 99f639d..673f024 100644 --- a/src/router/index.js +++ b/src/router/index.js @@ -10,6 +10,8 @@ import ClientPayView from '../views/ClientPayView.vue' import PaymentView from '../views/PaymentView.vue' import ShopPayView from '../views/ShopPayView.vue' import ShopPayQRcodeView from '../views/ShopPayQRcodeView.vue' +import ShopLogView from '../views/ShopLogView.vue' +import OrderView from '../views/OrderView.vue' const router = createRouter({ history: createWebHistory(import.meta.env.BASE_URL), @@ -69,6 +71,16 @@ const router = createRouter({ name: 'shopayqrcode', component: ShopPayQRcodeView }, + { + path: '/shop/log', + name: 'shopaylog', + component: ShopLogView + }, + { + path: '/order/:id', + name: 'order', + component: OrderView + }, ] }) diff --git a/src/views/OrderView.vue b/src/views/OrderView.vue new file mode 100644 index 0000000..c6e0706 --- /dev/null +++ b/src/views/OrderView.vue @@ -0,0 +1,109 @@ + + + diff --git a/src/views/PaymentView.vue b/src/views/PaymentView.vue index 79c2098..28dbece 100644 --- a/src/views/PaymentView.vue +++ b/src/views/PaymentView.vue @@ -76,6 +76,13 @@ export default { // await this.bank.methods.pay(this.number, this.shop.address, this.amountWei).send({ from: this.clientAddr }) try { await this.bank.methods.pay(this.orderId, this.shop.address, this.amountWei).send({ from: this.clientAddr }) + await fetch(import.meta.env.VITE_BACKEND_PREFIX+"/order/"+this.orderId, { + method: 'PATCH', + headers: { + 'Content-Type': 'application/json' + }, + body: JSON.stringify({'client': this.clientAddr}) + }) this.link = '/client/info' this.msg = '支付成功!
已經支付'+this.amount+" ETH 給"+this.shop.name+" ("+this.shop.address+")" this.successModalStatus = true diff --git a/src/views/ShopLogView.vue b/src/views/ShopLogView.vue new file mode 100644 index 0000000..43b9309 --- /dev/null +++ b/src/views/ShopLogView.vue @@ -0,0 +1,92 @@ + + +