Commit 7c551ac6 by Vladislav

#19473 Получение кеша фраз

1 parent b9c066d8
......@@ -101,6 +101,7 @@ class AdGroup extends Model
'serving_status',
'restricted_region_ids',
'updated_self',
'keywords_loaded_at',
];
protected $casts = [
......@@ -118,6 +119,7 @@ class AdGroup extends Model
'smart_ad_group' => 'json',
'restricted_region_ids' => 'json',
'updated_self' => 'datetime',
'keywords_loaded_at' => 'datetime',
];
/**
......
<?php
namespace App\Models;
use App\Models\Pivots\GoalAdGroup;
use Carbon\Carbon;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Support\Collection;
class Keyword extends Model
{
const STATE_OFF = 'OFF';
const STATE_ON = 'ON';
const STATE_SUSPENDED = 'SUSPENDED';
const STATUS_ACCEPTED = 'ACCEPTED';
const STATUS_DRAFT = 'DRAFT';
const STATUS_REJECTED = 'REJECTED';
const STATUS_UNKNOWN = 'UNKNOWN';
const SERVING_STATUS_ELIGIBLE = 'ELIGIBLE';
const SERVING_STATUS_RARELY_SERVED = 'RARELY_SERVED';
protected $fillable = [
'external_id',
'ad_group_external_id',
'ad_group_id',
'keyword',
'user_param_1',
'user_param_2',
'bid',
'context_bid',
'state',
'status',
'serving_status',
'statistics_search',
'statistics_network',
];
protected $casts = [
'external_id' => 'int',
'ad_group_external_id' => 'int',
'ad_group_id' => 'int',
'bid' => 'int',
'context_bid' => 'int',
'statistics_search' => 'json',
'statistics_network' => 'json',
];
/**
* @return Collection
*/
static public function getPropertiesWatch()
{
return collect([
'ad_group_external_id',
'keyword',
'user_param_1',
'user_param_2',
'bid',
'context_bid',
'state',
'status',
'serving_status',
'statistics_search',
'statistics_network',
]);
}
public static function boot()
{
parent::boot();
static::created(function (Keyword $keyword) {
//
});
static::updated(function (Keyword $keyword) {
if (GoalKeyword::getPropertiesCopyWithPivot()->first(function ($property_name) use ($keyword) {
return $keyword->{$property_name} !== $keyword->getOriginal($property_name);
})) {
$keyword->goalKeywords()->update(
GoalKeyword::copyPropertyFromMain($keyword)
);
}
if (self::getPropertiesWatch()->first(function ($property_name) use ($keyword) {
return $keyword->{$property_name} !== $keyword->getOriginal($property_name);
})) {
$keyword->goalKeywords()->update([
'updated_need' => Carbon::now(),
]);
}
});
}
public function goalKeywords()
{
return $this->hasMany(GoalKeyword::class, 'keyword_id');
}
public function group()
{
return $this->belongsTo(AdGroup::class, 'ad_group_id');
}
}
......@@ -68,6 +68,7 @@ class GoalAdGroup extends Pivot
'external_updated_at',
'updated_need',
'updated_self',
'keywords_loaded_at',
];
protected $casts = [
......@@ -80,6 +81,7 @@ class GoalAdGroup extends Pivot
'external_updated_at' => 'datetime',
'updated_need' => 'datetime',
'updated_self' => 'datetime',
'keywords_loaded_at' => 'datetime',
];
static public function getWithPivot()
......@@ -96,6 +98,7 @@ class GoalAdGroup extends Pivot
'external_updated_at',
'updated_self',
'updated_need',
'keywords_loaded_at',
];
}
......
......@@ -58,6 +58,7 @@ class CreateAdGroupsTable extends Migration
])->nullable();
$table->json('restricted_region_ids')->nullable();
$table->timestamp('updated_self')->nullable();
$table->timestamp('keywords_loaded_at')->nullable();
$table->timestamps();
......
......@@ -25,6 +25,7 @@ class CreateGoalAdGroupsTable extends Migration
$table->timestamp('external_updated_at')->nullable();
$table->timestamp('updated_need')->nullable();
$table->timestamp('updated_self')->nullable();
$table->timestamp('keywords_loaded_at')->nullable();
$table->timestamps();
......
<?php
use App\Models\Keyword;
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
class CreateKeywordsTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('keywords', function (Blueprint $table) {
$table->id();
$table->bigInteger('external_id')->nullable();
$table->bigInteger('ad_group_external_id')->nullable();
$table->bigInteger('ad_group_id')->unsigned();
$table->text('keyword')->nullable();
$table->string('user_param_1', 255)->nullable();
$table->string('user_param_2', 255)->nullable();
$table->bigInteger('bid')->nullable();
$table->bigInteger('context_bid')->nullable();
$table->enum('state', [
Keyword::STATE_OFF,
Keyword::STATE_ON,
Keyword::STATE_SUSPENDED,
])->nullable();
$table->enum('status', [
Keyword::STATUS_ACCEPTED,
Keyword::STATUS_DRAFT,
Keyword::STATUS_REJECTED,
Keyword::STATUS_UNKNOWN,
])->nullable();
$table->enum('serving_status', [
Keyword::SERVING_STATUS_ELIGIBLE,
Keyword::SERVING_STATUS_RARELY_SERVED,
])->nullable();
$table->json('statistics_search')->nullable();
$table->json('statistics_network')->nullable();
$table->timestamps();
$table->foreign('ad_group_id')->references('id')->on('ad_groups')
->cascadeOnDelete();
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::dropIfExists('keywords');
}
}
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
class CreateGoalKeywordsTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('goal_keywords', function (Blueprint $table) {
$table->id();
$table->bigInteger('external_id')->nullable();
$table->bigInteger('goal_ad_group_external_id')->nullable();
$table->bigInteger('goal_ad_group_id')->unsigned();
$table->bigInteger('keyword_id')->unsigned();
$table->timestamp('external_upload_at')->nullable();
$table->timestamp('external_updated_at')->nullable();
$table->timestamp('updated_need')->nullable();
$table->timestamps();
$table->foreign('ad_group_id')->references('id')->on('ad_groups')
->cascadeOnDelete();
$table->foreign('keyword_id')->references('id')->on('keywords')
->cascadeOnDelete();
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::dropIfExists('goal_keywords');
}
}
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!