Files
Django/jituan/management/commands/backfill_role_daily_club_id.py

37 lines
1.2 KiB
Python
Raw 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.
"""回填角色日统计 club_id按用户归属俱乐部"""
from django.core.management.base import BaseCommand
from django.db import transaction
from backend.models import (
LeaderDailyStats,
ManagerDailyStats,
ManagerRenewalDailyStats,
MerchantDailyStats,
PlayerDailyStats,
)
from backend.utils import _club_id_for_yonghuid
MODELS = [
(MerchantDailyStats, 'MerchantID'),
(PlayerDailyStats, 'PlayerID'),
(LeaderDailyStats, 'LeaderID'),
(ManagerDailyStats, 'ManagerID'),
(ManagerRenewalDailyStats, 'ManagerID'),
]
class Command(BaseCommand):
help = '回填 5 张角色日统计表的 club_id'
def handle(self, *args, **options):
updated = 0
with transaction.atomic():
for model, uid_field in MODELS:
for row in model.query.all().only('id', uid_field, 'club_id'):
cid = _club_id_for_yonghuid(getattr(row, uid_field))
if row.club_id != cid:
model.query.filter(id=row.id).update(club_id=cid)
updated += 1
self.stdout.write(self.style.SUCCESS(f'角色日统计 club_id 更新 {updated}'))