Example #1
0
 public function index()
 {
     $root = array();
     $root['return'] = 1;
     $catalog_id = intval($GLOBALS['request']['catalog_id']);
     //商品分类ID
     $cata_type_id = intval($GLOBALS['request']['cata_type_id']);
     //商品二级分类
     $city_id = intval($GLOBALS['request']['city_id']);
     //城市分类ID
     $page = intval($GLOBALS['request']['page']);
     //分页
     $keyword = strim($GLOBALS['request']['keyword']);
     $page = $page == 0 ? 1 : $page;
     $quan_id = intval($GLOBALS['request']['quan_id']);
     //商圈id
     $order_type = strim($GLOBALS['request']['order_type']);
     //if(!$city_id)
     //{
     //	$city = get_current_deal_city();
     //	$city_id = $city['id'];
     //}
     $ytop = $latitude_top = floatval($GLOBALS['request']['latitude_top']);
     //最上边纬线值 ypoint
     $ybottom = $latitude_bottom = floatval($GLOBALS['request']['latitude_bottom']);
     //最下边纬线值 ypoint
     $xleft = $longitude_left = floatval($GLOBALS['request']['longitude_left']);
     //最左边经度值  xpoint
     $xright = $longitude_right = floatval($GLOBALS['request']['longitude_right']);
     //最右边经度值 xpoint
     $ypoint = $m_latitude = doubleval($GLOBALS['request']['m_latitude']);
     //ypoint
     $xpoint = $m_longitude = doubleval($GLOBALS['request']['m_longitude']);
     //xpoint
     /*输出分类*/
     $bcate_list = getCateList();
     $url_param['quan_id'] = $quan_id;
     $url_param['catalog_id'] = $catalog_id;
     $url_param['cata_type_id'] = $cata_type_id;
     foreach ($bcate_list as $k => $v) {
         $tmp_url_param = $url_param;
         unset($tmp_url_param['catalog_id']);
         $tmp_url_param['catalog_id'] = $v['id'];
         $tmp_url_param['catename'] = $v['name'];
         if ($quan_id > 0) {
             $quanname = $GLOBALS['db']->getOne("select name from " . DB_PREFIX . "area where id=" . $quan_id);
             $tmp_url_param['quanname'] = $quanname;
         } else {
             $tmp_url_param['quanname'] = "全城";
         }
         $turl = wap_url("index", "tuanlist", $tmp_url_param);
         $url = str_replace('sjmapi', 'wap', $turl);
         $bcate_list[$k]["url"] = $url;
         foreach ($v['bcate_type'] as $kk => $vv) {
             $tmp_url_param = $url_param;
             unset($tmp_url_param['cata_type_id']);
             $tmp_url_param['cata_type_id'] = $vv["id"];
             $tmp_url_param['catename'] = $vv['name'];
             $tmp_url_param['catalog_id'] = $vv['cate_id'];
             if ($quan_id > 0) {
                 $quanname = $GLOBALS['db']->getOne("select name from " . DB_PREFIX . "area  where id=" . $quan_id);
                 $tmp_url_param['quanname'] = $quanname;
             } else {
                 $tmp_url_param['quanname'] = "全城";
             }
             $turl = wap_url("index", "tuanlist", $tmp_url_param);
             $url = str_replace('sjmapi', 'wap', $turl);
             $bcate_list[$k]["bcate_type"][$kk]["url"] = $url;
         }
     }
     /*输出商圈*/
     $quan_list = getQuanList($city_id);
     foreach ($quan_list as $k => $v) {
         $tmp_url_param = $url_param;
         unset($tmp_url_param['quan_id']);
         $tmp_url_param['quan_id'] = $v['id'];
         $tmp_url_param['quanname'] = $v['name'];
         if ($catalog_id > 0) {
             $catename = $GLOBALS['db']->getOne("select name from " . DB_PREFIX . "deal_cate  where id=" . $catalog_id);
             $tmp_url_param['catename'] = $catename;
         } else {
             $tmp_url_param['catename'] = "全部分类";
         }
         $turl = wap_url("index", "tuanlist", $tmp_url_param);
         $url = str_replace('sjmapi', 'wap', $turl);
         $quan_list[$k]["url"] = $url;
         foreach ($v['quan_sub'] as $kk => $vv) {
             $tmp_url_param = $url_param;
             unset($tmp_url_param['quan_id']);
             $tmp_url_param['quan_id'] = $vv['id'];
             $tmp_url_param['quanname'] = $vv['name'];
             if ($catalog_id > 0) {
                 $catename = $GLOBALS['db']->getOne("select name from " . DB_PREFIX . "deal_cate  where id=" . $catalog_id);
                 $tmp_url_param['catename'] = $catename;
             } else {
                 $tmp_url_param['catename'] = "全部分类";
             }
             $turl = wap_url("index", "tuanlist", $tmp_url_param);
             $url = str_replace('sjmapi', 'wap', $turl);
             $quan_list[$k]["quan_sub"][$kk]["url"] = $url;
         }
     }
     $page_size = PAGE_SIZE;
     $limit = ($page - 1) * $page_size . "," . $page_size;
     if ($keyword) {
         $kws_div = div_str($keyword);
         foreach ($kws_div as $k => $item) {
             $kws[$k] = str_to_unicode_string($item);
         }
         $ukeyword = implode(" ", $kws);
         $condition = "  (match(tag_match,name_match,locate_match,deal_cate_match) against('" . $ukeyword . "' IN BOOLEAN MODE) or name like '%" . $keyword . "%') and ";
     }
     //buy_type 0普通团购;2在线订购;3秒杀抢团
     //is_shop 0团购;1:商品;
     $condition .= " buy_type = 0 and is_shop = 0 and is_lottery = 0 ";
     if ($xpoint > 0) {
         $pi = 3.14159265;
         //圆周率
         $r = 6378137;
         //地球平均半径(米)
         $field_append = ", (ACOS(SIN(({$ypoint} * {$pi}) / 180 ) *SIN((ypoint * {$pi}) / 180 ) +COS(({$ypoint} * {$pi}) / 180 ) * COS((ypoint * {$pi}) / 180 ) *COS(({$xpoint} * {$pi}) / 180 - (xpoint * {$pi}) / 180 ) ) * {$r}) as distance ";
         if ($ybottom != 0 && $ytop != 0 && $xleft != 0 && $xright != 0) {
             if ($condition != "") {
                 $condition .= " and ";
             }
             $condition .= " ypoint > {$ybottom} and ypoint < {$ytop} and xpoint > {$xleft} and xpoint < {$xright} ";
         }
         $order = " distance asc,id desc ";
     } else {
         $order = "sort desc,id desc ";
     }
     /*排序  
     		 智能排序和 离我最的 是一样的 都以距离来升序来排序,只有这两种情况有传经纬度过来,就没有把 这两种情况写在 下面的判断里,写在上面了。
     		default 智能(默认),nearby  离我,avg_point 评价,newest 最新,buy_count 人气,price_asc 价低,price_desc 价高 */
     $ordertype[] = array("name" => "默认排序", "sc" => "avg_point");
     $ordertype[] = array("name" => "最新发布", "sc" => "newest");
     $ordertype[] = array("name" => "销量最高", "sc" => "buy_count");
     $ordertype[] = array("name" => "价格最高", "sc" => "price_desc");
     $ordertype[] = array("name" => "价格最低", "sc" => "price_asc");
     foreach ($ordertype as $k => $v) {
         $tmp_url_param = $url_param;
         if ($quanname) {
             $tmp_url_param['quanname'] = $quanname;
         }
         if ($catename) {
             $tmp_url_param['catename'] = $catename;
         }
         if ($keyword) {
             $tmp_url_param['keyword'] = $keyword;
         }
         $tmp_url_param['order_type'] = $v['sc'];
         $turl = wap_url("index", "goodslist", $tmp_url_param);
         $url = str_replace('sjmapi', 'wap', $turl);
         $ordertype[$k]["url"] = $url;
     }
     $root['ordertype'] = $ordertype;
     if ($order_type == 'avg_point') {
         /*评价*/
         $order = " avg_point desc,id desc ";
     } elseif ($order_type == 'newest') {
         /*最新*/
         $order = " create_time desc,id desc ";
     } elseif ($order_type == 'buy_count') {
         /*销量*/
         $order = " buy_count desc,id desc ";
     } elseif ($order_type == 'price_asc') {
         /*价格升*/
         $order = " current_price asc,id desc ";
     } elseif ($order_type == 'price_desc') {
         /*价格降*/
         $order = " current_price desc,id desc ";
     }
     //根据传入的商圈ID来搜索该商圈下的商品
     if ($quan_id > 0) {
         $sql_q = "select name from " . DB_PREFIX . "area where id = " . intval($quan_id);
         $q_name = $GLOBALS['db']->getOne($sql_q);
         $q_name_unicode = str_to_unicode_string($q_name);
         $condition .= " and (match(locate_match) against('" . $q_name_unicode . "' IN BOOLEAN MODE))";
     }
     $deals = m_get_deal_list($limit, $catalog_id, $city_id, array(DEAL_ONLINE), $condition, $order, 0, $field_append, $cata_type_id);
     $list = $deals['list'];
     $count = $deals['count'];
     $page_total = ceil($count / $page_size);
     //$root['sql'] = $deals['sql'];
     $taday_begin = to_timespan(to_date(get_gmtime(), 'Y-m-d'));
     $taday_end = $taday_begin * 24 * 60 * 60;
     $goodses = array();
     foreach ($list as $k => $v) {
         $goodses[$k]['id'] = $v['id'];
         $goodses[$k]['distance'] = $v['distance'];
         $goodses[$k]['ypoint'] = $v['ypoint'];
         $goodses[$k]['xpoint'] = $v['xpoint'];
         $goodses[$k]['name'] = $v['name'];
         $goodses[$k]['sub_name'] = $v['sub_name'];
         $goodses[$k]['goods_brief'] = $v['brief'];
         $goodses[$k]['buy_count'] = $v['buy_count'];
         $goodses[$k]['auto_order'] = $v['auto_order'];
         $goodses[$k]['current_price'] = round($v['current_price'], 2);
         $goodses[$k]['origin_price'] = round($v['origin_price'], 2);
         $goodses[$k]['icon'] = get_abs_img_root(get_spec_image($v['icon'], 140, 85, 0));
         if ($v['begin_time'] > 0 && ($taday_begin < $v['begin_time'] && $v['begin_time'] < $taday_end)) {
             $goodses[$k]['is_taday'] = 1;
         } else {
             if ($v['begin_time'] == 0 && ($taday_begin < $v['create_time'] && $v['create_time'] < $taday_end)) {
                 $goodses[$k]['is_taday'] = 1;
             } else {
                 $goodses[$k]['is_taday'] = 0;
             }
         }
     }
     $root['city_id'] = $city_id;
     $root['quan_id'] = $quan_id;
     $root['catalog_id'] = $catalog_id;
     $root['page_title'] = "团购列表";
     $root['page'] = array("page" => $page, "page_total" => $page_total, "page_size" => $page_size);
     if ($goodses === false) {
         $root['item'] = array();
     } else {
         $root['item'] = $goodses;
     }
     if ($bcate_list === false) {
         $root[''] = array();
     } else {
         $root['bcate_list'] = $bcate_list;
     }
     if ($quan_list === false) {
         $root['quan_list'] = array();
     } else {
         $root['quan_list'] = $quan_list;
     }
     output($root);
 }
Example #2
0
 public function index()
 {
     //print_r($GLOBALS['request']);
     $root = array();
     $root['return'] = 1;
     /*
     $email = addslashes($GLOBALS['request']['email']);//用户名或邮箱
     $pwd = addslashes($GLOBALS['request']['pwd']);//密码
     
     //检查用户,用户密码
     $user = user_check($email,$pwd);		
     $user_id  = intval($user['id']);
     */
     $city_name = strim($GLOBALS['request']['city_name']);
     //城市名称
     $city_id = intval($GLOBALS['request']['city_id']);
     $quan_id = intval($GLOBALS['request']['quan_id']);
     $cate_id = intval($GLOBALS['request']['cate_id']);
     $brand_id = intval($GLOBALS['request']['brand_id']);
     $keyword = strim($GLOBALS['request']['keyword']);
     $page = intval($GLOBALS['request']['page']);
     //分页
     $cata_type_id = intval($GLOBALS['request']['cata_type_id']);
     //商品二级分类
     $order_type = strim($GLOBALS['request']['order_type']);
     $is_auto_order = intval($GLOBALS['request']['is_auto_order']);
     //1:手机自主下单;消费者(在手机端上)可以直接给该门店支付金额
     $ytop = $latitude_top = floatval($GLOBALS['request']['latitude_top']);
     //最上边纬线值 ypoint
     $ybottom = $latitude_bottom = floatval($GLOBALS['request']['latitude_bottom']);
     //最下边纬线值 ypoint
     $xleft = $longitude_left = floatval($GLOBALS['request']['longitude_left']);
     //最左边经度值  xpoint
     $xright = $longitude_right = floatval($GLOBALS['request']['longitude_right']);
     //最右边经度值 xpoint
     $ypoint = doubleval($GLOBALS['request']['m_latitude']);
     //ypoint
     $xpoint = doubleval($GLOBALS['request']['m_longitude']);
     //xpoint
     $root['ypoint'] = $ypoint;
     $root['xpoint'] = $xpoint;
     //$root['sql'] = $sql;
     //if(!$city_id)
     //{
     //	$city = get_current_deal_city();
     //	$city_id = $city['id'];
     //}
     /*输出分类*/
     $bcate_list = getCateList();
     /*输出商圈*/
     $quan_list = getQuanList($city_id);
     $page = $page == 0 ? 1 : $page;
     $page_size = PAGE_SIZE;
     $limit = ($page - 1) * $page_size . "," . $page_size;
     if ($xpoint > 0) {
         $pi = 3.14159265;
         //圆周率
         $r = 6378137;
         //地球平均半径(米)
         $field_append = ", (ACOS(SIN(({$ypoint} * {$pi}) / 180 ) *SIN((a.ypoint * {$pi}) / 180 ) +COS(({$ypoint} * {$pi}) / 180 ) * COS((a.ypoint * {$pi}) / 180 ) *COS(({$xpoint} * {$pi}) / 180 - (a.xpoint * {$pi}) / 180 ) ) * {$r}) as distance ";
         if ($ybottom != 0 && $ytop != 0 && $xleft != 0 && $xright != 0) {
             $condition = " and  a.ypoint > {$ybottom} and a.ypoint < {$ytop} and a.xpoint > {$xleft} and a.xpoint < {$xright} ";
         }
         $orderby = " order by distance asc ";
     } else {
         $field_append = "";
         $orderby = " order by a.sort desc,a.id desc";
     }
     /*排序*/
     if ($GLOBALS['request']['from'] == "wap") {
         if ($order_type == 'avg_point') {
             $orderby = " order by  a.avg_point desc,a.sort desc,a.id desc ";
         } else {
             $orderby = " order by  a.id desc";
         }
     } else {
         if ($order_type == 'avg_point') {
             /*评价*/
             $orderby = " order by  a.avg_point desc,a.sort desc,a.id desc ";
         }
     }
     $sql_count = "select count(*) from " . DB_PREFIX . "supplier_location" . " as a";
     $sql = "select a.id,a.deal_cate_id,a.name,a.avg_point,a.city_id, a.mobile_brief,a.mobile_brief as brief,a.tel,a.preview as logo,a.dp_count as comment_count,a.xpoint,a.ypoint,a.address, a.api_address, 0 as is_dy {$field_append} from   " . DB_PREFIX . "supplier_location as a ";
     $where = "1 = 1 and a.deal_cate_id > 0 ";
     if ($city_id > 0) {
         $ids = load_auto_cache("deal_city_belone_ids", array("city_id" => $city_id));
         if ($ids) {
             $where .= " and a.city_id in (" . implode(",", $ids) . ")";
         }
     }
     if ($quan_id > 0) {
         $sql_q = "select name from " . DB_PREFIX . "area where id = " . intval($quan_id);
         $q_name = $GLOBALS['db']->getOne($sql_q);
         $q_name_unicode = str_to_unicode_string($q_name);
         $where .= " and (match(a.locate_match) against('" . $q_name_unicode . "' IN BOOLEAN MODE))";
         //$where .= " and a.locate_match = $quan_id";
     }
     if ($cate_id > 0) {
         $deal_cate_name = $GLOBALS['db']->getOne("select name from " . DB_PREFIX . "deal_cate where id = " . $cate_id);
         $deal_cate_name_unicode = str_to_unicode_string($deal_cate_name);
         $where .= " and (match(a.deal_cate_match) against('" . $deal_cate_name_unicode . "' IN BOOLEAN MODE)) ";
     }
     if ($cate_id > 0) {
         if ($cata_type_id > 0) {
             $deal_type_name = $GLOBALS['db']->getOne("select name from " . DB_PREFIX . "deal_cate_type where id = " . $cata_type_id);
             $deal_type_name_unicode = str_to_unicode_string($deal_type_name);
             $where .= " and (match(a.deal_cate_match) against('" . $deal_type_name_unicode . "' IN BOOLEAN MODE)) ";
         }
     }
     //1:手机自主下单;消费者(在手机端上)可以直接给该门店支付金额
     if ($is_auto_order > 0) {
         $where .= " and a.is_auto_order = {$is_auto_order}";
     }
     if ($brand_id > 0) {
         $where .= " and a.supplier_id = {$brand_id}";
     }
     if ($keyword) {
         $GLOBALS['tmpl']->assign("keyword", $keyword);
         $kws_div = div_str($keyword);
         foreach ($kws_div as $k => $item) {
             $kw[$k] = str_to_unicode_string($item);
         }
         $kw_unicode = implode(" ", $kw);
         //有筛选
         $where .= " and (match(a.name_match,a.locate_match,a.deal_cate_match,a.tags_match) against('" . $kw_unicode . "' IN BOOLEAN MODE) or name like '%" . $keyword . "%')";
     }
     $where .= $condition;
     $sql_count .= " where " . $where;
     $sql .= " where " . $where;
     $sql .= $orderby;
     $sql .= " limit " . $limit;
     $total = $GLOBALS['db']->getOne($sql_count);
     $page_total = ceil($total / $page_size);
     $root['sql'] = $sql;
     $list = $GLOBALS['db']->getAll($sql);
     $merchant_list = array();
     $l_ids = array();
     foreach ($list as $item) {
         $item = m_merchantItem($item);
         $merchant_list[] = $item;
         $l_ids[] = $item['id'];
     }
     /*区域*/
     $l_area = $GLOBALS['db']->getAll("select a.name as a_name,b.location_id from " . DB_PREFIX . "area as a left join " . DB_PREFIX . "supplier_location_area_link as b on a.id=b.area_id where b.location_id in(" . implode(',', $l_ids) . ") and a.pid=0");
     $l_area_var = array();
     foreach ($l_area as $k => $v) {
         if (array_key_exists($v['location_id'], $l_area_var)) {
             $l_area_var[$v['location_id']] .= "/" . $v['a_name'];
         } else {
             $l_area_var[$v['location_id']] = $v['a_name'];
         }
     }
     /*小分类*/
     $l_cate_type = $GLOBALS['db']->getAll("select a.name as ct_name,b.location_id from " . DB_PREFIX . "deal_cate_type as a left join " . DB_PREFIX . "deal_cate_type_location_link as b on a.id=b.deal_cate_type_id where b.location_id in(" . implode(',', $l_ids) . ")");
     $l_cate_type_var = array();
     foreach ($l_cate_type as $k => $v) {
         if (array_key_exists($v['location_id'], $l_cate_type_var)) {
             $l_cate_type_var[$v['location_id']] .= "/" . $v['ct_name'];
         } else {
             $l_cate_type_var[$v['location_id']] = $v['ct_name'];
         }
     }
     foreach ($merchant_list as $k => $v) {
         if (array_key_exists($v['id'], $l_area_var)) {
             $merchant_list[$k]['l_area'] = $l_area_var[$v['id']];
         } else {
             $merchant_list[$k]['l_area'] = '';
         }
         if (array_key_exists($v['id'], $l_cate_type_var)) {
             $merchant_list[$k]['l_cate_type'] = $l_cate_type_var[$v['id']];
         } else {
             $merchant_list[$k]['l_cate_type'] = '';
         }
         $merchant_list[$k]['cate_name'] = $GLOBALS['db']->getOne("select name from " . DB_PREFIX . "deal_cate where id=" . $v['deal_cate_id']);
         $merchant_list[$k]['width'] = $v['avg_point'] > 0 ? $v['avg_point'] / 5 * 75 : 0;
         $merchant_list[$k]['avg_point'] = round($v['avg_point'], 1);
         if (empty($merchant_list[$k]['mobile_brief'])) {
             $merchant_list[$k]['mobile_brief'] = $merchant_list[$k]['l_cate_type'] . ' ' . $merchant_list[$k]['l_area'];
         }
     }
     $root['item'] = $merchant_list;
     $root['page'] = array("page" => $page, "page_total" => $page_total, "page_size" => $page_size);
     $root['bcate_list'] = $bcate_list;
     $root['quan_list'] = $quan_list;
     $root['city_id'] = $city_id;
     $root['city_name'] = $city_name;
     $root['is_auto_order'] = $is_auto_order;
     //$root['email']=$email;
     if ($is_auto_order == 1) {
         $root['page_title'] = '门店自主下单列表';
     } else {
         $root['page_title'] = '商家列表';
     }
     output($root);
 }
Example #3
0
 public function index()
 {
     $root = array();
     $root['return'] = 1;
     $catalog_id = intval($GLOBALS['request']['cate_id']);
     //商品分类ID
     $cata_type_id = intval($GLOBALS['request']['cata_type_id']);
     //商品二级分类
     $city_id = intval($GLOBALS['request']['city_id']);
     $quan_id = intval($GLOBALS['request']['quan_id']);
     $cate_id = intval($GLOBALS['request']['cate_id']);
     $keyword = strim($GLOBALS['request']['keyword']);
     $city_name = strim($GLOBALS['request']['city_name']);
     //城市名称
     $order_type = $GLOBALS['request']['order_type'];
     $ytop = $latitude_top = floatval($GLOBALS['request']['latitude_top']);
     //最上边纬线值 ypoint
     $ybottom = $latitude_bottom = floatval($GLOBALS['request']['latitude_bottom']);
     //最下边纬线值 ypoint
     $xleft = $longitude_left = floatval($GLOBALS['request']['longitude_left']);
     //最左边经度值  xpoint
     $xright = $longitude_right = floatval($GLOBALS['request']['longitude_right']);
     //最右边经度值 xpoint
     $m_distance = doubleval($GLOBALS['request']['m_distance']);
     //范围(米)
     $ypoint = $m_latitude = doubleval($GLOBALS['request']['m_latitude']);
     //ypoint
     $xpoint = $m_longitude = doubleval($GLOBALS['request']['m_longitude']);
     //xpoint
     /*输出分类*/
     $bcate_list = getCateList();
     $url_param['quan_id'] = $quan_id;
     $url_param['catalog_id'] = $catalog_id;
     $url_param['cata_type_id'] = $cata_type_id;
     foreach ($bcate_list as $k => $v) {
         $tmp_url_param = $url_param;
         unset($tmp_url_param['catalog_id']);
         $tmp_url_param['catalog_id'] = $v['id'];
         $tmp_url_param['catename'] = $v['name'];
         if ($quan_id > 0) {
             $quanname = $GLOBALS['db']->getOne("select name from " . DB_PREFIX . "area where id=" . $quan_id);
             $tmp_url_param['quanname'] = $quanname;
         } else {
             $tmp_url_param['quanname'] = "全城";
         }
         $turl = url("index", "tuanlist", $tmp_url_param);
         $url = str_replace('sjmapi', 'wap', $turl);
         $bcate_list[$k]["url"] = $url;
         foreach ($v['bcate_type'] as $kk => $vv) {
             $tmp_url_param = $url_param;
             unset($tmp_url_param['cata_type_id']);
             $tmp_url_param['cata_type_id'] = $vv["id"];
             $tmp_url_param['catename'] = $vv['name'];
             $tmp_url_param['catalog_id'] = $vv['cate_id'];
             if ($quan_id > 0) {
                 $quanname = $GLOBALS['db']->getOne("select name from " . DB_PREFIX . "area  where id=" . $quan_id);
                 $tmp_url_param['quanname'] = $quanname;
             } else {
                 $tmp_url_param['quanname'] = "全城";
             }
             $turl = url("index", "tuanlist", $tmp_url_param);
             $url = str_replace('sjmapi', 'wap', $turl);
             $bcate_list[$k]["bcate_type"][$kk]["url"] = $url;
         }
     }
     /*输出分类
     		$bcate_list = getCateList();
     		$url_param['quan_id'] = $quan_id;
     		$url_param['cate_id'] = $cate_id;
     		
     		$catalog_id = $cate_id;
     		
     		foreach($bcate_list as $k=>$v)
     		{
     			if($catalog_id==$v['id'])
     			{
     				$bcate_list['bcate_type'][$k]['act'] = 1;
     			}
     			$tmp_url_param = $url_param;
     			unset($tmp_url_param['cate_id']);
     			$tmp_url_param['cate_id']=$v['id'];
     			$tmp_url_param['catename']=$v['name'];
     			if($quan_id>0){
     				$quanname=$GLOBALS['db']->getOne("select name from ".DB_PREFIX."area where id=".$quan_id);
     				$tmp_url_param['quanname']=$quanname;
     			}else{
     				$tmp_url_param['quanname']="全城";
     			}
     			$turl = url("index","youhuilist",$tmp_url_param);
     			$url=str_replace('sjmapi','wap', $turl);
     			$bcate_list[$k]["url"]=$url;
     				
     			foreach($v['bcate_type'] as $kk=>$vv){
     				if($catalog_id==$vv['id'])
     				{
     					$bcate_list['bcate_type'][$kk]['act'] = 1;
     				}
     				$tmp_url_param = $url_param;
     				unset($tmp_url_param['cate_id']);
     				$tmp_url_param['cate_id']=$vv['id'];
     				$tmp_url_param['catename']=$vv['name'];
     				if($quan_id>0){
     					$quanname=$GLOBALS['db']->getOne("select name from ".DB_PREFIX."area  where id=".$quan_id);
     					$tmp_url_param['quanname']=$quanname;
     				}else{
     					$tmp_url_param['quanname']="全城";
     				}
     				$turl = url("index","youhuilist",$tmp_url_param);
     				$url=str_replace('sjmapi','wap', $turl);
     				$bcate_list[$k]["bcate_type"][$kk]["url"]=$url;
     			}
     				
     		
     		}
     		*/
     /*输出商圈*/
     $quan_list = getQuanList($city_id);
     foreach ($quan_list as $k => $v) {
         /*
         if($catalog_id==$v['id'])
         {
         	$quan_list['bcate_type'][$k]['act'] = 1;
         }
         */
         $tmp_url_param = $url_param;
         unset($tmp_url_param['quan_id']);
         $tmp_url_param['quan_id'] = $v['id'];
         $tmp_url_param['quanname'] = $v['name'];
         if ($catalog_id > 0) {
             $catename = $GLOBALS['db']->getOne("select name from " . DB_PREFIX . "deal_cate  where id=" . $catalog_id);
             $tmp_url_param['catename'] = $catename;
         } else {
             $tmp_url_param['catename'] = "全部分类";
         }
         $turl = url("index", "youhuilist", $tmp_url_param);
         $url = str_replace('sjmapi', 'wap', $turl);
         $quan_list[$k]["url"] = $url;
         foreach ($v['quan_sub'] as $kk => $vv) {
             /*
             if($catalog_id==$vv['id'])
             {
             	$quan_list['quan_sub'][$kk]['act'] = 1;
             }
             */
             $tmp_url_param = $url_param;
             unset($tmp_url_param['quan_id']);
             $tmp_url_param['quan_id'] = $vv['id'];
             $tmp_url_param['quanname'] = $vv['name'];
             if ($catalog_id > 0) {
                 $catename = $GLOBALS['db']->getOne("select name from " . DB_PREFIX . "deal_cate  where id=" . $catalog_id);
                 $tmp_url_param['catename'] = $catename;
             } else {
                 $tmp_url_param['catename'] = "全部分类";
             }
             $turl = url("index", "youhuilist", $tmp_url_param);
             $url = str_replace('sjmapi', 'wap', $turl);
             $quan_list[$k]["quan_sub"][$kk]["url"] = $url;
         }
     }
     $page = intval($GLOBALS['request']['page']);
     //分页
     $page = $page == 0 ? 1 : $page;
     $page_size = PAGE_SIZE;
     $limit = ($page - 1) * $page_size . "," . $page_size;
     $pi = 3.14159265;
     //圆周率
     $r = 6378137;
     //地球平均半径(米)
     $sql_count = "select count(*) from " . DB_PREFIX . "youhui ";
     $sql = "select id,supplier_id as merchant_id,begin_time,youhui_type,total_num,end_time,name as title,list_brief as content,icon as merchant_logo,create_time,xpoint,ypoint,address as api_address,icon as image_1,\n\t\t\t\t (ACOS(SIN(({$ypoint} * {$pi}) / 180 ) *SIN((ypoint * {$pi}) / 180 ) +COS(({$ypoint} * {$pi}) / 180 ) * COS((ypoint * {$pi}) / 180 ) *COS(({$xpoint} * {$pi}) / 180 - (xpoint * {$pi}) / 180 ) ) * {$r}) as distance  \n\t\t\t\tfrom " . DB_PREFIX . "youhui ";
     $now = get_gmtime();
     $where = "1 = 1 and is_effect = 1 and begin_time<" . $now . " and (end_time = 0 or end_time > " . $now . ")";
     if ($city_id > 0) {
         $ids = load_auto_cache("deal_city_belone_ids", array("city_id" => $city_id));
         if ($ids) {
             $where .= " and city_id in (" . implode(",", $ids) . ")";
         }
     }
     if ($quan_id > 0) {
         $ids = load_auto_cache("deal_quan_ids", array("quan_id" => $quan_id));
         $quan_list2 = $GLOBALS['db']->getAll("select `name` from " . DB_PREFIX . "area where id in (" . implode(",", $ids) . ")");
         $unicode_quans = array();
         foreach ($quan_list2 as $k => $v) {
             $unicode_quans[] = str_to_unicode_string($v['name']);
         }
         $kw_unicode = implode(" ", $unicode_quans);
         $where .= " and (match(locate_match) against('" . $kw_unicode . "' IN BOOLEAN MODE)) ";
     }
     if ($cate_id > 0) {
         $where .= " and deal_cate_id = {$cate_id}";
     }
     if ($keyword) {
         $kws_div = div_str($keyword);
         foreach ($kws_div as $k => $item) {
             $kw[$k] = str_to_unicode_string($item);
         }
         $ukeyword = implode(" ", $kw);
         $where .= " and match(name_match) against('" . $ukeyword . "'  IN BOOLEAN MODE) or name like '%" . $keyword . "%' ";
     }
     $merchant_id = intval($GLOBALS['request']['merchant_id']);
     if ($merchant_id > 0) {
         $youhui_ids = $GLOBALS['db']->getOne("select group_concat(youhui_id) from " . DB_PREFIX . "youhui_location_link where location_id = " . $merchant_id);
         if ($youhui_ids) {
             $where .= " and id in (" . $youhui_ids . ") ";
         } else {
             $where .= " and id = 0 ";
         }
     }
     $sql_count .= " where " . $where;
     $sql .= " where " . $where;
     if ($xpoint > 0) {
         $orderby = " order by distance asc ";
     } else {
         $orderby = " order by sort desc,id desc";
     }
     /*排序*/
     if ($order_type == 'avg_point') {
         $orderby = " order by avg_point desc,id desc ";
     } elseif ($order_type == 'newest') {
         $orderby = " order by create_time desc,id desc ";
     } elseif ($order_type == 'buy_count') {
         $orderby = " order by view_count desc,id desc ";
     }
     $sql .= $orderby . " limit " . $limit;
     //echo $sql; exit;
     $total = $GLOBALS['db']->getOne($sql_count);
     $page_total = ceil($total / $page_size);
     $list = $GLOBALS['db']->getAll($sql);
     $youhui_list = array();
     foreach ($list as $item) {
         $youhui_list[] = m_youhuiItem($item);
     }
     foreach ($youhui_list as $k => $v) {
         $youhui_list[$k]['logo'] = get_abs_img_root(get_spec_image($v['logo'], 140, 85, 0));
     }
     /*输出分类*/
     //$bcate_list = getCateList();
     /*输出商圈*/
     //$quan_list=getQuanList($city_id);
     //print_r($quan_list);exit;
     if ($bcate_list === false) {
         $root['bcate_list'] = array();
     } else {
         $root['bcate_list'] = $bcate_list;
     }
     if ($quan_list === false) {
         $root['quan_list'] = array();
     } else {
         $root['quan_list'] = $quan_list;
     }
     $root['item'] = $youhui_list;
     $root['page'] = array("page" => $page, "page_total" => $page_total, "page_size" => $page_size);
     $root['page_title'] = "优惠券列表";
     //fwb 2014-08-27
     $root['city_name'] = $city_name;
     output($root);
 }
Example #4
0
 public function index()
 {
     require_once APP_ROOT_PATH . 'app/Lib/youhui_lib.php';
     $catalog_id = intval($GLOBALS['request']['catalog_id']);
     //商品分类ID
     $city_id = intval($GLOBALS['request']['city_id']);
     //城市分类ID
     $page = intval($GLOBALS['request']['page']);
     //分页
     $keyword = strim($GLOBALS['request']['keyword']);
     $city_name = strim($GLOBALS['request']['city_name']);
     //城市名称
     $page = $page == 0 ? 1 : $page;
     $ytop = $latitude_top = floatval($GLOBALS['request']['latitude_top']);
     //最上边纬线值 ypoint
     $ybottom = $latitude_bottom = floatval($GLOBALS['request']['latitude_bottom']);
     //最下边纬线值 ypoint
     $xleft = $longitude_left = floatval($GLOBALS['request']['longitude_left']);
     //最左边经度值  xpoint
     $xright = $longitude_right = floatval($GLOBALS['request']['longitude_right']);
     //最右边经度值 xpoint
     $ypoint = $m_latitude = doubleval($GLOBALS['request']['m_latitude']);
     //ypoint
     $xpoint = $m_longitude = doubleval($GLOBALS['request']['m_longitude']);
     //xpoint
     /*输出分类*/
     $bcate_list = getCateList();
     /*输出商圈*/
     $quan_list = getQuanList($city_id);
     $page_size = PAGE_SIZE;
     $limit = ($page - 1) * $page_size . "," . $page_size;
     if ($keyword) {
         $kws_div = div_str($keyword);
         foreach ($kws_div as $k => $item) {
             $kws[$k] = str_to_unicode_string($item);
         }
         $ukeyword = implode(" ", $kws);
         $condition = "  (match(tag_match,name_match,locate_match,deal_cate_match) against('" . $ukeyword . "' IN BOOLEAN MODE) or name like '%" . $keyword . "%') ";
     }
     if ($xpoint > 0) {
         $pi = 3.14159265;
         //圆周率
         $r = 6378137;
         //地球平均半径(米)
         $field_append = ", (ACOS(SIN(({$ypoint} * {$pi}) / 180 ) *SIN((ypoint * {$pi}) / 180 ) +COS(({$ypoint} * {$pi}) / 180 ) * COS((ypoint * {$pi}) / 180 ) *COS(({$xpoint} * {$pi}) / 180 - (xpoint * {$pi}) / 180 ) ) * {$r}) as distance ";
         if ($ybottom != 0 && $ytop != 0 && $xleft != 0 && $xright != 0) {
             if ($condition != "") {
                 $condition .= " and ";
             }
             $condition .= "  ypoint > {$ybottom} and ypoint < {$ytop} and xpoint > {$xleft} and xpoint < {$xright} ";
         }
         $order = " distance asc ";
     } else {
         $field_append = "";
         $order = " sort desc ";
     }
     $deals = m_search_youhui_list($limit, intval($catalog_id), $condition, $order, $city_id, $field_append);
     //		$deals = get_goods_list($limit,$catalog_id,"","sort desc",false,$city_id);
     $list = $deals['list'];
     $count = $deals['count'];
     $page_total = ceil($count / $page_size);
     $root = array();
     $root['return'] = 1;
     $goodses = array();
     foreach ($list as $item) {
         //$goods = array();
         $goods = getGoodsArray($item);
         $goods['distance'] = round($goods['distance']);
         $goodses[] = $goods;
     }
     $root['item'] = $goodses;
     $root['bcate_list'] = $bcate_list;
     $root['quan_list'] = $quan_list;
     $root['page'] = array("page" => $page, "page_total" => $page_total, "page_size" => $page_size);
     $root['page_title'] = '代金券列表';
     $root['city_name'] = $city_name;
     output($root);
 }