LoginPlatform.php 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. <?php
  2. namespace App\Support;
  3. /**
  4. * user_login.platform 规范值 → 后台统计 bucket
  5. *
  6. * 写入侧(melbet)负责一次写对:
  7. * - iOS / Android = 原生 APP
  8. * - H5 = 手机 H5
  9. * - PC = 电脑
  10. * - WeChat = 微信(统计并入 mobile)
  11. *
  12. * 读侧只做映射,不再用 login_domain 二次推断。
  13. */
  14. final class LoginPlatform
  15. {
  16. public const BUCKET_APPLE = 'apple';
  17. public const BUCKET_ANDROID = 'android';
  18. public const BUCKET_PC = 'pc';
  19. public const BUCKET_MOBILE = 'mobile';
  20. public const BUCKET_UNKNOWN = 'unknown';
  21. /**
  22. * @return self::BUCKET_*
  23. */
  24. public static function toBucket(string $platform): string
  25. {
  26. $p = strtolower(trim($platform));
  27. return match ($p) {
  28. 'ios', 'apple', '苹果' => self::BUCKET_APPLE,
  29. 'android', '安卓' => self::BUCKET_ANDROID,
  30. 'pc', 'windows', 'mac', 'macos', 'linux', 'chrome os', 'chromeos' => self::BUCKET_PC,
  31. 'h5', 'mobile', '移动', 'wechat', '微信' => self::BUCKET_MOBILE,
  32. default => self::BUCKET_UNKNOWN,
  33. };
  34. }
  35. /**
  36. * 空计数骨架
  37. *
  38. * @return array{total:int,apple:int,android:int,pc:int,mobile:int,wechat:int,unknown:int}
  39. */
  40. public static function emptyCounts(): array
  41. {
  42. return [
  43. 'total' => 0,
  44. 'apple' => 0,
  45. 'android' => 0,
  46. 'pc' => 0,
  47. 'mobile' => 0,
  48. 'wechat' => 0,
  49. 'unknown' => 0,
  50. ];
  51. }
  52. }