fix: 处罚/罚款列表俱乐部过滤与全部Tab;回填fadan club_id
This commit is contained in:
@@ -1,18 +1,23 @@
|
||||
"""回填 chufajilu / duoci_fenhong club_id。"""
|
||||
"""回填 chufajilu / fadan / duoci_fenhong club_id。"""
|
||||
from django.core.management.base import BaseCommand
|
||||
from django.db import transaction
|
||||
|
||||
from jituan.constants import CLUB_ID_DEFAULT
|
||||
from jituan.services.club_penalty import resolve_gsfenhong_club_id, resolve_penalty_record_club_id
|
||||
from orders.models import PenaltyRecord
|
||||
from jituan.services.club_penalty import (
|
||||
resolve_gsfenhong_club_id,
|
||||
resolve_penalty_club_id,
|
||||
resolve_penalty_record_club_id,
|
||||
)
|
||||
from orders.models import Penalty, PenaltyRecord
|
||||
from products.models import DuociFenhong
|
||||
|
||||
|
||||
class Command(BaseCommand):
|
||||
help = '回填 PenaltyRecord / DuociFenhong 的 club_id'
|
||||
help = '回填 PenaltyRecord / Penalty / DuociFenhong 的 club_id'
|
||||
|
||||
def handle(self, *args, **options):
|
||||
pr_updated = 0
|
||||
fd_updated = 0
|
||||
df_updated = 0
|
||||
with transaction.atomic():
|
||||
for row in PenaltyRecord.query.all().only('id', 'OrderID', 'PlayerID', 'ClubID'):
|
||||
@@ -20,6 +25,19 @@ class Command(BaseCommand):
|
||||
if row.ClubID != cid:
|
||||
PenaltyRecord.query.filter(id=row.id).update(ClubID=cid)
|
||||
pr_updated += 1
|
||||
for row in Penalty.query.all().only('id', 'RelatedOrderID', 'PenalizedUserID', 'ClubID'):
|
||||
cid = resolve_penalty_club_id(
|
||||
order=None,
|
||||
penalized_user_id=row.PenalizedUserID,
|
||||
)
|
||||
if row.RelatedOrderID:
|
||||
from orders.models import Order
|
||||
o = Order.query.filter(OrderID=row.RelatedOrderID).first()
|
||||
if o:
|
||||
cid = resolve_penalty_club_id(order=o, penalized_user_id=row.PenalizedUserID)
|
||||
if row.ClubID != cid:
|
||||
Penalty.query.filter(id=row.id).update(ClubID=cid)
|
||||
fd_updated += 1
|
||||
for row in DuociFenhong.query.all().only('huiyuan', 'yonghuid', 'cishu', 'club_id'):
|
||||
cid = resolve_gsfenhong_club_id(dashouid=row.yonghuid) or CLUB_ID_DEFAULT
|
||||
if row.club_id != cid:
|
||||
@@ -31,5 +49,5 @@ class Command(BaseCommand):
|
||||
).update(club_id=cid)
|
||||
df_updated += 1
|
||||
self.stdout.write(self.style.SUCCESS(
|
||||
f'PenaltyRecord={pr_updated}, DuociFenhong={df_updated}'
|
||||
f'PenaltyRecord={pr_updated}, Penalty={fd_updated}, DuociFenhong={df_updated}'
|
||||
))
|
||||
|
||||
Reference in New Issue
Block a user