def main(): print("Welcome to atm home page!!") operation = input("Please input your operation(m > 管理 , l > 登陆):") if operation == "m": manage.atm_manage() elif operation == "l": name = input("Please input your name:") password = input("Please input your password:") login_data = auth.auth(name, password) if login_data: transaction.transaction(login_data)
def repay(user_data, transaction_log): ''' 还款功能 ''' print('当前额度:%s\n' '当前余额:%s' % (user_data['credit_limit'], user_data['balance'])) amount = input('请输入还款金额:') trans_state = transaction.transaction(user_data, 'repay', amount, transaction_log) if trans_state: print('还款成功, 当前可用余额:%s ' % user_data['balance'])
def payment(costs_amount): pay_acc_data = login.login(user_data) # print(pay_acc_data) pay_status = transaction.transaction(pay_acc_data, 'payment', costs_amount) # print(pay_status) if pay_acc_data and pay_status: logger.logger( 'transaction', pay_acc_data['account'], "账户 %s 购物消费 %s 元" % (pay_acc_data['account'], costs_amount)) return pay_acc_data, pay_status
def transfer(acc_data): acc_data = account.load_account_data(acc_data['account_id']) exit_flag = False while not exit_flag: acc_data = account.load_account_data(acc_data['id']) curr_info = '''------------ Alex Bank ------------ Credit:%s Balance:%s''' % (acc_data['id'], acc_data['balance']) print("\033[33;1m%s\033[0m" % curr_info) to_credit = input("\033[34;1m对方账号>>:\033[0m") amount = input("\033[34;1m转账金额>>:\033[0m").strip() to_acc_data = account.load_account_data(to_credit) if len(amount) > 0 and amount.isnumeric(): amount = float(amount) ack = transaction.transaction(acc_data, 'transfer', amount) ack2 = transaction.transaction(to_acc_data, 'repay', amount) if ack == "True" and ack2 == "True": print("transfer success") if amount == "b": exit_flag = True
def withdraw(user_data, transaction_log): ''' 提现功能 ''' print('当前额度:%s\n' '当前余额:%s' % (user_data['credit_limit'], user_data['balance'])) amount = input('请提现金额:') if (user_data['balance'] / 2) > int(amount): trans_state = transaction.transaction(user_data, 'withdraw', amount, transaction_log) if trans_state: print('\033[32m取现成功,当前余额:%s \033[0m' % user_data['balance']) else: print('余额不足')
def transfer(user_data): # 转账 account_info(user_data) account_data = user_data['account_data'] while True: # 录入转账目标账户 transfer_account = input("请输入您要转账的账户卡号:").strip() if transfer_account == account_data['account']: print(account_data['account']) print("请不要输入自己的账户!") return trans_acc_data = accounts.load_account(transfer_account) if trans_acc_data: break else: print("您要转账的账户 %s 不存在,请重新输入!" % transfer_account) print(trans_acc_data) while True: transfer_amount = input("请输入您要转账的金额:").strip() if transfer_amount.isdigit() or type(eval(transfer_amount)) == float: account_data, interest = transaction.transaction( account_data, 'transfer', transfer_amount) transaction.transaction(trans_acc_data, 'repayment', transfer_amount) if account_data: logger.logger( 'transaction', account_data['account'], "成功向账户 %s 转账 %s 元,手续费 %s 元" % (account_data['account'], transfer_amount, interest)) logger.logger( 'transaction', transfer_account, "账户 %s 向您转账 %s 元" % (transfer_account, transfer_amount)) print("转账操作完成,成功向 %s 转账 %s 元。您当前的剩余额度为:%s 元,本次转账收取手续费 %s 元。" % (transfer_account, transfer_amount, account_data['balance'], interest)) else: print("%s 不是一个有效的数字,请您确认是否输入正确。")
def paying(): from core import transaction if transaction.transaction(1,BUYLISTDICT['sum'],USERLOGIN): print('支付成功') with open(r'../logs/paying.log','a+') as fn: import time s = str(USERLOGIN['user_id']) + ' ' + str(USERLOGIN['username']) +' '+ str(time.strftime("%Y-%m-%d %H:%M %p", time.localtime())) + ' ' + '购物清单:' + str(ORDERDICT) + ' '+ '总额:'+ str(BUYLISTDICT['sum']) +' 支付成功!\n' fn.writelines(s) global BUYLISTDICT BUYLISTDICT['status'] = False BUYLISTDICT['sum'] = None getUserInfo(USERLOGIN['username']) return True else: print('支付失敗') return False
def repay(acc_data): acc_data = account.load_account_data(acc_data['account_id']) exit_flag = False while not exit_flag: acc_data = account.load_account_data(acc_data['id']) curr_info = '''------------ Alex Bank ------------ Credit:%s Balance:%s''' % (acc_data['id'], acc_data['balance']) print("\033[33;1m%s\033[0m" % curr_info) amount = input("\033[34;1m>>:\033[0m").strip() if len(amount) > 0 and amount.isdigit(): amount = float(amount) ack = transaction.transaction(acc_data, 'repay', amount) if ack == "True": print("repay success") if amount == "b": exit_flag = True
def consume(consume_amount): ''' 用户消费 ''' auth_data = consume_interface(user_state, access_log) if auth_data: if auth_data['user_data']['balance'] > int(consume_amount): trans_state = transaction.transaction(auth_data['user_data'], 'consume', consume_amount, transaction_log) if trans_state: print('\033[32m支付成功,当前余额:%s\033[0m' % auth_data['user_data']['balance']) auth_data['is_login'] = False return True else: auth_data['is_login'] = False print('\033[31m账号余额不足。\033[0m') return False
def transfer(user_data, transaction_log): """ 转账功能 """ print('当前信用额度:%s\n' '当前可用余额:%s' % (user_data['credit_limit'], user_data['balance'])) target_id = input('请输入目标用户ID:') amount = input('请输入转入金额:') if user_data['balance'] > int(amount): target_account = account_manage.account_load(target_id, 'common_user') if target_account: state = transaction.transaction(user_data, 'transfer', amount, transaction_log, target_account) if state: print('转账成功, 当前可用余额:%s ' % user_data['balance']) else: print('用户不存在') else: print('账户余额不足')
def withdraw(user_data): # 用于提现 account_info(user_data) account_data = user_data['account_data'] while True: withdraw_amount = input("请输入您要提取的现金额度,'b'键返回:").strip() if withdraw_amount.isdigit() or type(eval(withdraw_amount)) == float: account_data, interest = transaction.transaction( account_data, 'withdraw', withdraw_amount) if account_data: logger.logger( 'transaction', user_data['user_id'], "账户 %s 提取现金 %s 元,手续费 %s 元" % (account_data['account'], withdraw_amount, interest)) print("提现操作完成,您当前的剩余额度为:%s 元。本次提现收取手续费 %s 元。" % (account_data['balance'], interest)) return else: print("%s 不是一个有效的数字,请您确认是否输入正确。" % withdraw_amount)
def repayment(user_data): # 用于还款 account_info(user_data) # 显示当前账户的信息 account_data = user_data['account_data'] # 获取当前账户的信息 print("您还需归还的金额为 %s 元。" % float((account_data['credit']) - float(account_data['balance']))) while True: if account_data['credit'] == account_data['balance']: print("您的欠款已结清,无需还款!") break repay_amount = input("请输入您想要归还的金额,'b'键返回:") if repay_amount.isdigit() or type( eval(repay_amount)) == float: # 如果输入的是整数或浮点数 account_data, interest = transaction.transaction( account_data, 'repayment', repay_amount) if account_data: logger.logger( 'transaction', user_data['user_id'], "账户 %s 还款 %s 元" % (account_data['account'], repay_amount)) print("归还操作完成,您当前的剩余额度为:%s 元。" % account_data['balance']) return else: print("%s 不是一个有效的数字,请您确认是否输入正确。" % repay_amount)
def getMomey(): from core import transaction if transaction.transaction(2, USERLOGIN): getUserInfo(USERLOGIN['username']) return True