| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384 |
- <?php
- namespace Longyi\FreeGift\Config;
- /**
- * 赠品活动(Free Gift)的全局常量。
- *
- * 5 种规则类型直接复用 Bagisto 的 `cart_rules.action_type` 字段,
- * 不额外建 action 枚举表,和原生的 by_percent / by_fixed / cart_fixed / buy_x_get_y 并列。
- */
- class Gift
- {
- /**
- * 买它送它:购买指定商品本身,按 discount_step 送 discount_amount 个同款赠品。
- */
- public const ACTION_SAME_PRODUCT = 'free_gift_same_product';
- /**
- * 买指定商品送:购物车中存在满足条件的商品时赠送。
- */
- public const ACTION_WITH_PRODUCTS = 'free_gift_with_products';
- /**
- * 每 N 件送:每买满 discount_step 件,送 discount_amount 个赠品。
- */
- public const ACTION_EACH_N = 'free_gift_each_n';
- /**
- * 整车送:只要满足条件(通常条件为空)就送。
- */
- public const ACTION_WHOLE_CART = 'free_gift_whole_cart';
- /**
- * 满额送:满足条件商品的金额每达到 discount_step,送 discount_amount 个赠品。
- */
- public const ACTION_SPENT = 'free_gift_spent';
- /**
- * 全部赠品型 action。
- */
- public const ACTION_TYPES = [
- self::ACTION_SAME_PRODUCT,
- self::ACTION_WITH_PRODUCTS,
- self::ACTION_EACH_N,
- self::ACTION_WHOLE_CART,
- self::ACTION_SPENT,
- ];
- /**
- * 赠品组类型:列表里每个 SKU 各送 N 个。
- */
- public const TYPE_ALL = 0;
- /**
- * 赠品组类型:列表合计只送 N 个,由用户自选。
- */
- public const TYPE_ONE = 1;
- /**
- * `cart_items.additional` 中标记「该行是赠品」的键,值为 cart_rules.id。
- */
- public const CART_ITEM_FLAG = 'free_gift_rule_id';
- /**
- * 判定 action_type 是否为赠品型。
- */
- public static function isGiftAction($actionType): bool
- {
- return in_array($actionType, self::ACTION_TYPES, true);
- }
- /**
- * 判定 action_type 是否是「必须绑定商品条件」的类型。
- */
- public static function requiresProductCondition($actionType): bool
- {
- return in_array($actionType, [
- self::ACTION_SAME_PRODUCT,
- self::ACTION_WITH_PRODUCTS,
- self::ACTION_EACH_N,
- self::ACTION_SPENT,
- ], true);
- }
- }
|