westlove / wstlovecoupondiscount
优惠券折扣
dev-main
2024-04-03 18:49 UTC
Requires
- php: ^7.4|^8.0|^8.1
- illuminate/database: ^6.0|^7.0|^8.0|^9.0|^10.0
- illuminate/pagination: ^6.0|^7.0|^8.0|^9.0|^10.0
This package is auto-updated.
Last update: 2024-09-03 19:35:38 UTC
README
这是一个用于优惠券折扣的PHP/Laravel包。此包可以在laravel或laravel/php项目中使用。您可以使用此包进行无头/rest实现,以及blade或常规模式开发。我们在进行一个项目时创建了此包,并认为将其发布出来可以帮助所有人。此包作为常规php composer包提供。
需求
- PHP >=7.4
安装
composer require codeboxr/coupondiscount
用法
如果您在laravel中使用此包,您必须首先发布迁移,然后通过以下命令迁移。
php artisan vendor:publish --provider="Codeboxr\CouponDiscount\CouponDiscountServiceProvider"
php artisan migrate
创建了coupons和coupon_histories两个数据库表。
注意:
如果您使用原始PHP或其他PHP框架,您可能需要手动将copuondiscount/database/sql
SQL文件导入到您的数据库中。
1. 创建新优惠券
*** 使用Laravel应用
use Codeboxr\CouponDiscount\Facades\Coupon;
Coupon::add([
'coupon_code' => "", // (required) Coupon code
'discount_type' => "", // (required) coupon discount type. two type are accepted (1. percentage and 2. fixed)
'discount_amount' => "", // (required) discount amount or percentage value
'start_date' => "", // (required) coupon start date
'end_date' => "", // (required) coupon end date
'status' => "", // (required) two status are accepted. (for active 1 and for inactive 0)
'minimum_spend' => "", // (optional) for apply this coupon minimum spend amount. if set empty then it's take unlimited
'maximum_spend' => "", // (optional) for apply this coupon maximum spend amount. if set empty then it's take unlimited
'use_limit' => "", // (optional) how many times are use this coupon. if set empty then it's take unlimited
'use_same_ip_limit' => "", // (optional) how many times are use this coupon in same ip address. if set empty then it's take unlimited
'user_limit' => "", // (optional) how many times are use this coupon a user. if set empty then it's take unlimited
'use_device' => "", // (optional) This coupon can be used on any device
'multiple_use' => "", // (optional) you can check manually by this multiple coupon code use or not
'vendor_id' => "" // (optional) if coupon code use specific shop or vendor
]);
*** 使用原始PHP或其他PHP框架
use Codeboxr\CouponDiscount\Services\CouponService;
$copuon = new CouponService([
"driver" => "", // (optional) database driver. By default it takes `mysql`
"host" => "", // (optional) database host. By default it takes `localhost`
"username => "", // (required) database user name.
"password" => "" // (required) database password,
]);
$copuon->add([
'coupon_code' => "", // (required) Coupon code
'discount_type' => "", // (required) coupon discount type. two type are accepted (1. percentage and 2. fixed)
'discount_amount' => "", // (required) discount amount or percentage value
'start_date' => "", // (required) coupon start date
'end_date' => "", // (required) coupon end date
'status' => "", // (required) two status are accepted. (for active 1 and for inactive 0)
'minimum_spend' => "", // (optional) for apply this coupon minimum spend amount. if set empty then it's take unlimited
'maximum_spend' => "", // (optional) for apply this coupon maximum spend amount. if set empty then it's take unlimited
'use_limit' => "", // (optional) how many times are use this coupon. if set empty then it's take unlimited
'use_same_ip_limit' => "", // (optional) how many times are use this coupon in same ip address. if set empty then it's take unlimited
'user_limit' => "", // (optional) how many times are use this coupon a user. if set empty then it's take unlimited
'use_device' => "", // (optional) This coupon can be used on any device
'multiple_use' => "", // (optional) you can check manually by this multiple coupon code use or not
'vendor_id' => "" // (optional) if coupon code use specific shop or vendor
]);
2. 更新优惠券
*** 使用Laravel应用
use Codeboxr\CouponDiscount\Facades\Coupon;
Coupon::update([
'coupon_code' => "", // (required) Coupon code
'discount_type' => "", // (required) coupon discount type. two type are accepted (1. percentage and 2. fixed)
'discount_amount' => "", // (required) discount amount or percentage value
'start_date' => "", // (required) coupon start date
'end_date' => "", // (required) coupon end date
'status' => "", // (required) two status are accepted. (for active 1 and for inactive 0)
'minimum_spend' => "", // (optional) for apply this coupon minimum spend amount. if set empty then it's take unlimited
'maximum_spend' => "", // (optional) for apply this coupon maximum spend amount. if set empty then it's take unlimited
'use_limit' => "", // (optional) how many times are use this coupon. if set empty then it's take unlimited
'use_same_ip_limit' => "", // (optional) how many times are use this coupon in same ip address. if set empty then it's take unlimited
'user_limit' => "", // (optional) how many times are use this coupon a user. if set empty then it's take unlimited
'use_device' => "", // (optional) This coupon can be used on any device
'multiple_use' => "", // (optional) you can check manually by this multiple coupon code use or not
'vendor_id' => "" // (optional) if coupon code use specific shop or vendor
], $couponId);
*** 使用原始PHP或其他PHP框架
$copuon->update([
'coupon_code' => "", // (required) Coupon code
'discount_type' => "", // (required) coupon discount type. two type are accepted (1. percentage and 2. fixed)
'discount_amount' => "", // (required) discount amount or percentage value
'start_date' => "", // (required) coupon start date
'end_date' => "", // (required) coupon end date
'status' => "", // (required) two status are accepted. (for active 1 and for inactive 0)
'minimum_spend' => "", // (optional) for apply this coupon minimum spend amount. if set empty then it's take unlimited
'maximum_spend' => "", // (optional) for apply this coupon maximum spend amount. if set empty then it's take unlimited
'use_limit' => "", // (optional) how many times are use this coupon. if set empty then it's take unlimited
'use_same_ip_limit' => "", // (optional) how many times are use this coupon in same ip address. if set empty then it's take unlimited
'user_limit' => "", // (optional) how many times are use this coupon a user. if set empty then it's take unlimited
'use_device' => "", // (optional) This coupon can be used on any device
'multiple_use' => "", // (optional) you can check manually by this multiple coupon code use or not
'vendor_id' => "" // (optional) if coupon code use specific shop or vendor
], $couponId);
3. 删除优惠券
*** 使用Laravel应用
use Codeboxr\CouponDiscount\Facades\Coupon;
Coupon::remove($couponId)
*** 使用原始PHP或其他PHP框架
$copuon->remove($couponId);
4. 优惠券列表
*** 使用Laravel应用
use Codeboxr\CouponDiscount\Facades\Coupon;
Coupon::list()->get();
*** 使用原始PHP或其他PHP框架
$copuon->list()->get();
5. 优惠券有效性检查
use Codeboxr\CouponDiscount\Facades\Coupon;
Coupon::validity("CBX23",1200,1,"app","192.168.0.1",5);
*** 使用原始PHP或其他PHP框架
$copuon->validity("CBX23",1200,1,"app","192.168.0.1",5);
note: validity()方法的前3个参数是必需的,其他的是可选的
6. 应用优惠券
use Codeboxr\CouponDiscount\Facades\Coupon;
Coupon::apply([
"code" => "", // coupon code. (required)
"amount" => "", // total amount to apply coupon. must be a numberic number (required)
"user_id" => "", // user id (required)
"order_id" => "", // order id (required)
"device_name" => "", // device name (optional)
"ip_address" => "", // ip address (optional)
]);
*** 使用原始PHP或其他PHP框架
$copuon->apply([
"code" => "", // coupon code. (required)
"amount" => "", // total amount to apply coupon. must be a numberic number (required)
"user_id" => "", // user id (required)
"order_id" => "", // order id (required)
"device_name" => "", // device name (optional)
"ip_address" => "", // ip address (optional)
]);
7. 优惠券历史列表
*** 使用Laravel应用
use Codeboxr\CouponDiscount\Facades\Coupon;
Coupon::history()->get();
*** 使用原始PHP或其他PHP框架
$copuon->history()->get();
8. 删除优惠券历史
*** 使用Laravel应用
use Codeboxr\CouponDiscount\Facades\Coupon;
Coupon::historyDelete($historyId)
*** 使用原始PHP或其他PHP框架
$copuon->historyDelete($historyId);
贡献
欢迎为优惠券折扣包做出贡献。在提交您的pull请求之前,请注意以下指南。
- 遵循 PSR-4 编码标准。
许可证
优惠券折扣包采用MIT许可证。
版权所有 2023 Codeboxr