修正字段名不同的问题
This commit is contained in:
156
backend/view.py
156
backend/view.py
@@ -918,162 +918,6 @@ class KefuGetDashouDetailView(APIView):
|
||||
|
||||
|
||||
|
||||
|
||||
'''class KefuGetDashouDetailView(APIView):
|
||||
"""
|
||||
客服获取打手详情接口
|
||||
请求:POST /yonghu/kefuhqdsxq
|
||||
参数:{
|
||||
"phone": "客服手机号",
|
||||
"uid": "打手ID (yonghuid)"
|
||||
}
|
||||
认证:JWT
|
||||
返回:code=0 + 打手信息 + 会员列表
|
||||
"""
|
||||
permission_classes = [IsAuthenticated]
|
||||
parser_classes = [JSONParser]
|
||||
|
||||
def post(self, request):
|
||||
# 1. 获取参数
|
||||
username = request.data.get('phone', '').strip()
|
||||
uid = request.data.get('uid', '').strip()
|
||||
|
||||
if not username or not uid:
|
||||
return Response({'code': 401, 'msg': '认证失败'}, status=status.HTTP_401_UNAUTHORIZED)
|
||||
|
||||
# 2. 客服身份验证
|
||||
current_user = request.user
|
||||
|
||||
# 2. 公共权限校验(验证客服身份,获取权限列表)
|
||||
kefu, permissions = verify_kefu_permission(request, username)
|
||||
if kefu is None:
|
||||
return permissions # 直接返回错误响应
|
||||
|
||||
# 3. 检查是否拥有打手管理相关权限(至少一个)
|
||||
required_perms = {'001aa', '001bb', '001cc', '001dd', '001ee', '001ff', '001gg'}
|
||||
if not any(p in permissions for p in required_perms):
|
||||
return Response({'code': 403, 'msg': '您没有权限查看打手列表'})
|
||||
|
||||
# 3. 查询打手主表和扩展表
|
||||
try:
|
||||
# 使用 select_related 预加载 dashou_profile,减少数据库查询
|
||||
user_main = User.query.select_related('DashouProfile').get(
|
||||
UserUID=uid
|
||||
)
|
||||
except User.DoesNotExist:
|
||||
return Response({'code': 404, 'msg': '打手不存在'}, status=status.HTTP_404_NOT_FOUND)
|
||||
|
||||
# 验证用户类型是否为打手(可选,但建议验证)
|
||||
# 如果该用户没有打手扩展表,则返回空信息(但前端会显示未注册)
|
||||
try:
|
||||
dashou = user_main.DashouProfile
|
||||
except ObjectDoesNotExist:
|
||||
# 用户存在但未注册打手身份,返回基本信息
|
||||
user_info = {
|
||||
'yonghuid': user_main.UserUID,
|
||||
'avatar': user_main.Avatar or '',
|
||||
'zaixianzhuangtai': 0,
|
||||
'zhanghaozhuangtai': 0,
|
||||
'zhuangtai': 0,
|
||||
'nicheng': '',
|
||||
'chenghao': '',
|
||||
'dianhua': '',
|
||||
'wechat': '',
|
||||
'phone': user_main.Phone or '',
|
||||
'CreateTime': user_main.UserCreateTime,
|
||||
'ip': user_main.IP or '',
|
||||
'jiedanzongliang': 0,
|
||||
'chengjiaozongliang': 0,
|
||||
'tuikuanliang': 0,
|
||||
'jinrijiedan': 0,
|
||||
'yue': 0.00,
|
||||
'zonge': 0.00,
|
||||
'jifen': 0,
|
||||
'yajin': 0.00,
|
||||
'jinrishouyi': 0.00,
|
||||
'jinyueshouyi': 0.00,
|
||||
'yaoqingren': '',
|
||||
'jieshao': '',
|
||||
}
|
||||
member_list = []
|
||||
return Response({
|
||||
'code': 0,
|
||||
'data': {
|
||||
'user_info': user_info,
|
||||
'member_list': member_list
|
||||
}
|
||||
})
|
||||
|
||||
# 4. 构建打手信息
|
||||
user_info = {
|
||||
'yonghuid': user_main.UserUID,
|
||||
'avatar': user_main.Avatar or '',
|
||||
'zaixianzhuangtai': dashou.zaixianzhuangtai,
|
||||
'zhanghaozhuangtai': dashou.zhanghaozhuangtai,
|
||||
'zhuangtai': dashou.zhuangtai,
|
||||
'nicheng': dashou.nicheng or '',
|
||||
'chenghao': dashou.chenghao or '',
|
||||
'dianhua': dashou.dianhua or '',
|
||||
'wechat': dashou.wechat or '',
|
||||
'phone': user_main.Phone or '',
|
||||
'CreateTime': user_main.UserCreateTime,
|
||||
'ip': user_main.IP or '',
|
||||
'jiedanzongliang': dashou.jiedanzongliang,
|
||||
'chengjiaozongliang': dashou.chengjiaozongliang,
|
||||
'tuikuanliang': dashou.tuikuanliang,
|
||||
'jinrijiedan': dashou.jinrijiedan,
|
||||
'yue': float(dashou.yue) if dashou.yue else 0.00,
|
||||
'zonge': float(dashou.zonge) if dashou.zonge else 0.00,
|
||||
'jifen': dashou.jifen,
|
||||
'yajin': float(dashou.yajin) if dashou.yajin else 0.00,
|
||||
'jinrishouyi': float(dashou.jinrishouyi) if dashou.jinrishouyi else 0.00,
|
||||
'jinyueshouyi': float(dashou.jinyueshouyi) if dashou.jinyueshouyi else 0.00,
|
||||
'yaoqingren': dashou.yaoqingren or '',
|
||||
'jieshao': dashou.jieshao or '',
|
||||
}
|
||||
|
||||
# 5. 查询打手会员信息(仅未过期)
|
||||
member_records = Huiyuangoumai.query.filter(
|
||||
yonghu_id=uid
|
||||
).order_by('-CreateTime')
|
||||
|
||||
member_list = []
|
||||
for record in member_records:
|
||||
# 调用模型方法检查是否过期
|
||||
if hasattr(record, 'jiance_shifou_daoqi'):
|
||||
is_expired = record.jiance_shifou_daoqi()
|
||||
else:
|
||||
# 如果方法不存在,简单判断
|
||||
is_expired = record.daoqi_time < timezone.now() if record.daoqi_time else True
|
||||
|
||||
if not is_expired:
|
||||
# 获取会员详情
|
||||
try:
|
||||
huiyuan = Huiyuan.query.get(huiyuan_id=record.huiyuan_id)
|
||||
huiyuan_name = huiyuan.jieshao
|
||||
except Huiyuan.DoesNotExist:
|
||||
huiyuan_name = '未知会员'
|
||||
|
||||
member_list.append({
|
||||
'id': record.id,
|
||||
'huiyuan_name': huiyuan_name,
|
||||
'daoqi_time': record.daoqi_time,
|
||||
'is_active': record.huiyuan_zhuangtai == 1,
|
||||
})
|
||||
|
||||
return Response({
|
||||
'code': 0,
|
||||
'data': {
|
||||
'user_info': user_info,
|
||||
'member_list': member_list
|
||||
}
|
||||
})'''
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
class KefuUpdateDashouView(APIView):
|
||||
"""
|
||||
客服修改打手信息接口
|
||||
|
||||
Reference in New Issue
Block a user