feat: H5链接配对群ID与客服订单详情扩展(指定响应/罚款)
This commit is contained in:
@@ -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)
|
||||
|
||||
@@ -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})
|
||||
|
||||
|
||||
|
||||
@@ -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 ''
|
||||
|
||||
Reference in New Issue
Block a user