57 lines
1.4 KiB
PHP
57 lines
1.4 KiB
PHP
<?php
|
|
|
|
namespace app\model;
|
|
|
|
use think\Model;
|
|
|
|
class Asset extends Model
|
|
{
|
|
// 设置表名
|
|
protected $table = 'bps.bps_google_ads_asset';
|
|
|
|
// 设置主键
|
|
protected $pk = 'asset_id';
|
|
|
|
// 设置时间戳字段
|
|
protected $createTime = 'create_at';
|
|
protected $updateTime = 'update_at';
|
|
|
|
// 定义 JSONB 类型字段
|
|
protected $json = ['metadata'];
|
|
|
|
// 类型判断常量
|
|
const TYPE_YOUTUBE_VIDEO = 2;
|
|
const TYPE_IMAGE = 4;
|
|
|
|
// 获取类型
|
|
public function getTypeTextAttr($value, $data)
|
|
{
|
|
$statusMap = [
|
|
self::TYPE_YOUTUBE_VIDEO => 'YOUTUBE_VIDEO',
|
|
self::TYPE_IMAGE => 'IMAGE'
|
|
];
|
|
return $statusMap[$data['asset_type']] ?? 'UNKNOWN';
|
|
}
|
|
|
|
// 允许批量赋值的字段
|
|
protected $fillable = ['customer_id', 'asset_type', 'asset_name', 'resource_name','asset_url', 'status', 'metadata'];
|
|
|
|
// 关联到广告、广告组和广告活动
|
|
public function relations()
|
|
{
|
|
return $this->hasMany(AssetRelation::class, 'asset_id', 'asset_id');
|
|
}
|
|
|
|
// 获取素材的广告、广告组和广告活动
|
|
public function getRelations()
|
|
{
|
|
return $this->relations()->with(['ad', 'adGroup', 'campaign']);
|
|
}
|
|
|
|
// 追加自定义字段到模型结果中
|
|
public function appendCustomAttributes()
|
|
{
|
|
return ['relations'];
|
|
}
|
|
}
|