feat: add multiple hooks, pligun schedule support ,add hook:list artisan command

This commit is contained in:
xboard
2025-07-21 13:29:17 +08:00
parent 768e14bdb9
commit c9bab8fb02
16 changed files with 271 additions and 75 deletions
@@ -10,16 +10,21 @@ use App\Services\OrderService;
use App\Services\PaymentService;
use App\Services\TelegramService;
use Illuminate\Http\Request;
use App\Services\Plugin\HookManager;
class PaymentController extends Controller
{
public function notify($method, $uuid, Request $request)
{
HookManager::call('payment.notify.before', [$method, $uuid, $request]);
try {
$paymentService = new PaymentService($method, null, $uuid);
$verify = $paymentService->notify($request->input());
if (!$verify)
if (!$verify) {
HookManager::call('payment.notify.failed', [$method, $uuid, $request]);
return $this->fail([422, 'verify error']);
}
HookManager::call('payment.notify.verified', $verify);
if (!$this->handle($verify['trade_no'], $verify['callback_no'])) {
return $this->fail([400, 'handle error']);
}
@@ -14,6 +14,7 @@ use App\Services\TicketService;
use App\Utils\Dict;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\DB;
use App\Services\Plugin\HookManager;
class TicketController extends Controller
{
@@ -65,6 +66,7 @@ class TicketController extends Controller
throw new \Exception(__('Failed to open ticket'));
}
DB::commit();
HookManager::call('ticket.create.after', $ticket);
$this->sendNotify($ticket, $request->input('message'), $request->user()->id);
return $this->success(true);
}catch(\Exception $e){
@@ -103,6 +105,7 @@ class TicketController extends Controller
)) {
return $this->fail([400, __('Ticket reply failed')]);
}
HookManager::call('ticket.reply.user.after', [$ticket, $this->getLastMessage($ticket->id)]);
$this->sendNotify($ticket, $request->input('message'), $request->user()->id);
return $this->success(true);
}
+16 -15
View File
@@ -2,35 +2,36 @@
namespace App\Http\Middleware;
use App\Models\Plugin;
use App\Services\Plugin\PluginManager;
use Closure;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Log;
/**
* Middleware to initialize all enabled plugins at the beginning of a request.
* It ensures that all plugin hooks, routes, and services are ready.
*/
class InitializePlugins
{
protected $pluginManager;
protected PluginManager $pluginManager;
public function __construct(PluginManager $pluginManager)
{
$this->pluginManager = $pluginManager;
}
/**
* Handle an incoming request.
*
* @param \Illuminate\Http\Request $request
* @param \Closure $next
* @return mixed
*/
public function handle(Request $request, Closure $next)
{
try {
$plugins = Plugin::query()
->where('is_enabled', true)
->get();
foreach ($plugins as $plugin) {
$this->pluginManager->enable($plugin->code);
}
} catch (\Exception $e) {
Log::error('Failed to load plugins: ' . $e->getMessage());
}
// This single method call handles loading and booting all enabled plugins.
// It's safe to call multiple times, as it will only run once per request.
$this->pluginManager->initializeEnabledPlugins();
return $next($request);
}
}
}