AgentClickLog.php 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. <?php
  2. namespace App\Models;
  3. use Illuminate\Database\Eloquent\Model;
  4. class AgentClickLog extends Model
  5. {
  6. /**
  7. * 数据库连接名
  8. */
  9. protected $connection = 'mysql';
  10. /**
  11. * 与模型关联的表名
  12. */
  13. protected $table = 'webgame.agent_click_logs';
  14. /**
  15. * 可批量赋值的属性
  16. */
  17. protected $fillable = [
  18. 'code',
  19. 'country',
  20. 'city',
  21. 'user_agent',
  22. 'client_ip',
  23. 'referrer',
  24. 'device_type',
  25. 'is_valid'
  26. ];
  27. /**
  28. * 指定不需要更新时间戳
  29. */
  30. const UPDATED_AT = null;
  31. /**
  32. * 根据User-Agent判断设备类型
  33. *
  34. * @param string $userAgent
  35. * @return string
  36. */
  37. public static function detectDeviceType($userAgent)
  38. {
  39. $userAgent = strtolower($userAgent);
  40. if (strpos($userAgent, 'mobile') !== false ||
  41. strpos($userAgent, 'android') !== false ||
  42. strpos($userAgent, 'iphone') !== false) {
  43. return 'mobile';
  44. } elseif (strpos($userAgent, 'ipad') !== false ||
  45. strpos($userAgent, 'tablet') !== false) {
  46. return 'tablet';
  47. } else {
  48. return 'desktop';
  49. }
  50. }
  51. /**
  52. * 获取关联的邀请码信息
  53. */
  54. public function agentInfo()
  55. {
  56. return $this->belongsTo(AgentUserInfo::class, 'code', 'referral_code');
  57. }
  58. }