# Generated by Django 6.0.1 on 2026-02-10 16:35

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


class Migration(migrations.Migration):

    dependencies = [
        ('shop', '0015_esp32config_commission_rate_and_more'),
        migrations.swappable_dependency(settings.AUTH_USER_MODEL),
    ]

    operations = [
        migrations.CreateModel(
            name='WeChatUser',
            fields=[
                ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
                ('openid', models.CharField(max_length=64, unique=True, verbose_name='OpenID')),
                ('unionid', models.CharField(blank=True, db_index=True, max_length=64, null=True, verbose_name='UnionID')),
                ('session_key', models.CharField(blank=True, max_length=64, verbose_name='SessionKey')),
                ('nickname', models.CharField(blank=True, max_length=64, verbose_name='昵称')),
                ('avatar_url', models.URLField(blank=True, verbose_name='头像URL')),
                ('gender', models.IntegerField(default=0, help_text='0:未知, 1:男, 2:女', verbose_name='性别')),
                ('country', models.CharField(blank=True, max_length=64, verbose_name='国家')),
                ('province', models.CharField(blank=True, max_length=64, verbose_name='省份')),
                ('city', models.CharField(blank=True, max_length=64, verbose_name='城市')),
                ('created_at', models.DateTimeField(auto_now_add=True, verbose_name='创建时间')),
                ('updated_at', models.DateTimeField(auto_now=True, verbose_name='更新时间')),
                ('user', models.OneToOneField(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, related_name='wechat_profile', to=settings.AUTH_USER_MODEL, verbose_name='关联系统用户')),
            ],
            options={
                'verbose_name': '微信用户',
                'verbose_name_plural': '微信用户管理',
            },
        ),
        migrations.CreateModel(
            name='Distributor',
            fields=[
                ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
                ('level', models.IntegerField(default=1, verbose_name='分销等级')),
                ('commission_rate', models.DecimalField(decimal_places=4, default=0.1, help_text='例如 0.10 表示 10%', max_digits=5, verbose_name='分佣比例')),
                ('total_earnings', models.DecimalField(decimal_places=2, default=0.0, max_digits=12, verbose_name='累计收益')),
                ('withdrawable_balance', models.DecimalField(decimal_places=2, default=0.0, max_digits=12, verbose_name='可提现余额')),
                ('status', models.CharField(choices=[('pending', '审核中'), ('active', '正常'), ('disabled', '已禁用')], default='pending', max_length=20, verbose_name='状态')),
                ('invite_code', models.CharField(blank=True, max_length=20, unique=True, verbose_name='邀请码')),
                ('qr_code_url', models.URLField(blank=True, verbose_name='推广二维码URL')),
                ('created_at', models.DateTimeField(auto_now_add=True, verbose_name='申请时间')),
                ('updated_at', models.DateTimeField(auto_now=True, verbose_name='更新时间')),
                ('parent', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='children', to='shop.distributor', verbose_name='上级分销员')),
                ('user', models.OneToOneField(on_delete=django.db.models.deletion.CASCADE, related_name='distributor', to='shop.wechatuser', verbose_name='关联微信用户')),
            ],
            options={
                'verbose_name': '分销员',
                'verbose_name_plural': '分销员管理',
            },
        ),
        migrations.AddField(
            model_name='order',
            name='wechat_user',
            field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='orders', to='shop.wechatuser', verbose_name='下单微信用户'),
        ),
    ]
