Python开发程序:ATM+购物商城

时间:2020-12-19 06:01:08

一、程序要求

模拟实现一个ATM + 购物商城程序

  1. 额度 15000或自定义
  2. 实现购物商城,买东西加入 购物车,调用信用卡接口结账
  3. 可以提现,手续费5%
  4. 每月22号出账单,每月10号为还款日,过期未还,按欠款总额 万分之5 每日计息
  5. 支持多账户登录
  6. 支持账户间转账
  7. 记录每月日常消费流水
  8. 提供还款接口
  9. ATM记录操作日志
  10. 提供管理接口,包括添加账户、用户额度,冻结账户等。。。
  11. 用户认证用装饰器

二、程序code

程序说明:

## ATM信用卡购物模拟程序

### 作者介绍:
* author:lzl
### 博客地址:
* http://www.cnblogs.com/lianzhilei/p/5770672.html
* http://www.cnblogs.com/lianzhilei/p/5786223.html(程序完整流程图) ### 功能介绍:
模拟实现一个ATM + 购物商城程序
额度 15000或自定义
实现购物商城,买东西加入 购物车,调用信用卡接口结账
可以提现,手续费5%
支持多账户登录
支持账户间转账
记录每月日常消费流水
提供还款接口
ATM记录操作日志
提供管理接口,包括添加账户、用户额度,冻结账户等。。。
用户认证用装饰器 ### 目录结构: Day4
├── Credit_card-shopping
├── README.md
├── core #入口程序目录
│ ├── __init__.py
│ └── main.py #入口程序(启动程序)
├── conf #配置文件目录
│ ├── __init__.py
│ └── setting.py
├── modules #程序核心目录
│ ├── __init__.py
│ ├── admincenter.py #管理模块
│ ├── authentication.py #认证模块
│ ├── creditcard.py #信用卡模块
│ ├── shopping.py #购物模块
├── database #程序数据库
│ ├── creditcard_dict #信用卡数据库
│ ├── creditcard_record #信用卡流水记录数据库
│ ├── details_tip #提示信息
│ ├── product_list #商城产品数据库
│ └── shopping_car #购物车数据库
│ ├── shopping_record #购物记录
│ └── users_dict #用户数据库
└── log
├── __init__.py
└── log #待扩展.... ### 运行说明: * 用户、信用卡信息数据库已经建立好
------用户:zhangsan 密码:123 ##测试用户,对所有的用户环节进行过测试,已存在购物信息,消费记录等
------用户:zhaosi 密码:123 ##初始账号,暂无任何记录
------用户:wangwu 密码:123 ##初始账号,暂无任何记录 ------信用卡:888888 密码:123 ##测试信用卡,对所有的信用卡环节进行过测试,已存在余额变动,账单流水等
------信用卡:666666 密码:123 ##初始信用卡账号,暂无任何记录 ------管理中心用户:admin 密码:admin * 目录结构保持一致,开始启动mian.py 一、主程序Credit_card-shopping开始
1、把admincenter,shopping,authentication,creditcard目录加载到系统
2、进入购物模拟程序,选择相应的模式
3、循环菜单
(1)、输入1,加载authentication.user_auth()进行系统账号认证,然后调用模块shopping,进入商城购物
(2)、输入2,加载authentication.creditcard_auth()进行信用卡认证,认证通过后调用creditcard模块,信用卡操作
(3)、输入3,加载authentication.admincenter_auth()进行信用卡认证,认证通过后调用admincenter模块,管理操作
(4)、输入q, 程序终止,退出程序
4、菜单1:shopping商城
(1)、加载user_auth()函数进行用户认证,用户认证通过后进行购物中心
(2)、输入值为1,加载shopping.Shopping_mall()函数,进行商品选购,选购的商品会加入到购物车,结束购物按b返回
(3)、输入值为2,加载shopping.Shopping_car()函数,查看当前用户的购物车数据库数据库,之前购物商场里选择的商品,
会在此显示,如果没进行购物,会显示为空,另当购物结算完成后,购物车会清空,商品记录到消费记录,按b返回,按f清空
(4)、输入值为3,加载 shopping.Pay_shopping(current_user)函数,询问是否要进行结账,对购物车商品进行购买;选择
结算操作,系统会加载账号是否绑定了信用卡,如果未绑定,会提示需到个人中心绑定才能结算;如果进行了绑定,加载
Auth_creditcard(creditcard)函数进行信用卡密码认证;认证成功加载Shoppingcar_record(current_user,list)、
Creditcard_record(creditcard, value)、Empty_shopping_car()函数进行信用卡流水,用户消费流水,购物车清空操作
(5)、输入值为4,进入个人中心设置,进入循环菜单:
①、输入1,加载shopping.Catcar_record(current_user)函数,进行当前用户的购物历史记录查看,无购物则为空,购物
记录用时间进行分割进行显示,按b返回
②、输入2,加载shopping.Updata_password(current_user)函数,选择是否对密码修改,输入y,输入账号原来的密码,匹配
成功,输入新的密码,再次输入新的密码,两次密码匹配成功,修改成功,否则修改失败;按b返回
③、输入3,加载shopping.Updata_address(current_user)函数,选择是否对收货地址进行修改,输入y,输入新的地址,保存
默认地址为none,按b返回
④、输入4,加载shopping.Link_creditcard(current_user)函数,选择是否进行信用卡绑定,默认为为绑定;选择y,输入信用卡
卡号,加载信用卡数据库进行匹配,如果信用卡存在绑定成功,否则失败,按b返回
⑤、输入b,返回上一级
(6)、输入值为b,返回上一级菜单 5、菜单2:信用卡中心
(1)、加载creditcard_auth()函数进行信用卡认证,认证通过后进入信用卡中心
(2)、输入值为1,加载creditcard.My_creditcard(current_creditcard)函数,查看当前信用卡卡号、额度、提现额度、持卡人,按b返回
(3)、输入值为2,加载creditcard.Cash_advance(current_creditcard)函数,进行现金提现,显示卡号、额度、可提现金额,还有取现具体
计算方式,输入提现的金额,不能大于可提现金额,也不可大于额度金额;提现成功,按b返回;提现是调用Creditcard_record
(current_creditcard, record)函数,进行信用卡流水记录
(4)、输入值为3,加载creditcard.Transfer(current_creditcard)函数,进入转账选项,选择确定转账;输入转账对方的账号,再次输入
转账对方账号,两次一致;输入转账金额,不大于当前额度,全部通过,转账成功;然后调用Creditcard_record(current_creditcard, record)
函数进行流水记录,否则提示转账失败,按b返回
(5)、输入值为4,加载creditcard.Repayment(current_creditcard))函数,对当前信用卡进行还款,输入正确的金额数字,还款成功,调用
Creditcard_record(current_creditcard, record)进行流水记录,否则还款失败,按b返回
(6)、输入值为5,加载creditcard.Catcard_record(current_creditcard)函数,打印当前信用卡账户流水账的日期,输入要查看的流水日期
匹配后打印日期当天的所有流水记录(按照时间的先后顺序),否则打印失败,重新输入,按b返回;没有进行过交易的卡号为空
(7)、输入值为b,返回上一级菜单 6、菜单3:管理中心
(1)、加载admincenter_auth()函数进行管理认证,认证通过后进入管理中心,显示管理菜单
(2)、输入值为1,加载admincenter.User_create()函数,打印当前已有账号,开始进行系统账号创建,询问是否进程新用户创建;选择y,开始创建用户
输入要创建的用户名,输入密码,如果创建的用户不存在,新建用户创建成功;否则失败,另输入的用户名不能为空,按b返回;打印当前最新用户列表
(3)、输入值为2,加载 admincenter.Lock_user()函数,打印当前用户列表,以及当前的锁定状态;输入要锁定的用户名,对已有的账号进行锁定,输入的
账号不存在,锁定失败;输入的账号存在,但是当前已经被锁定,锁定失败;账号存在,未被锁定,显示锁定成功;打印当前所有用户的锁定状态,锁定
高亮显示,被锁定的用户不能进行系统登录。按b返回
(4)、输入值为3,加载 admincenter.Unlock_user()函数,打印当前用户列表,以及当前的锁定状态;输入要解锁的用户名,对已有的账号进行解锁,输入的
账号不存在,解锁失败;输入的账号存在,但是当前未被被锁定,解锁失败;账号存在,之前被锁定,显示解锁成功;打印当前所有用户的锁定状态,锁定
高亮显示,被锁定的用户不能进行系统登录。按b返回
(5)、输入值为4,加载admincenter.Creditcard_create()函数,打印当前已有信用卡,开始进行系统信用卡发行,询问是否进程信用卡创建;选择y,开始发行信用卡
输入要创建的信用卡卡号,输入密码,如果创建的信用卡不存在,新建信用卡发行成功;否则失败,另输入的信用卡必须为6位数数字,不能重合,发行过
的信用卡不能在此进行发;按b返回,打印当前最新信用卡列表
(6)、输入值为5,加载admincenter.Lock_creditcard())函数,打印当前信用卡列表,以及当前的冻结状态;输入要冻结的信用卡卡号,对已有的信用卡进行冻结
输入的信用卡卡号不存在,冻结失败;输入的信用卡卡号存在,但是当前已经被冻结,冻结失败;账号存在,未被冻结,显示冻结成功;打印当前所有信用卡卡号的
冻结状态,被冻结的卡号高亮显示,被冻结的用户不能进行信用卡登录,不能进行购物消费。按b返回
(7)、输入值为6,加载admincenter.Unlock_creditcard())函数,打印当前信用卡列表,以及当前的冻结状态;输入要解冻的信用卡卡号,对已有的信用卡进行解冻
输入的信用卡卡号不存在,解冻失败;输入的信用卡卡号存在,但是当前未被冻结,解冻失败;账号存在,已经被冻结,显示解冻成功;打印当前所有信用卡卡号的
冻结状态,被冻结的卡号高亮显示,被冻结的用户不能进行信用卡登录,不能进行购物消费。按b返回
(8)、输入值为7,加载admincenter.Updata_limit()函数,打印当前信用卡账户账号,目前可用额度,取现额度,选择是否进行额度调整;选择y,进行额度调整,
输入要调整额度的信用卡卡号,6为数字,如果输入的信用卡不存在,提示错误;输入已有的信用卡开号,输入新的额度(5000以上),显示额度调整成功,再此
打印最新的信用卡账户账号,目前可用额度,取现额度列表;按b返回
(9)、输入值为b,返回上一级菜单 7 关于信用卡额度,取现额度,可以取现额度:
①信用卡默认取现额度为信用卡额度的50%(此系统默认取现额度为7500)
②信用卡进行消费时(未取现),取现额度不会变化
③信用卡额度低于取现额度时,可取现金额以当前额度为准(可取现金额=当前额度*0.95)
④取现额度只有两种状况会发生变化,一种进行取现,第二是对信用卡额度进行调整
⑤每次取现扣除5%的手续费
总结:信用卡额度为总共可消费额度,取现额度为理论上可取现额度,可取现额度为当前真正可以取现的额度(会出现信用卡额度低于取现额度的可能
此时已信用卡额度为准,另有手续费要加收,所以当前的额度不能全部取完,要扣除5%的手续费,此时可取现额度为额度的95%)

readme

程序效果:

Python开发程序:ATM+购物商城

系统目录结构:

### 目录结构:

    Day4
├── Credit_card-shopping
├── README.md
├── core #入口程序目录
│ ├── __init__.py
│ └── main.py #入口程序(启动程序)
├── conf #配置文件目录
│ ├── __init__.py
│ └── setting.py
├── modules #程序核心目录
│ ├── __init__.py
│ ├── admincenter.py #管理模块
│ ├── authentication.py #认证模块
│ ├── creditcard.py #信用卡模块
│ ├── shopping.py #购物模块
├── database #程序数据库
│ ├── creditcard_dict #信用卡数据库
│ ├── creditcard_record #信用卡流水记录数据库
│ ├── details_tip #提示信息
│ ├── product_list #商城产品数据库
│ └── shopping_car #购物车数据库
│ ├── shopping_record #购物记录
│ └── users_dict #用户数据库
└── log
├── __init__.py
└── log #待扩展....

 cord区域:

1、主程序core目录下的main.py:

#!/usr/bin/env python
# -*- coding:utf-8 -*-
#-Author-Lian
import sys,os #程序主目录
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
#添加环境变量
sys.path.append(BASE_DIR) from modules import admincenter,shopping,authentication,creditcard while True:
print("\33[35;1m欢迎进入信用卡购物模拟程序\33[0m".center(50, "#"),
"\n1 购物中心\n"
"2 信用卡中心\n"
"3 后台管理\n"
"q 退出程序\n")
choice_id = input("\33[34;0m选择要进入模式的ID\33[0m:") if choice_id == "":
res = authentication.user_auth()
if res != None :
if res[0] == "True":
current_user = res[1]
shopping.Empty_shopping_car()
while True:
print("\33[36;1m欢迎进入购物中心\33[0m".center(50,"*"),
"\n1 购物商场\n"
"2 查看购物车\n"
"3 购物结算\n"
"4 个人中心\n"
"b 返回\n")
choice_id = input("\33[34;0m选择要进入模式的ID\33[0m:")
if choice_id == "":
shopping.Shopping_mall()
elif choice_id == "":
shopping.Shopping_car()
elif choice_id == "":
shopping.Pay_shopping(current_user)
elif choice_id == "":
while True:
print("\33[33;1m个人中心\33[0m".center(50, "*"),
"\n1 购物历史记录\n"
"2 修改登录密码\n"
"3 修改个人信息\n"
"4 修改行用卡绑定\n"
"b 返回\n")
choice_id = input("\33[34;0m选择要进入模式的ID\33[0m:")
if choice_id == "":
shopping.Catcar_record(current_user)
elif choice_id == "":
shopping.Updata_password(current_user)
elif choice_id == "":
shopping.Updata_address(current_user)
elif choice_id == "":
shopping.Link_creditcard(current_user)
elif choice_id == "b":
break
else:
print("\33[31;0m输入的ID无效,请重新选择\33[0m")
elif choice_id == "b":
break
else:
print("\33[31;0m输入的ID无效,请重新选择\33[0m") elif choice_id == "":
res = authentication.creditcard_auth()
if res != None:
if res[0] == "True":
current_creditcard= res[1]
while True:
print("\33[36;1m信用卡中心\33[0m".center(50, "*"),
"\n1 我的信用卡\n"
"2 提现\n"
"3 转账\n"
"4 还款\n"
"5 流水记录\n"
"b 返回\n")
choice_id = input("\33[34;0m选择要进入模式的ID\33[0m:")
if choice_id == "":
creditcard.My_creditcard(current_creditcard)
elif choice_id == "":
creditcard.Cash_advance(current_creditcard)
elif choice_id == "":
creditcard.Transfer(current_creditcard)
elif choice_id == "":
creditcard.Repayment(current_creditcard)
elif choice_id == "":
creditcard.Catcard_record(current_creditcard)
elif choice_id == "b":
break
else:
print("\33[31;0m输入的ID无效,请重新选择\33[0m") elif choice_id == "":
res = authentication.admincenter_auth()
if res != None:
while True:
print("\33[36;1m管理中心\33[0m".center(50, "*"),
"\n1 创建账号\n"
"2 锁定账号\n"
"3 解锁账号\n"
"4 发行信用卡\n"
"5 冻结信用卡\n"
"6 解冻信用卡\n"
"7 提升信用卡额度\n"
"b 返回\n")
choice_id = input("\33[34;0m选择要进入模式的ID\33[0m:")
if choice_id == "":
admincenter.User_create()
elif choice_id == "":
admincenter.Lock_user()
elif choice_id == "":
admincenter.Unlock_user()
elif choice_id == "":
admincenter.Creditcard_create()
elif choice_id == "":
admincenter.Lock_creditcard()
elif choice_id == "":
admincenter.Unlock_creditcard()
elif choice_id == "":
admincenter.Updata_limit()
elif choice_id == "b":
break
else:
print("\33[31;0m输入的ID无效,请重新选择\33[0m") elif choice_id == "q":
break else:
print("\33[31;0m输入的ID无效,请重新选择\33[0m")

main.py

2、modules目录下的模块:

①、管理中心模块admincenter.py   

#!/usr/bin/env python
# -*- coding:utf-8 -*-
#-Author-Lian import os,json BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) '''数据库文件相对路径'''
__db_users_dict = BASE_DIR + r"\database\users_dict"
__db_creditcard_dict = BASE_DIR + r"\database\creditcard_dict" '''创建用户'''
def User_create(address="None",locked=0,creditcard=0):
while True:
print("开始创建用户".center(50,"-"))
with open(__db_users_dict, "r+") as f_users_dict:
users_dict = json.loads(f_users_dict.read())
for key in users_dict:
print("系统已有用户 【%s】" % (key))
if_create = input("\n\33[34;0m是否创建新的用户 确定【y】/返回【b】\33[0m:")
if if_create == "y":
username = input("\33[34;0m输入要添加账户的用户名:\33[0m")
password = input("\33[34;0m输入添加账户的密码:\33[0m")
if username not in users_dict.keys():
if len(username.strip()) > 0:
if len(password.strip()) > 0:
users_dict[username] = {"username":username,"password":password,"creditcard":creditcard,"address":address,
"locked":locked}
dict = json.dumps(users_dict)
f_users_dict.seek(0)
f_users_dict.truncate(0)
f_users_dict.write(dict)
print("\33[31;1m创建用户 %s 成功\33[0m\n"%(username))
else:
print("\33[31;0m输入的密码为空\33[0m\n")
else:
print("\33[31;0m输入的用户名为空\33[0m\n")
else:
print("\33[31;0m用户名 %s 已经存在\33[0m\n"%(username))
if if_create == "b":
break '''发行信用卡'''
def Creditcard_create(limit=15000,locked=0):
while True:
print("发行信用卡".center(50, "-"))
with open(__db_creditcard_dict, "r+") as f_creditcard_dict:
creditcard_dict = json.loads(f_creditcard_dict.read())
for key in creditcard_dict:
print("系统已有信用卡 【%s】 \t持卡人 【%s】" % (key,creditcard_dict[key]["personinfo"]))
if_create = input("\n\33[34;0m是否发行新的信用卡 确定【y】/返回【b】\33[0m:")
if if_create == "y":
creditcard = input("\33[34;0m输入要发行信用卡卡号(6位数字):\33[0m")
if creditcard not in creditcard_dict.keys():
if creditcard.isdigit() and len(creditcard) == 6:
password = input("\33[34;0m输入要发行信用卡的密码:\33[0m")
if len(password.strip()) > 0:
personinfo = input("\33[34;0m输入要发行信用卡申请人:\33[0m")
if len(personinfo.strip()) > 0:
creditcard_dict[creditcard] = {"creditcard":creditcard, "password":password, "personinfo":personinfo,
"limit":limit,"limitcash":limit//2,"locked":locked,"deflimit":limit}
dict = json.dumps(creditcard_dict)
f_creditcard_dict.seek(0)
f_creditcard_dict.truncate(0)
f_creditcard_dict.write(dict)
print("\33[31;0m发行信用卡 %s 成功 额度 %s\33[0m\n"%(creditcard,limit))
else:
print("\33[31;0m信用卡申请人不能为空\33[0m\n")
else:
print("\33[31;0m输入的密码为空\33[0m\n")
else:
print("\33[31;0m信用卡 %s 卡号不符合规范\33[0m\n" % (creditcard))
else:
print("\33[31;0m信用卡 %s 已经存在\33[0m\n" % (creditcard))
if if_create == "b":
break '''锁定用户'''
def Lock_user():
while True:
print("\33[32;0m锁定用户\33[0m".center(50, "-"))
with open(__db_users_dict, "r+") as f_users_dict:
users_dict = json.loads(f_users_dict.read())
for key in users_dict:
if users_dict[key]["locked"] == 0:
print("系统用户 【%s】\t\t锁定状态:【未锁定】"%(key))
else:
print("系统用户 【%s】\t\t锁定状态:\33[7m【已锁定】\33[0m" % (key))
if_lock = input("\n\33[34;0m是否进行用户锁定 确定【y】/返回【b】\33[0m:")
if if_lock == "y":
lock_user = input("\33[34;0m输入要锁定的用户名\33[0m:")
if lock_user in users_dict.keys():
if users_dict[lock_user]["locked"] == 0:
users_dict[lock_user]["locked"] = 1
dict = json.dumps(users_dict)
f_users_dict.seek(0)
f_users_dict.truncate(0)
f_users_dict.write(dict)
print("\33[31;1m用户 %s 锁定成功\33[0m\n" % (lock_user))
else:
print("\33[31;0m用户 %s 锁定失败 之前已经被锁定\33[0m\n" % (lock_user))
else:
print("\33[31;0m用户 %s 不存在\33[0m\n"%(lock_user))
if if_lock == "b":
break '''解锁用户'''
def Unlock_user():
while True:
print("\33[32;0m解锁用户\33[0m".center(50, "-"))
with open(__db_users_dict, "r+") as f_users_dict:
users_dict = json.loads(f_users_dict.read())
for key in users_dict:
if users_dict[key]["locked"] == 0:
print("系统用户 【%s】\t\t锁定状态:【未锁定】" % (key))
else:
print("系统用户 【%s】\t\t锁定状态:\33[7m【已锁定】\33[0m" % (key))
if_lock = input("\n\33[34;0m是否进行用户解锁 确定【y】/返回【b】\33[0m:")
if if_lock == "y":
unlock_user = input("\33[34;0m输入要解锁的用户名\33[0m:")
if unlock_user in users_dict.keys():
if users_dict[unlock_user]["locked"] == 1:
users_dict[unlock_user]["locked"] = 0
dict = json.dumps(users_dict)
f_users_dict.seek(0)
f_users_dict.truncate(0)
f_users_dict.write(dict)
print("\33[31;1m用户 %s 解锁成功\33[0m\n" % (unlock_user))
else:
print("\33[31;0m用户 %s 解锁失败 用户未被锁定\33[0m\n" % (unlock_user))
else:
print("\33[31;0m用户 %s 不存在\33[0m\n"%(unlock_user))
if if_lock == "b":
break '''冻结信用卡'''
def Lock_creditcard():
while True:
print("\33[32;0m冻结信用卡\33[0m".center(50, "-"))
with open(__db_creditcard_dict, "r+") as f_creditcard_dict:
creditcard_dict = json.loads(f_creditcard_dict.read())
for key in creditcard_dict:
if creditcard_dict[key]["locked"] == 0:
print("信用卡 【%s】\t\t冻结状态:【未冻结】" % (key))
else:
print("信用卡 【%s】\t\t冻结状态:\33[7m【已冻结】\33[0m" % (key))
if_Unlock = input("\n\33[34;0m是否进行信用卡冻结 确定【y】/返回【b】\33[0m:")
if if_Unlock == "y":
creditcard = input("\33[34;0m输入要冻结的信用卡卡号\33[0m:")
if creditcard in creditcard_dict.keys():
if creditcard_dict[creditcard]["locked"] == 0:
creditcard_dict[creditcard]["locked"] = 1
dict = json.dumps(creditcard_dict)
f_creditcard_dict.seek(0)
f_creditcard_dict.truncate(0)
f_creditcard_dict.write(dict)
print("\33[31;1m信用卡 %s 冻结成功\33[0m\n" % (creditcard))
else:
print("\33[31;0m信用卡 %s 冻结失败 之前已经被冻结\33[0m\n" % (creditcard))
else:
print("\33[31;0m信用卡 %s 不存在\33[0m\n" %(creditcard))
if if_Unlock == "b":
break '''解冻信用卡'''
def Unlock_creditcard():
while True:
print("\33[32;0m解冻信用卡\33[0m".center(50, "-"))
with open(__db_creditcard_dict, "r+") as f_creditcard_dict:
creditcard_dict = json.loads(f_creditcard_dict.read())
for key in creditcard_dict:
if creditcard_dict[key]["locked"] == 0:
print("信用卡 【%s】\t\t冻结状态:【未冻结】" % (key))
else:
print("信用卡 【%s】\t\t冻结状态:\33[7m【已冻结】\33[0m" % (key))
if_Unlock = input("\n\33[34;0m是否进行信用卡解冻 确定【y】/返回【b】\33[0m:")
if if_Unlock == "y":
creditcard = input("\33[34;0m输入要解冻的信用卡卡号\33[0m:")
if creditcard in creditcard_dict.keys():
if creditcard_dict[creditcard]["locked"] == 1:
creditcard_dict[creditcard]["locked"] = 0
dict = json.dumps(creditcard_dict)
f_creditcard_dict.seek(0)
f_creditcard_dict.truncate(0)
f_creditcard_dict.write(dict)
print("\33[31;1m信用卡 %s 解冻成功\33[0m\n" % (creditcard))
else:
print("\33[31;0m信用卡 %s 解冻失败 之前未被冻结\33[0m\n" % (creditcard))
else:
print("\33[31;0m信用卡 %s 不存在\33[0m\n" % (creditcard))
if if_Unlock == "b":
break '''修改信用卡额度'''
def Updata_limit():
while True:
print("\33[32;0m修改信用卡额度\33[0m".center(70, "-"))
with open(__db_creditcard_dict, "r+") as f_creditcard_dict:
creditcard_dict = json.loads(f_creditcard_dict.read())
for key in creditcard_dict:
limitcash = creditcard_dict[key]["limitcash"]
print("信用卡 【%s】\t目前可用额度:【¥%s】\t取现额度:【¥%s】" %
(key,creditcard_dict[key]["limit"],limitcash))
if_Updata = input("\n\33[34;0m是否进行信用卡额度调整 确定【y】/返回【b】\33[0m:")
if if_Updata == "y":
creditcard = input("\33[34;0m输入要修改额度的信用卡卡号\33[0m:")
if creditcard in creditcard_dict.keys():
limit = input("\33[34;0m输入额度修改后的金额(至少¥5000)\33[0m:")
if limit.isdigit():
limit_default = creditcard_dict[creditcard]["deflimit"]
limit = int(limit)
if limit >=5000:
updata = limit - limit_default
creditcard_dict[creditcard]["limit"] +=updata
creditcard_dict[creditcard]["limitcash"] += updata//2
creditcard_dict[creditcard]["deflimit"]=limit
dict = json.dumps(creditcard_dict)
f_creditcard_dict.seek(0)
f_creditcard_dict.truncate(0)
f_creditcard_dict.write(dict)
print("\33[31;1m信用卡 %s 额度修改成功 额度 %s \33[0m\n" % (creditcard,limit))
else:
print("\33[31;0m输入金额 ¥%s 小于¥5000\33[0m\n" % (limit))
else:
print("\33[31;0m输入金额 ¥%s 格式错误\33[0m\n" % (limit))
else:
print("\33[31;0m信用卡 【%s】 不存在\33[0m\n" % (creditcard))
if if_Updata == "b":
break

admincenter.py

②、认证中心模块authentication.py

#!/usr/bin/env python
# -*- coding:utf-8 -*-
#-Author-Lian import os,json
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) '''数据库文件相对路径'''
__db_users_dict = BASE_DIR + r"\database\users_dict"
__db_creditcard_dict = BASE_DIR + r"\database\creditcard_dict" '''认证装饰器'''
def auth(auth_type):
def outer_wrapper(func):
if auth_type == "user_auth":
def wrapper():
res = func()
username = input("\33[34;0m请输入用户名:\33[0m")
password = input("\33[34;0m请输入密码:\33[0m")
if len(username.strip()) > 0:
with open(__db_users_dict, "r+") as f_users_dict:
users_dict = json.loads(f_users_dict.read())
if username in users_dict.keys():
if password == users_dict[username]["password"]:
if users_dict[username]["locked"] == 0:
print("\33[31;0m用户 %s 认证成功\33[0m"%(username))
return res,username
else:
print("\33[31;0m用户 %s 已经被锁定 认证失败\33[0m" % (username))
else:
print("\33[31;0m输入的密码不匹配 认证失败\33[0m")
else:
print("\33[31;0m输入的用户名不存在 认证失败\33[0m")
else:
print("\33[31;0m输入的用户名为空 认证失败\33[0m")
return wrapper if auth_type == "creditcard_auth":
def wrapper():
res = func()
creditcard = input("\33[34;0m输入信用卡卡号(6位数字):\33[0m")
password = input("\33[34;0m输入信用卡的密码:\33[0m")
if len(creditcard.strip()) > 0:
with open(__db_creditcard_dict, "r+") as f_creditcard_dict:
creditcard_dict = json.loads(f_creditcard_dict.read())
if creditcard in creditcard_dict.keys():
if password == creditcard_dict[creditcard]["password"]:
if creditcard_dict[creditcard]["locked"] == 0:
print("\33[31;0m信用卡 %s 认证成功\33[0m" % (creditcard))
return res,creditcard
else:
print("\33[31;0m信用卡 %s 已经被冻结 认证失败\33[0m" % (creditcard))
else:
print("\33[31;0m输入的密码不匹配 认证失败\33[0m")
else:
print("\33[31;0m输入的信用卡卡号不存在 认证失败\33[0m")
else:
print("\33[31;0m输入的信用卡卡号为空 认证失败\33[0m")
return wrapper if auth_type == "admincenter_auth":
def wrapper():
res = func()
admincenter_dict ={"admin":"admin"}
username = input("\33[34;0m请输入管理用户名:\33[0m")
password = input("\33[34;0m请输入管理密码:\33[0m")
if len(username.strip()) > 0:
if username in admincenter_dict.keys():
if password == admincenter_dict[username]:
print("\33[31;0m管理用户 %s 认证成功\33[0m" % (username))
return res, username
else:
print("\33[31;0m输入的密码不匹配 认证失败\33[0m")
else:
print("\33[31;0m输入的用户名不存在 认证失败\33[0m")
else:
print("\33[31;0m输入的用户名为空 认证失败\33[0m") return wrapper
return outer_wrapper '''用户登录认证'''
@auth(auth_type="user_auth")
def user_auth():
print("\33[32;0m用户登录认证\33[0m".center(40,"-"))
return "True" '''信用卡认证'''
@auth(auth_type="creditcard_auth")
def creditcard_auth():
print("\33[32;0m信用卡登录认证\33[0m".center(40,"-"))
return "True" '''后台管理认证'''
@auth(auth_type="admincenter_auth")
def admincenter_auth():
print("\33[32;0m后台管理登录认证\33[0m".center(40,"-"))
return "True"

authentication.py

③、信用卡模块creditcard.py

#!/usr/bin/env python
# -*- coding:utf-8 -*-
#-Author-Lian import json,os,datetime,time
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) '''数据库文件相对路径'''
__db_creditcard_dict = BASE_DIR + r"\database\creditcard_dict"
__db_details_tip = BASE_DIR + r"\database\details_tip"
__db_creditcard_record = BASE_DIR + r"\database\creditcard_record" '''取现需知'''
def details_tip():
with open(__db_details_tip,"r",encoding="utf-8") as f_details_tip:
print(f_details_tip.read()) '''我的信用卡'''
def My_creditcard(current_creditcard):
while True:
print("\33[32;0m我的信用卡信息\33[0m".center(40, "-"))
with open(__db_creditcard_dict, "r+") as f_creditcard_dict:
creditcard_dict = json.loads(f_creditcard_dict.read())
print("卡号:\t【%s】\n额度:\t【¥%s】\n提现额度:\t【¥%s】\n持卡人:\t【%s】\n"%(current_creditcard,
creditcard_dict[current_creditcard]["limit"],creditcard_dict[current_creditcard]["limitcash"],
creditcard_dict[current_creditcard]["personinfo"]))
if_back = input("\33[34;0m是否退出 返回【b】\33[0m:")
if if_back == "b":
break '''信用卡流水记录'''
def Creditcard_record(creditcard,value):
with open(__db_creditcard_record, "r+") as f_creditcard_record:
record_dict = json.loads(f_creditcard_record.read())
month = time.strftime('%Y-%m-%d', time.localtime())
times = time.strftime("%H:%M:%S")
if str(creditcard) not in record_dict.keys():
record_dict[creditcard]={month:{times:value}}
else:
if month not in record_dict[creditcard].keys():
record_dict[creditcard][month] = {times: value}
else:
record_dict[creditcard][month][times] = value
dict = json.dumps(record_dict)
f_creditcard_record.seek(0)
f_creditcard_record.truncate(0)
f_creditcard_record.write(dict) '''提现'''
def Cash_advance(current_creditcard):
while True:
print("\33[32;0m提现\33[0m".center(40, "-"))
with open(__db_creditcard_dict, "r+") as f_creditcard_dict:
creditcard_dict = json.loads(f_creditcard_dict.read())
limit = creditcard_dict[current_creditcard]["limit"]
limitcash = creditcard_dict[current_creditcard]["limitcash"]
print("信用卡号:\t【%s】\n提现额度:\t【¥%s】" % (current_creditcard, limitcash))
if limit >= limitcash:
print("可提现金额:\t【¥%s】\n" % (limitcash))
details_tip()
if_adv = input("\n\33[34;0m是否进行提现 确定【y】/返回【b】\33[0m:")
if if_adv == "y":
cash = input("\33[34;0m输入要提现的金额 收取%5手续费\33[0m:")
if cash.isdigit():
cash=int(cash)
if cash != 0:
if cash <= limitcash:
limitcash = limitcash - int(cash*1.05)
limit = limit - int(cash*1.05)
creditcard_dict[current_creditcard]["limit"]=limit
creditcard_dict[current_creditcard]["limitcash"] = limitcash
f_creditcard_dict.seek(0)
f_creditcard_dict.truncate(0)
dict = json.dumps(creditcard_dict)
f_creditcard_dict.write(dict)
record = "\33[31;1m提现¥%s 手续费¥%s\33[0m"%(cash,int(cash*0.05))
print(record,"\n")
Creditcard_record(current_creditcard,record)
else:
print("\33[31;0m超出信用卡提现额度\33[0m\n")
else:
print("\33[31;0m提现额度不能为空\33[0m\n")
if if_adv == "b":
break if limit < limitcash:
print("可提现金额:\t¥【%s】\n" % (int(limit*0.95)))
details_tip()
if_adv = input("\n\33[34;0m是否进行提现 确定【y】/返回【b】\33[0m:")
if if_adv == "y":
cash = input("\33[34;0m输入要提现的金额 收取%5手续费\33[0m:")
if cash.isdigit():
cash = int(cash)
if cash != 0:
if cash <= int(limit*0.95):
limit = limit - int(cash * 1.05)
limitcash = limitcash - int(cash * 1.05)
creditcard_dict[current_creditcard]["limitcash"] = limitcash
creditcard_dict[current_creditcard]["limit"] = limit
f_creditcard_dict.seek(0)
f_creditcard_dict.truncate(0)
dict = json.dumps(creditcard_dict)
f_creditcard_dict.write(dict)
record= "\33[31;1m提现¥%s 手续费¥%s\33[0m" % (cash, int(cash * 0.05))
print(record,"\n")
Creditcard_record(current_creditcard, record)
else:
print("\33[31;0m信用卡没有足够的额度去支付提现,请去【我的信用卡】查看当前额度\33[0m\n")
else:
print("\33[31;0m提现额度不能为空\33[0m\n")
if if_adv == "b":
break '''转账'''
def Transfer(current_creditcard):
while True:
print("\33[32;0m转账\33[0m".center(40, "-"))
if_trans = input("\n\33[34;0m是否进行转账 确定【y】/返回【b】\33[0m:")
if if_trans == "y":
with open(__db_creditcard_dict, "r+") as f_creditcard_dict:
creditcard_dict = json.loads(f_creditcard_dict.read())
current_limit = creditcard_dict[current_creditcard]["limit"]
transfer_creditcard = input("\33[34;0m输入转账的银行卡卡号\33[0m:")
if transfer_creditcard.isdigit():
if len(transfer_creditcard) == 6:
if transfer_creditcard in creditcard_dict.keys():
again_creditcard = input("\33[34;0m再次确认转账的银行卡卡号\33[0m:")
if transfer_creditcard == again_creditcard:
transfer_cash = input("\33[34;0m输入转账的金额\33[0m:")
if transfer_cash.isdigit():
transfer_cash=int(transfer_cash)
if transfer_cash <= current_limit:
transfer_limit = creditcard_dict[current_creditcard]["limit"]
creditcard_dict[current_creditcard]["limit"] = current_limit-transfer_cash
creditcard_dict[transfer_creditcard]["limit"] = transfer_limit+transfer_cash
f_creditcard_dict.seek(0)
f_creditcard_dict.truncate(0)
dict = json.dumps(creditcard_dict)
f_creditcard_dict.write(dict)
record="\33[31;1m转账卡号 %s 金额 ¥%s 转账成功\33[0m"%(transfer_creditcard,transfer_cash)
print(record,"\n")
Creditcard_record(current_creditcard, record)
else:
print("\33[31;0m金额不足 转账失败\33[0m\n")
else:
print("\33[31;0m输入金额有误\33[0m\n")
else:
print("\33[31;0m两次输入银行卡卡号不一致\33[0m\n")
else:
print("\33[31;0m输入银行卡不存在\33[0m\n")
else:
print("\33[31;0m输入银行卡有误\33[0m\n")
else:
print("\33[31;0m输入银行卡有误\33[0m\n")
if if_trans == "b":
break '''还款'''
def Repayment(current_creditcard):
while True:
print("\33[32;0m还款\33[0m".center(40, "-"))
if_repay = input("\n\33[34;0m是否进行还款 确定【y】/返回【b】\33[0m:")
if if_repay == "y":
repay_cash = input("\33[34;0m输入要还款的金额\33[0m:")
if repay_cash.isdigit():
repay_cash=int(repay_cash)
with open(__db_creditcard_dict, "r+") as f_creditcard_dict:
creditcard_dict = json.loads(f_creditcard_dict.read())
limit = creditcard_dict[current_creditcard]["limit"]
limit = limit+repay_cash
creditcard_dict[current_creditcard]["limit"]=limit
f_creditcard_dict.seek(0)
f_creditcard_dict.truncate(0)
dict = json.dumps(creditcard_dict)
f_creditcard_dict.write(dict)
record="\33[31;1m信用卡 %s 还款金额 ¥%s 还款成功\33[0m" % (current_creditcard, repay_cash)
print(record,"\n")
Creditcard_record(current_creditcard, record)
else:
print("\33[31;0m输入金额格式有误\33[0m\n")
if if_repay == "b":
break '''查看信用卡流水'''
def Catcard_record(current_creditcard):
while True:
print("\33[32;0m信用卡流水单\33[0m".center(40, "-"))
with open(__db_creditcard_record, "r+") as f_creditcard_record:
f_creditcard_record.seek(0)
record_dict = json.loads(f_creditcard_record.read())
#print(record_dict)
print("\33[34;0m流水单日期\33[0m:")
if current_creditcard in record_dict.keys():
for key in record_dict[current_creditcard]:
print(key)
date = input("\n\33[34;0m流水单查询 返回【b】 / 输入流水单的日期【2000-01-01】\33[0m:")
if date == "b":
break
if date in record_dict[current_creditcard].keys():
keys = sorted(record_dict[current_creditcard][date])
print("\33[31;1m当前信用卡【%s】 交易记录-》》\33[0m"%(current_creditcard))
for key in keys:
print("\33[31;1m时间:%s %s\33[0m"%(key,record_dict[current_creditcard][date][key]))
print("")
else:
print("\33[31;0m输入的日期有误\33[0m\n")
else:
print("\33[31;0m信用卡 %s 还没有进行过消费\33[0m\n"%(current_creditcard))
break

creditcard.py

④、购物模块shopping.py

#!/usr/bin/env python
# -*- coding:utf-8 -*-
#-Author-Lian
import json,os,time
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) '''数据库文件相对路径'''
__db_product = BASE_DIR + r"\database\product_list"
__db_shoping_car = BASE_DIR + r"\database\shopping_car"
__db_users_dict = BASE_DIR + r"\database\users_dict"
__db_creditcard_dict = BASE_DIR + r"\database\creditcard_dict"
__db_shopping_record = BASE_DIR + r"\database\shopping_record"
__db_creditcard_record = BASE_DIR + r"\database\creditcard_record" '''购物商城'''
def Shopping_mall():
shopping_list,pro_list = [],[]
with open(__db_product, "r", encoding="utf-8") as f_product:
for item in f_product:
pro_list.append(item.strip("\n").split())
def pro_inf():
print("编号\t商品\t\t价格")
for index, item in enumerate(pro_list):
print("%s\t\t%s\t\t%s" % (index, item[0], item[1]))
while True:
print(("\33[32;0m目前商城在售的商品信息\33[0m").center(40, "-"))
pro_inf()
choice_id = input("\n\33[34;0m选择要购买的商品编号 【购买 ID】/【返回 b】\33[0m:")
if choice_id.isdigit():
choice_id = int(choice_id)
if choice_id < len(pro_list) and choice_id >=0:
pro_item = pro_list[choice_id]
print("\33[31;0m商品%s加入购物车 价格%s\33[0m"%(pro_item[0],pro_item[1]))
shopping_list.append(pro_item) else:
print("\33[31;0m错误:没有相应的编号 请重新输入:\33[0m\n")
elif choice_id == "b":
with open(__db_shoping_car, "r+") as f_shopping_car:
list = json.loads(f_shopping_car.read())
list.extend(shopping_list)
f_shopping_car.seek(0)
f_shopping_car.truncate(0)
list = json.dumps(list)
f_shopping_car.write(list)
break
else:
print("\33[31;0m错误:没有相应的编号 请重新输入:\33[0m\n") '''清空购物车'''
def Empty_shopping_car():
with open(__db_shoping_car, "w") as f_shopping_car:
list = json.dumps([])
f_shopping_car.write(list) '''购物车'''
def Shopping_car():
while True:
with open(__db_shoping_car, "r+") as f_shopping_car:
list = json.loads(f_shopping_car.read())
sum = 0
print("\33[32;0m购物车信息清单\33[0m".center(40,"-"))
for index,item in enumerate(list):
print(index,item[0],item[1])
sum +=int(item[1])
print("\33[31;1m商品总额共计: %s\33[0m"%(sum))
if_buy = input("\n\33[34;0m选择要进行的操作 返回【b】/清空【f】\33[0m:")
if if_buy == "b" :
break
if if_buy == "f":
Empty_shopping_car() '''购物记录'''
def Shoppingcar_record(current_user,value):
with open(__db_shopping_record, "r+") as f_shoppingcar_record:
record_dict = json.loads(f_shoppingcar_record.read())
month = time.strftime('%Y-%m-%d', time.localtime())
times = time.strftime("%H:%M:%S")
if str(current_user) not in record_dict.keys():
record_dict[current_user]={month:{times:value}}
else:
if month not in record_dict[current_user].keys():
record_dict[current_user][month] = {times: value}
else:
record_dict[current_user][month][times] = value
dict = json.dumps(record_dict)
f_shoppingcar_record.seek(0)
f_shoppingcar_record.truncate(0)
f_shoppingcar_record.write(dict) '''查看购物记录'''
def Catcar_record(current_user):
while True:
print("\33[32;0m用户 %s 购物记录\33[0m".center(40, "-")%(current_user))
with open(__db_shopping_record, "r+") as f_shoppingcar_record:
record_dict = json.loads(f_shoppingcar_record.read())
if current_user not in record_dict.keys():
print("\33[31;0m用户 %s 还没有进行过消费\33[0m\n" % (current_user))
else:
data = sorted(record_dict[current_user])
for d in data:
times = sorted(record_dict[current_user][d])
for t in times:
print("\33[31;0m【时间】 %s %s\33[0m"%(d, t))
items =record_dict[current_user][d][t]
print("\33[31;0m【商品】 【价格】\33[0m")
for v in items:
print("\33[31;0m %s\t\t%s\33[0m"%(v[0],v[1]))
if_back = input("\n\33[34;0m是否返回 返回【b】\33[0m:")
if if_back == "b":
break def Creditcard_record(creditcard,value):
with open(__db_creditcard_record, "r+") as f_creditcard_record:
record_dict = json.loads(f_creditcard_record.read())
month = time.strftime('%Y-%m-%d', time.localtime())
times = time.strftime("%H:%M:%S")
if str(creditcard) not in record_dict.keys():
record_dict[creditcard]={month:{times:value}}
else:
if month not in record_dict[creditcard].keys():
record_dict[creditcard][month] = {times: value}
else:
record_dict[creditcard][month][times] = value
dict = json.dumps(record_dict)
f_creditcard_record.seek(0)
f_creditcard_record.truncate(0)
f_creditcard_record.write(dict) '''信用卡密码认证'''
def Auth_creditcard(creditcard):
with open(__db_creditcard_dict, "r+") as f_creditcard_dict:
creditcard_dict = json.loads(f_creditcard_dict.read())
passwd = input("\33[34;0m当前信用卡【%s】 请输入支付密码:\33[0m:"%(creditcard))
if passwd == creditcard_dict[creditcard]["password"]:
return True
else:
print("\33[31;0m密码输入错误,支付失败\33[0m") '''购物结算'''
def Pay_shopping(current_user):
while True:
sum = 0
print("\33[32;0m购物结算\33[0m".center(40, "-"))
with open(__db_shoping_car, "r+") as f_shopping_car:
list = json.loads(f_shopping_car.read())
for item in list:
sum += int(item[1])
if_pay = input("\n\n\33[34;0m当前商品总额:%s 是否进行支付 确定【y】/返回【b】\33[0m:"%(sum))
if if_pay == "y":
with open(__db_users_dict, "r+") as f_users_dict:
users_dict = json.loads(f_users_dict.read())
creditcard=users_dict[current_user]["creditcard"]
if creditcard == 0:
print("\33[31;0m账号 %s未绑定信用卡,请到个人中心里修改信用卡绑定\33[0m\n"%(current_user))
else:
with open(__db_creditcard_dict, "r+") as f_creditcard_dict:
creditcard_dict = json.loads(f_creditcard_dict.read())
limit = creditcard_dict[creditcard]["limit"]
limit_new = limit - sum
if limit_new >=0:
res = Auth_creditcard(creditcard)
if res == True:
creditcard_dict[creditcard]["limit"]=limit_new
dict=json.dumps(creditcard_dict)
f_creditcard_dict.seek(0)
f_creditcard_dict.truncate(0)
f_creditcard_dict.write(dict)
value = "购物支付 %s"%(sum)
print("\33[31;1m支付成功,当前余额 %s元\33[0m\n"%(limit_new))
Shoppingcar_record(current_user,list)
Creditcard_record(creditcard, value)
Empty_shopping_car()
else:
print("\33[31;0m当前信用卡额度 %s元 不足矣支付购物款 可绑定其他信用卡支付\33[0m\n"%(limit))
if if_pay == "b":
break '''信用卡绑定'''
def Link_creditcard(current_user):
while True:
print("\33[32;0m修改信用卡绑定\33[0m".center(40, "-"))
with open(__db_users_dict, "r+") as f_users_dict:
users_dict = json.loads(f_users_dict.read())
creditcard = users_dict[current_user]["creditcard"]
if creditcard == 0 :
print("当前账号: \t%s"%(current_user))
print("信用卡绑定:\33[31;0m未绑定\33[0m\n")
else:
print("当前账号: \t%s" %(current_user))
print("绑定的信用卡: %s\n"%(creditcard))
if_updata = input("\33[34;0m是否要修改信用卡绑定 确定【y】/返回【b】\33[0m:")
if if_updata == "y":
creditcard_new = input("\33[34;0m输入新的信用卡卡号(6位数字)\33[0m:")
if creditcard_new.isdigit() and len(creditcard_new) ==6:
with open(__db_creditcard_dict, "r+") as f_creditcard_dict:
creditcard_dict = json.loads(f_creditcard_dict.read())
if creditcard_new in creditcard_dict.keys():
users_dict[current_user]["creditcard"]=creditcard_new
dict = json.dumps(users_dict)
f_users_dict.seek(0)
f_users_dict.truncate(0)
f_users_dict.write(dict)
print("\33[31;1m信用卡绑定成功\33[0m\n")
else:
print("\33[31;0m输入信用卡卡号不存在(未发行)\33[0m\n")
else:
print("\33[31;0m输入信用卡格式错误\33[0m\n")
if if_updata == "b":
break '''修改登录密码'''
def Updata_password(current_user):
while True:
print("\33[32;0m修改登录密码\33[0m".center(40, "-"))
print("当前账号:\t%s\n当前密码:\t**\n"%(current_user))
if_updata = input("\33[34;0m是否要修改 % s登录密码 确定【y】/返回【b】\33[0m:"%(current_user))
if if_updata == "y":
with open(__db_users_dict, "r+") as f_users_dict:
users_dict = json.loads(f_users_dict.read())
password = users_dict[current_user]["password"]
old_pwd = input("\33[34;0m输入原来的密码\33[0m:")
if old_pwd == password:
new_pwd = input("\33[34;0m输入新的密码\33[0m:")
agin_pwd = input("\33[34;0m再输入新的密码\33[0m:")
if new_pwd == agin_pwd:
users_dict[current_user]["password"]=new_pwd
dict = json.dumps(users_dict)
f_users_dict.seek(0)
f_users_dict.truncate(0)
f_users_dict.write(dict)
print("\33[31;1m密码修改成功\33[0m\n")
else:
print("\33[31;0m两次密码不一致\33[0m\n")
else:
print("\33[31;0m密码不正确\33[0m\n")
if if_updata == "b":
break '''修改个人资料'''
def Updata_address(current_user):
while True:
print("\33[32;0m修改个人资料\33[0m".center(40, "-"))
with open(__db_users_dict, "r+") as f_users_dict:
users_dict = json.loads(f_users_dict.read())
address = users_dict[current_user]["address"]
print("当前账号:\t%s\n当前收货地址:\t%s\n" % (current_user,address))
if_updata = input("\33[34;0m是否要修改 % s登录密码 确定【y】/返回【b】\33[0m:" % (current_user))
if if_updata == "y":
new_address = input("\33[34;0m输入新的收货地址\33[0m:")
users_dict[current_user]["address"]=new_address
dict = json.dumps(users_dict)
f_users_dict.seek(0)
f_users_dict.truncate(0)
f_users_dict.write(dict)
print("\33[31;1m收货地址修改成功\33[0m\n")
if if_updata == "b":
break

shopping.py

3、database目录下的数据库

①、信用卡数据库creditcard_dict

{"": {"personinfo": "\u5929\u68da\u5143\u5e05", "password": "", "limit": 16288, "locked": 0, "limitcash": 7500, "deflimit": 15000, "creditcard": ""}, "": {"personinfo": "\u94f6\u89d2\u5927\u738b", "password": "", "limit": 15000, "locked": 1, "limitcash": 7500, "deflimit": 15000, "creditcard": ""}, "": {"personinfo": "\u91d1\u89d2\u5927\u738b", "password": "", "limit": 14288, "locked": 0, "limitcash": 7585, "deflimit": 20000, "creditcard": ""}}

creditcard_dict

②、信用卡流水记录数据库creditcard_record

{"": {"2016-08-19": {"09:59:31": "\u8d2d\u7269\u652f\u4ed8 6297", "10:24:55": "\u001b[31;1m\u4fe1\u7528\u5361 888888 \u8fd8\u6b3e\u91d1\u989d \uffe55000 \u8fd8\u6b3e\u6210\u529f\u001b[0m", "10:22:48": "\u001b[31;1m\u8f6c\u8d26\u5361\u53f7 666666 \u91d1\u989d \uffe51000 \u8f6c\u8d26\u6210\u529f\u001b[0m", "11:14:54": "\u001b[31;1m\u8f6c\u8d26\u5361\u53f7 666666 \u91d1\u989d \uffe51000 \u8f6c\u8d26\u6210\u529f\u001b[0m", "10:19:55": "\u001b[31;1m\u63d0\u73b0\uffe52000 \u624b\u7eed\u8d39\uffe5100\u001b[0m", "10:19:45": "\u001b[31;1m\u63d0\u73b0\uffe5300 \u624b\u7eed\u8d39\uffe515\u001b[0m"}}}

creditcard_record

③、信用卡取现流程需知details_tip

信用卡取现需知-》》
①信用卡默认取现额度为信用卡额度的50%(此系统默认取现额度为7500)
②信用卡进行消费时(未取现),取现额度不会变化
③信用卡额度低于取现额度时,可取现金额以当前额度为准(可取现金额=当前额度*0.95)
④取现额度只有两种状况会发生变化,一种进行取现,第二是对信用卡额度进行调整
⑤每次取现扣除5%的手续费

details_tip

④、购物商场产品信息product_list

iPhone    1299
iWatch 2999
MacBo 1999
iPad 2199
Bicyc 999
X-box 1199
Letv 819
Book 599

product_list

⑤、购物车数据库shopping_car

[]

shopping_car

⑥、用户购物流水账单数据库shopping_record

{"zhangsan": {"2016-08-19": {"09:59:31": [["iPhone", ""], ["iWatch", ""], ["MacBo", ""]]}}}

shopping_record

⑦、用户信息数据库users_dict

{"zhangsan": {"address": "None", "creditcard": "", "locked": 0, "username": "zhangsan", "password": ""}, "laoqiqi": {"address": "None", "creditcard": 0, "password": "", "username": "laoqiqi", "locked": 1}, "wangwu": {"address": "None", "creditcard": 0, "locked": 0, "username": "wangwu", "password": ""}, "zhaosi": {"address": "None", "creditcard": 0, "password": "", "username": "zhaosi", "locked": 0}}

users_dict

4、logs目录下系统日志收集log

知识量有限,暂未实现,留以后扩展

log

5、conf目录下的settings,系统初始模块加载

此次作业程序未涉及,变量都加载到了各个模块当中,留以后扩展

settings

三、操作流程图

1、购物中心(在任何位置输入不符合要求的内容都会提示报错,重新输入)

---------------进入购物中心,购物+结算正常流程-------------------

Python开发程序:ATM+购物商城

Python开发程序:ATM+购物商城

Python开发程序:ATM+购物商城

Python开发程序:ATM+购物商城

Python开发程序:ATM+购物商城

Python开发程序:ATM+购物商城

-------------进入个人中心,购物后流水账单查看+修改密码----------

Python开发程序:ATM+购物商城

Python开发程序:ATM+购物商城

2、信用卡中心,重点部分(在任何位置输入不符合要求的内容都会提示报错,重新输入)

---------------进入信用卡中心,查看信用卡信息,以及取现-------------------

Python开发程序:ATM+购物商城

Python开发程序:ATM+购物商城

----更好的理解额度小于取现额度的情况,进行购物把额度降到2335以下-----

Python开发程序:ATM+购物商城

Python开发程序:ATM+购物商城

Python开发程序:ATM+购物商城

-------------进入信用卡中心,转账,还款,查看流水记录------------

Python开发程序:ATM+购物商城

Python开发程序:ATM+购物商城

Python开发程序:ATM+购物商城

Python开发程序:ATM+购物商城

3、管理中心(在任何位置输入不符合要求的内容都会提示报错,重新输入)

---------------进入管理中心,创建用户、锁定、解锁-------------

创建用户:

Python开发程序:ATM+购物商城

验证:

Python开发程序:ATM+购物商城

锁定用户:

Python开发程序:ATM+购物商城

验证:

Python开发程序:ATM+购物商城

解锁:

Python开发程序:ATM+购物商城

验证:

Python开发程序:ATM+购物商城

---------------进入管理中心,信用卡发行,冻结,解冻-------------

发行:

Python开发程序:ATM+购物商城

验证:

Python开发程序:ATM+购物商城

冻结:

Python开发程序:ATM+购物商城

验证:

Python开发程序:ATM+购物商城

解冻:

Python开发程序:ATM+购物商城

验证:

Python开发程序:ATM+购物商城

---------------进入管理中心,信用卡修改信用额度-------------

Python开发程序:ATM+购物商城

Python开发程序:ATM+购物商城

Python开发程序:ATM+购物商城

Python开发程序:ATM+购物商城