28 lines
1.3 KiB
PHP
28 lines
1.3 KiB
PHP
<?php
|
|
namespace Plugin\VipLoyalty;
|
|
use App\Services\Plugin\AbstractPlugin;
|
|
use Illuminate\Support\Facades\{Log,Schema};
|
|
use Illuminate\Validation\ValidationException;
|
|
final class Plugin extends AbstractPlugin {
|
|
public function boot(): void {
|
|
if(!Schema::hasTable('fuc_vip_accounts'))return;
|
|
$service=app(Service::class);
|
|
try {$enabled=$service->enabled();}
|
|
catch(ValidationException $e) {
|
|
// An enabled but corrupt policy must not silently lose paid consumption.
|
|
// Hooks below reject new creation/opening until an administrator repairs it.
|
|
Log::warning('vip_loyalty_invalid_configuration');$enabled=true;
|
|
}
|
|
if(!$enabled){$service->suspend();return;}
|
|
$this->listen('order.create.before',static function($payload)use($service){$service->sync($payload[0]->id);});
|
|
if (Schema::hasTable('fuc_order_discounts')) {
|
|
$this->listen('order.create.after', [app(OrderDiscounts::class), 'record']);
|
|
}
|
|
$this->listen('order.open.before',[$service,'openingOrder']);
|
|
$this->listen('admin.user.update.after',[$service,'manualChanged']);
|
|
}
|
|
public function cleanup(): void {
|
|
if(Schema::hasTable('fuc_vip_accounts'))app(Service::class)->suspend();
|
|
}
|
|
}
|