From 634796b012a70e89f764455c045161a30b348aeb Mon Sep 17 00:00:00 2001 From: XingQue Date: Mon, 29 Jun 2026 06:51:49 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20H5=E9=93=BE=E6=8E=A5=E9=85=8D=E5=AF=B9?= =?UTF-8?q?=E7=BE=A4ID=E4=B8=8E=E5=AE=A2=E6=9C=8D=E8=AE=A2=E5=8D=95?= =?UTF-8?q?=E8=AF=A6=E6=83=85=E6=89=A9=E5=B1=95(=E6=8C=87=E5=AE=9A?= =?UTF-8?q?=E5=93=8D=E5=BA=94/=E7=BD=9A=E6=AC=BE)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- config/views.py | 32 +++++++++--------------------- users/views.py | 40 ++++++++++++++++++++++++++++++++++++++ utils/chat_utils.py | 47 +++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 96 insertions(+), 23 deletions(-) diff --git a/config/views.py b/config/views.py index 03d5cd5..385b85d 100644 --- a/config/views.py +++ b/config/views.py @@ -30,7 +30,7 @@ from utils.weixin_token import get_weixin_mini_access_token, is_weixin_token_inv # from utils.ip_security import * from utils.invitationcode_utils import CreateInvitationCode, VerifyInvitationCode -from backend.utils import update_shangjia_daily +from utils.chat_utils import subscribe_merchant_link_chat from .models import ( Gonggao, Lunbo, Tupianpeizhi, Qunpeizhi, @@ -2258,31 +2258,17 @@ class KehuGetDingdanLianjieView(APIView): 'waibu_dingdan_id': dingdan_obj.ExternalOrderID or '', }) - # 获取聊天相关标识 - # 9.1 获取接单打手ID - jiedan_dashou_id = dingdan_obj.PlayerID - dashou_biaoshi = f'Ds{jiedan_dashou_id}' if jiedan_dashou_id else '' - - # 9.2 获取商家标识 - shangjia_biaoshi = '' - try: - shangjia_kuozhan = MerchantOrderExt.query.select_related('Order').filter( - Order__OrderID=lianjie_obj.OrderID - ).first() - - if shangjia_kuozhan and shangjia_kuozhan.MerchantID: - shangjia_biaoshi = f'Sj{shangjia_kuozhan.MerchantID}' - logger.info(f"生成商家标识: {shangjia_biaoshi}") - else: - logger.info(f"订单 {lianjie_obj.OrderID} 没有商家订单扩展信息") - except Exception as e: - logger.error(f"查询商家订单扩展异常: {str(e)}", exc_info=True) + # 获取聊天相关标识(新配对群优先,旧单保留 order 群) + chat_meta, _sub_ok = subscribe_merchant_link_chat(dingdan_obj, lianjie_obj.UserID) # 添加聊天标识 dingdan_info.update({ - 'dashou_biaoshi': dashou_biaoshi, - 'shangjia_biaoshi': shangjia_biaoshi, - 'you_dashou': bool(dashou_biaoshi), + 'dashou_biaoshi': chat_meta.get('dashou_biaoshi', ''), + 'shangjia_biaoshi': chat_meta.get('shangjia_biaoshi', ''), + 'you_dashou': chat_meta.get('you_dashou', False), + 'group_id': chat_meta.get('group_id', ''), + 'is_pair_group': chat_meta.get('is_pair_group', False), + 'legacy_group_id': chat_meta.get('legacy_group_id', ''), }) response_data.update(dingdan_info) diff --git a/users/views.py b/users/views.py index 745ffdb..1adf674 100644 --- a/users/views.py +++ b/users/views.py @@ -9270,6 +9270,46 @@ class KefuGetOrderDetailView(APIView): logger.exception(f"[kefuhqddxq] 退款理由查询异常 dingdan_id={dingdan_id}") response_data['tuikuan_liyou'] = '' + # 8. 指定打手响应 + ZHIDING_HF_TEXT = {1: '想接', 2: '不想接', 3: '等会接'} + hf = getattr(dingdan_obj, 'AssignedResponse', None) + response_data['zhiding_hf'] = hf + response_data['zhiding_hf_text'] = ZHIDING_HF_TEXT.get(hf, '') if hf else '' + response_data['zhiding_hf_sj'] = ( + dingdan_obj.AssignedResponseAt.strftime('%Y-%m-%d %H:%M:%S') + if getattr(dingdan_obj, 'AssignedResponseAt', None) else '' + ) + response_data['zhiding_dhj_sm'] = getattr(dingdan_obj, 'AssignedLaterNote', '') or '' + + # 9. 关联罚款(打手) + PENALTY_STATUS = {1: '待缴纳', 2: '已缴纳', 3: '申诉中', 4: '已驳回'} + try: + from orders.models import Penalty + dashou_id = dingdan_obj.PlayerID or dingdan_obj.AssignedID or '' + fakuan_qs = Penalty.query.filter(RelatedOrderID=dingdan_id) + if dashou_id: + fakuan_qs = fakuan_qs.filter(PenalizedUserID=dashou_id) + fakuan_list = [] + for p in fakuan_qs.order_by('-CreateTime')[:5]: + fakuan_list.append({ + 'amount': str(p.FineAmount or '0.00'), + 'status': p.Status, + 'status_text': PENALTY_STATUS.get(p.Status, ''), + 'reason': p.Reason or '', + 'create_time': p.CreateTime.strftime('%Y-%m-%d %H:%M:%S') if p.CreateTime else '', + }) + response_data['fakuan_list'] = fakuan_list + latest = fakuan_list[0] if fakuan_list else None + response_data['fakuan_info'] = latest + response_data['is_fadaned'] = Penalty.query.filter( + RelatedOrderID=dingdan_id, ApplicantID=getattr(current_user, 'UserUID', '') + ).exists() + except Exception as e: + logger.exception(f"[kefuhqddxq] 罚款查询异常 dingdan_id={dingdan_id}") + response_data['fakuan_list'] = [] + response_data['fakuan_info'] = None + response_data['is_fadaned'] = False + return Response({'code': 0, 'data': response_data}) diff --git a/utils/chat_utils.py b/utils/chat_utils.py index bd80e3e..127411a 100644 --- a/utils/chat_utils.py +++ b/utils/chat_utils.py @@ -35,6 +35,53 @@ def _full_local_avatar(relative_url): return relative_url +def build_merchant_link_chat_meta(order, link_merchant_uid): + """H5 商家链接页群聊:新单走配对群,旧单或无打手时回落 group_{orderId}""" + pair_id = resolve_pair_group_id(order) + legacy_id = f'group_{order.OrderID}' + group_id = pair_id or legacy_id + dashou_uid = order.PlayerID or '' + self_user_id = f'B{link_merchant_uid}' if link_merchant_uid else '' + shangjia_biaoshi = '' + try: + if order.Platform == 2 and getattr(order, 'shangjia_kuozhan', None): + mid = order.shangjia_kuozhan.MerchantID + if mid: + shangjia_biaoshi = f'Sj{mid}' + except Exception: + pass + return { + 'group_id': group_id, + 'is_pair_group': bool(pair_id), + 'legacy_group_id': legacy_id, + 'self_user_id': self_user_id, + 'dashou_biaoshi': f'Ds{dashou_uid}' if dashou_uid else '', + 'shangjia_biaoshi': shangjia_biaoshi, + 'you_dashou': bool(dashou_uid), + } + + +def subscribe_merchant_link_chat(order, link_merchant_uid): + """链接页有打手时,预订阅 B{商家} 与打手到对应群(新旧群 ID 均兼容)""" + meta = build_merchant_link_chat_meta(order, link_merchant_uid) + if not meta.get('you_dashou'): + return meta, True + appkey = _get_self_goeasy_appkey() + secret = _get_self_goeasy_secret() + if not appkey: + return meta, False + user_ids = [] + if meta.get('self_user_id'): + user_ids.append(meta['self_user_id']) + if meta.get('dashou_biaoshi'): + user_ids.append(meta['dashou_biaoshi']) + group_ids = [meta['group_id']] + if meta.get('legacy_group_id') and meta['legacy_group_id'] != meta['group_id']: + group_ids.append(meta['legacy_group_id']) + ok = _subscribe_users_to_group(user_ids, group_ids, appkey, secret) + return meta, ok + + def resolve_pair_group_id(order): """打手+商家/老板配对群 ID,与前端 resolveLocalGroupId 一致(同两人共用一个群)""" dashou_uid = order.PlayerID or ''