class MachineUsage(db.Model): __tablename__ = 'machine_usage' InfoUse, InfoStop = (0, 1) id = db.Column(db.Integer, autoincrement=True, nullable=False, primary_key=True) userId = db.Column(db.Integer, db.ForeignKey('user.id')) machineId = db.Column(db.Integer, db.ForeignKey('machine.id', ondelete="CASCADE")) action = db.Column(db.String(20), nullable=True) #0代表开始使用,1代表停止使用 actiomTime = db.Column(db.DateTime) def __init__(self, userId, machineId, action=None, actionTime=datetime.datetime.utcnow()): self.userId = userId self.machineId = machineId self.action = action self.actiomTime = actionTime def toJson(self): result = dict( (c.name, getattr(self, c.name)) for c in self.__table__.columns) if self.actiomTime: result['actiomTime'] = self.actiomTime.strftime("%Y-%m-%d %H:%M") return result
class Comment(db.Model): __tablename__ = 'comment' id = db.Column(db.Integer, autoincrement=True, nullable=False, primary_key=True) userId = db.Column(db.Integer, db.ForeignKey('user.id')) shareId = db.Column(db.Integer, db.ForeignKey('share.id', ondelete="CASCADE")) content = db.Column(db.String(200)) voteFlag = db.Column(db.Integer, default=0) commentTime = db.Column(db.DateTime, default=datetime.datetime.utcnow) score = db.Column(db.Integer, default=0) imageUrl = db.Column(db.String(100)) def __init__(self, **kargs): self.userId = kargs.get('UserId') self.shareId = kargs.get("ShareId") self.content = kargs.get('Content') self.voteFlag = kargs.get('VoteFlag', 0) self.score = kargs.get('Score', 0) self.imageUrl = kargs.get('ImageUrl') def toJson(self): result = dict( (c.name, getattr(self, c.name)) for c in self.__table__.columns) if self.shareCreateTime: result['commentTime'] = self.commentTime.strftime("%Y-%m-%d %H:%M") return result
class Order(db.Model): __tablename__ = 'order' Init, WaitingPay, TradeDone, TradeClosed = (0, 1, 2, 3) orderId = db.Column(db.String(30), nullable=False, primary_key=True) userId = db.Column(db.Integer, db.ForeignKey('user.id')) shareId = db.Column(db.Integer, db.ForeignKey('share.id', ondelete="CASCADE")) money = db.Column(db.Float) status = db.Column(db.Integer, default=Init) createTime = db.Column(db.DateTime, default=datetime.datetime.utcnow) def __init__(self, userId, shareId, money, status=Init, createTime=datetime.datetime.utcnow()): self.orderId = str(datetime.datetime.now().strftime("%Y%m%d%H%M%S") + shortuuid.ShortUUID(alphabet="0123456789").random( length=10)) self.userId = userId self.shareId = shareId self.money = money self.status = status self.createTime = createTime def toJson(self): result = dict( (c.name, getattr(self, c.name)) for c in self.__table__.columns) if self.createTime: result['createTime'] = self.createTime.strftime("%Y-%m-%d %H:%M") return result
class QuanXian(db.Model): __tablename__ = 'user_machine' # 0是厂家,1是超级管理员,2是管理员,3是普通用户,4是访客,5是无权,6是匿名 Producer, SuperAdmin, Admin, User, Vistor, NoRight, Anonymous = (0, 1, 2, 3, 4, 5, 6) #__table_args__ = (PrimaryKeyConstraint('userId', 'machineId'),) id = db.Column(db.Integer, autoincrement=True, nullable=False, primary_key=True) userId = db.Column(db.Integer, db.ForeignKey('user.id')) machineId = db.Column(db.Integer, db.ForeignKey('machine.id', ondelete='CASCADE')) permission = db.Column(db.Integer, default=User) reason = db.Column(db.String(200)) startTime = db.Column(db.DateTime) endTime = db.Column(db.DateTime) money = db.Column(db.Float, default=0.0) machineName = db.Column(db.String(200)) #用户对机器的命名 def __init__(self, userId, machineId, permission=User, reason=None, startTime=None, endTime=None, money=0, machineName=0): self.userId = userId self.machineId = machineId self.permission = permission self.reason = reason if startTime: self.startTime = startTime if endTime: self.endTime = endTime self.money = money self.machineName = machineName def toJson(self): result = dict( (c.name, getattr(self, c.name)) for c in self.__table__.columns) if self.startTime: result['startTime'] = self.startTime.strftime("%Y-%m-%d %H:%M") if self.endTime: result['endTime'] = self.endTime.strftime("%Y-%m-%d %H:%M") return result
class ShenQing(db.Model): __tablename__ = 'shen_qing' id = db.Column(db.Integer, autoincrement=True, nullable=False, primary_key=True) userId = db.Column(db.Integer, db.ForeignKey('user.id')) machineId = db.Column(db.Integer, db.ForeignKey('machine.id', ondelete="CASCADE")) statusCode = db.Column(db.Integer, default=0) #0代表管理员未查看该权限申请请求,-1表示拒绝该申请,1表示通过该申请 needPermission = db.Column(db.Integer, default=0) reason = db.Column(db.String(200)) time = db.Column(db.DateTime, default=datetime.datetime.utcnow) #申请的时间 startTime = db.Column(db.DateTime) # 开始使用该机器的时间 endTime = db.Column(db.DateTime) # 结束使用该机器的时间 money = db.Column(db.Float, default=0.0) def __init__(self, userId, machineId, statusCode=0, needPermission=-1, reason='', startTime=None, endTime=None, money=0.0, time=datetime.datetime.utcnow()): self.userId = userId self.machineId = machineId self.statusCode = statusCode self.needPermission = needPermission self.reason = reason self.time = time self.startTime = startTime self.endTime = endTime self.money = money def toJson(self): result = dict( (c.name, getattr(self, c.name)) for c in self.__table__.columns) if self.startTime: result['startTime'] = self.startTime.strftime("%Y-%m-%d %H:%M") if self.endTime: result['endTime'] = self.endTime.strftime("%Y-%m-%d %H:%M") return result
class Share(db.Model): __tablename__ = 'share' PriceHour, PriceDay, PriceMonth, PriceYear = (1, 2, 3, 4) Offline, Online = (0, 1) id = db.Column(db.Integer, autoincrement=True, nullable=False, primary_key=True) userId = db.Column(db.Integer, db.ForeignKey('user.id')) #machineId = db.Column(db.Integer, db.ForeignKey('machine.id', ondelete="CASCADE")) title = db.Column(db.String(100)) address = db.Column(db.String(200)) imageUrls = db.Column(db.String(300)) hotPointIds = db.Column(db.String(20)) price = db.Column(db.Float) priceUnit = db.Column(db.Integer) #表示价格是每次、每小时、每天等 startTime = db.Column(db.DateTime) endTime = db.Column(db.DateTime) longitude = db.Column(db.Float) latitude = db.Column(db.Float) comments = db.Column(db.String(200)) usageInstruction = db.Column(db.String(200)) shareCreateTime = db.Column(db.DateTime, default=datetime.datetime.utcnow) status = db.Column(db.Integer, default=Online) #该分享“上线”或“下线”状态,有时候不想分享了,就下线。 def __init__(self, **kargs): self.userId = kargs.get("UserId") self.title = kargs.get('Title', "") self.address = kargs.get('Address', '').encode('utf-8') self.hotPointIds = kargs.get('HotPointIds', "") self.price = kargs.get('Price', 0) self.priceUnit = kargs.get('PriceUnit', 0) self.startTime = kargs.get('StartTime', None) self.endTime = kargs.get('EndTime', None) self.longitude = kargs.get('Longitude', 0.0) self.latitude = kargs.get('Latitude', 0.0) self.comments = kargs.get('Comments', '') self.usageInstruction = kargs.get('UsageInstruction', "") self.status = kargs.get('Status', Share.Online) self.imageUrls = kargs.get('ImageUrls', "") def toJson(self): result = dict( (c.name, getattr(self, c.name)) for c in self.__table__.columns) if self.shareCreateTime: result['shareCreateTime'] = self.shareCreateTime.strftime( "%Y-%m-%d %H:%M") if self.startTime: result['startTime'] = self.startTime.strftime("%Y-%m-%d %H:%M") if self.endTime: result['endTime'] = self.endTime.strftime("%Y-%m-%d %H:%M") result['imageUrls'] = self.imageUrls.split(',') return result