Coder Social home page Coder Social logo

coupon's Introduction

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

coupon's People

Contributors

m809745357 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

coupon's Issues

一对多的关联感觉有局限性

如同品类某优惠券可以下发到多个用户,
以当前表结构,coupon表中就会产生多个相同coupon,绑定不同用户.
感觉可以将关联模型做成多对多关联,coupon过期或者禁用后可针对性或者范围性更新pivot值

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.