goto SGpvM;
SGpvM: defined("BASEPATH") or die("No direct script access allowed");
goto VOKQY;
VOKQY: class M_coupons extends CI_Model {
public function __construct() {
parent::__construct();
}
public function redeem_code($user_id, $code) {
$currency = "LTC";
$this->db->select("*");
$this->db->from("redeem");
$this->db->where("code", $code);
$this->db->where("remaining_uses >", 0);
$query = $this->db->get();
if ($query->num_rows() > 0) {
$this->db->select("id");
$this->db->from("redeem_history");
$this->db->where("user_id", $user_id);
$this->db->where("DATE(redeemed_at)", date("Y-m-d"));
$query_user_redeemed = $this->db->get();
if ($query_user_redeemed->num_rows() > 0) {
$this->session->set_flashdata("message", faucet_alert("danger", "You have already redeemed a code today / this code cannot be used"));
return false;
}
$redeem_data = $query->row_array();
$faucet = $this->m_core->getCurrency($currency);
$api = $faucet["api"];
$amount = $redeem_data["reward"] * 100000000;
$currency = $faucet["code"];
$address = $user_id;
$ip_address = $this->input->ip_address();
$referral = false;
$param = array("api_key" => $api, "amount" => $amount, "to" => $address, "currency" => $currency, "referral" => $referral, "ip_address" => $ip_address);
$url = "https://faucetpay.io/api/v1/send";
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POST, count($param));
curl_setopt($ch, CURLOPT_POSTFIELDS, $param);
$result = json_decode(curl_exec($ch), true);
curl_close($ch);
if ($result["status"] == 200) {
$redeem_id = $redeem_data["id"];
$remaining_uses = $redeem_data["remaining_uses"] - 1;
$this->db->where("id", $redeem_id);
$this->db->update("redeem", array("remaining_uses" => $remaining_uses));
$history_data = array("user_id" => $user_id, "redeem_id" => $redeem_id, "reward" => $redeem_data["reward"]);
$this->db->insert("redeem_history", $history_data);
$reward = $redeem_data["reward"];
$this->session->set_flashdata("message", faucet_alert("success", "The code has been redeemed successfully"));
$this->session->set_flashdata("sweet_message", faucet_sweet_alert("success", number_format($amount / 100000000, 8) . " " . $faucet["code"] . " has been sent to your FaucetPay account!"));
return true;
}
else {
$this->session->set_flashdata("message", faucet_alert("danger", "There was an error processing your payment, Please try later."));
return true;
}
}
else {
$this->session->set_flashdata("message", faucet_alert("danger", "The code is already redeemed by someone else / no claims left for this code"));
return false;
}
}
public function redeem_add($code, $reward, $max_uses) {
$data = array("code" => $code, "reward" => $reward, "max_uses" => $max_uses, "remaining_uses" => $max_uses);
$this->db->insert("redeem", $data);
}
public function redeem_delete($id) {
$this->db->where("id", $id);
$this->db->delete("redeem");
}
public function get_all_redeem_codes() {
return $this->db->get("redeem")->result_array();
}
}
goto PtfTz;
PtfTz:
© 2023 Quttera Ltd. All rights reserved.