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

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

51cto在编辑python代码的时候非常的垃圾,python当中有多行注释符号,“ '''''' ”,但是跟它这里的这个什么代码高亮冲突,垃圾、垃圾啊!!!!这还是一个技术网站呢,垃圾!

程序说明:程序code

readme.md


## ATM信用卡购物模拟程序### 作者介绍:
* author:hgz
### 博客地址:
* https://blog.51cto.com/11019859/2060110### 功能介绍:
模拟实现一个ATM + 购物商城程序
额度 15000或自定义
实现购物商城,买东西加入 购物车,调用信用卡接口结账
可以提现,手续费5%
支持多账户登录
支持账户间转账
记录每月日常消费流水
提供还款接口
ATM记录操作日志
提供管理接口,包括添加账户、用户额度,冻结账户等。。。
用户认证用装饰器### 目录结构:Day5├── ATM-CreditCard├── README.md├── core #入口程序目录│   └── main.py  #入口程序(启动程序)├── conf #配置文件目录│   └── setting.py├── modules #程序核心目录│   ├── admincenter.py  #管理模块│   ├── authentication.py  #认证模块│   ├── common.py       # 日志模块│   ├── creditcard.py  #信用卡模块│   ├── shopping.py  #购物模块├── database #程序数据库│   ├── creditcard_dict  #信用卡数据库│   ├── creditcard_record  #信用卡流水记录数据库│   ├── details_tip  #提示信息│   ├── product_list  #商城产品数据库│   └── shopping_car  #购物车数据库│   ├── shopping_record  #购物记录│   └── users_dict  #用户数据库└── log└── log  #待扩展....### 运行说明:* 用户、信用卡信息数据库已经建立好------用户:hgz   密码:123------信用卡:888888   密码:123------信用卡:666666   密码:123------管理中心用户:admin  密码:admin* 目录结构保持一致,开始启动mian.py一、主程序ATM-CreditCard开始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%)

流程图:

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

#!/usr/bin/python
#_*_coding:utf-8_*_import os,sysBASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
sys.path.append(BASE_DIR)from modules import admincenter,authentication,creditcard,shoppingwhile 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: ').strip()if choice_id == "1":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 == "1":shopping.shopping_mall()elif choice_id == "2":shopping.shopping_car()elif choice_id == "3":shopping.pay_shopping(current_user)elif choice_id == "4":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 == "1":shopping.catcar_record(current_user)elif choice_id == "2":shopping.updata_password(current_user)elif choice_id == "3":shopping.updata_address(current_user)elif choice_id == "4":shopping.link_creditcard(current_user)elif choice_id == "b":breakelse:print("\33[31;0m输入的ID无效,请重新选择\33[0m")elif choice_id == "b":breakelse:print("\33[31;0m输入的ID无效,请重新选择\33[0m")elif choice_id == "2":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 == "1":creditcard.my_creditcard(current_creditcard)elif choice_id == "2":creditcard.cash_advance(current_creditcard)elif choice_id == "3":creditcard.transfer_accounts(current_creditcard)elif choice_id == "4":creditcard.repayment(current_creditcard)elif choice_id == "5":creditcard.catcard_record(current_creditcard)elif choice_id == "b":breakelse:print("\33[31;0m输入的ID无效,请重新选择\33[0m")elif choice_id == "3":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 == "1":admincenter.user_create()elif choice_id == "2":admincenter.lock_user()elif choice_id == "3":admincenter.unlock_user()elif choice_id == "4":admincenter.creditcard_create()elif choice_id == "5":admincenter.lock_creditcard()elif choice_id == "6":admincenter.unlock_creditcard()elif choice_id == "7":admincenter.updata_limit()elif choice_id == "b":breakelse:print("\33[31;0m输入的ID无效,请重新选择\33[0m")elif choice_id == "q":breakelse:print("\33[31;0m输入的ID无效,请重新选择\33[0m")

2、modules目录下的模块:

  • 管理中心模块admincenter.py

    
    #!/usr/bin/python
    #_*_coding:utf-8_*_

import os,json

BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(file)))

数据库文件相对路径

db_users_dict = os.path.join(BASE_DIR,'database','user_dict')
db_creditcard_dict = os.path.join(BASE_DIR,'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:').strip()if if_create == 'y':username = input("\33[34;0m输入要添加账户的用户名:\33[0m").strip()password = input("\33[34;0m输入添加账户的密码:\33[0m").strip()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_createcard_dict:
creditcard_dict = json.loads(f_createcard_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: ').strip()
if if_create == 'y':
creditcard = input('\33[34;0m输入要发行信用卡卡号(6位数字):\33[0m').strip()
if creditcard not in creditcard_dict.keys():
if creditcard.isdigit() and len(creditcard.strip()) == 6:
password = input('\33[34;0m输入要发行信用卡的密码:\33[0m').strip()
if len(password) > 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_createcard_dict.seek(0)
f_createcard_dict.truncate(0)
f_createcard_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信用卡 %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_user_dict:
user_dict = json.loads(f_user_dict.read())
for key in user_dict:
if user_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: ').strip()
if if_lock == 'y':
lock_user = input('\33[34;0m输入要锁定的用户名\33[0m: ').strip()
if lock_user in user_dict.keys():
if user_dict[lock_user]['locked'] == 0:
user_dict[lock_user]['locked'] = 1
dict = json.dumps(user_dict)
f_user_dict.seek(0)
f_user_dict.truncate(0)
f_user_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_user_dict:
user_dict = json.loads(f_user_dict.read())
for key in user_dict:
if user_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 user_dict.keys():
if user_dict[unlock_user]['locked'] == 1:
user_dict[unlock_user]['locked'] = 0
dict = json.dumps(user_dict)
f_user_dict.seek(0)
f_user_dict.truncate(0)
f_user_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: ').strip()if if_unlock == 'y':creditcard = input('\33[34;0m输入要冻结的信用卡卡号\33[0m: ').strip()if creditcard.isdigit() and len(creditcard) ==6:if creditcard in creditcard_dict.keys():if creditcard_dict[creditcard]['locked'] == 0:creditcard_dict[creditcard]["locked"] = 1dict = 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))else:print('\33[31;0m信用卡 %s 不合法,请输入6位的卡号\33[0m\n ' % (creditcard))if if_unlock == 'b':break

解冻信用卡

def unlock_crditcard():
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.keys():
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:').strip()
if creditcard.isdigit() and len(creditcard) == 6:
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))
else:
print('\33[31;0m信用卡 %s 不合法,请输入6位的卡号\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.keys():
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:').strip()
if creditcard.isdigit() and len(creditcard) == 6:
if creditcard in creditcard_dict.keys():
limit = input('\33[34;0m输入额度修改后的金额(至少¥5000)\33[0m:').strip()
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))
else:
print('\33[31;0m信用卡 %s 不合法,请输入6位的卡号\33[0m\n' % (creditcard))
if if_updata == 'b':
break

* 认证中心模块authentication.py

#!/usr/bin/python
#_coding:utf-8_

import os,json

BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(file)))

数据库文件相对路径

db_user_dict = os.path.join(BASE_DIR,'database','user_dict')
db_creditcard_dict = os.path.join(BASE_DIR,'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').strip()
password = input('\33[34;0m请输入密码:\33[0m').strip()
if len(username) > 0:
with open(db_user_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').strip()
password = input('\33[34;0m输入信用卡的密码:\33[0m').strip()
if len(creditcard) > 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').strip()password = input('\33[34;0m请输入管理员密码:\33[0m').strip()if len(username) > 0:if username in admincenter_dict.keys():if password == admincenter_dict[username]:print('\33[31;0m管理用户 %s 认证成功\33[0m' %(username))return res,usernameelse: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():
'''
用户登录认证
:return:
'''''
print(' \33[32;0m用户登录认证\33[0m '.center(50,'#'))
return True

@auth(auth_type="creditcard_auth")
def creditcard_auth():
'''
信用卡认证
:return:
'''''
print(' \33[32;0m信用卡登录认证\33[0m '.center(50,'#'))
return True

@auth(auth_type="admincenter_auth")
def admincenter_auth():
'''
管理后台登录认证
:return:
'''''
print(' \33[32;0m后台管理登录认证\33[0m '.center(50,'#'))
return True

* 信用卡模块creditcard.py

#!/usr/bin/python
#_coding:utf-8_

import os,json,datetime,time

BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(file)))

数据库文件相对路径

db_creditcard_dict = os.path.join(BASE_DIR,'database','creditcard_dict')
db_details_tip = os.path.join(BASE_DIR,'database','details_tip')
__db_creditcard_record = os.path.join(BASE_DIR,'database','creditcard_record')

def details_tip():
'''
取现须知
:return:
'''''
with open(__db_details_tip,'r',encoding='utf-8') as f_details_tip:
print(f_details_tip.read())

def my_creditcard(current_creditcard):
'''
我的信用卡
:return:
'''''
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())
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):
'''
信用卡流水记录
:return:
'''''
with open(__db_creditcard_record,'r+') as f_creditcard_record:
record_dict = json.loads(f_creditcard_record.read())
mouth = time.strftime('%Y-%m-%d', time.localtime())
times = time.strftime('%H:%M:%S')
if str(creditcard) not in record_dict.keys():
record_dict[creditcard] = {mouth:{times:value}}
else:
if mouth not in record_dict[creditcard].keys():
record_dict[creditcard][mouth] = {times:value}
else:
record_dict[creditcard][mouth][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):
'''
取现
:return:
'''''
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())
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:').strip()
if cash.isdigit():
cash = int(cash)
if cash != 0:
if cash <= limitcash:
limitcash = limitcash - int(cash1.05)
limit = limit - int(cash
1.05)
creditcard_dict[current_creditcard]['limit'] = limit
creditcard_dict[current_creditcard]['limitcash'] = limitcash
dict = json.dumps(creditcard_dict)
f_creditcard_dict.seek(0)
f_creditcard_dict.truncate(0)
f_creditcard_dict.write(dict)
record = '\33[31;1m提现¥%s 手续费¥%s\33[0m' %(limitcash,int(cash*0.05))
print(record,'\n')
else:
print('\33[31;0m超出信用卡提现额度\33[0m\n')
else:
print('\33[31;0m提现额度不能为空\33[0m\n')
if if_adv == 'b':
break

def transfer_accounts(current_creditcard):
'''
转账
:param current_creditcard:
:return:
'''''
while True:
print('\33[32;0m转账\33[0m'.center(50,'#'))
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() and 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[current_creditcard]['limit'] = transfer_cash + transfer_limit
dict = json.dumps(creditcard_dict)
f_creditcard_dict.seek(0)
f_creditcard_dict.truncate(0)
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输入银行卡不合法,请输入6位的银行卡号!\33[0m\n')
if if_trans == 'b':
break

transfer_accounts('888888')

def repayment(current_creditcard):
'''
还款
:param current_creditcard:
:return:
'''''
while True:
print(' \33[32;0m还款\33[0m '.center(50,'#'))
if_repay = input('\n\33[34;0m是否进行还款 确定【y】/返回【b】\33[0m:')
if if_repay == 'y':
repay_cash = input('\33[34;0m输入要还款的金额\33[0m:').strip()
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

repayment('888888')

def catcard_record(current_creditcard):
'''
查看信用卡流水
:param current_creditcard:
:return:
'''''
while True:
print(' \33[32;0m信用卡流水单\33[0m '.center(50,'#'))
with open(__db_creditcard_record,'r+') as f_creditcard_record:
f_creditcard_record.seek(0)
record_dict = json.loads(f_creditcard_record.read())
print('\33[34;0m流水单日期\33[0m: ')
if current_creditcard in record_dict.keys():
if key in record_dict[current_creditcard]:
print(key)
date = input('"\n\33[34;0m流水单查询 返回【b】 / 输入流水单的日期【2018-01-10】\33[0m: ').strip()
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

catcard_record('888888')

* 购物模块shopping.py

#!/usr/bin/python
#_coding:utf-8_

import os,json,time

BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(file)))

数据库文件相对路径

__db_product = os.path.join(BASE_DIR,'database','product_list')
db_shopping_car = os.path.join(BASE_DIR,'database','shopping_car')
db_users_dict = os.path.join(BASE_DIR,'database','users_dict')
db_creditcard_dict = os.path.join(BASE_DIR,'databse','creditcard_dict')
db_shopping_record = os.path.join(BASE_DIR,'database','shopping_record')
__db_creditcard_record = os.path.join(BASE_DIR,'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\t\t价格')for index, item in enumerate(pro_list):print('%s\t\t%s\t\t%s' % (index+1,item[0],item[1]))while True:print(' \33[32;0m商品信息\33[0m '.center(50,'#'))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_shopping_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)breakelse:print('\33[31;0m错误:没有相应的商品编号 请重新输入:\33[0m\n')

清空购物车

def empty_shopping_car():
with open(__db_shopping_car,'r+') as f_shopping_car:
list = json.dumps([])
f_shopping_car.write(list)

购物车

def shopping_car():
while True:
with open(__db_shopping_car,'r+') as f_shopping_car:
list = json.loads(f_shopping_car.read())
sum = 0
print(' \33[32;0m购物车信息清单\33[0m '.center(50,'#'))
for index,item in enumerate(list):
print(index+1,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_creditcard_record,'r+') as f_shoppingcar_record:
record_dict = json.loads(f_shoppingcar_record.read())
mouth = 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] = {mouth:{times:value}}
else:
if mouth not in record_dict[current_user].keys():
record_dict[current_user][mouth] = {times:value}
else:
record_dict[current_user][mouth][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(50,'#') %(current_user))
with open(__db_shopping_record,'r+') as f_shopping_record:
record_dict = json.loads(f_shopping_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())
mouth = time.strftime('%Y-%m-%d', time.localtime())
times = time.strftime('%H-%M-%S')
if str(creditcard) not in record_dict.keys():
record_dict[creditcard] = {mouth:{times:value}}
else:
if mouth not in record_dict[creditcard].keys():
record_dict[creditcard][mouth] = {times:value}
else:
record_dict[creditcard][mouth][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(50,'#'))
with open(db_shopping_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]['credictcard']
if creditcard == 0:
print('\33[31;0m账号 %s未绑定信用卡,请到个人中心里修改信用卡绑定\33[0m\n' %(current_user))
else:
with open(__db_creditcard_dict,'r+') as f_credictcard_dict:
credictcard_dict = json.loads(f_credictcard_dict.read())
limit = credictcard_dict[creditcard]['limit']
limit_new = limit - sum
if limit_new > 0:
res = auth_creditcard(creditcard)
if res == True:
credictcard_dict[creditcard]['limit'] = limit_new
dict = json.dumps(credictcard_dict)
f_credictcard_dict.seek(0)
f_credictcard_dict.truncate(0)
f_credictcard_dict.write(dict)
value = '购物支付 %s' %(sum)
print('\33[31;1m支付成功,当前余额 %s元\33[0m\n' %(limit_new))
shoppingcar_record(current_user,list)
credictcard_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(50,'#'))
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' %(creditcard))
print('信用卡绑定:\33[31;0m未绑定\33[0m\n')
else:
print('当前账号: \t%s' %(creditcard))
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_newdict = 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(50,'#'))
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:').strip()
if old_pwd == password:
new_pwd = input('\33[34;0m输入新的密码\33[0m:').strip()
again_pwd = input('\33[34;0m再输入新的密码\33[0m:').strip()
if new_pwd == again_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(50,'#'))
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: ').strip()
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

* 日志模块 common.py

#!/usr/bin/python
#_coding:utf-8_

from conf import setting
import logging.config

def logger_handle(log_name):
logging.config.dictConfig(setting.LOGGING_DIC) # 导入上面定义的logging配置
logger = logging.getLogger(log_name) # 生成一个log实例
return logger


3、database目录下的数据库
信用卡数据库creditcard_dict

{"888888": {"personinfo": "\u91d1\u89d2\u5927\u738b", "password": "123", "limit": 14288, "locked": 0, "limitcash": 485, "deflimit": 10000, "creditcard": "888888"}, "666666": {"creditcard": "666666", "password": "123", "personinfo": "24K\u7eaf\u5e05", "limit": 15000, "limitcash": 7500, "locked": 0, "deflimit": 15000}}


信用卡流水记录数据库creditcard_record

{"888888": {"2018-01-10": {"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"}}}


信用卡取现流程需知details_tip

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


购物商场产品信息product_list

iPhone 1299
iWatch 2999
MacPro 11999
iPad 2199
Bicycle 999
TPlink 1199
Letv 819
Book 599


购物车数据库shopping_car

[]


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

{"hgz": {"2018-01-10": {"09:59:31": [["iPhone", "1299"], ["iWatch", "2999"], ["MacBo", "1999"]]}}}


用户信息数据库users_dict

{"hgz": {"username": "hgz", "password": "123", "creditcard": 0, "address": "None", "locked": 0}, "hgz1": {"username": "hgz1", "password": "123", "creditcard": 0, "address": "null", "locked": 0}}


5、conf目录下的settings

#!/usr/bin/python
#_coding:utf-8_

import logging.config
import os

BASE_DIR=os.path.dirname(os.path.dirname(os.path.abspath(file)))
LOG_PATH=os.path.join(BASE_DIR,'log','access.log')
ERROR_PATH=os.path.join(BASE_DIR,'log','error.log')
DB_PATH=os.path.join(BASE_DIR,'db','user')

定义三种日志输出格式 开始

standard_format = '[%(asctime)s][%(threadName)s:%(thread)d][task_id:%(name)s][%(filename)s:%(lineno)d]' \
'[%(levelname)s][%(message)s]'

simple_format = '[%(levelname)s][%(asctime)s][%(filename)s:%(lineno)d]%(message)s'

id_simple_format = '[%(levelname)s][%(asctime)s] %(message)s'

log配置字典

LOGGING_DIC = {
'version': 1,
'disable_existing_loggers': False,
'formatters': {
'standard': {
'format': standard_format
},
'simple': {
'format': simple_format
},
'id_simple' : {
'format' : id_simple_format
},
},
'filters': {},
'handlers': {
#打印到终端的日志
'console': {
'level': 'DEBUG',
'class': 'logging.StreamHandler', # 打印到屏幕
'formatter': 'simple'
},
#打印到文件的日志,收集info及以上的日志
'default': {
'level': 'DEBUG',
'class': 'logging.handlers.RotatingFileHandler', # 保存到文件
'formatter': 'standard',
'filename': LOG_PATH, # 日志文件
'maxBytes': 102410245, # 日志大小 5M
'backupCount': 5,
'encoding': 'utf-8', # 日志文件的编码,再也不用担心中文log乱码了
},
'errorcode': {
'level': 'ERROR',
'class': 'logging.handlers.RotatingFileHandler', # 保存到文件
'formatter': 'simple',
'filename': ERROR_PATH, # 日志文件
'maxBytes': 102410245, # 日志大小 5M
'backupCount': 5,
'encoding': 'utf-8', # 日志文件的编码,再也不用担心中文log乱码了
},
},
'loggers': {
'': {
'handlers': ['default', 'console','collect'], # 这里把上面定义的两个handler都加上,即log数据既写入文件又打印到屏幕
'level': 'DEBUG',
'propagate': False, # 向上(更高level的logger)传递
},
},
}

参考链接:https://www.cnblogs.com/lianzhilei/p/5786223.html
代码下载链接:链接: https://pan.baidu.com/s/1kWjrZGN 密码: tt9b

转载于:https://blog.51cto.com/11019859/2060110

python模拟ATM + 购物商城相关推荐

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

    需求:模拟实现一个ATM+购物商城程序1.额度1500或者自定义2.实现购物商城,买东西加入购物车,调用信用卡接口3.可以提现,手续费5%4.支持账户登录5.支持账户间转账6.记录每日日常消费流水7. ...

  2. python模拟购物车购物过程_python实现购物车+ATM机 第五天

    模拟实现一个ATM + 购物商城程序 1.额度 15000或自定义 2.实现购物商城,买东西加入 购物车,调用信用卡接口结账 3.可以提现,手续费5% 4.每月22号出账单,每月10号为还款日,过期未 ...

  3. ATM + 购物商城程序

    模拟实现一个ATM + 购物商城程序 额度 15000或自定义 实现购物商城,买东西加入 购物车,调用信用卡接口结账 可以提现,手续费5% 每月22号出账单,每月10号为还款日,过期未还,按欠款总额 ...

  4. python实现简单购物商城_如何用python语言实现简单购物商城

    本文为大家分享用python语言实现购物商城小程序,供大家参考,具体内容如下,希望对大家学习python语言有所帮助. 软件版本:python3.x 功能:实现简单购物商城 1.允许用户选择购买多少件 ...

  5. 商城管理系统服务器,基于Python实现的购物商城管理系统

    完整项目地址: 简介 本项目使用Python语言编写,实现了顾客端和商家端. 功能 店主功能:注册.登录.修改店铺信息.添加商品.删除商品.修改商品.查找商品.查看交易记录. 顾客功能:注册.登录.修 ...

  6. python模拟砍价代码_Python__模拟实现一个ATM+购物商城程序

    1 #Author wangmengzhu 2 ''' 3 用户认证,确认是用户登录,判断用户登录的用户名和密码是否正确,判断用户认证的长度是否为0,使用装饰器4 用户登录认证,信用卡登录认证,管理员 ...

  7. python模拟购物车购物过程_Python 模拟购物车的实例讲解

    1.功能简介 此程序模拟用户登陆商城后购买商品操作.可实现用户登陆.商品购买.历史消费记查询.余额和消费信息更新等功能.首次登陆输入初始账户资金,后续登陆则从文件获取上次消费后的余额,每次购买商品后会 ...

  8. python 信用卡系统+购物商城见解

    通过完成信用卡系统+购物商城 使自己在利用 字典和列表方面有了较大的提升,感悟很深, 下面将我对此次作业所展示的重点列表如下: #!/usr/bin/env python3.5 # -*-coding ...

  9. python实现简单购物商城_python实现简单购物商城

    本文为大家分享了购物商城小程序,供大家参考,具体内容如下 软件版本:python3.x 功能:实现简单购物商城 1.允许用户选择购买多少件 2.允许多用户登录,下一次登录后,继续按上次的余额继续购买 ...

最新文章

  1. C语言库自带的二分查找函数bsearch函数的使用示例
  2. OpenCV非真实感渲染的实例(附完整代码)
  3. Linux驱动编程 step-by-step (五)主要的文件操作方法实现
  4. 80端口请求太多超时 php_apmserver 80端口老是被占用问题解决
  5. java class获取type_java – 获取Class [Runtime-Type Token]的实例
  6. 【资源下载】DeepMindUCL深度学习与强化学习进阶课程
  7. 华为P40系列发布!新机皇临世,售价首次过万!
  8. Linux 命令(76)—— kill 命令
  9. 计算机控制技术证书可以考吗,计算机控制技术专业可考哪些资格证书
  10. Spring 事务和事务传播机制
  11. 服务器主板检测卡显示06,主板检测卡代码大全对照表
  12. 计算机连接小米usb驱动,小米手机USB驱动电脑版
  13. 计算几何常用的函数/方法
  14. 2020年4月github上最热门项目-python
  15. 面试经历(某大型机器人少儿编程培训机构)
  16. mysql主从同步延迟优化大全
  17. android 苹果开发进度,IOS 锁屏音乐信息显示(进度条,歌名等信息。)
  18. CAD新建、保存图形文件
  19. 买游戏来运营_游戏化思维帮你玩转社群运营
  20. Jenkins笔记02-Jenkins安装和持续集成环境配置

热门文章

  1. vc++实现avi文件的操作 用于视频解析及录制(转)
  2. 一个低级错误引发Netty编码解码中文异常
  3. SqlServer中获取所有数据库,所有表,所有字段
  4. HDFS集中式缓存管理(Centralized Cache Management)
  5. 前端自动化构建工具Grunt
  6. ios开发之UIView的frame、bounds跟center属性的区别(附图)
  7. Ubuntu默认密码,及其修改
  8. ASP.NET Web - 服务器控件
  9. Windows 2008远程桌面多用户登陆的配置方法 - z
  10. 【原】Ubuntu中安装 mercurial - TortoiseHG