tourze / coupon-core-bundle
优惠券核心模块,提供优惠券管理、券码生成和验证功能
Installs: 306
Dependents: 4
Suggesters: 0
Security: 0
Stars: 0
Watchers: 0
Forks: 0
Open Issues: 0
Type:symfony-bundle
pkg:composer/tourze/coupon-core-bundle
Requires
- php: ^8.1
- atelierdisko/coupon_code: ^1.0
- doctrine/collections: ^2.3
- doctrine/data-fixtures: ^2.0
- doctrine/dbal: ^4.0
- doctrine/doctrine-bundle: ^2.13
- doctrine/doctrine-fixtures-bundle: ^4.0
- doctrine/orm: ^3.0
- doctrine/persistence: ^3.1 || ^4
- easycorp/easyadmin-bundle: ^4
- knplabs/knp-menu: ^3.7
- monolog/monolog: ^3.1
- nesbot/carbon: ^2.72 || ^3
- psr/log: ^3|^2|^1
- symfony/config: ^6.4
- symfony/console: ^6.4
- symfony/dependency-injection: ^6.4
- symfony/doctrine-bridge: ^6.4
- symfony/event-dispatcher-contracts: ^2.5 | ^3
- symfony/form: ^6.4
- symfony/framework-bundle: ^6.4
- symfony/http-foundation: ^6.4
- symfony/http-kernel: ^6.4
- symfony/messenger: ^6.4
- symfony/routing: ^6.4
- symfony/security-bundle: ^6.4
- symfony/security-core: ^6.4
- symfony/security-http: ^6.4
- symfony/serializer: ^6.4
- symfony/yaml: ^6.4 || ^7.1
- tourze/arrayable: 0.0.*
- tourze/async-contracts: 0.0.*
- tourze/benifit-bundle: 0.0.*
- tourze/bundle-dependency: 0.0.*
- tourze/condition-system-bundle: 0.0.*
- tourze/coupon-contracts: 0.0.*
- tourze/doctrine-async-bundle: ^0.0.6
- tourze/doctrine-helper: 0.0.*
- tourze/doctrine-indexed-bundle: 0.0.*
- tourze/doctrine-ip-bundle: 0.0.*
- tourze/doctrine-random-bundle: 0.1.*
- tourze/doctrine-snowflake-bundle: 0.1.*
- tourze/doctrine-timestamp-bundle: 0.0.*
- tourze/doctrine-track-bundle: 0.1.*
- tourze/doctrine-user-bundle: 0.0.*
- tourze/easy-admin-attribute: 0.1.*
- tourze/easy-admin-menu-bundle: 0.1.*
- tourze/enum-extra: 0.1.*
- tourze/http-client-bundle: 0.1.*
- tourze/json-rpc-cache-bundle: 0.1.*
- tourze/json-rpc-core: 0.0.*
- tourze/json-rpc-lock-bundle: 0.1.*
- tourze/json-rpc-log-bundle: 0.1.*
- tourze/json-rpc-paginator-bundle: 0.0.*
- tourze/resource-manage-bundle: 0.1.*
- tourze/symfony-cron-job-bundle: 0.1.*
- tourze/symfony-routing-auto-loader-bundle: 0.0.*
- yiisoft/json: ^1.0
Requires (Dev)
- maglnet/composer-require-checker: ^4
- phpstan/phpstan: ^2.1
- phpunit/phpunit: ^10.0
- symfony/phpunit-bridge: ^6.4
This package is auto-updated.
Last update: 2025-10-31 19:54:03 UTC
README
A Symfony bundle providing core functionality for coupon management, including coupon categories, batches, codes, discounts, and channel management.
Features
- Coupon Management: Comprehensive coupon lifecycle management
- Batch Operations: Create and manage coupon batches
- Channel Integration: Multi-channel coupon distribution
- Discount Rules: Flexible discount configurations
- Automatic Expiration: Scheduled tasks for handling expired coupons
- Statistics Tracking: Built-in coupon usage statistics
Installation
composer require tourze/coupon-core-bundle
Bundle Registration
Register the bundle in your config/bundles.php:
return [ // ... Tourze\CouponCoreBundle\CouponCoreBundle::class => ['all' => true], ];
Configuration
Database Migration
Run migrations to create the necessary database tables:
php bin/console doctrine:migrations:migrate
Console Commands
The bundle provides the following console commands:
Check Expired Categories
php bin/console coupon:check-expired-category
This command checks coupon categories for expiration and marks expired categories as invalid. It runs as a cron task every minute to ensure categories are automatically invalidated when they expire.
Features:
- Automatically marks categories as invalid when outside their valid time range
- Runs every minute via cron task integration
- Ensures coupon availability is properly controlled by time constraints
Revoke Expired Codes
php bin/console coupon:revoke-expired-code
This command automatically revokes expired coupon codes that haven't been used. It processes up to 500 codes per execution to manage system load.
Features:
- Finds unused coupon codes that have passed their expiration date
- Marks expired codes as invalid
- Processes in batches of 500 codes per run
- Prevents expired coupons from being redeemed
Core Entities
Category
Represents coupon categories with validation time ranges.
Batch
Groups coupons for batch operations and management.
Code
Individual coupon codes with unique identifiers and validation status.
Coupon
The main coupon entity linking categories, batches, and codes.
Channel
Distribution channels for coupon allocation.
Discount
Discount rules and configurations for coupons.
CouponStat
Statistical data for coupon usage tracking.
Usage Examples
Creating a Coupon Category
use Tourze\CouponCoreBundle\Entity\Category; use Doctrine\ORM\EntityManagerInterface; $category = new Category(); $category->setName('Summer Sale'); $category->setStartTime(new \DateTime('2024-06-01')); $category->setEndTime(new \DateTime('2024-08-31')); $category->setValid(true); $entityManager->persist($category); $entityManager->flush();
Generating Coupon Codes
use Tourze\CouponCoreBundle\Entity\Code; use Tourze\CouponCoreBundle\Entity\Batch; $batch = new Batch(); $batch->setName('SUMMER2024'); $batch->setCategory($category); for ($i = 0; $i < 100; $i++) { $code = new Code(); $code->setCode(generateUniqueCode()); // Your code generation logic $code->setBatch($batch); $code->setValid(true); $code->setExpireTime(new \DateTime('+30 days')); $entityManager->persist($code); } $entityManager->flush();
Integration with Other Bundles
This bundle integrates with:
tourze/benefit-bundle- For benefit calculationstourze/condition-system-bundle- For conditional coupon rulestourze/doctrine-snowflake-bundle- For unique ID generationtourze/symfony-cron-job-bundle- For scheduled tasks
Testing
Run the test suite:
./vendor/bin/phpunit packages/coupon-core-bundle/tests
Contributing
Please ensure all tests pass and code meets PHPStan level 8 standards before submitting pull requests.
License
This bundle is released under the MIT License.