Files
hub/app/Http/Controllers/Seller/MarketingAutomationRunController.php
kelly 50bb3fce77 feat: add marketing automations / playbooks engine (Phase 6)
Adds the Marketing Automations system that allows sellers to create
automated marketing workflows triggered by CannaiQ intelligence data.

Features:
- Automation configuration with triggers (scheduled, manual)
- Condition evaluators (competitor OOS, slow mover, new store)
- Action executors (create promo, create campaign)
- Scheduled command and queued job execution
- Full CRUD UI with quick-start presets
- Run history tracking with detailed logs

Components:
- MarketingAutomation and MarketingAutomationRun models
- AutomationRunner service with extensible condition/action handlers
- RunDueMarketingAutomations command for cron scheduling
- RunMarketingAutomationJob for Horizon-backed execution
- Seller UI at /s/{business}/marketing/automations
2025-12-09 16:41:32 -07:00

67 lines
2.1 KiB
PHP

<?php
namespace App\Http\Controllers\Seller;
use App\Http\Controllers\Controller;
use App\Models\Business;
use App\Models\Marketing\MarketingAutomation;
use App\Models\Marketing\MarketingAutomationRun;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Auth;
class MarketingAutomationRunController extends Controller
{
public function index(Request $request, Business $business, MarketingAutomation $automation)
{
$this->authorizeForBusiness($business);
$this->ensureAutomationBelongsToBusiness($automation, $business);
$runs = MarketingAutomationRun::where('marketing_automation_id', $automation->id)
->when($request->status, fn ($q, $status) => $q->where('status', $status))
->orderBy('started_at', 'desc')
->paginate(25);
return view('seller.marketing.automations.runs.index', compact(
'business',
'automation',
'runs'
));
}
public function show(Request $request, Business $business, MarketingAutomation $automation, MarketingAutomationRun $run)
{
$this->authorizeForBusiness($business);
$this->ensureAutomationBelongsToBusiness($automation, $business);
$this->ensureRunBelongsToAutomation($run, $automation);
return view('seller.marketing.automations.runs.show', compact(
'business',
'automation',
'run'
));
}
protected function authorizeForBusiness(Business $business): void
{
$user = Auth::user();
if (! $user->businesses->contains($business->id) && ! $user->hasRole('Super Admin')) {
abort(403, 'Unauthorized access to this business.');
}
}
protected function ensureAutomationBelongsToBusiness(MarketingAutomation $automation, Business $business): void
{
if ($automation->business_id !== $business->id) {
abort(404);
}
}
protected function ensureRunBelongsToAutomation(MarketingAutomationRun $run, MarketingAutomation $automation): void
{
if ($run->marketing_automation_id !== $automation->id) {
abort(404);
}
}
}