class Application(db.Model): """ 应用表 """ __tablename__ = 'apps' __table_args__ = (db.UniqueConstraint('user_id', 'appname'), ) id = db.Column(db.Integer, primary_key=True, comment=u'自增id') user_id = db.Column(db.Integer, db.ForeignKey('user.id'), nullable=False, comment=u'应用所属用户') appname = db.Column(db.String(128), nullable=False, comment=u'应用名') apptype_id = db.Column(db.Integer, db.ForeignKey('app_type.id'), nullable=False, comment=u'应用分类') appdes = db.Column(db.String(500), comment=u'应用描述') appkey = db.Column(db.String(32), unique=True, index=True, nullable=False, comment=u'应用的标识') secret = db.Column(db.String(32), unique=True, nullable=False, comment=u'私钥, 用来签名请求') create_timed = db.Column(db.DateTime, server_default=db.func.now(), comment=u'创建时间') update_timed = db.Column(db.DateTime, onupdate=db.func.now(), comment=u'最后更新时间')
class Consume(db.Model): """ 资源消费表 """ __tablename__ = 'consume' __table_args__ = (db.UniqueConstraint('claim_id', 'customer', 'appkey'), ) # 消费者对某资源只需一次付费 txid = db.Column(db.String(64), primary_key=True, comment=u'消费资源,交易id') claim_id = db.Column(db.String(64), db.ForeignKey('content.claim_id'), nullable=False, comment=u'外键,资源交易id') customer = db.Column(db.String(64), nullable=False, index=True, comment=u'消费者(某个应用的用户名)') appkey = db.Column(db.String(32), db.ForeignKey('apps.appkey'), index=True, nullable=False) price = db.Column(db.Numeric(20, 8), nullable=False, default=0, comment=u'消费价格') create_timed = db.Column(db.DateTime, server_default=db.func.now(), comment=u'资源消费时间, 默认为当前时间')
class StatisticsAppUser(db.Model): """ Statistical user """ __tablename__ = 'statistics_appuser' __table_args__ = (db.UniqueConstraint('appkey', 'app_username'), ) id = db.Column(db.Integer, primary_key=True, comment=u'自增id') appkey = db.Column(db.String(32), db.ForeignKey('apps.appkey'), nullable=False) app_username = db.Column(db.String(64), nullable=False, comment=u'app的用户名') create_timed = db.Column(db.DateTime, nullable=False, server_default=db.func.now(), comment=u'创建时间')
class AppUser(db.Model): """ 用于记录应用的用户, 仅作备份 当应用给其用户请求生成钱包时,插入一条数据 """ __tablename__ = 'app_user' __table_args__ = (db.UniqueConstraint('appkey', 'app_username'), ) id = db.Column(db.Integer, primary_key=True, comment=u'自增id') appkey = db.Column(db.String(32), db.ForeignKey('apps.appkey'), nullable=False) app_username = db.Column(db.String(64), nullable=False, comment=u'app的用户名') create_timed = db.Column(db.DateTime, nullable=False, server_default=db.func.now(), comment=u'创建时间')
class Consume(db.Model): """ 资源消费表 """ __tablename__ = 'consume' __table_args__ = (db.UniqueConstraint('claim_id', 'customer', 'appkey'),) # 消费者对某资源只需一次付费 txid = db.Column(db.String(64), primary_key=True, comment=u'消费资源,交易id') claim_id = db.Column(db.String(64), db.ForeignKey('content.claim_id'), nullable=False, comment=u'外键,资源交易id') customer = db.Column(db.String(64), nullable=False, index=True, comment=u'消费者(某个应用的用户名)') appkey = db.Column(db.String(32), db.ForeignKey('apps.appkey'), index=True, nullable=False) price = db.Column(db.Numeric(20, 8), nullable=False, default=0, comment=u'消费价格') create_timed = db.Column(db.DateTime, server_default=db.func.now(), comment=u'资源消费时间, 默认为当前时间') @property def create_timed_str(self): """输出日期字符串""" return self.create_timed.strftime("%Y-%m-%d %H:%M:%S") @property def create_timed_timestamp(self): """输出时间戳""" return int(time.mktime(self.create_timed.timetuple()))