设为首页 收藏本站
查看: 1067|回复: 0

[经验分享] python模拟ATM + 购物商城

[复制链接]

尚未签到

发表于 2018-8-9 10:13:55 | 显示全部楼层 |阅读模式
  模拟实现一个ATM + 购物商城程序


  • 额度 15000或自定义
  • 实现购物商城,买东西加入 购物车,调用信用卡接口结账
  • 可以提现,手续费5%
  • 每月22号出账单,每月10号为还款日,过期未还,按欠款总额 万分之5 每日计息
  • 支持多账户登录
  • 支持账户间转账
  • 记录每月日常消费流水
  • 提供还款接口
  • ATM记录操作日志
  • 提供管理接口,包括添加账户、用户额度,冻结账户等。。。
  • 用户认证用装饰器
  51cto在编辑python代码的时候非常的垃圾,python当中有多行注释符号,“ '''''' ”,但是跟它这里的这个什么代码高亮冲突,垃圾、垃圾啊!!!!这还是一个技术网站呢,垃圾!
  程序说明:程序code
  readme.md
  

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

  
### 作者介绍:
  
* author:hgz
  
### 博客地址:
  
* http://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%)
  

  流程图:
DSC0000.jpg

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

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

  
import os,sys
  

  
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
  
sys.path.append(BASE_DIR)
  

  
from modules import admincenter,authentication,creditcard,shopping
  

  
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: ').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":
  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 == "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":
  break
  else:
  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":
  break
  else:
  print("\33[31;0m输入的ID无效,请重新选择\33[0m")
  

  elif choice_id == "q":
  break
  

  else:
  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"] = 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))
  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,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():
  '''
  用户登录认证
  :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(cash1.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('&quot;\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选择要购买的商品编号 【购买>  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)
  break
  else:
  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_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(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
  

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

  
信用卡流水记录数据库creditcard_record
  

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

  
信用卡取现流程需知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
  

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

  
用户信息数据库users_dict
  

  {&quot;hgz&quot;: {&quot;username&quot;: &quot;hgz&quot;, &quot;password&quot;: &quot;123&quot;, &quot;creditcard&quot;: 0, &quot;address&quot;: &quot;None&quot;, &quot;locked&quot;: 0}, &quot;hgz1&quot;: {&quot;username&quot;: &quot;hgz1&quot;, &quot;password&quot;: &quot;123&quot;, &quot;creditcard&quot;: 0, &quot;address&quot;: &quot;null&quot;, &quot;locked&quot;: 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' :>  },
  },
  '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

运维网声明 1、欢迎大家加入本站运维交流群:群②:261659950 群⑤:202807635 群⑦870801961 群⑧679858003
2、本站所有主题由该帖子作者发表,该帖子作者与运维网享有帖子相关版权
3、所有作品的著作权均归原作者享有,请您和我们一样尊重他人的著作权等合法权益。如果您对作品感到满意,请购买正版
4、禁止制作、复制、发布和传播具有反动、淫秽、色情、暴力、凶杀等内容的信息,一经发现立即删除。若您因此触犯法律,一切后果自负,我们对此不承担任何责任
5、所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其内容的准确性、可靠性、正当性、安全性、合法性等负责,亦不承担任何法律责任
6、所有作品仅供您个人学习、研究或欣赏,不得用于商业或者其他用途,否则,一切后果均由您自己承担,我们对此不承担任何法律责任
7、如涉及侵犯版权等问题,请您及时通知我们,我们将立即采取措施予以解决
8、联系人Email:admin@iyunv.com 网址:www.yunweiku.com

所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其承担任何法律责任,如涉及侵犯版权等问题,请您及时通知我们,我们将立即处理,联系人Email:kefu@iyunv.com,QQ:1061981298 本贴地址:https://www.yunweiku.com/thread-549021-1-1.html 上篇帖子: Python操作数据库之Mongodb-12666522 下篇帖子: 安装python
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

扫码加入运维网微信交流群X

扫码加入运维网微信交流群

扫描二维码加入运维网微信交流群,最新一手资源尽在官方微信交流群!快快加入我们吧...

扫描微信二维码查看详情

客服E-mail:kefu@iyunv.com 客服QQ:1061981298


QQ群⑦:运维网交流群⑦ QQ群⑧:运维网交流群⑧ k8s群:运维网kubernetes交流群


提醒:禁止发布任何违反国家法律、法规的言论与图片等内容;本站内容均来自个人观点与网络等信息,非本站认同之观点.


本站大部分资源是网友从网上搜集分享而来,其版权均归原作者及其网站所有,我们尊重他人的合法权益,如有内容侵犯您的合法权益,请及时与我们联系进行核实删除!



合作伙伴: 青云cloud

快速回复 返回顶部 返回列表