Example #1
0
 public function index()
 {
     $root = array();
     $root['return'] = 1;
     //检查用户,用户密码
     $user = $GLOBALS['user_info'];
     $user_id = intval($user['id']);
     if ($user_id == 0) {
         $root['user_login_status'] = 0;
         //用户登陆状态:1:成功登陆;0:未成功登陆
         output($root);
     } else {
         $root['user_login_status'] = 1;
     }
     $brand_ids = $GLOBALS['db']->getOne("select group_concat(brand_id) from " . DB_PREFIX . "brand_dy where uid = " . $user_id);
     //print_r($brand_ids);
     if (!$brand_ids) {
         $brand_ids = -1;
     }
     if (substr($brand_ids, -1, 1) == ',') {
         $brand_ids = substr($brand_ids, 0, -1);
     }
     $merchant_ids = $GLOBALS['db']->getOne("select group_concat(supplier_id) from " . DB_PREFIX . "supplier_dy where uid = " . $user_id);
     if (!$merchant_ids) {
         $merchant_ids = -1;
     }
     if (substr($merchant_ids, -1, 1) == ',') {
         $merchant_ids = substr($merchant_ids, 0, -1);
     }
     $page = intval($GLOBALS['request']['page']);
     //分页
     $page_size = PAGE_SIZE;
     $limit = ($page - 1) * $page_size . "," . $page_size;
     $sql_count = "select count(*) from " . DB_PREFIX . "youhui ";
     //$sql = "select id,merchant_id,title,content,merchant_logo,create_time,merchant_xpoint,merchant_ypoint,merchant_api_address,image_1 from ".FDB::table("merchant_youhui");
     $sql = "select id, supplier_id as merchant_id,name as title,list_brief as content,icon as merchant_logo,create_time,xpoint,ypoint,address as api_address,icon as image_1 from " . DB_PREFIX . "youhui ";
     $now = get_gmtime();
     $where = "1 = 1 and is_effect = 1 and (end_time = 0 or end_time > " . $now . ") and  (brand_id in (" . $brand_ids . ") or supplier_id in (" . $merchant_ids . "))";
     $sql_count .= " where " . $where;
     $sql .= " where " . $where;
     $sql .= " order by create_time desc limit " . $limit;
     $total = $GLOBALS['db']->getOne($sql_count);
     $page_total = ceil($total / $page_size);
     //print_r($sql); exit;
     $list = $GLOBALS['db']->getAll($sql);
     $youhui_list = array();
     foreach ($list as $item) {
         $youhui_list[] = m_youhuiItem($item);
     }
     if ($GLOBALS['request']['from'] == 'wap') {
         $root['email'] = $email;
         $root['f_link_data'] = get_link_list();
     }
     $root['item'] = $youhui_list;
     $root['page'] = array("page" => $page, "page_total" => $page_total, "page_size" => $page_size);
     $root['now'] = $now;
     output($root);
 }
Example #2
0
 public function index()
 {
     $root = array();
     $root['return'] = 1;
     $city_id = intval($GLOBALS['request']['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
     $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
     $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;
     //地球平均半径(米)
     $now = get_gmtime();
     $sql_count = "select count(*) from " . DB_PREFIX . "youhui ";
     $sql = "select id, supplier_id as merchant_id,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";
     if ($ybottom != 0 && $ytop != 0 && $xleft != 0 && $xright != 0) {
         $where = " ypoint > {$ybottom} and ypoint < {$ytop} and xpoint > {$xleft} and xpoint < {$xright} and is_effect = 1 and begin_time<" . $now . " and (end_time = 0 or end_time > " . $now . ") ";
     } else {
         $where = " is_effect = 1 and begin_time<" . $now . " and (end_time = 0 or end_time > " . $now . ") ";
     }
     $sql .= " where " . $where;
     $sql .= " order by distance asc ";
     $sql_count .= " where " . $where;
     $sql .= " limit " . $limit;
     $total = $GLOBALS['db']->getOne($sql_count);
     $page_total = ceil($total / $page_size);
     $list = $GLOBALS['db']->getAll($sql);
     $youhui_list = array();
     foreach ($list as $item) {
         $item = m_youhuiItem($item);
         $item['distance'] = round($item['distance']);
         $youhui_list[] = $item;
     }
     $root['item'] = $youhui_list;
     $root['page'] = array("page" => $page, "page_total" => $page_total, "page_size" => $page_size);
     output($root);
 }
 public function index()
 {
     $root = array();
     $root['return'] = 1;
     $page = intval($_FANWE['requestData']['page']);
     //分页
     $page = $page == 0 ? 1 : $page;
     $email = addslashes($GLOBALS['request']['email']);
     //用户名或邮箱
     $pwd = addslashes($GLOBALS['request']['pwd']);
     //密码
     //检查用户,用户密码
     $user = user_check($email, $pwd);
     $user_id = intval($user['id']);
     if ($user_id == 0) {
         $root['user_login_status'] = 0;
         //用户登陆状态:1:成功登陆;0:未成功登陆
         output($root);
     } else {
         $root['user_login_status'] = 1;
     }
     $page_size = PAGE_SIZE;
     $limit = ($page - 1) * $page_size . "," . $page_size;
     $sql_count = "select count(*) from " . DB_PREFIX . "youhui as yh left join " . DB_PREFIX . "youhui_sc as sc on yh.id = sc.youhui_id ";
     $sql = "select yh.id, yh.supplier_id as merchant_id,yh.name as title,yh.list_brief as content,yh.icon as merchant_logo,yh.create_time,yh.xpoint,yh.ypoint,yh.address as api_address,yh.icon as image_1 from " . DB_PREFIX . "youhui as yh left join " . DB_PREFIX . "youhui_sc as sc on yh.id = sc.youhui_id ";
     $where = " 1 = 1 and yh.is_effect = 1 and sc.uid = " . $user_id;
     $sql_count .= " where " . $where;
     $sql .= " where " . $where;
     $sql .= " order by yh.create_time desc limit " . $limit;
     $total = $GLOBALS['db']->getOne($sql_count);
     $page_total = ceil($total / $page_size);
     //echo $sql;
     $list = $GLOBALS['db']->getAll($sql);
     $youhui_list = array();
     foreach ($list as $item) {
         $youhui_list[] = m_youhuiItem($item);
         //
     }
     $root['item'] = $youhui_list;
     $root['page'] = array("page" => $page, "page_total" => $page_total);
     $root['now'] = $now;
     output($root);
 }
 public function run()
 {
     global $_FANWE;
     $root = array();
     $root['return'] = 1;
     $city_id = intval($_FANWE['requestData']['city_id']);
     $quan_id = intval($_FANWE['requestData']['quan_id']);
     $cate_id = intval($_FANWE['requestData']['cate_id']);
     $page = intval($_FANWE['requestData']['page']);
     //分页
     $page = $page == 0 ? 1 : $page;
     $page_size = PAGE_SIZE;
     $limit = ($page - 1) * $page_size . "," . $page_size;
     $sql_count = "select count(*) from " . FDB::table("merchant_youhui");
     $sql = "select id,merchant_id,title,content,merchant_logo,create_time,merchant_xpoint,merchant_ypoint,merchant_api_address,image_1 from " . FDB::table("merchant_youhui");
     $now = TIME_UTC;
     $where = "1 = 1 and status = 1 and begin_time<" . $now . " and (end_time = 0 or end_time > " . $now . ")";
     if ($city_id > 0) {
         $where .= " and merchant_city_id = {$city_id}";
     }
     if ($quan_id > 0) {
         $where .= " and merchant_quan_id = {$quan_id}";
     }
     if ($cate_id > 0) {
         $where .= " and merchant_category_id = {$cate_id}";
     }
     $sql_count .= " where " . $where;
     $sql .= " where " . $where;
     $sql .= " limit " . $limit;
     //echo $sql; exit;
     $total = FDB::resultFirst($sql_count);
     $page_total = ceil($total / $page_size);
     $list = FDB::fetchAll($sql);
     $youhui_list = array();
     foreach ($list as $item) {
         $youhui_list[] = m_youhuiItem($item);
     }
     $root['item'] = $youhui_list;
     $root['page'] = array("page" => $page, "page_total" => $page_total);
     m_display($root);
 }
 public function index()
 {
     $act_2 = $GLOBALS['request']['act_2'];
     //子操作 空:没子操作; dz:设置打折提醒;sc:(取消)收藏
     $email = addslashes($GLOBALS['request']['email']);
     //用户名或邮箱
     $pwd = addslashes($GLOBALS['request']['pwd']);
     //密码
     //print_r($email);
     //print_r($pwd);
     //检查用户,用户密码
     $user = user_check($email, $pwd);
     //print_r($user);exit;
     $user_id = intval($user['id']);
     if ($act_2 != '' && $user_id == 0) {
         $root['act_2'] = $act_2;
         $root['user_login_status'] = 0;
         //用户登陆状态:1:成功登陆;0:未成功登陆
         output($root);
     }
     $id = intval($GLOBALS['request']['id']);
     //sc:(取消)收藏
     if ($act_2 == "sc") {
         $sql = "select uid from  " . DB_PREFIX . "youhui_sc where uid = {$user_id} and youhui_id = {$id}";
         if (intval($GLOBALS['db']->getOne($sql) > 0)) {
             //已经设置打折提醒,则取消
             $sql = "delete from " . DB_PREFIX . "youhui_sc where uid = {$user_id} and youhui_id = {$id}";
             $GLOBALS['db']->query($sql);
         } else {
             //没设置,则设置
             $merchant_youhui_sc = array('uid' => $user_id, 'youhui_id' => $id);
             $GLOBALS['db']->autoExecute(DB_PREFIX . "youhui_sc", $merchant_youhui_sc, 'INSERT');
         }
     }
     $sql = "select a.id, a.supplier_id as merchant_id, a.name as title, a.brief as content,a.icon as merchant_logo,a.create_time,a.xpoint,a.ypoint,a.address as api_address,a.icon as image_1, a.image_3,a.image_3_w,a.image_3_h, a.begin_time,a.end_time, " . "(select count(*) from " . DB_PREFIX . "youhui_sc as b where b.uid = {$user_id} and b.youhui_id = a.id) as is_sc, " . "(select count(*) from " . DB_PREFIX . "message as c where c.rel_table = 'youhui' and c.rel_id = a.id) as comment_count, " . "(select name from " . DB_PREFIX . "deal_city as d where d.id = a.city_id) as city_name " . " from " . DB_PREFIX . "youhui as a where a.id = {$id} ";
     //echo $sql; exit;
     $youhui = $GLOBALS['db']->getRow($sql);
     $root = m_youhuiItem($youhui);
     //$root['merchant_id'] = 0;
     $root['act_2'] = $act_2;
     $root['user_login_status'] = 1;
     //print_r($root);exit;
     //分享信息
     //$site_url = ';网址:'.str_replace($_FANWE['site_root'],'',$_FANWE['site_url']).FU('yh/detail',array('id'=>$youhui['id']));
     //$site_url = get_domain().url("youhui","ydetail",array("id"=>$deal['id']));
     $site_url = get_domain() . url("youhui", "ydetail", array("id" => $youhui['id']));
     $site_url = str_replace('/mapi/', '/', $site_url);
     $root['share_content'] = msubstr($youhui['title'], 0, 140 - strlen($site_url) - 3) . $site_url;
     $root['return'] = 1;
     $merchant_id = intval($youhui[merchant_id]);
     if ($merchant_id > 0) {
         if ($act_2 == "dz") {
             $sql = "select uid from  " . DB_PREFIX . "supplier_dy where uid = {$user_id} and supplier_id = {$merchant_id}";
             if (intval($GLOBALS['db']->getOne($sql) > 0)) {
                 //已经设置打折提醒,则取消
                 $sql = "delete from " . DB_PREFIX . "supplier_dy where uid = {$user_id} and supplier_id = {$merchant_id}";
                 $GLOBALS['db']->query($sql);
             } else {
                 //没设置,则设置
                 $merchant_dy = array('uid' => $user_id, 'supplier_id' => $merchant_id);
                 $GLOBALS['db']->autoExecute(DB_PREFIX . "supplier_dy", $merchant_dy, 'INSERT');
             }
         }
         $sql = "select a.id,a.name,a.content as brief,a.preview as logo, b.uid as is_dy from " . DB_PREFIX . "supplier as a " . " left outer join " . DB_PREFIX . "supplier_dy as b on b.uid = {$user_id} and b.supplier_id = a.id " . "where a.id = {$merchant_id} ";
         //echo $sql; exit;
         $merchant = $GLOBALS['db']->getRow($sql);
         $merchant = m_merchantItem($merchant);
         $root['merchant'] = $merchant;
         $ypoint = $m_latitude = doubleval($GLOBALS['request']['m_latitude']);
         //ypoint
         $xpoint = $m_longitude = doubleval($GLOBALS['request']['m_longitude']);
         //xpoint
         $pi = 3.14159265;
         //圆周率
         $r = 6378137;
         //地球平均半径(米)
         $sql = "select a.id,a.name,a.address,a.tel,a.supplier_id as brand_id,a.brief,a.preview as logo,a.xpoint,a.ypoint,a.route as api_address, (select count(*) from " . DB_PREFIX . "message as m where m.rel_table = 'supplier_location' and m.rel_id = a.id) as comment_count,c.name as city_name,\r\n\t\t\t\t(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 \r\n\t\t\t\t from " . DB_PREFIX . "supplier_location as a " . " left outer join " . DB_PREFIX . "deal_city as c on c.id = a.city_id " . "where a.supplier_id = {$merchant_id} ";
         $list = $GLOBALS['db']->getAll($sql);
         $list_merchant = array();
         foreach ($list as $item) {
             $list_merchant[] = m_merchantItem($item);
         }
         $root['list_merchant'] = $list_merchant;
     }
     output($root);
 }
Example #6
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 #7
0
 public function index()
 {
     $act_2 = $GLOBALS['request']['act_2'];
     //子操作 空:没子操作; dz:设置打折提醒;sc:(取消)收藏
     $city_name = strim($GLOBALS['request']['city_name']);
     //城市名称
     //print_r($email);
     //print_r($pwd);
     //检查用户,用户密码
     $user = $GLOBALS['user_info'];
     //print_r($user);exit;
     $user_id = intval($user['id']);
     if ($act_2 != '' && $user_id == 0) {
         $root['act_2'] = $act_2;
         $root['user_login_status'] = 0;
         //用户登陆状态:1:成功登陆;0:未成功登陆
         output($root);
     }
     $id = intval($GLOBALS['request']['id']);
     $sql = "update " . DB_PREFIX . "youhui set view_count = view_count + 1 where id = " . $id;
     $GLOBALS['db']->query($sql);
     //sc:(取消)收藏
     if ($act_2 == "sc") {
         $sql = "select uid from  " . DB_PREFIX . "youhui_sc where uid = {$user_id} and youhui_id = {$id}";
         if (intval($GLOBALS['db']->getOne($sql) > 0)) {
             //已经设置打折提醒,则取消
             $sql = "delete from " . DB_PREFIX . "youhui_sc where uid = {$user_id} and youhui_id = {$id}";
             $GLOBALS['db']->query($sql);
         } else {
             //没设置,则设置
             $merchant_youhui_sc = array('uid' => $user_id, 'youhui_id' => $id);
             $GLOBALS['db']->autoExecute(DB_PREFIX . "youhui_sc", $merchant_youhui_sc, 'INSERT');
         }
     }
     $sql = "select a.id, a.supplier_id as merchant_id,a.is_sms, a.name as title, a.icon as merchant_logo,a.create_time,a.xpoint,a.ypoint,a.address as api_address,a.icon as image_1, a.image_3,a.image_3_w,a.image_3_h, a.begin_time,a.end_time, a.description as content,a.use_notice,a.view_count,a.print_count,a.sms_count," . "(select count(*) from " . DB_PREFIX . "youhui_sc as b where b.uid = {$user_id} and b.youhui_id = a.id) as is_sc, " . "(select count(*) from " . DB_PREFIX . "message as c where c.rel_table = 'youhui' and c.rel_id = a.id) as comment_count, " . "(select name from " . DB_PREFIX . "deal_city as d where d.id = a.city_id) as city_name " . " from " . DB_PREFIX . "youhui as a where a.id = {$id} ";
     //file_put_contents(APP_ROOT_PATH. "sjmapi/log/sql_".strftime("%Y%m%d%H%M%S",time()).".txt",$sql);
     //echo $sql; exit;
     $youhui = $GLOBALS['db']->getRow($sql);
     $root = m_youhuiItem($youhui);
     $root['logo'] = get_abs_img_root(get_spec_image($root['logo'], 320, 194, 0));
     $root['down_count'] = $root['sms_count'] + $root['print_count'];
     //$root['merchant_id'] = 0;
     $root['act_2'] = $act_2;
     $root['user_login_status'] = 1;
     //print_r($root);exit;
     //分享信息
     //$site_url = ';网址:'.str_replace($_FANWE['site_root'],'',$_FANWE['site_url']).FU('yh/detail',array('id'=>$youhui['id']));
     //$site_url = get_domain().url("youhui","ydetail",array("id"=>$deal['id']));
     $site_url = get_domain() . url("youhui", "fdetail", array("id" => $youhui['id']));
     $site_url = str_replace('/sjmapi/', '/', $site_url);
     $root['share_content'] = msubstr($youhui['title'], 0, 140 - strlen($site_url) - 3) . $site_url;
     $root['return'] = 1;
     $merchant_id = intval($youhui[merchant_id]);
     if ($merchant_id > 0) {
         if ($act_2 == "dz") {
             $sql = "select uid from  " . DB_PREFIX . "supplier_dy where uid = {$user_id} and supplier_id = {$merchant_id}";
             if (intval($GLOBALS['db']->getOne($sql) > 0)) {
                 //已经设置打折提醒,则取消
                 $sql = "delete from " . DB_PREFIX . "supplier_dy where uid = {$user_id} and supplier_id = {$merchant_id}";
                 $GLOBALS['db']->query($sql);
             } else {
                 //没设置,则设置
                 $merchant_dy = array('uid' => $user_id, 'supplier_id' => $merchant_id);
                 $GLOBALS['db']->autoExecute(DB_PREFIX . "supplier_dy", $merchant_dy, 'INSERT');
             }
         }
         $sql = "select a.id,a.name,a.content as brief,a.preview as logo, b.uid as is_dy from " . DB_PREFIX . "supplier as a " . " left outer join " . DB_PREFIX . "supplier_dy as b on b.uid = {$user_id} and b.supplier_id = a.id " . "where a.id = {$merchant_id} ";
         //echo $sql; exit;
         $merchant = $GLOBALS['db']->getRow($sql);
         $merchant = m_merchantItem($merchant);
         $root['merchant'] = $merchant;
         $ypoint = $m_latitude = doubleval($GLOBALS['request']['m_latitude']);
         //ypoint
         $xpoint = $m_longitude = doubleval($GLOBALS['request']['m_longitude']);
         //xpoint
         $pi = 3.14159265;
         //圆周率
         $r = 6378137;
         //地球平均半径(米)
         /*
         if($GLOBALS['request']['from']=="wap"){
         		//购买评论			
         	$message_re=m_get_message_list(3," m.rel_table = 'deal' and m.rel_id=".$id." and m.is_buy = 1");//购买评论
         	$root['message_list']=$message_re['list']; 
         	$root['message_count']=$message_re['count'];
         	$supplier_location_id=$GLOBALS['db']->getOne("select id from ".DB_PREFIX."supplier_location where supplier_id=".$merchant_id);
         	
         	//门店评论
         	$comment_list=$GLOBALS['db']->getAll("select a.id,a.content,a.point,a.avg_price,a.create_time,b.id as user_id,b.user_name from ".DB_PREFIX."supplier_location_dp as a left join ".DB_PREFIX."user as b on b.id=a.user_id where a.supplier_location_id = ".$supplier_location_id." and a.status = 1");
         	$youhui_count=$GLOBALS['db']->getOne("select count(*) from ".DB_PREFIX."message where rel_table = 'youhui' and rel_id=".$id." and user_id=".$user_id);
         	$comment_count=$GLOBALS['db']->getOne("select count(*) from ".DB_PREFIX."supplier_location_dp as a left join ".DB_PREFIX."user as b on b.id=a.user_id where a.supplier_location_id = ".$supplier_location_id." and a.status = 1");
         	$count_point=0;
         	foreach($comment_list as $k=>$v)
         	{
         		$comment_list[$k]['avg_price']=round($v['avg_price'],2);
         		$comment_list[$k]['time']=pass_date($v['create_time']);
         		$count_point+=$v['point'];
         	}
         	$root['comment_list']=$comment_list;
         	$root['youhui_count']=$youhui_count;
         	$score=round($count_point/$comment_count,2);
         
         	$width = $score > 0 ? ($score / 5) * 100 : 0;
         	$root['point']=$score;
         	$root['width']=$width;
         	$root['comment_count']=$comment_count;
         		//fwb 2014-08-27
         }//fwb add 2014-08-27
         */
         $sql = "select a.id,a.name,a.address,a.api_address, a.tel,a.supplier_id as brand_id,a.brief,a.preview as logo,a.xpoint,a.ypoint,a.route, (select count(*) from " . DB_PREFIX . "message as m where m.rel_table = 'supplier_location' and m.rel_id = a.id) as comment_count,c.name as city_name,\n\t\t\t\t(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 \n\t\t\t\t from " . DB_PREFIX . "supplier_location as a " . " left outer join " . DB_PREFIX . "deal_city as c on c.id = a.city_id " . "where a.supplier_id = {$merchant_id} ";
         $list = $GLOBALS['db']->getAll($sql);
         $list_merchant = array();
         foreach ($list as $item) {
             $list_merchant[] = m_merchantItem($item);
         }
         $root['list_merchant'] = $list_merchant;
     }
     require_once APP_ROOT_PATH . "system/model/review.php";
     require_once APP_ROOT_PATH . "system/model/user.php";
     $message_re = get_dp_list(3, $param = array("deal_id" => 0, "youhui_id" => $youhui['id'], "event_id" => 0, "location_id" => 0, "tag" => ""), "", "");
     foreach ($message_re['list'] as $k => $v) {
         $message_re['list'][$k]['width'] = $v['point'] / 5 * 100;
         $uinfo = load_user($v['user_id']);
         $message_re['list'][$k]['user_name'] = $uinfo['user_name'];
         foreach ($message_re['list'][$k]['images'] as $kk => $vv) {
             $message_re['list'][$k]['images'][$kk] = get_abs_img_root(get_spec_image($vv, 60, 60, 1));
             $message_re['list'][$k]['oimages'][$kk] = get_abs_img_root($vv);
         }
     }
     $root['message_list'] = $message_re['list'];
     if (count($message_re['list']) > 0) {
         $sql = "select count(*) from " . DB_PREFIX . "supplier_location_dp where  " . $message_re['condition'];
         $message_re['count'] = $GLOBALS['db']->getOne($sql);
     }
     $root['message_count'] = $message_re['count'];
     $root['city_name'] = $city_name;
     $root['page_title'] = "优惠券详情";
     output($root);
 }
 public function index()
 {
     $root = array();
     $root['return'] = 1;
     $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']);
     $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
     $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,name as title,list_brief as content,icon as merchant_logo,create_time,xpoint,ypoint,address as api_address,icon as image_1,\r\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  \r\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_list = $GLOBALS['db']->getAll("select `name` from " . DB_PREFIX . "area where id in (" . implode(",", $ids) . ")");
         $unicode_quans = array();
         foreach ($quan_list 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;
     $sql .= " order by distance asc ";
     $sql .= " 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);
     }
     $root['item'] = $youhui_list;
     $root['page'] = array("page" => $page, "page_total" => $page_total);
     output($root);
 }