Files
cmhub/apps/billing/migrations/0004_rechargeorder_and_more.py
T

73 lines
3.5 KiB
Python

# Generated by Django 5.2.15 on 2026-07-03 00:45
import django.db.models.deletion
from django.conf import settings
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('billing', '0003_pointsledger_unique_ledger_change_type_per_call'),
migrations.swappable_dependency(settings.AUTH_USER_MODEL),
]
operations = [
migrations.CreateModel(
name='RechargeOrder',
fields=[
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('order_no', models.CharField(max_length=64, unique=True)),
('amount_money', models.DecimalField(decimal_places=2, max_digits=12)),
('currency', models.CharField(default='CNY', max_length=10)),
('pay_method', models.CharField(choices=[('weixin', 'Weixin'), ('alipay', 'Alipay')], max_length=20)),
('exchange_rate', models.DecimalField(decimal_places=4, max_digits=12)),
('points_granted', models.BigIntegerField()),
('status', models.CharField(choices=[('pending', 'Pending'), ('paid', 'Paid'), ('failed', 'Failed'), ('expired', 'Expired')], default='pending', max_length=20)),
('code_url', models.TextField(blank=True)),
('expires_at', models.DateTimeField(blank=True, null=True)),
('payment_txn_no', models.CharField(blank=True, max_length=128)),
('paid_at', models.DateTimeField(blank=True, null=True)),
('created_at', models.DateTimeField(auto_now_add=True)),
('updated_at', models.DateTimeField(auto_now=True)),
],
options={
'db_table': 'recharge_order',
'ordering': ('-created_at', '-id'),
},
),
migrations.AddConstraint(
model_name='pointsledger',
constraint=models.UniqueConstraint(fields=('ref_order_id', 'change_type'), name='unique_ledger_change_type_per_order'),
),
migrations.AddField(
model_name='rechargeorder',
name='user',
field=models.ForeignKey(on_delete=django.db.models.deletion.PROTECT, related_name='recharge_orders', to=settings.AUTH_USER_MODEL),
),
migrations.AddIndex(
model_name='rechargeorder',
index=models.Index(fields=['user', 'created_at'], name='recharge_or_user_id_312e87_idx'),
),
migrations.AddIndex(
model_name='rechargeorder',
index=models.Index(fields=['status', 'created_at'], name='recharge_or_status_139277_idx'),
),
migrations.AddIndex(
model_name='rechargeorder',
index=models.Index(fields=['pay_method', 'status'], name='recharge_or_pay_met_4c0043_idx'),
),
migrations.AddConstraint(
model_name='rechargeorder',
constraint=models.CheckConstraint(condition=models.Q(('amount_money__gt', 0)), name='recharge_order_amount_money_positive'),
),
migrations.AddConstraint(
model_name='rechargeorder',
constraint=models.CheckConstraint(condition=models.Q(('exchange_rate__gt', 0)), name='recharge_order_exchange_rate_positive'),
),
migrations.AddConstraint(
model_name='rechargeorder',
constraint=models.CheckConstraint(condition=models.Q(('points_granted__gt', 0)), name='recharge_order_points_granted_positive'),
),
]