feat: 假单计入类型数量;按类型配置强制展示订单价格

This commit is contained in:
XingQue
2026-07-30 21:04:17 +08:00
parent 9744e800eb
commit 09f05605ff
7 changed files with 152 additions and 7 deletions

View File

@@ -11,10 +11,32 @@ from django.db.models import Count
logger = logging.getLogger(__name__)
def grab_pool_type_pending_counts(club_id: str) -> dict[str, int]:
def _fake_type_counts(club_id: str) -> dict[str, int]:
try:
from orders.models import FakeGrabOrder
rows = (
FakeGrabOrder.query.filter(ClubID=club_id)
.exclude(ProductTypeID__isnull=True)
.values('ProductTypeID')
.annotate(cnt=Count('OrderID'))
)
out = {}
for r in rows:
lid = r.get('ProductTypeID')
if lid is None:
continue
out[str(int(lid))] = int(r.get('cnt') or 0)
return out
except Exception as e:
logger.warning('_fake_type_counts failed club=%s: %s', club_id, e)
return {}
def grab_pool_type_pending_counts(club_id: str, user=None) -> dict[str, int]:
"""
与 /dingdan/ddhq 同口径Status in (1,7) + 抢单俱乐部范围,按 ProductTypeID 聚合。
返回 { \"类型id\": 数量 }key 一律 str方便 JSON / 前端
若传入 user按假单展示模式把假单数计入mix/fake_only 计入real_only/off 不计)
返回 { \"类型id\": 数量 }key 一律 str。
"""
club_id = (club_id or '').strip()
if not club_id:
@@ -37,6 +59,37 @@ def grab_pool_type_pending_counts(club_id: str) -> dict[str, int]:
if lid is None:
continue
out[str(int(lid))] = int(r.get('cnt') or 0)
if user is not None:
try:
from orders.services.fake_order_pool import (
MODE_FAKE_ONLY,
MODE_MIX,
resolve_fake_pool_mode,
)
fake_counts = _fake_type_counts(club_id)
# 所有出现过的类型(真单或假单)
all_keys = set(out.keys()) | set(fake_counts.keys())
adjusted = {}
for key in all_keys:
try:
lid = int(key)
except (TypeError, ValueError):
continue
real_n = int(out.get(key) or 0)
fake_n = int(fake_counts.get(key) or 0)
mode = resolve_fake_pool_mode(user, club_id=club_id, leixing_id=lid)
if mode == MODE_FAKE_ONLY:
adjusted[key] = fake_n
elif mode == MODE_MIX:
adjusted[key] = real_n + fake_n
else:
# off / real_only不计假单
adjusted[key] = real_n
out = adjusted
except Exception as e:
logger.warning('merge fake into type counts failed: %s', e)
return out
except Exception as e:
logger.warning('grab_pool_type_pending_counts failed club=%s: %s', club_id, e)
@@ -73,9 +126,9 @@ def team_pending_count(club_id: str) -> int:
return 0
def dashou_badge_fields(club_id: str) -> dict:
def dashou_badge_fields(club_id: str, user=None) -> dict:
"""附加到接口 data 的角标字段(旧字段不受影响)。"""
type_counts = grab_pool_type_pending_counts(club_id)
type_counts = grab_pool_type_pending_counts(club_id, user=user)
total = int(sum(type_counts.values()))
return {
'type_pending_counts': type_counts,

View File

@@ -416,7 +416,7 @@ class DashouDingdanHuoquView(APIView):
badge = {}
try:
from orders.services.dashou_badges import dashou_badge_fields
badge = dashou_badge_fields(club_id)
badge = dashou_badge_fields(club_id, user=request.user)
except Exception as e:
logger.warning('ddhq 角标附加失败: %s', e)
@@ -808,7 +808,8 @@ class DashouDingdanHuoquView1(APIView):
from jituan.services.club_context import resolve_effective_club_id
from orders.services.dashou_badges import dashou_badge_fields
badge = dashou_badge_fields(
resolve_effective_club_id(request, getattr(request, 'user', None))
resolve_effective_club_id(request, getattr(request, 'user', None)),
user=getattr(request, 'user', None),
)
except Exception as e:
logger.warning('dshqdingdan 角标附加失败: %s', e)
@@ -1623,7 +1624,7 @@ class DashouHuoquLeixingView(APIView):
badge = {}
try:
from orders.services.dashou_badges import dashou_badge_fields, attach_pending_to_leixing_list
badge = dashou_badge_fields(club_id)
badge = dashou_badge_fields(club_id, user=request.user)
leixing_list = attach_pending_to_leixing_list(
leixing_list, badge.get('type_pending_counts'),
)