khaleds / voucher
Laravel的优惠券和促销代码生成器。
v1.0.0
2023-03-12 14:38 UTC
This package is auto-updated.
Last update: 2024-09-12 17:50:22 UTC
README
Laravel Voucher Package
优惠券和券码检查器。您可以创建满足您业务需求的多种条件的券。
可用条件
这个包会检查所有这些条件。
如果您有针对特定用户、供应商或客户的优惠券,或者需要为类别、服务或产品应用优惠券(全部或特定一些),怎么办呢?
voucher_implementation_id ;) 这个外键与表相关,包含 [类路径,值作为json]。您可以将您的优惠券受众添加到 voucher_audiences 中作为形态表,其中包含可用的_type作为表名, usable_id作为模型ID,is_all布尔值表示该表中的所有记录和券ID。在 voucher_implementations 表中,您可以找到每个券的实现记录,默认实现是应用的。默认实现只是检查模型表、ID或is_all在券受众表中检查。
内容列表
- 安装
- 它是如何工作的?
- 如何使用
- 高级使用
安装
composer require khaleds/voucher
迁移表
php artisan make:migration
种子
在您的 DatabaseSeeder 类的run方法中添加此代码
use Khaleds\Voucher\Seeder\VoucherImplementaionSeeder; $this->call(VoucherImplementaionSeeder::class);
它是如何工作的?
券表
此表包含优惠券条件,如
其他列
如果您想要更多的条件,如特定模型或ID,例如,我想为所有账户表或用户表或具有某些ID的用户创建此券,您可以在该表中完成此操作。
券受众表
此表包含
关系为一对多,因此您可以为每个券添加多个ID。
用户券表
此表包含使用函数 apply 时添加的优惠券的用户。
如何使用
您有两个静态类
// $code : voucher code // model : which model uses this voucher // amount : the amount that you want to apply voucher on it // return : voucher object if passed all conditions ex if not passed VoucherFactory::get(string $code,Model $user,float $amount)->check()->get() // if you pass 0 that mean the voucher applied and not used // applay will add the model to voucher if passes the conditions and increment uses column VoucherFactory::get(string $code,Model $user,float $amount)->check()->apply(1)->get()
如果您想避免所有检查并应用优惠券
VoucherFactory::get(string $code,Model $user,float $amount)->apply(bool $is_used, string $code, Model $model))
高级使用
关于您有额外的条件,例如,您想仅添加包含国家、服务、产品或类别的优惠券
使用
VoucherFactory::get(string $code,Model $user)->check() // it tacks table name as a key and array of ids ->append( [ "categories" => [1,2,3], "products" => [1,2,3], ] ) ->apply(1)->get()
您只需在 Vouchers Audiences 表 中添加您的受众
如果您想覆盖实现类,请更改 voucher_implementations 表中的类路径,并从 DefaultVoucher 类扩展