小程序分销
All checks were successful
Deploy to Server / deploy (push) Successful in 24s

This commit is contained in:
jeremygan2021
2026-02-17 11:41:23 +08:00
parent 094f9032c5
commit 1555bec154
2 changed files with 21 additions and 1 deletions

View File

@@ -1466,7 +1466,22 @@ class DistributorViewSet(viewsets.GenericViewSet):
distributor = user.distributor
if distributor.qr_code_url:
return Response({'qr_code_url': distributor.qr_code_url})
# 检查文件是否真的存在
try:
# 如果是本地存储,检查文件路径
if distributor.qr_code_url.startswith(settings.MEDIA_URL):
file_path = distributor.qr_code_url.replace(settings.MEDIA_URL, '', 1)
if default_storage.exists(file_path):
return Response({'qr_code_url': distributor.qr_code_url})
elif distributor.qr_code_url.startswith('http'):
# 远程 URL假设有效
return Response({'qr_code_url': distributor.qr_code_url})
except Exception as e:
logger.warning(f"Error checking QR code existence: {e}")
# 如果文件不存在,重置 URL 并重新生成
distributor.qr_code_url = ''
distributor.save()
# 确保有邀请码
if not distributor.invite_code: