from django.db import models


# Create your models here.
# 用户表
class UserModel(models.Model):
    id = models.AutoField(primary_key=True)
    username = models.CharField(max_length=64, unique=True, default='', verbose_name='用户名')
    password = models.CharField(max_length=128, default='', verbose_name='密码')
    role_id = models.CharField(max_length=64, default='', verbose_name='角色')
    addTime = models.IntegerField(verbose_name='添加时间', default=0)
    updTime = models.IntegerField(verbose_name='更新时间', default=0)

    class Meta:
        ordering = ('-addTime',)
        verbose_name = '用户表'
        db_table = 'lang_user'

    def __str__(self):
        return self.username


# 语种
class LangAreaModel(models.Model):
    id = models.AutoField(primary_key=True)
    lang = models.CharField(max_length=32, default='', verbose_name='语言')
    addTime = models.IntegerField(verbose_name='添加时间', default=0)
    updTime = models.IntegerField(verbose_name='更新时间', default=0)

    class Meta:
        ordering = ('-addTime',)
        verbose_name = '语种'
        db_table = 'lang_area'


# 用户关联语种配置
class LangSetModel(models.Model):
    id = models.AutoField(primary_key=True)
    user = models.ForeignKey(UserModel, verbose_name='用户表id', to_field='id', on_delete=models.CASCADE)
    lang = models.ForeignKey(LangAreaModel, verbose_name='关联语种id', to_field='id', on_delete=models.CASCADE)
    addTime = models.IntegerField(verbose_name='添加时间', default=0)
    updTime = models.IntegerField(verbose_name='更新时间', default=0)

    class Meta:
        ordering = ('-addTime',)
        verbose_name = '用户关联语种配置'
        db_table = 'lang_set'


# 词汇
class LangKeyModel(models.Model):
    id = models.AutoField(primary_key=True)
    word_key = models.CharField(default='', max_length=64, verbose_name='词汇键', unique=True)
    addTime = models.IntegerField(default=0, verbose_name='添加时间')
    updTime = models.IntegerField(default=0, verbose_name='更新时间')

    class Meta:
        ordering = ('-addTime',)
        verbose_name = '词汇k表'
        db_table = 'lang_key'


class LangValModel(models.Model):
    id = models.AutoField(primary_key=True)
    lk = models.ForeignKey(LangKeyModel, verbose_name='v关联词汇k', to_field='id', on_delete=models.CASCADE)
    la = models.ForeignKey(LangAreaModel, verbose_name='词汇k关联语种', to_field='id', on_delete=models.CASCADE)
    word_val = models.CharField(default='', max_length=64, verbose_name='词汇v')
    addTime = models.IntegerField(default=0, verbose_name='添加时间')
    updTime = models.IntegerField(default=0, verbose_name='更新时间')

    class Meta:
        ordering = ('-addTime',)
        verbose_name = '词汇v表'
        db_table = 'lang_val'


#
class AsImgModel(models.Model):
    id = models.AutoField(primary_key=True)  # 主键
    asin = models.CharField(default='', max_length=32, verbose_name='产品编码', db_index=True)  # 产品asin吗，唯一
    url = models.CharField(default='', max_length=128, verbose_name='产品图片url')
    md5 = models.CharField(default='', max_length=128, verbose_name='图片md5')
    addTime = models.IntegerField(default=0, verbose_name="添加时间")
    updTime = models.IntegerField(default=0, verbose_name='更新时间')

    class Meta:
        ordering = ('-addTime',)
        verbose_name = '亚马逊图片表'
        db_table = 'as_img'


class SysSetModel(models.Model):
    id = models.AutoField(primary_key=True)
    key = models.CharField(default='', max_length=64, verbose_name='键名')  # 亚马逊产品图片检测邮箱
    val = models.CharField(default='', max_length=64, verbose_name='键值')  # 亚马逊产品图片检测邮箱
    addTime = models.IntegerField(default=0, verbose_name='添加时间')
    updTime = models.IntegerField(default=0, verbose_name='更新时间')

    class Meta:
        ordering = ('-addTime',)
        verbose_name = '系统配置表'
        db_table = 'sys_set'


# 手机注册表 抽奖
class phoneNumModel(models.Model):
    id = models.AutoField(primary_key=True)
    phone = models.CharField(default='', verbose_name='手机', max_length=11)
    status = models.SmallIntegerField(default=0, verbose_name='中奖状态')  # 1为c611,2为c612
    addr = models.TextField(blank=True, default='', verbose_name=u'更新内容')
    addTime = models.IntegerField(default=0, verbose_name='添加时间')
    updTime = models.IntegerField(default=0, verbose_name='更新时间')

    class Meta:
        ordering = ('-addTime',)
        verbose_name = '手机注册表'
        db_table = 'phoneNum'

# sku套装名称表
class skuSuitModel(models.Model):
    id = models.AutoField(primary_key=True)
    suitName = models.CharField(default='', verbose_name='套装名称', max_length=64)
    addTime = models.IntegerField(default=0, verbose_name='添加时间')
    updTime = models.IntegerField(default=0, verbose_name='更新时间')
    class Meta:
        ordering = ('-id',)
        verbose_name = 'sku套装名称表'
        db_table = 'sku_suit_name'
# sku规则名称表
class skuRuleModel(models.Model):
    id = models.AutoField(primary_key=True)
    rs = models.ForeignKey(skuSuitModel, verbose_name='关联套装名称表', to_field='id', on_delete=models.CASCADE)
    ruleName = models.CharField(default='', verbose_name='规则名称', max_length=64)
    addTime = models.IntegerField(default=0, verbose_name='添加时间')
    updTime = models.IntegerField(default=0, verbose_name='更新时间')
    class Meta:
        ordering = ('-id',)
        verbose_name = 'sku规则名称表'
        db_table = 'sku_rule_name'
#sku 条件表
class skuConditionModel(models.Model):
    id = models.AutoField(primary_key=True)
    cr = models.ForeignKey(skuRuleModel , verbose_name='关联规则名称表', to_field='id', on_delete=models.CASCADE)
    numName = models.CharField(default='', verbose_name='字母表示', max_length=64)
    conditionName = models.CharField(default='', verbose_name='条件名称', max_length=64)
    addTime = models.IntegerField(default=0, verbose_name='添加时间')
    updTime = models.IntegerField(default=0, verbose_name='更新时间')
    class Meta:
        ordering = ('-id',)
        verbose_name = 'sku条件表'
        db_table = 'sku_condition_name'


# 用户关联可编辑语种配置
class LangPermModel(models.Model):
    id = models.AutoField(primary_key=True)
    user = models.ForeignKey(UserModel, verbose_name='用户表id', to_field='id', on_delete=models.CASCADE)
    lang = models.ForeignKey(LangAreaModel, verbose_name='关联语种id', to_field='id', on_delete=models.CASCADE)
    addTime = models.IntegerField(verbose_name='添加时间', default=0)
    updTime = models.IntegerField(verbose_name='更新时间', default=0)

    class Meta:
        ordering = ('-addTime',)
        verbose_name = '用户关联语种配置'
        db_table = 'lang_perm'