# coding=utf-8

from django.db import models


class Config(models.Model):
    # 购买商品赠送积分比例
    KEY_POINT_RULE = "point_rule"
    # 推荐用户首次购买返利  1、2、3级返现金比例  4、5级返积分比例
    KEY_FIRST_LEVEL1 = "first_lv1"
    KEY_FIRST_LEVEL2 = "first_lv2"
    KEY_FIRST_LEVEL3 = "first_lv3"
    KEY_FIRST_LEVEL4 = "first_lv4"
    KEY_FIRST_LEVEL5 = "first_lv5"
    # 推荐用户再次购买返利  1、2、3级返现金比例  4、5级返积分比例
    KEY_AGAIN_LEVEL1 = "again_lv1"
    KEY_AGAIN_LEVEL2 = "again_lv2"
    KEY_AGAIN_LEVEL3 = "again_lv3"
    KEY_AGAIN_LEVEL4 = "again_lv4"
    KEY_AGAIN_LEVEL5 = "again_lv5"

    property = models.CharField(max_length=100, verbose_name=u'属性')
    value = models.TextField(verbose_name=u'值')

    class Meta:
        db_table = "system_config"
        verbose_name = u"综合设置"
        index_together = (
            'property',
        )
        default_permissions = ()
        permissions = []

    @staticmethod
    def getPackagePercentage(tenant_id):
        try:
            row = Config.objects.get(property=Config.KEY_POINT_RULE)
            return float(row.value)
        except:
            return 0
