예제 #1
0
 /**
  * 根据距离 升降序商品
  * @param	$where string
  * @param	$orderbyfield 排序字段
  * @param	$orderbymethod 排序方式	ASC DESC
  * @param	$offset
  * @param	$limit
  * @param	$is_show_distance (0:不调取距离,1,调取距离,)
  * @return	array
  */
 public function getSellingBydistance($where = "", $order_by_field, $order_by_method, $offset, $limit, $is_show_distance = "")
 {
     $db_prefix = option('system.DB_PREFIX');
     if (!empty($order_by_field) && !empty($order_by_method)) {
         $order = $order_by_field . ' ' . strtoupper($order_by_method);
         if ($order_by_field == 'sort') {
             $order .= ', product_id DESC';
         }
     } else {
         // 默认排序
         $order = 'sort DESC, product_id DESC';
     }
     $julis = "";
     $WebUserInfo = show_distance();
     $long = $WebUserInfo['long'];
     $lat = $WebUserInfo['lat'];
     //不出现分销
     if (is_array($where)) {
         $where = implode(" and ", $where);
     }
     $where = $where ? $where . "and" : "";
     $where = $where . "  p.supplier_id=0 and p.status=1 and p.is_recommend=1 and sc.long>0";
     $products = $this->db->table("Product as p")->join('Store as s ON s.store_id=p.store_id', 'LEFT')->join('Store_contact as sc ON sc.store_id=p.store_id', 'LEFT')->field("`p`.*, ROUND(6378.138 * 2 * ASIN(SQRT(POW(SIN(({$lat}*PI()/180-`sc`.`lat`*PI()/180)/2),2)+COS({$lat}*PI()/180)*COS(`sc`.`lat`*PI()/180)*POW(SIN(({$long}*PI()/180-`sc`.`long`*PI()/180)/2),2)))*1000) AS juli")->where($where)->group('p.store_id')->order("`juli` " . $order_by_method)->limit($offset . ',' . $limit)->select();
     foreach ($products as &$tmp) {
         $tmp['image'] = getAttachmentUrl($tmp['image']);
         $tmp['link'] = url_rewrite('goods:index', array('id' => $tmp['product_id']));
     }
     return $products;
 }
예제 #2
0
 public function __construct()
 {
     parent::__construct();
     $this->user_session = $_SESSION['user'];
     $this->assign('user_session', $_SESSION['user']);
     // 基类已经分类过此变量
     //$config = option('config');
     //$this->assign('config', $config);
     /**
      * 用F进行缓存时,后台更新此值,直接进行清空缓存
      */
     //获取导航 对此值进行文件缓存
     $navList = F('pc_slider_pc_nav');
     if (empty($navList)) {
         $navList = M('Slider')->get_slider_by_key('pc_nav', 7);
         F('pc_slider_pc_nav', $navList);
     }
     $this->assign('navList', $navList);
     //导航栏目
     //获取热门搜索 对此值进行文件缓存
     $search_hot = F('pc_search_hot');
     if (empty($search_hot)) {
         $search_hot = D('Search_hot')->order("sort asc ,id desc")->limit(7)->select();
         F('pc_search_hot', $search_hot);
     }
     $this->assign('search_hot', $search_hot);
     //公用头部右侧广告位 对此值进行文件缓存
     $public_top_ad = F('pc_adver_pc_index_top_right');
     if (empty($public_top_ad)) {
         $public_top_ad = M('Adver')->get_adver_by_key('pc_index_top_right', 1);
         F('pc_adver_pc_index_top_right', $public_top_ad);
     }
     $this->assign('public_top_ad', $public_top_ad[0]);
     // 购物内的数量
     //dump($this->user_session);
     $cart_number = 0;
     if (isset($this->user_session['uid'])) {
         $user_cart = D('User_cart')->where(array('uid' => $this->user_session['uid']))->field('sum(pro_num) as number')->find();
         $cart_number = $user_cart['number'];
     }
     $this->cart_number = $cart_number;
     $this->assign('cart_number', $cart_number);
     // 产品分类进行缓存
     $categoryList = F('pc_product_category_all');
     if (empty($categoryList)) {
         $categoryList = M('Product_category')->getAllCategory(15, true);
         F('pc_product_category_all', $categoryList);
     }
     $this->assign('categoryList', $categoryList);
     //cookie 地理坐标
     $WebUserInfo = show_distance();
     /*
     		if($WebUserInfo['long']) {
     		$xml_array=simplexml_load_file("http://api.map.baidu.com/geocoder?location={$WebUserInfo[lat]},{$WebUserInfo[long]}&output=xml&key=18bcdd84fae25699606ffad27f8da77b"); //将XML中的数据,读取到数组对象中 
     			foreach($xml_array as $tmp){ 
     				$WebUserInfo['address'] = $tmp->formatted_address; 
     			} 
     		}*/
     $this->assign('WebUserInfo', $WebUserInfo);
     $this->user_location = $WebUserInfo;
     // 友情链接
     $flink_list = D('Flink')->where(array('status' => 1))->order('sort desc')->limit(10)->select();
     $this->assign('flink_list', $flink_list);
     if (empty($WebUserInfo['long']) || empty($WebUserInfo['lat'])) {
         if (empty($_COOKIE['Location_qrcode']) || empty($_COOKIE['Location_qrcode']['ticket']) || $_COOKIE['Location_qrcode']['status'] > 0) {
             $location_return = M('Recognition')->get_location_qrcode();
             if ($location_qrcode['error_code'] == false) {
                 $location_data = D('Location_qrcode')->where(array('id' => $location_return['id']))->find();
                 setcookie('Location_qrcode[id]', $location_return['id'], time() + 60 * 60 * 24);
                 setcookie('Location_qrcode[ticket]', $location_return['ticket'], time() + 60 * 60 * 24);
                 setcookie('Location_qrcode[status]', $location_data['status'], time() + 60 * 60 * 24);
             }
             //dump($location_return);
             $this->assign('location_qrcode', $location_return);
         } else {
             $this->assign('location_qrcode', $_COOKIE['Location_qrcode']);
         }
     } else {
         $location_return = M('Recognition')->get_location_qrcode();
         $location_data = D('Location_qrcode')->where(array('id' => $location_return['id']))->find();
         $location_qrcode['id'] = $location_return['id'];
         $location_qrcode['ticket'] = $location_return['ticket'];
         $location_qrcode['status'] = $location_data['status'];
         $this->assign('location_qrcode', $location_qrcode);
     }
     if ($_SERVER['REMOTE_ADDR'] == '117.65.199.0') {
     }
 }
예제 #3
0
 function ajax_loaction()
 {
     $WebUserInfo = show_distance();
     if ($WebUserInfo['long']) {
         $xml_array = simplexml_load_file("http://api.map.baidu.com/geocoder?location={$WebUserInfo[lat]},{$WebUserInfo[long]}&output=xml&key=18bcdd84fae25699606ffad27f8da77b");
         //将XML中的数据,读取到数组对象中
         foreach ($xml_array as $tmp) {
             $WebUserInfo['address'] = $tmp->formatted_address;
         }
         if (!empty($WebUserInfo['address'])) {
             echo json_encode(array('status' => true, 'msgAll' => $WebUserInfo['address'], 'msg' => msubstr($WebUserInfo['address'], 0, 8, 'utf-8')));
             exit;
         } else {
             echo json_encode(array('status' => false));
             exit;
         }
     } else {
         echo json_encode(array('status' => false));
         exit;
     }
 }
예제 #4
0
 public function nearshops($long, $lat, $order, $sort = "asc", $offset = "0", $limit = "10", $get_distance = "", $wheres = "")
 {
     $limit = $limit ? $limit : '12';
     //$order = $order ? $order : "`juli` ASC";
     $where = "";
     $where2 = "";
     $WebUserInfo = show_distance();
     $db_prefix = option('system.DB_PREFIX');
     $order_juli = "";
     $orders = "";
     if ($order == 'juli') {
         $order_juli = " order by c.juli " . $sort;
     } else {
         $orders = " order by " . $order . ' ' . $sort;
     }
     $julis = "";
     if ($get_distance) {
         $squares = returnSquarePoint($WebUserInfo['long'], $WebUserInfo['lat'], $get_distance);
         $where .= "and sc.lat<>0 and sc.lat>{$squares['right-bottom']['lat']} and sc.lat<{$squares['left-top']['lat']} and sc.long>{$squares['left-top']['lng']} and sc.long<{$squares['right-bottom']['lng']}";
         $get_distance = $get_distance * 1000;
         $julis .= " where c.juli < " . $get_distance;
     }
     $sql = "select * from (select `s`.`store_id`, `s`.`name`, `s`.`logo`, `s`.`intro`,`sc`.`long`,`sc`.`lat`, ROUND(6378.138 * 2 * ASIN(SQRT(POW(SIN(({$lat}*PI()/180-`sc`.`lat`*PI()/180)/2),2)+COS({$lat}*PI()/180)*COS(`sc`.`lat`*PI()/180)*POW(SIN(({$long}*PI()/180-`sc`.`long`*PI()/180)/2),2)))*1000) AS juli from " . $db_prefix . "store_contact as sc, " . $db_prefix . "store as s where " . $wheres . " s.status = 1 and sc.store_id = s.store_id " . $where . $orders . " ) as c " . $julis . $order_juli . "  limit {$offset},{$limit}";
     $near_store_list = $this->db->query($sql);
     foreach ($near_store_list as $key => $value) {
         $value['url'] = option('config.wap_site_url') . '/home.php?id=' . $value['store_id'] . '&platform=1';
         $value['pcurl'] = url_rewrite('store:index', array('id' => $value['store_id']));
         if (empty($value['logo'])) {
             $value['logo'] = getAttachmentUrl('images/default_shop_2.jpg', false);
         } else {
             $value['logo'] = getAttachmentUrl($value['logo']);
         }
         $near_store_list[$key]['logo'] = $value['logo'];
         $near_store_list[$key]['url'] = $value['url'];
         $near_store_list[$key]['pcurl'] = $value['pcurl'];
     }
     return $near_store_list;
 }
예제 #5
0
 public function index()
 {
     // 获取参数
     $prop = $_GET['prop'];
     $start_price = $_GET['start_price'] + 0;
     $end_price = $_GET['end_price'] + 0;
     $page = max(1, $_GET['page']);
     $order = $_GET['order'];
     $sort = $_GET['sort'];
     $limit = 50;
     // 筛选属性ID集合
     $prop_arr = array();
     if (!empty($prop)) {
         $prop_arr = explode('_', $prop);
     }
     // url条件,价格在后面
     $param['id'] = $this->cate_id;
     $param['page'] = $page;
     $param['order'] = $order;
     $param['sort'] = $sort;
     // 修正价格和排序
     //$order_arr = array('sort', 'sales', 'price', 'collect', 'distance');
     $order_arr = array('sort', 'sales', 'price', 'collect', 'distance');
     $sort_arr = array('desc', 'asc');
     if (!in_array($order, $order_arr)) {
         $order = 'sort';
     }
     if (!in_array($sort, $sort_arr)) {
         $sort = $sort;
     }
     /* if ($order == 'sort' || $order == 'sales') {
     	  $sort = 'desc';
     	  } */
     if (!empty($start_price) && !empty($end_price) && $start_price > $end_price) {
         $tmp_price = $start_price;
         $start_price = $end_price;
         $end_price = $tmp_price;
     }
     $product_category_model = M('Product_category');
     if (!empty($this->cate_id)) {
         // 顶级分类和子分类
         $category_detail = $product_category_model->getCategory($this->cate_id);
         // 目前产品分类只支持两级
         $cid = $category_detail['cat_id'];
         // 当访问的不是首分类时,修正为父级分类ID
         if ($category_detail['cat_fid'] != 0) {
             $cid = $category_detail['cat_fid'];
         }
         // 父类分类
         $f_category = array();
         $s_category = array();
         // 搜索分类id
         $search_cat_id_arr = array();
         $s_category = D('Product_category')->where(array('cat_fid' => $cid, 'cat_status' => 1))->order('cat_sort desc, cat_id asc')->select();
         if ($cid == $category_detail['cat_id']) {
             $f_category = $category_detail;
             foreach ($s_category as $tmp) {
                 $search_cat_id_arr[] = $tmp['cat_id'];
             }
             $search_cat_id_arr[] = $cid;
         } else {
             $f_category = $product_category_model->getCategory($cid);
         }
     } else {
         $s_category = D('Product_category')->where(array('cat_fid' => $cid, 'cat_status' => 1))->order('cat_sort desc, cat_id asc')->select();
     }
     $property_list = array();
     if (!empty($category_detail)) {
         $property_list = M('System_product_property')->getPropertyAndValue($category_detail['filter_attr']);
     }
     // 查询属性条件
     $is_prop = false;
     $product_id_str = '';
     if (!empty($prop_arr)) {
         $product_id_str = M('System_product_to_property_value')->getProductIDByVid($prop_arr);
         $is_prop = true;
     }
     // 查找满足条件产品的数量
     $where_sql = '`status` = 1';
     $where_sql2 = "";
     if (!empty($start_price)) {
         $where_sql .= " AND `price` >= '" . $start_price . "'";
         $where_sql2[] = "  `p`.`price` >= '" . $start_price . "'";
         $param['start_price'] = $start_price;
     }
     if (!empty($end_price)) {
         $where_sql .= " AND `price` <= '" . $end_price . "'";
         $where_sql2[] = "  p.`price` <= '" . $end_price . "'";
         $param['end_price'] = $end_price;
     }
     if (!empty($this->cate_id)) {
         if (empty($search_cat_id_arr)) {
             $where_sql .= " AND `category_id` = '" . $this->cate_id . "'";
             $where_sql2[] = "  `p`.`category_id` = '" . $this->cate_id . "'";
         } else {
             if ($_GET['id'] != 99999) {
                 $where_sql .= " AND `category_id` in (" . join(',', $search_cat_id_arr) . ")";
                 $where_sql2[] = "  `p`.`category_id` in (" . join(',', $search_cat_id_arr) . ")";
             }
         }
     }
     // 不出现分销
     $where_sql .= " AND `supplier_id` = '0'";
     if ($order != 'distance') {
         if ($is_prop && $product_id_str) {
             $where_sql .= " AND `product_id` in (" . $product_id_str . ")";
             $count = D('Product')->where($where_sql)->count('product_id');
         } else {
             if ($is_prop) {
                 $count = 0;
             } else {
                 $count = D('Product')->where($where_sql)->count('product_id');
             }
         }
     } else {
         if ($is_prop && $product_id_str) {
             if ($where_sql2) {
                 $where_sql2 = implode(" and ", $where_sql2);
             }
             $where_sql2 .= " AND `p`.`product_id` in (" . $product_id_str . ")";
             $count = M('Product')->getSellingBydistanceCount($where_sql2);
         } else {
             if ($is_prop) {
                 $count = 0;
             } else {
                 if ($where_sql2) {
                     $where_sql2 = implode(" and ", $where_sql2);
                 }
                 $count = M('Product')->getSellingBydistanceCount($where_sql2);
             }
         }
     }
     $product_list = array();
     $store_list = array();
     $pages = '';
     $total_pages = ceil($count / $limit);
     if ($count > 0) {
         $page = min($page, $total_pages);
         $offset = ($page - 1) * $limit;
         if ($order == 'distance') {
             $orders = "juli";
             $product_list = M('Product')->getSellingBydistance($where_sql2, $orders, $sort, $offset, $limit);
         } else {
             $product_list = M('Product')->getSelling($where_sql, $order, $sort, $offset, $limit);
             //->where($where_sql)->order($order . ' ' . $sort)->limit($offset . ',' . $limit)->select();
         }
         $store_id_list = array();
         foreach ($product_list as &$product) {
             $store_id_list[$product['store_id']] = $product['store_id'];
         }
         $store_list = M('Store')->getStoreName($store_id_list);
         $store_contact_info = M('store_contact')->get_store_contact_info($store_id_list);
         // 分页
         import('source.class.user_page');
         $user_page = new Page($count, $limit, $page);
         $pages = $user_page->show();
     }
     $search_sort = $sort == 'asc' ? 'desc' : 'asc';
     if (empty($this->cate_id)) {
         //unset($param['id']);
     }
     // 排序
     $search_param = $param;
     unset($search_param['page']);
     if (empty($search_param['order'])) {
         unset($search_param['order']);
     }
     if (empty($search_param['sort'])) {
         unset($search_param['sort']);
     }
     if (!empty($prop)) {
         $search_param['prop'] = 'prop_' . $prop;
     }
     // 热销url条件
     $hot_param = $param;
     $hot_param['order'] = 'sales';
     $hot_param['sort'] = $search_sort;
     if (!empty($prop)) {
         $hot_param['prop'] = 'prop_' . $prop;
     }
     unset($hot_param['page']);
     // 价格排序url条件
     $price_param = $param;
     $price_param['order'] = 'price';
     $price_param['sort'] = $search_sort;
     if (!empty($prop)) {
         $price_param['prop'] = 'prop_' . $prop;
     }
     unset($price_param['page']);
     //人气排序url条件
     $collect_param = $param;
     $collect_param['order'] = 'collect';
     $collect_param['sort'] = $search_sort;
     if (!empty($prop)) {
         $collect_param['prop'] = 'prop_' . $prop;
     }
     unset($collect_param['page']);
     //距离排序url条件
     $distance_param = $param;
     $distance_param['order'] = 'distance';
     $distance_param['sort'] = $search_sort;
     if (!empty($prop)) {
         $distance_param['prop'] = 'prop_' . $prop;
     }
     unset($distance_param['page']);
     // 默认排序url条件
     $default_param = $param;
     if (!empty($prop)) {
         $default_param['prop'] = 'prop_' . $prop;
     }
     unset($default_param['page']);
     unset($default_param['order']);
     unset($default_param['sort']);
     //导航栏
     //$categoryList = parent::nav_list();
     // $this->assign('categoryList', $categoryList);
     //获取当前位置
     $cookie_location = show_distance();
     $this->assign('prop_arr', $prop_arr);
     $this->assign('category_detail', $category_detail);
     //当前的产品类别id
     $this->assign('f_category', $f_category);
     $this->assign('s_category', $s_category);
     $this->assign('product_list', $product_list);
     $this->assign('store_list', $store_list);
     $this->assign('search_url', $search_url);
     $this->assign('search_sort', $search_sort);
     $this->assign('pages', $pages);
     $this->assign('search_param', $search_param);
     $this->assign('default_param', $default_param);
     $this->assign('hot_param', $hot_param);
     $this->assign('price_param', $price_param);
     $this->assign('collect_param', $collect_param);
     $this->assign('distance_param', $distance_param);
     $this->assign('page_arr', array('current_page' => $page, 'total_pages' => $total_pages));
     $this->assign('property_list', $property_list);
     $this->assign('store_contact_info', $store_contact_info);
     //获取全部的顶级分类
     $top_cate_list = D('Product_category')->where(array('cat_fid' => 0))->field('cat_id,cat_name')->select();
     $this->assign('top_cate_list', $top_cate_list);
     $this->assign('product_count', $count);
     $this->display();
 }