Download the PHP package zgldh/discount-and-coupon without Composer
On this page you can find all versions of the php package zgldh/discount-and-coupon. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Please rate this library. Is it a good library?
Informations about the package discount-and-coupon
zgldh/discount-and-coupon
优惠活动、折扣计算器
定义
- 折扣活动,通常用于店铺对所有消费者的活动。
- 优惠券,通常属于一个特定的消费者的特权。
- 以上两者在下文统称“benefit 权益”
zgldh\DiscountAndCoupon\Benefit::class
是可享用的权益的基类,用于定义一系列折扣活动、优惠券的类型。注意是定义类型而不是实例。priority
表示该权益的判断优先级,数值越高越优先判断。
功能
- 输入“权益(benefit)”和一些货品,即可计算出最终价格。
- 可以得出每一个货品参与了哪些 权益。
用法
先给个感性认识。
如何定义店铺折扣活动 Discount
1. 定义店铺的“满减活动”:
上面我们定义了 FlatDiscountWhenPurchaseExceed
类,用于描述“满减”这一类活动。
然后我们新建了 3 个该类的对象,分别代表满20减2, 满50减10, 满100减30 这三种活动。
注意 priority
属性, 它决定了 Calculator
在尝试应用折扣时的判断顺序。由于默认以上三种活动同属于“满减”活动,且只能应用其中一种(请参考 Benefit
类的源码中对 $group
的说明)。所以我们让优惠额度最大的优先级最高,以便总是能帮客户享用最大的优惠力度。
2. 定义店铺的“迎中秋早餐8折”活动,不与其他活动同享:
3. 定义“新品促销,XX酸奶买一送一” 活动,不与其他活动同享。
下列代码是以减价实现本促销活动,会影响本次订单最终价格。
下列代码是以赠送货品实现促销活动,不会影响本次订单最终价格,但会增加商品。
如何定义优惠券 Coupon
其实优惠券和折扣活动逻辑上没有区别,请在您具体的业务代码里,删掉使用过的优惠券。
1. 定义代金券
2. 定义 “饮料升级优惠券”
能把订单内的某种饮料的一件商品替换成更贵的饮料。 本质是替换商品,所以你可以任意定义规则。
All versions of discount-and-coupon with dependencies
PHP Build Version
Package Version
Requires
php Version
>=7.0.0
The package zgldh/discount-and-coupon contains the following files
Loading the files please wait ....