财务恢复:只读日统计表,废弃szjilu,新增restore_finance_stats
This commit is contained in:
64
config/management/commands/restore_finance_stats.py
Normal file
64
config/management/commands/restore_finance_stats.py
Normal file
@@ -0,0 +1,64 @@
|
||||
"""
|
||||
一键恢复财务「每日收入」统计(repair_wechat_income 搞乱后执行)。
|
||||
|
||||
只重建:
|
||||
- daily_income_stat(每日收入统计表,财务看板读这个)
|
||||
- platform_income_log(支付幂等日志)
|
||||
|
||||
绝不碰:
|
||||
- daily_payout_stat(每日支出,repair 没动过)
|
||||
- szjilu(收支记录表,已废弃)
|
||||
- 订单 / 充值业务表
|
||||
|
||||
用法:
|
||||
预览:python manage.py restore_finance_stats
|
||||
执行:python manage.py restore_finance_stats --yes
|
||||
"""
|
||||
from datetime import date
|
||||
|
||||
from django.core.management.base import BaseCommand
|
||||
|
||||
from jituan.services.szjilu_accounting import restore_finance_daily_stats
|
||||
|
||||
|
||||
class Command(BaseCommand):
|
||||
help = '从订单/充值重建 daily_income_stat(恢复 repair 搞乱的每日收入)'
|
||||
|
||||
def add_arguments(self, parser):
|
||||
parser.add_argument('--since-year', type=int, default=2020, help='从哪年开始重算')
|
||||
parser.add_argument('--until-year', type=int, default=0, help='到哪年,默认今年')
|
||||
parser.add_argument('--yes', action='store_true', help='确认写入数据库')
|
||||
|
||||
def handle(self, *args, **options):
|
||||
until_year = options['until_year'] or date.today().year
|
||||
since_year = options['since_year'] or 2020
|
||||
dry_run = not options['yes']
|
||||
|
||||
if dry_run:
|
||||
self.stdout.write(self.style.WARNING(
|
||||
'【预览】未改数据库。下面「恢复后」应是正确每日收入合计。\n'
|
||||
))
|
||||
else:
|
||||
self.stdout.write(self.style.WARNING(
|
||||
'【执行】正在从订单/充值重建 daily_income_stat...\n'
|
||||
))
|
||||
|
||||
r = restore_finance_daily_stats(since_year, until_year, dry_run=dry_run)
|
||||
|
||||
self.stdout.write(f'范围: {r["since_year"]} ~ {r["until_year"]}')
|
||||
self.stdout.write(f' 支付笔数: {r["after_count"]}')
|
||||
self.stdout.write(f' 恢复前 daily 合计: {r["before_daily_total"]:.2f} 元')
|
||||
self.stdout.write(self.style.SUCCESS(
|
||||
f' 恢复后 daily 合计: {r.get("after_daily_total", r["after_total"]):.2f} 元'
|
||||
))
|
||||
self.stdout.write(f' 其中今日收入: {r["today_amount"]:.2f} 元 / {r["today_count"]} 笔')
|
||||
|
||||
if dry_run:
|
||||
self.stdout.write(self.style.WARNING(
|
||||
'\n数字对的话执行:\n'
|
||||
' python manage.py restore_finance_stats --yes'
|
||||
))
|
||||
else:
|
||||
self.stdout.write(self.style.SUCCESS(
|
||||
'\n完成。daily_payout_stat 未动。请 push 代码后刷新财务页。'
|
||||
))
|
||||
@@ -1,12 +0,0 @@
|
||||
"""按真实支付重算 szjilu 收支记录表(与每日收入看板无关,可选执行)。"""
|
||||
from django.core.management.base import BaseCommand
|
||||
|
||||
from jituan.services.live_income_stats import sync_szjilu_from_live_payments
|
||||
|
||||
|
||||
class Command(BaseCommand):
|
||||
help = '按订单/充值重算 szjilu 表 TotalIncome、TotalFlow、DailyFlow(不动 daily_income_stat)'
|
||||
|
||||
def handle(self, *args, **options):
|
||||
n = sync_szjilu_from_live_payments()
|
||||
self.stdout.write(self.style.SUCCESS(f'已更新 {n} 条 szjilu 记录'))
|
||||
Reference in New Issue
Block a user