Commit 205dcb7e by Tobin

Merge branch 'jansa' into 'master'

Jansa See merge request !95
parents 90fb8b78 98b3933a
......@@ -522,7 +522,6 @@ class Webservice extends CI_Controller {
}
public function get_friend_requests(){
$data = (array) json_decode(file_get_contents('php://input'));
$data['auth_token'] = $this->auth_token;
$res = $this->Webservice_model->get_friend_requests($data);
if($res['status']!=0){
......@@ -578,5 +577,17 @@ class Webservice extends CI_Controller {
$this->errorResponse($res['code'],$res['message']);
}
}
public function validate_promo_code(){
$data = (array) json_decode(file_get_contents('php://input'));
$data['auth_token'] = $this->auth_token;
$res = $this->Webservice_model->validate_promo_code($data);
if($res['status']!=0){
$this->response($res['data']);
}
else{
$this->errorResponse($res['code'],$res['message']);
}
}
}
?>
......@@ -40,10 +40,12 @@ class Promocode_model extends CI_Model {
}
$dataArr['city_id'] = $promodata['city_id'];
$dataArr['event_id'] = $promodata['event_id'];
$dataArr['end_date'] = $promodata['end_date'];
//$dataArr['end_date'] = $promodata['end_date'];
$dataArr['end_date'] = date('Y-m-d',$promodata['end_date']);
$dataArr['use_limit'] = $promodata['use_limit'];
$dataArr['max_redeem'] = $promodata['max_redeem'];
$dataArr['start_date'] = $promodata['start_date'];
//$dataArr['start_date'] = $promodata['start_date'];
$dataArr['start_date'] = date('Y-m-d',$promodata['start_date']);
$dataArr['category_id'] = $promodata['category_id'];
$dataArr['discount_type'] = $promodata['discount_type'];
$dataArr['promocode_name'] = $promodata['promocode_name'];
......@@ -89,10 +91,12 @@ class Promocode_model extends CI_Model {
}
$dataArr['city_id'] = $promodata['city_id'];
$dataArr['event_id'] = $promodata['event_id'];
$dataArr['end_date'] = $promodata['end_date'];
// $dataArr['end_date'] = $promodata['end_date'];
$dataArr['end_date'] = date('Y-m-d',$promodata['end_date']);
$dataArr['use_limit'] = $promodata['use_limit'];
$dataArr['max_redeem'] = $promodata['max_redeem'];
$dataArr['start_date'] = $promodata['start_date'];
// $dataArr['start_date'] = $promodata['start_date'];
$dataArr['start_date'] = date('Y-m-d',$promodata['start_date']);
$dataArr['category_id'] = $promodata['category_id'];
$dataArr['discount_type'] = $promodata['discount_type'];
$dataArr['promocode_name'] = $promodata['promocode_name'];
......
......@@ -185,6 +185,45 @@ class Validation_app_model extends CI_Model {
'message' => 'User id is null or empty'
)
)
),
'getCountry' => array(),
'validate_promo_code'=>array(
'auth_token' => array(
'required' => array(
'code' => 'ER02',
'message' => 'User id is null or empty'
)
) ,
'event_id' => array(
'required' => array(
'code' => 'ER04',
'message' => 'Event Id is null or empty'
) ,
),
'promo_code' => array(
'required' => array(
'code' => 'ER02',
'message' => 'Promocode is null or empty'
)
) ,
'no_of_tickets' => array(
'required' => array(
'code' => 'ER04',
'message' => 'No of Ticket is null or empty'
)
),
'seat_class' => array(
'required' => array(
'code' => 'ER04',
'message' => 'Seat Class is null or empty'
) ,
),
'tot_cost' => array(
'required' => array(
'code' => 'ER04',
'message' => 'Total Cost is null or empty'
) ,
)
)
);
......
......@@ -1773,10 +1773,12 @@ class Webservice_model extends CI_Model {
CHT.type AS friend_status
FROM customer AS CUST
LEFT JOIN chats AS CHT ON ((CUST.customer_id=CHT.from_user OR CUST.customer_id=CHT.to_user) AND CHT.type=1)
WHERE (".$phNumbers.") AND
customer_id NOT IN (SELECT from_user FROM chats WHERE (from_user=$user_id AND type='2') OR (to_user =$user_id AND type='2')) AND
customer_id NOT IN (SELECT to_user FROM chats WHERE (from_user=$user_id AND type='2') OR (to_user =$user_id AND type='2'))");
$respArr['status'] = 1;
if(!empty($result) && !empty($result = $result->result_array())){
$respArr['data'] = $result;
......@@ -1788,7 +1790,8 @@ class Webservice_model extends CI_Model {
public function update_friend_request($data){
$user_id = $this->auth_token_get($data['auth_token']);
$status = $this->db->query("UPDATE chats SET type = ".$data['add_as_friend']." WHERE from_user = $user_id AND to_user = ".$data['user_id']);
$status = $this->db->query("UPDATE chats SET type='".$data['add_as_friend']."'
WHERE from_user='".$data['user_id']."' AND to_user='".$user_id."'");
return ($status)?1:0;
}
......@@ -1813,10 +1816,12 @@ class Webservice_model extends CI_Model {
public function get_friend_requests($data){
$respArr = array('status'=>0,'code'=>'918','message'=>'No Request for you');
$user_id = $this->auth_token_get($data['auth_token']);
$this->db->select("name,phone,profile_image,customer_id");
$this->db->join('customer','customer.customer_id = chats.to_user');
$result=$this->db->get_where('chats',array('to_user'=>$user_id,'type'=>'0'))->result_array();
if(!empty($result)){
$result = $this->db->query("SELECT CUST.name,CUST.phone,CUST.profile_image,CUST.customer_id
FROM customer AS CUST
INNER JOIN chats AS CHT ON (CUST.customer_id = CHT.from_user)
WHERE type='0' AND to_user='".$user_id."'");
if(!empty($result) && !empty($result = $result->result())){
$respArr['status'] = 1;
$respArr['data'] = $result;
}
......@@ -1829,11 +1834,20 @@ class Webservice_model extends CI_Model {
$result = $this->db->query("SELECT from_user,to_user,type FROM chats WHERE (from_user=$user_id OR to_user=$user_id) AND type IN('0','1')")->result_array();
if(!empty($result)){
foreach ($result as $key => $value) {
if($value['to_user'] == $user_id && $value['type'] == 0){
if($value['type'] == 0){
continue;
}
$fromUsrId = '';
if($value['to_user']==$user_id){
$fromUsrId = $value['from_user'];
} else if ($value['from_user'] == $user_id){
$fromUsrId = $value['to_user'];
} else {
continue;
}
$this->db->select("name,phone,profile_image,customer_id");
$cust = $this->db->get_where('customer',array('customer_id'=>$value['to_user']));
$cust = $this->db->get_where('customer',array('customer_id'=>$fromUsrId));
if(!empty($cust) && !empty($cust = $cust->row_array())){
$custData[] = $cust;
}
......@@ -1844,7 +1858,7 @@ class Webservice_model extends CI_Model {
return $respArr;
}
function getCountry() {
public function getCountry() {
try {
$rs = $this->db->query("SELECT * FROM country WHERE status = 1 ORDER BY country_name")->result();
if(count($rs) > 0) {
......@@ -1858,7 +1872,7 @@ class Webservice_model extends CI_Model {
return $res;
}
function getCountryData($user_id){
public function getCountryData($user_id){
$ctryData = $this->db->query("SELECT CTRY.* FROM customer AS CUST
INNER JOIN country AS CTRY ON (CTRY.country_id=CUST.country_id)
WHERE CUST.customer_id='$user_id'")->row_array();
......@@ -1867,5 +1881,83 @@ class Webservice_model extends CI_Model {
}
return $ctryData;
}
public function validate_promo_code($data =array()){
$date = date('Y-m-d');
$promoCode = $data['promo_code'];
$tot_cost = $data['tot_cost'];
$promoData = $this->db->query("SELECT PROM.*
FROM promocode_management AS PROM
WHERE PROM.promocode_name='$promoCode' AND PROM.status='1' AND
PROM.start_date<='$date' AND PROM.end_date>='$date' AND
PROM.use_limit>(SELECT count(id) FROM promocode_used AS PU
WHERE PU.promocode_id=PROM.promocode_id AND
PU.status=1)");
if(empty($promoData) || empty($promoData = $promoData->row_array())){
$respArr['status'] = 0;
$respArr['code'] = 980;
$respArr['message'] = 'Invalid Promocode';
return $respArr;
}
$eventData = $this->db->query("SELECT VEN.region_id,EVT.category_id FROM events AS EVT
INNER JOIN venue AS VEN ON (VEN.id = EVT.venue_id)
WHERE EVT.event_id='".$promoData['event_id']."' AND EVT.status='1'");
if(empty($eventData) || empty($eventData = $eventData->row_array())){
$respArr['status'] = 0;
$respArr['code'] = 980;
$respArr['message'] = 'Promocode Invalid or Expired';
return $respArr;
}
if(!empty($promoData['event_id']) && $promoData['event_id'] != $data['event_id']){
$respArr['status'] = 0;
$respArr['code'] = 981;
$respArr['message'] = 'Promocode is not Valid for this Event';
return $respArr;
}
if(!empty($promoData['category_id']) && $promoData['category_id'] != $eventData['category_id']){
$respArr['status'] = 0;
$respArr['code'] = 982;
$respArr['message'] = 'Promocode is not Valid for this Category';
return $respArr;
}
if(!empty($promoData['city_id']) && $promoData['city_id'] != $eventData['region_id']){
$respArr['status'] = 0;
$respArr['code'] = 983;
$respArr['message'] = 'Promocode is not Valid for this City';
return $respArr;
}
if(!empty($promoData['min_order_amount']) && $promoData['min_order_amount'] > $tot_cost){
$respArr['status'] = 0;
$respArr['code'] = 984;
$respArr['message'] = 'Minimum amount is not satisfied';
$respArr['minimum_amount'] = $promoData['min_order_amount'];
return $respArr;
}
$discAmt = 0;
if($promoData['discount_type'] == 1){
$discAmt = $tot_cost - (($tot_cost * $promoData['discount_percentage'])/100);
} else {
$discAmt = ($tot_cost<=$promoData['discount_percentage'])?0:$tot_cost-$promoData['discount_percentage'];
}
if(!empty($promoData['max_redeem']) && $promoData['max_redeem'] < $discAmt){
$discAmt = $promoData['max_redeem'];
}
$promDetails = langTranslator($promoData['promocode_id'],'PROMO','');
$datas['discounted_price'] = $discAmt;
$datas['promocode_tc_ar'] = $promDetails['promocode_tc_AR'];
$datas['promocode_tc_en'] = $promDetails['promocode_tc_EN'];
$datas['promocode_desc_ar'] = $promDetails['promocode_desc_AR'];
$datas['promocode_desc_en'] = $promDetails['promocode_desc_EN'];
$respArr['status'] = 1;
$respArr['data'] = $datas;
return $respArr;
}
}
?>
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment