Skema entitas akun iklan & stok BM Konco. Tabel utama: ads_accounts (akun iklan yang disewa member), stock_ads_accounts (inventaris), ads_account_fundings (history funding).
ads_accounts
Akun iklan yang sedang/sempat disewa member. Tabel pusat siklus subscription lifecycle.
| Field | Tipe | Catatan |
|---|
id | UUID (PK) | Via UUID trait |
stock_ads_account_id | UUID (FK) | → stock_ads_accounts.id |
member_bm_id | UUID (FK) | → member_bms.id |
expired | datetime | Tanggal akhir sewa — trigger reminder & auto-deactivation |
is_active | boolean | Status aktif (dipakai scopeActive) |
created_by | UUID | Diisi WithAuthor |
updated_by | UUID | Diisi WithAuthor |
deleted_at | datetime | Soft delete (SoftDeletes) |
created_at, updated_at | datetime | Timestamp Laravel |
Konstanta
php// app/Models/AdsAccount.php
const EXPIRED_BEFORE = 7; // hari sebelum expired — trigger reminder
const EXPIRED_AFTER = 4; // hari grace period — auto-deactivation
Relasi
| Method | Tipe | Target |
|---|
stock_ads_account() | BelongsTo | StockAdsAccount |
member_bm() | BelongsTo | MemberBm |
ads_account_business_managers() | HasMany | AdsAccountBusinessManager |
business_managers() | BelongsToMany | MemberBm via ads_account_business_managers |
order_subscribe() | BelongsTo | OrderSubscribe |
refund() | HasMany | Refund |
Scope penting
| Scope | Fungsi |
|---|
scopeActive($q, $member_id = null) | expired > today - 7, is_active=true, stock_ads_account aktif |
scopeDummy($q, $member_id = null) | expired null, stock_ads_account_id null, is_active=true |
scopeWhere_member($q, $member_id) | Filter by member_bm.member_id |
Accessor penting
| Accessor | Fungsi |
|---|
getGraceExpiredAttribute() | Return expired + 4 hari |
getGraceLimitAttribute() | Carbon::parse(expired)->addDays(4) |
getDaysUntilExpiredAttribute() | Selisih hari ke expired |
getStatusTextAttribute() | Status label |
stock_ads_accounts
Inventaris akun iklan — stok yang bisa disewakan ke member.
| Field | Tipe | Catatan |
|---|
id | UUID (PK) | |
stock_bm_id | UUID (FK) | → stock_bms.id |
ads_id | string | ID akun iklan Facebook |
name | string | Nama akun iklan |
account_status | integer | Cast integer |
currency | string | Mata uang |
timezone_name | string | Timezone |
balance | decimal:2 | Saldo riil Facebook |
amount_spent | decimal:2 | Total spend |
spend_cap | decimal:2 | Limit spend |
last_synced_at | datetime | Sync terakhir dari Meta |
sync_status | string | Status sync |
is_deleted | boolean | Soft delete flag |
is_active | boolean | Status stok |
meta_data | array | Cast JSON |
deleted_at | datetime | SoftDeletes |
created_by, updated_by, created_at, updated_at | — | Standar |
ads_account_fundings
History funding akun iklan (topup/withdraw/refund records).
| Field | Tipe | Catatan |
|---|
id | UUID (PK) | |
ads_account_id | UUID (FK) | → ads_accounts.id |
amount | decimal:2 | Nominal |
type | string | topup / withdraw / refund / transfer |
reference_id | UUID | Reference ke order/admin request |
description | text | Catatan |
created_by, updated_by, timestamps | — | Standar |
ads_account_business_managers
Pivot relasi akun iklan ↔ BM (many-to-many).
| Field | Tipe |
|---|
id | UUID (PK) |
ads_account_id | UUID (FK) |
member_bm_id | UUID (FK) |
created_at, updated_at | datetime |
ad_campaigns / ad_adsets / ad_ads
Cache hierarki Meta Campaigns → AdSets → Ads.
| Field | Tipe | Catatan |
|---|
id | UUID (PK) | |
ads_account_id | UUID (FK) | → ads_accounts.id |
campaign_id / adset_id / ad_id | string | ID Meta |
name | string | |
status | string | ACTIVE / PAUSED |
daily_budget / lifetime_budget | decimal:2 | |
insights | array | Cast JSON — cache metrik |
last_synced_at | datetime | |
| timestamps | — | |
ads_export_schedules
Jadwal export laporan iklan terjadwal.
| Field | Tipe | Catatan |
|---|
id | UUID (PK) | |
user_id | UUID (FK) | Pemilik jadwal |
ads_account_id | UUID (FK) | Akun yang di-export |
frequency | string | daily / weekly |
day_of_week | string | Untuk weekly — e.g. monday |
time | time | Jam export |
email | string | Tujuan email |
is_active | boolean | |
| timestamps | — | |
Dispatched by scheduler jam 07:00 via SendScheduledAdsExportJob.
user_ads_column_preferences
Preferensi kolom tampilan Ads Manager per user.
| Field | Tipe |
|---|
id | UUID (PK) |
user_id | UUID (FK) |
columns | array (JSON) |
| timestamps | — |
pixel_configurations
Konfigurasi pixel per akun iklan.
| Field | Tipe |
|---|
id | UUID (PK) |
ads_account_id | UUID (FK) |
pixel_id | string |
config | array (JSON) |
| timestamps | — |
Langkah berikutnya