|
@@ -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}")
|
|
@@ -224,12 +231,12 @@ async def buy(userid,nftid):
|
|
|
|
|
|
if not table2.find_one(id=nftid):
|
|
|
print("error: nft not found")
|
|
|
- return {'msg': 'nft not found'}
|
|
|
+ return "該NFT商品不存在!如果有疑問,請洽網站的服務信箱!"
|
|
|
else:
|
|
|
user_obj = table2.find_one(id=nftid)
|
|
|
user_obj['userid'] = userid
|
|
|
table2.update(dict(user_obj), ['id'])
|
|
|
- return {'msg': 'OK'}
|
|
|
+ return "您已購買成功!"
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
uvicorn.run("main:app", host="0.0.0.0", port=8228, reload=True)
|