adeela/user-discounts 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

adeela/user-discounts

最新稳定版本:v1.0.0

Composer 安装命令:

composer require adeela/user-discounts

包简介

A Laravel package for user-level discounts

README 文档

README

A Laravel 8+ package to manage user-level discounts with deterministic stacking, usage caps, and audit logging.

✨ Features

  • Assign and revoke discounts to specific users
  • Validate user discount eligibility
  • Apply discounts with stacking and rounding logic
  • Enforce per-user usage limits
  • Log and audit discount usage
  • Fire events on discount assignment, revocation, and application

🧩 Installation

  1. Install via Composer

    composer require adeela/user-discounts
  2. Register Service Provider (if not auto-discovered)

    In config/app.php:

    'providers' => [
        Adeela\UserDiscounts\UserDiscountsServiceProvider::class,
    ],
  3. Publish Config File

    php artisan vendor:publish --provider="Adeela\UserDiscounts\UserDiscountsServiceProvider" --tag="config"

    This creates config/user-discounts.php.

  4. Run Migrations (if provided)

    php artisan migrate

⚙️ Configuration

Sample config/user-discounts.php:

```php
return [
    'stacking_order' => 'highest_first',
    'max_percentage_cap' => 50,
    'rounding' => 'round',
];
```

🧠 Usage Examples

1. Create a Discount

use Adeela\UserDiscounts\Models\Discount;

$discount = Discount::create([
    'code' => 'Save20',
    'name' => 'Save 20%',
    'type'       => 'percentage',
    'value'      => 20,
    'active'     => 1,
    'starts_at'  => now()->subDay(),
    'ends_at'    => now()->addDay(),
]);

2. Assign Discount to a User

$service = new \Adeela\UserDiscounts\Services\DiscountService();

$user = User::find(1);
$discount = Discount::find(34);

$service->assign($user, $discount);

4. Apply Discount

$service = new \Adeela\UserDiscounts\Services\DiscountService();
$amount = 100;
$orderRef = 'ORDER-12345';
$user = User::find(1);

$finalAmount = $service->apply($user, $amount, $orderRef);
dd("Final amount after discounts: {$finalAmount}");

5. Revoke Discount

$service = new \Adeela\UserDiscounts\Services\DiscountService();

$user = User::find(1);
$discount = Discount::find(34);

$service->revoke($user, $discount);

🔔 Events

Event Description
DiscountAssigned Triggered when a discount is assigned
DiscountRevoked Triggered when a discount is revoked
DiscountApplied Triggered when a discount is applied

🧪 Testing

vendor/bin/phpunit

统计信息

  • 总下载量: 2
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 0
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: Unknown
  • 更新时间: 2025-09-28