diff --git a/qy_lty/userapp/views.py b/qy_lty/userapp/views.py index 511d9f2..b546d8c 100644 --- a/qy_lty/userapp/views.py +++ b/qy_lty/userapp/views.py @@ -116,7 +116,8 @@ class MacAddressLoginView(APIView): device = Device.objects.get(mac_address=mac_address) # 检查设备是否已绑定给用户 - user_device = UserDevice.objects.filter(device=device).first() + # 按绑定时间倒序取最新绑定者作为设备归属人——"后绑的挤掉先绑的" + user_device = UserDevice.objects.filter(device=device).order_by('-bound_at').first() if not user_device: logger.warning(f"Device not bound to any user: {mac_address}") # 返回特定 code=4010,让设备端可以识别"未绑定"状态