説明なし

JxAdPlacementLog.php 4.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  1. <?php
  2. namespace App\Models;
  3. use Illuminate\Database\Eloquent\Model;
  4. class JxAdPlacementLog extends Model
  5. {
  6. /**
  7. * The table associated with the model.
  8. *
  9. * @var string
  10. */
  11. protected $table = 'jx_ad_placement_log';
  12. public $timestamps = false;
  13. protected static $unguarded = true;
  14. /**
  15. * The attributes that should be cast.
  16. *
  17. * @var array
  18. */
  19. protected $casts = [
  20. 'id' => 'integer',
  21. 'action_type' => 'integer',
  22. 'timestamp_ms' => 'integer',
  23. 'os_code' => 'integer',
  24. 'is_activate_report' => 'integer',
  25. 'created_at' => 'datetime',
  26. 'updated_at' => 'datetime',
  27. ];
  28. /**
  29. * Save a new ad placement log entry
  30. *
  31. * @param array $data
  32. * @return self
  33. */
  34. public static function saveLog(array $data)
  35. {
  36. $model = new self();
  37. $model->promotion_channel_id = $data['promotion_channel_id'];
  38. $model->action_type = $data['action_type'];
  39. $model->tracking_id = $data['tracking_id'];
  40. $model->campaign_id = $data['campaign_id'];
  41. $model->campaign_name = $data['campaign_name'];
  42. $model->ad_id = $data['ad_id'];
  43. $model->creative_id = $data['creative_id'];
  44. $model->idfa_withdash_md5 = $data['idfa_withdash_md5'];
  45. $model->mac_upper_withcolon = $data['mac_upper_withcolon'];
  46. $model->mac_upper_withcolon_md5 = $data['mac_upper_withcolon_md5'];
  47. $model->mac_upper_nocolon_md5 = $data['mac_upper_nocolon_md5'];
  48. $model->timestamp_ms = $data['timestamp_ms'] != '__TS__' ? $data['timestamp_ms'] : null;
  49. $model->ip = $data['ip'];
  50. $model->callback_url = $data['callback_url'];
  51. $model->csite = $data['csite'];
  52. $model->idfa_sha1 = $data['idfa_sha1'];
  53. $model->imei_md5 = $data['imei_md5'];
  54. $model->androidid_md5 = $data['androidid_md5'];
  55. $model->oaid = $data['oaid'];
  56. $model->oaid_md5 = $data['oaid_md5'];
  57. $model->imei_sha1 = $data['imei_sha1'];
  58. $model->androidid_sha1 = $data['androidid_sha1'];
  59. $model->ua = $data['ua'];
  60. $model->brand = $data['brand'];
  61. $model->os_code = $data['os_code'] != '__OS__' ? $data['os_code'] : 3;
  62. $model->account_id = $data['account_id'];
  63. $model->kuaishou_photo_id = $data['kuaishou_photo_id'];
  64. // $model->is_activate_report = $data['is_activate_report'];
  65. $model->kenyid_caa = $data['kenyid_caa'];
  66. $model->imei = $data['imei'];
  67. $model->idfa = $data['idfa'];
  68. $model->adsocial_uid = $data['adsocial_uid'];
  69. $model->adsocial_aid = $data['adsocial_aid'];
  70. $model->mission_id = $data['mission_id'] ?? '';
  71. $model->order_id = $data['order_id'] ?? '';
  72. $model->advertiser_space_id = $data['advertiser_space_id'] ?? '';
  73. $model->save();
  74. return $model;
  75. }
  76. /**
  77. * Query logs by campaign ID
  78. *
  79. * @param string $campaignId
  80. * @return \Illuminate\Database\Eloquent\Collection
  81. */
  82. public static function getByCampaignId($campaignId)
  83. {
  84. return self::where('campaign_id', $campaignId)->get();
  85. }
  86. /**
  87. * Query logs by action type
  88. *
  89. * @param int $actionType
  90. * @return \Illuminate\Database\Eloquent\Collection
  91. */
  92. public static function getByActionType($actionType)
  93. {
  94. return self::where('action_type', $actionType)->get();
  95. }
  96. /**
  97. * Query logs by time range
  98. *
  99. * @param int $startTime
  100. * @param int $endTime
  101. * @return \Illuminate\Database\Eloquent\Collection
  102. */
  103. public static function getByTimeRange($startTime, $endTime)
  104. {
  105. return self::whereBetween('timestamp_ms', [$startTime, $endTime])->get();
  106. }
  107. /**
  108. * Query logs by promotion channel ID
  109. *
  110. * @param string $channelId
  111. * @return \Illuminate\Database\Eloquent\Collection
  112. */
  113. public static function getByPromotionChannel($channelId)
  114. {
  115. return self::where('promotion_channel_id', $channelId)->get();
  116. }
  117. /**
  118. * Check if a log entry exists by tracking ID
  119. *
  120. * @param string $trackingId
  121. * @return bool
  122. */
  123. public static function existsByTrackingId($trackingId)
  124. {
  125. return self::where('tracking_id', $trackingId)->exists();
  126. }
  127. public static function getAccountIdByLogId($logId) {
  128. return self::query()->where('id', $logId)->value('account_id');
  129. }
  130. public static function getUrlById($logId) {
  131. return self::query()->where('id', $logId)->value('callback_url');
  132. }
  133. public static function getInfoById($logId) {
  134. return self::query()->where('id', $logId)->first();
  135. }
  136. }