db_dist.php — 数据库连接和所有业务函数
distributor_register.php — 推广员注册页面
distributor_login.php — 推广员登录/后台
admin_distributor.php — 管理后台(佣金比例/提现审核)
referral.php — 推广链接追踪 + 佣金结算API
distributor.db — SQLite 数据库(自动生成)
把整个 distributor/ 文件夹上传到你的网站目录
确保 PHP 有 SQLite 扩展(一般默认开启)
访问 admin_distributor.php,默认密码 admin123
务必在上线前修改密码!在文件顶部修改 ADMIN_PASSWORD 常量
在商城支付回调里调用佣金结算接口
// 在你的 return_url.php 或 notify_url.php 里加:
require_once __DIR__ . '/distributor/db_dist.php';
// 假设 $out_trade_no 是订单号, $money 是金额, $user_id 是用户ID
// 查找该用户绑定的推广员并结算佣金
$ref_code = $_COOKIE['dist_ref'] ?? '';
if (!empty($ref_code)) {
$distributor = dist_find_by_code($ref_code);
if ($distributor) {
dist_bind_referral($distributor['id'], $user_id);
dist_calculate_commission($distributor['id'], $out_trade_no, $money);
}
}
测试流程:
1. 注册一个推广员 → 拿到推广码
2. 访问 yourdomain.com/distributor/referral.php?ref=推广码
3. 用该用户的身份下单支付
4. 登录推广员后台查看佣金是否到账
1. 修改管理后台密码(admin_distributor.php 顶部)
2. distributor.db 文件建议放到网站根目录之外,或通过 .htaccess 禁止直接下载
3. 生产环境建议加 HTTPS
4. 佣金结算建议做防重复处理(同一订单不重复发佣金)