PHPackages                             tourze/campaign-bundle - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Admin Panels](/categories/admin)
4. /
5. tourze/campaign-bundle

ActiveSymfony-bundle[Admin Panels](/categories/admin)

tourze/campaign-bundle
======================

Symfony bundle for managing campaigns, awards, and user rewards system

0.0.1(6mo ago)01MITPHPPHP ^8.1CI failing

Since Nov 18Pushed 4mo ago1 watchersCompare

[ Source](https://github.com/tourze/campaign-bundle)[ Packagist](https://packagist.org/packages/tourze/campaign-bundle)[ RSS](/packages/tourze-campaign-bundle/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (1)Dependencies (44)Versions (2)Used By (0)

Campaign Bundle
===============

[](#campaign-bundle)

[English](README.md) | [中文](README.zh-CN.md)

\[[![Latest Version](https://camo.githubusercontent.com/19719276b60ad04975a8dde299eee10daa83ae028d834a3418b0865f338a6f98/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f746f75727a652f63616d706169676e2d62756e646c652e7376673f7374796c653d666c61742d737175617265)](https://camo.githubusercontent.com/19719276b60ad04975a8dde299eee10daa83ae028d834a3418b0865f338a6f98/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f746f75727a652f63616d706169676e2d62756e646c652e7376673f7374796c653d666c61742d737175617265)\] () \[[![PHP Version Require](https://camo.githubusercontent.com/31a86c49986dd14b145a10fd7778f177c4375b8d35315a9d3c6256049e6bd7fe/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f7068702d762f746f75727a652f63616d706169676e2d62756e646c653f7374796c653d666c61742d737175617265)](https://camo.githubusercontent.com/31a86c49986dd14b145a10fd7778f177c4375b8d35315a9d3c6256049e6bd7fe/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f7068702d762f746f75727a652f63616d706169676e2d62756e646c653f7374796c653d666c61742d737175617265)\] () \[[![License](https://camo.githubusercontent.com/ccb75e29c53d32a21928dec0de6386ad6e5ebf2df82b582555ae2308176b091f/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f6c2f746f75727a652f63616d706169676e2d62756e646c653f7374796c653d666c61742d737175617265)](https://camo.githubusercontent.com/ccb75e29c53d32a21928dec0de6386ad6e5ebf2df82b582555ae2308176b091f/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f6c2f746f75727a652f63616d706169676e2d62756e646c653f7374796c653d666c61742d737175617265)\] () \[[![Build Status](https://camo.githubusercontent.com/3c75cbf80739d3f42836bab035102123295320544fd5b4157e0fec7fc34b2780/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f746f75727a652f7068702d6d6f6e6f7265706f2f63692e796d6c3f6272616e63683d6d6173746572267374796c653d666c61742d737175617265)](https://camo.githubusercontent.com/3c75cbf80739d3f42836bab035102123295320544fd5b4157e0fec7fc34b2780/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f746f75727a652f7068702d6d6f6e6f7265706f2f63692e796d6c3f6272616e63683d6d6173746572267374796c653d666c61742d737175617265)\] () \[[![Coverage Status](https://camo.githubusercontent.com/d6a17333451b8d30e97db2783ce76e13c022ac7ec9626122a1939a04caac430a/68747470733a2f2f696d672e736869656c64732e696f2f636f766572616c6c732f6769746875622f746f75727a652f7068702d6d6f6e6f7265706f2f6d61737465723f7374796c653d666c61742d737175617265)](https://camo.githubusercontent.com/d6a17333451b8d30e97db2783ce76e13c022ac7ec9626122a1939a04caac430a/68747470733a2f2f696d672e736869656c64732e696f2f636f766572616c6c732f6769746875622f746f75727a652f7068702d6d6f6e6f7265706f2f6d61737465723f7374796c653d666c61742d737175617265)\] ()

A comprehensive campaign management bundle for Symfony applications, supporting various marketing campaign types including lottery events, coupon distribution, and credit rewards with flexible participation rules and automated lifecycle management.

Table of Contents
-----------------

[](#table-of-contents)

- [Features](#features)
- [Installation](#installation)
- [Configuration](#configuration)
- [Commands](#commands)
- [Usage](#usage)
- [Core Components](#core-components)
- [Dependencies](#dependencies)
- [Advanced Usage](#advanced-usage)
- [Contributing](#contributing)
- [License](#license)

Features
--------

[](#features)

- **Comprehensive Campaign Management**: Support for various marketing campaigns with configurable participation rules
- **Flexible Reward System**: Configurable rewards including coupons, credits, SKU/SPU purchase qualifications
- **Smart Limitation System**: Daily, weekly, monthly, quarterly, yearly, and total limits for reward distribution
- **User Participation Tracking**: Complete event logging and user interaction tracking with context data
- **Automated Lifecycle Management**: Built-in commands for campaign and user chance expiration
- **EasyAdmin Integration**: Ready-to-use admin interface for campaign management
- **JSON-RPC API**: 7 comprehensive API endpoints for campaign operations
- **Expression Language Support**: Configurable participation conditions using Symfony Expression Language
- **Extensible Architecture**: Easy to extend with custom reward types and limitation rules

Installation
------------

[](#installation)

```
composer require tourze/campaign-bundle
```

Configuration
-------------

[](#configuration)

Add the bundle to your `bundles.php`:

```
return [
    // ... other bundles
    CampaignBundle\CampaignBundle::class => ['all' => true],
];
```

Commands
--------

[](#commands)

The bundle provides several console commands for campaign management:

### `campaign:chance-expire`

[](#campaignchance-expire)

Automatically processes expired user chances/opportunities in campaigns.

```
php bin/console campaign:chance-expire
```

This command runs every minute via cron job to:

- Find expired user chances
- Mark them as invalid
- Update expiration remarks

### `campaign:check-expired-campaign`

[](#campaigncheck-expired-campaign)

Automatically disables campaigns that have passed their end time.

```
php bin/console campaign:check-expired-campaign
```

This command runs every minute via cron job to:

- Find campaigns past their end time
- Mark them as invalid
- Ensure proper campaign lifecycle management

Usage
-----

[](#usage)

### Basic Campaign Creation

[](#basic-campaign-creation)

```
use CampaignBundle\Entity\Campaign;
use CampaignBundle\Entity\Award;
use CampaignBundle\Enum\AwardType;
use CampaignBundle\Enum\AwardLimitType;

// Create campaign
$campaign = new Campaign();
$campaign->setCode('SUMMER2024');
$campaign->setName('Summer Sale');
$campaign->setStartTime(new \DateTime('2024-07-01'));
$campaign->setEndTime(new \DateTime('2024-07-31'));
$campaign->setValid(true);

// Add coupon reward
$award = new Award();
$award->setCampaign($campaign);
$award->setEvent('join');
$award->setType(AwardType::COUPON);
$award->setValue('COUPON_CODE_001');
$award->setPrizeQuantity(1000);
$award->setAwardLimitType(AwardLimitType::BUY_TOTAL);
$award->setTimes(1);
```

### Setting Participation Conditions

[](#setting-participation-conditions)

```
// Configure participation expression
$campaign->setRequestExpression('
    user.getCreatedAt() < date("-30 days")
    and user.hasTag("VIP")
');
```

### JSON-RPC API

[](#json-rpc-api)

The bundle provides 7 JSON-RPC procedures for API integration:

- `RequestCampaignChance`: Request participation opportunity in a campaign
- `ConsumeCampaignChance`: Consume a campaign opportunity and receive rewards
- `GetCampaignConfig`: Retrieve complete campaign configuration
- `GetCampaignCategoryList`: Get campaign categories with pagination
- `GetCampaignRewards`: Retrieve user's rewards from specific campaign
- `GetCampaignEventLogs`: Retrieve campaign event logs with filtering
- `ReportCampaignEventLog`: Report user events in campaign

#### Example API Usage

[](#example-api-usage)

```
// Request participation chance
$response = $jsonRpcClient->call('RequestCampaignChance', [
    'campaignCode' => 'SUMMER2024'
]);

// Consume chance and get reward
$response = $jsonRpcClient->call('ConsumeCampaignChance', [
    'chanceId' => $chanceId,
    'event' => 'join'
]);
```

Core Components
---------------

[](#core-components)

### Entities

[](#entities)

- **Campaign**: Main campaign entity with status management and time-based lifecycle
- **Award**: Reward configurations with quantity and limitation controls
- **Chance**: User participation opportunities with expiration management
- **Reward**: User reward records with unique serial numbers
- **EventLog**: Comprehensive event tracking with arbitrary data support
- **Limit**: Flexible limitation rules for reward distribution
- **Category**: Hierarchical campaign categorization
- **Attribute**: Custom key-value properties for campaigns

### Reward Types

[](#reward-types)

- **Coupons**: Both local and external coupon support
- **Credits**: Configurable credit point rewards
- **Purchase Qualifications**: SKU/SPU purchase rights
- **Custom Rewards**: Extensible reward system

### Limitation Types

[](#limitation-types)

- **Daily/Weekly/Monthly/Quarterly/Yearly**: Time-based limitations
- **Total Limit**: Overall quantity restrictions
- **User Tag Based**: User group specific limitations
- **Chance Based**: Participation opportunity limitations

Dependencies
------------

[](#dependencies)

This bundle requires:

- **PHP**: 8.1 or higher
- **Symfony**: 6.4 or higher
- **Doctrine ORM**: 3.0 or higher
- **EasyAdmin**: 4.0 or higher

### Required Symfony Bundles

[](#required-symfony-bundles)

- `doctrine/doctrine-bundle`
- `easycorp/easyadmin-bundle`
- `symfony/security-bundle`
- `symfony/framework-bundle`

### Optional Dependencies

[](#optional-dependencies)

- `tourze/coupon-core-bundle`: For coupon reward support
- `tourze/credit-bundle`: For credit point rewards
- `tourze/product-core-bundle`: For SKU/SPU purchase qualifications
- `tourze/order-core-bundle`: For order-related campaign features

Advanced Usage
--------------

[](#advanced-usage)

### Custom Reward Types

[](#custom-reward-types)

Extend the reward system with custom reward types:

```
use CampaignBundle\Enum\AwardType;
use CampaignBundle\Service\CampaignService;

// Create custom reward handler
class CustomRewardHandler
{
    public function handleCustomReward(Award $award, UserInterface $user): Reward
    {
        // Custom reward logic here
        $reward = new Reward();
        $reward->setType(AwardType::CUSTOM);
        $reward->setValue($award->getValue());
        $reward->setUser($user);

        return $reward;
    }
}
```

### Expression Language Functions

[](#expression-language-functions)

Use built-in expression language functions for complex participation conditions:

```
// Available functions:
// - hasChance(user, campaign): Check if user has valid chance
// - getChanceCount(user, campaign): Get user's remaining chances
// - hasTag(user, tagName): Check if user has specific tag
// - getTagValue(user, tagName): Get user tag value

$campaign->setRequestExpression('
    hasChance(user, campaign)
    and user.getCreatedAt() < date("-30 days")
    and hasTag(user, "VIP")
    and getTagValue(user, "level") >= 5
');
```

### Event System Integration

[](#event-system-integration)

Integrate with Symfony's event system for advanced workflows:

```
use CampaignBundle\Event\UserEventReportEvent;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;

class CampaignEventSubscriber implements EventSubscriberInterface
{
    public static function getSubscribedEvents(): array
    {
        return [
            UserEventReportEvent::class => 'onUserEventReport',
        ];
    }

    public function onUserEventReport(UserEventReportEvent $event): void
    {
        // Custom event processing logic
        $this->logger->info('User event reported', [
            'user_id' => $event->getUser()->getId(),
            'event' => $event->getEvent(),
            'data' => $event->getData(),
        ]);
    }
}
```

### Database Optimization

[](#database-optimization)

For high-traffic campaigns, consider these optimizations:

```
# Use dedicated database connections for campaign operations
# Configure in doctrine.yaml:
doctrine:
    dbal:
        connections:
            campaign:
                url: '%env(resolve:DATABASE_CAMPAIGN_URL)%'
            default:
                url: '%env(resolve:DATABASE_URL)%'
```

```
// Use database-level locks for concurrent reward distribution
use Tourze\Symfony\AopDoctrineBundle\Attribute\Transactional;

class CampaignService
{
    #[Transactional]
    public function distributeRewardWithLock(Award $award, UserInterface $user): Reward
    {
        // Atomic reward distribution with database locks
        return $this->rewardUser($user, $award);
    }
}
```

Performance Monitoring
----------------------

[](#performance-monitoring)

Monitor campaign performance with built-in metrics:

```
// Track campaign metrics
$metrics = [
    'total_participants' => $this->getParticipantCount($campaign),
    'total_rewards_distributed' => $this->getRewardCount($campaign),
    'conversion_rate' => $this->getConversionRate($campaign),
    'average_participation_time' => $this->getAverageParticipationTime($campaign),
];
```

Contributing
------------

[](#contributing)

Please see [CONTRIBUTING.md](CONTRIBUTING.md) for details.

License
-------

[](#license)

The MIT License (MIT). Please see [License File](LICENSE) for more information.

###  Health Score

29

—

LowBetter than 59% of packages

Maintenance71

Regular maintenance activity

Popularity1

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity33

Early-stage or recently created project

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Unknown

Total

1

Last Release

182d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/e354fdb316da535dfa8ba2e9193a473c403b6bc6fb9170778d1dc50e304c6e9d?d=identicon)[tourze](/maintainers/tourze)

---

Top Contributors

[![tourze](https://avatars.githubusercontent.com/u/13899502?v=4)](https://github.com/tourze "tourze (4 commits)")

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan

Type Coverage Yes

### Embed Badge

![Health badge](/badges/tourze-campaign-bundle/health.svg)

```
[![Health](https://phpackages.com/badges/tourze-campaign-bundle/health.svg)](https://phpackages.com/packages/tourze-campaign-bundle)
```

###  Alternatives

[sylius/sylius

E-Commerce platform for PHP, based on Symfony framework.

8.4k5.6M651](/packages/sylius-sylius)[sulu/sulu

Core framework that implements the functionality of the Sulu content management system

1.3k1.3M152](/packages/sulu-sulu)[contao/core-bundle

Contao Open Source CMS

1231.6M2.4k](/packages/contao-core-bundle)[ec-cube/ec-cube

EC-CUBE EC open platform.

78527.0k1](/packages/ec-cube-ec-cube)[open-dxp/opendxp

Content &amp; Product Management Framework (CMS/PIM)

7310.3k29](/packages/open-dxp-opendxp)[netgen/layouts-core

Netgen Layouts enables you to build and manage complex web pages in a simpler way and with less coding. This is the core of Netgen Layouts, its heart and soul.

3689.4k10](/packages/netgen-layouts-core)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
