feat: 管事分佣明细v2与打手本人入账额展示
This commit is contained in:
1 parent
b49da23bd7
commit
712d497672
4 files changed
+185
-3
No files matched your search
+68
-1
@@ -797,6 +797,11 @@ class DashouDingdanHuoquView1(APIView):
|
||||
if wants_auto_settle_pending(data):
|
||||
query &= Q(Status=8, AutoSettleEligible=True, AutoExpireAt__isnull=False)
|
||||
|
||||
# 佣金记录页:with_my_share=1 时追加本人入账额(不改 jine 语义)
|
||||
with_my_share = str(data.get('with_my_share') or '').strip().lower() in (
|
||||
'1', 'true', 'yes', 'y',
|
||||
)
|
||||
|
||||
# 5. 执行查询,按创建时间倒序
|
||||
dingdan_query = Order.query.filter(query).order_by('-CreateTime')
|
||||
|
||||
@@ -826,12 +831,18 @@ class DashouDingdanHuoquView1(APIView):
|
||||
from orders.services.team_recruit import batch_team_list_flags
|
||||
page_oids = [o.OrderID for o in current_page_orders]
|
||||
team_flags = batch_team_list_flags(page_oids, viewer_uid=yonghuid)
|
||||
|
||||
settle_map = {}
|
||||
if with_my_share and page_oids:
|
||||
settle_map = self._batch_my_settle_amounts(page_oids, yonghuid)
|
||||
|
||||
order_list = []
|
||||
for order in current_page_orders:
|
||||
full_amt = float(order.PlayerCommission) if order.PlayerCommission else 0.0
|
||||
order_data = {
|
||||
'dingdan_id': order.OrderID,
|
||||
'zhuangtai': order.Status,
|
||||
'jine': float(order.PlayerCommission) if order.PlayerCommission else 0.0,
|
||||
'jine': full_amt,
|
||||
'jieshao': order.Description or '',
|
||||
'tupian': order.ImageURL or '',
|
||||
'nicheng': order.Nickname or '',
|
||||
@@ -840,6 +851,15 @@ class DashouDingdanHuoquView1(APIView):
|
||||
order_data.update(order_auto_settle_payload(order))
|
||||
tf = team_flags.get(order.OrderID) or {'has_team': False}
|
||||
order_data.update(tf)
|
||||
if with_my_share:
|
||||
is_team = bool(tf.get('has_team'))
|
||||
my_amt = settle_map.get(order.OrderID)
|
||||
if my_amt is None:
|
||||
my_amt = full_amt
|
||||
order_data['my_settle_amount'] = float(my_amt)
|
||||
order_data['is_team'] = is_team
|
||||
if 'team_role' not in order_data:
|
||||
order_data['team_role'] = tf.get('team_role') or ''
|
||||
order_list.append(order_data)
|
||||
|
||||
# 8. 判断是否还有更多数据
|
||||
@@ -878,6 +898,53 @@ class DashouDingdanHuoquView1(APIView):
|
||||
'data': None
|
||||
}, status=status.HTTP_500_INTERNAL_SERVER_ERROR)
|
||||
|
||||
@staticmethod
|
||||
def _batch_my_settle_amounts(order_ids, user_uid):
|
||||
"""
|
||||
本人实际入账额:优先 team_settle_ledger;否则 TeamMember.share_amount;
|
||||
都没有则由调用方回落 PlayerCommission。
|
||||
返回 {order_id: float}
|
||||
"""
|
||||
from decimal import Decimal
|
||||
from orders.models import TeamSettleLedger, TeamRecruit, TeamMember
|
||||
|
||||
oids = [str(x) for x in (order_ids or []) if x]
|
||||
uid = (user_uid or '').strip()
|
||||
if not oids or not uid:
|
||||
return {}
|
||||
|
||||
out = {}
|
||||
try:
|
||||
for row in TeamSettleLedger.query.filter(order_id__in=oids, user_uid=uid):
|
||||
oid = row.order_id
|
||||
amt = Decimal(str(row.amount or 0))
|
||||
out[oid] = float(out.get(oid, 0) + float(amt))
|
||||
except Exception as e:
|
||||
logger.warning('batch settle ledger 失败: %s', e)
|
||||
|
||||
missing = [oid for oid in oids if oid not in out]
|
||||
if not missing:
|
||||
return out
|
||||
|
||||
try:
|
||||
recs = list(TeamRecruit.query.filter(order_id__in=missing).order_by('-id'))
|
||||
best = {}
|
||||
for r in recs:
|
||||
if r.order_id not in best:
|
||||
best[r.order_id] = r
|
||||
if best:
|
||||
rid_to_oid = {r.id: oid for oid, r in best.items()}
|
||||
for m in TeamMember.query.filter(
|
||||
recruit_id__in=list(rid_to_oid.keys()),
|
||||
user_uid=uid,
|
||||
join_status=TeamMember.JOIN_ACTIVE,
|
||||
):
|
||||
oid = rid_to_oid.get(m.recruit_id)
|
||||
if oid and oid not in out:
|
||||
out[oid] = float(Decimal(str(m.share_amount or 0)))
|
||||
except Exception as e:
|
||||
logger.warning('batch member share 失败: %s', e)
|
||||
return out
|
||||
|
||||
|
||||
class DashouCOSZhengshuView(APIView):
|
||||
|
||||
Reference in new issue
Block a user