• ATM-interface-bank


    from lib import common
    from db import db_handler

    user_logger = common.get_logger('bank')


    def check_balance(name):
    dic =db_handler.select(name)
    return dic['balance']


    def transfer_interface(from_name,toname,balance):
    if from_name==toname:
    return False,'不能转账给自己'
    to_dic =db_handler.select(toname)
    if to_dic:
    from_dic = db_handler.select(from_name)
    if from_dic['balance']>=balance:
    from_dic['balance']-=balance
    to_dic['balance']+=balance
    from_dic['bankflow'].append('%s转%s元账给了%s'%(from_name,balance,toname))
    to_dic['bankflow'].append('%s收到了%s转来的%s元'%(toname,from_name,balance))
    db_handler.save(from_dic)
    db_handler.save(to_dic)
    user_logger.info('%s转账给了%s:%s元'%(from_name,toname,balance))
    return True,'转账成功'
    else:
    return False,'余额不足'
    else:
    return False,'转账的用户名不存在'


    def repay_interface(name,balance):
    dic = db_handler.select(name)
    dic['balance']+=balance
    dic['bankflow'].append('%s还款了%s元'%(name,balance))
    db_handler.save(dic)
    user_logger.info('%s还款了%s元'%(name,balance))
    return True,'还款成功'


    def withdraw_interface(name,balance):
    dic = db_handler.select(name)
    balance1 = balance*1.05
    if dic['balance']>=balance1:
    dic['balance']-=balance
    dic['bankflow'].append('%s取走了%s元'%(name,balance))
    user_logger.info('%s取走了%s元'%(name,balance))
    db_handler.save(dic)
    return True,'取款成功'
    else:
    return False,'取款失败'


    def check_record_interface(name):
    dic = db_handler.select(name)
    return dic['bankflow']


    def consume_interface(name,cost):
    dic = db_handler.select(name)
    if dic['balance']>=cost:
    dic['balance']-=cost
    db_handler.save(dic)
    return True,'扣款成功'
    else:
    return False,'余额不足'





  • 相关阅读:
    bzoj 1054
    bzoj 1047
    bzoj 2761
    bzoj 1191
    bzoj 2748
    bzoj_1003 物流运输
    新的开始( [USACO08OCT]打井Watering Hole)
    map
    Generic Cow Protests-G——60分做法
    逆序对
  • 原文地址:https://www.cnblogs.com/wangcheng9418/p/9221762.html
Copyright © 2020-2023  润新知