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)。
|
||||
|
||||
@@ -211,7 +211,7 @@ class WechatPayNotifyView(APIView):
|
||||
try:
|
||||
from jituan.services.szjilu_accounting import repair_wechat_income_if_missing
|
||||
repair_wechat_income_if_missing(
|
||||
dingdan.Amount, getattr(dingdan, 'ClubID', None), biz_ref=f'order:{out_trade_no}',
|
||||
dingdan.Amount, getattr(dingdan, 'ClubID', None), biz_ref=f'order:{dingdan.OrderID}',
|
||||
)
|
||||
except Exception as e:
|
||||
logger.error(f'订单补记收支失败 {out_trade_no}: {e}', exc_info=True)
|
||||
@@ -318,7 +318,7 @@ class WechatPayNotifyView(APIView):
|
||||
try:
|
||||
from jituan.services.szjilu_accounting import repair_wechat_income_if_missing
|
||||
repair_wechat_income_if_missing(
|
||||
dingdan.Amount, getattr(dingdan, 'ClubID', None), biz_ref=f'order:{out_trade_no}',
|
||||
dingdan.Amount, getattr(dingdan, 'ClubID', None), biz_ref=f'order:{dingdan.OrderID}',
|
||||
)
|
||||
except Exception as e:
|
||||
logger.error(f'订单收支统计失败 {out_trade_no}: {e}', exc_info=True)
|
||||
|
||||
Reference in New Issue
Block a user