PHP code example of tourze / lottery-bundle

1. Go to this page and download the library: Download tourze/lottery-bundle library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

tourze / lottery-bundle example snippets




use LotteryBundle\Service\LotteryService;
use LotteryBundle\Service\PrizeService;
use LotteryBundle\Entity\Chance;

// Execute lottery draw
$lotteryService = $container->get(LotteryService::class);
$result = $lotteryService->doLottery($chance);

// Count valid chances for user
$validChances = $lotteryService->countValidChance($user, $activity);

// Award chances to user
$lotteryService->giveChance($user, $chance);

// Prize management
$prizeService = $container->get(PrizeService::class);
$prizeService->sendPrize($chance);

// Check if activity is currently active
$isActive = $activity->isActive();

// Get available lottery templates
$templates = $lotteryService->getAvailableTemplates();

LotteryBundle\LotteryBundle::class => ['all' => true],

use LotteryBundle\Event\UserJoinSuccessEvent;
use LotteryBundle\Event\DecidePoolEvent;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;

class CustomLotterySubscriber implements EventSubscriberInterface
{
    public static function getSubscribedEvents(): array
    {
        return [
            UserJoinSuccessEvent::class => 'onUserJoinSuccess',
            DecidePoolEvent::class => 'onDecidePool',
        ];
    }

    public function onUserJoinSuccess(UserJoinSuccessEvent $event): void
    {
        // Send notification, award points, etc.
        $chance = $event->getChance();
        $this->notificationService->sendLotteryResult($chance);
    }

    public function onDecidePool(DecidePoolEvent $event): void
    {
        // Custom pool selection based on user VIP level
        $user = $event->getUser();
        if ($user->isVip()) {
            $event->setPool($this->getVipPool());
        }
    }
}

// Join lottery from external application
$result = $client->call('JoinLottery', [
    'activityId' => 1,
    'count' => 3, // Draw 3 times
]);

// Get user's lottery history
$history = $client->call('GetUserLotteryChanceList', [
    'page' => 1,
    'limit' => 20,
]);

// Check available chances
$chances = $client->call('GetUserValidLotteryChanceCounts', [
    'activityId' => 1,
]);
bash
php bin/console lottery:check-expire-chance
bash
php bin/console lottery:check-review-chance-send-prize