feat: 假单计入类型数量;按类型配置强制展示订单价格
This commit is contained in:
22
jituan/migrations/0023_club_leixing_show_price.py
Normal file
22
jituan/migrations/0023_club_leixing_show_price.py
Normal file
@@ -0,0 +1,22 @@
|
||||
# Generated manually for ClubShangpinLeixingConfig.show_price
|
||||
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('jituan', '0022_user_wx_openid_wx_appid'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AddField(
|
||||
model_name='clubshangpinleixingconfig',
|
||||
name='show_price',
|
||||
field=models.BooleanField(
|
||||
default=False,
|
||||
help_text='开启后小程序该类型订单显示分成价格,即使未开通对应会员',
|
||||
verbose_name='强制展示订单价格',
|
||||
),
|
||||
),
|
||||
]
|
||||
@@ -246,6 +246,12 @@ class ClubShangpinLeixingConfig(QModel):
|
||||
is_enabled = models.BooleanField(default=True, verbose_name='是否上架')
|
||||
tupian_url = models.CharField(max_length=500, blank=True, default='', verbose_name='俱乐部专属图标')
|
||||
paixu = models.IntegerField(default=0, verbose_name='排序权重')
|
||||
# 新字段:旧小程序忽略;开启后该类型下真单强制展示价格(不改 hasRequiredMember 抢单逻辑)
|
||||
show_price = models.BooleanField(
|
||||
default=False,
|
||||
verbose_name='强制展示订单价格',
|
||||
help_text='开启后小程序该类型订单显示分成价格,即使未开通对应会员',
|
||||
)
|
||||
CreateTime = models.DateTimeField(auto_now_add=True)
|
||||
UpdateTime = models.DateTimeField(auto_now=True)
|
||||
|
||||
|
||||
@@ -62,6 +62,8 @@ def build_leixing_item(leixing, cfg=None):
|
||||
'bankuai_id': leixing.bankuai_id,
|
||||
'club_enabled': True,
|
||||
'icon_source': 'club' if cfg and cfg.tupian_url else 'global',
|
||||
# 新字段:旧客户端忽略;1/true 时该类型订单强制展示价格
|
||||
'show_price': bool(getattr(cfg, 'show_price', False)) if cfg else False,
|
||||
}
|
||||
return item
|
||||
|
||||
@@ -165,6 +167,33 @@ def disable_leixing_for_club(request, leixing_id):
|
||||
return {'leixing_id': leixing_id}, None
|
||||
|
||||
|
||||
def set_leixing_show_price(request, leixing_id, show_price):
|
||||
"""按俱乐部商品类型开关:是否强制展示订单价格。"""
|
||||
if club_write_blocked(request):
|
||||
return None, CLUB_WRITE_SCOPE_MSG
|
||||
club_id = club_id_for_write(request)
|
||||
try:
|
||||
lx = ShangpinLeixing.query.get(id=leixing_id)
|
||||
except ShangpinLeixing.DoesNotExist:
|
||||
return None, '商品类型不存在'
|
||||
|
||||
row, _ = ClubShangpinLeixingConfig.query.get_or_create(
|
||||
club_id=club_id,
|
||||
leixing_id=int(leixing_id),
|
||||
defaults={
|
||||
'is_enabled': club_id == CLUB_ID_DEFAULT,
|
||||
'paixu': int(lx.paixu or 0),
|
||||
'show_price': False,
|
||||
},
|
||||
)
|
||||
row.show_price = bool(show_price)
|
||||
row.save(update_fields=['show_price', 'UpdateTime'])
|
||||
return {
|
||||
'leixing_id': int(leixing_id),
|
||||
'show_price': bool(row.show_price),
|
||||
}, None
|
||||
|
||||
|
||||
def upload_leixing_icon(request, leixing_id, file_obj):
|
||||
if club_write_blocked(request):
|
||||
return None, CLUB_WRITE_SCOPE_MSG
|
||||
@@ -206,4 +235,5 @@ def copy_club_shangpin_leixing_config(template_club_id, new_club_id):
|
||||
is_enabled=row.is_enabled,
|
||||
tupian_url='', # 新俱乐部需自行上传图标,不复制 OSS 路径
|
||||
paixu=row.paixu,
|
||||
show_price=bool(getattr(row, 'show_price', False)),
|
||||
)
|
||||
|
||||
@@ -87,6 +87,7 @@ from jituan.views_club_catalog import (
|
||||
ClubShangpinLeixingEnableView,
|
||||
ClubShangpinLeixingIconView,
|
||||
ClubShangpinLeixingListView,
|
||||
ClubShangpinLeixingShowPriceView,
|
||||
)
|
||||
from jituan.views_shenhe_manage import ClubKhgglAddView
|
||||
from jituan.views_payment_channel import ClubPaymentChannelManageView
|
||||
@@ -216,6 +217,7 @@ urlpatterns = [
|
||||
path('houtai/club-leixing-enable', ClubShangpinLeixingEnableView.as_view(), name='jituan_club_leixing_enable'),
|
||||
path('houtai/club-leixing-disable', ClubShangpinLeixingDisableView.as_view(), name='jituan_club_leixing_disable'),
|
||||
path('houtai/club-leixing-icon', ClubShangpinLeixingIconView.as_view(), name='jituan_club_leixing_icon'),
|
||||
path('houtai/club-leixing-show-price', ClubShangpinLeixingShowPriceView.as_view(), name='jituan_club_leixing_show_price'),
|
||||
path('houtai/club-kaohe-list', ClubKaoheChenghaoListView.as_view(), name='jituan_club_kaohe_list'),
|
||||
path('houtai/club-kaohe-catalog', ClubKaoheChenghaoCatalogView.as_view(), name='jituan_club_kaohe_catalog'),
|
||||
path('houtai/club-kaohe-enable', ClubKaoheChenghaoEnableView.as_view(), name='jituan_club_kaohe_enable'),
|
||||
|
||||
@@ -118,6 +118,37 @@ class ClubShangpinLeixingIconView(APIView):
|
||||
return Response({'code': 0, 'msg': '上传成功', 'data': data})
|
||||
|
||||
|
||||
class ClubShangpinLeixingShowPriceView(APIView):
|
||||
"""POST /jituan/houtai/club-leixing-show-price 开关该类型强制展示订单价格"""
|
||||
permission_classes = [IsAuthenticated]
|
||||
parser_classes = [JSONParser]
|
||||
|
||||
def post(self, request):
|
||||
phone = (request.data.get('phone') or request.data.get('username') or '').strip()
|
||||
leixing_id = request.data.get('leixing_id')
|
||||
if not phone or leixing_id in (None, ''):
|
||||
return Response({'code': 400, 'msg': '参数不完整'})
|
||||
kefu, permissions = verify_kefu_permission(request, phone)
|
||||
if kefu is None:
|
||||
return permissions
|
||||
if not _has_club_leixing_perm(permissions):
|
||||
return Response({'code': 403, 'msg': '无权限'})
|
||||
raw = request.data.get('show_price', request.data.get('enabled'))
|
||||
if isinstance(raw, str):
|
||||
show_price = raw.strip().lower() in ('1', 'true', 'yes', 'on')
|
||||
else:
|
||||
show_price = bool(raw)
|
||||
from jituan.services.club_shangpin_leixing import set_leixing_show_price
|
||||
data, err = set_leixing_show_price(request, int(leixing_id), show_price)
|
||||
if err:
|
||||
return Response({'code': 400, 'msg': err})
|
||||
return Response({
|
||||
'code': 0,
|
||||
'msg': '已开启价格展示' if data.get('show_price') else '已关闭价格展示',
|
||||
'data': data,
|
||||
})
|
||||
|
||||
|
||||
class ClubKaoheChenghaoListView(APIView):
|
||||
"""POST /jituan/houtai/club-kaohe-list"""
|
||||
permission_classes = [IsAuthenticated]
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -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'),
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user