megaads / coupon-utils
优惠券工具
v1.1.7
2020-09-25 02:29 UTC
Requires
- php: >=5.6.4
README
安装
composer require megaads/coupon-utils
安装完成后,将 Service Provider class 配置到 Laravel 项目的 config 目录下的 app.php 文件中,如下所示:
Megaads\CouponUtils\CouponUtilsServiceProvider::class,
然后运行以下命令来创建配置文件
php artisan vendor:publish --provider="Megaads\CouponUtils\CouponUtilsServiceProvider" --tag=config --force
运行命令后,生成的配置文件内容如下
return [
'free_shipping' => [
'text' => ['free(.*)shipping'],
'regex' => [
'default' => '/#text/i'
],
'value' => [
'default' => ''
]
],
'percent' => [
'text' => ['off'],
'regex' => [
'default' => '/(\d+)% #text/i'
],
'value' => [
'default' => '#value%'
]
],
'amount' => [
'text' => ['off'],
'regex' => [
'default' => '/\$(\d+) #text/i'
],
'value' => [
'default' => '$#value'
]
],
];
修改完配置文件后,运行以下命令来清除缓存
php artisan config:cache
php artisan cache:clear
将以下内容添加到 app.php 文件中的 'aliases' => [] 部分
'CouponUtils' => Megaads\CouponUtils\CouponUtils::class,
然后调用这个方法来获取优惠券促销类型
$couponType = CouponUtils::detectCouponType($titleOfCoupon);
或者按照以下旧方式调用,不使用上面的配置文件
$couponType = CouponUtils::getCouponType($titleOfCoupon);
返回类型如下
$retval = [
'type' => 'deal',
'value' => '',
];
其中 type 可能是:'deal', 'percent', 'amount', 'free_shipping'
Value 可能是:'30', '' 等