PHP code example of lian / coupon

1. Go to this page and download the library: Download lian/coupon library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

lian / coupon example snippets




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

    'title' => 'coupon',
];




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



// 用户创建优惠券
$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();
shell
php artisan vendor:publish --provider="Lian\CouponCouponServiceProvider" --tag="migrations"
shell
php artisan vendor:publish --provider="Lian\CouponCouponServiceProvider" --tag="config"