D
Engineering

customers

Skema koleksi customers — kontak pelanggan, tags array, address vs addresses dual field, SoftDeletes.

Kontak pelanggan per store. SoftDeletes aktif. Inkonsistensi address vs addresses dan tipe tags (string vs UUID).

Definisi model

app/Models/Customer.php

PropertiNilaiSumber
Collectioncustomers (diverifikasi via Rule::unique('customers', 'wa'))ContactController.php:191,588,1883
$guarded[]Customer.php:15
SoftDeletesCustomer.php:13
Casts❌ (commented out)Customer.php:20-22// 'tags' => 'array'
Primary keyUUID stringCustomer.php:16-18,24-30

Field

FieldTipeDefaultSumber
idstring UUIDgeneratedCustomer.php:28
namestringContactController.php:217, OrderController.php:1989
emailstring/nullnullContactController.php:217, ShortlinkController.php:240
wastring (+62.../62...)ContactController.php:207,631,1896, OrderController.php:1988
store_idstringContactController.php:208, OrderController.php:1990 (scope tenant)
addressesobject/nullnullContactController.php:209,633,1897
other_addressesobject/nullnull:1898
addressstring/nullnullShortlinkController.php:243 legacy
otherarray[]ContactController.php:210, OrderController.php:1991
segment_idstring/nullnullContactController.php:211,635,1613,1655,1992
profilepicstring/nullnullContactController.php:212,635, OrderController.php:1993
latest_contactstring/nullnullContactController.php:213,636, OrderController.php:1994
categorystring'private'ContactController.php:214,637 ('private'/'group')
tagsarray (string/UUID)[]ContactController.php:215,638,1902,1693,983, OrderController.php:1996
typestring'Customer'ContactController.php:216,628,639, OrderController.php:1997
cityobject/nullnullShortlinkController.php:247
subdistrictobject/nullnullShortlinkController.php:248
provinceobject/nullnullShortlinkController.php:250
statusstring'active'ContactController.php:1988,1990,2033,2037 ('active'/'archive')
ratingintegerContactController.php:2095
deleted_atdatetimeSoftDeletes
created_atdatetimeauto
updated_atdatetimeauto

Relasi

NamaTipeFKSumber
ordershasManyOrder.customer_ididCustomer.php:33-35
broadcast_submit_loghasManyBroadcastLog.customer_idid:37-39
segmentbelongsToSegment.idsegment_id:41-43
productbelongsToProduct.idproduct_id:45-47 (select name only)
chatsmanual queryChatList.where('customer_id', $id).orWhere('nohp', $wa):49-55
latestChatfirstchats()->orderBy('waktu','desc')->first():57-59

Index & constraint

  • Tidak ada index di model
  • Validation: Rule::unique('customers', 'wa')->where('store_id', $store->id) di ContactController.php:191,588,1883validasi aplikasi, bukan DB constraint. Race condition bisa bocor.
  • Primary key: UUID string

Contoh dokumen

json
{
  "_id": ObjectId("..."),
  "id": "uuid-customer",
  "wa": "+6281234567890",
  "name": "Budi",
  "store_id": "<store.id>",
  "other": [],
  "segment_id": null,
  "profilepic": null,
  "latest_contact": null,
  "category": "private",
  "tags": ["<tag.id-1>", "<tag.id-2>"],
  "type": "Customer",
  "status": "active",
  "rating": 0,
  "created_at": ISODate("..."),
  "updated_at": ISODate("...")
}

Seeder

  • RefactorTagInCustomer.php — migrasi tags dari string ke UUID
  • CustomerJsonSeeder.php — export ke JSON
  • ImportCustomerTagsSeeder.php — re-import tags

Referensi

  • Kontak Module — fitur dari sisi user
  • app/Models/Customer.php — model
  • app/Http/Controllers/ContactController.php — controller 2.403 baris