Exemple #1
0
class Account(models.Model, BaseModel):
    class Meta:
        app_label = 'trade'
        db_table = 'account'
        unique_together = [
            ('user_id', 'platform_id'),
            ('username',),
        ]

    class Role(ModelEnum):
        PLATFORM_OWNER = 'platform_owner'   # 平台属主
        PAY_USER = '******'               # 付费用户
        FREE_USER = '******'             # 免费用户

    id = models.AutoField(primary_key=True)
    user_id = models.BigIntegerField()
    platform_id = models.BigIntegerField()
    #
    username = models.CharField(max_length=255)
    password = models.CharField(max_length=255)
    radius_password = models.CharField(max_length=255)
    is_enable = models.BooleanField(default=True)
    role = models.CharField(max_length=32, choices=Role.choices(), default=Role.PAY_USER.value)
    #
    expired_at = models.DateTimeField()
    #
    created_at = models.DateTimeField(auto_now_add=True)    # auto_now_add only generated on 新创建
    updated_at = models.DateTimeField(auto_now=True)        # auto_now is generated on 每次修改

    @classmethod
    def get(cls, user_id, platform_id) -> 'Account':
        obj = cls.objects.filter(user_id=user_id, platform_id=platform_id).first()
        return obj or None

    @classmethod
    def search(cls, user_id):
        accounts = cls.objects.filter(user_id=user_id)
        if not accounts:
            return []
        return accounts

    @property
    def status(self):
        # expired: 已过期; working: 使用中; disable: 已停用
        if not self.is_enable:
            return 'disable'

        if self.expired_at > timezone.localtime():
            return 'working'

        return 'expired'

    def to_dict(self, fields=None, exclude=None):
        data = super(self.__class__, self).to_dict(fields=fields, exclude=exclude)
        data['status'] = self.status
        return data
Exemple #2
0
class ApOwner(models.Model, BaseModel):
    class Meta:
        app_label = 'trade'
        db_table = 'ap_owner'

    id = models.AutoField(primary_key=True)
    username = models.CharField(max_length=255)
    ap_mac = models.CharField(max_length=24)  # 连接符"-", 全部大写. 5E-DA-F9-68-41-2B
    is_public = models.BooleanField(default=False)
    remark = models.CharField(max_length=32)
class ResourceChange(models.Model, BaseModel):
    class Meta:
        app_label = 'trade'
        db_table = 'resource_change'

    id = models.AutoField(primary_key=True)
    user_id = models.BigIntegerField()
    out_trade_no = models.CharField(max_length=255)  # 商家订单号 out_trade_no
    before = models.DateTimeField()
    after = models.DateTimeField()
    created_at = models.DateTimeField(
        auto_now_add=True)  # auto_now_add only generated on 新创建
Exemple #4
0
class StatAp(models.Model, BaseModel):
    class Meta:
        app_label = 'trade'
        db_table = 'stat_ap'

    id = models.AutoField(primary_key=True)
    ap_mac = models.CharField(max_length=24)  # 连接符"-", 全部大写. 5E-DA-F9-68-41-2B
    last_auth_user = models.CharField(max_length=255)
    last_auth_date = models.DateField()
    #
    created_at = models.DateTimeField(
        auto_now_add=True)  # auto_now_add only generated on 新创建
Exemple #5
0
class StatUser(models.Model, BaseModel):
    class Meta:
        app_label = 'trade'
        db_table = 'stat_user'

    id = models.AutoField(primary_key=True)
    username = models.CharField(max_length=255)
    user_mac = models.CharField(
        max_length=24)  # 连接符"-", 全部大写. 5E-DA-F9-68-41-2B
    ap_mac = models.CharField(max_length=24)  # 连接符"-", 全部大写. 5E-DA-F9-68-41-2B
    accept_count = models.IntegerField()
    #
    created_at = models.DateTimeField(
        auto_now_add=True)  # auto_now_add only generated on 新创建
Exemple #6
0
class MacAccount(models.Model, BaseModel):
    class Meta:
        app_label = 'trade'
        db_table = 'mac_account'
        unique_together = [
            ('username', ),
        ]

    id = models.AutoField(primary_key=True)
    #
    username = models.CharField(max_length=255)
    radius_password = models.CharField(max_length=255)
    ap_mac = models.CharField(max_length=24)  # 连接符"-", 全部大写. 5E-DA-F9-68-41-2B
    is_enable = models.BooleanField(default=True)
    bind_username = models.CharField(max_length=255, null=True)
    #
    expired_at = models.DateTimeField()
    #
    created_at = models.DateTimeField(
        auto_now_add=True)  # auto_now_add only generated on 新创建
Exemple #7
0
class Order(models.Model, BaseModel):
    class Meta:
        app_label = 'trade'
        db_table = 'orders'
        unique_together = [
            ('out_trade_no', ),
        ]

    class Status(ModelEnum):
        UNPAID = 'unpaid'  # 未支付
        PAID = 'paid'  # 已支付
        EXPIRED = 'expired'  # 已过期

    id = models.AutoField(primary_key=True)
    user_id = models.BigIntegerField()
    platform_id = models.BigIntegerField()
    #
    openid = models.CharField(max_length=255)
    out_trade_no = models.CharField(max_length=255)  # 商家订单号 out_trade_no
    attach = models.CharField(max_length=255)  # 附加信息
    transaction_id = models.CharField(default='', max_length=255)  # 微信订单号
    total_fee = models.IntegerField()  # 单位分
    appid = models.CharField(max_length=32)  # appid
    mch_id = models.CharField(max_length=32)  # 商户号
    status = models.CharField(default='unpaid',
                              max_length=32,
                              choices=Status.choices())
    created_at = models.DateTimeField(auto_now_add=True)
    updated_at = models.DateTimeField(auto_now=True)

    @classmethod
    def get(cls, out_trade_no) -> Order:
        order = cls.objects.filter(out_trade_no=out_trade_no).first()
        if not order:
            return None
        return order

    def is_paid(self) -> bool:
        return self.status == Order.Status.PAID.value
Exemple #8
0
class User(models.Model, BaseModel):
    class Meta:
        app_label = 'trade'
        db_table = 'user'
        unique_together = [
            ('user_id',),
            ('openid',),
        ]

    id = models.AutoField(primary_key=True)
    user_id = models.BigIntegerField(default=new_id)
    openid = models.CharField(max_length=255)
    bind_platform_id = models.BigIntegerField()
    # 头像: JPEG 格式 http://thirdwx.qlogo.cn/mmopen/vi_32/lRUxxd0YsmibtZKWiaw7g/132
    nickname = models.CharField(max_length=255)
    picture_url = models.URLField(max_length=512)
    #
    created_at = models.DateTimeField(auto_now_add=True)    # auto_now_add only generated on 新创建
    updated_at = models.DateTimeField(auto_now=True)        # auto_now is generated on 每次修改

    @classmethod
    def get(cls, user_id=None, openid=None) -> 'User':
        if user_id:
            obj = cls.objects.filter(user_id=user_id).first()
        elif openid:
            obj = cls.objects.filter(openid=openid).first()
        else:
            raise Exception('param error')
        if not obj:
            return None
        return obj

    @classmethod
    def search(cls, nickname__contains):
        users = cls.objects.filter(nickname__contains=nickname__contains)
        if not users:
            return []
        return users