Files

116 lines
8.8 KiB
Python
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# Generated by Django 5.2.12 on 2026-09-07 02:14
import django.db.models.deletion
from django.conf import settings
from django.db import migrations, models
class Migration(migrations.Migration):
initial = True
dependencies = [
('core', '0001_initial'),
('inventory', '0001_initial'),
('partner', '0001_initial'),
('sales', '0001_initial'),
migrations.swappable_dependency(settings.AUTH_USER_MODEL),
]
operations = [
migrations.CreateModel(
name='ChannelAccount',
fields=[
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('created_at', models.DateTimeField(auto_now_add=True)),
('updated_at', models.DateTimeField(auto_now=True)),
('is_deleted', models.BooleanField(default=False)),
('deleted_at', models.DateTimeField(blank=True, null=True)),
('ext_data', models.JSONField(blank=True, default=dict)),
('source_channel', models.CharField(blank=True, default='manual', max_length=32)),
('platform', models.CharField(choices=[('douyin', '抖音电商 / 抖店'), ('pinduoduo', '拼多多'), ('1688', '1688 阿里分销'), ('kuaishou', '快手小店'), ('custom', '自定义开放接口')], default='douyin', max_length=32)),
('shop_id', models.CharField(help_text='外部平台店铺ID', max_length=64)),
('shop_name', models.CharField(help_text='店铺名称', max_length=128)),
('app_key', models.CharField(blank=True, default='', max_length=128)),
('app_secret', models.CharField(blank=True, default='', max_length=255)),
('access_token', models.TextField(blank=True, default='')),
('refresh_token', models.TextField(blank=True, default='')),
('token_expires_at', models.DateTimeField(blank=True, null=True)),
('is_active', models.BooleanField(default=True)),
('created_by', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='+', to=settings.AUTH_USER_MODEL)),
('default_customer', models.ForeignKey(blank=True, help_text='该店铺归属的客户(挂账往来)', null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='+', to='partner.customer')),
('default_warehouse', models.ForeignKey(blank=True, help_text='该店铺订单默认出库仓库', null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='+', to='inventory.warehouse')),
('org', models.ForeignKey(blank=True, help_text='所属组织(多机构预留)', null=True, on_delete=django.db.models.deletion.PROTECT, related_name='+', to='core.org')),
('tenant', models.ForeignKey(help_text='所属租户', on_delete=django.db.models.deletion.PROTECT, related_name='+', to='core.tenant')),
('updated_by', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='+', to=settings.AUTH_USER_MODEL)),
],
options={
'verbose_name_plural': '电商店铺配置',
'db_table': 'channel_account',
'ordering': ['platform', 'shop_name'],
'unique_together': {('tenant', 'platform', 'shop_id')},
},
),
migrations.CreateModel(
name='WebhookEvent',
fields=[
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('created_at', models.DateTimeField(auto_now_add=True)),
('updated_at', models.DateTimeField(auto_now=True)),
('is_deleted', models.BooleanField(default=False)),
('deleted_at', models.DateTimeField(blank=True, null=True)),
('ext_data', models.JSONField(blank=True, default=dict)),
('source_channel', models.CharField(blank=True, default='manual', max_length=32)),
('direction', models.CharField(choices=[('inbound', '外部推送回调'), ('outbound', '本系统向外推送')], default='inbound', max_length=16)),
('event_type', models.CharField(help_text='事件类型,如 order.paid, stock.changed', max_length=64)),
('source', models.CharField(default='douyin', help_text='来源系统或平台', max_length=32)),
('payload', models.JSONField(blank=True, default=dict)),
('status', models.CharField(choices=[('received', '已接收'), ('processed', '处理成功'), ('failed', '处理失败')], default='received', max_length=16)),
('error_message', models.TextField(blank=True, default='')),
('created_by', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='+', to=settings.AUTH_USER_MODEL)),
('org', models.ForeignKey(blank=True, help_text='所属组织(多机构预留)', null=True, on_delete=django.db.models.deletion.PROTECT, related_name='+', to='core.org')),
('tenant', models.ForeignKey(help_text='所属租户', on_delete=django.db.models.deletion.PROTECT, related_name='+', to='core.tenant')),
('updated_by', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='+', to=settings.AUTH_USER_MODEL)),
],
options={
'verbose_name_plural': 'Webhook事件日志',
'db_table': 'channel_webhook_event',
'ordering': ['-created_at'],
},
),
migrations.CreateModel(
name='ChannelOrder',
fields=[
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('created_at', models.DateTimeField(auto_now_add=True)),
('updated_at', models.DateTimeField(auto_now=True)),
('is_deleted', models.BooleanField(default=False)),
('deleted_at', models.DateTimeField(blank=True, null=True)),
('ext_data', models.JSONField(blank=True, default=dict)),
('source_channel', models.CharField(blank=True, default='manual', max_length=32)),
('external_order_id', models.CharField(help_text='外部平台订单号', max_length=128)),
('order_status', models.CharField(default='', help_text='外部平台订单状态(如 PAID, SHIPPED)', max_length=64)),
('order_amount', models.DecimalField(decimal_places=4, default=0, max_digits=18)),
('buyer_name', models.CharField(blank=True, default='', max_length=64)),
('buyer_phone', models.CharField(blank=True, default='', max_length=32)),
('receiver_address', models.CharField(blank=True, default='', max_length=255)),
('sync_status', models.CharField(choices=[('pending', '待转单'), ('converted', '已转销售单'), ('failed', '转单失败'), ('ignored', '已忽略')], default='pending', max_length=16)),
('sync_error', models.TextField(blank=True, default='')),
('raw_payload', models.JSONField(blank=True, default=dict, help_text='外部原始订单 JSON')),
('channel_account', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='orders', to='channel.channelaccount')),
('created_by', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='+', to=settings.AUTH_USER_MODEL)),
('org', models.ForeignKey(blank=True, help_text='所属组织(多机构预留)', null=True, on_delete=django.db.models.deletion.PROTECT, related_name='+', to='core.org')),
('sales_order', models.ForeignKey(blank=True, help_text='关联的内部销售订单', null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='channel_orders', to='sales.salesorder')),
('tenant', models.ForeignKey(help_text='所属租户', on_delete=django.db.models.deletion.PROTECT, related_name='+', to='core.tenant')),
('updated_by', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='+', to=settings.AUTH_USER_MODEL)),
],
options={
'verbose_name_plural': '渠道订单',
'db_table': 'channel_order',
'ordering': ['-created_at'],
'indexes': [models.Index(fields=['tenant', 'sync_status'], name='channel_ord_tenant__78f581_idx'), models.Index(fields=['tenant', 'external_order_id'], name='channel_ord_tenant__b39995_idx')],
'unique_together': {('tenant', 'channel_account', 'external_order_id')},
},
),
]