ReportActivity.php 1.0 KB

12345678910111213141516171819202122
  1. <?php
  2. namespace App\Services\Reporting;
  3. use Illuminate\Support\Facades\DB;
  4. use Illuminate\Support\Facades\Log;
  5. use Illuminate\Support\Facades\Schema;
  6. class ReportActivity
  7. {
  8. public static function telegram($user): void
  9. {
  10. if (request()->path() !== 'api/onMessage' || (int) ($user->from ?? 0) === 2) return;
  11. try {
  12. if (!Schema::hasTable('reporting_activity')) return;
  13. $now = now('Asia/Shanghai')->format('Y-m-d H:i:00');
  14. $parent = Schema::hasTable('share_members') ? DB::table('share_members')->where('user_id', $user->id)->where('bound_at', '<=', $now)->value('parent_user_id') : null;
  15. DB::table('reporting_activity')->insertOrIgnore(['user_id' => $user->id, 'agent_id' => $user->agent_id, 'inviter_id' => $parent,
  16. 'client_platform' => 'unknown', 'session_hash' => hash('sha256', 'telegram:' . $user->id), 'observed_at' => $now]);
  17. } catch (\Throwable $e) { Log::error('reporting_telegram_activity_failed', ['exception' => get_class($e)]); }
  18. }
  19. }