۱۵ — قوانین تخفیف (Discount)
۱. انواع
| type | value | example |
|---|---|---|
percent | 0–100 | 20% off |
fixed | toman | 10,000 off |
۲. Scope
| scope | vendor_id | who creates |
|---|---|---|
platform | null | admin |
vendor | required | admin or vendor (MVP: admin only) |
۳. Validation rules (به ترتیب)
is_active == truenowbetweenvalid_fromandvalid_tousage_count < usage_limit_total(if set)- user usage <
usage_limit_per_user(if set) order.subtotal >= min_order_amount(if set)- if vendor scope → order.vendor_id matches
- compute discount:
- percent:
min(subtotal * rate, max_discount_amount) - fixed:
min(value, subtotal)
- percent:
total = subtotal - discount(min 0)
۴. Stacking
MVP: one code per order — no stack
۵. Application timing
| When | allowed |
|---|---|
| Before payment | ✅ |
| After paid | ❌ |
۶. Examples
| Code | Type | Value | Min order | Result on 65K |
|---|---|---|---|---|
| WELCOME20 | percent | 20 | 50K | 52,000 |
| FIRST10K | fixed | 10K | 60K | 55,000 |
| VIP30 | percent | 30 | — | 45,500 |
۷. Admin UI fields
- code (uppercase auto)
- scope, vendor picker
- type, value
- min_order_amount, max_discount_amount
- usage_limit_total, usage_limit_per_user
- valid_from, valid_to
- is_active toggle
۸. Abuse prevention
- normalize code: trim, uppercase
- rate limit validate endpoint
- log failed attempts
- deactivate after N fraud flags (v2)
۹. Reporting
- usage_count per code
- total discount given (GMV impact)
- orders with discount vs without