Yeknava/simple-affiliate

为Laravel的简单联盟包

0.6 2020-10-09 15:38 UTC

This package is auto-updated.

Last update: 2024-09-09 23:50:38 UTC


README

Laravel Simple Affiliate Package.

功能

  • Utm代码
  • 出版商余额
  • 推广日志
  • 速率限制

安装

使用composer包管理器来安装simple affiliate包。

composer require yeknava/simple-affiliate

使用

在您的终端运行此命令

php artisan vendor:publish

将AffiliatePublisher特质添加到用户模型。

<?php

use Yeknava\SimpleAffiliate\AffiliatePublisher;

class User extends Model {
    use AffiliatePublisher;

    protected static function boot()
    {
        parent::boot();
        self::publisherBoot();
    }
}

将AffiliatePublishable特质添加到可发布(可购买)模型。

<?php

use Yeknava\SimpleAffiliate\AffiliatePublishable;

class ItemModel extends Model {
    use AffiliatePublishable;
}
$user1 = new UserModel([]);
$user1->save();

$code = $user1->utmCode();
$user1->publisherBalance(); // 0

$item = new ItemModel([]);
$item->save();

$data = [
    'source' => 'google',
    'medium' => 'email',
    'campaign' => 'spring-sale',
    'content' => 'footer-button',
    'type' => 'paid',
    'extra' => [
        'user_id' => $user1->id
    ]
];

$item->promoted($code, $data, 1000, 1); // with 1 percent share (10 unit share for publisher)

$user1->publisherBalance(); // 10

$item->promoted($code, $data, 100); // with default share

配置

<?php

use Yeknava\SimpleAffiliate\Samples\WalletServiceSample;

return [
    'default_share' => 5,

    'dedicate_wallet_service' => null, //WalletServiceSample::class

    // seconds needs to passed before each new log
    // could be save with same utm code and item
    'rate_limit' => 0,

    'rate_limit_agent' => false,

    'rate_limit_throw_exception' => false,

    'create_utm_on_save' => true,

    // if create_utm_on_fetch be true, utm will be created if publisher has not any utm
    // useful when app does not have this package from first day of it's launch
    'create_utm_on_fetch' => true,

    'codes_table' => 'utm_codes',

    'logs_table' => 'utm_logs'
];

贡献

欢迎提交拉取请求。对于主要更改,请首先提交一个问题来讨论您想进行的更改。

许可证

MIT