修复了已知的生产环境问题

This commit is contained in:
2026-06-17 21:25:45 +08:00
parent d00f0d08e5
commit 4aca437d2b
25 changed files with 13547 additions and 13423 deletions

View File

@@ -1,166 +1,166 @@
# yonghu/fadan_fenhong_utils.py
# 罚款缴纳分红处理公共方法(支持更新罚单中的申请人分红金额)
import logging
from decimal import Decimal
from django.db import transaction
from orders.models import Fadan, FadanFenhong, FadanFenhongLilv
from users.models import UserShangjia
logger = logging.getLogger(__name__)
# 身份映射字典
IDENTITY_MAP = {
1: {'fenhong': 2, 'lilv': 1}, # 客服
2: {'fenhong': 5, 'lilv': 2}, # 售后
3: {'fenhong': 3, 'lilv': 3}, # 管理员
4: {'fenhong': 4, 'lilv': 4}, # 店铺
5: {'fenhong': 1, 'lilv': 5}, # 商家
}
def process_fadan_fenhong(fadan_id):
"""
罚款缴纳后的分红处理(在回调中调用)
参数:
fadan_id: 罚单 ID
返回:
(success, message)
"""
try:
# 1. 获取罚单对象(必须是已缴纳状态)
try:
fadan = Fadan.objects.get(id=fadan_id, zhuangtai=2)
except Fadan.DoesNotExist:
logger.error(f"罚单 {fadan_id} 不存在或状态不是已缴纳")
return False, "罚单不存在或状态异常"
# 2. 获取申请处罚者ID和身份源身份数字
shenqing_chufa = fadan.shenqing_chufa
src_shenfen = fadan.shenqingren_shenfen
if not shenqing_chufa:
logger.info(f"罚单 {fadan_id} 无申请处罚者,不进行分红")
# 即使无申请者也可将分红金额字段设为0默认已是0
return True, "无申请处罚者,无需分红"
# 3. 映射身份数字
if src_shenfen not in IDENTITY_MAP:
logger.error(f"未知的申请处罚者身份: {src_shenfen},罚单 {fadan_id}")
return False, f"未知身份 {src_shenfen}"
mapped = IDENTITY_MAP[src_shenfen]
fenhong_shenfen = mapped['fenhong'] # 用于 FadanFenhong.shenfen
lilv_shenfen = mapped['lilv'] # 用于 FadanFenhongLilv.shenfen
# 4. 获取罚款金额
fakuan_jine = fadan.fakuanjine
if fakuan_jine <= 0:
logger.info(f"罚单 {fadan_id} 罚款金额为0不产生分红")
fadan.shenqingren_fenhong_jine = Decimal('0.00')
fadan.save(update_fields=['shenqingren_fenhong_jine'])
return True, "罚款金额为0无分红"
# 5. 确定分红利率
rate = _get_fenhong_rate(shenqing_chufa, fenhong_shenfen, lilv_shenfen)
if rate is None:
logger.warning(f"未找到身份 {src_shenfen} (映射后 fenhong_shenfen={fenhong_shenfen}, lilv_shenfen={lilv_shenfen}) 的分红利率,罚单 {fadan_id} 不进行分红")
fadan.shenqingren_fenhong_jine = Decimal('0.00')
fadan.save(update_fields=['shenqingren_fenhong_jine'])
return True, "未配置分红利率,无分红"
# 6. 计算分红金额
fenhong_jine = (Decimal(str(fakuan_jine)) * Decimal(str(rate))).quantize(Decimal('0.01'))
if fenhong_jine <= 0:
logger.info(f"罚单 {fadan_id} 计算分红金额为0无需处理")
fadan.shenqingren_fenhong_jine = Decimal('0.00')
fadan.save(update_fields=['shenqingren_fenhong_jine'])
return True, "分红金额为0"
# 7. 根据申请处罚者身份执行不同的分红逻辑
# src_shenfen == 5 代表商家(源身份)
if src_shenfen == 5:
# 商家特殊处理只记录总额可提现分红永远为0直接加到商家余额
with transaction.atomic():
fenhong_record, created = FadanFenhong.objects.get_or_create(
fenhongzhe_id=shenqing_chufa,
shenfen=fenhong_shenfen,
defaults={
'zonge': Decimal('0.00'),
'ketixian_fenhong': Decimal('0.00'),
'fenhong_cishu': 0,
'yingde_lilv': rate,
'is_individual_rate': False
}
)
fenhong_record.zonge += fenhong_jine
# 可提现分红不累加保持0
fenhong_record.fenhong_cishu += 1
fenhong_record.save()
# 直接增加商家余额UserShangjia.yue
try:
shangjia = UserShangjia.objects.get(user__yonghuid=shenqing_chufa)
shangjia.yue += fenhong_jine
shangjia.save(update_fields=['yue'])
logger.info(f"商家 {shenqing_chufa} 余额增加 {fenhong_jine}")
except UserShangjia.DoesNotExist:
logger.error(f"商家 {shenqing_chufa} 扩展表不存在,无法增加余额")
raise Exception(f"商家 {shenqing_chufa} 扩展表不存在,无法增加余额")
# 更新罚单中的申请人分红金额
fadan.shenqingren_fenhong_jine = fenhong_jine
fadan.save(update_fields=['shenqingren_fenhong_jine'])
else:
# 其他身份(客服、售后、管理员、店铺):同时增加总额和可提现分红
with transaction.atomic():
fenhong_record, created = FadanFenhong.objects.get_or_create(
fenhongzhe_id=shenqing_chufa,
shenfen=fenhong_shenfen,
defaults={
'zonge': Decimal('0.00'),
'ketixian_fenhong': Decimal('0.00'),
'fenhong_cishu': 0,
'yingde_lilv': rate,
'is_individual_rate': False
}
)
fenhong_record.zonge += fenhong_jine
fenhong_record.ketixian_fenhong += fenhong_jine
fenhong_record.fenhong_cishu += 1
fenhong_record.save()
# 更新罚单中的申请人分红金额
fadan.shenqingren_fenhong_jine = fenhong_jine
fadan.save(update_fields=['shenqingren_fenhong_jine'])
logger.info(f"罚单 {fadan_id} 分红处理成功: 申请者 {shenqing_chufa}, 分红金额 {fenhong_jine} 元, 源身份 {src_shenfen}, 映射后分红身份 {fenhong_shenfen}")
return True, "分红处理成功"
except Exception as e:
logger.error(f"罚单 {fadan_id} 分红处理异常: {str(e)}", exc_info=True)
return False, f"分红处理异常: {str(e)}"
def _get_fenhong_rate(fenhongzhe_id, fenhong_shenfen, lilv_shenfen):
"""
获取分红利率(优先使用个人单独配置,否则使用全局身份配置)
"""
try:
individual = FadanFenhong.objects.get(
fenhongzhe_id=fenhongzhe_id,
shenfen=fenhong_shenfen,
is_individual_rate=True
)
return individual.yingde_lilv
except FadanFenhong.DoesNotExist:
pass
try:
global_rate = FadanFenhongLilv.objects.get(shenfen=lilv_shenfen)
return global_rate.lilv
except FadanFenhongLilv.DoesNotExist:
# yonghu/fadan_fenhong_utils.py
# 罚款缴纳分红处理公共方法(支持更新罚单中的申请人分红金额)
import logging
from decimal import Decimal
from django.db import transaction
from orders.models import Fadan, FadanFenhong, FadanFenhongLilv
from users.models import UserShangjia
logger = logging.getLogger(__name__)
# 身份映射字典
IDENTITY_MAP = {
1: {'fenhong': 2, 'lilv': 1}, # 客服
2: {'fenhong': 5, 'lilv': 2}, # 售后
3: {'fenhong': 3, 'lilv': 3}, # 管理员
4: {'fenhong': 4, 'lilv': 4}, # 店铺
5: {'fenhong': 1, 'lilv': 5}, # 商家
}
def process_fadan_fenhong(fadan_id):
"""
罚款缴纳后的分红处理(在回调中调用)
参数:
fadan_id: 罚单 ID
返回:
(success, message)
"""
try:
# 1. 获取罚单对象(必须是已缴纳状态)
try:
fadan = Fadan.objects.get(id=fadan_id, zhuangtai=2)
except Fadan.DoesNotExist:
logger.error(f"罚单 {fadan_id} 不存在或状态不是已缴纳")
return False, "罚单不存在或状态异常"
# 2. 获取申请处罚者ID和身份源身份数字
shenqing_chufa = fadan.shenqing_chufa
src_shenfen = fadan.shenqingren_shenfen
if not shenqing_chufa:
logger.info(f"罚单 {fadan_id} 无申请处罚者,不进行分红")
# 即使无申请者也可将分红金额字段设为0默认已是0
return True, "无申请处罚者,无需分红"
# 3. 映射身份数字
if src_shenfen not in IDENTITY_MAP:
logger.error(f"未知的申请处罚者身份: {src_shenfen},罚单 {fadan_id}")
return False, f"未知身份 {src_shenfen}"
mapped = IDENTITY_MAP[src_shenfen]
fenhong_shenfen = mapped['fenhong'] # 用于 FadanFenhong.shenfen
lilv_shenfen = mapped['lilv'] # 用于 FadanFenhongLilv.shenfen
# 4. 获取罚款金额
fakuan_jine = fadan.fakuanjine
if fakuan_jine <= 0:
logger.info(f"罚单 {fadan_id} 罚款金额为0不产生分红")
fadan.shenqingren_fenhong_jine = Decimal('0.00')
fadan.save(update_fields=['shenqingren_fenhong_jine'])
return True, "罚款金额为0无分红"
# 5. 确定分红利率
rate = _get_fenhong_rate(shenqing_chufa, fenhong_shenfen, lilv_shenfen)
if rate is None:
logger.warning(f"未找到身份 {src_shenfen} (映射后 fenhong_shenfen={fenhong_shenfen}, lilv_shenfen={lilv_shenfen}) 的分红利率,罚单 {fadan_id} 不进行分红")
fadan.shenqingren_fenhong_jine = Decimal('0.00')
fadan.save(update_fields=['shenqingren_fenhong_jine'])
return True, "未配置分红利率,无分红"
# 6. 计算分红金额
fenhong_jine = (Decimal(str(fakuan_jine)) * Decimal(str(rate))).quantize(Decimal('0.01'))
if fenhong_jine <= 0:
logger.info(f"罚单 {fadan_id} 计算分红金额为0无需处理")
fadan.shenqingren_fenhong_jine = Decimal('0.00')
fadan.save(update_fields=['shenqingren_fenhong_jine'])
return True, "分红金额为0"
# 7. 根据申请处罚者身份执行不同的分红逻辑
# src_shenfen == 5 代表商家(源身份)
if src_shenfen == 5:
# 商家特殊处理只记录总额可提现分红永远为0直接加到商家余额
with transaction.atomic():
fenhong_record, created = FadanFenhong.objects.get_or_create(
fenhongzhe_id=shenqing_chufa,
shenfen=fenhong_shenfen,
defaults={
'zonge': Decimal('0.00'),
'ketixian_fenhong': Decimal('0.00'),
'fenhong_cishu': 0,
'yingde_lilv': rate,
'is_individual_rate': False
}
)
fenhong_record.zonge += fenhong_jine
# 可提现分红不累加保持0
fenhong_record.fenhong_cishu += 1
fenhong_record.save()
# 直接增加商家余额UserShangjia.yue
try:
shangjia = UserShangjia.objects.get(user__UserUID=shenqing_chufa)
shangjia.yue += fenhong_jine
shangjia.save(update_fields=['yue'])
logger.info(f"商家 {shenqing_chufa} 余额增加 {fenhong_jine}")
except UserShangjia.DoesNotExist:
logger.error(f"商家 {shenqing_chufa} 扩展表不存在,无法增加余额")
raise Exception(f"商家 {shenqing_chufa} 扩展表不存在,无法增加余额")
# 更新罚单中的申请人分红金额
fadan.shenqingren_fenhong_jine = fenhong_jine
fadan.save(update_fields=['shenqingren_fenhong_jine'])
else:
# 其他身份(客服、售后、管理员、店铺):同时增加总额和可提现分红
with transaction.atomic():
fenhong_record, created = FadanFenhong.objects.get_or_create(
fenhongzhe_id=shenqing_chufa,
shenfen=fenhong_shenfen,
defaults={
'zonge': Decimal('0.00'),
'ketixian_fenhong': Decimal('0.00'),
'fenhong_cishu': 0,
'yingde_lilv': rate,
'is_individual_rate': False
}
)
fenhong_record.zonge += fenhong_jine
fenhong_record.ketixian_fenhong += fenhong_jine
fenhong_record.fenhong_cishu += 1
fenhong_record.save()
# 更新罚单中的申请人分红金额
fadan.shenqingren_fenhong_jine = fenhong_jine
fadan.save(update_fields=['shenqingren_fenhong_jine'])
logger.info(f"罚单 {fadan_id} 分红处理成功: 申请者 {shenqing_chufa}, 分红金额 {fenhong_jine} 元, 源身份 {src_shenfen}, 映射后分红身份 {fenhong_shenfen}")
return True, "分红处理成功"
except Exception as e:
logger.error(f"罚单 {fadan_id} 分红处理异常: {str(e)}", exc_info=True)
return False, f"分红处理异常: {str(e)}"
def _get_fenhong_rate(fenhongzhe_id, fenhong_shenfen, lilv_shenfen):
"""
获取分红利率(优先使用个人单独配置,否则使用全局身份配置)
"""
try:
individual = FadanFenhong.objects.get(
fenhongzhe_id=fenhongzhe_id,
shenfen=fenhong_shenfen,
is_individual_rate=True
)
return individual.yingde_lilv
except FadanFenhong.DoesNotExist:
pass
try:
global_rate = FadanFenhongLilv.objects.get(shenfen=lilv_shenfen)
return global_rate.lilv
except FadanFenhongLilv.DoesNotExist:
return None

View File

@@ -1,218 +1,218 @@
"""
排行榜接口 — 基于 houtai 日统计表聚合查询
POST /yonghu/phbhqsj
"""
import logging
from datetime import date, timedelta
from decimal import Decimal
from django.db.models import Sum
from rest_framework.permissions import IsAuthenticated
from rest_framework.response import Response
from rest_framework.views import APIView
from backend.models import (
DashouRiTongji,
GuanshiRiTongji,
ZuzhangRiTongji,
ShangjiaRiTongji,
)
from users.models import UserDashou, UserShangjia, UserBoss
from gvsdsdk.models import User
logger = logging.getLogger(__name__)
MAX_RANK = 50
RIQI_OPTIONS = frozenset({'今日', '本周', '本月', '总榜', '昨日', '上周', '上月'})
SHENFEN_OPTIONS = frozenset({'dashou', 'guanshi', 'zuzhang', 'shangjia'})
ROLE_CONFIG = {
'dashou': {
'model': DashouRiTongji,
'sort_field': 'chengjiao_zonge',
'fields': ('jiedan_zongliang', 'chengjiao_zongliang', 'jiedan_zonge', 'chengjiao_zonge'),
'int_fields': frozenset({'jiedan_zongliang', 'chengjiao_zongliang'}),
},
'guanshi': {
'model': GuanshiRiTongji,
'sort_field': 'shouru_zonge',
'fields': ('yaoqing_dashou_shu', 'chongzhi_dashou_shu', 'shouru_zonge'),
'int_fields': frozenset({'yaoqing_dashou_shu', 'chongzhi_dashou_shu'}),
},
'zuzhang': {
'model': ZuzhangRiTongji,
'sort_field': 'shouru_zonge',
'fields': ('yaoqing_guanshi_shu', 'fenyong_jine', 'shouru_zonge'),
'int_fields': frozenset({'yaoqing_guanshi_shu'}),
},
'shangjia': {
'model': ShangjiaRiTongji,
'sort_field': 'jiesuan_jine',
'fields': ('paifa_dingdan_shu', 'paifa_jine', 'jiesuan_dingdan_shu', 'jiesuan_jine'),
'int_fields': frozenset({'paifa_dingdan_shu', 'jiesuan_dingdan_shu'}),
},
}
def _resolve_date_range(riqi: str):
"""根据前端 riqi 参数返回 (start_date, end_date) 闭区间。"""
today = date.today()
if riqi == '今日':
return today, today
if riqi == '昨日':
d = today - timedelta(days=1)
return d, d
if riqi == '本周':
monday = today - timedelta(days=today.weekday())
return monday, today
if riqi == '上周':
this_monday = today - timedelta(days=today.weekday())
last_sunday = this_monday - timedelta(days=1)
last_monday = last_sunday - timedelta(days=6)
return last_monday, last_sunday
if riqi == '本月':
return today.replace(day=1), today
if riqi == '上月':
first_this_month = today.replace(day=1)
last_day_prev = first_this_month - timedelta(days=1)
return last_day_prev.replace(day=1), last_day_prev
return None
def _fmt_value(val, is_int: bool):
if val is None:
return 0 if is_int else 0.0
if is_int:
return int(val)
if isinstance(val, Decimal):
return float(val.quantize(Decimal('0.01')))
return float(val)
class PhbHqsjView(APIView):
"""
排行榜数据接口
POST /yonghu/phbhqsj
请求参数:
shenfen: dashou | guanshi | zuzhang | shangjia
riqi: 今日 | 本周 | 本月 | 总榜 | 昨日 | 上周 | 上月
响应 data.list[]最多50条已按各身份排序字段降序:
mingci, yonghuid, nicheng, touxiang + 各身份统计字段
"""
permission_classes = [IsAuthenticated]
def post(self, request):
shenfen = (request.data.get('shenfen') or '').strip()
riqi = (request.data.get('riqi') or '').strip()
if shenfen not in SHENFEN_OPTIONS:
return Response({
'code': 400,
'msg': '参数错误shenfen 必须为 dashou/guanshi/zuzhang/shangjia',
'data': {'list': []},
})
if riqi not in RIQI_OPTIONS:
return Response({
'code': 400,
'msg': '参数错误riqi 必须为 今日/本周/本月/总榜/昨日/上周/上月',
'data': {'list': []},
})
try:
if riqi == '总榜':
rows = self._query_rank_rows(shenfen, all_time=True)
else:
date_range = _resolve_date_range(riqi)
if date_range is None:
return Response({
'code': 400,
'msg': '参数错误:无效的日期范围',
'data': {'list': []},
})
rows = self._query_rank_rows(shenfen, date_range[0], date_range[1])
nick_map, avatar_map = self._load_user_display(rows, shenfen)
cfg = ROLE_CONFIG[shenfen]
int_fields = cfg['int_fields']
result_list = []
for idx, row in enumerate(rows):
yonghuid = row['yonghuid']
item = {
'mingci': idx + 1,
'yonghuid': yonghuid,
'nicheng': nick_map.get(yonghuid, '用户'),
'touxiang': avatar_map.get(yonghuid, '') or '',
}
for field in cfg['fields']:
item[field] = _fmt_value(row.get(field), field in int_fields)
result_list.append(item)
return Response({
'code': 200,
'msg': '获取成功',
'data': {'list': result_list},
})
except Exception as e:
logger.error('排行榜查询失败 shenfen=%s riqi=%s: %s', shenfen, riqi, e, exc_info=True)
return Response({
'code': 500,
'msg': '服务器内部错误',
'data': {'list': []},
})
def _query_rank_rows(self, shenfen, start_date=None, end_date=None, all_time=False):
cfg = ROLE_CONFIG[shenfen]
model = cfg['model']
sort_field = cfg['sort_field']
fields = cfg['fields']
annotate_kwargs = {f: Sum(f) for f in fields}
if all_time:
rows = (
model.objects
.values('yonghuid')
.annotate(**annotate_kwargs)
.order_by(f'-{sort_field}')[:MAX_RANK]
)
return list(rows)
if start_date == end_date:
qs = model.objects.filter(riqi=start_date).order_by(f'-{sort_field}')[:MAX_RANK]
return [
{'yonghuid': r.yonghuid, **{f: getattr(r, f) for f in fields}}
for r in qs
]
rows = (
model.objects
.filter(riqi__gte=start_date, riqi__lte=end_date)
.values('yonghuid')
.annotate(**annotate_kwargs)
.order_by(f'-{sort_field}')[:MAX_RANK]
)
return list(rows)
def _load_user_display(self, rows, shenfen):
yonghuids = [r['yonghuid'] for r in rows if r.get('yonghuid')]
if not yonghuids:
return {}, {}
users = User.objects.filter(yonghuid__in=yonghuids)
avatar_map = {u.yonghuid: u.avatar or '' for u in users}
nick_map = {}
if shenfen == 'dashou':
for p in UserDashou.objects.filter(user__yonghuid__in=yonghuids).select_related('user'):
nick_map[p.user.yonghuid] = p.nicheng or '用户'
elif shenfen == 'shangjia':
for p in UserShangjia.objects.filter(user__yonghuid__in=yonghuids).select_related('user'):
nick_map[p.user.yonghuid] = p.nicheng or '用户'
else:
for b in UserBoss.objects.filter(user__yonghuid__in=yonghuids).select_related('user'):
nick_map[b.user.yonghuid] = b.nickname or '用户'
return nick_map, avatar_map
"""
排行榜接口 — 基于 houtai 日统计表聚合查询
POST /yonghu/phbhqsj
"""
import logging
from datetime import date, timedelta
from decimal import Decimal
from django.db.models import Sum
from rest_framework.permissions import IsAuthenticated
from rest_framework.response import Response
from rest_framework.views import APIView
from backend.models import (
DashouRiTongji,
GuanshiRiTongji,
ZuzhangRiTongji,
ShangjiaRiTongji,
)
from users.models import UserDashou, UserShangjia, UserBoss
from gvsdsdk.models import User
logger = logging.getLogger(__name__)
MAX_RANK = 50
RIQI_OPTIONS = frozenset({'今日', '本周', '本月', '总榜', '昨日', '上周', '上月'})
SHENFEN_OPTIONS = frozenset({'dashou', 'guanshi', 'zuzhang', 'shangjia'})
ROLE_CONFIG = {
'dashou': {
'model': DashouRiTongji,
'sort_field': 'chengjiao_zonge',
'fields': ('jiedan_zongliang', 'chengjiao_zongliang', 'jiedan_zonge', 'chengjiao_zonge'),
'int_fields': frozenset({'jiedan_zongliang', 'chengjiao_zongliang'}),
},
'guanshi': {
'model': GuanshiRiTongji,
'sort_field': 'shouru_zonge',
'fields': ('yaoqing_dashou_shu', 'chongzhi_dashou_shu', 'shouru_zonge'),
'int_fields': frozenset({'yaoqing_dashou_shu', 'chongzhi_dashou_shu'}),
},
'zuzhang': {
'model': ZuzhangRiTongji,
'sort_field': 'shouru_zonge',
'fields': ('yaoqing_guanshi_shu', 'fenyong_jine', 'shouru_zonge'),
'int_fields': frozenset({'yaoqing_guanshi_shu'}),
},
'shangjia': {
'model': ShangjiaRiTongji,
'sort_field': 'jiesuan_jine',
'fields': ('paifa_dingdan_shu', 'paifa_jine', 'jiesuan_dingdan_shu', 'jiesuan_jine'),
'int_fields': frozenset({'paifa_dingdan_shu', 'jiesuan_dingdan_shu'}),
},
}
def _resolve_date_range(riqi: str):
"""根据前端 riqi 参数返回 (start_date, end_date) 闭区间。"""
today = date.today()
if riqi == '今日':
return today, today
if riqi == '昨日':
d = today - timedelta(days=1)
return d, d
if riqi == '本周':
monday = today - timedelta(days=today.weekday())
return monday, today
if riqi == '上周':
this_monday = today - timedelta(days=today.weekday())
last_sunday = this_monday - timedelta(days=1)
last_monday = last_sunday - timedelta(days=6)
return last_monday, last_sunday
if riqi == '本月':
return today.replace(day=1), today
if riqi == '上月':
first_this_month = today.replace(day=1)
last_day_prev = first_this_month - timedelta(days=1)
return last_day_prev.replace(day=1), last_day_prev
return None
def _fmt_value(val, is_int: bool):
if val is None:
return 0 if is_int else 0.0
if is_int:
return int(val)
if isinstance(val, Decimal):
return float(val.quantize(Decimal('0.01')))
return float(val)
class PhbHqsjView(APIView):
"""
排行榜数据接口
POST /yonghu/phbhqsj
请求参数:
shenfen: dashou | guanshi | zuzhang | shangjia
riqi: 今日 | 本周 | 本月 | 总榜 | 昨日 | 上周 | 上月
响应 data.list[]最多50条已按各身份排序字段降序:
mingci, yonghuid, nicheng, touxiang + 各身份统计字段
"""
permission_classes = [IsAuthenticated]
def post(self, request):
shenfen = (request.data.get('shenfen') or '').strip()
riqi = (request.data.get('riqi') or '').strip()
if shenfen not in SHENFEN_OPTIONS:
return Response({
'code': 400,
'msg': '参数错误shenfen 必须为 dashou/guanshi/zuzhang/shangjia',
'data': {'list': []},
})
if riqi not in RIQI_OPTIONS:
return Response({
'code': 400,
'msg': '参数错误riqi 必须为 今日/本周/本月/总榜/昨日/上周/上月',
'data': {'list': []},
})
try:
if riqi == '总榜':
rows = self._query_rank_rows(shenfen, all_time=True)
else:
date_range = _resolve_date_range(riqi)
if date_range is None:
return Response({
'code': 400,
'msg': '参数错误:无效的日期范围',
'data': {'list': []},
})
rows = self._query_rank_rows(shenfen, date_range[0], date_range[1])
nick_map, avatar_map = self._load_user_display(rows, shenfen)
cfg = ROLE_CONFIG[shenfen]
int_fields = cfg['int_fields']
result_list = []
for idx, row in enumerate(rows):
yonghuid = row['yonghuid']
item = {
'mingci': idx + 1,
'yonghuid': yonghuid,
'nicheng': nick_map.get(yonghuid, '用户'),
'touxiang': avatar_map.get(yonghuid, '') or '',
}
for field in cfg['fields']:
item[field] = _fmt_value(row.get(field), field in int_fields)
result_list.append(item)
return Response({
'code': 200,
'msg': '获取成功',
'data': {'list': result_list},
})
except Exception as e:
logger.error('排行榜查询失败 shenfen=%s riqi=%s: %s', shenfen, riqi, e, exc_info=True)
return Response({
'code': 500,
'msg': '服务器内部错误',
'data': {'list': []},
})
def _query_rank_rows(self, shenfen, start_date=None, end_date=None, all_time=False):
cfg = ROLE_CONFIG[shenfen]
model = cfg['model']
sort_field = cfg['sort_field']
fields = cfg['fields']
annotate_kwargs = {f: Sum(f) for f in fields}
if all_time:
rows = (
model.objects
.values('yonghuid')
.annotate(**annotate_kwargs)
.order_by(f'-{sort_field}')[:MAX_RANK]
)
return list(rows)
if start_date == end_date:
qs = model.objects.filter(riqi=start_date).order_by(f'-{sort_field}')[:MAX_RANK]
return [
{'yonghuid': r.yonghuid, **{f: getattr(r, f) for f in fields}}
for r in qs
]
rows = (
model.objects
.filter(riqi__gte=start_date, riqi__lte=end_date)
.values('yonghuid')
.annotate(**annotate_kwargs)
.order_by(f'-{sort_field}')[:MAX_RANK]
)
return list(rows)
def _load_user_display(self, rows, shenfen):
yonghuids = [r['yonghuid'] for r in rows if r.get('yonghuid')]
if not yonghuids:
return {}, {}
users = User.objects.filter(UserUID__in=yonghuids)
avatar_map = {u.yonghuid: u.avatar or '' for u in users}
nick_map = {}
if shenfen == 'dashou':
for p in UserDashou.objects.filter(user__UserUID__in=yonghuids).select_related('user'):
nick_map[p.user.yonghuid] = p.nicheng or '用户'
elif shenfen == 'shangjia':
for p in UserShangjia.objects.filter(user__UserUID__in=yonghuids).select_related('user'):
nick_map[p.user.yonghuid] = p.nicheng or '用户'
else:
for b in UserBoss.objects.filter(user__UserUID__in=yonghuids).select_related('user'):
nick_map[b.user.yonghuid] = b.nickname or '用户'
return nick_map, avatar_map

File diff suppressed because it is too large Load Diff

View File

@@ -39,8 +39,8 @@ from rest_framework.throttling import AnonRateThrottle
from rest_framework_simplejwt.tokens import RefreshToken
from rest_framework_simplejwt.authentication import JWTAuthentication
from gvsdsdk.fluent import db, func, FQ
from gvsdsdk.fluent import db, func, FQ
from utils.oss_utils import validate_image, upload_to_oss, delete_from_oss
from utils.fadan_utils import check_fadan_qiangdan_eligible
from utils.wechat_v3 import verify_wechat_sign, decrypt_callback_ciphertext
@@ -343,7 +343,7 @@ class WechatMiniProgramLoginView(APIView):
user_id = timestamp_part + random_part
if len(user_id) == 7 and user_id.isdigit():
if not User.query.filter(yonghuid=user_id).exists():
if not User.query.filter(UserUID=user_id).exists():
return user_id
raise Exception('生成用户ID失败')
@@ -827,7 +827,7 @@ class HuoQuYaoQingRenView(APIView):
# 3. 查询邀请人主表(头像)
try:
inviter_main = User.query.get(yonghuid=yaoqingren_id)
inviter_main = User.query.get(UserUID=yaoqingren_id)
touxiang = inviter_main.avatar or ''
except User.DoesNotExist:
return Response({
@@ -1081,7 +1081,7 @@ class ShangJiaXinXiView(APIView):
# ------------------- 3. 从 ShangjiaRiTongji 获取今日统计 -------------------
try:
today_stat = ShangjiaRiTongji.query.get(yonghuid=yonghuid, riqi=today)
today_stat = ShangjiaRiTongji.query.get(UserUID=yonghuid, riqi=today)
jinri_paifa_dingdan = today_stat.paifa_dingdan_shu
jinri_paifa_jine = float(today_stat.paifa_jine)
jinri_tuikuan_dingdan = today_stat.tuikuan_dingdan_shu
@@ -1096,7 +1096,7 @@ class ShangJiaXinXiView(APIView):
# ------------------- 4. 从 ShangjiaRiTongji 获取本月统计 -------------------
month_stats = ShangjiaRiTongji.query.filter(
yonghuid=yonghuid,
UserUID=yonghuid,
riqi__gte=this_month_start,
riqi__lte=today
).aggregate(
@@ -2161,7 +2161,7 @@ class TixianJiluHuoquViewV2(APIView):
limit = 100
offset = (page - 1) * limit
qs = Tixianjilu.query.filter(yonghuid=yonghuid)
qs = Tixianjilu.query.filter(UserUID=yonghuid)
if mode == 2:
# 自动提现含新审核关联记录zhuangtai>0 时按状态筛选
if zhuangtai_filter > 0:
@@ -3668,7 +3668,7 @@ class AdTongYiChuFa(APIView):
# 11.2 查询打手扩展表(只是验证存在性)
try:
dashou = UserDashou.query.get(user__yonghuid=chufajilu.dashouid)
dashou = UserDashou.query.get(user__UserUID=chufajilu.dashouid)
except UserDashou.DoesNotExist:
return Response(
{'code': 404, 'message': '被处罚打手不存在', 'data': None},
@@ -3698,7 +3698,7 @@ class AdTongYiChuFa(APIView):
# 🔴【新增】11.5 返还打手积分加5分
if chufajilu.jifen > 0:
try:
dashou = UserDashou.query.get(user__yonghuid=chufajilu.dashouid)
dashou = UserDashou.query.get(user__UserUID=chufajilu.dashouid)
# 🔴【新增】安全验证必须积分小于等于5分才允许加分
if dashou.jifen <= 5: # 判断积分是否小于等于5分
@@ -3827,7 +3827,7 @@ class AdckyhxqView(APIView):
}, status=status.HTTP_400_BAD_REQUEST)
# 查询用户主表 - 使用select_related优化查询
user_main = User.query.filter(yonghuid=uid).first()
user_main = User.query.filter(UserUID=uid).first()
if not user_main:
return Response({
'code': 404,
@@ -3856,7 +3856,7 @@ class AdckyhxqView(APIView):
# 根据用户类型查询扩展信息
if user_type == 1: # 老板
# 使用select_related预取boss_profile
user_main = User.query.filter(yonghuid=uid).select_related('boss_profile').first()
user_main = User.query.filter(UserUID=uid).select_related('boss_profile').first()
if user_main.boss_profile:
boss_profile = user_main.boss_profile
user_info.update({
@@ -3869,7 +3869,7 @@ class AdckyhxqView(APIView):
elif user_type == 2: # 打手
# 使用select_related预取dashou_profile
user_main = User.query.filter(yonghuid=uid).select_related('dashou_profile').first()
user_main = User.query.filter(UserUID=uid).select_related('dashou_profile').first()
if user_main.dashou_profile:
dashou_profile = user_main.dashou_profile
@@ -3928,7 +3928,7 @@ class AdckyhxqView(APIView):
elif user_type == 3: # 管事
# 使用select_related预取guanshi_profile
user_main = User.query.filter(yonghuid=uid).select_related('guanshi_profile').first()
user_main = User.query.filter(UserUID=uid).select_related('guanshi_profile').first()
if user_main.guanshi_profile:
guanshi_profile = user_main.guanshi_profile
user_info.update({
@@ -3947,7 +3947,7 @@ class AdckyhxqView(APIView):
elif user_type == 4: # 商家
# 使用select_related预取shop_profile
user_main = User.query.filter(yonghuid=uid).select_related('shop_profile').first()
user_main = User.query.filter(UserUID=uid).select_related('shop_profile').first()
if user_main.shop_profile:
shop_profile = user_main.shop_profile
user_info.update({
@@ -4061,7 +4061,7 @@ class AdcjxgView(APIView):
}, status=status.HTTP_400_BAD_REQUEST)
# 查询用户主表
user_main = User.query.filter(yonghuid=uid).first()
user_main = User.query.filter(UserUID=uid).first()
if not user_main:
return Response({
'code': 404,
@@ -5457,7 +5457,7 @@ class WechatLoginAndDashouRegisterView(APIView):
user_id = timestamp_part + random_part
if len(user_id) == 7 and user_id.isdigit():
if not User.query.filter(yonghuid=user_id).exists():
if not User.query.filter(UserUID=user_id).exists():
return user_id
raise Exception('生成用户ID失败')
@@ -5730,7 +5730,7 @@ class YonghuTixianShenheXiugaiView(APIView):
try:
tixian_record = Tixianjilu.objects.select_for_update().get(
id=tixian_id,
yonghuid=current_yonghuid # 确保只能修改自己的记录
UserUID=current_yonghuid # 确保只能修改自己的记录
)
except Tixianjilu.DoesNotExist:
return Response({
@@ -6158,7 +6158,7 @@ class ChufaJiluHuoquView(APIView):
zhengju_mapping = {}
if dingdan_ids and shangjia_ids:
# 构建Q对象dingdan_id在列表中 AND yonghuid在商家ID列表中
zhengju_q = Q(dingdan_id__in=dingdan_ids, yonghuid__in=shangjia_ids)
zhengju_q = Q(dingdan_id__in=dingdan_ids, UserUID__in=shangjia_ids)
zhengju_queryset = Chufatupian.query.filter(zhengju_q).values('dingdan_id', 'yonghuid', 'tupian')
for item in zhengju_queryset:
@@ -6353,7 +6353,7 @@ class DashouShensuView(APIView):
# 检查是否已经有申诉图片
existing_shensu_tupian = Chufatupian.query.filter(
dingdan_id=chufa_record.dingdan_id,
yonghuid=yonghuid
UserUID=yonghuid
).exists()
if existing_shensu_tupian:
@@ -6600,7 +6600,7 @@ class ShangjiaChufaJiluHuoquView(APIView):
shensu_mapping = {}
if dingdan_ids and dashou_ids:
# 构建Q对象dingdan_id在列表中 AND yonghuid在打手ID列表中
shensu_q = Q(dingdan_id__in=dingdan_ids, yonghuid__in=dashou_ids)
shensu_q = Q(dingdan_id__in=dingdan_ids, UserUID__in=dashou_ids)
shensu_queryset = Chufatupian.query.filter(shensu_q).values('dingdan_id', 'yonghuid', 'tupian')
for item in shensu_queryset:
@@ -7064,7 +7064,7 @@ class KefuGetOrderListView(APIView):
laoban_ids = [o.pingtai_kuozhan.laoban_id for o in orders_qs if hasattr(o, 'pingtai_kuozhan') and o.pingtai_kuozhan.laoban_id]
nickname_map = {}
if laoban_ids:
users = User.query.filter(yonghuid__in=laoban_ids).select_related('boss_profile').only(
users = User.query.filter(UserUID__in=laoban_ids).select_related('boss_profile').only(
'yonghuid', 'boss_profile__nickname'
)
for user in users:
@@ -7233,7 +7233,7 @@ class KefuGetShangjiaOrderListView(APIView):
shangjia_ids = [o.shangjia_kuozhan.shangjia_id for o in orders_qs if hasattr(o, 'shangjia_kuozhan') and o.shangjia_kuozhan.shangjia_id]
nickname_map = {}
if shangjia_ids:
users = User.query.filter(yonghuid__in=shangjia_ids).select_related('shop_profile').only(
users = User.query.filter(UserUID__in=shangjia_ids).select_related('shop_profile').only(
'yonghuid', 'shop_profile__nicheng'
)
for user in users:
@@ -7339,7 +7339,7 @@ class KefuChangeDashouView(APIView):
# 5. 查询新打手
try:
new_dashou_user = User.query.get(yonghuid=new_dashou_id)
new_dashou_user = User.query.get(UserUID=new_dashou_id)
except User.DoesNotExist:
return Response({'code': 404, 'msg': '打手不存在'}, status=status.HTTP_404_NOT_FOUND)
@@ -7401,7 +7401,7 @@ class KefuChangeDashouView(APIView):
old_dashou_id = order.jiedan_dashou_id
if old_dashou_id:
try:
old_dashou_user = User.query.get(yonghuid=old_dashou_id)
old_dashou_user = User.query.get(UserUID=old_dashou_id)
old_dashou_profile = old_dashou_user.dashou_profile
old_dashou_profile.zhuangtai = 1 # 恢复空闲
old_dashou_profile.tuikuanliang += 1 # 原打手退款总量+1业务逻辑
@@ -7577,7 +7577,7 @@ class KefuPlatformRefundView(APIView):
jiedan_dashou_id = order.jiedan_dashou_id
if jiedan_dashou_id:
try:
dashou_user = User.query.get(yonghuid=jiedan_dashou_id)
dashou_user = User.query.get(UserUID=jiedan_dashou_id)
dashou_profile = dashou_user.dashou_profile
dashou_profile.tuikuanliang += 1
dashou_profile.zhuangtai = 1 # 打手状态设为空闲
@@ -7842,7 +7842,7 @@ class KefuRejectRefundView(APIView):
# 7. 给打手结算(返还分成)
if jiedan_dashou_id:
try:
dashou_user = User.query.get(yonghuid=jiedan_dashou_id)
dashou_user = User.query.get(UserUID=jiedan_dashou_id)
dashou_profile = dashou_user.dashou_profile
# 增加打手相关统计数据
dashou_profile.chengjiaozongliang += 1
@@ -7862,7 +7862,7 @@ class KefuRejectRefundView(APIView):
shangjia_kuozhan = order.shangjia_kuozhan
shangjia_id = shangjia_kuozhan.shangjia_id
if shangjia_id:
shangjia_user = User.query.get(yonghuid=shangjia_id)
shangjia_user = User.query.get(UserUID=shangjia_id)
shangjia_profile = shangjia_user.shop_profile
shangjia_profile.chengjiao += 1
shangjia_profile.save()
@@ -8019,7 +8019,7 @@ class KefuMerchantRefundView(APIView):
# 更新打手
if jiedan_dashou_id:
try:
dashou_user = User.query.get(yonghuid=jiedan_dashou_id)
dashou_user = User.query.get(UserUID=jiedan_dashou_id)
dashou_profile = dashou_user.dashou_profile
dashou_profile.tuikuanliang += 1
dashou_profile.zhuangtai = 1
@@ -8029,7 +8029,7 @@ class KefuMerchantRefundView(APIView):
# 更新商家
try:
shangjia_user = User.query.get(yonghuid=shangjia_id)
shangjia_user = User.query.get(UserUID=shangjia_id)
shangjia_profile = shangjia_user.shop_profile
shangjia_profile.tuikuan += 1
shangjia_profile.yue += jine
@@ -8156,7 +8156,7 @@ class KefuRejectSettlementView(APIView):
# 5.3 更新打手扩展表
try:
dashou_user = User.query.get(yonghuid=jiedan_dashou_id)
dashou_user = User.query.get(UserUID=jiedan_dashou_id)
dashou_profile = dashou_user.dashou_profile
dashou_profile.zhuangtai = 1 # 打手状态设为空闲
dashou_profile.tuikuanliang += 1 # 退款订单总量+1
@@ -8240,7 +8240,7 @@ class KefuTransferHallView(APIView):
if order.jiedan_dashou_id:
UserDashou.query.filter(user__yonghuid=order.jiedan_dashou_id).update(zhuangtai=1)
UserDashou.query.filter(user__UserUID=order.jiedan_dashou_id).update(zhuangtai=1)
else:
pass
@@ -8617,7 +8617,7 @@ class KefuUpdateDashouView(APIView):
# 3. 查询打手是否存在
try:
dashou_user = User.query.get(yonghuid=dashou_id, user_type='dashou')
dashou_user = User.query.get(UserUID=dashou_id, user_type='dashou')
dashou_profile = dashou_user.dashou_profile
except User.DoesNotExist:
return Response({'code': 404, 'msg': '打手不存在'})
@@ -9189,11 +9189,11 @@ class KefuPunishmentDetailView(APIView):
shensu_images = []
try:
# 商家证据图片:上传者为请求人 (qingqiuid)
zhengju_qs = Chufatupian.query.filter(dingdan_id=dingdan_id, yonghuid=record.qingqiuid)
zhengju_qs = Chufatupian.query.filter(dingdan_id=dingdan_id, UserUID=record.qingqiuid)
zhengju_images = [item.tupian for item in zhengju_qs if item.tupian]
# 打手申诉图片:上传者为打手 (dashouid)
shensu_qs = Chufatupian.query.filter(dingdan_id=dingdan_id, yonghuid=record.dashouid)
shensu_qs = Chufatupian.query.filter(dingdan_id=dingdan_id, UserUID=record.dashouid)
shensu_images = [item.tupian for item in shensu_qs if item.tupian]
except Exception as e:
logger.error(f"查询图片失败: {e}")
@@ -9294,7 +9294,7 @@ class KefuPunishmentActionView(APIView):
# 可选验证打手存在
if record.dashouid:
try:
dashou = UserDashou.query.get(user__yonghuid=record.dashouid)
dashou = UserDashou.query.get(user__UserUID=record.dashouid)
except UserDashou.DoesNotExist:
return Response({'code': 400, 'msg': '被处罚打手不存在'}, status=status.HTTP_400_BAD_REQUEST)
@@ -9315,7 +9315,7 @@ class KefuPunishmentActionView(APIView):
# 返还积分
if record.jifen > 0 and record.dashouid:
try:
dashou = UserDashou.query.get(user__yonghuid=record.dashouid)
dashou = UserDashou.query.get(user__UserUID=record.dashouid)
if dashou.jifen <= 1000: # 安全限制
dashou.jifen += record.jifen
dashou.save()
@@ -9410,7 +9410,7 @@ class KefuForceCompleteView(APIView):
# 5. 给打手结算
try:
dashou_user = User.query.get(yonghuid=dashou_id)
dashou_user = User.query.get(UserUID=dashou_id)
dashou_profile = dashou_user.dashou_profile
# 原子更新(避免并发重复加)
dashou_profile.chengjiaozongliang = F('chengjiaozongliang') + 1
@@ -9431,7 +9431,7 @@ class KefuForceCompleteView(APIView):
# 通过 DingdanShangjia 获取商家ID
shangjia_ext = order.shangjia_kuozhan # 假设 related_name='shangjia_kuozhan'
if shangjia_ext and shangjia_ext.shangjia_id:
shangjia_user = User.query.get(yonghuid=shangjia_ext.shangjia_id)
shangjia_user = User.query.get(UserUID=shangjia_ext.shangjia_id)
shangjia_profile = shangjia_user.shop_profile
shangjia_profile.chengjiao = F('chengjiao') + 1
shangjia_profile.save(update_fields=['chengjiao'])
@@ -9874,7 +9874,7 @@ class KefuWithdrawDetailView(APIView):
# 查询用户主表
try:
user = User.query.get(yonghuid=record.yonghuid)
user = User.query.get(UserUID=record.yonghuid)
except User.DoesNotExist:
user = None
@@ -10047,7 +10047,7 @@ class KefuWithdrawActionView(APIView):
raise ValueError(f'提现记录{tixian_id}:审核记录非审核中状态')
try:
user = User.objects.select_for_update().get(yonghuid=req_yonghuid)
user = User.objects.select_for_update().get(UserUID=req_yonghuid)
except User.DoesNotExist:
raise ValueError(f'用户{req_yonghuid}不存在')
@@ -10100,7 +10100,7 @@ class KefuWithdrawActionView(APIView):
raise ValueError(f'提现记录{tixian_id}:自动打款请走自动流程')
try:
user = User.query.get(yonghuid=tixian.yonghuid)
user = User.query.get(UserUID=tixian.yonghuid)
except User.DoesNotExist:
raise ValueError(f'用户{tixian.yonghuid}不存在')
@@ -10247,7 +10247,7 @@ class KefuPunishView(APIView):
# 5. 查询打手
try:
dashou_user = User.query.get(yonghuid=dashou_id)
dashou_user = User.query.get(UserUID=dashou_id)
dashou = dashou_user.dashou_profile
except User.DoesNotExist:
return Response({'code': 404, 'msg': '打手用户不存在'}, status=status.HTTP_404_NOT_FOUND)
@@ -10329,7 +10329,7 @@ class AdKftjView(APIView):
timestamp = str(int(time.time()))[-5:]
rand = str(random.randint(0, 99)).zfill(2)
uid = timestamp + rand
if len(uid) == 7 and not User.query.filter(yonghuid=uid).exists():
if len(uid) == 7 and not User.query.filter(UserUID=uid).exists():
return uid
raise Exception('无法生成唯一用户ID')
@@ -10645,7 +10645,7 @@ class WechatLoginAndGuanshiRegisterView(APIView):
random_part = str(random.randint(0, 99)).zfill(2)
user_id = timestamp_part + random_part
if len(user_id) == 7 and user_id.isdigit():
if not User.query.filter(yonghuid=user_id).exists():
if not User.query.filter(UserUID=user_id).exists():
return user_id
raise Exception('生成用户ID失败')
@@ -11931,7 +11931,7 @@ class FaKuanPayPollView(APIView):
if not dingdanid:
return Response({'code': 400, 'message': '订单ID不能为空'})
order = Czjilu.query.get(dingdan_id=dingdanid, yonghuid=request.user.yonghuid)
order = Czjilu.query.get(dingdan_id=dingdanid, UserUID=request.user.yonghuid)
if order.zhuangtai == 3:
return Response({'code': 200, 'message': '支付成功'})
else:
@@ -11954,7 +11954,7 @@ class FaKuanPayFailView(APIView):
if not dingdanid:
return Response({'code': 400, 'message': '订单ID不能为空'})
order = Czjilu.query.get(dingdan_id=dingdanid, yonghuid=request.user.yonghuid)
order = Czjilu.query.get(dingdan_id=dingdanid, UserUID=request.user.yonghuid)
if order.zhuangtai == 9: # 未支付
order.delete()
logger.info(f"用户{request.user.yonghuid}删除未支付订单: {dingdanid}")
@@ -12004,7 +12004,7 @@ class KaohePayView(APIView):
# 1. 检查是否有未支付的考核订单
"""unpaid_order = Czjilu.query.filter(
yonghuid=user.yonghuid,
UserUID=user.yonghuid,
leixing=5,
zhuangtai=9
).exists()
@@ -12366,10 +12366,10 @@ class KaohePayCallbackView(View):
# 从临时表获取业务参数并创建审核记录
try:
temp = KaohePayTemp.query.get(dingdan_id=out_trade_no, yonghuid=order.yonghuid)
temp = KaohePayTemp.query.get(dingdan_id=out_trade_no, UserUID=order.yonghuid)
logger.info(f"找到临时表记录: {out_trade_no}, 用户ID: {order.yonghuid}")
user = User.query.get(yonghuid=order.yonghuid)
user = User.query.get(UserUID=order.yonghuid)
logger.info(f"获取用户信息成功: {user.yonghuid}")
success, msg, record = create_shenhe_jilu_from_temp(user, temp)
@@ -12486,7 +12486,7 @@ class KaohePayPollView(APIView):
if not dingdanid:
return Response({'code': 400, 'message': '订单ID不能为空'})
try:
order = Czjilu.query.get(dingdan_id=dingdanid, yonghuid=request.user.yonghuid, leixing=5)
order = Czjilu.query.get(dingdan_id=dingdanid, UserUID=request.user.yonghuid, leixing=5)
if order.zhuangtai == 3:
return Response({'code': 200, 'message': '支付成功'})
return Response({'code': 400, 'message': '订单尚未支付'})
@@ -12503,7 +12503,7 @@ class KaohePayFailView(APIView):
if not dingdanid:
return Response({'code': 400, 'message': '订单ID不能为空'})
try:
order = Czjilu.query.get(dingdan_id=dingdanid, yonghuid=request.user.yonghuid, leixing=5)
order = Czjilu.query.get(dingdan_id=dingdanid, UserUID=request.user.yonghuid, leixing=5)
if order.zhuangtai == 9:
order.delete()
return Response({'code': 200, 'message': '订单已删除'})
@@ -12676,7 +12676,7 @@ class GuanshiContactView(APIView):
# 4. 根据邀请人用户ID查询用户主表
try:
inviter_user = User.query.get(yonghuid=inviter_yonghuid)
inviter_user = User.query.get(UserUID=inviter_yonghuid)
except User.DoesNotExist:
logger.error(f"邀请人用户不存在: yonghuid={inviter_yonghuid}")
return Response({
@@ -12855,7 +12855,7 @@ class TixianQueRenAutoView(APIView):
try:
auto_record = TixianAutoRecord.objects.select_for_update().get(
tixian_id=tixian_id,
yonghuid=user_main.yonghuid,
UserUID=user_main.yonghuid,
)
except TixianAutoRecord.DoesNotExist:
return Response({'code': 4, 'msg': '提现记录不存在'}, status=status.HTTP_404_NOT_FOUND)