# Mobile Unlock Service Platform - Quick Reference

## Quick Start (5 minutes)

### 1. Database Setup
```bash
# Create tables
php artisan migrate

# Add demo data
php artisan db:seed --class=UnlockServiceSeeder
```

### 2. Access Points
| Role | URL | Action |
|------|-----|--------|
| Shop | `/shop/register` | Create account |
| Shop | `/shop/login` | Login |
| Shop | `/shop/dashboard` | View stats |
| Shop | `/shop/orders/create` | Create order |
| Admin | `/admin/unlock-service/dashboard` | View analytics |
| Admin | `/admin/unlock-service/orders` | Manage orders |
| Admin | `/admin/unlock-service/users` | View shops |
| Admin | `/admin/unlock-service/payments` | Record payment |

## Service Types
- **FRP** - Factory Reset Protection unlock
- **iCloud** - Apple ID unlock
- **Network** - Carrier unlock
- **MDM** - Mobile Device Management unlock

## Order Status Flow
```
Pending → In Progress → Done
```

## Key Models
```php
ShopUser
  - shop_name
  - phone_number
  - password (hashed)
  - getBalance() // Returns due amount

UnlockOrder
  - customer_name
  - device_model
  - imei_number
  - service_type (enum)
  - status (enum)
  - service_price
  - note

ShopPayment
  - amount
  - payment_method
  - status (enum)
  - reference
```

## Authentication Guards
- `auth:shop` - Shop user
- `auth` + `admin` - Admin user
- `guest:shop` - For public shop pages

## Key Routes
```php
// Shop Routes
Route::post('shop/register')           // Register shop
Route::post('shop/login')              // Shop login
Route::get('shop/dashboard')           // Dashboard
Route::get('shop/orders')              // View orders
Route::post('shop/orders')             // Create order

// Admin Routes
Route::get('/admin/unlock-service/dashboard')      // Analytics
Route::get('/admin/unlock-service/orders')         // Orders list
Route::put('/admin/unlock-service/orders/{order}/status') // Update status
Route::get('/admin/unlock-service/users')          // Users list
Route::get('/admin/unlock-service/payments')       // Payments list
Route::post('/admin/unlock-service/payments')      // Record payment
```

## Database Queries

### Get all orders for a shop
```php
$orders = ShopUser::find($shopId)->unlockOrders;
```

### Get pending orders
```php
$pending = UnlockOrder::where('status', 'pending')->get();
```

### Calculate shop balance
```php
$balance = $shopUser->getBalance();
```

### Get all completed income
```php
$income = UnlockOrder::where('status', 'done')->sum('service_price');
```

## API Responses

### Order Creation
```json
{
  "success": true,
  "message": "Order submitted successfully!"
}
```

### Dashboard Stats
```json
{
  "stats": {
    "today_orders": 5,
    "pending_orders": 3,
    "completed_orders": 2,
    "total_income": 1500.00,
    "balance": 450.00
  }
}
```

## Common Tasks

### Register new shop
1. Go to `/shop/register`
2. Enter shop name, phone, password
3. Click register
4. Auto-login to dashboard

### Submit order as shop
1. Click "New Order"
2. Fill customer details
3. Select service type & price
4. Click "Submit Order"

### Manage order as admin
1. Go to `/admin/unlock-service/orders`
2. Click order to view details
3. Update status (pending → in progress → done)
4. Add note if needed

### Record payment as admin
1. Go to `/admin/unlock-service/payments`
2. Click "Record Payment"
3. Select shop, enter amount
4. Select payment method
5. Click save

## File Structure (Key Files)
```
app/Models/
  ├─ ShopUser.php
  ├─ UnlockOrder.php
  └─ ShopPayment.php

app/Http/Controllers/
  ├─ ShopAuthController.php
  ├─ ShopOrderController.php
  ├─ ShopDashboardController.php
  └─ Admin/
     ├─ UnlockServiceDashboardController.php
     ├─ AdminOrderController.php
     ├─ AdminPaymentController.php
     └─ AdminShopUserController.php

routes/
  ├─ web.php (shop routes)
  └─ admin.php (admin routes)

database/migrations/
  ├─ 2026_04_15_000001_create_shop_users_table.php
  ├─ 2026_04_15_000002_create_unlock_orders_table.php
  └─ 2026_04_15_000003_create_shop_payments_table.php

resources/js/Pages/
  ├─ Shop/Auth/{Login,Register}.vue
  ├─ Shop/{Dashboard,Orders/*}.vue
  └─ Admin/Pages/UnlockService/*.vue
```

## Troubleshooting

### Shop user can't login
- Check phone number is correct
- Verify password hash in database
- Check `auth:shop` guard in config/auth.php

### Orders not showing
- Verify shop_user_id is set correctly
- Check date format matches database

### Admin routes not working
- Ensure admin middleware is applied
- Check routes/admin.php has correct guards

## Performance Tips

- Use eager loading: `with('shopUser')`
- Index phone_number for faster lookups
- Cache dashboard stats for heavy traffic
- Paginate large order lists

## Testing

```bash
# Run migrations fresh
php artisan migrate:fresh

# Seed demo data
php artisan db:seed --class=UnlockServiceSeeder

# Test shop flow
# 1. /shop/register - Create account
# 2. /shop/orders/create - Create order
# 3. Login as admin
# 4. /admin/unlock-service/orders - View order
# 5. Update status to "done"
# 6. Shop user sees status change
```

## Next Steps

1. **Deploy to hosting** with domain name
2. **Add SMS notifications** - Notify shops of status changes
3. **Setup payment gateway** - eSewa/Khalti integration
4. **Add mobile app** - Native mobile app for shops
5. **Analytics** - Revenue reports, popular services
6. **Support system** - Help & dispute resolution

---

For full documentation, see `UNLOCK_SERVICE_SETUP.md`
