PHPackages                             tourze/coupon-command-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. [Utility &amp; Helpers](/categories/utility)
4. /
5. tourze/coupon-command-bundle

ActiveSymfony-bundle[Utility &amp; Helpers](/categories/utility)

tourze/coupon-command-bundle
============================

口令优惠券系统，提供基于口令的优惠券发放、验证和使用记录功能

0.0.2(5mo ago)0141MITPHPCI failing

Since Jun 1Pushed 4mo agoCompare

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

READMEChangelog (2)Dependencies (41)Versions (3)Used By (1)

CouponCommandBundle
===================

[](#couponcommandbundle)

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

[![Latest Version](https://camo.githubusercontent.com/95b6719850f8b9542413fc2dee39b1c8200649cc22ead6d2669e83ab5ca2bf0b/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f746f75727a652f636f75706f6e2d636f6d6d616e642d62756e646c652e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/tourze/coupon-command-bundle)[![PHP Version Require](https://camo.githubusercontent.com/5eea28efccf7e82b760a9ea6b9f9bd17138d195f1cc8202dc43b496ab16675cb/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f7068702d762f746f75727a652f636f75706f6e2d636f6d6d616e642d62756e646c652e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/tourze/coupon-command-bundle)[![License](https://camo.githubusercontent.com/518fc661b7221e8ef12eb7d457f5602849ff37cabcf48121e8ff4757d832c485/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f6c2f746f75727a652f636f75706f6e2d636f6d6d616e642d62756e646c652e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/tourze/coupon-command-bundle)[![Build Status](https://camo.githubusercontent.com/71c899315a8f155d504bb23baebabdd724ea15a42a5f7e72e49e6b4e9ebc30d3/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f746f75727a652f7068702d6d6f6e6f7265706f2f746573742e796d6c3f6272616e63683d6d6173746572267374796c653d666c61742d737175617265)](https://github.com/tourze/php-monorepo/actions)[![Quality Score](https://camo.githubusercontent.com/43930c8561a14d3f5a68c62b692ee20749bac4c043e09e88fd3fdd611660198f/68747470733a2f2f696d672e736869656c64732e696f2f7363727574696e697a65722f672f746f75727a652f7068702d6d6f6e6f7265706f2e7376673f7374796c653d666c61742d737175617265)](https://scrutinizer-ci.com/g/tourze/php-monorepo)[![Code Coverage](https://camo.githubusercontent.com/fce86ff4532b4694c22512e5e192a270f73dd27d6e5495fffb59c73cf14de807/68747470733a2f2f696d672e736869656c64732e696f2f7363727574696e697a65722f636f7665726167652f672f746f75727a652f7068702d6d6f6e6f7265706f2e7376673f7374796c653d666c61742d737175617265)](https://scrutinizer-ci.com/g/tourze/php-monorepo/?branch=master)[![Total Downloads](https://camo.githubusercontent.com/d54486167f35a6517eebeb0b0f69fed0d1f509811d730f8b32f7948ce947a1c1/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f746f75727a652f636f75706f6e2d636f6d6d616e642d62756e646c652e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/tourze/coupon-command-bundle)

A Symfony bundle for coupon command code system that provides command-based coupon distribution and management functionality.

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

[](#table-of-contents)

- [Features](#features)
- [Requirements](#requirements)
- [Installation](#installation)
- [Quick Start](#quick-start)
- [Core Concepts](#core-concepts)
- [JsonRPC Interface](#jsonrpc-interface)
- [Admin Interface](#admin-interface)
- [Architecture](#architecture)
- [Usage Examples](#usage-examples)
- [Advanced Usage](#advanced-usage)
- [Service Configuration](#service-configuration)
- [Error Handling](#error-handling)
- [Testing](#testing)
- [Contributing](#contributing)
- [Support](#support)
- [License](#license)
- [Changelog](#changelog)

Features
--------

[](#features)

- **Command Management**: Create, edit, and delete coupon command codes
- **Usage Restrictions**: Multi-dimensional usage restrictions (time, count, user groups, etc.)
- **JsonRPC Interface**: Standard JSON-RPC 2.0 API endpoints
- **Admin Interface**: Complete management interface based on EasyAdmin
- **Usage Records**: Complete command usage tracking and statistics
- **Flexible Restrictions**: Time windows, usage limits, and user targeting
- **User Group Targeting**: Allow specific users or user tags to use commands

Requirements
------------

[](#requirements)

- PHP 8.1+
- Symfony 6.4+
- Doctrine ORM 3.0+
- tourze/coupon-core-bundle
- tourze/json-rpc-core

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

[](#installation)

### Install via Composer

[](#install-via-composer)

```
composer require tourze/coupon-command-bundle
```

### Enable the Bundle

[](#enable-the-bundle)

Add to `config/bundles.php`:

```
return [
    // ...
    Tourze\CouponCommandBundle\CouponCommandBundle::class => ['all' => true],
];
```

### Database Migration

[](#database-migration)

```
php bin/console doctrine:migrations:diff
php bin/console doctrine:migrations:migrate
```

Quick Start
-----------

[](#quick-start)

```
use Tourze\CouponCommandBundle\Service\CommandValidationService;
use Tourze\CouponCommandBundle\Service\CommandManagementService;

// Validate command
$validationService = $container->get(CommandValidationService::class);
$result = $validationService->validateCommand('NEWUSER2024', 'user123');

if ($result['valid']) {
    // Command is valid, can be used
    $useResult = $validationService->useCommand('NEWUSER2024', 'user123');

    if ($useResult['success']) {
        echo "Coupon claimed successfully, ID: " . $useResult['couponId'];
    }
}
```

Core Concepts
-------------

[](#core-concepts)

### Restriction Types

[](#restriction-types)

1. **Time Restrictions**: Set valid time range for commands
2. **Count Restrictions**: Total usage count and per-user usage limits
3. **User Restrictions**: Specify allowed user groups for command usage
4. **Status Control**: Enable/disable command restrictions

JsonRPC Interface
-----------------

[](#jsonrpc-interface)

### Validate Command - ValidateCouponCommand

[](#validate-command---validatecouponcommand)

Validates command validity without actually using the command.

**Request Parameters:**

```
{
    "command": "string",     // Command content
    "userId": "string"       // User ID (optional)
}
```

**Response Example:**

```
{
    "valid": true,
    "couponInfo": {
        "id": "1234567890",
        "name": "New User Coupon",
        "type": "discount",
        "amount": 100
    },
    "commandConfig": {
        "id": "9876543210",
        "command": "NEWUSER2024"
    }
}
```

### Use Command - UseCouponCommand

[](#use-command---usecouponcommand)

Use command to claim coupon.

**Request Parameters:**

```
{
    "command": "string",     // Command content
    "userId": "string"       // User ID (required)
}
```

**Response Example:**

```
{
    "success": true,
    "couponId": "1234567890",
    "message": "Coupon claimed successfully"
}
```

Admin Interface
---------------

[](#admin-interface)

The bundle provides complete EasyAdmin management interface:

1. **Command Configuration Management** - `CommandConfigCrudController`

    - Create and edit commands
    - Link to coupons
    - View usage statistics
2. **Restriction Configuration Management** - `CommandLimitCrudController`

    - Set usage restrictions
    - Configure time windows
    - Manage user group restrictions
3. **Usage Record Viewing** - `CommandUsageRecordCrudController`

    - View detailed usage records
    - Success/failure statistics
    - User usage tracking

Architecture
------------

[](#architecture)

### Entity Relationships

[](#entity-relationships)

- **CommandConfig**: Command configuration, linked to specific coupons
- **CommandLimit**: Command usage restriction configuration
- **CommandUsageRecord**: Command usage tracking records

### Service Layer

[](#service-layer)

- **CommandValidationService**: Command validation and execution
- **CommandManagementService**: Command management and statistics

### Core Features

[](#core-features)

- **Audit Trails**: All usage is tracked with IP, user, and timestamp information
- **Flexible Validation**: Time-based, count-based, and user-based restrictions
- **Admin Interface**: Complete CRUD operations via EasyAdmin controllers

Usage Examples
--------------

[](#usage-examples)

### Basic Usage

[](#basic-usage)

```
// Create command configuration
$managementService = $container->get(CommandManagementService::class);
$commandConfig = $managementService->createCommandConfig('SPRING2024', $coupon);

// Add usage restrictions
$managementService->addCommandLimit(
    $commandConfig->getId(),
    maxUsagePerUser: 1,        // 1 use per person
    maxTotalUsage: 1000,       // 1000 total uses
    startTime: new \DateTime('2024-03-01'),
    endTime: new \DateTime('2024-03-31')
);
```

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

[](#advanced-usage)

### User Group Restrictions

[](#user-group-restrictions)

```
// Create command with user group restrictions
$managementService->addCommandLimit(
    $commandConfigId,
    maxUsagePerUser: 3,
    allowedUsers: ['vip_user_1', 'vip_user_2'],  // Only allow VIP users
    allowedUserTags: ['premium', 'gold']         // Allow specific tagged users
);

// Get usage statistics
$stats = $managementService->getCommandConfigDetail($commandConfigId);
echo "Total usage: " . $stats['stats']['totalUsage'];
echo "Successful usage: " . $stats['stats']['successUsage'];
```

Service Configuration
---------------------

[](#service-configuration)

In `services.yaml`, the bundle automatically registers the following services:

- `CommandValidationService`: Command validation service
- `CommandManagementService`: Command management service
- JsonRPC methods: `ValidateCouponCommand`, `UseCouponCommand`

Error Handling
--------------

[](#error-handling)

### Common Error Messages

[](#common-error-messages)

Error MessageDescriptionSolutionCommand does not existEntered command is not configuredCheck if command is correct or has been createdCoupon does not existAssociated coupon has been deletedRe-associate with a valid couponCommand usage time is outside valid periodOutside time restrictionsCheck time configurationCommand usage count has reached limitExceeded total count limitIncrease limit or create new commandYou are not in the usage scope of this commandUser not in allowed listAdd user to allowed listYou have reached the usage limit for this commandUser personal count limit exceededIncrease personal usage limit### Logging

[](#logging)

All command usage is logged with detailed information:

- Usage timestamp
- User information
- Success/failure status
- Failure reason
- Additional context information

Testing
-------

[](#testing)

Run the test suite:

```
./vendor/bin/phpunit packages/coupon-command-bundle/tests
```

Test coverage includes:

- Entity unit tests
- Service layer business logic tests
- Integration tests
- JsonRPC interface tests

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

[](#contributing)

Please see [CONTRIBUTING.md](../../CONTRIBUTING.md) for details on how to contribute to this project.

Support
-------

[](#support)

For issues or suggestions, please submit an Issue or Pull Request on the [main repository](https://github.com/tourze/php-monorepo).

License
-------

[](#license)

MIT License

Changelog
---------

[](#changelog)

### v0.0.1

[](#v001)

- Initial version release
- Complete command system functionality
- JSON-RPC 2.0 interface support
- EasyAdmin management interface
- Complete unit test coverage

###  Health Score

29

—

LowBetter than 60% of packages

Maintenance72

Regular maintenance activity

Popularity6

Limited adoption so far

Community8

Small or concentrated contributor base

Maturity28

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

Every ~165 days

Total

2

Last Release

178d 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-coupon-command-bundle/health.svg)

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

###  Alternatives

[sylius/sylius

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

8.4k5.6M650](/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.3k](/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)
