123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151 |
- <?php
- namespace App\Models;
- use Illuminate\Database\Eloquent\Model;
- class JxAdPlacementLog extends Model
- {
- /**
- * The table associated with the model.
- *
- * @var string
- */
- protected $table = 'jx_ad_placement_log';
- public $timestamps = false;
- protected static $unguarded = true;
- /**
- * The attributes that should be cast.
- *
- * @var array
- */
- protected $casts = [
- 'id' => 'integer',
- 'action_type' => 'integer',
- 'timestamp_ms' => 'integer',
- 'os_code' => 'integer',
- 'is_activate_report' => 'integer',
- 'created_at' => 'datetime',
- 'updated_at' => 'datetime',
- ];
- /**
- * Save a new ad placement log entry
- *
- * @param array $data
- * @return self
- */
- public static function saveLog(array $data)
- {
- $model = new self();
- $model->promotion_channel_id = $data['promotion_channel_id'];
- $model->action_type = $data['action_type'];
- $model->tracking_id = $data['tracking_id'];
- $model->campaign_id = $data['campaign_id'];
- $model->campaign_name = $data['campaign_name'];
- $model->ad_id = $data['ad_id'];
- $model->creative_id = $data['creative_id'];
- $model->idfa_withdash_md5 = $data['idfa_withdash_md5'];
- $model->mac_upper_withcolon = $data['mac_upper_withcolon'];
- $model->mac_upper_withcolon_md5 = $data['mac_upper_withcolon_md5'];
- $model->mac_upper_nocolon_md5 = $data['mac_upper_nocolon_md5'];
- $model->timestamp_ms = $data['timestamp_ms'] != '__TS__' ? $data['timestamp_ms'] : null;
- $model->ip = $data['ip'];
- $model->callback_url = $data['callback_url'];
- $model->csite = $data['csite'];
- $model->idfa_sha1 = $data['idfa_sha1'];
- $model->imei_md5 = $data['imei_md5'];
- $model->androidid_md5 = $data['androidid_md5'];
- $model->oaid = $data['oaid'];
- $model->oaid_md5 = $data['oaid_md5'];
- $model->imei_sha1 = $data['imei_sha1'];
- $model->androidid_sha1 = $data['androidid_sha1'];
- $model->ua = $data['ua'];
- $model->brand = $data['brand'];
- $model->os_code = $data['os_code'] != '__OS__' ? $data['os_code'] : 3;
- $model->account_id = $data['account_id'];
- $model->kuaishou_photo_id = $data['kuaishou_photo_id'];
- // $model->is_activate_report = $data['is_activate_report'];
- $model->kenyid_caa = $data['kenyid_caa'];
- $model->imei = $data['imei'];
- $model->idfa = $data['idfa'];
- $model->adsocial_uid = $data['adsocial_uid'];
- $model->adsocial_aid = $data['adsocial_aid'];
- $model->mission_id = $data['mission_id'] ?? '';
- $model->order_id = $data['order_id'] ?? '';
- $model->advertiser_space_id = $data['advertiser_space_id'] ?? '';
- $model->save();
- return $model;
- }
- /**
- * Query logs by campaign ID
- *
- * @param string $campaignId
- * @return \Illuminate\Database\Eloquent\Collection
- */
- public static function getByCampaignId($campaignId)
- {
- return self::where('campaign_id', $campaignId)->get();
- }
- /**
- * Query logs by action type
- *
- * @param int $actionType
- * @return \Illuminate\Database\Eloquent\Collection
- */
- public static function getByActionType($actionType)
- {
- return self::where('action_type', $actionType)->get();
- }
- /**
- * Query logs by time range
- *
- * @param int $startTime
- * @param int $endTime
- * @return \Illuminate\Database\Eloquent\Collection
- */
- public static function getByTimeRange($startTime, $endTime)
- {
- return self::whereBetween('timestamp_ms', [$startTime, $endTime])->get();
- }
- /**
- * Query logs by promotion channel ID
- *
- * @param string $channelId
- * @return \Illuminate\Database\Eloquent\Collection
- */
- public static function getByPromotionChannel($channelId)
- {
- return self::where('promotion_channel_id', $channelId)->get();
- }
- /**
- * Check if a log entry exists by tracking ID
- *
- * @param string $trackingId
- * @return bool
- */
- public static function existsByTrackingId($trackingId)
- {
- return self::where('tracking_id', $trackingId)->exists();
- }
- public static function getAccountIdByLogId($logId) {
- return self::query()->where('id', $logId)->value('account_id');
- }
- public static function getUrlById($logId) {
- return self::query()->where('id', $logId)->value('callback_url');
- }
- public static function getInfoById($logId) {
- return self::query()->where('id', $logId)->first();
- }
- }
|