Exemplo n.º 1
0
 function login_post()
 {
     $userName = trim($this->post('userName'));
     $password = trim($this->post('password'));
     $UDID = trim($this->post('UDID'));
     $deviceType = trim($this->post('deviceType'));
     $deviceToken = trim($this->post('deviceToken'));
     $latitude = trim($this->post('latitude'));
     $longitude = trim($this->post('longitude'));
     if (!filter_var($userName, FILTER_VALIDATE_EMAIL)) {
         $this->response(array('error' => 'Please provide valid email.'), 400);
         return FALSE;
     }
     if ($password == "") {
         $this->response(array('error' => 'Please provide password.'), 400);
         return FALSE;
     }
     $defaultDataArr = array('UDID' => $UDID, 'deviceType' => $deviceType, 'deviceToken' => $deviceToken, 'latitude' => $latitude, 'longitude' => $longitude);
     $isValideDefaultData = $this->check_default_data($defaultDataArr);
     if ($isValideDefaultData['type'] == 'fail') {
         $this->response(array('error' => $isValideDefaultData['message']), 400);
         return FALSE;
     }
     $countryShortName = get_counry_code_from_lat_long($latitude, $longitude);
     //$countryShortName='IN';
     if ($countryShortName == FALSE) {
         //$this->response(array('error' => 'Please provide valid latitude and longitude!'), 400); return FALSE;
     }
     //$rs=$this->db->from('user')->where('userName',$userName,'password',  base64_decode($password).'~'.)
     $rs = $this->user->check_login_data($userName, $password, 'logistics');
     if (count($rs) > 0) {
         $parram = array('userId' => $rs[0]->userId, 'message' => 'You have logedin successfully');
         success_response_after_post_get($parram);
     } else {
         $this->response(array('error' => 'Invalid username or password,please try again.'), 400);
         return FALSE;
     }
 }
Exemplo n.º 2
0
 /**
  *
  * @param type $categoryId
  * @param type $offset
  * @param type $limit
  * @param type $cond
  * @return type
  */
 public function get_search_products_app($offset = null, $limit = null, $cond, $latitude, $longitude)
 {
     $this->_currentUserCountryCode = get_counry_code_from_lat_long($latitude, $longitude);
     $group_by = ' GROUP BY p.productId';
     $join_query = "";
     $sort = array('featured', 'isNew', 'popular', 'lowestPrice');
     $order_by = 'p.popular';
     if (array_key_exists('order_by', $cond)) {
         if (isset($cond['order_by']) && $cond['order_by'] && in_array($cond['order_by'], $sort)) {
             $order_by = '  ORDER BY ' . $cond['order_by'];
             unset($cond['order_by']);
         } else {
             $order_by = '  ORDER BY p.popular';
         }
     } else {
         $order_by = '  ORDER BY p.popular';
     }
     $order_sort = ' ASC';
     if (array_key_exists('order_sort', $cond)) {
         if (isset($cond['order_sort']) && $cond['order_sort']) {
             $order_sort = ' ' . $cond['order_sort'];
             unset($cond['order_sort']);
         }
     }
     $plimit = '';
     if ($offset >= 0 && $limit) {
         $plimit = ' LIMIT ' . $offset . ', ' . $limit;
     }
     $where_str = 'p.status = 1 ';
     if (array_key_exists('qtype', $cond) && array_key_exists('id', $cond)) {
         if ($cond['qtype'] == "category" && $cond['id']) {
             $where_str = $where_str . " AND c.categoryId = " . $cond['id'] . "";
         }
     }
     $bd = false;
     $bdor = 0;
     $bdquery = "";
     $bb = "";
     if (array_key_exists('brand', $cond)) {
         if (isset($cond['brand']) && $cond['brand']) {
             $brands = implode('","', $cond['brand']);
             $bdquery = $bdquery . ' AND b.title IN ("' . $brands . '")';
             $bb = $bb . ' b.title IN ("' . $brands . '")';
             $bd = true;
         }
     }
     if (array_key_exists('qtype', $cond) && array_key_exists('id', $cond)) {
         if ($cond['qtype'] == "brand" && $cond['id']) {
             $opr = "AND";
             if ($bd) {
                 $opr = "OR";
                 $bdquery = " AND ( " . $bb . " ";
             }
             $bdquery = $bdquery . " " . $opr . " b.brandId = " . $cond['id'] . "";
             if ($bd) {
                 $bdquery = $bdquery . " ) ";
             }
         }
     }
     $where_str = $where_str . $bdquery;
     if (array_key_exists('range', $cond)) {
         if (isset($cond['range']) && $cond['range']) {
             $lowestPrice = $cond['range'][0];
             $heighestPrice = $cond['range'][1];
             $where_str = $where_str . ' AND p.lowestPrice >= ' . $lowestPrice . ' AND p.lowestPrice <= ' . $heighestPrice;
         }
     }
     if (array_key_exists('qtype', $cond) && array_key_exists('id', $cond)) {
         if ($cond['qtype'] == "product" && $cond['id']) {
             $where_str = $where_str . " AND p.productId = " . $cond['id'] . "";
         }
     }
     if (array_key_exists('range', $cond)) {
         if (isset($cond['terms']) && $cond['terms']) {
             //$where_str = $where_str." ( ";
             $join_query .= " LEFT JOIN product_option_values AS popvalue ON popvalue.productId = p.productId ";
             $qdata = [];
             $parts = $cond['terms'];
             $p = count($parts);
             $qstring = "";
             for ($i = 0; $i < $p; $i++) {
                 if ($i == 0) {
                     $qstring .= ' AND ( ';
                 } else {
                     $qstring .= ' OR ';
                 }
                 $qstring .= ' p.title LIKE "%' . $parts[$i] . '%"';
                 if (array_key_exists('qtype', $cond) || array_key_exists('id', $cond)) {
                     $qstring .= '  OR c.categoryName LIKE "%' . $parts[$i] . '%"';
                     $qstring .= '  OR b.title LIKE "%' . $parts[$i] . '%" ';
                     //$qstring .= ' OR (popvalue.value LIKE "%'.$parts[$i].'%" OR popvalue.value LIKE "%'.$parts[$i].'%") ';
                 }
             }
             $where_str = $where_str . $qstring;
             $where_str = $where_str . " ) ";
         }
     }
     if (isset($cond['query']) && $cond['query']) {
         $qdata = [];
         foreach ($cond['query'] as $qry) {
             $exq = explode("@", $qry);
             $qdata[$exq[0]][] = $exq[1];
         }
         $q_string = " ";
         $qn = count($qdata);
         $i = 0;
         foreach ($qdata as $qkey => $qopval) {
             $opval = implode("','", $qopval);
             $q_string .= " popvalue.option_id = '" . $qkey . "' AND value IN ('" . $opval . "')";
             $i++;
             if ($i < $qn) {
                 $q_string .= " OR ";
             }
         }
         $where_str = $where_str . ' AND (' . $q_string . ') ';
     }
     $sql = "SELECT `p`.*, `b`.`title` AS `btitle`, `c`.`categoryName`,\n            `c`.`image` AS `catImage`,`pimage`.`image` AS `pImage`\n            FROM `product` AS p\n            JOIN product_seller AS ps ON(p.productId=ps.productId) JOIN user AS u ON(ps.userId=u.userId)\n            JOIN billing_address AS ba ON(u.userId=ba.userId) JOIN country AS co ON(ba.countryId=co.countryId)\n            LEFT JOIN product_brand AS pb ON p.productId = pb.productId\n            LEFT JOIN brand AS b ON pb.brandId = b.brandId\n            LEFT JOIN product_category AS pc ON pc.productId = p.productId\n            LEFT JOIN category AS c ON c.categoryId = pc.categoryId\n            LEFT JOIN product_image AS pimage ON pimage.productId = p.productId\n            {$join_query}\n            WHERE co.countryCode='" . $this->_currentUserCountryCode . "' AND {$where_str} {$group_by} {$order_by} {$order_sort} {$plimit}";
     $rs = $this->db->query($sql)->result();
     //echo $this->db->last_query();//print_r($rs);
     $products = array();
     $brands = array();
     $pids = [];
     if ($rs) {
         foreach ($rs as $key => $product) {
             $products['products'][] = $product;
             $brands[$product->btitle] = $product->btitle;
             $pids[] = $product->productId;
         }
     }
     $options = $this->get_products_common_options($pids);
     if ($options) {
         $products['options'] = $options;
     } else {
         $products['options'] = [];
     }
     $products['brands'] = $brands;
     return $products;
 }
Exemplo n.º 3
0
 function check_default_data($dataArr)
 {
     $validateArr = array('type' => 'success');
     if ($dataArr['UDID'] == "") {
         $validateArr['type'] = 'fail';
         $validateArr['message'] = 'Please provide UDID.';
         return $validateArr;
     }
     if ($dataArr['deviceToken'] == "") {
         $validateArr['type'] = 'fail';
         $validateArr['message'] = 'Please provide deviceToken.';
         return $validateArr;
     }
     if ($dataArr['deviceType'] == "") {
         $validateArr['type'] = 'fail';
         $validateArr['message'] = 'Please provide deviceType.';
         return $validateArr;
     }
     if ($dataArr['latitude'] == "") {
         $validateArr['type'] = 'fail';
         $validateArr['message'] = 'Please provide latitude.';
         return $validateArr;
     }
     if ($dataArr['longitude'] == "") {
         $validateArr['type'] = 'fail';
         $validateArr['message'] = 'Please provide longitude.';
         return $validateArr;
     }
     $countryShortName = get_counry_code_from_lat_long($dataArr['latitude'], $dataArr['longitude']);
     //die($countryShortName);
     if ($countryShortName == FALSE) {
         $validateArr['type'] = 'fail';
         $validateArr['message'] = 'Please provide valid latitude and longitude';
         return $validateArr;
     }
     return $validateArr;
 }
Exemplo n.º 4
0
 function move_to_wish_list_post()
 {
     $userId = $this->post('userId');
     $latitude = $this->post('latitude');
     $longitude = $this->post('longitude');
     $deviceType = $this->post('deviceType');
     $user = $this->user->get_details_by_id($userId);
     if (empty($user)) {
         $this->response(array('error' => 'Please provide valid user index.'), 400);
         return FALSE;
     }
     $orderId = $this->post('orderId');
     $orderDetails = $this->order->details($orderId);
     if (empty($orderDetails)) {
         $this->response(array('error' => 'Please provide valid order index.'), 400);
         return FALSE;
     } elseif ($orderDetails[0]->status > 0) {
         $this->response(array('error' => 'Please provide valid order index,current is not in truck.'), 400);
         return FALSE;
     }
     $countryShortName = get_counry_code_from_lat_long($latitude, $longitude);
     $orderInfo = unserialize(base64_decode($orderDetails[0]->orderInfo));
     //pre($orderInfo);die;
     $productId = $orderInfo['priceinfo']->productId;
     $productPriceId = $orderInfo['priceinfo']->productPriceId;
     $wishListDataArr = array('userId' => $userId, 'productId' => $productId, 'productPriceId' => $productPriceId, 'latitude' => $latitude, 'longitude' => $longitude, 'appSource' => $deviceType, 'fromSource' => 'cart');
     if ($this->order->add_to_wish_list($wishListDataArr)) {
         $this->order->remove_order_from_cart($orderId, $userId);
         $result = array();
         $result['message'] = 'selected item moved wishlist successfully';
         success_response_after_post_get($result);
     } else {
         $this->response(array('error' => 'Unknow error to move the selected item to wishlist.'), 400);
     }
 }