Skip to content

m809745357/coupon

Repository files navigation

coupon

Image text

一个公用的优惠券管理工具.

Build Status StyleCI build status codecov Codacy Badge Latest Stable Version Total Downloads Latest Unstable Version License

安装

$ composer require lian/coupon -vvv

使用

发布 migration 文件

php artisan vendor:publish --provider="Lian\CouponCouponServiceProvider" --tag="migrations"

发布 config 文件

php artisan vendor:publish --provider="Lian\CouponCouponServiceProvider" --tag="config"

修改配置文件

config/coupon.php

<?php

return [
    'model' => \App\User::class, //修改成自己的 User 模型 eg. \App\Models\User::class
    
    'distance' => 7,

    'title' => 'coupon',
];

增加 trait

<?php

use Lian\Coupon\Traits\HasCoupon;
...
use HasCoupon;

可以使用的方法

<?php

// 用户创建优惠券
$user->addCoupon([
    'title' => 'this is a title',
    'amount' => 1.00,
    'start_time' => now(),
    'end_time' -> now()->addDays(7)
]);

// or
$user->addCouponOnce(1.00); // 默认 7 天

$user->addCouponOnce(1.00, 7); // 默认标题 coupon

$user->addCouponOnce(1.00, 7, 'this is a title');

// 用户领取优惠券
$user->receiveCoupon($coupon);

// 判断优惠券是否使用
$coupon->isBeUsed();

// 判断优惠券是否过期
$coupon->isBeOverdue();

// 使用优惠券
$coupon->apply();

// 获取优惠券到期时间
$coupon->distanceEndTime();

测试

$ composer test

Contributing

You can contribute in one of three ways:

  1. File bug reports using the issue tracker.
  2. Answer questions or fix bugs on the issue tracker.
  3. Contribute new features or update the wiki.

The code contribution process is not very formal. You just need to make sure that you follow the PSR-0, PSR-1, and PSR-2 coding guidelines. Any new code contributions must be accompanied by unit tests where applicable.

License

MIT

About

💵 基于 Laravel 5.5 以上版本的优惠券管理工具。

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages