Explorar o código

Merge branch 'master' of http://git.choozmo.com:3000/choozmo/ArkCard-Linebot into master

jeter20131220 %!s(int64=3) %!d(string=hai) anos
pai
achega
cc96d27184

BIN=BIN
ArkCard-web/qrcode/U23264a4a3b20c3bf7bd3936bb59243f4.png


BIN=BIN
ArkCard-web/qrcode/U80198b20860c34a6c8b9463f9e5cb125.png


BIN=BIN
ArkCard-web/qrcode/Ubcf31adc132d8ca77146371e0a85cc60.png


BIN=BIN
__pycache__/main.cpython-38.pyc


+ 51 - 14
main.py

@@ -77,7 +77,7 @@ def handle_follow(event):
         qr.make(fit=True)
 
         img_qr = qr.make_image(fill='black', back_color='white')
-        filename = "qrcode/" + real_user_id + '.png'
+        filename = "/var/www/ArkCard-Linebot/ArkCard-web/qrcode/" + real_user_id + '.png'
         img_save = img_qr.save(filename)
 
         # add to db
@@ -119,14 +119,14 @@ def message(event):
                 alt_text="Receive",
                 template=button_template_message))
 
-    elif '我的NFT收藏' in event.message.text:
+    elif 'NFT商店' in event.message.text:
         button_template_message = ButtonsTemplate(
             title=' ',
-            text='點擊並打開收藏頁面,就可以查看所有的收藏品哦!',
+            text='點擊並打開NFT商品頁,就可以購買您所想要的NFT商品哦!',
             actions=[
                 URITemplateAction(
-                    label='打開我的NFT收藏頁面',
-                    uri='http://ark.cards/collect.html?' + event.source.user_id),])
+                    label='打開NFT商品頁面',
+                    uri='http://ark.cards/shop.html?' + event.source.user_id),])
         line_bot_api.reply_message(
             event.reply_token,
             TemplateSendMessage(
@@ -152,16 +152,23 @@ def message(event):
 def collection(userid):
     # db connect
     db = dataset.connect('mysql://choozmo:pAssw0rd@db.ptt.cx:3306/arkcard?charset=utf8mb4')
+    table1 = db['users']
+    table2 = db['nft']
 
-    xname = userid
-    sql = 'SELECT a.* FROM nft a INNER JOIN (SELECT userid FROM users WHERE userid="'+xname+'") b ON b.userid = a.userid'
-    result = db.query(sql)
-    rows = {}
-    i = 0
-    for row in result:
-        rows[i] = row
-        i += 1
-    return rows
+    if table1.find_one(userid=userid) and not table2.find_one(userid=userid):
+        return "您尚未擁有NFT商品,歡迎前往NFT商店購買!"
+    elif not table2.find_one(userid=userid):
+        return "使用者不存在"
+    else:
+        xname = userid
+        sql = 'SELECT a.* FROM nft a INNER JOIN (SELECT userid FROM users WHERE userid="' + xname + '") b ON b.userid = a.userid'
+        result = db.query(sql)
+        rows = {}
+        i = 0
+        for row in result:
+            rows[i] = row
+            i += 1
+        return rows
 
 # receive handler
 @app.get("/receive/{userid}")
@@ -201,5 +208,35 @@ async def receive(userModel : models.TransactionNft):
         table2.update(dict(user_obj), ['id'])
     return {'msg': 'OK'}
 
+# shop handler
+@app.get("/shop/{userid}")
+def buy(userid):
+    # db connect
+    db = dataset.connect('mysql://choozmo:pAssw0rd@db.ptt.cx:3306/arkcard?charset=utf8mb4')
+
+    sql = 'SELECT * FROM nft WHERE userid IS NULL LIMIT 5'
+    result = db.query(sql)
+    rows = {}
+    i = 0
+    for row in result:
+        rows[i] = row
+        i += 1
+    return rows
+
+@app.get("/buy/{userid}/{nftid}")
+async def buy(userid,nftid):
+    # db connect
+    db = dataset.connect('mysql://choozmo:pAssw0rd@db.ptt.cx:3306/arkcard?charset=utf8mb4')
+    table2 = db['nft']
+
+    if not table2.find_one(id=nftid):
+        print("error: nft not found")
+        return "該NFT商品不存在!如果有疑問,請洽網站的服務信箱!"
+    else:
+        user_obj = table2.find_one(id=nftid)
+        user_obj['userid'] = userid
+        table2.update(dict(user_obj), ['id'])
+    return "您已購買成功!"
+
 if __name__ == '__main__':
     uvicorn.run("main:app", host="0.0.0.0", port=8228, reload=True)