<?php  if (!defined('DASHBOARD_ROOT')) { http_response_code(403); exit; } function calculateTrust(int $userId): array { $orders=(int)Database::scalar("SELECT COUNT(*) FROM orders WHERE user_id=:uid AND status_code=2002",[":uid"=>$userId]); $age=(int)Database::scalar("SELECT DATEDIFF(NOW(),created_at) FROM users WHERE id=:uid",[":uid"=>$userId]); $ipChanges=(int)Database::scalar("SELECT COUNT(DISTINCT ip_address) FROM device_bindings WHERE user_id=:uid",[":uid"=>$userId]); $score=min(100,($orders*10)+min($age,50)-($ipChanges>5?20:0)); return ["score"=>max(0,$score),"orders"=>$orders,"age_days"=>$age,"ip_count"=>$ipChanges]; } 