fix: undo_repair_wechat_income 反向撤销重复记账
This commit is contained in:
@@ -65,6 +65,29 @@ def update_daily_income(amount, club_id=None):
|
||||
)
|
||||
|
||||
|
||||
def subtract_daily_income(amount, club_id=None, stat_date=None):
|
||||
"""扣减指定日期的收入统计(repair 反向操作用)。"""
|
||||
from jituan.constants import CLUB_ID_DEFAULT
|
||||
|
||||
cid = club_id or CLUB_ID_DEFAULT
|
||||
target = stat_date or date.today()
|
||||
|
||||
with transaction.atomic():
|
||||
stat = DailyIncomeStat.objects.select_for_update().filter(
|
||||
date=target, club_id=cid,
|
||||
).first()
|
||||
if not stat:
|
||||
return
|
||||
jine = Decimal(str(amount))
|
||||
zero = Decimal('0.00')
|
||||
new_amt = max(zero, Decimal(str(stat.total_amount or 0)) - jine)
|
||||
new_cnt = max(0, int(stat.total_count or 0) - 1)
|
||||
stat.total_amount = new_amt
|
||||
stat.total_count = new_cnt
|
||||
stat.save(update_fields=['total_amount', 'total_count'])
|
||||
logger.info(f"每日收入扣减[{cid}]: {target}, -{amount}元")
|
||||
|
||||
|
||||
def update_daily_payout(amount, club_id=None):
|
||||
"""
|
||||
原子更新当日出款统计(金额累加,笔数加1)。
|
||||
|
||||
Reference in New Issue
Block a user