diff --git a/app/model/Ad.php b/app/model/Ad.php index 4a4b55a..9e93583 100644 --- a/app/model/Ad.php +++ b/app/model/Ad.php @@ -6,12 +6,41 @@ use think\Model; class Ad extends Model { - protected $table = 'ad_ga_ads'; - protected $primaryKey = 'id'; + // 设置当前模型对应的完整数据表名称 + protected $table = 'bps_google_ads_ad'; + + // 设置主键 + protected $pk = 'ad_id'; + + // 设置自动时间戳 protected $autoWriteTimestamp = true; + // 定义时间戳字段 + protected $createTime = 'create_at'; + protected $updateTime = 'update_at'; + + // 设置字段类型和默认值 + protected $casts = [ + 'ad_id' => 'int', + 'ad_group_id' => 'int', + 'customer_id' => 'int', + ]; + + // 默认值设置 + protected $defaults = [ + 'status' => 'ENABLED', // 广告状态默认值为 'ENABLED' + ]; + + // 关联 AdGroup 模型(广告属于广告组) + // 即使没有外键约束,依然可以使用 belongsTo 访问 AdGroup 数据 public function adGroup() { - return $this->belongsTo(AdGroup::class, 'ad_group_id', 'id'); + return $this->belongsTo(GoogleAdsAdGroup::class, 'ad_group_id', 'ad_group_id'); } -} + + // 关联 Customer 模型(广告属于客户) +// public function customer() +// { +// return $this->belongsTo(GoogleAdsCustomer::class, 'customer_id', 'customer_id'); +// } +} \ No newline at end of file diff --git a/app/model/AdGroup.php b/app/model/AdGroup.php index 8ae5f97..ceb0bc0 100644 --- a/app/model/AdGroup.php +++ b/app/model/AdGroup.php @@ -6,12 +6,48 @@ use think\Model; class AdGroup extends Model { - protected $table = 'ad_ga_ad_groups'; - protected $primaryKey = 'id'; + // 设置当前模型对应的完整数据表名称 + protected $table = 'bps_google_ads_ad_group'; + + // 设置主键 + protected $pk = 'ad_group_id'; + + // 设置自动时间戳 protected $autoWriteTimestamp = true; + // 定义时间戳字段 + protected $createTime = 'create_at'; + protected $updateTime = 'update_at'; + + // 设置字段类型和默认值 + protected $casts = [ + 'ad_group_id' => 'int', + 'campaign_id' => 'int', + 'customer_id' => 'int', + 'cpc_bid_micros' => 'int', + ]; + + // 默认值设置 + protected $defaults = [ + 'cpc_bid_micros' => 0, // 每次点击出价默认值为0 + ]; + + // 关联 Campaign 模型(广告组属于广告活动) public function campaign() { - return $this->belongsTo(Campaign::class, 'campaign_id', 'id'); + return $this->belongsTo(Campaign::class, 'campaign_id', 'campaign_id'); + } + + // 关联 Customer 模型(广告组属于客户) +// public function customer() +// { +// return $this->belongsTo(GoogleAdsCustomer::class, 'customer_id', 'customer_id'); +// } + + // 关联 Ad 模型(广告组包含多个广告) + public function ads() + { + return $this->hasMany(Ad::class, 'ad_group_id', 'ad_group_id'); } } + diff --git a/app/model/Campaign.php b/app/model/Campaign.php index 27220dc..a32366a 100644 --- a/app/model/Campaign.php +++ b/app/model/Campaign.php @@ -4,17 +4,49 @@ namespace app\model; use think\Model; -class Campaign extends PgBaseModel +class BpsGoogleAdsCampaign extends Model { - protected $table = 'ad_ga_campaigns'; // 对应数据库表名 - protected $primaryKey = 'id'; // 主键 - protected $autoWriteTimestamp = true; // 自动时间戳 - protected $createTime = 'created_at'; // 创建时间字段 - protected $updateTime = 'updated_at'; // 更新时间字段 + // 设置当前模型对应的完整数据表名称 + protected $table = 'bps_google_ads_campaign'; - // 关联广告预算 - public function campaignBudget() + // 设置主键 + protected $pk = 'campaign_id'; + + // 设置自动时间戳 + protected $autoWriteTimestamp = true; + + // 定义时间戳字段 + protected $createTime = 'create_at'; + protected $updateTime = 'update_at'; + + // 设置字段类型和默认值 + protected $casts = [ + 'campaign_id' => 'int', + 'customer_id' => 'int', + 'budget_amount_micros' => 'int', + ]; + + // 默认值设置 + protected $defaults = [ + 'status' => 'ENABLED', // 活动状态默认值为 'ENABLED' + 'advertising_channel_type' => 'SEARCH', // 广告渠道类型默认值为 'SEARCH' + ]; + + // 关联 Customer 模型(广告活动属于客户) + public function customer() { - return $this->belongsTo(CampaignBudget::class, 'budget_id', 'id'); + return $this->belongsTo(GoogleAdsCustomer::class, 'customer_id', 'customer_id'); } -} + + // 关联 AdGroup 模型(一个广告活动下有多个广告组) + public function adGroups() + { + return $this->hasMany(GoogleAdsAdGroup::class, 'campaign_id', 'campaign_id'); + } + + // 关联 Ad 模型(一个广告活动下有多个广告) + public function ads() + { + return $this->hasManyThrough(GoogleAdsAd::class, GoogleAdsAdGroup::class, 'campaign_id', 'ad_group_id', 'campaign_id', 'ad_group_id'); + } +} \ No newline at end of file diff --git a/app/model/CampaignBudget.php b/app/model/CampaignBudget.php index 56f58f5..b4b831b 100644 --- a/app/model/CampaignBudget.php +++ b/app/model/CampaignBudget.php @@ -6,12 +6,38 @@ use think\Model; class CampaignBudget extends Model { - protected $table = 'ad_ga_campaign_budgets'; - protected $primaryKey = 'id'; + // 设置当前模型对应的完整数据表名称 + protected $table = 'bps_google_ads_budget'; + + // 设置主键 + protected $pk = 'budget_id'; + + // 设置自动时间戳 protected $autoWriteTimestamp = true; - public function campaigns() - { - return $this->hasMany(Campaign::class, 'budget_id', 'id'); - } + // 定义时间戳字段 + protected $createTime = 'create_at'; + protected $updateTime = 'update_at'; + + // 设置字段类型和默认值 + protected $casts = [ + 'budget_id' => 'int', + 'customer_id' => 'int', + 'amount_micros' => 'int', + 'start_date' => 'date', + 'end_date' => 'date', + ]; + + // 默认值设置 + protected $defaults = [ + 'amount_micros' => 0, // 预算金额默认0 + ]; + + // 关联 Customer 模型(预算与客户相关) +// public function customer() +// { +// return $this->belongsTo(GoogleAdsCustomer::class, 'customer_id', 'customer_id'); +// } + + // 可以根据需要添加其他关联方法,假设有其他与预算相关的表,例如广告系列(campaign) } diff --git a/app/model/DayData.php b/app/model/DayData.php new file mode 100644 index 0000000..f1f6a40 --- /dev/null +++ b/app/model/DayData.php @@ -0,0 +1,72 @@ + 'int', + 'customer_id' => 'int', + 'clicks' => 'int', + 'cost_micros' => 'int', + 'conversions' => 'int', + 'conversions_value' => 'float', + 'impressions' => 'int', + 'date' => 'date', + ]; + + // 默认值设置 + protected $defaults = [ + 'clicks' => 0, + 'cost_micros' => 0, + 'conversions' => 0, + 'conversions_value' => 0.0, + 'impressions' => 0, + ]; + + // 关联 Campaign 模型(报告数据属于广告活动) + public function campaign() + { + return $this->belongsTo(GoogleAdsCampaign::class, 'campaign_id', 'campaign_id'); + } + + // 关联 AdGroup 模型(报告数据属于广告组) + public function adGroup() + { + return $this->belongsTo(GoogleAdsAdGroup::class, 'group_id', 'group_id'); + } + + // 关联 Ad 模型(报告数据属于广告) + public function ad() + { + return $this->belongsTo(GoogleAdsAd::class, 'ad_id', 'ad_id'); + } + + // 关联 Customer 模型(报告数据与客户相关) +// public function customer() +// { +// return $this->belongsTo(GoogleAdsCustomer::class, 'customer_id', 'customer_id'); +// } + + // 关联 Budget 模型(报告数据与预算相关) + public function budget() + { + return $this->belongsTo(GoogleAdsBudget::class, 'budget_id', 'budget_id'); + } +} \ No newline at end of file