from django.db import migrations, models
import django.db.models.deletion


class Migration(migrations.Migration):

    dependencies = [
        ('rank', '0003_rename_dashou_biao_dashou__36e1c3_idx_dashou_biao_dashou__502414_idx_and_more'),
    ]

    operations = [
        migrations.CreateModel(
            name='RankRewardScheme',
            fields=[
                ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
                ('club_id', models.CharField(db_index=True, max_length=16, verbose_name='俱乐部ID')),
                ('shenfen', models.CharField(db_index=True, max_length=16, verbose_name='身份')),
                ('period_type', models.CharField(choices=[('day', '日榜(昨日)'), ('week', '周榜(上周)'), ('month', '月榜(上月)')], max_length=16, verbose_name='周期类型')),
                ('sort_field', models.CharField(max_length=32, verbose_name='排序指标键')),
                ('title', models.CharField(blank=True, default='', max_length=128, verbose_name='展示标题')),
                ('description', models.TextField(blank=True, default='', verbose_name='规则说明')),
                ('enabled', models.BooleanField(default=False, verbose_name='启用')),
                ('claim_days', models.PositiveSmallIntegerField(default=30, verbose_name='领取有效天数')),
                ('min_metric', models.DecimalField(decimal_places=2, default=0, max_digits=12, verbose_name='最低指标门槛')),
                ('CreateTime', models.DateTimeField(auto_now_add=True, verbose_name='创建时间')),
                ('UpdateTime', models.DateTimeField(auto_now=True, verbose_name='更新时间')),
            ],
            options={
                'verbose_name': '排行榜奖励方案',
                'verbose_name_plural': '排行榜奖励方案',
                'db_table': 'rank_reward_scheme',
                'unique_together': {('club_id', 'shenfen', 'period_type')},
            },
        ),
        migrations.CreateModel(
            name='RankRewardTier',
            fields=[
                ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
                ('rank_from', models.PositiveSmallIntegerField(verbose_name='名次起')),
                ('rank_to', models.PositiveSmallIntegerField(verbose_name='名次止')),
                ('reward_amount', models.DecimalField(decimal_places=2, max_digits=10, verbose_name='奖金(元)')),
                ('label', models.CharField(blank=True, default='', max_length=32, verbose_name='档位标签')),
                ('scheme', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='tiers', to='rank.rankrewardscheme', verbose_name='方案')),
            ],
            options={
                'verbose_name': '排行榜奖励档位',
                'verbose_name_plural': '排行榜奖励档位',
                'db_table': 'rank_reward_tier',
                'ordering': ['rank_from'],
            },
        ),
        migrations.CreateModel(
            name='RankRewardSettlement',
            fields=[
                ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
                ('club_id', models.CharField(db_index=True, max_length=16, verbose_name='俱乐部ID')),
                ('period_key', models.CharField(db_index=True, max_length=32, verbose_name='周期键')),
                ('period_start', models.DateField(verbose_name='统计起始')),
                ('period_end', models.DateField(verbose_name='统计截止')),
                ('riqi_label', models.CharField(max_length=16, verbose_name='前端周期文案')),
                ('sort_field', models.CharField(max_length=32, verbose_name='结算时排序字段快照')),
                ('settled_at', models.DateTimeField(auto_now_add=True, verbose_name='结算时间')),
                ('claim_count', models.PositiveIntegerField(default=0, verbose_name='生成待领取数')),
                ('scheme', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='rank.rankrewardscheme', verbose_name='方案')),
            ],
            options={
                'verbose_name': '排行榜奖励结算',
                'verbose_name_plural': '排行榜奖励结算',
                'db_table': 'rank_reward_settlement',
                'unique_together': {('club_id', 'scheme', 'period_key')},
            },
        ),
        migrations.CreateModel(
            name='RankRewardClaim',
            fields=[
                ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
                ('club_id', models.CharField(db_index=True, max_length=16, verbose_name='俱乐部ID')),
                ('yonghuid', models.CharField(db_index=True, max_length=7, verbose_name='用户ID')),
                ('shenfen', models.CharField(max_length=16, verbose_name='身份')),
                ('mingci', models.PositiveSmallIntegerField(verbose_name='名次')),
                ('metric_value', models.DecimalField(decimal_places=2, default=0, max_digits=12, verbose_name='指标快照')),
                ('reward_amount', models.DecimalField(decimal_places=2, max_digits=10, verbose_name='奖金')),
                ('status', models.PositiveSmallIntegerField(choices=[(0, '待领取'), (1, '已领取'), (2, '已过期'), (3, '已取消')], db_index=True, default=0)),
                ('expire_at', models.DateTimeField(verbose_name='领取截止')),
                ('claimed_at', models.DateTimeField(blank=True, null=True, verbose_name='领取时间')),
                ('balance_field', models.CharField(max_length=32, verbose_name='入账字段')),
                ('idempotent_key', models.CharField(max_length=96, unique=True, verbose_name='幂等键')),
                ('CreateTime', models.DateTimeField(auto_now_add=True, verbose_name='创建时间')),
                ('UpdateTime', models.DateTimeField(auto_now=True, verbose_name='更新时间')),
                ('settlement', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='claims', to='rank.rankrewardsettlement', verbose_name='结算批次')),
            ],
            options={
                'verbose_name': '排行榜奖励领取',
                'verbose_name_plural': '排行榜奖励领取',
                'db_table': 'rank_reward_claim',
                'indexes': [
                    models.Index(fields=['yonghuid', 'status'], name='rank_reward_yonghu_st_idx'),
                    models.Index(fields=['club_id', 'status'], name='rank_reward_club_st_idx'),
                ],
            },
        ),
    ]
