SurePhone ERD — Domain 1b: Business Settings (ตั้งค่าในบ้าน · AD11)

ตั้งค่าระดับกิจการ (admin แต่ละบ้านแก้เอง): รูปปก login/OTP, สี UI, script ติดตาม, รายละเอียดคืนเครื่อง, รูปตัวอย่างประกอบฟอร์ม terms (เงื่อนไขการให้บริการ) อยู่ org.terms_and_conditions (versioned, ใช้ทั้งร้าน+ลูกค้า) schema = org · audit/r2_file อยู่ 00-shared


DBML

//// audit_c, audit_cu + sys.r2_file นิยามใน 00-shared.dbml · org.businesses ใน 01-org-access.md
 
Enum org.form_type {
  "CONTRACT"   [note: 'ฟอร์มสร้างสัญญา']
  "CLOSE_CASE" [note: 'ฟอร์มปิดเคส']
}
 
//// ───────── org: ตั้งค่าระดับกิจการ (AD11) ─────────
Table org.business_settings {
  business_id uuid [pk, note: '1:1 กับ org.businesses — singleton ต่อบ้าน']
 
  // รูปปก (AD11.1)
  login_cover_file_id uuid [note: 'FK → sys.r2_file · รูปปกหน้า login ร้าน (public)']
  otp_cover_file_id uuid [note: 'FK → sys.r2_file · รูปปกหน้ายืนยัน OTP (public)']
 
  // สี UI (AD11.2)
  primary_color varchar(7) [not null, default: '#E65100', note: 'สีหลัก (ส่วนหัว) hex #RRGGBB']
  secondary_color varchar(7) [not null, default: '#1A237E', note: 'สีรอง (ปุ่ม/หัวข้อ pop-up) hex']
 
  // ข้อความ (ไม่มีเวอร์ชัน)
  tracking_script text [note: 'สคริปต์ติดตามลูกค้า (AD11.4) — ไม่มี version']
  device_return_detail text [note: 'รายละเอียดขั้นตอนคืนอุปกรณ์ — ไม่มี version']
 
  ~audit_cu
 
  checks {
    `primary_color ~ '^#[0-9A-Fa-f]{6}$'`
    `secondary_color ~ '^#[0-9A-Fa-f]{6}$'`
  }
  Note: 'ตั้งค่าระดับกิจการ (AD11) — 1 แถวต่อบ้าน · terms แยกไป org.terms_and_conditions (versioned)'
}
Ref fk_bizsettings_business: org.business_settings.business_id > org.businesses.id [delete: cascade, update: no action]
Ref fk_bizsettings_login_cover: org.business_settings.login_cover_file_id > sys.r2_file.id [delete: set null, update: no action]
Ref fk_bizsettings_otp_cover: org.business_settings.otp_cover_file_id > sys.r2_file.id [delete: set null, update: no action]
 
Table org.form_example_images {
  id serial [pk]
  business_id uuid [not null]
  form_type org.form_type [not null, note: 'ฟอร์มที่รูปนี้ใช้ประกอบ']
  slot_key varchar(50) [not null, note: 'รหัสช่อง เช่น box_back, occupation_proof, device_condition, device_detail, device_general']
  label varchar(255) [not null, note: 'ป้ายช่อง เช่น "รูปหลังกล่องสินค้า"']
  file_id uuid [not null, note: 'FK → sys.r2_file (รูปตัวอย่าง, public)']
  ~audit_cu
 
  indexes {
    (business_id, form_type, slot_key) [name: 'idx_form_example_slot', unique]
  }
  Note: 'รูปตัวอย่างประกอบการกรอกฟอร์ม (สร้างสัญญา/ปิดเคส) ราย slot — ต่อบ้าน · admin จัดการ (AD11.1)'
}
Ref fk_form_example_business: org.form_example_images.business_id > org.businesses.id [delete: cascade, update: no action]
Ref fk_form_example_file: org.form_example_images.file_id > sys.r2_file.id [delete: restrict, update: no action]

Mermaid ER

erDiagram
  businesses ||--|| business_settings : "ตั้งค่า (1:1)"
  businesses ||--o{ form_example_images : "รูปตัวอย่างฟอร์ม"
  r2_file ||--o{ business_settings : "ปก login/OTP"
  r2_file ||--o{ form_example_images : "รูปตัวอย่าง"

  business_settings {
    uuid business_id PK
    uuid login_cover_file_id FK
    uuid otp_cover_file_id FK
    varchar primary_color
    varchar secondary_color
    text tracking_script
    text device_return_detail
    varchar created_by
    varchar updated_by
    timestamptz created_at
    timestamptz updated_at
  }
  form_example_images {
    serial id PK
    uuid business_id FK
    enum form_type
    varchar slot_key
    varchar label
    uuid file_id FK
  }

✅ Resolved (AD11) — 16 มิ.ย. 2026

  • รูปปก login + OTP → business_settings.login_cover_file_id / otp_cover_file_id
  • สี UI → primary_color / secondary_color (hex + check)
  • script ติดตาม + รายละเอียดคืนเครื่อง → text (ไม่มี version)
  • รูปประกอบฟอร์ม (สร้างสัญญา/ปิดเคส) → form_example_images ราย slot (form_type + slot_key)
  • terms “เงื่อนไขการให้บริการ” ใช้ทั้งร้าน+ลูกค้า → org.terms_and_conditions type=TERMS_OF_SERVICE (versioned)

❓ ยังค้าง

  • slot_key มาตรฐานของแต่ละฟอร์ม (เก็บเป็น seed/lookup ไหม) — ตอนนี้ free text + label
  • AD13.2 “ข้อมูลบริการ” 8 หมวด (เปลี่ยนวันชำระ/ผู้ถือ/…) ยังไม่ทำ — อาจเป็น terms อีกชุดหรือ config แยก