From 65db2772d8d79ddceb266b06749cc1f9750ee8ec Mon Sep 17 00:00:00 2001 From: XingQue Date: Thu, 23 Jul 2026 00:31:47 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E7=82=B9=E5=8D=95=E7=AB=AF=E6=90=9C?= =?UTF-8?q?=E7=B4=A2=E5=8F=AF=E6=8C=87=E5=AE=9A=E6=89=93=E6=89=8B=E6=8E=A5?= =?UTF-8?q?=E5=8F=A3=20sousuodashou?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 仅返回未封禁且当前未在服务中的打手,按俱乐部隔离,不影响其他业务。 Co-authored-by: Cursor --- users/urls.py | 3 +- users/views/__init__.py | 2 + users/views/boss_dashou_search.py | 70 +++++++++++++++++++++++++++++++ 3 files changed, 74 insertions(+), 1 deletion(-) create mode 100644 users/views/boss_dashou_search.py diff --git a/users/urls.py b/users/urls.py index 02a5948..8b11779 100644 --- a/users/urls.py +++ b/users/urls.py @@ -17,7 +17,7 @@ from .views import WechatMiniProgramLoginView, UserInfoUpdateView, DashouXinxiAP AdKfxgView,GuanshiRegisterView, WechatLoginAndGuanshiRegisterView,ZuzhangZhuceView, ZuzhangXinxiView,KefuForceCompleteView,HuoQuYaoQingRenView, DashouJianquanView, LaobanJianquanView,\ FaKuanJiFenTongJiView, DaShouFaKuanLieBiaoView, ShangjiaCufaTongjiView, ShangjiaFakuanLieBiaoView,\ FaKuanShenSuView, FaKuanPayView,FaKuanHuitiaoView, FaKuanPayPollView, FaKuanPayFailView,KaohePayView,KaohePayCallbackView, KaohePayPollView,KaohePayFailView, TixianAssetView, GuanshiContactView,TixianQueRenAutoView, TixianShenqingV3View, TixianCallbackV3View, \ - GetUserPhoneView, BindUserPhoneView + GetUserPhoneView, BindUserPhoneView, BossSearchDashouView from .tixian_shenhe_views import TixianZddkshApplyView from .paihang_views import PhbHqsjView from .xzj_paihang_views import XzjPhbHqsjView @@ -30,6 +30,7 @@ urlpatterns = [ path('xiugai', UserInfoUpdateView.as_view(), name='用户信息修改'), path('hqshouji', GetUserPhoneView.as_view(), name='获取用户手机号认证状态'), path('rzwlsjh', BindUserPhoneView.as_view(), name='一键认证手机号'), + path('sousuodashou', BossSearchDashouView.as_view(), name='点单端搜索可指定打手'), # 打手信息接口 path('dashouxinxi', DashouXinxiAPIView.as_view(), name='打手信息查询'), # 更改在线状态接口 diff --git a/users/views/__init__.py b/users/views/__init__.py index e776e46..5222b83 100644 --- a/users/views/__init__.py +++ b/users/views/__init__.py @@ -117,6 +117,8 @@ from .kefu_dashou import ( KefuUpdateDashouView, ) +from .boss_dashou_search import BossSearchDashouView + from .kefu_punishment import ( KefuPunishView, KefuPunishmentActionView, diff --git a/users/views/boss_dashou_search.py b/users/views/boss_dashou_search.py new file mode 100644 index 0000000..2d85ac2 --- /dev/null +++ b/users/views/boss_dashou_search.py @@ -0,0 +1,70 @@ +# -*- coding: utf-8 -*- +"""点单端搜索可指定打手(仅返回未封禁、当前未在服务中的打手)。""" +from django.db.models import Q +from rest_framework.permissions import IsAuthenticated +from rest_framework.response import Response +from rest_framework.views import APIView + +from jituan.constants import CLUB_ID_DEFAULT +from jituan.services.club_context import resolve_effective_club_id +from orders.models import Order +from users.models import UserDashou + + +# 视为「接单中」:服务中 / 待结单 / 指定待接 +_BUSY_ORDER_STATUS = (2, 7, 8) + + +class BossSearchDashouView(APIView): + """ + POST /yonghu/sousuodashou + body: { "keyword": "昵称或UID" } — 必须有关键词才返回列表(点搜索才展示) + """ + permission_classes = [IsAuthenticated] + + def post(self, request): + keyword = (request.data.get('keyword') or '').strip() + if not keyword: + return Response({'code': 0, 'data': {'list': []}, 'msg': '请输入昵称或UID后搜索'}) + + club_id = resolve_effective_club_id(request, request.user) or CLUB_ID_DEFAULT + + # 当前俱乐部忙碌打手 UID + busy_qs = Order.query.filter( + club_id=club_id, + zhuangtai__in=_BUSY_ORDER_STATUS, + ) + busy_uids = set() + for row in busy_qs.only('PlayerID', 'AssignedID')[:2000]: + if row.PlayerID: + busy_uids.add(str(row.PlayerID)) + if row.AssignedID: + busy_uids.add(str(row.AssignedID)) + + qs = ( + UserDashou.query.select_related('user') + .filter(zhuangtai=1, zhanghaozhuangtai=1) + .filter( + Q(nicheng__icontains=keyword) | Q(user__UserUID__icontains=keyword) + ) + .order_by('-jinrijiedan', '-CreateTime')[:50] + ) + + result = [] + for ds in qs: + user = ds.user + uid = str(user.UserUID or '') + if not uid or uid in busy_uids: + continue + user_club = (getattr(user, 'ClubID', None) or getattr(user, 'club_id', None) or '').strip() + # 有俱乐部归属时只返回本俱乐部打手;历史无 club 的也允许被指定 + if user_club and user_club != club_id: + continue + result.append({ + 'uid': uid, + 'nicheng': ds.nicheng or getattr(user, 'UserName', '') or uid, + 'touxiang': getattr(user, 'Avatar', '') or '', + 'zaixian': int(ds.zaixianzhuangtai or 0), + }) + + return Response({'code': 0, 'data': {'list': result}})