public function malllist() { $condition = " is_effect = 1 and is_delete = 0 and d.buy_type<>1 and supplier_id<>0 "; //条件 $join_str = ""; $sort_field = "current_price"; $sort_type = intval($_POST['price_sort']) === 1 ? "ASC" : "desc"; if ($_POST['cate_id']) { $cate_id = $_POST['cate_id']; $shop_cate_grade = $GLOBALS['db']->getOne("select grade from " . DB_PREFIX . "shop_cate where id =" . $cate_id); switch ($shop_cate_grade) { case "0": // 一级分类 $condition .= " and ( shop_cate_id=" . $cate_id . " or p_shop_cate_id=" . $cate_id . ")"; break; case "1": // 二级分类 $condition .= " and ( shop_cate_id=" . $cate_id . " or shop_cate_id in (select id from " . DB_PREFIX . "shop_cate where pid=" . $cate_id . "))"; break; default: $condition .= " and shop_cate_id=" . $cate_id; } } if (isset($_POST['city_id']) && $_POST['city_id'] > 1) { $condition .= " and city_id=" . $_POST['city_id']; } $distance = !empty($_POST['distance']) ? $_POST['distance'] : 10000000; //$distance = 10000000; $lng = '119.025595'; $lat = '33.596043'; if (!empty($_POST['lng']) && $_POST['lng'] != "" && !empty($_POST['lat']) && $_POST['lat'] != "") { $lng = $_POST['lng']; $lat = $_POST['lat']; $condition .= " and id in ( select deal_id from " . DB_PREFIX . "deal_location_link where location_id in (select id from " . DB_PREFIX . "supplier_location where " . search_where_radius($distance, $lng, $lat, "location") . "))"; } $num = empty($_POST['num']) ? 30 : $_POST['num']; // page size $prepage = empty($_POST['prepage']) ? 0 : $_POST['prepage']; $start = $prepage * $num + 0; $limit = $start . "," . $num; $kw = addslashes(htmlspecialchars(trim($_REQUEST['keyword']))); if ($kw != '') { $GLOBALS['tmpl']->assign('keyword', $kw); if ($add_title != '') { $add_title .= "-"; } $add_title .= $kw; $kws_div = div_str($kw); foreach ($kws_div as $k => $item) { $kws[$k] = str_to_unicode_string($item); } $ukeyword = implode(" ", $kws); $condition .= " and (match(d.tag_match,d.name_match,d.locate_match,d.shop_cate_match) against('" . $ukeyword . "' IN BOOLEAN MODE))"; //$condition.=" and (d.name like '%".$kw."%' or d.sub_name like '%".$kw."%' or d.brief like '%".$kw."%' or d.description like '%".$kw."%')"; } // file_put_contents("/tmp/mall.log", "\n".json_encode($_POST)."\n",FILE_APPEND); // file_put_contents("/tmp/mall.log", "\n condition:$condition\n",FILE_APPEND); $result = search_goods_list($limit, intval($cate_id), $condition, "d." . $sort_field . " " . $sort_type, false, $join_str); if ($result === FALSE) { $result = array('ret' => '102'); } else { $result['ret'] = '0'; $result['goodslist'] = array(); foreach ($result['list'] as $index => $val) { $result['goodslist'][$index]['brand_name'] = $GLOBALS['db']->getOne("select name from tb_brand where id =" . $val['brand_id']); $sql = "select xpoint as lng,ypoint as lat,ROUND(SQRT(POW(ABS(X(location)-" . $lng . ")/0.001024*100,2)+POW(ABS(Y(location)-" . $lat . ")/0.000886*100,2))) AS `dis` from " . DB_PREFIX . "supplier_location where id in (select location_id from " . DB_PREFIX . "deal_location_link where deal_id=" . $val['id'] . ") order by dis desc limit 1"; $location = $GLOBALS['db']->getAll($sql); $result['goodslist'][$index]['xpoint'] = '119.025595'; $result['goodslist'][$index]['ypoint'] = '33.596043'; if (!$location) { $result['goodslist'][$index]['location_list'] = array(); } else { $result['goodslist'][$index]['location_list'] = $location; $result['goodslist'][$index]['xpoint'] = $location[0]['lng']; $result['goodslist'][$index]['ypoint'] = $location[0]['lat']; $result['goodslist'][$index]['dis'] = $location[0]['dis']; } $result['goodslist'][$index]['id'] = $val['id']; $result['goodslist'][$index]['name'] = $val['name']; $result['goodslist'][$index]['sub_name'] = $val['sub_name']; $result['goodslist'][$index]['cate_id'] = $val['cate_id']; $result['goodslist'][$index]['img'] = $val['img']; //$result['goodslist'][$index]['description'] = $val['description']; $result['goodslist'][$index]['origin_price'] = $val['origin_price']; $result['goodslist'][$index]['current_price'] = $val['current_price']; $result['goodslist'][$index]['city_id'] = $val['city_id']; $result['goodslist'][$index]['icon'] = $val['icon']; $result['goodslist'][$index]['create_time'] = $val['create_time']; $result['goodslist'][$index]['brand_id'] = $val['brand_id']; $result['goodslist'][$index]['url'] = $val['url']; $result['goodslist'][$index]['is_delivery'] = $val['is_delivery']; $result['goodslist'][$index]['is_can_buy'] = is_can_buy($val['shop_cate_id']) ? '1' : '0'; $result['goodslist'][$index]['is_cash_pay'] = $val['is_cash_pay']; } $result['num'] = strval($num); $result['page'] = strval($prepage + 1); unset($result['list']); } echo json_encode($result); }
public function deal_is_can_buy() { if (empty($_POST['deal_id'])) { echo json_encode(array('ret' => '158', 'msg' => '请求参数为空')); } else { $deal_id = $_POST['deal_id']; $shop_cate_id = $GLOBALS['db']->getOne("select shop_cate_id from " . DB_PREFIX . "deal where id=" . $deal_id); if ($shop_cate_id > 0) { if (is_can_buy($shop_cate_id)) { ajax_return(array('ret' => '0', 'is_can_buy' => '1')); } ajax_return(array('ret' => '0', 'is_can_buy' => '0')); } else { ajax_return(array('ret' => '0', 'is_can_buy' => '0')); } } }
public function index() { $preview = intval($_REQUEST['preview']); $id = intval($_REQUEST['id']); if (isset($_GET['plat'])) { $plat = $_GET['plat']; } if ($preview > 0) { $goods = get_goods($id, $preview); if ($goods['buy_type'] == 1) { app_redirect(url("shop", "exchange", array("id" => $goods['id'], "preview" => $preview))); } $adm_session = es_session::get(md5(app_conf("AUTH_KEY"))); $adm_name = $adm_session['adm_name']; $adm_id = intval($adm_session['adm_id']); if ($adm_id == 0) { //验证是否当前的商家(不是后台管理员) $s_account_info = es_session::get("account_info"); if ($s_account_info) { foreach ($s_account_info['location_ids'] as $id) { $location = $GLOBALS['db']->getRow("select * from " . DB_PREFIX . "supplier_location where id = " . $id); if ($location) { $locations[] = $location; } } $deal_test = $GLOBALS['db']->getRow("select d.* from " . DB_PREFIX . "deal as d left join " . DB_PREFIX . "deal_location_link as l on l.deal_id = d.id where d.id = " . intval($goods['id']) . " and d.is_shop = 1 and d.publish_wait = 1 and l.location_id in (" . implode(",", $s_account_info['location_ids']) . ")"); if (!$deal_test) { showErr("产品不存在或者没有预览该产品的权限", 0, APP_ROOT . "/"); } } else { showErr("您不是系统管理员或者商家会员,无法预览", 0, APP_ROOT . "/"); } } } $GLOBALS['tmpl']->caching = true; $cache_id = md5(MODULE_NAME . ACTION_NAME . trim($_REQUEST['id']) . $GLOBALS['deal_city']['id'] . $preview); $GLOBALS['tmpl']->is_cached('goods_info.html', $cache_id); if (!$GLOBALS['tmpl']->is_cached('goods_info.html', $cache_id) || $plat == APP_PLAT) { $id = intval($_REQUEST['id']); //获取当前页的团购商品 $uname = addslashes(trim($_REQUEST['id'])); if ($id == 0 && $uname == '') { app_redirect(url("shop", "index")); } elseif ($id == 0 && $uname != '') { $id = $GLOBALS['db']->getOne("select id from " . DB_PREFIX . "deal where uname = '" . $uname . "'"); } //获取当前页的团购商品 if ($preview > 0) { $goods = get_goods($id, $preview); } else { $goods = get_goods($id); } //输出促销 if ($goods['allow_promote'] == 1) { $promote = load_auto_cache("cache_promote"); $GLOBALS['tmpl']->assign("promote", $promote); } //输出商城分类 $cate_tree = get_cate_tree($goods['shop_cate_id']); $GLOBALS['tmpl']->assign("cate_id", $goods['shop_cate_id']); $GLOBALS['tmpl']->assign("cate_tree", $cate_tree); if (!$goods || $goods['buy_type'] == 1) { app_redirect(url("shop", "mall")); } /** if($plat == APP_PLAT){ echo json_encode($goods);exit; } */ //判断is_shop自动跳转 jump_deal($goods, MODULE_NAME); //输出规格库存的配置 $attr_stock = $GLOBALS['db']->getAll("select * from " . DB_PREFIX . "attr_stock where deal_id = " . $goods['id'] . " order by id asc"); $attr_cfg_json = "{"; $attr_stock_json = "{"; foreach ($attr_stock as $k => $v) { $attr_cfg_json .= $k . ":" . "{"; $attr_stock_json .= $k . ":" . "{"; foreach ($v as $key => $vvv) { if ($key != 'attr_cfg') { $attr_stock_json .= "\"" . $key . "\":" . "\"" . $vvv . "\","; } } $attr_stock_json = substr($attr_stock_json, 0, -1); $attr_stock_json .= "},"; $attr_cfg_data = unserialize($v['attr_cfg']); foreach ($attr_cfg_data as $attr_id => $vv) { $attr_cfg_json .= $attr_id . ":" . "\"" . $vv . "\","; } $attr_cfg_json = substr($attr_cfg_json, 0, -1); $attr_cfg_json .= "},"; } if ($attr_stock) { $attr_cfg_json = substr($attr_cfg_json, 0, -1); $attr_stock_json = substr($attr_stock_json, 0, -1); } $attr_cfg_json .= "}"; $attr_stock_json .= "}"; $GLOBALS['tmpl']->assign("attr_cfg_json", $attr_cfg_json); $GLOBALS['tmpl']->assign("attr_stock_json", $attr_stock_json); // if($plat == APP_PLAT){ // if($goods['brand_id']>0){ // $goods['brand_name']=$GLOBALS['db']->getOne('select name from '.DB_PREFIX.'brand where id ='.$goods['brand_id']); // }else{ // $goods['brand_name'] =""; // } // array_recursive($goods, 'strval'); // echo json_encode($goods); // exit; // } // $GLOBALS['tmpl']->assign("goods", $goods); //开始输出当前的site_nav $cates = array(); $cate = $GLOBALS['db']->getRow("select * from " . DB_PREFIX . "shop_cate where id = " . $goods['shop_cate_id']); do { $cates[] = $cate; $pid = intval($cate['pid']); $cate = $GLOBALS['db']->getRow("select * from " . DB_PREFIX . "shop_cate where is_effect =1 and is_delete =0 and id = " . $pid); } while ($pid != 0); $page_title = substr($page_title, 0, -3); krsort($cates); $site_nav[] = array('name' => $GLOBALS['lang']['HOME_PAGE'], 'url' => APP_ROOT . "/"); $site_nav[] = array('name' => $GLOBALS['lang']['SHOP_HOME'], 'url' => url("shop", "mall#index", '')); if ($cates) { foreach ($cates as $cate_row) { if ($cate_row['uname'] != "") { $curl = url("shop", "cate#index", array("id" => $cate_row['uname'])); } else { $curl = url("shop", "cate#index", array("id" => $cate_row['id'])); } $site_nav[] = array('name' => $cate_row['name'], 'url' => $curl); } } if ($goods['uname'] != "") { $gurl = url("shop", "goods#index", array("id" => $goods['uname'])); } else { $gurl = url("shop", "goods#index", array("id" => $goods['id'])); } $site_nav[] = array('name' => $goods['name'], 'url' => $gurl); $GLOBALS['tmpl']->assign("site_nav", $site_nav); //输出当前的site_nav $seo_title = $goods['seo_title'] != '' ? $goods['seo_title'] : $goods['name']; $GLOBALS['tmpl']->assign("page_title", $seo_title); $seo_keyword = $goods['seo_keyword'] != '' ? $goods['seo_keyword'] : $goods['name']; $GLOBALS['tmpl']->assign("page_keyword", $seo_keyword . ","); $seo_description = $goods['seo_description'] != '' ? $goods['seo_description'] : $goods['name']; $GLOBALS['tmpl']->assign("page_description", $seo_description . ","); if (!$GLOBALS['user_info']) { $GLOBALS['tmpl']->assign("message_login_tip", sprintf($GLOBALS['lang']['MESSAGE_LOGIN_TIP'], url("shop", "user#login"), url("shop", "user#register"))); } //输出关联商品 $relate_list = get_goods_list(intval(app_conf("RELATE_GOODS_LIMIT")), $goods['shop_cate_id'], ' buy_type <> 1 and is_shop = 1 and id <> ' . $goods['id'], '', true); $shop_cate_uname = $GLOBALS['db']->getOne("select uname from " . DB_PREFIX . "shop_cate where id = " . $goods['shop_cate_id']); if ($shop_cate_uname != "") { $curl = url("shop", "cate#index", array("id" => $shop_cate_uname)); } else { $curl = url("shop", "cate#index", array("id" => $goods['shop_cate_id'])); } $GLOBALS['tmpl']->assign("relate_list", array('title' => $GLOBALS['lang']['RELATE_LIST'], 'list' => $relate_list['list'], 'url' => $curl)); //供应商的地址列表 //定义location_id $locations = $GLOBALS['db']->getAll("select a.* from " . DB_PREFIX . "supplier_location as a left join " . DB_PREFIX . "deal_location_link as b on a.id = b.location_id where a.is_effect = 1 and b.deal_id = " . intval($goods['id'])); $json_location = array(); $location_ids = array(0); foreach ($locations as $litem) { $location_ids[] = $litem['id']; $arr = array(); $arr['title'] = $litem['name']; $arr['address'] = $litem['address']; $arr['tel'] = $litem['tel']; $arr['lng'] = $litem['xpoint']; $arr['lat'] = $litem['ypoint']; $json_location[] = $arr; } $GLOBALS['tmpl']->assign("json_location", json_encode($json_location)); $GLOBALS['tmpl']->assign("locations", $locations); // 判断该商品所属类型是否允许购买 $is_can_buy = is_can_buy($goods['shop_cate_id']); $GLOBALS['tmpl']->assign("is_can_buy", $is_can_buy); // 输出套餐内容 $sql = "select * from " . DB_PREFIX . "set_meal where deal_id=" . $id; $set_meal = $GLOBALS['db']->getAll($sql); $GLOBALS['tmpl']->assign("set_meal", $set_meal); } if ($_REQUEST['plat'] == APP_PLAT) { $GLOBALS['tmpl']->display("goods_app_info.html"); } else { $GLOBALS['tmpl']->display("goods_info.html", $cache_id); } }
public function app_search() { // //file_put_contents("/tmp/ss.log", "\n".date("Y-m-d H:i:s")." post:".json_encode($_POST)."\n",FILE_APPEND); // $_POST['keyword'] = "电台灯"; // $_POST['s_type'] = "taoxin,deal"; // if (empty($_POST['keyword']) || empty($_POST['s_type'])) { echo json_encode(array('ret' => '102')); } else { // 搜索类型,all为搜索所有 $s_type = $_POST['s_type']; $s_type_arr = explode(",", $s_type); $kw = addslashes(htmlspecialchars(trim($_POST['keyword']))); $kws_div = div_str($kw); // $kws = array(); foreach ($kws_div as $k => $item) { $kws_div[] = str_to_unicode_string($item); } $ukeyword = implode(" ", $kws_div); $num = empty($_POST['num']) ? 10 : $_POST['num']; // page size $prepage = empty($_POST['prepage']) ? 0 : $_POST['prepage']; $start = $prepage * $num + 0; $limit = $start . "," . $num; if (!empty($_POST['lng']) && !empty($_POST['lat'])) { $distance = !empty($_POST['distance']) ? $_POST['distance'] : 1000000; $lng = $_POST['lng']; $lat = $_POST['lat']; } if (in_array("deal", $s_type_arr)) { $sort_type = intval($_POST['price_sort']) === 1 ? "ASC" : "desc"; // 搜索商品 $sql = "select id,name,shop_cate_id,current_price,origin_price,icon,is_delivery,is_cash_pay from " . DB_PREFIX . "deal where is_effect=1 and supplier_id<>0 "; $sql_count = "select count(*) from " . DB_PREFIX . "deal where is_effect=1 and supplier_id<>0 "; $condition = "and match(`name_match`,`deal_cate_match`,`locate_match`,`tag_match`,`shop_cate_match`) against('" . $ukeyword . "') and is_delete=0 "; if (!empty($_POST['lng']) && !empty($_POST['lat'])) { $condition .= "and id in ( select deal_id from " . DB_PREFIX . "deal_location_link as dll left join " . DB_PREFIX . "deal as d on d.id=dll.deal_id where dll.location_id in (select id from " . DB_PREFIX . "supplier_location where " . search_where_radius($distance, $lng, $lat, "location") . ") and d.is_effect=1 and d.is_delete=0)"; } $condition .= " order by current_price " . $sort_type; $condition .= " limit " . $limit; $sql = $sql . $condition; $sql_count = $sql_count . $condition; //file_put_contents("/tmp/ss.log", "\n".date("Y-m-d H:i:s")." sql:".$sql."\n",FILE_APPEND); $result['deal_list'] = $GLOBALS['db']->getAll($sql); $result['deal_count'] = $GLOBALS['db']->getOne($sql_count); if ($result['deal_list'] !== false) { foreach ($result['deal_list'] as $index => $v) { $sql = "select id,name,address,tel from " . DB_PREFIX . "supplier_location where id in (select location_id from " . DB_PREFIX . "deal_location_link where deal_id=" . $v['id'] . ")"; $result['deal_list'][$index]['location_list'] = $GLOBALS['db']->getAll($sql); $sql = "select id,name from " . DB_PREFIX . "supplier where id =" . $v['supplier_id']; $result['deal_list'][$index]['supplier'] = $GLOBALS['db']->getRow($sql); $result['deal_list'][$index]['is_can_buy'] = is_can_buy($v['shop_cate_id']) ? '1' : '0'; } } } if (in_array("taoxin", $s_type_arr)) { // 搜索淘信 $sql = "select id,title,price,contact,address,longitude as lng,latitude as lat from " . DB_PREFIX . "taoxin where match(title,detail) against('" . $ukeyword . "') and verify=1 limit " . $limit; $sql_count = "select count(*) from " . DB_PREFIX . "taoxin where verify=1 and match(title,detail) against('" . $ukeyword . "')"; $result['taoxin_list'] = $GLOBALS['db']->getAll($sql); if (empty($result['taoxin_list'])) { $result['taoxin_list'] = array(); } else { foreach ($result['taoxin_list'] as $i => $v) { $result['taoxin_list'][$i]['photos'] = empty($v['goods_photos']) ? array() : json_decode($v['goods_photos'], true); $result['taoxin_list'][$i]['create_time'] = date("Y-m-d H:i:s", $v['create_time']); $pcate = $GLOBALS['db']->getRow("select id,name from " . DB_PREFIX . "taoxin_cate where id=(select pid from " . DB_PREFIX . "taoxin_cate where id=" . $v['cate_id'] . ")"); if (intval($pcate['id']) == 1) { // 如果已经是一级分类,请求自己作为一级分类 $pcate = $GLOBALS['db']->getRow("select id,name from " . DB_PREFIX . "taoxin_cate where id=" . $v['cate_id']); } $result['taoxin_list'][$i]['pcate_name'] = $pcate['name']; $result['taoxin_list'][$i]['pcate_id'] = strval($pcate['id']); } } $result['taoxin_count'] = $GLOBALS['db']->getOne($sql_count); } if (in_array("supplier", $s_type_arr)) { // 搜索商家 $sql = "select id,name from " . DB_PREFIX . "supplier where match(name_match) against('" . $ukeyword . "') and is_effect=1 limit " . $limit; $sql_count = "select count(*) from " . DB_PREFIX . "supplier where match(name_match) against('" . $ukeyword . "') and is_effect=1"; $result['supplier_list'] = $GLOBALS['db']->getAll($sql); $result['supplier_count'] = $GLOBALS['db']->getOne($sql_count); if (empty($result['supplier_list'])) { $result['supplier_list'] = array(); } } if (in_array("location", $s_type_arr)) { //搜索未认证商家,即网络商家 $sql = "select id,name from " . DB_PREFIX . "supplier_location where match(name_match) against('" . $ukeyword . "') and is_verify=0 and is_effect=1 limit " . $limit; $sql_count = "select count(*) from " . DB_PREFIX . "supplier_location where match(name_match) against('" . $ukeyword . "') and is_verify=0 and is_effect=1"; $result['location_list'] = $GLOBALS['db']->getAll($sql); $result['location_count'] = $GLOBALS['db']->getOne($sql_count); if (empty($result['location_list'])) { $result['location_list'] = array(); } } if (in_array("event", $s_type_arr)) { // 搜索活动 $sql = "select id,name,address,icon from " . DB_PREFIX . "event where match(`locate_match`,`cate_match`,`name_match`) against('" . $ukeyword . "') and is_effect=1 limit " . $limit; $sql_count = "select count(*) from " . DB_PREFIX . "event where match(`locate_match`,`cate_match`,`name_match`) against('" . $ukeyword . "') and is_effect=1"; $result['event_list'] = $GLOBALS['db']->getAll($sql); $result['event_count'] = $GLOBALS['db']->getOne($sql_count); if (empty($result['event_list'])) { $result['event_list'] = array(); } } $result['ret'] = '0'; array_recursive($result, 'strval', true); //file_put_contents("/tmp/xiao.log", "\n result ".json_encode($result)."\n",FILE_APPEND); echo json_encode($result); } }