File size: 1,550 Bytes
0dff816 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
<?php
class Referral {
private $conn;
private $table_name = "referrals";
public $id;
public $referrer_id;
public $referred_id;
public $status;
public $commission_earned;
public function __construct($db) {
$this->conn = $db;
}
// Create new referral
public function createReferral($referrer_id, $referred_id) {
$query = "INSERT INTO " . $this->table_name . "
(referrer_id, referred_id, status)
VALUES (?, ?, 'pending')";
$stmt = $this->conn->prepare($query);
$stmt->bindParam(1, $referrer_id);
$stmt->bindParam(2, $referred_id);
return $stmt->execute();
}
// Complete referral (when referred user makes deposit)
public function completeReferral($referred_id, $commission_amount) {
$query = "UPDATE " . $this->table_name . "
SET status = 'completed', commission_earned = ?
WHERE referred_id = ? AND status = 'pending'";
$stmt = $this->conn->prepare($query);
$stmt->bindParam(1, $commission_amount);
$stmt->bindParam(2, $referred_id);
return $stmt->execute();
}
// Get referral by referred user ID
public function getReferralByReferredId($referred_id) {
$query = "SELECT * FROM " . $this->table_name . " WHERE referred_id = ? LIMIT 1";
$stmt = $this->conn->prepare($query);
$stmt->bindParam(1, $referred_id);
$stmt->execute();
return $stmt->fetch(PDO::FETCH_ASSOC);
}
}
?> |