def deposit(card_num, amount_of_money): """存款""" acc_path = os.path.join(USER_PATH, card_num, "account.json") acc = utils.load_file(acc_path) acc["deposit"] += amount_of_money utils.dump_to_file(acc_path, acc) system.recode_trade(card_num, "0", "0", amount_of_money)
def repayment(card_num, amount_of_money): """还款""" acc_path = os.path.join(USER_PATH, card_num, "account.json") acc = utils.load_file(acc_path) amounts_owed = acc["credit_total"] - acc["credit_balance"] if amount_of_money >= amounts_owed: acc["credit_balance"] = acc["credit_total"] acc[deposit] += (amount_of_money - amounts_owed) utils.dump_to_file(acc_path, acc) else: acc["credit_balance"] += amount_of_money utils.dump_to_file(acc_path, acc) system.recode_trade(card_num, "0", "0", amount_of_money)
def spend(card_num, card_pwd, amount_of_money): """消费""" acc_path = os.path.join(USER_PATH, card_num, "account.json") acc = utils.load_file(acc_path) if acc["state"] == 0: if card_pwd != acc["pwd"]: return "支付密码不正确" else: if acc["credit_balance"] >= amount_of_money: acc["credit_balance"] -= amount_of_money utils.dump_to_file(acc_path, acc) system.recode_trade(card_num, "1", "1", amount_of_money) else: return "额度不足" else: return "您的账户已冻结"
def transfer_accounts(to_num, amount_of_money): """转账""" global USER_INFO num = USER_INFO["username"] acc_path = os.path.join(USER_PATH, num) to_acc_path = os.path.join(USER_PATH, to_num) acc_path = os.path.join(acc_path, "account.json") to_acc_path = os.path.join(acc_path, "account.json") acc = utils.load_file(acc_path) try: to_acc = utils.load_file(to_acc_path) except Exception as e: print(e) if acc["deposit"] + acc["credit_balance"] >= amount_of_money: temp = to_acc["credit_balance"] + amount_of_money commission = 0 if acc["deposit"] >= amount_of_money: acc["deposit"] -= amount_of_money if temp <= to_acc["credit_total"]: to_acc["credit_balance"] += amount_of_money else: temp1 = temp - to_acc["credit_total"] to_acc["credit_balance"] = to_acc["credit_total"] to_acc["deposit"] += temp1 else: temp2 = amount_of_money - acc["deposit"] acc["deposit"] = 0 commission = temp2 * settings.FETCH_MONEY_RATE acc["credit_balance"] -= temp2 + commission if temp <= to_acc["credit_total"]: to_acc["credit_balance"] += amount_of_money else: temp3 = temp - to_acc["credit_total"] to_acc["credit_balance"] = to_acc["credit_total"] to_acc["deposit"] += temp3 utils.dump_to_file(acc_path, acc) utils.dump_to_file(to_acc_path, to_acc) system.recode_trade(num, "1", "1", amount_of_money, commission) system.recode_trade(to_num, "0", "0", amount_of_money) else: return "余额不足!"
def draw_cash(pwd, amount_of_money): """ 取现 """ global USER_INFO card_num = USER_INFO["username"] print(card_num) if card_num: num_path = os.path.join(USER_PATH, card_num) acc_path = os.path.join(num_path, "account.json") acc = utils.load_file(acc_path) if acc["state"] == 0: print("状态正常") if utils.encrypt(pwd) != acc["pwd"]: print("取款密码不正确") return "取款密码不正确" else: print("密码正确") amount_of_money = float(amount_of_money) if amount_of_money <= acc["deposit"]: acc["deposit"] -= amount_of_money utils.dump_to_file(acc_path, acc) print("账户修改成功") system.recode_trade(card_num, "1", "1", amount_of_money, 0) else: temp = amount_of_money - acc["deposit"] if acc["credit_balance"] >= temp: acc["deposit"] = 0 temp_final = temp + temp * settings.FETCH_MONEY_RATE acc["credit_balance"] -= temp_final utils.dump_to_file(acc_path, acc) system.recode_trade(card_num, "1", "1", amount_of_money, temp_final) else: return "额度不足" else: return "您的账户已冻结"