class UserOrder(Base): """用户订单表""" id = fields.IntField(pk=True) user = fields.ForeignKeyField("market.MarketUser", "orders", on_delete=fields.SET_NULL, null=True) product_id = fields.UUIDField(index=True) # 商品 ID product_type = fields.IntEnumField(ProductType) # 商品类型:1= 策略,2= 套餐,3=vip status = fields.IntEnumField(OrderStatus, default=OrderStatus.unpayed ) # 订单状态:1= 待支付,2= 支付成功,3= 支付失败,4= 取消支付 / 超时 total_cash = fields.FloatField(default=0) # 订单总金额 total_days = fields.IntField(default=0) # 订单总天数 coupon_days = fields.IntField(default=0) # 优惠券抵扣天数 coupon_cash = fields.FloatField(default=0) # 优惠券优惠金额 pay_cash = fields.FloatField(default=0) # 订单需支付金额 days = fields.IntField(default=0) # 购买时长 gift_days = fields.IntField(default=0) # 赠送时长 expire_dt = fields.DatetimeField(null=True) # 过期时间 create_dt = fields.DatetimeField(auto_now_add=True) # 创建时间 update_dt = fields.DatetimeField(auto_now=True) foreign_order_id = fields.CharField(max_length=32, default="") # 外部订单号 pay_id = fields.CharField(max_length=48, default="") # 支付平台订单号 pay_method = fields.IntEnumField(PayMethod, default=PayMethod.wechat) pay_url = fields.CharField(max_length=255, default="") # 支付链接(重新支付) pay_dt = fields.DatetimeField(null=True) # 支付时间 payed_cash = fields.FloatField(default=0) # 已支付金额 source = fields.CharField(max_length=32, default="default") # 订单来源:pc/mobile delete = fields.BooleanField(default=False) coupon = fields.JSONField(default=[]) # 使用的优惠券 product_snapshot = fields.JSONField(default={}) # 商品快照
class Player(Model): discord_id = fields.BigIntField(pk=True) discord_name = fields.CharField(max_length=200) percent_infected = fields.IntField(default=0) cured = fields.BooleanField(default=False) doctor = fields.BooleanField(default=False) immunodeficient = fields.BooleanField(default=False) total_infected_points = fields.IntField(default=0) total_cured_points = fields.IntField(default=0) maximum_infected_points = fields.IntField(default=0) isolation = fields.IntEnumField(Isolation, default=Isolation.normal_life) touched_last = fields.DatetimeField(auto_now_add=True) good = fields.IntEnumField(AlignmentGood) law = fields.IntEnumField(AlignmentLaw) charisma = fields.IntField() inventory: fields.ReverseRelation["Inventory"] achievements: fields.ReverseRelation["Achievements"] statistics: fields.ReverseRelation["Statistics"] def is_dead(self) -> bool: return self.percent_infected >= 100 def is_infected(self) -> bool: return self.percent_infected > 0 def can_be_touched(self) -> bool: if not self.is_dead(): return self.touched_last + datetime.timedelta( hours=3) < datetime.datetime.utcnow() return self.touched_last + datetime.timedelta( hours=1) < datetime.datetime.utcnow() def infect(self, add_infected: int = None) -> None: if add_infected is None: add_infected = random.randint(1, 8) if self.achievements.vaccinated: add_infected = min(0, add_infected) self.total_infected_points += max(0, add_infected) self.total_cured_points -= min(0, add_infected) self.percent_infected += add_infected self.percent_infected = max(self.percent_infected, 0) self.maximum_infected_points = max(self.maximum_infected_points, self.percent_infected) if self.total_infected_points >= 50 and self.percent_infected == 0: self.cured = True # Defining ``__str__`` is also optional, but gives you pretty # represent of model in debugger and interpreter def __str__(self): return self.discord_name
class QStrategy(Base): """ 上架策略详细信息 The User model """ product_id = fields.UUIDField(pk=True) sim_id = fields.IntField(index=True) user_id = fields.IntField(index=True) author_name = fields.CharField(max_length=32) task_id = fields.CharField(max_length=32, index=True) # 模拟交易的 ID sim_start_cash = fields.FloatField(default=0) # 模拟交易的初始资金 sim_start_dt = fields.DatetimeField() # 模拟交易的开始时间 sim_name = fields.CharField(max_length=128) bt_task_id = fields.CharField(max_length=32, index=True) # 回测的 ID # 状态:1= 上架审核中,2= 上架审核未通过,3= 正常,4= 下架审核中,5= 下架,6= 删除 status = fields.IntEnumField(ListStatus, default=1) market = fields.ForeignKeyField("market.StrategyMarket", "strategies", on_delete=fields.SET_NULL, null=True) package = fields.ForeignKeyField("market.StrategyPackage", "strategies", on_delete=fields.SET_NULL, null=True) name = fields.CharField(max_length=128) # 策略名称 buyout_price = fields.FloatField() # 买断价格 total_cnt = fields.IntField() # 总份数 category = fields.IntEnumField(QStrategyType, default=1) # 策略类型,1= 股票,2= 期货 style = fields.CharField(max_length=32, default="") # 策略风格 tags = fields.JSONField(defalt=[]) # 标签数组 ideas = fields.TextField(default="") # 策略思路 desc = fields.TextField(default="") # 描述 suit_money = fields.FloatField(default=10000000) # 适合资金 # package_name = fields.CharField(max_length=50) # 所属套餐 limit_copy = fields.IntField(default=100000) # 连续复制次数 limit_interval = fields.IntField(default=10000000) # 复制间隔 sell_cnt = fields.IntField(default=0) # 已销售数量 sell_cnt_show = fields.IntField(default=0) # 虚假的销量 create_dt = fields.DatetimeField(auto_now_add=True) # 最初申请上架时间 update_dt = fields.DatetimeField(auto_now=True) online_dt = fields.DatetimeField(null=True) offline_dt = fields.DatetimeField(null=True) view_cnt = fields.IntField(default=0) # 浏览次数 collect_cnt = fields.IntField(default=0) # 收藏次数 share_cnt = fields.IntField(default=0) # 分享次数 # 时段购买价格信息 [{"day": 20, "gift_day": 20, "price": 350}, ...] period_prices = fields.JSONField(default=[]) enable_discount = fields.BooleanField(default=True) # 折扣信息 [{"start_dt": xxx, "end_dt": xxx, "day": 10, "gift_day": 10, "price": 200}, ...] discount_info = fields.JSONField(default=[]) allow_coupon = fields.BooleanField(default=True) # 是否可使用优惠券
class User(Model, TimestampMixin): class Meta: table = 'user' id: UUID = fields.UUIDField(pk=True) email = fields.CharField(max_length=255) account = fields.CharField(max_length=64, null=True) hashed_password = fields.CharField(max_length=64, null=True) third_party_user_id = fields.TextField(null=True) type = fields.IntEnumField(UserType) status = fields.IntEnumField(UserStatus, default=UserStatus.NORMAL) is_email_verified = fields.BooleanField(default=False) extra = fields.JSONField(default={})
class Device(Model, TimestampMixin): class Meta: table = 'device' id = fields.BigIntField(pk=True) device_id = fields.CharField(max_length=255, index=True) push_token = fields.CharField(max_length=255, index=True, null=True) # push token from fcm send_platform = typing.cast(SendPlatform, fields.IntEnumField(DevicePlatform)) device_platform = typing.cast(DevicePlatform, fields.IntEnumField(DevicePlatform)) device_properties: fields.ReverseRelation[DeviceProperty]
class PushInfo(Base): """推送信息维护""" id = fields.IntField(pk=True) qstrategy_id = fields.UUIDField() task_id = fields.CharField(max_length=32, index=True) user_id = fields.IntField() # 申请人 # contact = fields.CharField(max_length=14) # 申请人手机号 status = fields.IntEnumField(PushStatus) # 推送状态:1= 推送,2= 停用,2= 权限过期 push_method = fields.IntEnumField(PushMethod, default=1) # 推送类型 push_id = fields.CharField(max_length=128) # 推送 id,微信号 / 邮箱地址 /post 地址等 create_dt = fields.DatetimeField(auto_now_add=True) # 创建时间 update_dt = fields.DatetimeField(auto_now=True)
class DiscordUser(Model): discord_id = fields.BigIntField(pk=True) first_seen = fields.DatetimeField(auto_now_add=True) name = fields.TextField() discriminator = fields.CharField(4) times_ran_example_command = fields.IntField(default=0) inventory = fields.JSONField(default=[]) trophys = fields.JSONField(default={}) ping_friendly = fields.BooleanField(default=True) language = fields.CharField(6, default="en") first_use = fields.BooleanField(default=True) access_level_override = fields.IntEnumField(enum_type=AccessLevel, default=AccessLevel.DEFAULT) class Meta: table = "users" def get_access_level(self): return self.access_level_override def __str__(self): return self.name def __repr__(self): return f"<User name={self.name}#{self.discriminator}>"
class TaskSolution(Model): """Модель решения задачи.""" content = fields.TextField() extension = fields.CharField(max_length=8) status = fields.IntEnumField( TaskSolutionStatus, default=TaskSolutionStatus.WAITING, ) timestamp = fields.DatetimeField(auto_now=True) student = fields.ForeignKeyField("models.User", related_name="solutions") task = fields.ForeignKeyField("models.Task", related_name="solutions") class Meta: """Мета-параметры модели. Условие на то, что у одного ученика может быть только одно решение. """ unique_together = ("student", "task") def set_status(self, is_correct: bool): """Установка статуса правильности решению задачи.""" if is_correct: self.status = TaskSolutionStatus.CORRECT else: self.status = TaskSolutionStatus.INCORRECT
class Config(BaseModel): label = fields.CharField(max_length=200) key = fields.CharField(max_length=20) value = fields.JSONField() status: Status = fields.IntEnumField(Status, default=Status.on, description='状态')
class Config(Model): label = fields.CharField(max_length=200) key = fields.CharField(max_length=20, unique=True, description="Unique key for config") value = fields.JSONField() status: Status = fields.IntEnumField(Status, default=Status.on)
class StrategyPackage(Base): """套餐表""" product_id = fields.UUIDField(pk=True) name = fields.CharField(max_length=64, unique=True, index=True) market = fields.ForeignKeyField("market.StrategyMarket", "packages", on_delete=fields.SET_NULL, null=True) tags = fields.JSONField() desc = fields.TextField() status = fields.IntEnumField(ListStatus, default=1) # 套餐状态:1= 正常,2= 下架,3= 删除 limit_copy = fields.IntField() # 连续复制次数 limit_interval = fields.IntField() # 复制间隔 view_cnt = fields.IntField(default=0) # 浏览次数 collect_cnt = fields.IntField(default=0) # 收藏次数 share_cnt = fields.IntField(default=0) # 分享次数 buyout_price = fields.FloatField() # 买断价格 # 时段购买价格信息 [{"day": 20, "gift_day": 20, "price": 350}, ...] period_prices = fields.JSONField() enable_discount = fields.BooleanField(default=True) # 折扣信息 [{"start_dt": xxx, "end_dt": xxx, "day": 10, "gift_day": 10, "price": 200}, ...] discount_info = fields.JSONField() allow_coupon = fields.BooleanField() # 是否可使用优惠券 create_dt = fields.DatetimeField(auto_now_add=True) # 最初申请上架时间 update_dt = fields.DatetimeField(auto_now=True) online_dt = fields.DatetimeField(null=True) offline_dt = fields.DatetimeField(null=True) # reverse relations strategies: fields.ReverseRelation["market.models.QStrategy"]
class DiscordMember(Model): id = fields.IntField(pk=True) guild: fields.ForeignKeyRelation[DiscordGuild] = \ fields.ForeignKeyField('models.DiscordGuild', related_name="members") user: fields.ForeignKeyRelation[DiscordUser] = \ fields.ForeignKeyField('models.DiscordUser', related_name="members") players: fields.ReverseRelation["Player"] access_level = fields.IntEnumField(enum_type=AccessLevel, default=AccessLevel.DEFAULT) def get_access_level(self): override = self.user.access_level_override if override != AccessLevel.DEFAULT: return override else: return self.access_level class Meta: table = "members" def __repr__(self): return f"<Member user={self.user} guild={self.guild}>"
class File(Model): id = fields.UUIDField(pk=True) name = fields.CharField(max_length=255) data = fields.BinaryField() status = fields.IntEnumField(FileStatus) def __str__(self): return f'id: {self.id} url:{self.name}'
class Config(Model): label = fields.CharField(max_length=200) key = fields.CharField(max_length=20) value = fields.JSONField() status: Status = fields.IntEnumField(Status, default=Status.on) class Meta: table = "configs"
class Config(Model): label = fields.CharField(max_length=200) key = fields.CharField(max_length=20) value = fields.JSONField() status: Status = fields.IntEnumField(Status, default=Status.on) def __str__(self): return f'{self.pk}#{self.label}'
class Permission(Model): label = fields.CharField(max_length=50) model = fields.CharField(max_length=50) action: enums.PermissionAction = fields.IntEnumField( enums.PermissionAction, default=enums.PermissionAction.read) def __str__(self): return self.label
class SysMenuParams(DateModelMixin, AbstractBaseModel): sys_menu = fields.ForeignKeyField('models.SysMenu', related_name='params') param_type = fields.IntEnumField(ParamTypeEnum, description='params?query') key = fields.CharField(max_length=255, description='参数键') value = fields.CharField(max_length=255, description='参数值') class Meta: table = "sys_menu_params"
class MarketAdminUser(Base): """策略市场管理员表""" id = fields.IntField(pk=True) uuid = fields.UUIDField(null=False, index=True) name = fields.CharField(max_length=32, unique=True) phone = fields.CharField(max_length=14, unique=True) email = fields.CharField(max_length=63, unique=True) password = fields.CharField(max_length=128) scope1 = fields.CharField(max_length=32) # 管理员职权范围(超市级别) scope2 = fields.IntEnumField(UserScope2) # 管理员职权范围(超市内级别) status = fields.IntEnumField(UserStatus, default=UserStatus.normal) create_dt = fields.DatetimeField(auto_now_add=True) # 创建时间 update_dt = fields.DatetimeField(auto_now=True) def is_active(self): return self.status == 1
class BaiduAi(BaseModel): app_id = fields.CharField(max_length=50) api_key = fields.CharField(max_length=50) app_secret = fields.CharField(max_length=50) category = fields.IntEnumField(BaiduAiCategory, description='应用类别', default=BaiduAiCategory.id_card) def __str__(self): return f'{self.pk}#{self.app_id}'
class GameTest(Model): game = fields.ForeignKeyField("models.Game", related_name="announcements") message = fields.BigIntField(unique=True) end = fields.DatetimeField() status = fields.IntEnumField(TestStatus, default=TestStatus.STARTED) feedback = fields.CharField(max_length=150, unique=True) def __str__(self): return f"Test {self.game}-{self.message}: {TestStatus._value2member_map_[self.status]} (end at {self.end})"
class UserCollection(Base): """用户收藏列表""" id = fields.IntField(pk=True) url = fields.CharField(max_length=512) product_id = fields.UUIDField(index=True) # 商品 ID product_type = fields.IntEnumField(ProductType) # 商品类型:1= 策略,2= 套餐,3=vip user_id = fields.IntField() canceled = fields.BooleanField(default=False) # 收藏状态:1= 正常,2= 取消收藏
class Swap(Model): id = fields.BigIntField(pk=True) creator = fields.ForeignKeyField('models.Holder', 'swaps') price = fields.BigIntField() amount = fields.BigIntField() amount_left = fields.BigIntField() level = fields.BigIntField() status = fields.IntEnumField(SwapStatus) timestamp = fields.DatetimeField()
class Tag(Base): """标签""" id = fields.IntField(pk=True) name = fields.CharField(max_length=32, unique=True, index=True) tag_type = fields.IntEnumField(TagType, default=1) # 标签类型:1= 标签,2= 风格 create_dt = fields.DatetimeField(auto_now_add=True) # 创建时间 update_dt = fields.DatetimeField(auto_now=True) deleted = fields.BooleanField(default=False) # 删除标记
class ReviewRecord(Base): """上下架审核记录表""" id = fields.IntField(pk=True) market = fields.ForeignKeyField("market.StrategyMarket", "reviews", on_delete=fields.SET_NULL, null=True) product_id = fields.UUIDField(index=True) # 商品 ID product_type = fields.IntEnumField(ProductType) # 商品类型:1= 策略,2= 套餐,3=vip create_dt = fields.DatetimeField(auto_now_add=True) update_dt = fields.DatetimeField(auto_now=True) operation = fields.IntEnumField(ReviewOP) # 操作类型:1= 上架,2= 下架 user_id = fields.IntField() # 申请人 contact = fields.CharField(max_length=14) # 申请人手机号 # 审核 review_status = fields.IntEnumField(ReviewStatus, default=1) # 审核状态 review_dt = fields.DatetimeField(null=True) review_msg = fields.TextField(null=True) # 审核备注
class Stat(Base): driver = fields.ForeignKeyField('models.Driver', related_name='stats') category: Category = fields.IntEnumField(Category) stat_type: StatsType = fields.IntEnumField(StatsType) avg_incidents = fields.TextField(null=True) total_laps = fields.IntField(null=True) laps_led = fields.IntField(null=True) laps_led_percentage = fields.TextField(null=True) points_avg = fields.IntField(null=True) points_club = fields.IntField(null=True) poles = fields.IntField(null=True) avg_start_pos = fields.IntField(null=True) avg_finish_pos = fields.IntField(null=True) total_starts = fields.IntField(null=True) top_five_percentage = fields.IntField(null=True) total_top_fives = fields.IntField(null=True) win_percentage = fields.IntField(null=True) total_wins = fields.IntField(null=True) year = fields.TextField(null=True)
class Trade(Model): id = fields.IntField(pk=True) symbol = fields.CharField(max_length=5) trader = fields.CharField(36) side = fields.IntEnumField(enum_type=TradeSide) quantity = fields.DecimalField(decimal_places=6, max_digits=20) price = fields.DecimalField(decimal_places=6, max_digits=20) slippage = fields.DecimalField(decimal_places=6, max_digits=20) level = fields.BigIntField() timestamp = fields.DatetimeField()
class Product(Model): categories = fields.ManyToManyField("models.Category") name = fields.CharField(max_length=50) view_num = fields.IntField(description="View Num") sort = fields.IntField() is_reviewed = fields.BooleanField(description="Is Reviewed") type = fields.IntEnumField(ProductType, description="Product Type") image = fields.CharField(max_length=200) body = fields.TextField() created_at = fields.DatetimeField(auto_now_add=True)
class Reminder(Model): id = fields.IntField(pk=True, generated=True) user_id = fields.BigIntField() channel_id = fields.BigIntField() guild_id = fields.CharField(max_length=20) message_id = fields.BigIntField() dm = fields.BooleanField() to_remind = fields.CharField(max_length=1800, collation="utf8mb4_general_ci") send = fields.BigIntField(null=True) time = fields.BigIntField() status = fields.IntEnumField(ReminderStatus)
class AppVersion(BaseModel): app = fields.ForeignKeyField('models.App', related_name='app_versions') channel = fields.CharField(max_length=20, description='渠道') device_sys = fields.IntEnumField(DeviceSys, default=DeviceSys.android, description='操作系统') version_code = fields.CharField(max_length=20, description='版本号') describe = fields.CharField(max_length=200, description='描述') download_url = fields.CharField(max_length=200, description='下载链接') is_update = fields.BooleanField(default=False, description='是否更新') class Meta: ordering = ['-id'] indexes = (('app', 'device_sys', 'channel'),)
class DiscordUser(Model): discord_id = fields.BigIntField(pk=True) first_seen = fields.DatetimeField(auto_now_add=True) support_tickets: fields.ReverseRelation[SupportTicket] closed_tickets: fields.ReverseRelation[SupportTicket] # inventory: fields.OneToOneRelation[UserInventory] members: fields.ReverseRelation["DiscordMember"] votes: fields.ReverseRelation["Vote"] tags: fields.ReverseRelation["Tag"] tags_aliases: fields.ReverseRelation["TagAlias"] name = fields.TextField() discriminator = fields.CharField(4) trophys = fields.JSONField(default=dict) ping_friendly = fields.BooleanField(default=True) language = fields.CharField(6, default="en") first_use = fields.BooleanField(default=True) access_level_override = fields.IntEnumField(enum_type=AccessLevel, default=AccessLevel.DEFAULT) boss_kills = fields.IntField(default=0) async def get_or_create_support_ticket(self) -> SupportTicket: support_ticket: typing.Optional[ SupportTicket] = await SupportTicket.filter(user=self, closed=False).first() if not support_ticket: support_ticket = SupportTicket(user=self) return support_ticket async def support_ticket_count(self, **filter_kwargs) -> int: return await SupportTicket.filter(user=self, **filter_kwargs).count() class Meta: table = "users" def get_access_level(self): return self.access_level_override def __str__(self): return self.name def __repr__(self): return f"<User name={self.name}#{self.discriminator}>"