Hệ thống quản trị Affiliate tập trung cho team vận hành (Owner/Leader/Partner), tối ưu cho:
- Quản lý tracking link và attribution
- Đồng bộ dữ liệu từ nền tảng (Shopee)
- Theo dõi click, đơn hàng, hoa hồng, payout
- Quản trị cảnh báo hệ thống + Telegram per-user
- Hỗ trợ AI Content Studio cho chiến dịch
| Dashboard | Tracking Links |
|---|---|
![]() |
| AI Content Studio | Alert Center |
|---|---|
![]() |
![]() |
| Integrations |
|---|
![]() |
- Production-ready:
Shopee - Multi-platform ready (kiến trúc mở rộng):
Lazada,TikTok(chưa có adapter sync chính thức)
open_api: dùng Open API (full discovery cho Offers)cookie: dùng cURL profile/cookie (item lookup ổn định cho Offers + sync API portal)portal_export: import file portal (không dùng cho discovery ở màn Offers)
Hệ thống đi theo service-oriented architecture trong Laravel:
flowchart LR
A[Vue 3 + Inertia Pages] --> B[Laravel Controllers]
B --> C[Services Layer]
C --> D[Repository Layer]
D --> E[(MySQL)]
C --> F[Jobs / Queue]
F --> G[(Redis)]
F --> E
C --> H[Shopee APIs]
app/Http/Controllers: điều phối request/response, không chứa business logic nặngapp/Services: business rules, orchestration, validation theo domainapp/Repositories/Eloquent: query/pagination/aggregateapp/Jobs: sync, aggregate, background tasksapp/Models: entity + cast + relation
- Session auth + CSRF cho
/api/*(quawebmiddleware) - Correlation Request ID (
X-Request-ID) - Security headers + CSP config-driven
- Trusted Host protection
- Audit logging cho action quan trọng
- Redaction dữ liệu nhạy cảm trong audit
- Authorization Policies cho Orders, AlertRules, PayoutBatches, PlatformConnections (IDOR prevention)
- Scraper SSRF hardening: domain allowlist (Shopee/Lazada/TikTok) + HTTPS-only + private IP CIDR blocklist
- Image upload hardening: MIME validation +
getimagesize()signature check + private disk storage - Payout finalize locking:
lockForUpdate()trên cả batch row và sub-items để đảm bảo tổng chính xác
- PHP
^8.4 - Laravel
^12 - Inertia Laravel
^2 - Repository pattern (
prettus/l5-repository) - Redis (
predis/predis) cho queue/cache/lock
- Vue 3 + Inertia.js
- Vite + Tailwind CSS v4
- ApexCharts, flatpickr, tom-select
- Docker Compose:
app,web (nginx),mysql,redis,worker-sync,scheduler,mailpit
- Login/Register/Forgot/Reset password
- Google OAuth login
- Profile + payout profile update
- KPI click/order/commission
- Summary API theo scope role
- Cache và global filters
- CRUD, archive, detail
- Refresh product info
- Attribution metadata
- List + global stats
- Sync campaign từ Shopee
- Deep-link sang Tracking Links
- Filter theo trạng thái/sàn/kỳ/search
- CSV import (queue-based)
- Mapping attribution từ sub_id/product
- Overview / Click report / Conversion report
- Aggregate daily stats (scheduled)
- Export endpoint
- Quản lý connection (open_api/cookie/portal_export)
- Test connection, sync manual, sync history
- Scheduled sync dispatch
- Search offers (theo mode connection)
- Offer detail
- Get tracking link từ offer
- Cookie mode: item lookup (item_id/URL Shopee)
- Billing/payout summary
- Sync payment data
- Payout batches + finalize (với
lockForUpdateđảm bảo totals chính xác) - Payout approval API (state machine: Pending → Approved/Rejected)
- FormRequest validation cho mọi input tài chính
- Rule-based alert center (Policy-protected per-user)
- Incident lifecycle (seen/resolve/comment)
- Template system (In-app + Telegram)
- Telegram config theo từng user (không dùng global env runtime)
- Content Studio cho tracking link
- History/statistics/generation status
- AI provider settings per-user
- Manual sync: người dùng bấm
Sync Now - Scheduled sync: job
DispatchScheduledSyncsJobquét connectionsync_mode=scheduled - Mutex lock per connection để chống chạy chồng job
- Lần đầu (chưa có
last_sync_at): backfill theoSHOPEE_BACKFILL_DAYS - Các lần sau: incremental sync với overlap
SYNC_INCREMENTAL_OVERLAP_HOURS - Có hard limit bởi
SHOPEE_HARD_LIMIT_DAYS
completedcompleted_with_warningsfailed_auth/failed_api/failed_validationrate_limitedskipped_locked/skipped_disabled
- Docker + Docker Compose
- Node.js 20+ (để chạy Vite trên host nếu cần)
cp .env.example .env
docker compose up -d --build
docker compose exec app composer install
docker compose exec app php artisan key:generate
docker compose exec app php artisan migrate --force
docker compose exec app php artisan db:seed --force
npm install
npm run devworker-sync và scheduler đã được khai báo trong docker-compose.yml và chạy nền cùng stack.
- App: http://localhost:8000
- Mailpit: http://localhost:8025
- Email: giá trị
SEED_ADMIN_EMAILtrong.env(defaultadmin@affentra.com) - Password:
SEED_ADMIN_PASSWORD(defaultpassword)
Yêu cầu có sẵn MySQL + Redis cục bộ.
cp .env.example .env
composer install
php artisan key:generate
php artisan migrate
php artisan db:seed
npm installChạy các tiến trình:
php artisan serve
php artisan queue:work --sleep=1 --tries=3 --timeout=120 --memory=256 --no-interaction
php artisan schedule:work
npm run devHoặc dùng script:
composer run devAPP_URL,APP_ENV,APP_DEBUGDB_*,REDIS_*,QUEUE_CONNECTION,CACHE_STORE
INTEGRATIONS_ENABLE_COOKIE_METHODSHOPEE_AFFILIATE_API_URLSHOPEE_SYNC_MODESHOPEE_BACKFILL_DAYSSHOPEE_HARD_LIMIT_DAYSSHOPEE_OFFER_CACHE_TTLSHOPEE_CAMPAIGN_SYNC_ATSYNC_INTERVAL_MINUTESSYNC_INCREMENTAL_OVERLAP_HOURSSYNC_LOCK_TTLSYNC_UPSERT_CHUNK
SECURITY_CSP_ENABLEDSECURITY_CSP_REPORT_ONLYSECURITY_CSP_DEV_ORIGINSSECURITY_HSTS_*
ALERT_EVALUATION_INTERVAL_MINUTESALERT_TELEGRAM_BOT_TOKEN/ALERT_TELEGRAM_CHAT_ID: deprecated (giữ comment, không dùng runtime)
/dashboard,/links,/campaigns,/orders,/partners,/integrations,/offers,/finance,/alerts,/ai/content,/settings/ai,/profile
dashboard/*links/*campaigns/*orders/*partners/*integrations/*offers/*analytics/clicks/*alerts/*finance/*,payout-batches/*,payout-approvals/*links/{trackingLink}/content/*,content-generations/*,ai/settings/*tools/scrape-product(SSRF-hardened, throttle 10/min)images/upload(private disk, signature check, throttle 20/min)ai/images/{filename}(serve private upload vớiContent-Disposition: inline)
Chạy test suite:
php artisan testChạy nhóm test cụ thể:
# Security tests
php artisan test tests/Feature/Tools/ScraperSecurityTest.php
php artisan test tests/Feature/Tools/ImageUploadSecurityTest.php
# Finance tests
php artisan test tests/Feature/Finance/PayoutBatchTest.php
php artisan test tests/Feature/PayoutApprovalTest.php
# Authorization
php artisan test tests/Feature/TrackingLinkAuthorizationTest.phpBuild frontend production:
npm run buildKiểm tra failed jobs:
php artisan queue:failed- Đảm bảo
.envcó:SECURITY_CSP_ENABLED=trueSECURITY_CSP_REPORT_ONLY=false(hoặc true để quan sát)SECURITY_CSP_DEV_ORIGINS=http://localhost:5173,http://127.0.0.1:5173
- Vite URL mặc định:
http://[::1]:5173
- Đây là soft-block từ Shopee endpoint cookie mode
- Cập nhật lại cURL profile đúng endpoint (dashboard/report/click/campaign/offer product)
- Test connection sẽ báo usable nếu còn endpoint pass hoặc soft-block có thể recover
- Kiểm tra
worker-sync+schedulercontainer đang up - Kiểm tra lock key Redis nếu nghi stuck
- Kiểm tra bảng
sync_runsvàplatform_connections.last_sync_status
- Cookie mode chỉ hỗ trợ item lookup
- Input phải là
item_idhoặc URL Shopee parse được item connection_idlà bắt buộc (không auto pick)
app/
Http/
Controllers/
Middleware/
Jobs/
Models/
Repositories/Eloquent/
Services/
config/
database/
docs/
architecture/
design/
runbooks/
resources/js/
Pages/
routes/
- Kiến trúc & contract:
docs/architecture/01-audit-contracts-and-plan.md - Runbook sync click:
docs/runbooks/click-sync-v5.md - UI checklist:
docs/design/phase2-ui-design-checklist.md
- Multi-platform adapters (Lazada/TikTok)
- Nâng cấp observability và báo cáo hiệu năng truy vấn
- Mở rộng automation và rules engine cho alert/payout



