public function index()
 {
     $email = addslashes($GLOBALS['request']['email']);
     //用户名或邮箱
     $pwd = addslashes($GLOBALS['request']['pwd']);
     //密码
     //检查用户,用户密码
     $user = user_check($email, $pwd);
     $user_id = intval($user['id']);
     $id = intval($GLOBALS['request']['id']);
     $act_2 = $GLOBALS['request']['act_2'];
     //子操作 空:没子操作; dz:设置打折提醒
     if ($act_2 != '' && $user_id == 0) {
         $root['act_2'] = $act_2;
         $root['user_login_status'] = 0;
         //用户登陆状态:1:成功登陆;0:未成功登陆
         output($root);
     }
     if ($act_2 == "dz") {
         $sql = "select uid from  " . DB_PREFIX . "supplier_dy where uid = {$user_id} and supplier_id = {$id}";
         if (intval($GLOBALS['db']->getOne($sql) > 0)) {
             //已经设置打折提醒,则取消
             $sql = "delete from " . DB_PREFIX . "supplier_dy where uid = {$user_id} and supplier_id = {$id}";
             $GLOBALS['db']->query($sql);
         } else {
             //没设置,则设置
             $merchant_dy = array('uid' => $user_id, 'supplier_id' => $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 = {$id} ";
     //echo $sql; exit;
     $merchant = $GLOBALS['db']->getRow($sql);
     $root = m_merchantItem($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 . "supplier_location_dp as dp where dp.supplier_location_id = a.id and dp.status = 1) as comment_count, c.name as city_name, \r\n\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  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 = {$id} ";
     $list = $GLOBALS['db']->getAll($sql);
     $list_merchant = array();
     foreach ($list as $item) {
         $list_merchant[] = m_merchantItem($item);
     }
     $root['list_merchant'] = $list_merchant;
     $root['return'] = 1;
     $root['user_login_status'] = 1;
     output($root);
 }
示例#2
0
 public function index()
 {
     //print_r($GLOBALS['request']);
     //检查用户,用户密码
     $user = $GLOBALS['user_info'];
     $user_id = intval($user['id']);
     $id = intval($GLOBALS['request']['id']);
     $city_id = intval($GLOBALS['request']['city_id']);
     $act_2 = $GLOBALS['request']['act_2'];
     //子操作 空:没子操作; dz:设置打折提醒
     if ($act_2 != '' && $user_id == 0) {
         $root['act_2'] = $act_2;
         $root['user_login_status'] = 0;
         //用户登陆状态:1:成功登陆;0:未成功登陆
         output($root);
     }
     $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.avg_point,a.address,a.api_address,a.supplier_id,a.tel,a.dp_count,a.avg_point,a.supplier_id as brand_id,a.brief,a.preview as logo,a.xpoint,a.ypoint,a.route,a.youhui_count,a.event_count,(select count(*) from " . DB_PREFIX . "supplier_location_dp as dp where dp.supplier_location_id = a.id and dp.status = 1) as comment_count, c.name as city_name, \n\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  from " . DB_PREFIX . "supplier_location as a " . " left outer join " . DB_PREFIX . "deal_city as c on c.id = a.city_id " . "where a.id = {$id} ";
     //file_put_contents(APP_ROOT_PATH. "sjmapi/log/sql_".strftime("%Y%m%d%H%M%S",time()).".txt",$sql);
     $list = $GLOBALS['db']->getRow($sql);
     $root = m_merchantItem($list);
     //is_auto_order 1:手机自主下单;消费者(在手机端上)可以直接给该门店支付金额
     $sql = "select is_auto_order from  " . DB_PREFIX . "supplier_location where id = " . $id;
     $is_auto_order = $GLOBALS['db']->getOne($sql);
     $root['is_auto_order'] = intval($is_auto_order);
     //$root['is_auto_order'] = 0;
     //其它门店
     $sql = "select a.id,a.name,a.avg_point,a.address,a.api_address,a.supplier_id,a.tel,a.dp_count,a.avg_point,a.supplier_id as brand_id,a.brief,a.preview as logo,a.xpoint,a.ypoint,a.route,a.youhui_count,a.event_count,(select count(*) from " . DB_PREFIX . "supplier_location_dp as dp where dp.supplier_location_id = a.id and dp.status = 1) as comment_count, c.name as city_name,\n\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\tfrom " . DB_PREFIX . "supplier_location as a " . " left outer join " . DB_PREFIX . "deal_city as c on c.id = a.city_id " . "where a.id != {$id} and a.supplier_id =" . intval($root['supplier_id']);
     //$root['ss'] = $sql;
     $other_supplier_location = $GLOBALS['db']->getAll($sql);
     if ($other_supplier_location === false) {
         $root['other_supplier_location'] = array();
     } else {
         foreach ($other_supplier_location as $k => $v) {
             $other_supplier_location[$k]['logo'] = get_abs_img_root($v['logo']);
         }
         $root['other_supplier_location'] = $other_supplier_location;
     }
     /*门店团购*/
     $time = get_gmtime();
     $t_where = "where b.location_id=" . $list['id'] . " and a.is_shop=0 and a.is_effect=1 and a.is_delete=0  and ((" . $time . ">= a.begin_time or a.begin_time = 0) and (" . $time . "< a.end_time or a.end_time = 0)) and a.buy_status <> 2";
     $g_where = "where b.location_id=" . $list['id'] . " and a.is_shop=1 and a.is_effect=1 and a.is_delete=0  and ((" . $time . ">= a.begin_time or a.begin_time = 0) and (" . $time . "< a.end_time or a.end_time = 0)) and a.buy_status <> 2";
     $y_where = "where a.is_effect = 1 and b.location_id=" . $list['id'] . " and ((" . $time . ">= a.begin_time or a.begin_time = 0) and (" . $time . "< a.end_time or a.end_time = 0))";
     if ($city_id == 0) {
         require_once APP_ROOT_PATH . "system/model/city.php";
         $city = City::locate_city();
         $city_id = $city['id'];
     }
     if ($city_id > 0) {
         $ids = load_auto_cache("deal_city_belone_ids", array("city_id" => $city_id));
         if ($ids) {
             $t_where .= " and a.city_id in (" . implode(",", $ids) . ")";
             $g_where .= " and a.city_id in (" . implode(",", $ids) . ")";
             $y_where .= " and a.city_id in (" . implode(",", $ids) . ")";
         }
     }
     $tuan_list = $GLOBALS['db']->getAll("select a.brief,a.auto_order,a.id,a.name,a.sub_name,a.origin_price,a.current_price,a.img,a.buy_count,a.discount from " . DB_PREFIX . "deal as a left join " . DB_PREFIX . "deal_location_link as b on b.deal_id=a.id " . $t_where . " order by a.sort desc,a.id desc");
     $tuan_count = $GLOBALS['db']->getOne("select count(a.id) from " . DB_PREFIX . "deal as a left join " . DB_PREFIX . "deal_location_link as b on b.deal_id=a.id " . $t_where . "");
     foreach ($tuan_list as $k => $v) {
         $tuan_list[$k]['origin_price'] = round($v['origin_price'], 2);
         $tuan_list[$k]['current_price'] = round($v['current_price'], 2);
         if ($v['origin_price'] > 0 && floatval($v['discount']) == 0) {
             //手动折扣
             $tuan_list[$k]['save_price'] = round($v['origin_price'] - $v['current_price'], 2);
         } else {
             $tuan_list[$k]['save_price'] = round($v['origin_price'] * ((10 - $v['discount']) / 10), 2);
         }
         if ($v['origin_price'] > 0 && floatval($v['discount']) == 0) {
             $tuan_list[$k]['discount'] = round($v['current_price'] / $v['origin_price'] * 10, 2);
         }
         $tuan_list[$k]['discount'] = round($tuan_list[$k]['discount'], 2);
         $tuan_list[$k]['img'] = get_abs_img_root(get_spec_image($v['img'], 140, 85, 0));
         if (empty($v['brief'])) {
             $tuan_list[$k]['brief'] = $v['name'];
             $tuan_list[$k]['name'] = $v['sub_name'];
         }
     }
     if ($tuan_list === false) {
         $root['tuan_list'] = array();
     } else {
         $root['tuan_list'] = $tuan_list;
     }
     $root['tuan_count'] = $tuan_count;
     /*门店商品*/
     $goods_list = $GLOBALS['db']->getAll("select a.brief,a.id,a.is_hot,a.name,a.sub_name,a.origin_price,a.current_price,a.img,a.buy_count,a.discount from " . DB_PREFIX . "deal as a left join " . DB_PREFIX . "deal_location_link as b on b.deal_id=a.id " . $g_where . " order by a.sort desc,a.id desc");
     foreach ($goods_list as $k => $v) {
         $goods_list[$k]['origin_price'] = round($v['origin_price'], 2);
         $goods_list[$k]['current_price'] = round($v['current_price'], 2);
         if ($v['origin_price'] > 0 && floatval($v['discount']) == 0) {
             //手动折扣
             $goods_list[$k]['save_price'] = round($v['origin_price'] - $v['current_price'], 2);
         } else {
             $goods_list[$k]['save_price'] = round($v['origin_price'] * ((10 - $v['discount']) / 10), 2);
         }
         if ($v['origin_price'] > 0 && floatval($v['discount']) == 0) {
             $goods_list[$k]['discount'] = round($v['current_price'] / $v['origin_price'] * 10, 2);
         }
         $goods_list[$k]['discount'] = round($goods_list[$k]['discount'], 2);
         $goods_list[$k]['img'] = get_abs_img_root(get_spec_image($v['img'], 140, 85, 0));
         if (empty($v['brief'])) {
             $goods_list[$k]['brief'] = $v['name'];
             $goods_list[$k]['name'] = $v['sub_name'];
         }
     }
     if ($goods_list === false) {
         $root['goods_list'] = array();
     } else {
         $root['goods_list'] = $goods_list;
     }
     /*优惠券*/
     $youhui_list = $GLOBALS['db']->getAll("select a.id,a.supplier_id as merchant_id,a.begin_time,a.youhui_type,a.total_num,a.end_time,a.name as title,a.list_brief as content,a.icon as merchant_logo,a.create_time,a.address as api_address,a.view_count,a.print_count,a.sms_count from " . DB_PREFIX . "youhui as a left join " . DB_PREFIX . "youhui_location_link as b on b.youhui_id=a.id " . $y_where . " order by a.sort desc,a.id desc");
     $sql = "select a.id,a.supplier_id as merchant_id,a.begin_time,a.youhui_type,a.total_num,a.end_time,a.name as title,a.list_brief as content,a.icon as merchant_logo,a.create_time,a.address as api_address,a.view_count,a.print_count,a.sms_count from " . DB_PREFIX . "youhui as a left join " . DB_PREFIX . "youhui_location_link as b on b.youhui_id=a.id " . $y_where . " order by a.sort desc,a.id desc";
     $youhui_list = $GLOBALS['db']->getAll($sql);
     foreach ($youhui_list as $k => $v) {
         $youhui_list[$k]['merchant_logo'] = get_abs_img_root(get_spec_image($v['merchant_logo'], 140, 85, 0));
         $youhui_list[$k]['down_count'] = $youhui_list[$k]['sms_count'] + $youhui_list[$k]['print_count'];
         $youhui_list[$k]['begin_time'] = to_date($v['begin_time'], "Y-m-d") . '至' . to_date($v['end_time'], "Y-m-d");
     }
     if ($youhui_list === false) {
         $root['youhui_list'] = array();
     } else {
         $root['youhui_list'] = $youhui_list;
     }
     /*门店评论*/
     // 		$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 = ".$list['id']." and a.status = 1 limit 10");
     // 		$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 = ".$list['id']." and a.status = 1");
     // 		foreach($comment_list as $k=>$v)
     // 		{
     // 			$comment_list[$k]['avg_price']=round($v['avg_price'],1);
     // 			$comment_list[$k]['time']=pass_date($v['create_time']);
     // 			$comment_list[$k]['width']=$v['avg_point'] > 0 ? ($v['avg_point'] / 5) * 90 : 0;
     // 		}
     // 		if ($comment_list === false){
     // 			$root['comment_list']= array();
     // 		}else{
     // 			$root['comment_list']=$comment_list;
     // 		}
     // 		$root['comment_count']=$comment_count;
     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" => 0, "event_id" => 0, "location_id" => $list['id'], "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'];
     if ($act_2 == "dz") {
         $sql = "select uid from  " . DB_PREFIX . "supplier_dy where uid = {$user_id} and supplier_id = " . $list['brand_id'];
         if (intval($GLOBALS['db']->getOne($sql) > 0)) {
             //已经设置打折提醒,则取消
             $sql = "delete from " . DB_PREFIX . "supplier_dy where uid = {$user_id} and supplier_id = " . $list['brand_id'];
             $GLOBALS['db']->query($sql);
         } else {
             //没设置,则设置
             $merchant_dy = array('uid' => $user_id, 'supplier_id' => $list['brand_id']);
             $GLOBALS['db']->autoExecute(DB_PREFIX . "supplier_dy", $merchant_dy, 'INSERT');
         }
     }
     $root['is_dy'] = $GLOBALS['db']->getOne("select uid from " . DB_PREFIX . "supplier_dy where uid = {$user_id} and supplier_id = " . $list['brand_id'] . " ");
     $root['return'] = 1;
     $root['user_login_status'] = 1;
     $root['page_title'] = "商家详情";
     output($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);
 }
 public function index()
 {
     $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_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']);
     //分页
     $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
     $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((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) {
             $condition = " and  ypoint > {$ybottom} and ypoint < {$ytop} and xpoint > {$xleft} and xpoint < {$xright} ";
         }
         $orderby = " order by distance asc ";
     } else {
         $field_append = "";
         $orderby = " ";
     }
     $sql_count = "select count(*) from " . DB_PREFIX . "supplier_location" . " as a";
     $sql = "select a.supplier_id as id,a.name,a.mobile_brief as brief,a.tel,a.preview as logo,a.dp_count as comment_count,a.xpoint,a.ypoint,a.address as api_address, 0 as is_dy {$field_append} from   " . DB_PREFIX . "supplier_location as a ";
     $where = "1 = 1 ";
     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) {
         $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) {
         $where .= " and a.deal_cate_id = {$cate_id}";
     }
     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);
     $list = $GLOBALS['db']->getAll($sql);
     $merchant_list = array();
     foreach ($list as $item) {
         $item = m_merchantItem($item);
         $merchant_list[] = $item;
     }
     $root['item'] = $merchant_list;
     $root['page'] = array("page" => $page, "page_total" => $page_total);
     output($root);
 }
示例#5
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);
 }
示例#6
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);
 }