feat: 组队招募(/zudui)+ 结单/自动结算/罚款挂钩

新增 Team 表与接口;进8强制锁、组队分账优先且失败不回退全额队长。

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
XingQue
2026-07-27 03:12:04 +08:00
parent e9e5ee85e2
commit 7002da6093
14 changed files with 1466 additions and 63 deletions

View File

@@ -207,12 +207,43 @@ def mark_order_completed_unified(order, *, source='auto_settle', operator=''):
except Exception:
return False, '打手不存在'
credit_dashou_order_settle(
order=locked,
dashou_profile=dashou_profile,
user_id=dashou_id,
amount=dashou_fencheng,
)
# 组队分账优先;无有效组队则全额给队长(原逻辑)
# 若本应组队分账却失败/异常:禁止回退全额队长(避免队友白做或重复入账)
try:
from orders.services.team_recruit import settle_team_or_legacy, get_active_recruit, team_should_split
from orders.models import TeamSettleLedger, TeamRecruit
rec = get_active_recruit(locked.OrderID)
if rec and rec.status == TeamRecruit.STATUS_RECRUITING:
# 进8锁失败的兜底结单前再强制锁一次
from orders.services.team_recruit import lock_recruit
lock_recruit(rec.id, actor_uid='system', reason='settle_force_lock')
team_done = settle_team_or_legacy(locked, set_idle_leader=True)
except Exception as e:
logger.error('组队分账异常 %s: %s', locked.OrderID, e)
from orders.models import TeamSettleLedger
if TeamSettleLedger.query.filter(order_id=locked.OrderID).exists():
return False, f'组队分账异常且已有入账记录: {e}'
try:
from orders.services.team_recruit import team_should_split, get_active_recruit
if get_active_recruit(locked.OrderID) or team_should_split(locked):
return False, f'组队分账失败: {e}'
except Exception:
pass
team_done = False
if not team_done:
try:
from orders.services.team_recruit import get_active_recruit
if get_active_recruit(locked.OrderID):
return False, '存在有效组队但分账未完成,已阻止全额打给队长'
except Exception:
pass
credit_dashou_order_settle(
order=locked,
dashou_profile=dashou_profile,
user_id=dashou_id,
amount=dashou_fencheng,
)
if locked.Platform == 2:
try: