shaygan / affiliate-bundle
一个简单的 Symfony Affiliate Bundle。
2.0.1
2022-07-26 07:09 UTC
Requires
- php: ^7.0|^8.0
- doctrine/orm: ^2.5
- knplabs/knp-paginator-bundle: *
- symfony/framework-bundle: >=4.4
- symfony/templating: *
- symfony/twig-bundle: *
- twig/twig: *
Requires (Dev)
- friendsofphp/php-cs-fixer: ^1.11
- phpunit/phpunit: ~4.8|~5.0
- symfony/phpunit-bridge: ^4.1.12
README
一个简单的 Symfony Affiliate Bundle。
此Bundle(原FOSUserBundle兼容)通过查询字符串参数跟踪推荐并检测通过cookie的推荐注册。您可以轻松地询问此Bundle佣金金额(如果有推荐者),并将金额应用于推荐者的用户账户。
您的订单对象需要实现 \Shaygan\AffiliateBundle\Model\OrderInterface。
安装
通过Composer
$ composer require shaygan/affiliate-bundle
编辑您的app/AppKernel.php,在registerBundles()方法中注册此Bundle,如上所示
class AppKernel extends Kernel { public function registerBundles() { $bundles = array( // ... // register the bundle here new \Shaygan\AffiliateBundle\ShayganAffiliateBundle() ); } }
配置Bundle
此Bundle旨在直接使用。为了使此Bundle运行,您需要配置的只有佣金类型金额和计数。
# app/config/config.yml shaygan_affiliate: programs: membership_upgrade: type: fixed-amount first_commission_amount: 3 commission_amount: 1 max_count: 10 purchase: type: percentage first_commission_percent: 15 commission_percent: 10 max_count: 10
默认情况下,它在URL中寻找?ref=REFERRER_ID,其中ref是可配置的
用法
ShayganAffiliateBundle自动跟踪FOSUserBundle注册,并在每次购买后,只需请求Bundle的佣金支付即可。如果推荐者有资格获得佣金,该Bundle将返回一个包含您需要支付给推荐者的金额的佣金实体,否则返回null。
// ... // MyOrder SHOULD implements \Shaygan\AffiliateBundle\Model\OrderInterface $order = new \AppBundle\Entity\MyOrder(); $order->setOwnerUser($this->getUser()); $em = $this->getDoctrine()->getManager(); $em->persist($order); $em->flush(); $affiliate = $this->get("shaygan_affiliate"); $commission = $affiliate->getPurchaseCommission($order); if(null !== $commission){ $commissionAmount = $commission->getCommissionAmount(); $referrer = $commission->getReferrer(); $referrerUserId = $referrer->getId(); // You can apply the commission amount to the accont of referrer User here // ... } //...
测试
尚未实现
许可
MIT许可(MIT)。有关更多信息,请参阅许可文件。