I am creating custom e-commerce website in PHP OOP. Almost all (shopping system) things are done. I just wanna add referral system. But i am confused how to do.
When customer sign up then referral code/link should generate for that user and when customer share that link with his friends and his friends registered in our website then that customer who refers and who signed up using that referral code/link, both will get reward (price). Even, i didn't understand how to make structure. If you know about how to create this kind of system. Then at least guide me structure and how to create this.
My users table is here:
Click to see screenshot
My insert users function:
public function createAccount($data){
$first_name = mysqli_real_escape_string($this->db->link, $data['first_name']);
$last_name = mysqli_real_escape_string($this->db->link, $data['last_name']);
$phone_number = mysqli_real_escape_string($this->db->link, $data['phone_number']);
$password = mysqli_real_escape_string($this->db->link, $data['password']);
if($first_name == "" || $last_name == "" || $phone_number == "" || $password == ""){
$msg = "Required fields can not be empty. Please fill the fields.";
return $msg;
} else if($this->checkPhoneNumber($phone_number) === true){
$msg = "Phone Number is already in use. Try another phone number!";
return $msg;
} else {
$query = "INSERT INTO users(first_name, last_name, phone_number, password, authority, created_on) VALUES('$first_name', '$last_name', '$phone_number', '$password', 'Customer' , NOW())";
$result = $this->db->insert($query);
if($result != false){
$func = $this->loginDuringCreatingAccount($phone_number, $password);
return $func;
}
}
}
public function checkPhoneNumber($phone_number){
$query = "SELECT `phone_number` FROM users WHERE phone_number = '$phone_number'";
$result = $this->db->select($query);
$count = @$result->num_rows;
if ($count > 0){
return true;
} else {
return false;
}
}
public function loginDuringCreatingAccount($phone_number, $password){
$query = "SELECT * FROM users WHERE phone_number = '$phone_number' AND password = '$password'";
$resultS = $this->db->select($query);
if($resultS != false){
$value = $resultS->fetch_assoc();
Session::set("userlogin", true);
Session::set("user_id", $value['user_id']);
Session::set("first_name", $value['first_name']);
Session::set("last_name", $value['last_name']);
Session::set("phone_number", $value['phone_number']);
Session::set("password", $value['password']);
header("Location: choose-username.php?step=last");
}
}
Now, i have to update/add some column names in this users table or for that system i have to create new table. And if i have to create new table then i have to join users and that new table or not?
Can you please guide me to create this system?