修复了管理员无法进后台的问题

This commit is contained in:
2026-06-19 01:58:34 +08:00
parent 5b9436b994
commit d71a81f279
22 changed files with 4396 additions and 4295 deletions

View File

@@ -68,7 +68,7 @@ def process_expired_order(self, dingdan_id):
dashou_user = User.query.filter(UserUID=dashou_id).first()
if dashou_user:
# 获取打手扩展表
dashou_profile = getattr(dashou_user, 'dashou_profile', None)
dashou_profile = getattr(dashou_user, 'DashouProfile', None)
if dashou_profile:
# 使用F表达式原子更新
UserDashou.query.filter(pk=dashou_profile.pk).update(
@@ -96,7 +96,7 @@ def process_expired_order(self, dingdan_id):
# 查询商家用户
shangjia_user = User.query.filter(UserUID=shangjia_id).first()
if shangjia_user:
shangjia_profile = getattr(shangjia_user, 'shop_profile', None)
shangjia_profile = getattr(shangjia_user, 'ShopProfile', None)
if shangjia_profile:
# 更新商家成交订单数量
UserShangjia.query.filter(pk=shangjia_profile.pk).update(

View File

@@ -179,7 +179,7 @@ def settle_shangjia_order_guanshi_fenhong(order, dashou_id):
dashouid=dashou_id,
shuoming='商家订单分红',
fenhong=guanshi_fencheng,
avatar=user_main.avatar if user_main else None,
avatar=user_main.Avatar if user_main else None,
nicheng=dashou.nicheng or '未知打手',
fenhong_leixing=3,
)

View File

@@ -91,7 +91,7 @@ class PaymentFailView(APIView):
if not dingdan:
return Response({'code': 2, 'msg': '订单不存在', 'data': None})
if dingdan.User1ID != f"Boss{request.user.yonghuid}":
if dingdan.User1ID != f"Boss{request.user.UserUID}":
return Response({'code': 3, 'msg': '无权操作此订单', 'data': None})
# 只允许删除未支付订单状态9
@@ -242,8 +242,8 @@ class WechatPayNotifyView(APIView):
laoban_id = dingdan.pingtai_kuozhan.BossID
if laoban_id:
user_main = User.query.filter(UserUID=laoban_id).first()
if user_main and hasattr(user_main, 'boss_profile'):
boss = user_main.boss_profile
if user_main and hasattr(user_main, 'BossProfile'):
boss = user_main.BossProfile
boss.zonge = (boss.zonge or 0) + (dingdan.Amount or 0)
boss.alldingdan = (boss.alldingdan or 0) + 1
boss.save()
@@ -433,9 +433,9 @@ class PaymentVerifyView(APIView):
# ---------- 3. 验证订单归属(安全) ----------
current_user = request.user
user_identifier = f"Boss{current_user.yonghuid}"
user_identifier = f"Boss{current_user.UserUID}"
if dingdan.User1ID != user_identifier:
logger.warning(f"用户 {current_user.yonghuid} 尝试复查他人订单 {dingdanid}")
logger.warning(f"用户 {current_user.UserUID} 尝试复查他人订单 {dingdanid}")
return Response({'code': 403, 'msg': '无权访问'})
# ---------- 4. 如果订单状态已是1/7直接返回成功 ----------
@@ -460,7 +460,7 @@ class PaymentVerifyView(APIView):
if trade_state == 'SUCCESS':
# 支付成功,执行本地更新
self._process_payment_success(dingdan, transaction_id, current_user.yonghuid)
self._process_payment_success(dingdan, transaction_id, current_user.UserUID)
# 重新获取订单以获取最新状态
dingdan.refresh_from_db()
return Response({
@@ -526,8 +526,8 @@ class PaymentVerifyView(APIView):
laoban_id = dingdan.pingtai_kuozhan.BossID if hasattr(dingdan, 'pingtai_kuozhan') else None
if laoban_id:
user_main = User.query.filter(UserUID=laoban_id).first()
if user_main and hasattr(user_main, 'boss_profile'):
boss = user_main.boss_profile
if user_main and hasattr(user_main, 'BossProfile'):
boss = user_main.BossProfile
boss.zonge = (boss.zonge or 0) + (dingdan.Amount or 0)
boss.alldingdan = (boss.alldingdan or 0) + 1
boss.save()
@@ -787,7 +787,7 @@ class CreateOrderView(APIView):
'Remark': beizhu,
'Nickname': nicheng,
'ImageURL':shangpin_tupian,
'User1ID':f"Boss{request.user.yonghuid}",
'User1ID':f"Boss{request.user.UserUID}",
'ProductTypeID':shangpin.leixing_id
}
@@ -1020,7 +1020,7 @@ class DingdanHuoquView(APIView):
# 获取当前登录用户
try:
current_user = request.user
yonghuid = current_user.yonghuid
yonghuid = current_user.UserUID
except Exception as e:
return Response({
'code': 1,
@@ -1135,7 +1135,7 @@ class DingdanXiangqingView(APIView):
# 获取当前登录用户
try:
current_user = request.user
yonghuid = current_user.yonghuid
yonghuid = current_user.UserUID
except Exception as e:
return Response({
'code': 1,
@@ -1243,7 +1243,7 @@ class JiedanView(APIView):
# 获取当前登录用户
try:
current_user = request.user
yonghuid = current_user.yonghuid
yonghuid = current_user.UserUID
except Exception as e:
return Response({
'code': 1,
@@ -1475,7 +1475,7 @@ class DingdanXiangqingView2(APIView):
def post(self, request):
try:
yonghuid = request.user.yonghuid
yonghuid = request.user.UserUID
except Exception:
return Response({'code': 1, 'msg': '用户认证失败', 'data': None})
@@ -1514,9 +1514,9 @@ class DingdanXiangqingView2(APIView):
if jiedan_dashou_id:
dashou_user = User.query.filter(UserUID=jiedan_dashou_id).first()
if dashou_user:
dashou_touxiang = dashou_user.avatar or ''
dashou_touxiang = dashou_user.Avatar or ''
try:
dashou_nicheng = dashou_user.dashou_profile.nicheng or ''
dashou_nicheng = dashou_user.DashouProfile.nicheng or ''
except UserDashou.DoesNotExist:
pass
biaoxian = DashouBiaoxian.query.filter(
@@ -1575,7 +1575,7 @@ class JiedanView2(APIView):
# 1. 用户认证
try:
current_user = request.user
yonghuid = current_user.yonghuid
yonghuid = current_user.UserUID
except Exception:
return Response({'code': 1, 'msg': '用户认证失败', 'data': None})
@@ -1664,7 +1664,7 @@ class JiedanView2(APIView):
dashou_user = User.query.filter(UserUID=jiedan_dashou_id).first()
if dashou_user:
try:
dashou_ext = dashou_user.dashou_profile
dashou_ext = dashou_user.DashouProfile
dashou_ext.zonge = (dashou_ext.zonge or Decimal('0.00')) + dashou_fencheng
dashou_ext.yue = (dashou_ext.yue or Decimal('0.00')) + dashou_fencheng
dashou_ext.jinrishouyi = (dashou_ext.jinrishouyi or Decimal('0.00')) + dashou_fencheng
@@ -1811,7 +1811,7 @@ class ShangjiaPaifaView(APIView):
permission_classes = [IsAuthenticated]
def post(self, request):
logger.info(f"商家派单请求: user_id={request.user.yonghuid}, data={request.data}")
logger.info(f"商家派单请求: user_id={request.user.UserUID}, data={request.data}")
try:
data = request.data
@@ -1899,9 +1899,9 @@ class ShangjiaPaifaView(APIView):
# ----- 8. 商家信息 -----
try:
shangjia = request.user.shop_profile
shangjia = request.user.ShopProfile
except UserShangjia.DoesNotExist:
logger.warning(f"用户不是商家: {request.user.yonghuid}")
logger.warning(f"用户不是商家: {request.user.UserUID}")
return Response({'code': 403, 'msg': '您不是商家'})
if shangjia.zhuangtai != 1:
@@ -1917,7 +1917,7 @@ class ShangjiaPaifaView(APIView):
if zhiding_uid:
try:
zhiding_user = User.query.get(UserUID=zhiding_uid)
zhiding_dashou = zhiding_user.dashou_profile
zhiding_dashou = zhiding_user.DashouProfile
if zhiding_dashou.zhanghaozhuangtai != 1:
return Response({'code': 400, 'msg': '指定打手状态异常'})
except User.DoesNotExist:
@@ -1955,14 +1955,14 @@ class ShangjiaPaifaView(APIView):
Description=dingdan_jieshao[:2000],
Remark=dingdan_beizhu[:1000],
Nickname=laoban_name[:50],
ImageURL=request.user.avatar,
User1ID=f"Sj{request.user.yonghuid}"
ImageURL=request.user.Avatar,
User1ID=f"Sj{request.user.UserUID}"
)
logger.info(f"订单主表创建: {dingdan.OrderID}")
MerchantOrderExt.query.create(
Order=dingdan,
MerchantID=request.user.yonghuid,
MerchantID=request.user.UserUID,
MerchantNickname=shangjia.nicheng,
)
@@ -1981,7 +1981,7 @@ class ShangjiaPaifaView(APIView):
)
update_shangjia_daily(
UserID=request.user.yonghuid,
UserID=request.user.UserUID,
amount=Decimal(str(jiage)),
action=1
)
@@ -2034,7 +2034,7 @@ class ShangjiaDingdanHuoquView(APIView):
# 1. 获取当前登录用户的yonghuid
try:
current_user = request.user
yonghuid = current_user.yonghuid
yonghuid = current_user.UserUID
except AttributeError:
return Response({
'code': 1,
@@ -2169,7 +2169,7 @@ class ShangjiaDingdanXiangqingView(APIView):
# 1. 获取当前登录用户的 yonghuid
try:
current_user = request.user
yonghuid = current_user.yonghuid
yonghuid = current_user.UserUID
except AttributeError:
return Response({
'code': 1,
@@ -2224,11 +2224,11 @@ class ShangjiaDingdanXiangqingView(APIView):
if dashou_yonghuid:
dashou_user = User.query.filter(
UserUID=dashou_yonghuid
).select_related('dashou_profile').first()
).select_related('DashouProfile').first()
if dashou_user:
dashou_avatar = dashou_user.avatar or ''
if hasattr(dashou_user, 'dashou_profile') and dashou_user.dashou_profile:
dashou_nicheng = dashou_user.dashou_profile.nicheng or ''
dashou_avatar = dashou_user.Avatar or ''
if hasattr(dashou_user, 'DashouProfile') and dashou_user.DashouProfile:
dashou_nicheng = dashou_user.DashouProfile.nicheng or ''
# 6. 罚款数据(如果存在)
fadan_obj = Penalty.query.filter(
@@ -2339,10 +2339,10 @@ class ShangjiaJiesuanView(APIView):
# 1. 获取当前登录用户
try:
current_user = request.user
yonghuid = current_user.yonghuid
yonghuid = current_user.UserUID
try:
shangjia = current_user.shop_profile
shangjia = current_user.ShopProfile
except UserShangjia.DoesNotExist:
return Response({
'code': 1,
@@ -2427,7 +2427,7 @@ class ShangjiaJiesuanView(APIView):
# 查询打手信息
try:
dashou_user = User.query.get(UserUID=jiedan_dashou_id)
dashou = dashou_user.dashou_profile
dashou = dashou_user.DashouProfile
except (User.DoesNotExist, UserDashou.DoesNotExist):
return Response({
'code': 8,
@@ -2484,7 +2484,7 @@ class ShangjiaJiesuanView(APIView):
# ✅ 新方法(行为驱动,更安全)
update_shangjia_daily(
UserID=request.user.yonghuid,
UserID=request.user.UserUID,
amount=Decimal(str(jine)),
action=2 # 2 = 结算
)
@@ -2534,7 +2534,7 @@ class ShangjiaChexiaoView(APIView):
try:
current_user = request.user
# 使用反向查询获取商家扩展信息(性能最佳)
shangjia = current_user.shop_profile
shangjia = current_user.ShopProfile
except UserShangjia.DoesNotExist:
return Response({
'code': 1,
@@ -2593,7 +2593,7 @@ class ShangjiaChexiaoView(APIView):
# 7. 验证订单所属商家(使用反向查询)
shangjia_kuozhan = MerchantOrderExt.query.filter(
Order__OrderID=dingdan_id,
MerchantID=current_user.yonghuid
MerchantID=current_user.UserUID
).first()
if not shangjia_kuozhan:
@@ -2606,7 +2606,7 @@ class ShangjiaChexiaoView(APIView):
# 8. 创建退款记录注意申请状态直接设为1-成功)
RefundRecord.query.create(
OrderID=dingdan_id,
ApplicantID=current_user.yonghuid,
ApplicantID=current_user.UserUID,
Reason=chexiao_liyou,
ApplyStatus=1, # 直接成功
Amount=dingdan.Amount,
@@ -2635,7 +2635,7 @@ class ShangjiaChexiaoView(APIView):
# 行为驱动
update_shangjia_daily(
UserID=request.user.yonghuid,
UserID=request.user.UserUID,
amount=Decimal(str(dingdan.Amount)),
action=3 # 3 = 退款
)
@@ -2670,7 +2670,7 @@ class ShangjiaTuikuanShenqingView(APIView):
# 1. 获取当前登录用户并验证商家身份
try:
current_user = request.user
shangjia = current_user.shop_profile
shangjia = current_user.ShopProfile
except UserShangjia.DoesNotExist:
return Response({
'code': 1,
@@ -2729,7 +2729,7 @@ class ShangjiaTuikuanShenqingView(APIView):
# 7. 验证订单所属商家
shangjia_kuozhan = MerchantOrderExt.query.filter(
Order__OrderID=dingdan_id,
MerchantID=current_user.yonghuid
MerchantID=current_user.UserUID
).first()
if not shangjia_kuozhan:
@@ -2744,7 +2744,7 @@ class ShangjiaTuikuanShenqingView(APIView):
OrderID=dingdan_id,
defaults={
'PlayerID': dingdan.PlayerID,
'ApplicantID': current_user.yonghuid,
'ApplicantID': current_user.UserUID,
'Reason': tuikuan_liyou,
'ApplyStatus': 0, # 待处理
'Amount': dingdan.Amount,
@@ -2771,8 +2771,8 @@ class ShangjiaTuikuanShenqingView(APIView):
dashou_main = User.query.filter(
UserUID=dingdan.PlayerID
).first()
if dashou_main and hasattr(dashou_main, 'dashou_profile'):
dashou_profile = dashou_main.dashou_profile
if dashou_main and hasattr(dashou_main, 'DashouProfile'):
dashou_profile = dashou_main.DashouProfile
dashou_profile.zhuangtai = 1
dashou_profile.save()
logger.info(f"退款申请成功,打手状态已更新:订单{dingdan_id},打手{dingdan.PlayerID}状态变更为1")
@@ -2808,7 +2808,7 @@ class ShangjiaChufaShenqingView(APIView):
# 1. 获取当前登录用户并验证商家身份
try:
current_user = request.user
shangjia = current_user.shop_profile
shangjia = current_user.ShopProfile
except UserShangjia.DoesNotExist:
return Response({
'code': 1,
@@ -2852,7 +2852,7 @@ class ShangjiaChufaShenqingView(APIView):
# 验证打手身份
try:
dashou_user = User.query.get(UserUID=dashou_id)
dashou = dashou_user.dashou_profile
dashou = dashou_user.DashouProfile
except User.DoesNotExist:
return Response({
'code': 5,
@@ -2886,7 +2886,7 @@ class ShangjiaChufaShenqingView(APIView):
# 验证订单所属商家
shangjia_kuozhan = MerchantOrderExt.query.filter(
Order__OrderID=dingdan_id,
MerchantID=current_user.yonghuid
MerchantID=current_user.UserUID
).first()
if not shangjia_kuozhan:
@@ -2907,7 +2907,7 @@ class ShangjiaChufaShenqingView(APIView):
# 创建处罚记录
chufajilu = PenaltyRecord.query.create(
PlayerID=dashou_id,
ApplicantID=current_user.yonghuid,
ApplicantID=current_user.UserUID,
PenaltyReason=chufa_liyou,
ApplyStatus=0, # 待处理
DeductedPoints=5, # 扣除5积分
@@ -2930,7 +2930,7 @@ class ShangjiaChufaShenqingView(APIView):
if tupian_url and tupian_url.strip():
PenaltyEvidenceImage.query.create(
OrderID=dingdan_id,
UserID=current_user.yonghuid,
UserID=current_user.UserUID,
ImageURL=tupian_url
)
@@ -3031,8 +3031,8 @@ class DashouDingdanHuoquView(APIView):
if zhiding_ids:
dashou_query = User.query.filter(
UserUID__in=zhiding_ids
).select_related('dashou_profile').annotate(
Nickname=F('dashou_profile__nicheng')
).select_related('DashouProfile').annotate(
Nickname=F('DashouProfile__nicheng')
).values('UserUID', 'Avatar', 'Nickname')
zhiding_info = {
item['UserUID']: {
@@ -3418,7 +3418,7 @@ class DaiLiQunLiaoXiaoXiView(APIView):
return Response({'code': 400, 'msg': 'identityType 无效'})
# ===== 2. 构造 senderId =====
uid = request.user.yonghuid
uid = request.user.UserUID
prefix_map = {'PlayerID': 'Ds', 'shangjia': 'Sj', 'boss': 'Boss'}
sender_id = prefix_map[identity_type] + uid
logger.info(f"[群聊代理] 登录用户 UserID={uid}, 构造 senderId={sender_id}")
@@ -3557,26 +3557,26 @@ class QiangdanView(APIView):
# ==================== 【新增】罚单检查 ====================
fadan_ok, fadan_msg = check_fadan_qiangdan_eligible(request.user.yonghuid,1)
fadan_ok, fadan_msg = check_fadan_qiangdan_eligible(request.user.UserUID,1)
if not fadan_ok:
return Response({'code': 400, 'msg': fadan_msg})
# =========================================================
# ========== 标签快速校验(提前拒绝,避免锁资源) ==========
biaoqian_ok, biaoqian_msg = check_dashou_biaoqian_required(dingdan_id, request.user.yonghuid)
biaoqian_ok, biaoqian_msg = check_dashou_biaoqian_required(dingdan_id, request.user.UserUID)
if not biaoqian_ok:
return Response({'code': 400, 'msg': biaoqian_msg})
# ===========================================================
# 2. 锁定并验证订单(行锁)
order_result = self._validate_and_lock_order(dingdan_id, request.user.yonghuid)
order_result = self._validate_and_lock_order(dingdan_id, request.user.UserUID)
if isinstance(order_result, str):
return Response({'code': 400, 'msg': order_result})
order = order_result
validation_result = self._validate_order_requirements(order, dashou_profile, request.user.yonghuid)
validation_result = self._validate_order_requirements(order, dashou_profile, request.user.UserUID)
if not validation_result['success']:
return Response({'code': 400, 'msg': validation_result['message']})
self._execute_qiangdan(order, dashou_profile, request.user.yonghuid)
self._execute_qiangdan(order, dashou_profile, request.user.UserUID)
# ========== 【唯一改动】聊天建立方式 ==========
chat_success = establish_order_chat(dingdan_id)
@@ -3619,7 +3619,7 @@ class QiangdanView(APIView):
# ---------- 以下所有方法原封不动照抄旧版 ----------
def _validate_dashou_status(self, user):
try:
dashou_profile = user.dashou_profile
dashou_profile = user.DashouProfile
if (dashou_profile.zhuangtai != 1 or
dashou_profile.zhanghaozhuangtai != 1 or
dashou_profile.DeductedPoints < 5):
@@ -3695,7 +3695,7 @@ class DashouDingdanHuoquView1(APIView):
# 1. 获取当前登录用户的 yonghuid
try:
current_user = request.user
yonghuid = current_user.yonghuid
yonghuid = current_user.UserUID
except AttributeError:
return Response({
'code': 1,
@@ -3829,13 +3829,13 @@ class DashouCOSZhengshuView(APIView):
try:
chufa_record = PenaltyRecord.query.filter(
OrderID=dingdan_id,
PlayerID=request.user.yonghuid,
PlayerID=request.user.UserUID,
ApplyStatus__in=[0, 3]
).first()
if not chufa_record:
return Response(
{'code': 403, 'msg': '处罚记录无权限或状态不对',
'error': f'No punishment record found for user {request.user.yonghuid} on order {dingdan_id}'},
'error': f'No punishment record found for user {request.user.UserUID} on order {dingdan_id}'},
status=status.HTTP_403_FORBIDDEN
)
except Exception as e:
@@ -3852,12 +3852,12 @@ class DashouCOSZhengshuView(APIView):
try:
dingdan = Order.query.get(
OrderID=dingdan_id,
PlayerID=request.user.yonghuid,
PlayerID=request.user.UserUID,
Status__in=[2, 8]
)
except Order.DoesNotExist:
return Response(
{'code': 403, 'msg': '此功能暂未开放', 'error': f'Order {dingdan_id} not found or not assigned to user {request.user.yonghuid}'},
{'code': 403, 'msg': '此功能暂未开放', 'error': f'Order {dingdan_id} not found or not assigned to user {request.user.UserUID}'},
status=status.HTTP_403_FORBIDDEN
)
@@ -3968,7 +3968,7 @@ class ShangjiaCOSZhengshuView(APIView):
# 2. 🔴【修改】验证商家身份 - 通过反向查询shop_profile判断是否为商家
try:
# 检查是否有商家扩展表
shangjia_profile = request.user.shop_profile
shangjia_profile = request.user.ShopProfile
# 验证商家状态是否为1正常
if shangjia_profile.zhuangtai != 1:
@@ -3976,7 +3976,7 @@ class ShangjiaCOSZhengshuView(APIView):
status=status.HTTP_403_FORBIDDEN)
# 🔴【重要】获取商家ID从商家扩展表中获取
shangjia_id = request.user.yonghuid # 假设商家扩展表中有yonghuid字段
shangjia_id = request.user.UserUID # 假设商家扩展表中有yonghuid字段
except AttributeError:
# 没有shop_profile属性说明不是商家
@@ -4179,10 +4179,10 @@ class DashouTijiaoView(APIView):
# 3. 获取当前用户并验证打手身份
current_user = request.user
yonghuid = current_user.yonghuid
yonghuid = current_user.UserUID
try:
dashou_profile = current_user.dashou_profile
dashou_profile = current_user.DashouProfile
except UserDashou.DoesNotExist:
return Response({
'code': 6,
@@ -4271,10 +4271,10 @@ class DashouDingdanXiangqingView(APIView):
# 2. 获取当前用户并验证权限
current_user = request.user
yonghuid = current_user.yonghuid
yonghuid = current_user.UserUID
try:
dashou_profile = current_user.dashou_profile
dashou_profile = current_user.DashouProfile
except UserDashou.DoesNotExist:
return Response({
'code': 2,
@@ -4426,14 +4426,14 @@ class AdGetDingdanXiangQing(APIView):
dangqianyonghu = request.user
# 3. 验证手机号是否匹配
if not hasattr(dangqianyonghu, 'phone') or str(dangqianyonghu.phone) != qianzhanghao:
if not hasattr(dangqianyonghu, 'Phone') or str(dangqianyonghu.Phone) != qianzhanghao:
return Response(
{'code': 401, 'message': '身份验证失败', 'data': None},
status=status.HTTP_401_UNAUTHORIZED
)
# 4. 验证用户类型是否为管理员
if dangqianyonghu.user_type != 'admin':
if dangqianyonghu.UserType != 'admin':
return Response(
{'code': 401, 'message': '身份验证失败', 'data': None},
status=status.HTTP_401_UNAUTHORIZED
@@ -4441,7 +4441,7 @@ class AdGetDingdanXiangQing(APIView):
# 5. 验证管理员扩展表是否存在
try:
guanliyuan = dangqianyonghu.admin_profile
guanliyuan = dangqianyonghu.AdminProfile
except AttributeError:
return Response(
{'code': 401, 'message': '身份验证失败', 'data': None},
@@ -4633,14 +4633,14 @@ class AdGengHuanDaShou(APIView):
dangqianyonghu = request.user
# 3. 验证手机号是否匹配
if not hasattr(dangqianyonghu, 'phone') or str(dangqianyonghu.phone) != qianzhanghao:
if not hasattr(dangqianyonghu, 'Phone') or str(dangqianyonghu.Phone) != qianzhanghao:
return Response(
{'code': 401, 'message': '身份验证失败', 'data': None},
status=status.HTTP_401_UNAUTHORIZED
)
# 4. 验证用户类型是否为管理员
if dangqianyonghu.user_type != 'admin':
if dangqianyonghu.UserType != 'admin':
return Response(
{'code': 401, 'message': '身份验证失败', 'data': None},
status=status.HTTP_401_UNAUTHORIZED
@@ -4648,7 +4648,7 @@ class AdGengHuanDaShou(APIView):
# 5. 验证管理员扩展表是否存在
try:
guanliyuan = dangqianyonghu.admin_profile
guanliyuan = dangqianyonghu.AdminProfile
except AttributeError:
return Response(
{'code': 401, 'message': '身份验证失败', 'data': None},
@@ -4685,7 +4685,7 @@ class AdGengHuanDaShou(APIView):
# 9. 获取新打手扩展表
try:
new_dashou_profile = new_dashou_user.dashou_profile
new_dashou_profile = new_dashou_user.DashouProfile
except AttributeError:
return Response(
{'code': 404, 'message': '打手信息不完整', 'data': None},
@@ -4774,7 +4774,7 @@ class AdGengHuanDaShou(APIView):
)
# 获取原打手扩展表
old_dashou_profile = old_dashou_user.dashou_profile
old_dashou_profile = old_dashou_user.DashouProfile
# 更新原打手状态
old_dashou_profile.zhuangtai = 1 # 空闲
@@ -4852,14 +4852,14 @@ class AdQiangZhiJieDan(APIView):
dangqianyonghu = request.user
# 3. 验证手机号是否匹配
if not hasattr(dangqianyonghu, 'phone') or str(dangqianyonghu.phone) != qianzhanghao:
if not hasattr(dangqianyonghu, 'Phone') or str(dangqianyonghu.Phone) != qianzhanghao:
return Response(
{'code': 401, 'message': '身份验证失败', 'data': None},
status=status.HTTP_401_UNAUTHORIZED
)
# 4. 验证用户类型是否为管理员
if dangqianyonghu.user_type != 'admin':
if dangqianyonghu.UserType != 'admin':
return Response(
{'code': 401, 'message': '身份验证失败', 'data': None},
status=status.HTTP_401_UNAUTHORIZED
@@ -4867,7 +4867,7 @@ class AdQiangZhiJieDan(APIView):
# 5. 验证管理员扩展表是否存在
try:
guanliyuan = dangqianyonghu.admin_profile
guanliyuan = dangqianyonghu.AdminProfile
except AttributeError:
return Response(
{'code': 401, 'message': '身份验证失败', 'data': None},
@@ -4918,7 +4918,7 @@ class AdQiangZhiJieDan(APIView):
)
# 获取打手扩展表
dashou_profile = dashou_user.dashou_profile
dashou_profile = dashou_user.DashouProfile
# 更新打手扩展表数据
# ✅ 确认字段chengjiaozongliang 成交单总量
@@ -4961,7 +4961,7 @@ class AdQiangZhiJieDan(APIView):
)
# 获取商家扩展表
shangjia_profile = shangjia_user.shop_profile
shangjia_profile = shangjia_user.ShopProfile
# ✅ 确认字段chengjiao 商家成交订单总量
shangjia_profile.chengjiao += 1
@@ -5035,14 +5035,14 @@ class AdJuJueTuiKuan(APIView):
dangqianyonghu = request.user
# 3. 验证手机号是否匹配
if not hasattr(dangqianyonghu, 'phone') or str(dangqianyonghu.phone) != qianzhanghao:
if not hasattr(dangqianyonghu, 'Phone') or str(dangqianyonghu.Phone) != qianzhanghao:
return Response(
{'code': 401, 'message': '身份验证失败', 'data': None},
status=status.HTTP_401_UNAUTHORIZED
)
# 4. 验证用户类型是否为管理员
if dangqianyonghu.user_type != 'admin':
if dangqianyonghu.UserType != 'admin':
return Response(
{'code': 401, 'message': '身份验证失败', 'data': None},
status=status.HTTP_401_UNAUTHORIZED
@@ -5050,7 +5050,7 @@ class AdJuJueTuiKuan(APIView):
# 5. 验证管理员扩展表是否存在
try:
guanliyuan = dangqianyonghu.admin_profile
guanliyuan = dangqianyonghu.AdminProfile
except AttributeError:
return Response(
{'code': 401, 'message': '身份验证失败', 'data': None},
@@ -5094,7 +5094,7 @@ class AdJuJueTuiKuan(APIView):
)
# 获取打手扩展表
dashou_profile = dashou_user.dashou_profile
dashou_profile = dashou_user.DashouProfile
# 更新打手扩展表数据
# ✅ 确认字段chengjiaozongliang 成交单总量
@@ -5137,7 +5137,7 @@ class AdJuJueTuiKuan(APIView):
)
# 获取商家扩展表
shangjia_profile = shangjia_user.shop_profile
shangjia_profile = shangjia_user.ShopProfile
# ✅ 确认字段chengjiao 商家成交订单总量
shangjia_profile.chengjiao += 1
@@ -5236,14 +5236,14 @@ class AdTongYiTuiKuanShangJia(APIView):
dangqianyonghu = request.user
# 3. 验证手机号是否匹配
if not hasattr(dangqianyonghu, 'phone') or str(dangqianyonghu.phone) != qianzhanghao:
if not hasattr(dangqianyonghu, 'Phone') or str(dangqianyonghu.Phone) != qianzhanghao:
return Response(
{'code': 401, 'message': '身份验证失败', 'data': None},
status=status.HTTP_401_UNAUTHORIZED
)
# 4. 验证用户类型是否为管理员
if dangqianyonghu.user_type != 'admin':
if dangqianyonghu.UserType != 'admin':
return Response(
{'code': 401, 'message': '身份验证失败', 'data': None},
status=status.HTTP_401_UNAUTHORIZED
@@ -5251,7 +5251,7 @@ class AdTongYiTuiKuanShangJia(APIView):
# 5. 验证管理员扩展表是否存在
try:
guanliyuan = dangqianyonghu.admin_profile
guanliyuan = dangqianyonghu.AdminProfile
except AttributeError:
return Response(
{'code': 401, 'message': '身份验证失败', 'data': None},
@@ -5259,7 +5259,7 @@ class AdTongYiTuiKuanShangJia(APIView):
)
# 6. 验证支付密码对比openid
if pay_password != dangqianyonghu.openid:
if pay_password != dangqianyonghu.OpenID:
return Response(
{'code': 401, 'message': '支付密码错误', 'data': None},
status=status.HTTP_401_UNAUTHORIZED
@@ -5325,7 +5325,7 @@ class AdTongYiTuiKuanShangJia(APIView):
)
# 获取打手扩展表
dashou_profile = dashou_user.dashou_profile
dashou_profile = dashou_user.DashouProfile
# ✅ 确认字段tuikuanliang 退款订单总量
dashou_profile.tuikuanliang += 1
@@ -5350,7 +5350,7 @@ class AdTongYiTuiKuanShangJia(APIView):
)
# 获取商家扩展表
shangjia_profile = shangjia_user.shop_profile
shangjia_profile = shangjia_user.ShopProfile
# ✅ 确认字段tuikuan 退款订单总量
shangjia_profile.tuikuan += 1
@@ -5444,7 +5444,7 @@ class AdTongYiTuiKuanPingTai(APIView):
)
# 4. 验证用户类型是否为管理员
if dangqianyonghu.user_type != 'admin':
if dangqianyonghu.UserType != 'admin':
return Response(
{'code': 401, 'message': '身份验证失败', 'data': None},
status=status.HTTP_401_UNAUTHORIZED
@@ -5452,7 +5452,7 @@ class AdTongYiTuiKuanPingTai(APIView):
# 5. 验证管理员扩展表是否存在
try:
guanliyuan = dangqianyonghu.admin_profile
guanliyuan = dangqianyonghu.AdminProfile
except AttributeError:
return Response(
{'code': 401, 'message': '身份验证失败', 'data': None},
@@ -5460,7 +5460,7 @@ class AdTongYiTuiKuanPingTai(APIView):
)
# 6. 验证支付密码对比openid
if pay_password != dangqianyonghu.openid:
if pay_password != dangqianyonghu.OpenID:
return Response(
{'code': 401, 'message': '支付密码错误', 'data': None},
status=status.HTTP_401_UNAUTHORIZED
@@ -5530,7 +5530,7 @@ class AdTongYiTuiKuanPingTai(APIView):
if jiedan_dashou_id:
try:
dashou_user = User.query.get(UserUID=jiedan_dashou_id)
dashou_profile = dashou_user.dashou_profile
dashou_profile = dashou_user.DashouProfile
dashou_profile.zhuangtai = 1 # 打手状态设为空闲
dashou_profile.tuikuanliang += 1
dashou_profile.save()
@@ -5541,7 +5541,7 @@ class AdTongYiTuiKuanPingTai(APIView):
if laoban_id:
try:
laoban_user = User.query.get(UserUID=laoban_id)
laoban_profile = laoban_user.boss_profile
laoban_profile = laoban_user.BossProfile
laoban_profile.alltui += 1
laoban_profile.zonge -= jine
if laoban_profile.zonge < 0:
@@ -5738,7 +5738,7 @@ class DashouHuoquLeixingView(APIView):
3. 数据已排序paixu降序 → id升序
"""
try:
logger.info(f"打手获取商品类型请求 - 用户ID: {request.user.yonghuid}")
logger.info(f"打手获取商品类型请求 - 用户ID: {request.user.UserUID}")
# 🔴 查询所有正常状态的商品类型
# 条件shenhezhuangtai=1正常状态
@@ -5762,7 +5762,7 @@ class DashouHuoquLeixingView(APIView):
})
# 🔴 记录日志
logger.info(f"返回商品类型数据:{len(leixing_list)}条,用户: {request.user.yonghuid}")
logger.info(f"返回商品类型数据:{len(leixing_list)}条,用户: {request.user.UserUID}")
# 🔴 返回成功响应
# 注意:保持与前端原数据格式完全一致
@@ -5776,7 +5776,7 @@ class DashouHuoquLeixingView(APIView):
except Exception as e:
# 🔴 异常处理
logger.error(f"打手获取商品类型失败 - 用户ID: {request.user.yonghuid}, 错误: {str(e)}", exc_info=True)
logger.error(f"打手获取商品类型失败 - 用户ID: {request.user.UserUID}, 错误: {str(e)}", exc_info=True)
return Response({
"code": 500,
@@ -5821,14 +5821,14 @@ class AdJuJueJieSuan(APIView):
dangqianyonghu = request.user
# 3. 验证手机号匹配(管理员账号通常为手机号)
if str(dangqianyonghu.phone) != qianzhanghao:
if str(dangqianyonghu.Phone) != qianzhanghao:
return Response(
{'code': 401, 'message': '身份验证失败', 'data': None},
status=status.HTTP_401_UNAUTHORIZED
)
# 4. 验证用户类型为管理员
if dangqianyonghu.user_type != 'admin':
if dangqianyonghu.UserType != 'admin':
return Response(
{'code': 401, 'message': '身份验证失败', 'data': None},
status=status.HTTP_401_UNAUTHORIZED
@@ -5866,7 +5866,7 @@ class AdJuJueJieSuan(APIView):
# 8. 更新打手扩展表
try:
dashou_user = User.query.get(UserUID=jiedan_dashou_id)
dashou_profile = dashou_user.dashou_profile
dashou_profile = dashou_user.DashouProfile
dashou_profile.zhuangtai = 1 # 打手状态设为正常
dashou_profile.tuikuanliang += 1 # 退款订单总量+1
dashou_profile.save()
@@ -5909,13 +5909,13 @@ class AdZhuanYiDaTing(APIView):
dangqianyonghu = request.user
if str(dangqianyonghu.phone) != qianzhanghao:
if str(dangqianyonghu.Phone) != qianzhanghao:
return Response(
{'code': 401, 'message': '身份验证失败', 'data': None},
status=status.HTTP_401_UNAUTHORIZED
)
if dangqianyonghu.user_type != 'admin':
if dangqianyonghu.UserType != 'admin':
return Response(
{'code': 401, 'message': '身份验证失败', 'data': None},
status=status.HTTP_401_UNAUTHORIZED
@@ -5948,7 +5948,7 @@ class AdZhuanYiDaTing(APIView):
if jiedan_dashou_id:
try:
dashou_user = User.query.get(UserUID=jiedan_dashou_id)
dashou_profile = dashou_user.dashou_profile
dashou_profile = dashou_user.DashouProfile
dashou_profile.zhuangtai = 1
dashou_profile.tuikuanliang += 1
dashou_profile.save()
@@ -5991,13 +5991,13 @@ class AdQuXiaoZhiDing(APIView):
dangqianyonghu = request.user
if str(dangqianyonghu.phone) != qianzhanghao:
if str(dangqianyonghu.Phone) != qianzhanghao:
return Response(
{'code': 401, 'message': '身份验证失败', 'data': None},
status=status.HTTP_401_UNAUTHORIZED
)
if dangqianyonghu.user_type != 'admin':
if dangqianyonghu.UserType != 'admin':
return Response(
{'code': 401, 'message': '身份验证失败', 'data': None},
status=status.HTTP_401_UNAUTHORIZED
@@ -6078,11 +6078,11 @@ class DashouXiugaiView(APIView):
# ---------- 用户身份验证 ----------
current_user = request.user
yonghuid = current_user.yonghuid
yonghuid = current_user.UserUID
# 检查是否为打手
try:
dashou_profile = current_user.dashou_profile # 假设User模型related_name='dashou_profile'
dashou_profile = current_user.DashouProfile # User 模型反向 related_name='DashouProfile'
except UserDashou.DoesNotExist:
return Response({'code': 5, 'msg': '用户不是打手身份', 'data': None},
status=status.HTTP_403_FORBIDDEN)
@@ -6173,7 +6173,7 @@ class ZxsjghdsView(APIView):
# ========== 1. 获取当前商家用户 ==========
current_user = request.user
try:
yonghuid = current_user.yonghuid
yonghuid = current_user.UserUID
except AttributeError:
return Response({'code': 1, 'msg': '用户认证失败'}, status=status.HTTP_401_UNAUTHORIZED)
@@ -6226,7 +6226,7 @@ class ZxsjghdsView(APIView):
if dashou_id:
try:
dashou_user = User.query.get(UserUID=dashou_id)
dashou_profile = dashou_user.dashou_profile
dashou_profile = dashou_user.DashouProfile
dashou_profile.tuikuanliang = (dashou_profile.tuikuanliang or 0) + 1
dashou_profile.zhuangtai = 1 # 空闲
dashou_profile.save(update_fields=['tuikuanliang', 'zhuangtai'])
@@ -6371,7 +6371,7 @@ class ShangjiaFakuanApplyView(APIView):
# ========== 1. 身份验证 ==========
current_user = request.user
try:
shangjia_id = current_user.yonghuid # 商家的用户ID
shangjia_id = current_user.UserUID # 商家的用户ID
except AttributeError:
return Response({'code': 1, 'msg': '用户认证失败'}, status=status.HTTP_401_UNAUTHORIZED)
@@ -6439,7 +6439,7 @@ class ShangjiaFakuaiXiugaiView(APIView):
user = request.user
# 验证商家身份
try:
shangjia = user.shop_profile
shangjia = user.ShopProfile
except UserShangjia.DoesNotExist:
return Response({'code': 403, 'msg': '您不是商家'}, status=status.HTTP_403_FORBIDDEN)
if shangjia.zhuangtai != 1:
@@ -6455,7 +6455,7 @@ class ShangjiaFakuaiXiugaiView(APIView):
dingdan = Order.query.select_related('shangjia_kuozhan').get(OrderID=dingdan_id)
except Order.DoesNotExist:
return Response({'code': 404, 'msg': '订单不存在'}, status=status.HTTP_404_NOT_FOUND)
if not hasattr(dingdan, 'shangjia_kuozhan') or dingdan.shangjia_kuozhan.MerchantID != user.yonghuid:
if not hasattr(dingdan, 'shangjia_kuozhan') or dingdan.shangjia_kuozhan.MerchantID != user.UserUID:
return Response({'code': 403, 'msg': '无权操作此订单'}, status=status.HTTP_403_FORBIDDEN)
# 处理订单相关操作