用户模型类
comment—models—user.py
from comment.models import db
from werkzeug.security import generate_password_hash,check_password_hash
from datetime import datetime
class User(db.Model):
__tablename__ = 't_user'
id = db.Column(db.BIGINT, primary_key=True, autoincrement=True)
username = db.Column(db.String(64), comment='用户名')
password = db.Column(db.String(128), comment='密码')
payPassword = db.Column(db.String(128), comment='支付密码')
payPwdStatus = db.Column(db.Integer, comment='支付密码验证', default=0)
email = db.Column(db.String(100), comment='邮箱')
emailStatus = db.Column(db.Integer, comment='邮箱验证', default=0) # 1代表已经验证
inviteId = db.Column(db.Integer, comment='邀请码')
ip = db.Column(db.String(128), comment='ip')
phone = db.Column(db.String(11), comment='手机号')
onlock = db.Column(db.Integer, comment='用户状态') # 0代码正常
phoneStatus = db.Column(db.Integer, comment='手机验证', default=1) # # 1代表已经验证
realName = db.Column(db.String(64), comment='真实姓名')
remark = db.Column(db.String(500), comment='备注')
realNameStatus = db.Column(db.Integer, comment='实名认证', default=0) # 1代表已认证
nick_name = db.Column(db.String(200), comment='昵称')
avatar = db.Column(db.String(128), comment='头像')
idNum = db.Column(db.String(64), comment='身份证号码')
sumFriends = db.Column(db.Integer, comment='邀请数量统计')
invite_user_id= db.Column(db.Integer, comment='邀请的用户id')
role = db.Column(db.Integer, comment='是否管理员', default=0) # 0普通用户 1管理员
loginTime = db.Column(db.DateTime, default=datetime.now(), comment='登录时间')
registerTime = db.Column(db.DateTime, default=datetime.now(), comment='用户注册的时间')
#todo 定义pwd的getter函数,对外使用的属性的名字;上面password是对应sqlalchemy的(对内的)
@property
def pwd(self):
return self.password #todo 返回对内的password的属性值,数据库存放的是加密之后的值
#todo 定义pwd的setter函数,作用:对密码加密
@pwd.setter
def pwd(self,x_password): #x_password:是明文
'''
根据明文的密码加密之后得到密文
:param x_password:
:return: 加密之后的密文
'''
#根据flask提供的算法,进行加密操作
self.password=generate_password_hash(x_password)
def check_password(self,x_password):
'''
验证密码是否正确
:param x_password:密码的明文
:return:
'''
return check_password_hash(self.password,x_password)
@property
def pay_pwd(self):
"""
支付密码
"""
return self.payPassword
@pay_pwd.setter
def pay_pwd(self, p_password):
self.payPassword = generate_password_hash(p_password) # 根据flask提供的算法来加密
def check_pay_password(self, p_password):
return check_password_hash(self.payPassword, p_password)
账户模型类
from comment.models import db
from sqlalchemy import ForeignKey
class Account(db.Model):
__tablename__ = 't_account'
id = db.Column(db.Integer, primary_key=True, autoincrement=True)
userId = db.Column(db.BIGINT, ForeignKey('t_user.id'), comment='用户表主键')
#userlist:一对一关系表,一定不是列表
user = db.relationship('User', backref=db.backref('accountInfo', lazy=True, uselist=False))
total = db.Column(db.Float(10, 2), comment='帐户总额', default=0)
balance = db.Column(db.Float(10, 2), comment='帐户可用余额', default=0)
frozen = db.Column(db.Float(10, 2), comment='账户总计冻结总额', default=0)
inverstmentW = db.Column(db.Float(10, 2), comment='总计待收本金', default=0)
interestTotal = db.Column(db.Float(10, 2), comment='总计待收利息', default=0)
addCapitalTotal = db.Column(db.Float(10, 2), comment='月投总额', default=0)
recyclingInterest = db.Column(db.Float(10, 2), comment='月取总额', default=0)
capitalTotal = db.Column(db.Float(10, 2), comment='月乘总额', default=0)
inverstmentA = db.Column(db.Float(10, 2), comment='已投资总额', default=0)
interestA = db.Column(db.Float(10, 2), comment='已赚取利息', default=0)
uApplyExtractMoney = db.Column(db.Float(10, 2), comment='申请提现金额', default=0)
discount = db.Column(db.Float(8, 2), comment='代金券总金额', default=0)
映射到数据库中
详细讲解在博客
https://blog.csdn.net/YZL40514131/article/details/123954906?spm=1001.2014.3001.5502
版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 举报,一经查实,本站将立刻删除。
文章由极客之音整理,本文链接:https://www.bmabk.com/index.php/post/74127.html