public function index() { $root = array(); $root['response_code'] = 1; $root['kf_phone'] = $GLOBALS['m_config']['kf_phone']; //客服电话 $root['kf_email'] = $GLOBALS['m_config']['kf_email']; //客服邮箱 //关于我们(填文章ID) $root['about_info'] = intval($GLOBALS['m_config']['about_info']); $root['version'] = VERSION; //接口版本号int $root['page_size'] = PAGE_SIZE; //默认分页大小 $root['program_title'] = $GLOBALS['m_config']['program_title']; $root['site_domain'] = str_replace("/mapi", "", SITE_DOMAIN . APP_ROOT); //站点域名; $root['site_domain'] = str_replace("http://", "", $root['site_domain']); //站点域名; $root['site_domain'] = str_replace("https://", "", $root['site_domain']); //站点域名; /*虚拟的累计项目总个数,支持总人数,项目支持总金额*/ $virtual_effect = $GLOBALS['db']->getOne("select count(*) from " . DB_PREFIX . "deal where is_effect = 1 and is_delete=0"); $virtual_person = $GLOBALS['db']->getOne("select sum((support_count+virtual_person)) from " . DB_PREFIX . "deal_item"); $virtual_money = $GLOBALS['db']->getOne("select sum((support_count+virtual_person)*price) from " . DB_PREFIX . "deal_item"); $root['virtual_effect'] = $virtual_effect; //项目总个数 $root['virtual_person'] = $virtual_person; //累计支持人 $root['virtual_money'] = number_format($virtual_money, 2); //筹资总金额 /*虚拟的累计项目总个数,支持总人数,项目支持总金额 结束*/ /*取6个推荐项目*/ $index_list = $GLOBALS['db']->getAll(" select * from " . DB_PREFIX . "deal where is_effect=1 and is_recommend=1 order by sort desc limit 0,6"); $deal_list = array(); $time = time(); foreach ($index_list as $k => $v) { if ($v['image'] != '') { $v['image'] = get_abs_img_root_wap(get_spec_image($v['image'], 900, 480, 1)); } if ($v['start_time'] > $time) { $tmp_start_day = ceil(($v['start_time'] - $time) / 86400); $v['show'] = "还有" . $tmp_start_day . "天开始"; } elseif ($time > $v['end_time']) { $v['show'] = "已过期"; } else { $tmp_end_day = ceil(($v['end_time'] - $time) / 86400); $v['show'] = "剩余" . $tmp_end_day . "天"; } $deal_list[] = $v; } $GLOBALS['tmpl']->assign('deal_list', $deal_list); /*取3个专题*/ $topic_list = $GLOBALS['db']->getAll("select * from " . DB_PREFIX . "zhuanti where state=1 order by sort desc limit 0,3"); //获取所有分类 $cates = getCateList(); $GLOBALS['tmpl']->assign('topic_list', $topic_list); $GLOBALS['tmpl']->assign('cates', $cates); $GLOBALS['tmpl']->display("index.html"); }
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); }
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); }
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); }
public function index() { $is_ap = $_REQUEST['isap']; //判断是否是爱前进积分商城 //积分商城现判断用户合法性 if ($is_ap == 1) { $this->ap_login(); } $page_title = $is_ap == 1 ? "积分商城" : "推荐项目"; //获取页码 $p = $_REQUEST['p'] ? intval($_REQUEST['p']) : 1; $to_num = ($p - 1) * 10; $condition = " d.is_delete = 0 and d.is_effect = 1 "; if ($is_ap == 1) { $condition .= "and (d.is_ap = 1 or d.is_ap = 2) "; } else { $condition .= "and (d.is_ap = 0 or d.is_ap = 2) "; } //积分商城时需判断 $limit = $to_num . ' , 10'; /* * 增加搜索条件 * 1.cate 分类搜索 * 2.status 状态搜索 * status=1 已成功 status=2 失败 status=3 筹资中 status=4 长期项目 status=0 未开始 all 全部 3.keyword 关键字搜索 * */ if ($_REQUEST['keyword']) { //keyword $condition .= "and d.name like N'%"; $condition .= urldecode($_REQUEST['keyword']) . "%' "; $page_title = "搜索结果"; } if ($_REQUEST['cate']) { //cate $cates_condition = $_REQUEST['cate'] !== "all" ? explode(',', $_REQUEST['cate']) : ""; if ($cates_condition) { $condition .= 'and ('; for ($i = 0; $i < count($cates_condition); $i++) { $condition .= ' d.cate_id = '; $condition .= $cates_condition[$i]; if ($i < count($cates_condition) - 1) { $condition .= ' or'; } } $condition .= ")"; } $page_title = "搜索结果"; } if (isset($_REQUEST['status'])) { //status $status = $_REQUEST['status'] !== "all" ? explode(',', $_REQUEST['status']) : ""; $status_condition = ""; if (!empty($status[0])) { foreach ($status as $key => $v) { $status_condition .= $this->get_status_condition($v); //获取该状态sql语句 if ($key != count($status) - 1) { $status_condition .= ' or '; } } $condition .= ' and '; $condition .= $status_condition; $page_title = "搜索结果"; } } /*search condition END*/ // echo $condition; $result = get_deal_list($limit, $condition); $index_list = $result['list']; $deal_list = array(); $time = time(); foreach ($index_list as $k => $v) { if ($v['image'] != '') { $v['image'] = get_abs_img_root_wap(get_spec_image($v['image'], 560, 220, 1)); } if ($v['start_time'] > $time) { $tmp_start_day = ceil(($v['start_time'] - $time) / 86400); $v['show'] = "还有" . $tmp_start_day . "天开始"; $v['showtype'] = 1; } elseif ($time > $v['end_time']) { $v['show'] = "已过期"; $v['showtype'] = 2; } else { $tmp_end_day = ceil(($v['end_time'] - $time) / 86400); $v['show'] = $tmp_end_day; $v['showtype'] = 3; } $v['cate_name'] = get_cate($v['cate_id']); //如果为积分商城,则将总数*ratio后显示 if ($is_ap == 1) { $v['support_amount'] = (int) $v['support_amount'] * (int) $v['ap_ratio']; $v['limit_price'] = (int) $v['limit_price'] * (int) $v['ap_ratio']; } $deal_list[] = $v; } //获取页面分页数据 // $alldealnum = $GLOBALS['db']->getRow(" select count(id) as num from ".DB_PREFIX."deal as d where ".$condition); $allPNum = ceil($result['rs_count'] / 10); $page = get_pages($allPNum); //获取所有分类 $cates = getCateList(); // print_r($deal_list); $GLOBALS['tmpl']->assign('page', $page); //数量有待验证 $GLOBALS['tmpl']->assign('result_count', ceil($result['rs_count'])); $GLOBALS['tmpl']->assign('page_title', $page_title); $GLOBALS['tmpl']->assign('cates', $cates); $GLOBALS['tmpl']->assign('deal_list', $deal_list); if ($is_ap == 1) { $GLOBALS['tmpl']->display("ap_deals_index.html"); exit; } $GLOBALS['tmpl']->display("deals_index.html"); }
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); }