def freeze(*args): """ 冻结账户 """ account_id = format_input("输入修改信用卡的卡号") data = db_handle.db_handle("select * from atm where id=%s" % account_id) if not data: log_access.info("开号为[%s]不存在" % (account_id)) return data["status"] = 0 db_handle.db_handle("update atm where id=%s" % account_id, new_data=data) log_access.info("开号为[%s]已冻结" % (account_id)) print("开号为[%s]已冻结" % (account_id))
def change_pay_day(*args): """ 修改还款日期 """ account_id = format_input("输入修改信用卡的卡号") account_day = format_input("输入修改信用还款日(1-28)") data = db_handle.db_handle("select * from atm where id=%s" % account_id) if not data: log_access.info("开号为[%s]不存在" % (account_id)) return data["pay_date"] = account_day db_handle.db_handle("update atm where id=%s" % account_id, new_data=data) log_access.info("开号为[%s]修改还款日为[%s]" % (account_id, account_day)) print("开号为[%s]修改还款日为[%s]" % (account_id, account_day))
def change_credit(*args): """ 修改信用额度 """ account_id = format_input("输入修改信用卡的卡号") account_credit = format_input("输入修改信用额度数") data = db_handle.db_handle("select * from atm where id=%s" % account_id) if not data: log_access.info("开号为[%s]不存在" % (account_id)) return data["credit"] = float(account_credit) db_handle.db_handle("update atm where id=%s" % account_id, new_data=data) log_access.info("开号为[%s]修改额度为[%s]元" % (account_id, account_credit)) print("开号为[%s]修改额度为[%s]元" % (account_id, account_credit))
def transfer(user_data): """ 转账功能 """ print("-------转账提示----------------") account_id = format_input("输入转账的账号") amount = format_input("输入转账的金额") transfer_data = db_handle.db_handle("select * from atm where id=%s" % account_id) if transfer_data: user_data1 = transaction.transactions(user_data, amount, tran_type="transfer") if user_data1: user_data_new = { 'account_id': account_id, 'is_authenticated': False, 'account_data': transfer_data } transaction.transactions(user_data_new, amount, tran_type="repay") print("开号为[%s]向开号为[%s]转账[%s]元成功" % (user_data1.get("account_id"), account_id, amount)) log_access.info("开号为[%s]向开号为[%s]转账[%s]元成功" % (user_data1.get("account_id"), account_id, amount)) else: log_access.error("开号为[%s]向开号为[%s]转账[%s]元失败" \ %(user_data.get("account_id"),account_id,amount,amount)) print("开号为[%s]向开号为[%s]转账[%s]元失败" % (user_data.get("account_id"), account_id, amount, amount))
def query_info_condition2(*args): """ 查询用户详情 """ account_id = args[1] data = db_handle.db_handle("select * from atm where id=%s" % account_id) if not data: log_access.error("开号为%s的用户不存在" % (data.get("id"))) return #data=user_data.get("account_data") info=""" ----------用户信息------------------- 开 号:%s 姓 名:%s 信用额度:%s元 剩余额度:%s元 注册日期:%s 过期日期:%s 每月还款日:%s -------------------------------------- """ %(data.get("id"),data.get("name"),data.get("credit"),data.get("balance"), \ data.get("enroll_date"),data.get("expire_date"),data.get("pay_date")) print(info) log_access.info("开号为%s的用户,查询了用户信息" % (data.get("id")))
def acc_auth(account, passwd, table_name): sql = "select * from %s where account=%s" % (table_name, account) data = db_handle.db_handle(sql) if data["passwd"] == passwd: expire_date_stmap = time.mktime( time.strptime(data["expire_date"], '%Y-%m-%d')) if time.time() > expire_date_stmap or data["status"] in [1, 2]: data["status"] = 1 db_handle.db_handle("update atm where id=%s" % account, new_data=data) print("开号为%s的用户,您的信用卡已过期或冻结\n" % data["id"]) log_access.error("开号为%s的用户,您的信用卡已过期或冻结\n" % data["id"]) exit() else: return data else: log_access.info("开号为%s的用户,您输入的密码不正确\n" % data["id"])
def transactions(user_data, amount, tran_type="withdraw", **kwargs): action_dict = { "repay": "还款", "withdraw": "提现", "transfer": "转账", "consume": "消费" } data = user_data.get("account_data") amount = float(amount) if tran_type in settings.TRANSACTION_TYPE: interest = amount * settings.TRANSACTION_TYPE[tran_type]['interest'] old_balance = data['balance'] if settings.TRANSACTION_TYPE[tran_type]['action'] == 'plus': new_balance = old_balance + amount + interest elif settings.TRANSACTION_TYPE[tran_type]['action'] == 'minus': new_balance = old_balance - amount - interest #check credit if new_balance < 0: print( '''\033[31;1m您的信用额度为[%s]元,您的交易金额为[%s]元,您的剩余金额为[%s]元,交易不成功\033[0m''' % (data['credit'], (amount + interest), old_balance)) return data['balance'] = new_balance db_handle.db_handle("update atm where id=%s" % data['id'], new_data=data) bill_dict = {} bill_dict["id"] = str(data['id']) bill_dict["tran_type"] = action_dict.get(tran_type) bill_dict["amount"] = str(amount) bill_dict["interest"] = str(interest) bill_dict["action_date"] = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime()) db_handle.add_bill(bill_dict) log_transaction.info("开号:%s %s:%s 金额:%s 手续费:%s" % (data['id'], action_dict.get(tran_type), tran_type, amount, interest)) return user_data else: print("\033[31;1mTransaction type [%s] is not exist!\033[0m" % tran_type)
def query_info2(user_data): """ 用户简要信息查询 """ if not user_data.get("account_data"): user_data = db_handle.db_handle("select atm where id=%s" % user_data.get("account_id")) data = user_data.get("account_data") info="姓名为[%s]的用户,开号为[%s]额度金额变为[%s]元" \ %(data.get("name"),data.get("id"),data.get("balance")) print(info) log_access.info(info)
def query_info(user_data): """ 查询用户详情 """ if not user_data.get("account_data"): user_data = db_handle.db_handle("select atm where id=%s" % user_data.get("account_id")) data = user_data.get("account_data") info=""" ----------用户信息------------------- 开 号:%s 姓 名:%s 信用额度:%s元 剩余额度:%s元 注册日期:%s 过期日期:%s 每月还款日:%s -------------------------------------- """ %(data.get("id"),data.get("name"),data.get("credit"),data.get("balance"), \ data.get("enroll_date"),data.get("expire_date"),data.get("pay_date")) print(info) log_access.info("开号为%s的用户,查询了用户信息" % (data.get("id")))