fix: 恢复 repair 重复记账 + 禁用错误补账命令
This commit is contained in:
68
config/management/commands/sync_daily_income_from_log.py
Normal file
68
config/management/commands/sync_daily_income_from_log.py
Normal file
@@ -0,0 +1,68 @@
|
||||
"""
|
||||
用 platform_income_log 重写 daily_income_stat,纠正重复记账后的虚高数字。
|
||||
权威数据源是 platform_income_log(每笔支付一条,biz_ref 唯一),不是扫订单重算。
|
||||
"""
|
||||
from datetime import date, timedelta
|
||||
|
||||
from django.core.management.base import BaseCommand
|
||||
|
||||
from jituan.services.szjilu_accounting import (
|
||||
sync_daily_income_stat_for_date,
|
||||
sync_szjilu_income_from_logs,
|
||||
)
|
||||
|
||||
|
||||
class Command(BaseCommand):
|
||||
help = (
|
||||
'按 platform_income_log 同步 daily_income_stat(纠正今日收入虚高/笔数不准)。'
|
||||
'不要用 repair_wechat_income,那个会重复加钱。'
|
||||
)
|
||||
|
||||
def add_arguments(self, parser):
|
||||
parser.add_argument(
|
||||
'--date',
|
||||
type=str,
|
||||
default='',
|
||||
help='同步日期 YYYY-MM-DD,默认今天',
|
||||
)
|
||||
parser.add_argument(
|
||||
'--days',
|
||||
type=int,
|
||||
default=1,
|
||||
help='从指定日期起向前同步几天,默认 1',
|
||||
)
|
||||
parser.add_argument(
|
||||
'--reset-day',
|
||||
action='store_true',
|
||||
help='同步前先删除该日全部日统计行,再按日志重建(纠正重复记账必选)',
|
||||
)
|
||||
parser.add_argument(
|
||||
'--sync-szjilu',
|
||||
action='store_true',
|
||||
help='同时按日志全量重算 szjilu 累计收入/今日流水',
|
||||
)
|
||||
|
||||
def handle(self, *args, **options):
|
||||
if options['date']:
|
||||
end_day = date.fromisoformat(options['date'])
|
||||
else:
|
||||
end_day = date.today()
|
||||
days = max(1, int(options['days'] or 1))
|
||||
start_day = end_day - timedelta(days=days - 1)
|
||||
reset_day = bool(options['reset_day'])
|
||||
|
||||
total = 0
|
||||
for i in range(days):
|
||||
d = start_day + timedelta(days=i)
|
||||
n = sync_daily_income_stat_for_date(d, reset_day=reset_day)
|
||||
total += n
|
||||
self.stdout.write(f'{d}: 已同步 {n} 个俱乐部日统计行')
|
||||
|
||||
if options['sync_szjilu']:
|
||||
sz = sync_szjilu_income_from_logs()
|
||||
self.stdout.write(f'szjilu: 已重算 {sz} 个俱乐部累计收入')
|
||||
|
||||
self.stdout.write(self.style.SUCCESS(
|
||||
f'完成。今日收入/笔数现与 platform_income_log 一致。'
|
||||
f'若仍有漏记支付,请确认 migrate config 后等新支付自动入账。'
|
||||
))
|
||||
Reference in New Issue
Block a user