codeboxr / coupondiscount
优惠券折扣
v1.0.5
2024-05-07 04:13 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
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()方法的前三个参数是必需的,其他参数是可选的
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)
"vendor_id" => "", // vendor id (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)
"vendor_id" => "", // vendor id (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