การตั้งค่าระบบ + Cron + APIs + Migrations
| ไฟล์ | หน้าที่ |
|---|---|
app_config.php | config public (อยู่ใน webroot) |
app_secret.php | secrets — นอก webroot ✅ |
db.php | เชื่อมต่อ MySQL |
smtp_config.php | SMTP server credentials |
line_config.php | LINE Bot channel access token |
lib/bootstrap.php | โหลด wide ทุก session |
ระบบใช้ PHPMailer ส่ง email สำหรับ: OTP, reset password, error alerts, broadcast
smtp_config.php<?php return [ 'host' => 'smtp.gmail.com', 'port' => 587, 'username' => '[email protected]', 'password' => 'xxxx xxxx xxxx xxxx', // App password 'encryption' => 'tls', 'from_email' => '[email protected]', 'from_name' => 'ThaibadTournaments', ];
หากใช้ Gmail ต้อง enable 2FA ก่อน → สร้าง App Password ที่ myaccount.google.com/apppasswords
เปิด test_error_monitor.php → จะส่ง test email ไป admin email
อ่านเอกสาร: Line_Admin_Setup.md, Line_Noti.md, Line_User_Guide.md
developers.line.bizline_config.php:
return [ 'channel_access_token' => 'xxxxx...', 'channel_secret' => 'xxxxx...', 'liff_id' => 'xxxxx-xxxxx', ];
https://thaibadtournaments.com/badminton/line_webhook.phpสำหรับ login ผ่าน LINE ในเว็บ — สร้าง LIFF app type=Full → URL ชี้ไปที่ auth_line.php
ระบบมี 2 cron jobs หลักที่ต้องตั้งใน server
*/3 * * * * curl -s -H "X-Cron-Secret: YOUR_SECRET" \ https://thaibadtournaments.com/badminton/cron_notify_matches.php \ >> /var/log/thaibad_cron.log 2>&1
0 6 * * * curl -s -H "X-Cron-Secret: YOUR_SECRET" \ "https://thaibadtournaments.com/badminton/admin_morning_broadcast.php?auto=1&date=TODAY"
0 3 * * 0 php /path/to/cleanup_old_logs.php
ตั้ง CRON_SECRET ใน app_secret.php → ใช้เป็น header X-Cron-Secret เพื่อกัน cron URL ถูกเรียกจากภายนอก
สำหรับการตรวจสลิปอัตโนมัติ
slipok.com → เลือกแพ็กเกจbranch_idapi_keyedit_match.php → ฟิลด์:
slipok_branch_idslipok_api_keypayment_account_name — ต้องตรงกับใน SlipOKlib/slipok.php ส่ง POST ไปยัง https://api.slipok.com/api/line/apikey/{branch_id} พร้อมรูปสลิป
1000 = ตรวจผ่าน1002 = ยอดไม่ตรง1003 = สลิปซ้ำ (duplicate)1010 = ชื่อผู้รับไม่ตรงai.google.dev → สร้าง API Keyapp_secret.php:
'GEMINI_API_KEY' => 'AIzaSy...',
gemini-2.5-flash-preview-tts + voice Kore (Thai)ระบบเก็บไฟล์เสียงใน /uploads/tts_cache/SHA256(text+voice).wav
admin_tts_cache.php → batch generateเมื่ออัปเดตระบบ — รัน migration scripts ใน root ของ project
| Script | เพิ่มอะไร |
|---|---|
migrate_2fa_tables.php | 2FA + backup codes |
migrate_payment_system.php | payment_mode, slipok, slip status |
migrate_clubs.php | clubs, members, banner_designs |
migrate_lockout.php | failed_login_attempts, lockout_until |
migrate_add_gender.php | users.gender (M/F) |
migrate_age_categories.php | available_age_categories JSON |
migrate_identity_verification.php | identity_verified + id_card_image |
migrate_errors_log.php | errors_log table |
migrate_line_chat_states.php | state machine ของ webhook |
migrate_line_link_pins.php | PIN 6 หลักผูก LINE |
migrate_notify_flags.php | notify_* flags ต่อ tournament |
migrate_calendar_province.php | filter จังหวัด |
migrate_calendar_map_url.php | Google Maps URL |
migrate_match_tab_visibility.php | tab_*_enabled flags |
migrate_match_permissions_role.php | per-tournament role |
migrate_tts_cache.php | tts_quota_daily + cache table |
migrate_cleanup_legacy_roles.php | cleanup เก่า ๆ |
ใช้ mysqldump backup ก่อนรันทุกครั้ง — ไม่มี rollback automatic
อ่านเอกสาร Real_time_Co_work.md
ตาราง editing_presence:
user_id, tournament_id, field_name, started_atmatch_order_api.php — GET ดู order + presence, POST update + lockschedule_api.php — build_pairings, auto_schedule, save_scheduleFrontend poll ทุก 2 วินาที — ไม่ใช้ WebSocket (เพื่อง่ายในการ host บน shared hosting)