加固管理员解冻:校验落库并返回余额/冻结池变动明细。

解冻接口返回 unfreeze_result,便于后台核对池→余额是否真正写回。

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
XingQue
2026-07-12 13:15:10 +08:00
parent 59af2fc18a
commit c3bab3564a
2 changed files with 34 additions and 6 deletions

View File

@@ -77,12 +77,20 @@ class DongjieUserConfigView(APIView):
return Response({'code': 400, 'msg': '请填写解冻金额'})
try:
with transaction.atomic():
new_balance = admin_unfreeze_balance(
result = admin_unfreeze_balance(
user_main, leixing, jine,
operator_id=username, beizhu=beizhu,
)
info = get_user_freeze_info(user_main, leixing)
info['balance'] = str(new_balance)
info['balance'] = str(result['balance_after'])
info['dongjie_chi'] = str(result['dongjie_chi_after'])
info['unfreeze_result'] = {
'balance_before': str(result['balance_before']),
'balance_after': str(result['balance_after']),
'dongjie_chi_before': str(result['dongjie_chi_before']),
'dongjie_chi_after': str(result['dongjie_chi_after']),
'unfreeze_jine': str(result['unfreeze_jine']),
}
return Response({'code': 0, 'msg': '解冻成功', 'data': info})
except ValueError as e:
return Response({'code': 400, 'msg': str(e)})

View File

@@ -313,8 +313,8 @@ def apply_balance_freeze(user_main: UserMain, leixing: int, apply_jine) -> Apply
)
def admin_unfreeze_balance(user_main: UserMain, leixing: int, jine, operator_id='', beizhu='') -> decimal.Decimal:
"""管理员解冻:冻结池 → 可提现余额。"""
def admin_unfreeze_balance(user_main: UserMain, leixing: int, jine, operator_id='', beizhu='') -> dict:
"""管理员解冻:冻结池 → 可提现余额。返回变动前后快照。"""
leixing = int(leixing)
jine = _q(jine)
if jine <= 0:
@@ -334,12 +334,32 @@ def admin_unfreeze_balance(user_main: UserMain, leixing: int, jine, operator_id=
if hasattr(profile, 'update_time'):
update_fields.append('update_time')
profile.save(update_fields=update_fields)
profile.refresh_from_db()
actual_balance = _q(getattr(profile, meta['balance']))
actual_pool = _q(getattr(profile, meta['pool']))
if actual_balance != new_balance or actual_pool != new_pool:
logger.error(
'解冻落库不一致 yonghuid=%s leixing=%s expect_balance=%s actual=%s expect_pool=%s actual=%s',
user_main.yonghuid, leixing, new_balance, actual_balance, new_pool, actual_pool,
)
raise ValueError('解冻写入失败,请重试或联系技术')
_write_freeze_log(
user_main.yonghuid, leixing, jine, pool, new_pool,
user_main.yonghuid, leixing, jine, pool, actual_pool,
TixianDongjieJilu.CAOZUO_UNFREEZE, operator_id=operator_id, beizhu=beizhu,
)
return new_balance
logger.info(
'管理员解冻 yonghuid=%s leixing=%s jine=%s balance %s%s pool %s%s operator=%s',
user_main.yonghuid, leixing, jine, balance, actual_balance, pool, actual_pool, operator_id,
)
return {
'balance_before': balance,
'balance_after': actual_balance,
'dongjie_chi_before': pool,
'dongjie_chi_after': actual_pool,
'unfreeze_jine': jine,
}
def get_user_freeze_info(user_main: UserMain, leixing: int) -> dict: