File: /home/barbeatleanalyti/public_html/m.beatleanalytics.com/application/models/Customer_model.php
<?php
class Customer_model extends CI_Model
{
/*
public function loginSurvey($depId)
{
$this->load->database();
$query = $this->db->get_where("beatle_industry" , array("db_IndLoginId"=>$depId));
$result = $query->result();
return $result;
} */
public function endUserLogin($username,$password)
{
$this->load->database();
$pass = md5($password);
$SQL = "SELECT * FROM beatle_userlogin WHERE (db_phone = '".$username."' OR db_userLoginName = '".$username."') AND db_password = '".$pass."' AND db_usertype = 'End_user' ";
//echo "<br />";
$query = $this->db->query($SQL);
$data = $query->result();
if($data)
{
return $data;
}
else
{
$json = '0';
return $json;
}
}
public function SignUpUserLogin($insertdata,$enduseremail)
{
$this->load->database();
$select = $this->db->get_where("beatle_userlogin" , array("db_phone"=>$enduseremail));
$result = $select->result();
if (!empty($result))
{
$error = 'already';
return $error;
}
else
{
$query = $this->db->insert("beatle_userlogin",$insertdata);
if ($query)
{
$success = 'yes';
//$json = json_encode($success);
return $success;
}
else
{
$success = '0';
$json = json_encode($success);
return $json;
}
}
}
public function fetchProductsImage(){
}
public function LoadCustomerData(){
$this->load->database();
$userID = $this->session->userdata('userId');
$select = $this->db->get_where("beatle_userlogin" , array("userId"=>$userID));
$result = $select->result();
return $result;
}
public function fetchStateData(){
$this->load->database();
$select = $this->db->get_where("states" , array("country_id"=>101));
$result = $select->result();
return $result;
}
public function fetchStateDataIndividual($stateid){
$this->load->database();
$select = $this->db->get_where("states" , array("id"=>$stateid));
$result = $select->result();
return $result;
}
public function fetchCityDataIndividual($cityid){
$this->load->database();
$select = $this->db->get_where("cities" , array("id"=>$cityid));
$result = $select->result();
return $result;
}
public function fetchCityData($stateid){
$this->load->database();
$select = $this->db->get_where("cities" , array("id"=>$stateid));
$result = $select->result();
return $result;
}
public function UpdateCustomerData($updateArr){
$this->load->database();
$userID = $this->session->userdata('userId');
return $query = $this->db->where('userId',$userID)->update('beatle_userlogin',$updateArr);
}
public function checkEmailExist($email){
$this->load->database();
$userID = $this->session->userdata('userId');
//$select = $this->db->get_where("beatle_userlogin" , array("db_email"=>$email));
$select = $this->db->get_where('beatle_userlogin' , array('db_email'=>$email,'userId != '=>$userID));
$result = $select->result();
if(count($result) > 0){
return 'Y';
}else{
return 'N';
}
}
public function insertOrderData($insertArr){
$this->load->database();
$this->db->insert("beatle_order" , $insertArr);
return $this->db->insert_id() ;
}
public function insertPointData($insertArr){
$this->load->database();
return $this->db->insert("beatle_points" , $insertArr);
//return $this->db->insert_id() ;
}
public function UpdateOrderUniqueID($orderid,$updateArr){
$this->load->database();
return $query = $this->db->where('orderid',$orderid)->update('beatle_order',$updateArr);
}
public function fetchMyOrders(){
$this->load->database();
$userid = $this->session->userdata('userId');
$this->db->select("*");
$this->db->from("beatle_order");
$this->db->where("userid",$userid);
$this->db->order_by('created_date','desc');
$query = $this->db->get();
return $result = $query->result();
//return $query = $this->db->where('userid',$userid)->update('beatle_order',$updateArr);
}
public function fetchMyBonusPoint(){
$this->load->database();
$userid = $this->session->userdata('userId');
$this->db->select("SUM(Amount) AS AddedBonus");
$this->db->from("beatle_points");
$this->db->where("userid",$userid);
$this->db->where("IsRedeem","N");
$query = $this->db->get();
$result = $query->result();
$totalBonus = $result[0]->AddedBonus;
$this->db->select("SUM(Amount) AS RedeemBonus");
$this->db->from("beatle_points");
$this->db->where("userid",$userid);
$this->db->where("IsRedeem","Y");
$query = $this->db->get();
$result = $query->result();
$RedeemBonus = $result[0]->RedeemBonus;
return $totalBonus-$RedeemBonus;
//return $query = $this->db->where('userid',$userid)->update('beatle_order',$updateArr);
}
public function fetchMyBonusPointDetails(){
$this->load->database();
$userid = $this->session->userdata('userId');
$this->db->select("*");
$this->db->from("beatle_points");
$this->db->where("UserID",$userid);
$this->db->where("IsRedeem","N");
$this->db->order_by("AddedDate","DESC");
$query = $this->db->get();
return $result = $query->result();
}
public function fetchOffersData(){
$this->load->database();
$this->db->select("*");
$this->db->from("beatle_offers");
$this->db->where("active","Y");
$this->db->where("onhold","N");
$this->db->where("onhold","N");
$this->db->where('startdate <= ',date('Y-m-d H:i:s'));
$this->db->where('enddate >= ',date('Y-m-d H:i:s'));
$query = $this->db->get();
return $result = $query->result();
//return $query = $this->db->where('userid',$userid)->update('beatle_order',$updateArr);
}
public function fetchOfferUsingOfferid($offerid){
$this->load->database();
$select = $this->db->get_where("beatle_offers" , array("offerid"=>$offerid));
return $result = $select->result();
}
public function fetchAppliedOfferDataByCustomer($offerid){
$this->load->database();
$sdate = date("Y-m-d H:i:s");
$edate = date("Y-m-d H:i:s",strtotime("+1 hour"));
$userid = $this->session->userdata('userId');
$this->db->select("*");
$this->db->from("beatle_offers_apply");
$this->db->where("userid",$userid);
$this->db->where("offerid",$offerid);
$this->db->where("cancel","N");
$this->db->where("approved","N");
$this->db->where('expire_time BETWEEN "'.$sdate.'" AND "'.$edate.'"');
$query = $this->db->get();
return $result = $query->result();
}
public function insertOfferAppliedDataToCustomer($insertData){
$this->load->database();
return $this->db->insert('beatle_offers_apply',$insertData);
}
public function GeneratePassword($length_ = 5){
$alphabet = "0123456789";
$pass = array(); //remember to declare $pass as an array
$alphaLength = strlen($alphabet) - 1; //put the length -1 in cache
for ($i = 0; $i < $length_; $i++) {
$n = rand(0, $alphaLength);
$pass[] = $alphabet[$n];
}
return implode($pass); //turn the array into a string
}
public function UpdateProductStockQuantity($prodid,$updateStockArr){
$this->load->database();
return $query = $this->db->where('productid',$prodid)->update('beatle_products',$updateStockArr);
}
public function getOrganizationById($Orgid)
{
$this->load->database();
$query = $this->db->get_where('beatle_organization' , array('OrgId'=>$Orgid));
$result = $query->result();
return $result;
}
public function getBranchName($brnchID){
$this->load->database();
$query = $this->db->get_where('beatle_branch' , array('branchId'=>$brnchID));
$result = $query->result();
return $result;
}
public function getIndustryName($indid){
$this->load->database();
$query = $this->db->get_where('beatle_industry' , array('IndId'=>$indid));
$result = $query->result();
return $result;
}
public function defineCustomerAppColor(){
$this->load->database();
$select = $this->db->get('appconfig');
$rsConfig = $select->result();
foreach($rsConfig as $key => $val){
define($val->ConfigName,$val->ConfigValue);
}
/*
$select = $this->db->get_where('appconfig' , array('ConfigName'=>"CA_BACKGROUND_COLOR"));
$result = $select->result();
define("CA_BACKGROUND_COLOR",$result[0]->ConfigValue);
$select = $this->db->get_where('appconfig' , array('ConfigName'=>"CA_FOOTER_COLOR"));
$result = $select->result();
define("CA_FOOTER_COLOR",$result[0]->ConfigValue);
$select = $this->db->get_where('appconfig' , array('ConfigName'=>"CA_LOGIN_BUTTON_COLOR"));
$result = $select->result();
define("CA_LOGIN_BUTTON_COLOR",$result[0]->ConfigValue); */
}
/*
public function insertUserFeedback($userid,$LoginIndid,$pageid,$pageConId,$avavalue)
{
$this->load->database();
$branchId = 0;
$getBranchID = $this->db->get_where("beatle_industry" ,array("IndId"=>$this->session->userdata('LoginIndid')));
$rsBrandID = $getBranchID->result();
$branchId = $rsBrandID[0]->db_bracnchid;
// to get orgid
$rsBranches = $this->db->get_where("beatle_branch",array("branchId"=>$branchId));
$rsBrancDetails = $rsBranches->result();
$orgID = $rsBrancDetails[0]->db_branchOrg;
$date = date('Y-m-d H:i:s');
$insertdata = array
(
'db_surveyUserid' => $userid,
'db_surveyIndId' => $LoginIndid,
'db_surveyPageid' => $pageid,
'db_surveyContentId' => $pageConId,
'db_surveyBranchid' => $branchId,
'db_surveyValue' => $avavalue,
'created_date' => $date,
'tokenid' => $this->session->userdata('tokenID'),
'orgid' => $orgID,
'is_submit' => "N"
);
$updatecheck = array
(
'db_surveyUserid' => $userid,
'db_surveyIndId' => $LoginIndid,
'db_surveyPageid' => $pageid,
'db_surveyBranchid' => $branchId,
'db_surveyContentId' => $pageConId,
'tokenid' => $this->session->userdata('tokenID'),
'orgid' => $orgID,
'is_submit' => "N"
);
//$this->db->select("*");
//$this->db->from();
$query = $this->db->get_where("beatle_survey" , $updatecheck);
$result = $query->result();
if (empty($result))
{
$insertquery = $this->db->insert("beatle_survey" , $insertdata);
if ($insertquery)
{
echo 'ddd';
}
}
else
{
$this->load->database();
$this->db->where("db_surveyUserid",$userid);
$this->db->where("db_surveyIndId",$LoginIndid);
$this->db->where("db_surveyPageid",$pageid);
$this->db->where("db_surveyContentId",$pageConId);
$insertquery = $this->db->update("beatle_survey" , array('db_surveyValue' => $avavalue));
if ($insertquery)
{
echo 'update';
}
}
} */
}
?>