Исправление отрицательных значений coins_add, coins_del

main
Your Name 2 weeks ago
parent 15f882085a
commit f3eb0c9435

@ -134,7 +134,7 @@ class Coins_add(BaseModel):
amount: str amount: str
@app.post('/api/coins_add/') @app.post('/api/coins_add/')
def coins_add(it: Coins_add): def coins_add(it: Coins_add):
token, id, amount = it.token, it.id, float(it.amount) token, id, amount = it.token, it.id, abs(float(it.amount))
if token_check(token): if token_check(token):
db = read() db = read()
db['id'][id]['bal'] = fix_add(db['id'][id]['bal'], amount) db['id'][id]['bal'] = fix_add(db['id'][id]['bal'], amount)
@ -150,15 +150,18 @@ class Coins_del(BaseModel):
amount: str amount: str
@app.post('/api/coins_del/') @app.post('/api/coins_del/')
def coins_del(it: Coins_del): def coins_del(it: Coins_del):
token, id, amount = it.token, it.id, float(it.amount) token, id, amount = it.token, it.id, abs(float(it.amount))
if token_check(token): if token_check(token):
db = read() db = read()
if db['id'][id]['bal'] >= amount:
db['id'][id]['bal'] = fix_sub(db['id'][id]['bal'], amount) db['id'][id]['bal'] = fix_sub(db['id'][id]['bal'], amount)
write(db) write(db)
stat_run(amount*-1) stat_run(amount*-1)
return 'OK' return 'OK'
else: else:
return 'Error' return 'Error'
else:
return 'Error'
class Coins_transfer(BaseModel): class Coins_transfer(BaseModel):
token: str token: str

Loading…
Cancel
Save