|
@@ -221,24 +221,36 @@ def receive(userid):
|
|
|
async def receive(userModel : models.TransactionNft):
|
|
|
# db connect
|
|
|
db = dataset.connect('mysql://choozmo:pAssw0rd@db.ptt.cx:3306/arkcard?charset=utf8mb4')
|
|
|
+ table = db['users']
|
|
|
table2 = db['nft']
|
|
|
+ table3 = db['nftdrops']
|
|
|
|
|
|
- # input
|
|
|
+ # input and find userid
|
|
|
nftid = userModel.nftid
|
|
|
address = userModel.address
|
|
|
- result = ""
|
|
|
- if not table2.find_one(id=nftid):
|
|
|
+ result = table.find_one(useraddress=address)
|
|
|
+
|
|
|
+ # first confirm if the user exist
|
|
|
+ if not result:
|
|
|
db.close()
|
|
|
- print("error: nft not found")
|
|
|
- return {'msg': 'nft not found'}
|
|
|
+ return {'msg': 'user address not found'}
|
|
|
else:
|
|
|
- statement = 'SELECT userid FROM users WHERE useraddress ="'+address+'"'
|
|
|
- for row in db.query(statement):
|
|
|
- result = row['userid']
|
|
|
- user_obj = table2.find_one(id=nftid)
|
|
|
- user_obj['userid'] = result
|
|
|
- table2.update(dict(user_obj), ['id'])
|
|
|
+ userid = result['userid']
|
|
|
+ db.close()
|
|
|
+
|
|
|
+ # update nft owner
|
|
|
+ if table3.find_one(nftid=nftid):
|
|
|
+ data = dict(nftid=nftid, userid=userid)
|
|
|
+ table3.update(data, ['nftid'])
|
|
|
+ db.close()
|
|
|
+ elif table2.find_one(id=nftid):
|
|
|
+ data = dict(id=nftid, userid=userid)
|
|
|
+ table2.update(data, ['id'])
|
|
|
db.close()
|
|
|
+ else:
|
|
|
+ db.close()
|
|
|
+ return {'msg': 'nft not found'}
|
|
|
+ db.close()
|
|
|
return {'msg': 'OK'}
|
|
|
|
|
|
# shop handler
|
|
@@ -287,6 +299,7 @@ async def nftdrops(userModel : models.NftDrops):
|
|
|
# input對應
|
|
|
eventid = '1'
|
|
|
nftid = '101'
|
|
|
+ nftid2 = '102'
|
|
|
userid = userModel.userid
|
|
|
email = userModel.email
|
|
|
|
|
@@ -294,6 +307,7 @@ async def nftdrops(userModel : models.NftDrops):
|
|
|
if not table3.find_one(userid=userid):
|
|
|
# 新增資料
|
|
|
table3.insert(dict(eventid=eventid, nftid=nftid, userid=userid, email=email))
|
|
|
+ table3.insert(dict(eventid=eventid, nftid=nftid2, userid=userid, email=email))
|
|
|
db.close()
|
|
|
return "新增成功"
|
|
|
# 如果userid存在,回傳通知
|