feat: 点单端搜索可指定打手接口 sousuodashou
仅返回未封禁且当前未在服务中的打手,按俱乐部隔离,不影响其他业务。 Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -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='打手信息查询'),
|
||||
# 更改在线状态接口
|
||||
|
||||
@@ -117,6 +117,8 @@ from .kefu_dashou import (
|
||||
KefuUpdateDashouView,
|
||||
)
|
||||
|
||||
from .boss_dashou_search import BossSearchDashouView
|
||||
|
||||
from .kefu_punishment import (
|
||||
KefuPunishView,
|
||||
KefuPunishmentActionView,
|
||||
|
||||
70
users/views/boss_dashou_search.py
Normal file
70
users/views/boss_dashou_search.py
Normal file
@@ -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}})
|
||||
Reference in New Issue
Block a user