# Generated manually for fund freeze P0 tables

from decimal import Decimal

from django.db import migrations, models


class Migration(migrations.Migration):

    dependencies = [
        ('jituan', '0016_club_order_grab_link'),
    ]

    operations = [
        migrations.CreateModel(
            name='ClubFundFreezeConfig',
            fields=[
                ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
                ('club_id', models.CharField(db_index=True, max_length=16, verbose_name='俱乐部')),
                ('role', models.CharField(choices=[('dashou', '打手'), ('guanshi', '管事'), ('zuzhang', '组长'), ('shenheguan', '考核官')], db_index=True, max_length=16, verbose_name='角色')),
                ('enabled', models.BooleanField(default=False, verbose_name='是否启用冻结')),
                ('freeze_mode', models.SmallIntegerField(choices=[(1, '按比例'), (2, '固定额'), (3, '比例+单笔上限')], default=1)),
                ('freeze_rate', models.DecimalField(decimal_places=6, default=Decimal('0'), help_text='0.2=20%', max_digits=8, verbose_name='冻结比例')),
                ('freeze_fixed', models.DecimalField(decimal_places=2, default=Decimal('0'), max_digits=12)),
                ('freeze_cap', models.DecimalField(decimal_places=2, default=Decimal('0'), max_digits=12, verbose_name='单笔冻结上限(0=不限)')),
                ('min_credit_to_freeze', models.DecimalField(decimal_places=2, default=Decimal('0'), max_digits=12, verbose_name='低于此入账不冻')),
                ('source_scope', models.JSONField(blank=True, default=list, help_text='空=全部来源；如 ["order_settle"]', verbose_name='入账来源白名单')),
                ('unfreeze_trigger', models.CharField(choices=[('time_only', '仅到期'), ('condition_only', '仅条件达标'), ('time_and_condition', '到期且达标'), ('time_or_condition', '到期或达标'), ('manual_only', '仅手动')], default='time_only', max_length=32)),
                ('schedule_mode', models.CharField(choices=[('all_at_once', '一次全解'), ('installment', '分期解冻')], default='all_at_once', max_length=16)),
                ('installment_json', models.JSONField(blank=True, default=dict, help_text='{"steps":[...]}', verbose_name='分期计划')),
                ('condition_json', models.JSONField(blank=True, default=dict, verbose_name='解冻条件')),
                ('freeze_min_days', models.IntegerField(default=0, verbose_name='最短冻结天数')),
                ('remark', models.CharField(blank=True, default='', max_length=255)),
                ('updated_by', models.CharField(blank=True, default='', max_length=32)),
                ('CreateTime', models.DateTimeField(auto_now_add=True)),
                ('UpdateTime', models.DateTimeField(auto_now=True)),
            ],
            options={
                'verbose_name': '资金冻结规则',
                'db_table': 'club_fund_freeze_config',
                'unique_together': {('club_id', 'role')},
            },
        ),
        migrations.CreateModel(
            name='FundFreezeLedger',
            fields=[
                ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
                ('club_id', models.CharField(db_index=True, max_length=16)),
                ('user_id', models.CharField(db_index=True, max_length=16, verbose_name='UserUID')),
                ('role', models.CharField(db_index=True, max_length=16)),
                ('amount_total', models.DecimalField(decimal_places=2, max_digits=12)),
                ('amount_unfrozen', models.DecimalField(decimal_places=2, default=Decimal('0'), max_digits=12)),
                ('status', models.SmallIntegerField(db_index=True, default=1)),
                ('frozen_at', models.DateTimeField(auto_now_add=True, db_index=True)),
                ('source_type', models.CharField(db_index=True, max_length=32)),
                ('order_id', models.CharField(blank=True, db_index=True, default='', max_length=64)),
                ('czjilu_id', models.CharField(blank=True, db_index=True, default='', max_length=64)),
                ('biz_id', models.CharField(max_length=64, verbose_name='幂等业务键')),
                ('freeze_reason', models.CharField(blank=True, default='', max_length=255)),
                ('config_snapshot', models.JSONField(blank=True, default=dict)),
                ('current_step', models.IntegerField(default=1)),
                ('next_eligible_at', models.DateTimeField(blank=True, db_index=True, null=True)),
                ('CreateTime', models.DateTimeField(auto_now_add=True)),
                ('UpdateTime', models.DateTimeField(auto_now=True)),
            ],
            options={
                'verbose_name': '资金冻结主单',
                'db_table': 'fund_freeze_ledger',
                'unique_together': {('club_id', 'role', 'source_type', 'biz_id')},
            },
        ),
        migrations.CreateModel(
            name='FundUnfreezeEvent',
            fields=[
                ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
                ('ledger_id', models.BigIntegerField(db_index=True)),
                ('club_id', models.CharField(db_index=True, max_length=16)),
                ('user_id', models.CharField(db_index=True, max_length=16)),
                ('role', models.CharField(max_length=16)),
                ('step_seq', models.IntegerField(default=1)),
                ('amount', models.DecimalField(decimal_places=2, max_digits=12)),
                ('unfrozen_at', models.DateTimeField(auto_now_add=True, db_index=True)),
                ('trigger', models.CharField(default='schedule', max_length=16)),
                ('reason', models.CharField(blank=True, default='', max_length=255)),
                ('operator_id', models.CharField(blank=True, default='', max_length=32)),
                ('condition_snapshot', models.JSONField(blank=True, default=dict)),
            ],
            options={
                'verbose_name': '资金解冻事件',
                'db_table': 'fund_unfreeze_event',
            },
        ),
        migrations.CreateModel(
            name='FundRiskStatDaily',
            fields=[
                ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
                ('club_id', models.CharField(db_index=True, max_length=16)),
                ('user_id', models.CharField(db_index=True, max_length=16)),
                ('role', models.CharField(db_index=True, max_length=16)),
                ('day', models.DateField(db_index=True)),
                ('completed_orders', models.IntegerField(default=0)),
                ('fine_count', models.IntegerField(default=0)),
                ('complaint_count', models.IntegerField(default=0)),
                ('valid_invite_count', models.IntegerField(default=0)),
                ('meta_json', models.JSONField(blank=True, default=dict)),
                ('CreateTime', models.DateTimeField(auto_now_add=True)),
                ('UpdateTime', models.DateTimeField(auto_now=True)),
            ],
            options={
                'verbose_name': '资金风险日汇总',
                'db_table': 'fund_risk_stat_daily',
                'unique_together': {('club_id', 'user_id', 'role', 'day')},
            },
        ),
        migrations.AddIndex(
            model_name='fundfreezeledger',
            index=models.Index(fields=['status', 'next_eligible_at'], name='idx_ffl_status_next'),
        ),
        migrations.AddIndex(
            model_name='fundfreezeledger',
            index=models.Index(fields=['user_id', 'role', 'status'], name='idx_ffl_user_role'),
        ),
        migrations.AddIndex(
            model_name='fundfreezeledger',
            index=models.Index(fields=['club_id', 'status', 'frozen_at'], name='idx_ffl_club_st'),
        ),
        migrations.AddIndex(
            model_name='fundriskstatdaily',
            index=models.Index(fields=['club_id', 'role', 'day'], name='idx_frsd_club_role_day'),
        ),
    ]
