Example #1
0
 public function load($param)
 {
     $param = array("cid" => $param['cid']);
     $key = $this->build_key(__CLASS__, $param);
     $GLOBALS['cache']->set_dir(APP_ROOT_PATH . "public/runtime/data/" . __CLASS__ . "/");
     $key_result = $GLOBALS['cache']->get($key);
     if ($key_result === false) {
         $param['cid'] = intval($GLOBALS['db']->getOne("select id from " . DB_PREFIX . "shop_cate where id = " . intval($param['cid'])));
         $key = $this->build_key(__CLASS__, $param);
         $GLOBALS['cache']->set_dir(APP_ROOT_PATH . "public/runtime/data/" . __CLASS__ . "/");
         $key_result = $GLOBALS['cache']->get($key);
         if ($key_result !== false) {
             return $key_result;
         }
         $cate_id = $param['cid'];
         require_once APP_ROOT_PATH . "system/utils/child.php";
         $ids_util = new child("shop_cate");
         $ids = $ids_util->getChildIds($cate_id);
         $ids[] = $cate_id;
         $deal_cate = $GLOBALS['db']->getAll("select name from " . DB_PREFIX . "shop_cate where id in (" . implode(",", $ids) . ") and is_effect = 1 and is_delete = 0");
         foreach ($deal_cate as $k => $item) {
             $name_words = div_str($item['name']);
             foreach ($name_words as $kk => $vv) {
                 $kw[] = str_to_unicode_string($vv);
             }
         }
         $key_result = implode(" ", $kw);
         $GLOBALS['cache']->set_dir(APP_ROOT_PATH . "public/runtime/data/" . __CLASS__ . "/");
         $GLOBALS['cache']->set($key, $key_result);
     }
     return $key_result;
 }
Example #2
0
 public function index()
 {
     //输出团购城市
     $city_list = M("DealCity")->where('is_delete = 0')->findAll();
     $city_list = D("DealCity")->toFormatTree($city_list, 'name');
     $this->assign("city_list", $city_list);
     //分类
     $cate_tree = M("DealCate")->where('is_delete = 0')->findAll();
     $cate_tree = D("DealCate")->toFormatTree($cate_tree, 'name');
     $this->assign("cate_tree", $cate_tree);
     //开始加载搜索条件
     if (intval($_REQUEST['id']) > 0) {
         $map['id'] = intval($_REQUEST['id']);
     }
     $map['is_delete'] = 0;
     if (strim($_REQUEST['name']) != '') {
         $map['name'] = array('like', '%' . strim($_REQUEST['name']) . '%');
     }
     if (intval($_REQUEST['city_id']) > 0) {
         require_once APP_ROOT_PATH . "system/utils/child.php";
         $child = new Child("deal_city");
         $city_ids = $child->getChildIds(intval($_REQUEST['city_id']));
         $city_ids[] = intval($_REQUEST['city_id']);
         $map['city_id'] = array("in", $city_ids);
     }
     if (intval($_REQUEST['cate_id']) > 0) {
         require_once APP_ROOT_PATH . "system/utils/child.php";
         $child = new Child("deal_cate");
         $cate_ids = $child->getChildIds(intval($_REQUEST['cate_id']));
         $cate_ids[] = intval($_REQUEST['cate_id']);
         $map['cate_id'] = array("in", $cate_ids);
     }
     if (strim($_REQUEST['supplier_name']) != '') {
         if (intval($GLOBALS['db']->getOne("select count(*) from " . DB_PREFIX . "supplier")) < 50000) {
             $sql = "select group_concat(id) from " . DB_PREFIX . "supplier where name like '%" . strim($_REQUEST['supplier_name']) . "%'";
         } else {
             $kws_div = div_str(trim($_REQUEST['supplier_name']));
             foreach ($kws_div as $k => $item) {
                 $kw[$k] = str_to_unicode_string($item);
             }
             $kw_unicode = implode(" ", $kw);
             $sql = "select group_concat(id) from " . DB_PREFIX . "supplier where (match(name_match) against('" . $kw_unicode . "' IN BOOLEAN MODE))";
         }
         $ids = $GLOBALS['db']->getOne($sql);
         $map['supplier_id'] = array("in", $ids);
     }
     $map['publish_wait'] = 0;
     $map['is_shop'] = 0;
     if (method_exists($this, '_filter')) {
         $this->_filter($map);
     }
     $name = $this->getActionName();
     $model = D($name);
     if (!empty($model)) {
         $this->_list($model, $map);
     }
     $this->display();
     return;
 }
 public function index()
 {
     $page_idx = intval($_REQUEST['p']) == 0 ? 1 : intval($_REQUEST['p']);
     $page_size = C('PAGE_LISTROWS');
     $limit = ($page_idx - 1) * $page_size . "," . $page_size;
     if (isset($_REQUEST['_order'])) {
         $order = $_REQUEST['_order'];
     }
     //排序方式默认按照倒序排列
     //接受 sost参数 0 表示倒序 非0都 表示正序
     if (isset($_REQUEST['_sort'])) {
         $sort = $_REQUEST['_sort'] ? 'asc' : 'desc';
     } else {
         $sort = 'desc';
     }
     if (isset($order)) {
         $orderby = "order by " . $order . " " . $sort;
     } else {
         $orderby = "";
     }
     if (trim($_REQUEST['name']) != '') {
         $total = $GLOBALS['db']->getOne("select count(*) from " . DB_PREFIX . "supplier");
         if ($total < 50000) {
             $list = $GLOBALS['db']->getAll("select * from " . DB_PREFIX . "supplier where name like '%" . trim($_REQUEST['name']) . "%'  {$orderby} limit " . $limit);
             $total = $GLOBALS['db']->getOne("select count(*) from " . DB_PREFIX . "supplier where name like '%" . trim($_REQUEST['name']) . "%'");
         } else {
             $kws_div = div_str(trim($_REQUEST['name']));
             foreach ($kws_div as $k => $item) {
                 $kw[$k] = str_to_unicode_string($item);
             }
             $kw_unicode = implode(" ", $kw);
             $list = $GLOBALS['db']->getAll("select * from " . DB_PREFIX . "supplier where match(`name_match`) against('" . $kw_unicode . "' IN BOOLEAN MODE)  {$orderby} limit " . $limit);
             $total = $GLOBALS['db']->getOne("select * from " . DB_PREFIX . "supplier where match(`name_match`) against('" . $kw_unicode . "' IN BOOLEAN MODE)");
         }
     } else {
         $list = $GLOBALS['db']->getAll("select * from " . DB_PREFIX . "supplier  {$orderby} limit " . $limit);
         $total = $GLOBALS['db']->getOne("select count(*) from " . DB_PREFIX . "supplier");
     }
     $p = new Page($total, '');
     $page = $p->show();
     $sortImg = $sort;
     //排序图标
     $sortAlt = $sort == 'desc' ? l("ASC_SORT") : l("DESC_SORT");
     //排序提示
     $sort = $sort == 'desc' ? 1 : 0;
     //排序方式
     //模板赋值显示
     $this->assign('sort', $sort);
     $this->assign('order', $order);
     $this->assign('sortImg', $sortImg);
     $this->assign('sortType', $sortAlt);
     $this->assign('list', $list);
     $this->assign("page", $page);
     $this->assign("nowPage", $p->nowPage);
     $this->display();
     return;
 }
 public function index()
 {
     require_once APP_ROOT_PATH . 'app/Lib/shop_lib.php';
     $catalog_id = intval($GLOBALS['request']['catalog_id']);
     //商品分类ID
     $city_id = intval($GLOBALS['request']['city_id']);
     //城市分类ID
     $page = intval($GLOBALS['request']['page']);
     //分页
     $keyword = strim($GLOBALS['request']['keyword']);
     $page = $page == 0 ? 1 : $page;
     $page_size = PAGE_SIZE;
     $limit = ($page - 1) * $page_size . "," . $page_size;
     $condition = " deal_type = 0 ";
     if ($keyword) {
         $kws_div = div_str($keyword);
         foreach ($kws_div as $k => $item) {
             $kws[$k] = str_to_unicode_string($item);
         }
         $ukeyword = implode(" ", $kws);
         $condition .= " and  (match(tag_match,name_match,locate_match,shop_cate_match) against('" . $ukeyword . "' IN BOOLEAN MODE) or name like '%" . $keyword . "%')";
     }
     $merchant_id = intval($GLOBALS['request']['merchant_id']);
     if ($merchant_id > 0) {
         $deal_ids = $GLOBALS['db']->getOne("select group_concat(deal_id) from " . DB_PREFIX . "deal_location_link where location_id = " . $merchant_id);
         if ($deal_ids) {
             $condition .= " and id in (" . $deal_ids . ") ";
         }
     }
     $deals = get_goods_list($limit, $catalog_id, $condition, "sort desc,id desc", false, $city_id);
     $list = $deals['list'];
     $count = $deals['count'];
     $page_total = ceil($count / $page_size);
     $root = array();
     $root['return'] = 1;
     $goodses = array();
     foreach ($list as $item) {
         //$goods = array();
         $goods = getGoodsArray($item);
         $goodses[] = $goods;
     }
     $root['item'] = $goodses;
     $root['page'] = array("page" => $page, "page_total" => $page_total);
     output($root);
 }
Example #5
0
function syn_deal($deal_id)
{
    $deal_info = $GLOBALS['db']->getRow("select * from " . DB_PREFIX . "crowd where id = " . $deal_id);
    if ($deal_info) {
        $deal_info['comment_count'] = intval($GLOBALS['db']->getOne("select count(*) from " . DB_PREFIX . "crowd_comment where deal_id = " . $deal_info['id'] . " and log_id = 0"));
        $deal_info['support_count'] = intval($GLOBALS['db']->getOne("select count(*) from " . DB_PREFIX . "crowd_support_log where deal_id = " . $deal_info['id']));
        $deal_info['focus_count'] = intval($GLOBALS['db']->getOne("select count(*) from " . DB_PREFIX . "crowd_focus_log where deal_id = " . $deal_info['id']));
        $deal_info['view_count'] = intval($GLOBALS['db']->getOne("select count(*) from " . DB_PREFIX . "crowd_visit_log where deal_id = " . $deal_info['id']));
        $deal_info['support_amount'] = doubleval($GLOBALS['db']->getOne("select sum(price) from " . DB_PREFIX . "crowd_support_log where deal_id = " . $deal_info['id']));
        $deal_info['delivery_fee_amount'] = doubleval($GLOBALS['db']->getOne("select sum(delivery_fee) from " . DB_PREFIX . "crowd_order where deal_id = " . $deal_info['id'] . " and order_status=3 "));
        if ($deal_info['type'] == 0) {
            $deal_info["virtual_num"] = $GLOBALS['db']->getOne("select sum(virtual_person) from " . DB_PREFIX . "crowd_item where deal_id=" . $deal_id);
            $deal_info["virtual_price"] = $GLOBALS['db']->getOne("select sum(virtual_person*price) from " . DB_PREFIX . "crowd_item where deal_id=" . $deal_id);
            if ($deal_info['support_amount'] + $deal_info["virtual_price"] >= $deal_info['limit_price']) {
                $deal_info['is_success'] = 1;
            } else {
                $deal_info['is_success'] = 0;
            }
        } elseif ($deal_info['type'] == 1) {
        }
        if ($deal_info['pay_radio'] > 0) {
            $deal_info['pay_amount'] = $deal_info['support_amount'] * (1 - $deal_info['pay_radio']) + $deal_info['delivery_fee_amount'];
        } else {
            $deal_info['pay_amount'] = $deal_info['support_amount'] * (1 - app_conf("PAY_RADIO")) + $deal_info['delivery_fee_amount'];
        }
        $deal_info['tags_match'] = "";
        $deal_info['tags_match_row'] = "";
        $GLOBALS['db']->autoExecute(DB_PREFIX . "crowd", $deal_info, $mode = 'UPDATE', "id=" . $deal_info['id'], $querymode = 'SILENT');
        $tags_arr = preg_split("/[, ]/", $deal_info["tags"]);
        foreach ($tags_arr as $tgs) {
            if (trim($tgs) != "") {
                insert_match_item(trim($tgs), "crowd", $deal_info['id'], "tags_match");
            }
        }
        $name_arr = div_str($deal_info['name']);
        foreach ($name_arr as $name_item) {
            if (trim($name_item) != "") {
                insert_match_item(trim($name_item), "crowd", $deal_info['id'], "name_match");
            }
        }
    }
}
 public function index()
 {
     $page = intval($GLOBALS['request']['page']);
     if ($page == 0) {
         $page = 1;
     }
     $cate_id = intval($GLOBALS['request']['cate_id']);
     $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
     $ypoint = $m_latitude = doubleval($GLOBALS['request']['m_latitude']);
     //ypoint
     $xpoint = $m_longitude = doubleval($GLOBALS['request']['m_longitude']);
     //xpoint
     $keyword = strim($GLOBALS['request']['keyword']);
     if ($xpoint > 0) {
         $pi = 3.14159265;
         //圆周率
         $r = 6378137;
         //地球平均半径(米)
         $field_append = ", (ACOS(SIN(({$ypoint} * {$pi}) / 180 ) *SIN((ypoint * {$pi}) / 180 ) +COS(({$ypoint} * {$pi}) / 180 ) * COS((ypoint * {$pi}) / 180 ) *COS(({$xpoint} * {$pi}) / 180 - (xpoint * {$pi}) / 180 ) ) * {$r}) as distance ";
         if ($ybottom != 0 && $ytop != 0 && $xleft != 0 && $xright != 0) {
             $where = " ypoint > {$ybottom} and ypoint < {$ytop} and xpoint > {$xleft} and xpoint < {$xright} ";
         }
         $order = " distance asc ";
     } else {
         $field_append = $where = $order = "";
     }
     $limit = ($page - 1) * PAGE_SIZE . "," . PAGE_SIZE;
     if ($keyword) {
         $kws_div = div_str($keyword);
         foreach ($kws_div as $k => $item) {
             $kw[$k] = str_to_unicode_string($item);
         }
         $ukeyword = implode(" ", $kw);
         $where .= " (match(name_match) against('" . $ukeyword . "'  IN BOOLEAN MODE)  or name like '%" . $keyword . "%') ";
     }
     $res = m_search_event_list($limit, $cate_id, $city_id, $where, $order, $field_append);
     $pattern = "/<img([^>]*)\\/>/i";
     $replacement = "<img width=300 \$1 />";
     foreach ($res['list'] as $k => $v) {
         if ($v['ypoint'] == '') {
             $res['list'][$k]['ypoint'] = 0;
         }
         if ($v['xpoint'] == '') {
             $res['list'][$k]['xpoint'] = 0;
         }
         $res['list'][$k]['icon'] = get_abs_img_root($v['icon']);
         $res['list'][$k]['distance'] = round($v['distance']);
         $res['list'][$k]['date_time'] = pass_date($v['submit_begin_time']);
         $res['list'][$k]['content'] = preg_replace($pattern, $replacement, get_abs_img_root($v['content']));
     }
     $root = array();
     $root['return'] = 1;
     $root['item'] = $res['list'];
     $root['page'] = array("page" => $page, "page_total" => ceil($res['count'] / PAGE_SIZE));
     output($root);
 }
Example #7
0
 public function index()
 {
     $cid = intval($GLOBALS['request']['cid']);
     $keyword = addslashes($GLOBALS['request']['tag']);
     $is_hot = intval($GLOBALS['request']['is_hot']);
     $is_new = intval($GLOBALS['request']['is_new']);
     $page = intval($GLOBALS['request']['page']) > 0 ? intval($GLOBALS['request']['page']) : 1;
     $page_size = 20;
     $limit = ($page - 1) * $page_size . "," . $page_size;
     $root = array();
     $root['return'] = 1;
     $root['tag'] = $tag;
     $root['cid'] = $cid;
     $condition = " 1 = 1 ";
     $sort = "";
     if ($is_hot > 0) {
         $condition .= " and t.is_recommend = 1 and t.has_image = 1 ";
         $sort .= " order by  t.click_count desc,t.id desc  ";
     }
     if ($is_new > 0) {
         $condition .= " and t.has_image = 1 ";
         $sort .= " order by t.create_time desc,t.id desc  ";
     }
     if ($cid > 0) {
         $condition .= " and l.cate_id = " . $cid;
     }
     if ($keyword) {
         $kws_div = div_str($keyword);
         foreach ($kws_div as $k => $item) {
             $kw[$k] = str_to_unicode_string($item);
         }
         $ukeyword = implode(" ", $kw);
         $condition .= " and match(t.keyword_match) against('" . $ukeyword . "'  IN BOOLEAN MODE) ";
     }
     $sql = "select distinct(t.id) from " . DB_PREFIX . "topic as t left join " . DB_PREFIX . "topic_cate_link as l on l.topic_id = t.id where " . $condition . $sort . " limit " . $limit;
     $sql_total = "select count(distinct(t.id)) from " . DB_PREFIX . "topic as t left join " . DB_PREFIX . "topic_cate_link as l on l.topic_id = t.id where " . $condition;
     $total = $GLOBALS['db']->getOne($sql_total);
     $result = $GLOBALS['db']->getAll($sql);
     $share_list = array();
     foreach ($result as $k => $v) {
         $share_list[$k]['share_id'] = $v['id'];
         $image = $GLOBALS['db']->getRow("select * from " . DB_PREFIX . "topic_image where topic_id = " . $v['id'] . " limit 1");
         if ($image['o_path']) {
             $share_list[$k]['img'] = get_abs_img_root(get_spec_image($image['o_path'], 200, 0, 0));
         } else {
             unset($share_list[$k]);
         }
         $share_list[$k]['height'] = floor($image['height'] * (200 / $image['width']));
         $share_list[$k]['width'] = 200;
     }
     $root['item'] = array_values($share_list);
     //分页
     $page_info['page'] = $page;
     $page_info['page_total'] = ceil($total / $page_size);
     $page_info['page_size'] = $page_size;
     $root['page'] = $page_info;
     //广告
     if ($page == 1) {
         $adv_list = $GLOBALS['cache']->get("MOBILE_SHARELIST_ADVS_" . intval($GLOBALS['city_id']));
         if ($adv_list === false) {
             $advs = $GLOBALS['db']->getAll(" select * from " . DB_PREFIX . "m_adv where page = 'sharelist' and city_id in (0," . intval($GLOBALS['city_id']) . ") and status = 1 order by sort desc ");
             $adv_list = array();
             foreach ($advs as $k => $v) {
                 $adv_list[$k]['id'] = $v['id'];
                 $adv_list[$k]['name'] = $v['name'];
                 $adv_list[$k]['img'] = get_abs_img_root(get_spec_image($v['img'], 640, 100, 1));
                 $adv_list[$k]['type'] = $v['type'];
                 $adv_list[$k]['data'] = $v['data'] = unserialize($v['data']);
                 if ($v['type'] == 1) {
                     $tag_count = count($v['data']['tags']);
                     $adv_list[$k]['data']['count'] = $tag_count;
                 }
                 if (in_array($v['type'], array(9, 10, 11, 12, 13))) {
                     if ($v['type'] == 9 || $v['type'] == 12 || $v['type'] == 13) {
                         $adv_list[$k]['data']['cate_name'] = $GLOBALS['db']->getOne("select name from " . DB_PREFIX . "deal_cate where id = " . intval($v['data']['cate_id']));
                     } elseif ($v['type'] == 10) {
                         $adv_list[$k]['data']['cate_name'] = $GLOBALS['db']->getOne("select name from " . DB_PREFIX . "shop_cate where id = " . intval($v['data']['cate_id']));
                     } elseif ($v['type'] == 11) {
                         $adv_list[$k]['data']['cate_name'] = $GLOBALS['db']->getOne("select name from " . DB_PREFIX . "event_cate where id = " . intval($v['data']['cate_id']));
                     }
                     $adv_list[$k]['data']['cate_name'] = $adv_list[$k]['data']['cate_name'] ? $adv_list[$k]['data']['cate_name'] : "全部";
                 }
             }
             $GLOBALS['cache']->set("MOBILE_SHARELIST_ADVS_" . intval($GLOBALS['city_id']), $adv_list);
         }
         $root['advs'] = $adv_list;
     }
     output($root);
 }
Example #8
0
 public function deals()
 {
     $r = strim($_REQUEST['r']);
     //推荐类型
     $param['r'] = $r ? $r : '';
     $id = intval($_REQUEST['id']);
     //分类id
     $param['id'] = $id;
     $loc = strim($_REQUEST['loc']);
     //地区
     $param['loc'] = $loc;
     $tag = strim($_REQUEST['tag']);
     //标签
     $param['tag'] = $tag;
     $type = intval($_REQUEST['type']);
     //类型
     $param['type'] = $type;
     $kw = strim($_REQUEST['k']);
     //关键词
     $param['tag'] = $tag;
     $state = intval($_REQUEST['state']);
     //状态
     $param['state'] = $state;
     $step = intval($_REQUEST['step']);
     $param['step'] = $step;
     //融资金额
     $price = intval($_REQUEST['price']);
     if ($price > 0) {
         $param['price'] = $price;
         //$GLOBALS['tmpl']->assign("price",$price);
     }
     //关注数
     $focus = intval($_REQUEST['focus']);
     if ($focus > 0) {
         $param['focus'] = $focus;
         //$GLOBALS['tmpl']->assign("focus",$focus);
     }
     //剩余时间
     $time = intval($_REQUEST['time']);
     if ($time > 0) {
         $param['time'] = $time;
         //$GLOBALS['tmpl']->assign("time",$time);
     }
     //完成比例
     $cp = intval($_REQUEST['cp']);
     if ($cp > 0) {
         $param['cp'] = $cp;
         //$GLOBALS['tmpl']->assign("cp",$cp);
     }
     $page_size = DEAL_PAGE_SIZE;
     $step_size = DEAL_STEP_SIZE;
     if ($step == 0) {
         $step = 1;
     }
     $page = intval($_REQUEST['p']);
     if ($page == 0) {
         $page = 1;
     }
     $limit = ($page - 1) * $page_size + ($step - 1) * $step_size . "," . $step_size;
     $condition = " d.is_delete = 0 and d.is_effect = 1 ";
     if ($r != "") {
         if ($r == "new") {
             $condition .= " and " . NOW_TIME . " - d.begin_time < " . 7 * 24 * 3600 . " and " . NOW_TIME . " - d.begin_time > 0 ";
             //上线不超过一天
         } elseif ($r == "rec") {
             $condition .= "  and d.is_recommend = 1 ";
         } elseif ($r == "yure") {
             $condition .= "   and " . NOW_TIME . " <  d.begin_time ";
         } elseif ($r == "nend") {
             $condition .= " and d.end_time - " . NOW_TIME . " < " . 7 * 24 * 3600 . " and d.end_time - " . NOW_TIME . " > 0 ";
             //三天就要结束
         } elseif ($r == "classic") {
             $condition .= " and d.is_classic = 1 ";
         } elseif ($r == "limit_price") {
             $condition .= " and max(d.limit_price) ";
         }
     }
     switch ($state) {
         //筹资成功
         case 1:
             $condition .= " and d.is_success=1  and d.end_time < " . NOW_TIME;
             $GLOBALS['tmpl']->assign("page_title", "筹资成功");
             break;
             //筹资失败
         //筹资失败
         case 2:
             $condition .= " and d.end_time < " . NOW_TIME . " and d.end_time!=0  and d.is_success=0  ";
             $GLOBALS['tmpl']->assign("page_title", "筹资失败");
             break;
             //筹资中
         //筹资中
         case 3:
             $condition .= " and (d.end_time > " . NOW_TIME . " or d.end_time=0 ) and d.begin_time < " . NOW_TIME . "   ";
             $GLOBALS['tmpl']->assign("page_title", "筹资中");
             break;
     }
     $cate_list = load_dynamic_cache("INDEX_CATE_LIST");
     if (!$cate_list) {
         $cate_list = $GLOBALS['db']->getAll("select * from " . DB_PREFIX . "deal_cate order by sort asc");
         set_dynamic_cache("INDEX_CATE_LIST", $cate_list);
     }
     $cate_result = array();
     $kk = 0;
     foreach ($cate_list as $k => $v) {
         if ($v['pid'] == 0) {
             $temp_param = $param;
             $cate_result[$k + 1]['id'] = $v['id'];
             $cate_result[$k + 1]['name'] = $v['name'];
             $temp_param['id'] = $v['id'];
             $cate_result[$k + 1]['url'] = url("deals", $temp_param);
             $kk++;
         }
     }
     $GLOBALS['tmpl']->assign("cate_list", $cate_result);
     $pid = 0;
     //获取父类id
     if ($cate_list) {
         foreach ($cate_list as $k => $v) {
             if ($v['id'] == $id) {
                 if ($v['pid'] > 0) {
                     $pid = $v['pid'];
                 } else {
                     $pid = $id;
                 }
             }
         }
     }
     /*子分类 start*/
     $cate_ids = array();
     $is_has_child = false;
     $temp_cate_ids = array();
     if ($cate_list) {
         $child_cate_result = array();
         foreach ($cate_list as $k => $v) {
             if ($v['pid'] == $pid) {
                 if ($v['pid'] > 0) {
                     $temp_param = $param;
                     $child_cate_result[$v['id']]['id'] = $v['id'];
                     $child_cate_result[$v['id']]['name'] = $v['name'];
                     $temp_param['id'] = $v['id'];
                     $child_cate_result[$v['id']]['url'] = url("deals", $temp_param);
                     if ($v['id'] == $id) {
                         $is_has_child = true;
                     }
                 }
             }
             if ($v['pid'] == $pid || $pid == 0) {
                 $temp_cate_ids[] = $v['id'];
             }
         }
     }
     //假如选择了子类 那么使用子类ID  否则使用 父类和其子类
     if ($is_has_child) {
         $cate_ids[] = $id;
     } else {
         $cate_ids[] = $pid;
         $cate_ids = array_merge($cate_ids, $temp_cate_ids);
     }
     if (count($cate_ids) > 0) {
         $condition .= " and d.cate_id in (" . implode(",", $cate_ids) . ")";
     }
     if ($loc != "") {
         $condition .= " and (d.province = '" . $loc . "' or d.city = '" . $loc . "') ";
     }
     if ($tag != "") {
         $unicode_tag = str_to_unicode_string($tag);
         $condition .= " and match(d.tags_match) against('" . $unicode_tag . "'  IN BOOLEAN MODE) ";
     }
     if ($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.name_match) against('" . $ukeyword . "'  IN BOOLEAN MODE) or match(d.tags_match) against('" . $ukeyword . "'  IN BOOLEAN MODE)  or name like '%" . $kw . "%') ";
     }
     $condition .= " and d.type={$type} ";
     //		if($r=="new")
     //		{
     //			$orderby ="  d.begin_time desc ";
     //		}
     //		elseif($r=="rec")
     //		{
     //			$orderby.="   d.begin_time desc  ";
     //		}
     //        else
     //		{
     //			$orderby ="  sort asc ";
     //		}
     //========
     if ($price > 0) {
         if ($price == 1) {
             if ($type == 1) {
                 $orderby .= " d.invote_money desc";
             } else {
                 $orderby .= " (d.support_amount+d.virtual_price) desc";
             }
             $param_new['price'] = 2;
         } elseif ($price == 2) {
             if ($type == 1) {
                 $orderby .= " d.invote_money asc";
             } else {
                 $orderby .= " (d.support_amount+d.virtual_price) asc";
             }
             $param_new['price'] = 1;
         }
         $url_list['price_url'] = url("deals", $param_new);
     } elseif ($focus > 0) {
         if ($focus == 1) {
             $orderby .= " d.focus_count desc";
         } elseif ($focus == 2) {
             $orderby .= " d.focus_count asc";
         }
     } elseif ($time > 0) {
         if ($time == 1) {
             $orderby .= " d.end_time desc";
         } elseif ($time == 2) {
             $orderby .= " d.end_time asc";
         }
     } elseif ($cp > 0) {
         if ($cp == 1) {
             if ($type == 1) {
                 $orderby .= " d.invote_money/d.limit_price desc";
             } else {
                 $orderby .= " (d.support_amount+d.virtual_price)/d.limit_price desc";
             }
             $param_new['cp'] = 2;
         } else {
             if ($type == 1) {
                 $orderby .= " d.invote_money/d.limit_price asc";
             } else {
                 $orderby .= " (d.support_amount+d.virtual_price)/d.limit_price asc";
             }
             $param_new['cp'] = 1;
         }
         $url_list['cp_url'] = url("deals", $param_new);
     } else {
         $orderby = "  d.begin_time desc ";
     }
     // 		var_dump($limit);
     //		var_dump($condition);
     //		var_dump($orderby);
     $result = get_deal_list($limit, $condition, $orderby);
     $GLOBALS['tmpl']->assign("deal_list", $result['list']);
     $data['html'] = $GLOBALS['tmpl']->fetch("inc/deal_list.html");
     if ($step * $step_size < $page_size) {
         if ($result['rs_count'] <= ($page - 1) * $page_size + ($step - 1) * $step_size + $step_size) {
             $data['step'] = 0;
             ajax_return($data);
         } else {
             $data['step'] = $step + 1;
             ajax_return($data);
         }
     } else {
         $data['step'] = 0;
         ajax_return($data);
     }
 }
Example #9
0
 public function index()
 {
     $page = intval($GLOBALS['request']['page']);
     if ($page == 0) {
         $page = 1;
     }
     $cate_id = intval($GLOBALS['request']['cate_id']);
     $city_id = intval($GLOBALS['request']['city_id']);
     $city_name = strim($GLOBALS['request']['city_name']);
     //城市名称
     $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
     if ($GLOBALS['request']['from'] == "wap") {
         /*输出分类*/
         $bigcate_list = $GLOBALS['db']->getAll("select id,name from " . DB_PREFIX . "event_cate where is_effect=1 order by sort");
         /*输出商圈*/
         $all_quan_list = $GLOBALS['db']->getAll("select * from " . DB_PREFIX . "area where city_id=" . $city_id . "");
         $quan_list = array();
         $quan_sub_list = array();
         $quan_list[0]['id'] = 0;
         $quan_list[0]['name'] = '全城';
         $quan_list[0]['quan_sub'][0]['id'] = 0;
         $quan_list[0]['quan_sub'][0]['pid'] = 0;
         $quan_list[0]['quan_sub'][0]['name'] = '全城';
         foreach ($all_quan_list as $k => $v) {
             if ($v['pid'] == 0) {
                 $quan_list[] = $v;
             }
             if ($v['pid'] > 0) {
                 $quan_sub_list[$v['pid']][] = $v;
             }
         }
         foreach ($quan_list as $k => $v) {
             if ($v['name'] != "全城") {
                 if ($quan_sub_list[$v['id']] == null || $quan_sub_list[$v['id']] == '') {
                     $quan_list[$k]['quan_sub'] = array();
                 } else {
                     $quan_list[$k]['quan_sub'] = $quan_sub_list[$v['id']];
                 }
             }
         }
         $root[quan_list] = $quan_list;
     }
     $keyword = strim($GLOBALS['request']['keyword']);
     if ($xpoint > 0) {
         $pi = 3.14159265;
         //圆周率
         $r = 6378137;
         //地球平均半径(米)
         $field_append = ", (ACOS(SIN(({$ypoint} * {$pi}) / 180 ) *SIN((ypoint * {$pi}) / 180 ) +COS(({$ypoint} * {$pi}) / 180 ) * COS((ypoint * {$pi}) / 180 ) *COS(({$xpoint} * {$pi}) / 180 - (xpoint * {$pi}) / 180 ) ) * {$r}) as distance ";
         if ($ybottom != 0 && $ytop != 0 && $xleft != 0 && $xright != 0) {
             $where = " ypoint > {$ybottom} and ypoint < {$ytop} and xpoint > {$xleft} and xpoint < {$xright} ";
         }
         $order = " distance asc,is_recommend desc,sort desc,id desc";
     } else {
         $field_append = $where = $order = "";
     }
     $limit = ($page - 1) * PAGE_SIZE . "," . PAGE_SIZE;
     if ($keyword) {
         $kws_div = div_str($keyword);
         foreach ($kws_div as $k => $item) {
             $kw[$k] = str_to_unicode_string($item);
         }
         $ukeyword = implode(" ", $kw);
         $where .= " (match(name_match) against('" . $ukeyword . "'  IN BOOLEAN MODE)  or name like '%" . $keyword . "%') ";
     }
     $res = m_search_event_list($limit, $cate_id, $city_id, $where, $order, $field_append);
     $pattern = "/<img([^>]*)\\/>/i";
     $replacement = "<img width=300 \$1 />";
     foreach ($res['list'] as $k => $v) {
         if ($v['ypoint'] == '') {
             $res['list'][$k]['ypoint'] = 0;
         }
         if ($v['xpoint'] == '') {
             $res['list'][$k]['xpoint'] = 0;
         }
         $res['list'][$k]['icon'] = get_abs_img_root(get_spec_image($v['icon'], 140, 85, 0));
         $res['list'][$k]['distance'] = round($v['distance']);
         $res['list'][$k]['date_time'] = pass_date($v['submit_begin_time']);
         $res['list'][$k]['event_begin_time'] = to_date($v['event_begin_time'], 'Y-m-d');
         $res['list'][$k]['event_end_time'] = to_date($v['event_end_time'], 'Y-m-d');
         $res['list'][$k]['submit_end_time'] = to_date($v['submit_end_time'], 'Y-m-d');
         $res['list'][$k]['submit_begin_time'] = to_date($v['submit_begin_time'], 'Y-m-d');
         $res['list'][$k]['content'] = preg_replace($pattern, $replacement, get_abs_img_root($v['content']));
     }
     $root = array();
     $root['bigcate_list'] = $bigcate_list;
     $root['return'] = 1;
     $root['item'] = $res['list'];
     $root['page'] = array("page" => $page, "page_total" => ceil($res['count'] / PAGE_SIZE), "page_size" => PAGE_SIZE);
     $root['page_title'] = "活动列表";
     $root['city_name'] = $city_name;
     output($root);
 }
Example #10
0
 public function index()
 {
     require_once APP_ROOT_PATH . 'system/model/deal.php';
     $root = array();
     $root['return'] = 1;
     $catalog_id = intval($GLOBALS['request']['catalog_id']);
     //商品分类ID
     $cata_type_id = intval($GLOBALS['request']['cata_type_id']);
     //商品二级分类
     $city_id = intval($GLOBALS['request']['city_id']);
     //城市分类ID
     $page = intval($GLOBALS['request']['page']);
     //分页
     $keyword = strim($GLOBALS['request']['keyword']);
     $city_name = strim($GLOBALS['request']['city_name']);
     //城市名称
     //print_r($GLOBALS['request']);
     $order_type = strim($GLOBALS['request']['order_type']);
     $quan_id = intval($GLOBALS['request']['quan_id']);
     //商圈id
     if ($cata_type_id > 0) {
         $catalog_id = $cata_type_id;
     }
     if ($order_type == 'buy_count') {
         $marked_tag = 1;
     } elseif ($order_type == 'price_desc') {
         $marked_tag = 2;
     } elseif ($order_type == 'newest') {
         $marked_tag = 3;
     } else {
         $marked_tag = 1;
     }
     $root['marked_tag'] = $marked_tag;
     /*输出分类*/
     $bcate_list = getShopcateList();
     $url_param['quan_id'] = $quan_id;
     $url_param['catalog_id'] = $catalog_id;
     foreach ($bcate_list as $k => $v) {
         if ($catalog_id == $v['id']) {
             $bcate_list[$k]['marked_tag'] = 1;
         }
         /*
         if($catalog_id==$v['id'])
         {
         	$bcate_list['bcate_type'][$k]['act'] = 1;
         }
         */
         $tmp_url_param = $url_param;
         unset($tmp_url_param['catalog_id']);
         $tmp_url_param['catalog_id'] = $v['id'];
         $tmp_url_param['catename'] = $v['name'];
         if ($quan_id > 0) {
             $quanname = $GLOBALS['db']->getOne("select name from " . DB_PREFIX . "area  where id=" . $quan_id);
             $tmp_url_param['quanname'] = $quanname;
         } else {
             $tmp_url_param['quanname'] = "全城";
         }
         $turl = wap_url("index", "goodslist", $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['catalog_id']);
             $tmp_url_param['catalog_id'] = $vv['id'];
             if ($bcate_list['bcate_type'][$kk]['id'] == $vv['id']) {
                 $tmp_url_param['catename'] = $v['name'];
             } else {
                 $tmp_url_param['catename'] = $vv['name'];
             }
             if ($quan_id > 0) {
                 $quanname = $GLOBALS['db']->getOne("select name from " . DB_PREFIX . "area a where id=" . $quan_id);
                 $tmp_url_param['quanname'] = $quanname;
             } else {
                 $tmp_url_param['quanname'] = "全城";
             }
             $turl = wap_url("index", "goodslist", $tmp_url_param);
             $url = str_replace('sjmapi', 'wap', $turl);
             $bcate_list[$k]["bcate_type"][$kk]["url"] = $url;
         }
     }
     //品牌列表
     if ($catalog_id > 0) {
         $cate_key = load_auto_cache("shop_cate_key", array("cid" => $catalog_id));
         $brand_list = $GLOBALS['db']->getAll("select id,name,sort,0 as city_id, from " . DB_PREFIX . "brand where match(tag_match) against('" . $cate_key . "' IN BOOLEAN MODE)  order by sort limit 100");
     } else {
         $brand_list = $GLOBALS['db']->getAll("select id,name,sort,0 as city_id from " . DB_PREFIX . "brand  order by sort limit 100");
     }
     $quan_list = array();
     $quan_list[0]['id'] = 0;
     $quan_list[0]['name'] = '全部品牌';
     /*
     $quan_list[0]['quan_sub'][0]['id']=0;
     $quan_list[0]['quan_sub'][0]['pid']=0;
     $quan_list[0]['quan_sub'][0]['name']='全部';
     */
     foreach ($brand_list as $k => $v) {
         $quan_list[] = $v;
     }
     foreach ($quan_list as $k => $v) {
         $tmp_url_param = $url_param;
         unset($tmp_url_param['quan_id']);
         $tmp_url_param['quan_id'] = $v['id'];
         $tmp_url_param['quanname'] = $v['name'];
         if ($catalog_id > 0) {
             $catename = $GLOBALS['db']->getOne("select name from " . DB_PREFIX . "shop_cate  where id=" . $catalog_id);
             $tmp_url_param['catename'] = $catename;
         } else {
             $tmp_url_param['catename'] = "全部分类";
         }
         $turl = wap_url("index", "goodslist", $tmp_url_param);
         $url = str_replace('sjmapi', 'wap', $turl);
         $quan_list[$k]["url"] = $url;
         $quan_list[$k]['quan_sub'][] = array('id' => $v['id'], 'pid' => $v['id'], 'name' => '全部');
     }
     $ordertype[] = array("name" => "默认排序", "sc" => "avg_point");
     $ordertype[] = array("name" => "最新发布", "sc" => "newest");
     $ordertype[] = array("name" => "销量最高", "sc" => "buy_count");
     $ordertype[] = array("name" => "价格最高", "sc" => "price_desc");
     $ordertype[] = array("name" => "价格最低", "sc" => "price_asc");
     foreach ($ordertype as $k => $v) {
         $tmp_url_param = $url_param;
         if ($quanname) {
             $tmp_url_param['quanname'] = $quanname;
         }
         if ($catename) {
             $tmp_url_param['catename'] = $catename;
         }
         if ($keyword) {
             $tmp_url_param['keyword'] = $keyword;
         }
         $tmp_url_param['order_type'] = $v['sc'];
         $turl = wap_url("index", "goodslist", $tmp_url_param);
         $url = str_replace('sjmapi', 'wap', $turl);
         $ordertype[$k]["url"] = $url;
     }
     $root['ordertype'] = $ordertype;
     /*排序*/
     if ($order_type == 'avg_point') {
         $order = " avg_point desc,id desc ";
     } elseif ($order_type == 'newest') {
         $order = " create_time desc,id desc ";
     } elseif ($order_type == 'buy_count') {
         $order = " buy_count desc,id desc ";
     } elseif ($order_type == 'price_asc') {
         $order = " current_price asc,id desc ";
     } elseif ($order_type == 'price_desc') {
         $order = " current_price desc,id desc ";
     } else {
         $order = "sort desc,id desc ";
     }
     $page = $page == 0 ? 1 : $page;
     $page_size = PAGE_SIZE;
     $limit = ($page - 1) * $page_size . "," . $page_size;
     //buy_type = 0 普通商品;1积分商品
     $condition = " buy_type = 0  and is_shop=1";
     if ($keyword) {
         $kws_div = div_str($keyword);
         foreach ($kws_div as $k => $item) {
             $kws[$k] = str_to_unicode_string($item);
         }
         $ukeyword = implode(" ", $kws);
         $condition .= " and  (match(tag_match,name_match,locate_match,shop_cate_match) against('" . $ukeyword . "' IN BOOLEAN MODE) or name like '%" . $keyword . "%')";
     }
     $merchant_id = intval($GLOBALS['request']['merchant_id']);
     if ($merchant_id > 0) {
         $deal_ids = $GLOBALS['db']->getOne("select group_concat(deal_id) from " . DB_PREFIX . "deal_location_link where location_id = " . $merchant_id);
         if ($deal_ids) {
             $condition .= " and id in (" . $deal_ids . ") ";
         } else {
             $condition .= " and id ='' ";
         }
     }
     //根据传入的商圈ID来搜索该商圈下的商品
     if ($quan_id > 0) {
         $condition .= " and brand_id = " . $quan_id;
     }
     //get_goods_list($limit,$type=array(DEAL_ONLINE,DEAL_HISTORY,DEAL_NOTICE),$param=array("cid"=>0,"city_id"=>0), $join='', $where='',$orderby = '')
     $deals = get_goods_list($limit, array(DEAL_ONLINE, DEAL_HISTORY), array("cid" => $catalog_id, "city_id" => $city_id), '', $condition, $order);
     $condition = $deals['condition'];
     $sql = "select count(*) from " . DB_PREFIX . "deal as d where  " . $condition;
     $count = $GLOBALS['db']->getOne($sql);
     $list = $deals['list'];
     $page_total = ceil($count / $page_size);
     $goodses = array();
     foreach ($list as $item) {
         //$goods = array();
         $goods = getGoodsArray($item);
         $goods['image'] = get_abs_img_root(get_spec_image($item['img'], 140, 85, 0));
         $goodses[] = $goods;
     }
     $root['item'] = $goodses;
     $root['page'] = array("page" => $page, "page_total" => $page_total, "page_size" => $page_size);
     //$root['quan_list'] = getCityList();
     /*
     //输出城市
     $root['city_list']=getCityList();
     //输出商圈
     $quan_list=getQuanList($city_id);
     $root['quan_list2'] = $quan_list;
     */
     //$root['bcate_list'] = $bcate_list;
     //$root['quan_list'] = $quan_list;
     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['page_title'] = "商品列表";
     $root['city_name'] = $city_name;
     output($root);
 }
 public function index()
 {
     $root = array();
     $page = intval($GLOBALS['request']['page']);
     // 分页
     $page = $page == 0 ? 1 : $page;
     $root['response_code'] = 1;
     $param = array();
     // 参数集合
     // 数据来源参数
     $r = strim($_REQUEST['r']);
     // 推荐类型
     $param['r'] = $r ? $r : '';
     $id = intval($_REQUEST['id']);
     // 分类id3
     $param['id'] = $id;
     // ios标志
     if ($id == 0) {
         $isAll = 1;
     } else {
         $isAll = 0;
     }
     $loc = strim($_REQUEST['loc']);
     // 地区
     $param['loc'] = $loc;
     $GLOBALS['tmpl']->assign("p_loc", $loc);
     $state = intval($_REQUEST['state']);
     // 状态1
     $param['state'] = $state;
     $tag = strim($_REQUEST['tag']);
     // 标签
     $param['tag'] = $tag;
     $GLOBALS['tmpl']->assign("p_tag", $tag);
     $kw = strim($_REQUEST['key']);
     // 关键词
     $param['kw'] = $kw;
     $cate_list = load_dynamic_cache("INDEX_CATE_LIST");
     if (!$cate_list) {
         $cate_list = $GLOBALS['db']->getAll("select * from " . DB_PREFIX . "deal_cate order by sort asc");
         set_dynamic_cache("INDEX_CATE_LIST", $cate_list);
     }
     $cate_result = array();
     $cate_result[0]['id'] = '0';
     $cate_result[0]['name'] = "全部";
     foreach ($cate_list as $k => $v) {
         $temp_param = $param;
         $cate_result[$k + 1]['id'] = $v['id'];
         $cate_result[$k + 1]['name'] = $v['name'];
         $temp_param['id'] = $v['id'];
     }
     $root['cate_list'] = $cate_result;
     $pid = 0;
     // 获取父类id
     if ($cate_list) {
         foreach ($cate_list as $k => $v) {
             if ($v['id'] == $id) {
                 if ($v['pid'] > 0) {
                     $pid = $v['pid'];
                 } else {
                     $pid = $id;
                 }
             }
         }
     }
     /* 子分类 start */
     $cate_ids = array();
     $is_has_child = false;
     $temp_cate_ids = array();
     if ($cate_list) {
         $child_cate_result = array();
         foreach ($cate_list as $k => $v) {
             if ($v['pid'] == $pid) {
                 if ($v['pid'] > 0) {
                     $temp_param = $param;
                     $child_cate_result[$v['id']]['id'] = $v['id'];
                     $child_cate_result[$v['id']]['name'] = $v['name'];
                     $temp_param['id'] = $v['id'];
                     $child_cate_result[$v['id']]['url'] = url_mapi("deals", $temp_param);
                     if ($v['id'] == $id) {
                         $is_has_child = true;
                     }
                 }
             }
             if ($v['pid'] == $pid || $pid == 0) {
                 $temp_cate_ids[] = $v['id'];
             }
         }
     }
     // 假如选择了子类 那么使用子类ID 否则使用 父类和其子类
     if ($is_has_child) {
         $cate_ids[] = $id;
     } else {
         $cate_ids[] = $pid;
         $cate_ids = array_merge($cate_ids, $temp_cate_ids);
     }
     $root['child_cate_list'] = $child_cate_result;
     $root['pid'] = $pid;
     /* 子分类 end */
     $city_list = load_dynamic_cache("INDEX_CITY_LIST");
     if (!$city_list) {
         $city_list = $GLOBALS['db']->getAll("select province from " . DB_PREFIX . "deal group by province order by sort asc");
         set_dynamic_cache("INDEX_CITY_LIST", $city_list);
     }
     foreach ($city_list as $k => $v) {
         $temp_param = $param;
         $temp_param['loc'] = $v['province'];
         $city_list[$k]['url'] = url_mapi("deals", $temp_param);
     }
     $root['city_list'] = $city_list;
     $state_list = array(0 => array("name" => "全部"), 1 => array("name" => "筹资成功"), 2 => array("name" => "筹资失败"), 3 => array("name" => "筹资中"));
     foreach ($state_list as $k => $v) {
         $temp_param = $param;
         $temp_param['state'] = $k;
         $state_list[$k]['url'] = url_mapi("deals", $temp_param);
     }
     $root['state_list'] = $state_list;
     $page_size = $GLOBALS['m_config']['page_size'];
     $page = intval($_REQUEST['p']);
     if ($page == 0) {
         $page = 1;
     }
     $limit = ($page - 1) * $page_size . "," . $page_size;
     $condition = " is_delete = 0 and is_effect = 1 ";
     if ($r != "") {
         if ($r == "new") {
             $condition .= " and " . NOW_TIME . " - begin_time < " . 24 * 3600 . " and " . NOW_TIME . " - begin_time > 0 ";
             // 上线不超过一天
             $GLOBALS['tmpl']->assign("page_title", "最新上线");
         }
         if ($r == "rec") {
             $condition .= " and " . NOW_TIME . " <= end_time AND " . NOW_TIME . " >= begin_time and is_recommend = 1 ";
             $GLOBALS['tmpl']->assign("page_title", "推荐项目");
         }
         if ($r == "yure") {
             $condition .= " and " . NOW_TIME . " - begin_time < " . 24 * 3600 . " and " . NOW_TIME . " - begin_time <  0 ";
             // 上线不超过一天
             $GLOBALS['tmpl']->assign("page_title", "正在预热");
         }
         if ($r == "nend") {
             $condition .= " and end_time - " . NOW_TIME . " < " . 24 * 3600 . " and end_time - " . NOW_TIME . " > 0 ";
             // 当天就要结束
             $GLOBALS['tmpl']->assign("page_title", "即将结束");
         }
         if ($r == "classic") {
             $condition .= " and is_classic = 1 ";
             $GLOBALS['tmpl']->assign("page_title", "经典项目");
         }
         if ($r == "limit_price") {
             $condition .= " and max(limit_price) ";
             $GLOBALS['tmpl']->assign("page_title", "最高目标金额");
         }
     }
     switch ($state) {
         // 筹资中
         case 0:
             $GLOBALS['tmpl']->assign("page_title", "全部");
             break;
             // 筹资成功
         // 筹资成功
         case 1:
             $condition .= " and end_time < " . NOW_TIME . "  and support_amount >= limit_price";
             $GLOBALS['tmpl']->assign("page_title", "筹资成功");
             break;
             // 筹资失败
         // 筹资失败
         case 2:
             $condition .= " and end_time < " . NOW_TIME . "  and  support_amount < limit_price ";
             $GLOBALS['tmpl']->assign("page_title", "筹资失败");
             break;
             // 筹资中
         // 筹资中
         case 3:
             $condition .= " and end_time > " . NOW_TIME . "  and begin_time < " . NOW_TIME . " ";
             $GLOBALS['tmpl']->assign("page_title", "筹资中");
             break;
     }
     if (count($cate_ids) > 0) {
         $condition .= " and cate_id in (" . implode(",", $cate_ids) . ")";
         $GLOBALS['tmpl']->assign("page_title", $cate_result[$id]['name']);
     }
     if ($loc != "") {
         $condition .= " and (province = '" . $loc . "' or city = '" . $loc . "') ";
         $GLOBALS['tmpl']->assign("page_title", $loc);
     }
     if ($tag != "") {
         $unicode_tag = str_to_unicode_string($tag);
         $condition .= " and match(tags_match) against('" . $unicode_tag . "'  IN BOOLEAN MODE) ";
         $GLOBALS['tmpl']->assign("page_title", $tag);
     }
     if ($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(name_match) against('" . $ukeyword . "'  IN BOOLEAN MODE) or match(tags_match) against('" . $ukeyword . "'  IN BOOLEAN MODE)  or name like '%" . $kw . "%') ";
         $GLOBALS['tmpl']->assign("page_title", $kw);
     }
     // 权限浏览控制
     if ($GLOBALS['user_info']['user_level'] != 0) {
         $condition .= " AND (user_level ='' or user_level=0 or user_level <=" . $GLOBALS['user_info']['user_level'] . ") ";
     } else {
         $condition .= " AND (user_level =0 or user_level =1 or user_level ='') ";
     }
     $deal_count = $GLOBALS['db']->getOne("select count(*) from " . DB_PREFIX . "deal where " . $condition);
     /* (所需项目)准备虚拟数据 start */
     $deal_list = array();
     if ($deal_count > 0) {
         $now_time = get_gmtime();
         // $deal_list = $GLOBALS['db']->getAll("select * from
         // ".DB_PREFIX."deal where ".$condition." order by sort asc ");
         $deal_list = $GLOBALS['db']->getAll("select * from " . DB_PREFIX . "deal where " . $condition . " order by sort asc limit " . $limit);
         $deal_ids = array();
         foreach ($deal_list as $k => $v) {
             // $deal_list['percent'] =
             // round($deal_list['support_amount']/$deal_list['limit_price']*100);
         }
         // 获取当前项目列表下的所有子项目
         $temp_virtual_person_list = $GLOBALS['db']->getAll("select deal_id,virtual_person,price from " . DB_PREFIX . "deal_item where deal_id in(" . implode(",", $deal_ids) . ") ");
         $virtual_person_list = array();
         // 重新组装一个以项目ID为KEY的 统计所有的虚拟人数和虚拟价格
         foreach ($temp_virtual_person_list as $k => $v) {
             $virtual_person_list[$v['deal_id']]['total_virtual_person'] += $v['virtual_person'];
             $virtual_person_list[$v['deal_id']]['total_virtual_price'] += $v['price'] * $v['virtual_person'];
         }
         unset($temp_virtual_person_list);
         // 将获取到的虚拟人数和虚拟价格拿到项目列表里面进行统计
         foreach ($deal_list as $k => $v) {
             $deal_list[$k]['virtual_person'] = $virtual_person_list[$v['id']]['total_virtual_person'];
             $deal_list[$k]['percent'] = round(($v['support_amount'] + $virtual_person_list[$v['id']]['total_virtual_price']) / $v['limit_price'] * 100);
             $deal_list[$k]['support_count'] += $deal_list[$k]['virtual_person'];
             $deal_list[$k]['support_amount'] += $virtual_person_list[$v['id']]['total_virtual_price'];
             /*
              *
              * $deal_list[$k]['description']=get_abs_img_root(get_spec_image($v['description'],640,240,1));
              * $deal_list[$k]['content']=get_abs_img_root(get_spec_image($v['description'],640,240,1));
              * $deal_list[$k]['content_1']=get_abs_img_root(get_spec_image($v['description_1'],640,240,1));
              * $deal_list[$k]['deal_extra_cache']=null;
              */
             $deal_list[$k]['image'] = get_abs_img_root(get_spec_image($v['image'], 640, 240, 1));
             if ($v['end_time'] > 0 && $v['end_time'] > $now_time) {
                 $deal_list[$k]['remain_days'] = floor(($v['end_time'] - $now_time) / (24 * 3600));
             } elseif ($v['end_time'] > 0 && $v['end_time'] <= $now_time) {
                 $deal_list[$k]['remain_days'] = 0;
             }
             if ($v['begin_time'] > $now_time) {
                 $deal_list[$k]['left_days'] = intval(($now_time - $v['create_time']) / 24 / 3600);
             } else {
                 $deal_list[$k]['left_days'] = 0;
             }
             $deal_list[$k]['num_days'] = floor(($v['end_time'] - $v['begin_time']) / (24 * 3600));
             // $deal_list[$k]['status']值0表示即将开始;1表示已成功;2表示筹资失败;3表示筹资中;4表示长期项目
             if ($v['begin_time'] > $now_time) {
                 $deal_list[$k]['status'] = '0';
             } elseif ($v['end_time'] < $now_time && $v['end_time'] > 0) {
                 if ($deal_list[$k]['percent'] >= 100) {
                     $deal_list[$k]['status'] = '1';
                 } else {
                     if ($deal_list[$k]['percent'] >= 0) {
                         $deal_list[$k]['status'] = '2';
                     }
                 }
             } else {
                 if ($v['end_time'] > 0) {
                     if ($deal_list[$k]['percent'] >= 100) {
                         $deal_list[$k]['status'] = '1';
                     } else {
                         $deal_list[$k]['status'] = '3';
                     }
                 } else {
                     $deal_list[$k]['status'] = '4';
                 }
             }
             $deal_list[$k]['end_time'] = to_date($v['end_time'], 'Y-m-d');
             $deal_list[$k]['begin_time'] = to_date($v['begin_time'], 'Y-m-d');
             $deal_list[$k]['create_time'] = to_date($v['create_time'], 'Y-m-d');
             $deal_ids[] = $v['id'];
             // 查询出对应项目id的user_level
             $deal_list[$k]['deal_level'] = $GLOBALS['db']->getOne("select level from " . DB_PREFIX . "deal_level where id=" . intval($deal_list[$k]['user_level']));
         }
     }
     /* (所需项目)准备虚拟数据 end */
     $root['isAll'] = $isAll;
     $root['deal_list'] = $deal_list;
     $root['deal_count'] = $deal_count;
     $root['page'] = array("page" => $page, "page_total" => ceil($deal_count / $page_size), "page_size" => intval($page_size), 'total' => intval($deal_count));
     output($root);
 }
Example #12
0
 public function index()
 {
     if (strim($_REQUEST['type']) == 1 && app_conf("INVEST_STATUS") == 1) {
         showErr("股权众筹已经关闭");
     }
     if (app_conf("INVEST_STATUS") == 2 && strim($_REQUEST['type']) == null) {
         showErr("产品众筹已经关闭");
     }
     //links
     $g_links = get_link_by_id(14);
     $GLOBALS['tmpl']->assign("g_links", $g_links);
     $GLOBALS['tmpl']->assign("page_title", "最新动态");
     $param = array();
     //参数集合
     //数据来源参数
     $r = strim($_REQUEST['r']);
     //推荐类型
     $param['r'] = $r ? $r : '';
     $GLOBALS['tmpl']->assign("p_r", $r);
     $id = intval($_REQUEST['id']);
     //分类id
     $param['id'] = $id;
     $GLOBALS['tmpl']->assign("p_id", $id);
     $loc = strim($_REQUEST['loc']);
     //地区
     $param['loc'] = $loc;
     $GLOBALS['tmpl']->assign("p_loc", $loc);
     $state = intval($_REQUEST['state']);
     //状态
     $param['state'] = $state;
     $GLOBALS['tmpl']->assign("p_state", $state);
     $tag = strim($_REQUEST['tag']);
     //标签
     $param['tag'] = $tag;
     $GLOBALS['tmpl']->assign("p_tag", $tag);
     $kw = strim($_REQUEST['k']);
     //关键词
     $param['k'] = $kw;
     $GLOBALS['tmpl']->assign("p_k", $kw);
     $type = intval($_REQUEST['type']);
     //推荐类型
     $param['type'] = $type;
     $GLOBALS['tmpl']->assign("p_type", $type);
     if (intval($_REQUEST['redirect']) == 1) {
         app_redirect(url("aps", $param));
     }
     $cate_list = load_dynamic_cache("INDEX_CATE_LIST");
     if (!$cate_list) {
         $cate_list = $GLOBALS['db']->getAll("select a.* from " . DB_PREFIX . "deal_cate as a where a.is_delete=0 and ( SELECT count( b.id ) AS num FROM xlc_deal AS b WHERE b.cate_id = a.id and b.is_ap>0) >0 order by sort asc");
         set_dynamic_cache("INDEX_CATE_LIST", $cate_list);
     }
     $cate_result = array();
     foreach ($cate_list as $k => $v) {
         if ($v['pid'] == 0) {
             $temp_param = $param;
             $cate_result[$k + 1]['id'] = $v['id'];
             $cate_result[$k + 1]['name'] = $v['name'];
             $temp_param['id'] = $v['id'];
             $cate_result[$k + 1]['url'] = url("aps", $temp_param);
         }
     }
     $GLOBALS['tmpl']->assign("cate_list", $cate_result);
     $pid = $id;
     //获取父类id
     if ($cate_list) {
         $pid = $this->get_child($cate_list, $pid);
     }
     /*子分类 start*/
     $cate_ids = array();
     $is_child = false;
     $temp_cate_ids = array();
     if ($cate_list) {
         $child_cate_result = array();
         foreach ($cate_list as $k => $v) {
             if ($v['pid'] == $pid) {
                 if ($v['id'] > 0) {
                     $temp_param = $param;
                     $child_cate_result[$v['id']]['id'] = $v['id'];
                     $child_cate_result[$v['id']]['name'] = $v['name'];
                     $temp_param['id'] = $v['id'];
                     $child_cate_result[$v['id']]['url'] = url("aps", $temp_param);
                     if ($id == $v['id']) {
                         $is_child = true;
                     }
                 }
             }
             if ($v['pid'] == $pid || $pid == 0) {
                 $temp_cate_ids[] = $v['id'];
             }
         }
     }
     //假如选择了子类 那么使用子类ID  否则使用 父类和其子类
     if ($is_child) {
         $cate_ids[] = $id;
     } else {
         $cate_ids[] = $pid;
         $cate_ids = array_merge($cate_ids, $temp_cate_ids);
     }
     $cate_ids = array_filter($cate_ids);
     $GLOBALS['tmpl']->assign("child_cate_list", $child_cate_result);
     $GLOBALS['tmpl']->assign("pid", $pid);
     /*子分类 end*/
     $city_list = load_dynamic_cache("INDEX_CITY_LIST");
     if (!$city_list) {
         $city_list = $GLOBALS['db']->getAll("select province from " . DB_PREFIX . "deal where is_ap>0 group by province order by sort asc");
         set_dynamic_cache("INDEX_CITY_LIST", $city_list);
     }
     foreach ($city_list as $k => $v) {
         $temp_param = $param;
         $temp_param['loc'] = $v['province'];
         $city_list[$k]['url'] = url("aps", $temp_param);
     }
     $GLOBALS['tmpl']->assign("city_list", $city_list);
     //============region_conf============
     $area_list = $GLOBALS['db']->getAll("select rc.* from " . DB_PREFIX . "region_conf as rc where rc.name in (select province from " . DB_PREFIX . "deal where is_ap>0) or  rc.name in (select city from " . DB_PREFIX . "deal where is_ap>0) or rc.is_hot=1 ");
     $area = array();
     $hot_area = array();
     foreach ($area_list as $k => $v) {
         $temp_param['loc'] = $v['name'];
         $area[strtoupper($v['py'][0])][$v['name']] = array('url' => url("aps", $temp_param), 'name' => $v['name']);
         if ($v['is_hot']) {
             $hot_area[] = array('url' => url("aps", $temp_param), 'name' => $v['name']);
         }
     }
     ksort($area);
     $area_array = array();
     $area_array = array_chunk(array_filter($area), 4, true);
     $area_array_num = array();
     foreach ($area_array as $k => $v) {
         foreach ($v as $k1 => $v1) {
             $area_array_str[$k] .= $k1;
         }
     }
     $GLOBALS['tmpl']->assign("area_array", $area_array);
     $GLOBALS['tmpl']->assign("area_array_str", $area_array_str);
     $GLOBALS['tmpl']->assign("hot_area", array_filter($hot_area));
     //=================region_conf==============
     if ($type == 1) {
         $state_list = array(1 => array("name" => "筹资成功"), 2 => array("name" => "筹资失败"), 3 => array("name" => "融资中"));
     } else {
         $state_list = array(1 => array("name" => "筹资成功"), 2 => array("name" => "筹资失败"), 3 => array("name" => "筹资中"));
     }
     foreach ($state_list as $k => $v) {
         $temp_param = $param;
         $temp_param['state'] = $k;
         $state_list[$k]['url'] = url("aps", $temp_param);
     }
     $GLOBALS['tmpl']->assign("state_list", $state_list);
     $page_size = 10;
     $step_size = 10;
     $step = intval($_REQUEST['step']);
     if ($step == 0) {
         $step = 1;
     }
     $page = intval($_REQUEST['p']);
     if ($page == 0) {
         $page = 1;
     }
     $limit = ($page - 1) * $page_size + ($step - 1) * $step_size . "," . $step_size;
     $GLOBALS['tmpl']->assign("current_page", $page);
     $condition = " d.is_delete = 0 and d.is_effect = 1 and d.is_ap>0";
     if ($r != "") {
         if ($r == "new") {
             $condition .= " and " . NOW_TIME . " - d.begin_time < " . 24 * 3600 . " and " . NOW_TIME . " - d.begin_time > 0 ";
             //上线不超过一天
             $GLOBALS['tmpl']->assign("page_title", "最新上线");
         }
         if ($r == "rec") {
             $condition .= " and " . NOW_TIME . " <= d.end_time AND " . NOW_TIME . " >= d.begin_time and d.is_recommend = 1 ";
             $GLOBALS['tmpl']->assign("page_title", "推荐项目");
         }
         if ($r == "yure") {
             $condition .= " and " . NOW_TIME . " - d.begin_time < " . 24 * 3600 . " and " . NOW_TIME . " - d.begin_time <  0 ";
             //上线不超过一天
             $GLOBALS['tmpl']->assign("page_title", "正在预热");
         }
         if ($r == "nend") {
             $condition .= " and d.end_time - " . NOW_TIME . " < " . 24 * 3600 . " and d.end_time - " . NOW_TIME . " > 0 ";
             //当天就要结束
             $GLOBALS['tmpl']->assign("page_title", "即将结束");
         }
         if ($r == "classic") {
             $condition .= " and d.is_classic = 1 ";
             $GLOBALS['tmpl']->assign("page_title", "经典项目");
             $GLOBALS['tmpl']->assign("is_classic", true);
         }
         if ($r == "limit_price") {
             $condition .= " and max(d.limit_price) ";
             $GLOBALS['tmpl']->assign("page_title", "最高目标金额");
         }
     }
     switch ($state) {
         //筹资成功
         case 1:
             $condition .= " and d.is_success=1  ";
             $GLOBALS['tmpl']->assign("page_title", "筹资成功");
             break;
             //筹资失败
         //筹资失败
         case 2:
             $condition .= " and d.end_time < " . NOW_TIME . " and d.end_time!=0  and d.is_success=0  ";
             $GLOBALS['tmpl']->assign("page_title", "筹资失败");
             break;
             //筹资中
         //筹资中
         case 3:
             $condition .= " and (d.end_time > " . NOW_TIME . " or d.end_time=0 ) and d.begin_time < " . NOW_TIME . " and d.is_success=0  ";
             $GLOBALS['tmpl']->assign("page_title", "筹资中");
             break;
     }
     if (count($cate_ids) > 0) {
         $condition .= " and d.cate_id in (" . implode(",", $cate_ids) . ")";
         $GLOBALS['tmpl']->assign("page_title", $cate_result[$id]['name']);
     }
     if ($loc != "") {
         $condition .= " and (d.province = '" . $loc . "' or city = '" . $loc . "') ";
         $GLOBALS['tmpl']->assign("page_title", $loc);
     }
     if ($type !== "") {
         $type = intval($type);
         $condition .= " and type={$type} ";
         $GLOBALS['tmpl']->assign("page_title", $loc);
     }
     if ($tag != "") {
         $unicode_tag = str_to_unicode_string($tag);
         $condition .= " and match(d.tags_match) against('" . $unicode_tag . "'  IN BOOLEAN MODE) ";
         $GLOBALS['tmpl']->assign("page_title", $tag);
     }
     if ($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.name_match) against('" . $ukeyword . "'  IN BOOLEAN MODE) or match(d.tags_match) against('" . $ukeyword . "'  IN BOOLEAN MODE)  or d.name like '%" . $kw . "%') ";
         $GLOBALS['tmpl']->assign("page_title", $kw);
     }
     $result = get_deal_list($limit, $condition);
     foreach ($result['list'] as $key => $val) {
         $result['list'][$key]['limit_ap'] = $val['limit_price'] * $val['ap_ratio'];
         $result['list'][$key]['ap_amount'] = $val['support_amount'] * $val['ap_ratio'];
     }
     if ($type == 1) {
         $GLOBALS['tmpl']->assign("deal_list_invest", $result['list']);
     } else {
         $GLOBALS['tmpl']->assign("deal_list", $result['list']);
     }
     $GLOBALS['tmpl']->assign("deal_count", $result['rs_count']);
     $page = new Page($result['rs_count'], $page_size);
     //初始化分页对象
     $p = $page->show();
     $GLOBALS['tmpl']->assign('pages', $p);
     if ($type == 1) {
         $GLOBALS['tmpl']->assign('deal_type', 'gq_type');
     } else {
         $GLOBALS['tmpl']->assign('deal_type', 'product_type');
     }
     if ($GLOBALS['tmpl']->_var['page_title'] == '') {
         $page_title = '';
         if ($type == 1) {
             foreach ($GLOBALS['nav_list'] as $k => $v) {
                 if ($v['u_module'] == 'deals' && $v['u_action'] == 'index' && $v['u_param'] == 'type=1') {
                     $page_title = $v['name'];
                 }
             }
             $page_title = $page_title ? $page_title : '股权项目';
         } else {
             foreach ($GLOBALS['nav_list'] as $k => $v) {
                 if ($v['u_module'] == 'deals' && $v['u_action'] == 'index' && $v['u_param'] == '') {
                     $page_title = $v['name'];
                 }
             }
             $page_title = $page_title ? $page_title : '产品项目';
         }
         $GLOBALS['tmpl']->assign("page_title", $page_title);
     }
     $GLOBALS['tmpl']->display("aps_index.html");
 }
 public function index()
 {
     if (strim($_REQUEST['type']) == 1 && app_conf("INVEST_STATUS") == 1) {
         showErr("股权众筹已经关闭");
     }
     if (app_conf("INVEST_STATUS") == 2 && strim($_REQUEST['type']) == null) {
         showErr("产品众筹已经关闭");
     }
     $GLOBALS['tmpl']->assign("page_title", "最新动态");
     $param = array();
     //参数集合
     //数据来源参数
     $r = strim($_REQUEST['r']);
     //推荐类型
     $param['r'] = $r ? $r : '';
     $GLOBALS['tmpl']->assign("p_r", $r);
     $id = intval($_REQUEST['id']);
     //分类id
     $param['id'] = $id;
     $GLOBALS['tmpl']->assign("p_id", $id);
     $loc = strim($_REQUEST['loc']);
     //地区
     $param['loc'] = $loc;
     $GLOBALS['tmpl']->assign("p_loc", $loc);
     $state = intval($_REQUEST['state']);
     //状态
     $param['state'] = $state;
     $GLOBALS['tmpl']->assign("p_state", $state);
     $tag = strim($_REQUEST['tag']);
     //标签
     $param['tag'] = $tag;
     $GLOBALS['tmpl']->assign("p_tag", $tag);
     $kw = strim($_REQUEST['k']);
     //关键词
     $param['k'] = $kw;
     $GLOBALS['tmpl']->assign("p_k", $kw);
     $type = intval($_REQUEST['type']);
     //推荐类型
     $param['type'] = $type;
     $GLOBALS['tmpl']->assign("p_type", $type);
     $param_new = $param;
     //融资金额
     $price = intval($_REQUEST['price']);
     if ($price > 0) {
         $param['price'] = $price;
         $GLOBALS['tmpl']->assign("price", $price);
     }
     //关注数
     $focus = intval($_REQUEST['focus']);
     if ($focus > 0) {
         $param['focus'] = $focus;
         $GLOBALS['tmpl']->assign("focus", $focus);
     }
     //剩余时间
     $time = intval($_REQUEST['time']);
     if ($time > 0) {
         $param['time'] = $time;
         $GLOBALS['tmpl']->assign("time", $time);
     }
     //完成比例
     $cp = intval($_REQUEST['cp']);
     if ($cp > 0) {
         $param['cp'] = $cp;
         $GLOBALS['tmpl']->assign("cp", $cp);
     }
     if (intval($_REQUEST['redirect']) == 1) {
         app_redirect(url("deals", $param));
     }
     $cate_list = load_dynamic_cache("INDEX_CATE_LIST");
     if (!$cate_list) {
         $cate_list = $GLOBALS['db']->getAll("select * from " . DB_PREFIX . "deal_cate where is_delete=0 order by sort asc");
         set_dynamic_cache("INDEX_CATE_LIST", $cate_list);
     }
     $cate_result = array();
     foreach ($cate_list as $k => $v) {
         if ($v['pid'] == 0) {
             $temp_param = $param;
             $cate_result[$k + 1]['id'] = $v['id'];
             $cate_result[$k + 1]['name'] = $v['name'];
             $temp_param['id'] = $v['id'];
             $cate_result[$k + 1]['url'] = url("deals", $temp_param);
         }
     }
     $GLOBALS['tmpl']->assign("cate_list", $cate_result);
     $pid = $id;
     //获取父类id
     if ($cate_list) {
         $pid = $this->get_child($cate_list, $pid);
     }
     /*子分类 start*/
     $cate_ids = array();
     $is_child = false;
     $temp_cate_ids = array();
     if ($cate_list) {
         $child_cate_result = array();
         foreach ($cate_list as $k => $v) {
             if ($v['pid'] == $pid) {
                 if ($v['id'] > 0) {
                     $temp_param = $param;
                     $child_cate_result[$v['id']]['id'] = $v['id'];
                     $child_cate_result[$v['id']]['name'] = $v['name'];
                     $temp_param['id'] = $v['id'];
                     $child_cate_result[$v['id']]['url'] = url("deals", $temp_param);
                     if ($id == $v['id']) {
                         $is_child = true;
                     }
                 }
             }
             if ($v['pid'] == $pid || $pid == 0) {
                 $temp_cate_ids[] = $v['id'];
             }
         }
     }
     //假如选择了子类 那么使用子类ID  否则使用 父类和其子类
     if ($is_child) {
         $cate_ids[] = $id;
     } else {
         $cate_ids[] = $pid;
         $cate_ids = array_merge($cate_ids, $temp_cate_ids);
     }
     $cate_ids = array_filter($cate_ids);
     $GLOBALS['tmpl']->assign("child_cate_list", $child_cate_result);
     $GLOBALS['tmpl']->assign("pid", $pid);
     /*子分类 end*/
     $city_list = load_dynamic_cache("INDEX_CITY_LIST");
     if ($type == 1) {
         if (!$city_list) {
             $city_list = $GLOBALS['db']->getAll("select province from " . DB_PREFIX . "deal where type=1 and is_effect =1 group by province  order by sort asc");
             //	set_dynamic_cache("INDEX_CITY_LIST",$city_list);
         }
     }
     if ($type == 0) {
         if (!$city_list) {
             $city_list = $GLOBALS['db']->getAll("select province from " . DB_PREFIX . "deal where type=0 and is_effect =1 group by province  order by sort asc");
             //	set_dynamic_cache("INDEX_CITY_LIST",$city_list);
         }
     }
     foreach ($city_list as $k => $v) {
         $temp_param = $param;
         $temp_param['loc'] = $v['province'];
         $city_list[$k]['url'] = url("deals", $temp_param);
     }
     $GLOBALS['tmpl']->assign("city_list", $city_list);
     //============region_conf============
     $area_list = $GLOBALS['db']->getAll("select rc.* from " . DB_PREFIX . "region_conf as rc where rc.name in (select province from " . DB_PREFIX . "deal) or  rc.name in (select city from " . DB_PREFIX . "deal) or rc.is_hot=1 ");
     $area = array();
     $hot_area = array();
     foreach ($area_list as $k => $v) {
         $temp_param['loc'] = $v['name'];
         $area[strtoupper($v['py'][0])][$v['name']] = array('url' => url("deals", $temp_param), 'name' => $v['name']);
         if ($v['is_hot']) {
             $hot_area[] = array('url' => url("deals", $temp_param), 'name' => $v['name']);
         }
     }
     ksort($area);
     $area_array = array();
     $area_array = array_chunk(array_filter($area), 4, true);
     $area_array_num = array();
     foreach ($area_array as $k => $v) {
         foreach ($v as $k1 => $v1) {
             $area_array_str[$k] .= $k1;
         }
     }
     $GLOBALS['tmpl']->assign("area_array", $area_array);
     $GLOBALS['tmpl']->assign("area_array_str", $area_array_str);
     $GLOBALS['tmpl']->assign("hot_area", array_filter($hot_area));
     //=================region_conf==============
     if ($type == 1) {
         $state_list = array(1 => array("name" => "筹资成功"), 2 => array("name" => "筹资失败"), 3 => array("name" => "融资中"));
     } else {
         $state_list = array(1 => array("name" => "筹资成功"), 2 => array("name" => "筹资失败"), 3 => array("name" => "筹资中"));
     }
     foreach ($state_list as $k => $v) {
         $temp_param = $param;
         $temp_param['state'] = $k;
         $state_list[$k]['url'] = url("deals", $temp_param);
     }
     $GLOBALS['tmpl']->assign("state_list", $state_list);
     $page_size = DEAL_PAGE_SIZE;
     $step_size = DEAL_STEP_SIZE;
     $step = intval($_REQUEST['step']);
     if ($step == 0) {
         $step = 1;
     }
     $page = intval($_REQUEST['p']);
     if ($page == 0) {
         $page = 1;
     }
     $limit = ($page - 1) * $page_size + ($step - 1) * $step_size . "," . $step_size;
     $GLOBALS['tmpl']->assign("current_page", $page);
     $condition = " d.is_delete = 0 and d.is_effect = 1 ";
     if ($r != "") {
         if ($r == "new") {
             $condition .= " and " . NOW_TIME . " - d.begin_time < " . 7 * 24 * 3600 . " and " . NOW_TIME . " - d.begin_time > 0 ";
             //上线不超过一天
             $GLOBALS['tmpl']->assign("page_title", "最新上线");
         } elseif ($r == "rec") {
             $condition .= " and d.is_recommend = 1 ";
             $GLOBALS['tmpl']->assign("page_title", "推荐项目");
         } elseif ($r == "yure") {
             $condition .= "   and " . NOW_TIME . " <  d.begin_time ";
             $GLOBALS['tmpl']->assign("page_title", "正在预热");
         } elseif ($r == "nend") {
             $condition .= " and d.end_time - " . NOW_TIME . " < " . 7 * 24 * 3600 . " and d.end_time - " . NOW_TIME . " > 0 ";
             //三天就要结束
             $GLOBALS['tmpl']->assign("page_title", "即将结束");
         } elseif ($r == "classic") {
             $condition .= " and d.is_classic = 1 ";
             $GLOBALS['tmpl']->assign("page_title", "经典项目");
             $GLOBALS['tmpl']->assign("is_classic", true);
         } elseif ($r == "limit_price") {
             $condition .= " and max(d.limit_price) ";
             $GLOBALS['tmpl']->assign("page_title", "最高目标金额");
         }
     }
     switch ($state) {
         //筹资成功
         case 1:
             $condition .= " and d.is_success=1  and d.end_time < " . NOW_TIME;
             $GLOBALS['tmpl']->assign("page_title", "筹资成功");
             break;
             //筹资失败
         //筹资失败
         case 2:
             $condition .= " and d.end_time < " . NOW_TIME . " and d.end_time!=0  and d.is_success=0  ";
             $GLOBALS['tmpl']->assign("page_title", "筹资失败");
             break;
             //筹资中
         //筹资中
         case 3:
             $condition .= " and (d.end_time > " . NOW_TIME . " or d.end_time=0 ) and d.begin_time < " . NOW_TIME . "   ";
             $GLOBALS['tmpl']->assign("page_title", "筹资中");
             break;
     }
     if (count($cate_ids) > 0) {
         $condition .= " and d.cate_id in (" . implode(",", $cate_ids) . ")";
         $GLOBALS['tmpl']->assign("page_title", $cate_result[$id]['name']);
     }
     if ($loc != "") {
         $condition .= " and (d.province = '" . $loc . "' or d.city = '" . $loc . "') ";
         $GLOBALS['tmpl']->assign("page_title", $loc);
     }
     if ($type !== "") {
         $type = intval($type);
         $condition .= " and d.type={$type} ";
         $GLOBALS['tmpl']->assign("page_title", $loc);
     }
     if ($tag != "") {
         $unicode_tag = str_to_unicode_string($tag);
         $condition .= " and match(d.tags_match) against('" . $unicode_tag . "'  IN BOOLEAN MODE) ";
         $GLOBALS['tmpl']->assign("page_title", $tag);
     }
     if ($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.name_match) against('" . $ukeyword . "'  IN BOOLEAN MODE) or match(d.tags_match) against('" . $ukeyword . "'  IN BOOLEAN MODE)  or d.name like '%" . $kw . "%') ";
         $GLOBALS['tmpl']->assign("page_title", $kw);
     }
     //		if($r=="new")
     //		{
     //			$orderby ="  d.begin_time desc ";
     //		}
     //		elseif($r=="rec")
     //		{
     //			$orderby.="   d.begin_time desc  ";
     //		}
     //        else
     //		{
     //			$orderby ="  sort asc ";
     //		}
     $temp_param_price = array_merge($param_new, array('price' => 1));
     $temp_param_focus = array_merge($param_new, array('focus' => 1));
     $temp_param_time = array_merge($param_new, array('time' => 1));
     $temp_param_cp = array_merge($param_new, array('cp' => 1));
     $url_list = array('price_url' => url("deals", $temp_param_price), 'focus_url' => url("deals", $temp_param_focus), 'time_url' => url("deals", $temp_param_time), 'cp_url' => url("deals", $temp_param_cp));
     //========
     if ($price > 0) {
         if ($price == 1) {
             if ($type == 1) {
                 $orderby .= " d.invote_money desc";
             } else {
                 $orderby .= " (d.support_amount+d.virtual_price) desc";
             }
             $param_new['price'] = 2;
         } elseif ($price == 2) {
             if ($type == 1) {
                 $orderby .= " d.invote_money asc";
             } else {
                 $orderby .= " (d.support_amount+d.virtual_price) asc";
             }
             $param_new['price'] = 1;
         }
         $url_list['price_url'] = url("deals", $param_new);
     } elseif ($focus > 0) {
         if ($focus == 1) {
             $orderby .= " d.focus_count desc";
             $param_new['focus'] = 2;
         } elseif ($focus == 2) {
             $orderby .= " d.focus_count asc";
             $param_new['focus'] = 1;
         }
         $url_list['focus_url'] = url("deals", $param_new);
     } elseif ($time > 0) {
         if ($time == 1) {
             $orderby .= " d.end_time desc";
             $param_new['time'] = 2;
         } elseif ($time == 2) {
             $orderby .= " d.end_time asc";
             $param_new['time'] = 1;
         }
         $url_list['time_url'] = url("deals", $param_new);
     } elseif ($cp > 0) {
         if ($cp == 1) {
             if ($type == 1) {
                 $orderby .= " d.invote_money/d.limit_price desc";
             } else {
                 $orderby .= " (d.support_amount+d.virtual_price)/d.limit_price desc";
             }
             $param_new['cp'] = 2;
         } else {
             if ($type == 1) {
                 $orderby .= " d.invote_money/d.limit_price asc";
             } else {
                 $orderby .= " (d.support_amount+d.virtual_price)/d.limit_price asc";
             }
             $param_new['cp'] = 1;
         }
         $url_list['cp_url'] = url("deals", $param_new);
     } else {
         $orderby = "  d.begin_time desc ";
     }
     $GLOBALS['tmpl']->assign("url_list", $url_list);
     //		if($r=="new")
     //		{
     //			$orderby ="  d.begin_time desc ";
     //		}
     //		elseif($r=="rec")
     //		{
     //			$orderby.="   d.begin_time desc  ";
     //		}
     //        else
     //		{
     //			$orderby ="  sort asc ";
     //		}
     //		var_dump($limit);
     //		var_dump($condition);
     //		var_dump($orderby);
     $result = get_deal_list($limit, $condition, $orderby);
     if ($type == 1) {
         $GLOBALS['tmpl']->assign("deal_list_invest", $result['list']);
     } else {
         $GLOBALS['tmpl']->assign("deal_list", $result['list']);
     }
     $GLOBALS['tmpl']->assign("deal_count", $result['rs_count']);
     $page = new Page($result['rs_count'], $page_size);
     //初始化分页对象
     $p = $page->para_show("deals#index", $param);
     $GLOBALS['tmpl']->assign('pages', $p);
     if ($type == 1) {
         $GLOBALS['tmpl']->assign('deal_type', 'gq_type');
     } else {
         $GLOBALS['tmpl']->assign('deal_type', 'product_type');
     }
     if ($GLOBALS['tmpl']->_var['page_title'] == '') {
         $page_title = '';
         if ($type == 1) {
             foreach ($GLOBALS['nav_list'] as $k => $v) {
                 if ($v['u_module'] == 'deals' && $v['u_action'] == 'index' && $v['u_param'] == 'type=1') {
                     $page_title = $v['name'];
                 }
             }
             $page_title = $page_title ? $page_title : '股权项目';
         } else {
             foreach ($GLOBALS['nav_list'] as $k => $v) {
                 if ($v['u_module'] == 'deals' && $v['u_action'] == 'index' && $v['u_param'] == '') {
                     $page_title = $v['name'];
                 }
             }
             $page_title = $page_title ? $page_title : '产品项目';
         }
         $GLOBALS['tmpl']->assign("page_title", $page_title);
     }
     $GLOBALS['tmpl']->display("deals_index.html");
 }
 public function pick()
 {
     $url_param = array("id" => addslashes(trim($_REQUEST['id'])), "b" => intval($_REQUEST['b']), "min_price" => doubleval($_REQUEST['min_price']), "max_price" => doubleval($_REQUEST['max_price']), "keyword" => addslashes(trim($_REQUEST['keyword'])));
     $filter_req = $_REQUEST['f'];
     //筛选数组
     if (count($filter_req) > 0) {
         foreach ($filter_req as $k => $v) {
             $url_param['f[' . $k . ']'] = $v;
         }
     }
     if (intval($_REQUEST['is_redirect']) == 1) {
         app_redirect(url("shop", "ss#pick", $url_param));
     }
     //输出商城分类
     $cate_tree = get_cate_tree();
     $all_cate_tree = get_cate_tree(0, 1);
     $GLOBALS['tmpl']->assign("cate_tree", $cate_tree);
     $GLOBALS['tmpl']->assign("all_cate_tree", $all_cate_tree);
     convert_req($_REQUEST);
     //获取当前页的团购商品列表
     //分页
     $page = intval($_REQUEST['p']);
     if ($page == 0) {
         $page = 1;
     }
     $limit = ($page - 1) * app_conf("DEAL_PAGE_SIZE") . "," . app_conf("DEAL_PAGE_SIZE");
     $id = intval($_REQUEST['id']);
     if ($id == 0) {
         $uname = addslashes(trim($_REQUEST['id']));
     }
     $cate_item = $GLOBALS['db']->getRow("select * from " . DB_PREFIX . "shop_cate where id = " . $id . " or (uname = '" . $uname . "' and uname <> '')");
     $condition = " d.buy_type<>1 ";
     //条件
     $ids = load_auto_cache("shop_sub_cate_ids", array("cate_id" => intval($cate_item['id'])));
     $add_title = "";
     //输出品牌
     $brand_id = intval($_REQUEST['b']);
     if ($brand_id > 0) {
         $condition .= " and d.brand_id = " . $brand_id;
         $add_title .= $GLOBALS['db']->getOne("select name from " . DB_PREFIX . "brand where id = " . $brand_id);
         $GLOBALS['tmpl']->assign("brand_id", $brand_id);
     }
     $brand_list = $GLOBALS['db']->getAll("select * from " . DB_PREFIX . "brand order by sort desc");
     $GLOBALS['tmpl']->assign("brand_list", $brand_list);
     //输出属性筛选
     $filter_req = $_REQUEST['f'];
     $join_str = "";
     $unicode_tags = array();
     foreach ($filter_req as $k => $v) {
         $filter_req[$k] = trim(addslashes(urldecode($v)));
         if ($filter_req[$k] != '' && $filter_req[$k] != 'all') {
             if ($add_title != '') {
                 $add_title .= " - ";
             }
             $add_title .= $filter_req[$k];
             //				//联表及条件
             //				$join_str.=" left join ".DB_PREFIX."deal_filter as df_".$k." on d.id=df_".$k.".deal_id and df_".$k.".filter_group_id = ".$k;
             //				$condition.=" and df_".$k.".filter like '%".$filter_req[$k]."%' ";
             $unicode_tags[] = "+" . str_to_unicode_string($filter_req[$k]);
         }
     }
     if (count($unicode_tags) > 0) {
         $kw_unicode = implode(" ", $unicode_tags);
         //有筛选
         $condition .= " and (match(d.tag_match) against('" . $kw_unicode . "' IN BOOLEAN MODE))";
     }
     if (intval($_REQUEST['id']) != 0) {
         $filter_group = $GLOBALS['db']->getAll("select * from " . DB_PREFIX . "filter_group where is_effect = 1 and cate_id in (" . implode(",", $ids) . ") order by sort desc");
         foreach ($filter_group as $k => $v) {
             $filter_group[$k]['value'] = $filter_req[$v['id']];
         }
         $GLOBALS['tmpl']->assign("filter_group", $filter_group);
     }
     //输出价格区间
     $min_price = doubleval($_REQUEST['min_price']);
     $max_price = doubleval($_REQUEST['max_price']);
     $GLOBALS['tmpl']->assign("min_price", $min_price);
     $GLOBALS['tmpl']->assign("max_price", $max_price);
     if ($min_price > 0) {
         $condition .= " and d.current_price >= " . $min_price;
     }
     if ($max_price > 0) {
         $condition .= " and d.current_price <= " . $max_price;
     }
     $sort_field = es_cookie::get("shop_sort_field") ? es_cookie::get("shop_sort_field") : "sort";
     $sort_type = es_cookie::get("shop_sort_type") ? es_cookie::get("shop_sort_type") : "desc";
     $GLOBALS['tmpl']->assign('sort_field', $sort_field);
     $GLOBALS['tmpl']->assign('sort_type', $sort_type);
     if (es_cookie::get("list_type") === null) {
         $list_type = app_conf("LIST_TYPE");
     } else {
         $list_type = intval(es_cookie::get("list_type"));
     }
     $GLOBALS['tmpl']->assign("list_type", $list_type);
     $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."%')";
     }
     if ($add_title != '') {
         $add_title .= "-";
     }
     $add_title .= $GLOBALS['lang']['GOODS_SEARCH'];
     $result = search_goods_list($limit, intval($cate_item['id']), $condition, "d." . $sort_field . " " . $sort_type, false, $join_str);
     $GLOBALS['tmpl']->assign("list", $result['list']);
     $page = new Page($result['count'], app_conf("DEAL_PAGE_SIZE"));
     //初始化分页对象
     $p = $page->show();
     $GLOBALS['tmpl']->assign('pages', $p);
     $GLOBALS['tmpl']->assign("cate_id", $cate_item['id']);
     $GLOBALS['tmpl']->assign("page_title", $add_title . $cate_item['name']);
     $GLOBALS['tmpl']->assign("page_keyword", $add_title . $cate_item['name'] . ",");
     $GLOBALS['tmpl']->assign("page_description", $add_title . $cate_item['name'] . ",");
     $GLOBALS['tmpl']->assign("filter", true);
     //显示筛选框
     $GLOBALS['tmpl']->assign("show_list", true);
     $GLOBALS['tmpl']->display("ss_index.html");
 }
Example #15
0
 public function index()
 {
     require_once APP_ROOT_PATH . "system/libs/user.php";
     $root = array();
     $email = strim($GLOBALS['request']['biz_email']);
     //用户名或邮箱
     $pwd = strim($GLOBALS['request']['biz_pwd']);
     //密码
     $user_qrcode = strim($GLOBALS['request']['user_qrcode']);
     //会员二维码
     $page = intval($GLOBALS['request']['page']);
     //分页
     if ($page == 0) {
         $page = 1;
     }
     $limit = ($page - 1) * PAGE_SIZE . "," . PAGE_SIZE;
     $keyword = strim($GLOBALS['request']['keyword']);
     //查询关键字
     //检查用户,用户密码
     $biz_user = biz_check($email, $pwd);
     $supplier_id = intval($biz_user['supplier_id']);
     if ($supplier_id > 0) {
         $root['user_login_status'] = 1;
         //用户登陆状态:1:成功登陆;0:未成功登陆
         $time = get_gmtime();
         $sql = "select id, user_name, user_qrcode, qrcode_end from " . DB_PREFIX . "user where user_qrcode = '" . $user_qrcode . "' limit 1";
         $user = $GLOBALS['db']->getRow($sql);
         if (!$user) {
             $root['return'] = 0;
             $root['info'] = "会员卡不存在";
             output($root);
         } else {
             if ($user['qrcode_end'] < $time) {
                 $root['return'] = 0;
                 $root['info'] = "会员卡已过期";
                 output($root);
             }
         }
         $root['user_id'] = $user['id'];
         $root['user_qrcode'] = $user['user_qrcode'];
         $root['user_name'] = $user['user_name'];
         $sql = "select d.id,d.name,d.sub_name,d.icon, d.current_price,d.return_qrcode_money from " . DB_PREFIX . "deal as d left join " . DB_PREFIX . "deal_location_link as l on l.deal_id = d.id where ";
         $count_sql = "select count(d.id) from " . DB_PREFIX . "deal as d left join " . DB_PREFIX . "deal_location_link as l on l.deal_id = d.id where ";
         $condition = " d.is_shop in (0,1) and l.location_id in (" . implode(",", $biz_user['location_ids']) . ") and d.is_delete = 0 and d.supplier_id = " . $supplier_id . " and d.buy_type = 0 and d.publish_wait = 0  ";
         $condition .= " and ((" . $time . ">= d.begin_time or d.begin_time = 0) and (" . $time . "< d.end_time or d.end_time = 0) and d.buy_status <> 2) ";
         //$condition .= " and d.return_qrcode_money > 0";
         if ($keyword) {
             $kws_div = div_str($keyword);
             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.deal_cate_match) against('" . $ukeyword . "' IN BOOLEAN MODE) or d.name like '%" . $keyword . "%') ";
         }
         $sql .= $condition . " order by d.id desc limit " . $limit;
         //$root['sql'] = $sql;
         $count_sql .= $condition;
         //print_r($biz_user);
         //echo $sql; exit;
         $deal_list = $GLOBALS['db']->getAll($sql);
         foreach ($deal_list as $k => $v) {
             $deal_list[$k]['icon'] = get_abs_img_root(get_spec_image($v['icon'], 360, 288, 0));
             $deal_list[$k]['current_price_format'] = format_price($v['current_price']);
             $deal_list[$k]['return_qrcode_money_format'] = format_price($v['return_qrcode_money']);
             $deal_list[$k]['allow_edit_total_money'] = 1;
             //允许下单时,直接编辑商品总价
         }
         $deal_count = $GLOBALS['db']->getOne($count_sql);
         $root['page'] = array("page" => $page, "page_total" => ceil($deal_count / PAGE_SIZE), "page_size" => PAGE_SIZE);
         if ($deal_list == false || $deal_list == null) {
             $deal_list = array();
         }
         $root['item'] = $deal_list;
         $root['return'] = 1;
         $root['info'] = "商品列表";
     } else {
         $root['return'] = 0;
         $root['user_login_status'] = 0;
         //用户登陆状态:1:成功登陆;0:未成功登陆
         $root['info'] = "商户不存在或密码错误";
     }
     output($root);
 }
 public function index()
 {
     $id = intval($GLOBALS['request']['id']);
     $type = addslashes($GLOBALS['request']['type']);
     $cid = intval($GLOBALS['request']['cid']);
     $keyword = addslashes($GLOBALS['request']['tag']);
     $is_hot = intval($GLOBALS['request']['is_hot']);
     $is_new = intval($GLOBALS['request']['is_new']);
     $page = intval($GLOBALS['request']['page']) > 0 ? intval($GLOBALS['request']['page']) : 1;
     $page_size = 20;
     $limit = ($page - 1) * $page_size . "," . $page_size;
     $root = array();
     $root['return'] = 1;
     $root['tag'] = $tag;
     $root['cid'] = $cid;
     $root['id'] = $id;
     $root['type'] = $type;
     $condition = " 1 = 1 ";
     $sort = "";
     if ($is_hot > 0) {
         $condition .= " and t.is_recommend = 1 and t.has_image = 1 ";
         $sort .= " order by  t.fav_count desc,t.relay_count desc,t.reply_count desc,t.id desc  ";
     }
     if ($is_new > 0) {
         $condition .= " and t.has_image = 1 ";
         $sort .= " order by t.create_time desc,t.id desc  ";
     }
     if ($cid > 0) {
         $condition .= " and l.cate_id = " . $cid;
     }
     if ($keyword) {
         $kws_div = div_str($keyword);
         foreach ($kws_div as $k => $item) {
             $kw[$k] = str_to_unicode_string($item);
         }
         $ukeyword = implode(" ", $kw);
         $condition .= " and match(t.keyword_match) against('" . $ukeyword . "'  IN BOOLEAN MODE) ";
     }
     $sql = "select distinct(t.id) from " . DB_PREFIX . "topic as t left join " . DB_PREFIX . "topic_cate_link as l on l.topic_id = t.id where " . $condition . $sort . " limit " . $limit;
     $sql_total = "select count(distinct(t.id)) from " . DB_PREFIX . "topic as t left join " . DB_PREFIX . "topic_cate_link as l on l.topic_id = t.id where " . $condition;
     $total = $GLOBALS['db']->getOne($sql_total);
     $result = $GLOBALS['db']->getAll($sql);
     $share_list = array();
     foreach ($result as $k => $v) {
         $share_list[$k]['share_id'] = $v['id'];
         $image = $GLOBALS['db']->getRow("select * from " . DB_PREFIX . "topic_image where topic_id = " . $v['id'] . " limit 1");
         $share_list[$k]['img'] = get_abs_img_root(get_spec_image($image['o_path'], 200, 0, 0));
         $share_list[$k]['height'] = floor($image['height'] * (200 / $image['width']));
     }
     $root['item'] = $share_list;
     //分页
     $page_info['page'] = $page;
     $page_info['page_total'] = ceil($total / $page_size);
     $root['page'] = $page_info;
     switch ($type) {
         case "index":
             $data_item = $GLOBALS['db']->getRow("select * from " . DB_PREFIX . "m_index where id = " . $id . " and city_id in (0," . intval($GLOBALS['city_id']) . ") and status = 1");
             break;
         case "adv":
             $data_item = $GLOBALS['db']->getRow("select * from " . DB_PREFIX . "m_adv where id = " . $id . " and city_id in (0," . intval($GLOBALS['city_id']) . ") and status = 1");
             break;
     }
     if ($data_item) {
         $data_item['data'] = unserialize($data_item['data']);
         foreach ($data_item['data']['tags'] as $tag_item) {
             $root['tags'][]['name'] = $tag_item;
         }
     }
     output($root);
 }
 public function index()
 {
     convert_req($_REQUEST);
     $_REQUEST['cid'] = intval($_REQUEST['cid']);
     $keyword = addslashes(htmlspecialchars(trim($_REQUEST['keyword'])));
     $GLOBALS['tmpl']->assign("keyword", $keyword);
     $url_param = array("cid" => $_REQUEST['cid'], "aid" => intval($_REQUEST['aid']), "tid" => intval($_REQUEST['tid']), "qid" => intval($_REQUEST['qid']), "min_price" => doubleval($_REQUEST['min_price']), "max_price" => doubleval($_REQUEST['max_price']), "keyword" => $keyword);
     if (intval($_REQUEST['is_redirect']) == 1) {
         app_redirect(url("youhui", "ycate", $url_param));
     }
     $site_nav[] = array('name' => $GLOBALS['lang']['HOME_PAGE'], 'url' => url("index", "index"));
     $site_nav[] = array('name' => $GLOBALS['lang']['NEED_BUY_YOUHUI'], 'url' => url("youhui", "ycate#index"));
     $GLOBALS['tmpl']->assign("site_nav", $site_nav);
     //输出当前的site_nav
     //输出热卖
     $res = search_youhui_list(app_conf("SIDE_DEAL_COUNT"), 0, "", "d.buy_count desc", true, "");
     $GLOBALS['tmpl']->assign("hot_sale_list", $res['list']);
     $seo_title = $GLOBALS['lang']['NEED_BUY_YOUHUI'];
     $seo_keyword = $GLOBALS['lang']['NEED_BUY_YOUHUI'];
     $seo_description = $GLOBALS['lang']['NEED_BUY_YOUHUI'];
     //
     $city_id = intval($GLOBALS['deal_city']['id']);
     //分页
     $page = intval($_REQUEST['p']);
     if ($page == 0) {
         $page = 1;
     }
     $limit = ($page - 1) * app_conf("DEAL_PAGE_SIZE") . "," . app_conf("DEAL_PAGE_SIZE");
     $id = intval($_REQUEST['cid']);
     if ($id == 0) {
         $uname = addslashes(trim($_REQUEST['id']));
     }
     $cate_item = $GLOBALS['db']->getRow("select * from " . DB_PREFIX . "deal_cate where id = " . $id . " or (uname = '" . $uname . "' and uname <> '')");
     $condition = " d.is_shop = 2 ";
     //条件
     $tp_url_param = $url_param;
     unset($tp_url_param['min_price']);
     unset($tp_url_param['max_price']);
     unset($tp_url_param['keyword']);
     $sub_nav[] = array("name" => $GLOBALS['lang']['FREE_YOUHUI'], "url" => url("youhui", "fcate", $tp_url_param), "current" => 0);
     $sub_nav[] = array("name" => $GLOBALS['lang']['NEED_BUY_YOUHUI'], "url" => url("youhui", "ycate", $tp_url_param), "current" => 1);
     $sub_nav[] = array("name" => $GLOBALS['lang']['TUAN'], "url" => url("youhui", "tuan", $tp_url_param), "current" => 0);
     $GLOBALS['tmpl']->assign("sub_nav", $sub_nav);
     $GLOBALS['tmpl']->assign("url_param", $tp_url_param);
     //将变量输出到模板
     $ids = load_auto_cache("deal_sub_cate_ids", array("cate_id" => intval($cate_item['id'])));
     $cache_param = array("city_id" => $city_id, "cid" => $cate_item['id'], "tid" => $url_param['tid'], "aid" => $url_param['aid'], "qid" => $url_param['qid']);
     $result = load_auto_cache("byouhui_filter_nav_cache", $cache_param);
     //输出大区
     $append_seo = "";
     $area_id = intval($_REQUEST['aid']);
     $quan_id = intval($_REQUEST['qid']);
     if ($area_id > 0) {
         $area_name = $GLOBALS['db']->getOne("select name from " . DB_PREFIX . "area where id = " . $area_id);
         $append_seo .= $area_name;
         if ($quan_id > 0) {
             $kw_unicode = str_to_unicode_string($area_name);
             //有筛选
             $condition .= " and (match(d.locate_match) against('" . $kw_unicode . "' IN BOOLEAN MODE))";
         } else {
             $ids = load_auto_cache("deal_quan_ids", array("quan_id" => $area_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);
             $condition .= " and (match(locate_match) against('" . $kw_unicode . "' IN BOOLEAN MODE))";
         }
     }
     $GLOBALS['tmpl']->assign("area_list", $result['area_list']);
     if ($area_id > 0) {
         //输出商圈
         if ($quan_id > 0) {
             $area_name = $GLOBALS['db']->getOne("select name from " . DB_PREFIX . "area where id = " . $quan_id);
             $kw_unicode = str_to_unicode_string($area_name);
             //有筛选
             $condition .= " and (match(d.locate_match) against('" . $kw_unicode . "' IN BOOLEAN MODE)) ";
             $append_seo = $append_seo . $area_name;
         }
         $GLOBALS['tmpl']->assign("quan_list", $result['quan_list']);
     }
     //输出分类
     $cate_id = $cate_item['id'];
     $GLOBALS['tmpl']->assign("cate_list", $result['cate_list']);
     //输出小分类
     $deal_type_id = intval($_REQUEST['tid']);
     $deal_cate_id = $cate_item['id'];
     $deal_quan_id = $area_id;
     if ($deal_cate_id > 0) {
         $GLOBALS['tmpl']->assign("scate_list", $result['scate_list']);
         if ($append_seo != "") {
             $append_seo .= " - ";
         }
         $append_seo .= $cate_item['name'];
     }
     //输出价格区间
     $min_price = doubleval($_REQUEST['min_price']);
     $max_price = doubleval($_REQUEST['max_price']);
     $GLOBALS['tmpl']->assign("min_price", $min_price);
     $GLOBALS['tmpl']->assign("max_price", $max_price);
     if ($min_price > 0) {
         $condition .= " and d.current_price >= " . $min_price;
     }
     if ($max_price > 0) {
         $condition .= " and d.current_price <= " . $max_price;
     }
     $sort_field = es_cookie::get("shop_sort_field") ? es_cookie::get("shop_sort_field") : "sort";
     $sort_type = es_cookie::get("shop_sort_type") ? es_cookie::get("shop_sort_type") : "desc";
     if ($sort_field != "update_time" && $sort_field != "current_price" && $sort_field != "buy_count" && $sort_field != "avg_point" && $sort_field != "sort") {
         $sort_field = "sort";
     }
     if ($sort_type != "desc" && $sort_type != "asc") {
         $sort_type = "desc";
     }
     $GLOBALS['tmpl']->assign('sort_field', $sort_field);
     $GLOBALS['tmpl']->assign('sort_type', $sort_type);
     if ($deal_type_id > 0) {
         $deal_type_name = $GLOBALS['db']->getOne("select name from " . DB_PREFIX . "deal_cate_type where id = " . $deal_type_id);
         $deal_type_name_unicode = str_to_unicode_string($deal_type_name);
         $condition .= " and (match(d.deal_cate_match) against('" . $deal_type_name_unicode . "' IN BOOLEAN MODE)) ";
         $append_seo .= $deal_type_name;
     }
     $seo_title = $append_seo . $seo_title;
     $seo_keyword = $append_seo . $seo_keyword;
     $seo_description = $append_seo . $seo_keyword;
     if ($keyword) {
         $kws_div = div_str($keyword);
         foreach ($kws_div as $k => $item) {
             $kw[$k] = str_to_unicode_string($item);
         }
         $ukeyword = implode(" ", $kw);
         $condition .= " and (match(d.name_match) against('" . $ukeyword . "'  IN BOOLEAN MODE) or d.name like '%" . $keyword . "%') ";
         $seo_title = $keyword . " - " . $seo_title;
     }
     $result = search_youhui_list($limit, intval($cate_item['id']), $condition, "d." . $sort_field . " " . $sort_type, false, "");
     $GLOBALS['tmpl']->assign("list", $result['list']);
     $page = new Page($result['count'], app_conf("DEAL_PAGE_SIZE"));
     //初始化分页对象
     $p = $page->show();
     $GLOBALS['tmpl']->assign('pages', $p);
     $GLOBALS['tmpl']->assign("cate_id", $cate_item['id']);
     //
     $GLOBALS['tmpl']->assign("page_title", $seo_title);
     $GLOBALS['tmpl']->assign("page_keyword", $seo_keyword);
     $GLOBALS['tmpl']->assign("page_description", $seo_description);
     $GLOBALS['tmpl']->display("youhui_ycate.html");
 }
Example #18
0
function syn_deal_match($deal_id)
{
    $deal = $GLOBALS['db']->getRow("select * from " . DB_PREFIX . "deal where id = " . $deal_id);
    if ($deal) {
        $deal['name_match'] = "";
        $deal['name_match_row'] = "";
        $deal['deal_cate_match'] = "";
        $deal['deal_cate_match_row'] = "";
        $deal['type_match'] = "";
        $deal['type_match_row'] = "";
        $deal['tag_match'] = "";
        $deal['tag_match_row'] = "";
        $GLOBALS['db']->autoExecute(DB_PREFIX . "deal", $deal, $mode = 'UPDATE', "id=" . $deal_id, $querymode = 'SILENT');
        //同步名称
        $name_arr = div_str(trim($deal['name']));
        foreach ($name_arr as $name_item) {
            insert_match_item($name_item, "deal", $deal_id, "name_match");
        }
        //分类类别
        $deal_cate = array();
        get_all_parent_id(intval($deal['cate_id']), DB_PREFIX . "deal_cate", $deal_cate);
        if (count($deal_cate) > 0) {
            $deal_cates = $GLOBALS['db']->getAll("select name from " . DB_PREFIX . "deal_cate where id in (" . implode(",", $deal_cate) . ")");
            foreach ($deal_cates as $row) {
                insert_match_item(trim($row['name']), "deal", $deal_id, "deal_cate_match");
            }
        }
        $goods_cate = array();
        get_all_parent_id(intval($deal['type_id']), DB_PREFIX . "deal_loan_type", $goods_cate);
        if (count($goods_cate) > 0) {
            $goods_cates = $GLOBALS['db']->getAll("select name from " . DB_PREFIX . "deal_loan_type where id in (" . implode(",", $goods_cate) . ")");
            foreach ($goods_cates as $row) {
                insert_match_item(trim($row['name']), "deal", $deal_id, "type_match");
            }
        }
    }
}
Example #19
0
 public function index()
 {
     $catalog_id = intval($GLOBALS['request']['catalog_id']);
     //商品分类ID
     $city_id = intval($GLOBALS['request']['city_id']);
     //城市分类ID
     $page = intval($GLOBALS['request']['page']);
     //分页
     $keyword = strim($GLOBALS['request']['keyword']);
     $page = $page == 0 ? 1 : $page;
     $quan_id = intval($GLOBALS['request']['quan_id']);
     //商圈id
     $ytop = $latitude_top = floatval($GLOBALS['request']['latitude_top']);
     //最上边纬线值 ypoint
     $ybottom = $latitude_bottom = floatval($GLOBALS['request']['latitude_bottom']);
     //最下边纬线值 ypoint
     $xleft = $longitude_left = floatval($GLOBALS['request']['longitude_left']);
     //最左边经度值  xpoint
     $xright = $longitude_right = floatval($GLOBALS['request']['longitude_right']);
     //最右边经度值 xpoint
     $ypoint = $m_latitude = doubleval($GLOBALS['request']['m_latitude']);
     //ypoint
     $xpoint = $m_longitude = doubleval($GLOBALS['request']['m_longitude']);
     //xpoint
     $page_size = PAGE_SIZE;
     $limit = ($page - 1) * $page_size . "," . $page_size;
     if ($keyword) {
         $kws_div = div_str($keyword);
         foreach ($kws_div as $k => $item) {
             $kws[$k] = str_to_unicode_string($item);
         }
         $ukeyword = implode(" ", $kws);
         $condition = "  (match(tag_match,name_match,locate_match,deal_cate_match) against('" . $ukeyword . "' IN BOOLEAN MODE) or name like '%" . $keyword . "%') and ";
     }
     $condition .= " buy_type<>1 and is_lottery = 0 ";
     if ($xpoint > 0) {
         $pi = 3.14159265;
         //圆周率
         $r = 6378137;
         //地球平均半径(米)
         $field_append = ", (ACOS(SIN(({$ypoint} * {$pi}) / 180 ) *SIN((ypoint * {$pi}) / 180 ) +COS(({$ypoint} * {$pi}) / 180 ) * COS((ypoint * {$pi}) / 180 ) *COS(({$xpoint} * {$pi}) / 180 - (xpoint * {$pi}) / 180 ) ) * {$r}) as distance ";
         if ($ybottom != 0 && $ytop != 0 && $xleft != 0 && $xright != 0) {
             if ($condition != "") {
                 $condition .= " and ";
             }
             $condition .= " ypoint > {$ybottom} and ypoint < {$ytop} and xpoint > {$xleft} and xpoint < {$xright} ";
         }
         $order = " distance asc,id desc ";
     } else {
         $field_append = "";
         $order = "sort desc,id desc ";
     }
     //根据传入的商圈ID来搜索该商圈下的商品
     if ($quan_id > 0) {
         $sql_q = "select name from " . DB_PREFIX . "area where id = " . intval($quan_id);
         $q_name = $GLOBALS['db']->getOne($sql_q);
         $q_name_unicode = str_to_unicode_string($q_name);
         $condition .= " and (match(locate_match) against('" . $q_name_unicode . "' IN BOOLEAN MODE))";
     }
     $deals = m_get_deal_list($limit, $catalog_id, $city_id, array(DEAL_ONLINE), $condition, $order, 0, $field_append);
     $list = $deals['list'];
     $count = $deals['count'];
     $page_total = ceil($count / $page_size);
     $root = array();
     $root['return'] = 1;
     $goodses = array();
     foreach ($list as $item) {
         //$goods = array();
         $goods = getGoodsArray($item);
         $goods['distance'] = round($goods['distance']);
         $goodses[] = $goods;
     }
     $root['item'] = $goodses;
     $root['page'] = array("page" => $page, "page_total" => $page_total, "page_size" => $page_size);
     output($root);
 }
Example #20
0
 public function index()
 {
     $l = intval($_REQUEST['l']) ? "limit " . intval($_REQUEST['l']) : "";
     $r = strim($_REQUEST['r']);
     //推荐类型
     $id = intval($_REQUEST['id']);
     //分类id
     $loc = strim($_REQUEST['loc']);
     //地区
     $tag = strim($_REQUEST['tag']);
     //标签
     $kw = strim($_REQUEST['k']);
     //关键词
     if (intval($_REQUEST['redirect']) == 1) {
         $param = array();
         if ($r != "") {
             $param = array_merge($param, array("r" => $r));
         }
         if ($id > 0) {
             $param = array_merge($param, array("id" => $id));
         }
         if ($loc != "") {
             $param = array_merge($param, array("loc" => $loc));
         }
         if ($tag != "") {
             $param = array_merge($param, array("tag" => $tag));
         }
         if ($kw != "") {
             $param = array_merge($param, array("k" => $kw));
         }
     }
     $image_list = load_dynamic_cache("INDEX_IMAGE_LIST");
     if ($image_list === false) {
         $image_list = $GLOBALS['db']->getAll("select * from " . DB_PREFIX . "index_image order by sort asc");
     }
     $cate_result = load_dynamic_cache("INDEX_CATE_LIST");
     if ($cate_result === false) {
         $cate_list = $GLOBALS['db']->getAll("select * from " . DB_PREFIX . "deal_cate order by sort asc");
         $cate_result = array();
         foreach ($cate_list as $k => $v) {
             $cate_result[$v['id']] = $v;
         }
     }
     $loc_result = load_dynamic_cache("INDEX_CATE_LOC");
     if ($loc_result === false) {
         $loc_list = $GLOBALS['db']->getAll("select province from " . DB_PREFIX . "deal GROUP by province");
         $loc_result = array();
         foreach ($loc_list as $k => $v) {
             $loc_result[$v['province']] = $v;
         }
     }
     $condition = " is_delete = 0 and is_effect = 1 ";
     if ($r != "") {
         if ($r == "new") {
             $condition .= " and " . NOW_TIME . " - begin_time < " . 24 * 3600 . " and " . NOW_TIME . " - begin_time > 0 ";
             //上线不超过一天
         }
         if ($r == "nend") {
             $condition .= " and end_time - " . NOW_TIME . " < " . 24 * 3600 . " and end_time - " . NOW_TIME . " > 0 ";
             //当天就要结束
         }
         if ($r == "classic") {
             $condition .= " and is_classic = 1 ";
         }
     }
     if ($id > 0) {
         $condition .= " and cate_id = " . $id;
     }
     if ($loc != "" && $loc != "all") {
         $condition .= " and (province = '" . $loc . "' or city = '" . $loc . "') ";
     }
     if ($tag != "") {
         $unicode_tag = str_to_unicode_string($tag);
         $condition .= " and match(tags_match) against('" . $unicode_tag . "'  IN BOOLEAN MODE) ";
     }
     if ($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(name_match) against('" . $ukeyword . "'  IN BOOLEAN MODE) or match(tags_match) against('" . $ukeyword . "'  IN BOOLEAN MODE)  or name like '%" . $kw . "%') ";
     }
     $deal_list = $GLOBALS['db']->getAll("select * from " . DB_PREFIX . "deal where " . $condition . " order by sort asc ");
     $deal_count = $GLOBALS['db']->getOne("select count(*) from " . DB_PREFIX . "deal where " . $condition);
     foreach ($deal_list as $k => $v) {
         $deal_list[$k]['support_amount'] = number_price_format($deal_list[$k]['support_amount']);
         $deal_list[$k]['image'] = APP_ROOT . substr($deal_list[$k]['image'], 1);
         $deal_list[$k]['remain_days'] = floor(($v['end_time'] - NOW_TIME) / (24 * 3600));
         $deal_list[$k]['percent'] = round($v['support_amount'] / $v['limit_price'] * 100);
         $deal_list[$k]['limit_price'] = number_format($v['limit_price']);
     }
     $arr = array('data' => $deal_list, 'total' => $deal_count);
     echo json_encode($arr);
 }
Example #21
0
 public function index()
 {
     $root = array();
     $root['return'] = 1;
     $catalog_id = intval($GLOBALS['request']['catalog_id']);
     //商品分类ID
     $cata_type_id = intval($GLOBALS['request']['cata_type_id']);
     //商品二级分类
     $city_id = intval($GLOBALS['request']['city_id']);
     //城市分类ID
     $page = intval($GLOBALS['request']['page']);
     //分页
     $keyword = strim($GLOBALS['request']['keyword']);
     $page = $page == 0 ? 1 : $page;
     $quan_id = intval($GLOBALS['request']['quan_id']);
     //商圈id
     $order_type = strim($GLOBALS['request']['order_type']);
     //if(!$city_id)
     //{
     //	$city = get_current_deal_city();
     //	$city_id = $city['id'];
     //}
     $ytop = $latitude_top = floatval($GLOBALS['request']['latitude_top']);
     //最上边纬线值 ypoint
     $ybottom = $latitude_bottom = floatval($GLOBALS['request']['latitude_bottom']);
     //最下边纬线值 ypoint
     $xleft = $longitude_left = floatval($GLOBALS['request']['longitude_left']);
     //最左边经度值  xpoint
     $xright = $longitude_right = floatval($GLOBALS['request']['longitude_right']);
     //最右边经度值 xpoint
     $ypoint = $m_latitude = doubleval($GLOBALS['request']['m_latitude']);
     //ypoint
     $xpoint = $m_longitude = doubleval($GLOBALS['request']['m_longitude']);
     //xpoint
     /*输出分类*/
     $bcate_list = getCateList();
     $url_param['quan_id'] = $quan_id;
     $url_param['catalog_id'] = $catalog_id;
     $url_param['cata_type_id'] = $cata_type_id;
     foreach ($bcate_list as $k => $v) {
         $tmp_url_param = $url_param;
         unset($tmp_url_param['catalog_id']);
         $tmp_url_param['catalog_id'] = $v['id'];
         $tmp_url_param['catename'] = $v['name'];
         if ($quan_id > 0) {
             $quanname = $GLOBALS['db']->getOne("select name from " . DB_PREFIX . "area where id=" . $quan_id);
             $tmp_url_param['quanname'] = $quanname;
         } else {
             $tmp_url_param['quanname'] = "全城";
         }
         $turl = wap_url("index", "tuanlist", $tmp_url_param);
         $url = str_replace('sjmapi', 'wap', $turl);
         $bcate_list[$k]["url"] = $url;
         foreach ($v['bcate_type'] as $kk => $vv) {
             $tmp_url_param = $url_param;
             unset($tmp_url_param['cata_type_id']);
             $tmp_url_param['cata_type_id'] = $vv["id"];
             $tmp_url_param['catename'] = $vv['name'];
             $tmp_url_param['catalog_id'] = $vv['cate_id'];
             if ($quan_id > 0) {
                 $quanname = $GLOBALS['db']->getOne("select name from " . DB_PREFIX . "area  where id=" . $quan_id);
                 $tmp_url_param['quanname'] = $quanname;
             } else {
                 $tmp_url_param['quanname'] = "全城";
             }
             $turl = wap_url("index", "tuanlist", $tmp_url_param);
             $url = str_replace('sjmapi', 'wap', $turl);
             $bcate_list[$k]["bcate_type"][$kk]["url"] = $url;
         }
     }
     /*输出商圈*/
     $quan_list = getQuanList($city_id);
     foreach ($quan_list as $k => $v) {
         $tmp_url_param = $url_param;
         unset($tmp_url_param['quan_id']);
         $tmp_url_param['quan_id'] = $v['id'];
         $tmp_url_param['quanname'] = $v['name'];
         if ($catalog_id > 0) {
             $catename = $GLOBALS['db']->getOne("select name from " . DB_PREFIX . "deal_cate  where id=" . $catalog_id);
             $tmp_url_param['catename'] = $catename;
         } else {
             $tmp_url_param['catename'] = "全部分类";
         }
         $turl = wap_url("index", "tuanlist", $tmp_url_param);
         $url = str_replace('sjmapi', 'wap', $turl);
         $quan_list[$k]["url"] = $url;
         foreach ($v['quan_sub'] as $kk => $vv) {
             $tmp_url_param = $url_param;
             unset($tmp_url_param['quan_id']);
             $tmp_url_param['quan_id'] = $vv['id'];
             $tmp_url_param['quanname'] = $vv['name'];
             if ($catalog_id > 0) {
                 $catename = $GLOBALS['db']->getOne("select name from " . DB_PREFIX . "deal_cate  where id=" . $catalog_id);
                 $tmp_url_param['catename'] = $catename;
             } else {
                 $tmp_url_param['catename'] = "全部分类";
             }
             $turl = wap_url("index", "tuanlist", $tmp_url_param);
             $url = str_replace('sjmapi', 'wap', $turl);
             $quan_list[$k]["quan_sub"][$kk]["url"] = $url;
         }
     }
     $page_size = PAGE_SIZE;
     $limit = ($page - 1) * $page_size . "," . $page_size;
     if ($keyword) {
         $kws_div = div_str($keyword);
         foreach ($kws_div as $k => $item) {
             $kws[$k] = str_to_unicode_string($item);
         }
         $ukeyword = implode(" ", $kws);
         $condition = "  (match(tag_match,name_match,locate_match,deal_cate_match) against('" . $ukeyword . "' IN BOOLEAN MODE) or name like '%" . $keyword . "%') and ";
     }
     //buy_type 0普通团购;2在线订购;3秒杀抢团
     //is_shop 0团购;1:商品;
     $condition .= " buy_type = 0 and is_shop = 0 and is_lottery = 0 ";
     if ($xpoint > 0) {
         $pi = 3.14159265;
         //圆周率
         $r = 6378137;
         //地球平均半径(米)
         $field_append = ", (ACOS(SIN(({$ypoint} * {$pi}) / 180 ) *SIN((ypoint * {$pi}) / 180 ) +COS(({$ypoint} * {$pi}) / 180 ) * COS((ypoint * {$pi}) / 180 ) *COS(({$xpoint} * {$pi}) / 180 - (xpoint * {$pi}) / 180 ) ) * {$r}) as distance ";
         if ($ybottom != 0 && $ytop != 0 && $xleft != 0 && $xright != 0) {
             if ($condition != "") {
                 $condition .= " and ";
             }
             $condition .= " ypoint > {$ybottom} and ypoint < {$ytop} and xpoint > {$xleft} and xpoint < {$xright} ";
         }
         $order = " distance asc,id desc ";
     } else {
         $order = "sort desc,id desc ";
     }
     /*排序  
     		 智能排序和 离我最的 是一样的 都以距离来升序来排序,只有这两种情况有传经纬度过来,就没有把 这两种情况写在 下面的判断里,写在上面了。
     		default 智能(默认),nearby  离我,avg_point 评价,newest 最新,buy_count 人气,price_asc 价低,price_desc 价高 */
     $ordertype[] = array("name" => "默认排序", "sc" => "avg_point");
     $ordertype[] = array("name" => "最新发布", "sc" => "newest");
     $ordertype[] = array("name" => "销量最高", "sc" => "buy_count");
     $ordertype[] = array("name" => "价格最高", "sc" => "price_desc");
     $ordertype[] = array("name" => "价格最低", "sc" => "price_asc");
     foreach ($ordertype as $k => $v) {
         $tmp_url_param = $url_param;
         if ($quanname) {
             $tmp_url_param['quanname'] = $quanname;
         }
         if ($catename) {
             $tmp_url_param['catename'] = $catename;
         }
         if ($keyword) {
             $tmp_url_param['keyword'] = $keyword;
         }
         $tmp_url_param['order_type'] = $v['sc'];
         $turl = wap_url("index", "goodslist", $tmp_url_param);
         $url = str_replace('sjmapi', 'wap', $turl);
         $ordertype[$k]["url"] = $url;
     }
     $root['ordertype'] = $ordertype;
     if ($order_type == 'avg_point') {
         /*评价*/
         $order = " avg_point desc,id desc ";
     } elseif ($order_type == 'newest') {
         /*最新*/
         $order = " create_time desc,id desc ";
     } elseif ($order_type == 'buy_count') {
         /*销量*/
         $order = " buy_count desc,id desc ";
     } elseif ($order_type == 'price_asc') {
         /*价格升*/
         $order = " current_price asc,id desc ";
     } elseif ($order_type == 'price_desc') {
         /*价格降*/
         $order = " current_price desc,id desc ";
     }
     //根据传入的商圈ID来搜索该商圈下的商品
     if ($quan_id > 0) {
         $sql_q = "select name from " . DB_PREFIX . "area where id = " . intval($quan_id);
         $q_name = $GLOBALS['db']->getOne($sql_q);
         $q_name_unicode = str_to_unicode_string($q_name);
         $condition .= " and (match(locate_match) against('" . $q_name_unicode . "' IN BOOLEAN MODE))";
     }
     $deals = m_get_deal_list($limit, $catalog_id, $city_id, array(DEAL_ONLINE), $condition, $order, 0, $field_append, $cata_type_id);
     $list = $deals['list'];
     $count = $deals['count'];
     $page_total = ceil($count / $page_size);
     //$root['sql'] = $deals['sql'];
     $taday_begin = to_timespan(to_date(get_gmtime(), 'Y-m-d'));
     $taday_end = $taday_begin * 24 * 60 * 60;
     $goodses = array();
     foreach ($list as $k => $v) {
         $goodses[$k]['id'] = $v['id'];
         $goodses[$k]['distance'] = $v['distance'];
         $goodses[$k]['ypoint'] = $v['ypoint'];
         $goodses[$k]['xpoint'] = $v['xpoint'];
         $goodses[$k]['name'] = $v['name'];
         $goodses[$k]['sub_name'] = $v['sub_name'];
         $goodses[$k]['goods_brief'] = $v['brief'];
         $goodses[$k]['buy_count'] = $v['buy_count'];
         $goodses[$k]['auto_order'] = $v['auto_order'];
         $goodses[$k]['current_price'] = round($v['current_price'], 2);
         $goodses[$k]['origin_price'] = round($v['origin_price'], 2);
         $goodses[$k]['icon'] = get_abs_img_root(get_spec_image($v['icon'], 140, 85, 0));
         if ($v['begin_time'] > 0 && ($taday_begin < $v['begin_time'] && $v['begin_time'] < $taday_end)) {
             $goodses[$k]['is_taday'] = 1;
         } else {
             if ($v['begin_time'] == 0 && ($taday_begin < $v['create_time'] && $v['create_time'] < $taday_end)) {
                 $goodses[$k]['is_taday'] = 1;
             } else {
                 $goodses[$k]['is_taday'] = 0;
             }
         }
     }
     $root['city_id'] = $city_id;
     $root['quan_id'] = $quan_id;
     $root['catalog_id'] = $catalog_id;
     $root['page_title'] = "团购列表";
     $root['page'] = array("page" => $page, "page_total" => $page_total, "page_size" => $page_size);
     if ($goodses === false) {
         $root['item'] = array();
     } else {
         $root['item'] = $goodses;
     }
     if ($bcate_list === false) {
         $root[''] = array();
     } else {
         $root['bcate_list'] = $bcate_list;
     }
     if ($quan_list === false) {
         $root['quan_list'] = array();
     } else {
         $root['quan_list'] = $quan_list;
     }
     output($root);
 }
 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);
 }
 public function search_supplier()
 {
     if (intval($GLOBALS['db']->getOne("select count(*) from " . DB_PREFIX . "supplier")) < 50000) {
         $sql = "select * from " . DB_PREFIX . "supplier where name like '%" . trim($_REQUEST['key']) . "%' limit 30";
     } else {
         $kws_div = div_str(trim($_REQUEST['key']));
         foreach ($kws_div as $k => $item) {
             $kw[$k] = str_to_unicode_string($item);
         }
         $kw_unicode = implode(" ", $kw);
         $sql = "select * from " . DB_PREFIX . "supplier where (match(name_match) against('" . $kw_unicode . "' IN BOOLEAN MODE)) limit 30";
     }
     $supplier_list = $GLOBALS['db']->getAll($sql);
     $this->assign("supplier_list", $supplier_list);
     $this->display();
 }
Example #24
0
 public function deals()
 {
     $r = strim($_REQUEST['r']);
     //推荐类型
     $id = intval($_REQUEST['id']);
     //分类id
     $loc = strim($_REQUEST['loc']);
     //地区
     $tag = strim($_REQUEST['tag']);
     //标签
     $kw = strim($_REQUEST['k']);
     //关键词
     $page_size = DEAL_PAGE_SIZE;
     $step_size = DEAL_STEP_SIZE;
     $step = intval($_REQUEST['step']);
     if ($step == 0) {
         $step = 1;
     }
     $page = intval($_REQUEST['p']);
     if ($page == 0) {
         $page = 1;
     }
     $limit = ($page - 1) * $page_size + ($step - 1) * $step_size . "," . $step_size;
     $condition = " is_delete = 0 and is_effect = 1 ";
     if ($r != "") {
         if ($r == "new") {
             $condition .= " and " . NOW_TIME . " - begin_time < " . 24 * 3600 . " and " . NOW_TIME . " - begin_time > 0 ";
             //上线不超过一天
         }
         if ($r == "nend") {
             $condition .= " and end_time - " . NOW_TIME . " < " . 24 * 3600 . " and end_time - " . NOW_TIME . " > 0 ";
             //当天就要结束
         }
         if ($r == "classic") {
             $condition .= " and is_classic = 1 ";
         }
     }
     if ($id > 0) {
         $condition .= " and cate_id = " . $id;
     }
     if ($loc != "") {
         $condition .= " and (province = '" . $loc . "' or city = '" . $loc . "') ";
     }
     if ($tag != "") {
         $unicode_tag = str_to_unicode_string($tag);
         $condition .= " and match(tags_match) against('" . $unicode_tag . "'  IN BOOLEAN MODE) ";
     }
     if ($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(name_match) against('" . $ukeyword . "'  IN BOOLEAN MODE) or match(tags_match) against('" . $ukeyword . "'  IN BOOLEAN MODE)  or name like '%" . $kw . "%') ";
     }
     $deal_list = $GLOBALS['db']->getAll("select * from " . DB_PREFIX . "deal where " . $condition . " order by sort asc limit " . $limit);
     $deal_count = $GLOBALS['db']->getOne("select count(*) from " . DB_PREFIX . "deal where " . $condition);
     foreach ($deal_list as $k => $v) {
         $deal_list[$k]['remain_days'] = floor(($v['end_time'] - NOW_TIME) / (24 * 3600));
         $deal_list[$k]['percent'] = round($v['support_amount'] / $v['limit_price'] * 100);
     }
     $GLOBALS['tmpl']->assign("deal_list", $deal_list);
     $data['html'] = $GLOBALS['tmpl']->fetch("inc/deal_list.html");
     if ($step * $step_size < $page_size) {
         if ($deal_count <= ($page - 1) * $page_size + ($step - 1) * $step_size + $step_size) {
             $data['step'] = 0;
             ajax_return($data);
         } else {
             $data['step'] = $step + 1;
             ajax_return($data);
         }
     } else {
         $data['step'] = 0;
         ajax_return($data);
     }
 }
 public function index()
 {
     convert_req($_REQUEST);
     $_REQUEST['cid'] = intval($_REQUEST['cid']);
     $keyword = addslashes(htmlspecialchars(trim($_REQUEST['keyword'])));
     $GLOBALS['tmpl']->assign("keyword", $keyword);
     $url_param = array("cid" => $_REQUEST['cid'], "aid" => intval($_REQUEST['aid']), "tid" => intval($_REQUEST['tid']), "qid" => intval($_REQUEST['qid']), "keyword" => $keyword);
     if (intval($_REQUEST['is_redirect']) == 1) {
         app_redirect(url("youhui", "fcate", $url_param));
     }
     $quan_id = intval($_REQUEST['qid']);
     //
     $city_id = intval($GLOBALS['deal_city']['id']);
     //分页
     $page = intval($_REQUEST['p']);
     if ($page == 0) {
         $page = 1;
     }
     $limit = ($page - 1) * app_conf("DEAL_PAGE_SIZE") . "," . app_conf("DEAL_PAGE_SIZE");
     $cid = intval($_REQUEST['cid']);
     if ($cid == 0) {
         $uname = addslashes(trim($_REQUEST['cid']));
     }
     $cate_item = $GLOBALS['db']->getRow("select * from " . DB_PREFIX . "deal_cate where id = " . $cid . " or (uname = '" . $uname . "' and uname <> '')");
     $free_youhui_list = get_free_youhui_list(5, intval($cate_item['id']), " is_recommend = 1 ", "");
     $GLOBALS['tmpl']->assign("free_youhui_list", $free_youhui_list['list']);
     $condition = " 1=1 ";
     //条件
     unset($url_param['keyword']);
     $sub_nav[] = array("name" => $GLOBALS['lang']['FREE_YOUHUI'], "url" => url("youhui", "fcate", $url_param), "current" => 1);
     $sub_nav[] = array("name" => $GLOBALS['lang']['NEED_BUY_YOUHUI'], "url" => url("youhui", "ycate", $url_param), "current" => 0);
     $sub_nav[] = array("name" => $GLOBALS['lang']['TUAN'], "url" => url("youhui", "tuan", $url_param), "current" => 0);
     $GLOBALS['tmpl']->assign("sub_nav", $sub_nav);
     $GLOBALS['tmpl']->assign("url_param", $url_param);
     //将变量输出到模板
     $seo_title = $GLOBALS['lang']['FREE_YOUHUI'];
     $seo_keyword = $GLOBALS['lang']['FREE_YOUHUI'];
     $seo_description = $GLOBALS['lang']['FREE_YOUHUI'];
     $cache_param = array("city_id" => $city_id, "cid" => $cate_item['id'], "tid" => $url_param['tid'], "aid" => $url_param['aid'], "qid" => $url_param['qid']);
     $result = load_auto_cache("fyouhui_filter_nav_cache", $cache_param);
     //输出行政区
     $append_seo = "";
     $area_id = intval($_REQUEST['aid']);
     if ($area_id > 0) {
         $area_name = $GLOBALS['db']->getOne("select name from " . DB_PREFIX . "area where id = " . $area_id);
         $append_seo = $area_name;
         if ($quan_id > 0) {
             $kw_unicode = str_to_unicode_string($area_name);
             //有筛选
             $condition .= " and (match(locate_match) against('" . $kw_unicode . "' IN BOOLEAN MODE)) ";
         } else {
             $ids = load_auto_cache("deal_quan_ids", array("quan_id" => $area_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);
             $condition .= " and (match(locate_match) against('" . $kw_unicode . "' IN BOOLEAN MODE))";
         }
     }
     $GLOBALS['tmpl']->assign("area_list", $result['area_list']);
     if ($area_id > 0) {
         //输出商圈
         if ($quan_id > 0) {
             $area_name = $GLOBALS['db']->getOne("select name from " . DB_PREFIX . "area where id = " . $quan_id);
             $kw_unicode = str_to_unicode_string($area_name);
             //有筛选
             $condition .= " and (match(locate_match) against('" . $kw_unicode . "' IN BOOLEAN MODE)) ";
             $append_seo = $append_seo . $area_name;
         }
         $GLOBALS['tmpl']->assign("quan_list", $result['quan_list']);
     }
     //输出分类
     $cate_id = $cate_item['id'];
     $GLOBALS['tmpl']->assign("cate_list", $result['cate_list']);
     //输出小分类
     $deal_type_id = intval($_REQUEST['tid']);
     $deal_cate_id = $cate_id;
     if ($deal_cate_id > 0) {
         $GLOBALS['tmpl']->assign("scate_list", $result['scate_list']);
         if ($append_seo != "") {
             $append_seo .= " - ";
         }
         $append_seo .= $cate_item['name'];
     }
     if ($deal_type_id > 0) {
         $deal_type_name = $GLOBALS['db']->getOne("select name from " . DB_PREFIX . "deal_cate_type where id = " . $deal_type_id);
         $deal_type_name_unicode = str_to_unicode_string($deal_type_name);
         $condition .= " and (match(deal_cate_match) against('" . $deal_type_name_unicode . "' IN BOOLEAN MODE)) ";
         $append_seo .= $deal_type_name;
     }
     $seo_title = $append_seo . $seo_title;
     $seo_keyword = $append_seo . $seo_keyword;
     $seo_description = $append_seo . $seo_keyword;
     if ($keyword) {
         $kws_div = div_str($keyword);
         foreach ($kws_div as $k => $item) {
             $kw[$k] = str_to_unicode_string($item);
         }
         $ukeyword = implode(" ", $kw);
         $condition .= " and (match(name_match) against('" . $ukeyword . "'  IN BOOLEAN MODE) or name like '%" . $keyword . "%') ";
         $seo_title = $keyword . " - " . $seo_title;
     }
     $result = get_free_youhui_list($limit, $cate_id, $condition, "");
     $GLOBALS['tmpl']->assign("list", $result['list']);
     $page = new Page($result['count'], app_conf("DEAL_PAGE_SIZE"));
     //初始化分页对象
     $p = $page->show();
     $GLOBALS['tmpl']->assign('pages', $p);
     //
     $site_nav[] = array('name' => $GLOBALS['lang']['HOME_PAGE'], 'url' => url("index", "index"));
     $site_nav[] = array('name' => $GLOBALS['lang']['FREE_YOUHUI'], 'url' => url("youhui", "fcate"));
     if ($_GET['model'] == "app") {
         echo json_encode(array('ret' => 1));
     } else {
         $GLOBALS['tmpl']->assign("site_nav", $site_nav);
         $GLOBALS['tmpl']->assign("page_title", $seo_title);
         $GLOBALS['tmpl']->assign("page_keyword", $seo_keyword . ",");
         $GLOBALS['tmpl']->assign("page_description", $seo_description . ",");
         $GLOBALS['tmpl']->display("youhui_fcate.html");
     }
 }
 public function index()
 {
     $GLOBALS['tmpl']->assign("page_title", "最新动态");
     $param = array();
     //参数集合
     //数据来源参数
     $r = strim($_REQUEST['r']);
     //推荐类型
     $param['r'] = $r ? $r : '';
     $GLOBALS['tmpl']->assign("p_r", $r);
     $id = intval($_REQUEST['id']);
     //分类id
     $param['id'] = $id;
     $GLOBALS['tmpl']->assign("p_id", $id);
     $loc = strim($_REQUEST['loc']);
     //地区
     $param['loc'] = $loc;
     $GLOBALS['tmpl']->assign("p_loc", $loc);
     $state = intval($_REQUEST['state']);
     //状态
     $param['state'] = $state;
     $GLOBALS['tmpl']->assign("p_state", $state);
     $tag = strim($_REQUEST['tag']);
     //标签
     $param['tag'] = $tag;
     $GLOBALS['tmpl']->assign("p_tag", $tag);
     $kw = strim($_REQUEST['k']);
     //关键词
     $param['k'] = $kw;
     $GLOBALS['tmpl']->assign("p_k", $kw);
     $type = intval($_REQUEST['type']);
     //推荐类型
     $param['type'] = $type;
     $GLOBALS['tmpl']->assign("p_type", $type);
     if (intval($_REQUEST['redirect']) == 1) {
         $param = array();
         if ($r != "") {
             $param = array_merge($param, array("r" => $r));
         }
         if ($id > 0) {
             $param = array_merge($param, array("id" => $id));
         }
         if ($loc != "") {
             $param = array_merge($param, array("loc" => $loc));
         }
         if ($state != "") {
             $param = array_merge($param, array("state" => $state));
         }
         if ($tag != "") {
             $param = array_merge($param, array("tag" => $tag));
         }
         if ($kw != "") {
             $param = array_merge($param, array("k" => $kw));
         }
         if ($type != "") {
             $param = array_merge($param, array("type" => $type));
         }
         app_redirect(url_wap("deals", $param));
     }
     $image_list = load_dynamic_cache("INDEX_IMAGE_LIST");
     if ($image_list === false) {
         $image_list = $GLOBALS['db']->getAll("select * from " . DB_PREFIX . "index_image order by sort asc");
         set_dynamic_cache("INDEX_IMAGE_LIST", $image_list);
     }
     $GLOBALS['tmpl']->assign("image_list", $image_list);
     $cate_list = load_dynamic_cache("INDEX_CATE_LIST");
     if (!$cate_list) {
         $cate_list = $GLOBALS['db']->getAll("select * from " . DB_PREFIX . "deal_cate order by sort asc");
         set_dynamic_cache("INDEX_CATE_LIST", $cate_list);
     }
     $cate_result = array();
     foreach ($cate_list as $k => $v) {
         if ($v['pid'] == 0) {
             $temp_param = $param;
             $cate_result[$v['id']]['id'] = $v['id'];
             $cate_result[$v['id']]['name'] = $v['name'];
             $temp_param['id'] = $v['id'];
             $cate_result[$v['id']]['url'] = url_wap("deals", $temp_param);
         } else {
             if ($v['pid'] > 0) {
                 $temp_param['id'] = $v['id'];
                 $cate_result[$v['pid']]['child'][] = array('id' => $v['id'], 'name' => $v['name'], 'url' => url_wap("deals", $temp_param));
             }
         }
         if ($v['id'] == $id) {
             $GLOBALS['tmpl']->assign("cate_name", $v['name']);
         }
     }
     $GLOBALS['tmpl']->assign("cate_list", $cate_result);
     $pid = $id;
     //获取父类id
     if ($cate_list) {
         $pid = $this->get_child($cate_list, $pid);
     }
     /*子分类 start*/
     $cate_ids = array();
     $is_child = false;
     $temp_cate_ids = array();
     if ($cate_list) {
         $child_cate_result = array();
         foreach ($cate_list as $k => $v) {
             if ($v['pid'] == $pid) {
                 if ($v['id'] > 0) {
                     $temp_param = $param;
                     $child_cate_result[$v['id']]['id'] = $v['id'];
                     $child_cate_result[$v['id']]['name'] = $v['name'];
                     $temp_param['id'] = $v['id'];
                     $child_cate_result[$v['id']]['url'] = url_wap("deals", $temp_param);
                     if ($id == $v['id']) {
                         $is_child = true;
                     }
                 }
             }
             if ($v['pid'] == $pid || $pid == 0) {
                 $temp_cate_ids[] = $v['id'];
             }
         }
     }
     //假如选择了子类 那么使用子类ID  否则使用 父类和其子类
     if ($is_child) {
         $cate_ids[] = $id;
     } else {
         $cate_ids[] = $pid;
         $cate_ids = array_merge($cate_ids, $temp_cate_ids);
     }
     $cate_ids = array_filter($cate_ids);
     $GLOBALS['tmpl']->assign("child_cate_list", $child_cate_result);
     $GLOBALS['tmpl']->assign("pid", $pid);
     /*子分类 end*/
     $city_list = load_dynamic_cache("INDEX_CITY_LIST");
     if ($type == 1) {
         if (!$city_list) {
             $city_list = $GLOBALS['db']->getAll("select province from " . DB_PREFIX . "deal where type=1 and is_effect =1 group by province  order by sort asc");
             //	set_dynamic_cache("INDEX_CITY_LIST",$city_list);
         }
     }
     if ($type == 0) {
         if (!$city_list) {
             $city_list = $GLOBALS['db']->getAll("select province from " . DB_PREFIX . "deal where type=0 and is_effect =1 group by province  order by sort asc");
             //	set_dynamic_cache("INDEX_CITY_LIST",$city_list);
         }
     }
     foreach ($city_list as $k => $v) {
         $temp_param = $param;
         $temp_param['loc'] = $v['province'];
         $city_list[$k]['url'] = url_wap("deals", $temp_param);
         if ($v['id']) {
             $child = $GLOBALS['db']->getAll("select * from " . DB_PREFIX . "region_conf where pid=" . $v['id']);
             if ($child) {
                 foreach ($child as $k1 => $v1) {
                     $temp_param['loc'] = $v1['name'];
                     $child[$k1]['url'] = url_wap("deals", $temp_param);
                 }
                 $city_list[$k]['child'] = $child;
             }
         }
     }
     $GLOBALS['tmpl']->assign("city_list", $city_list);
     //=================region_conf==============
     $state_list = array(1 => array("name" => "筹资成功"), 2 => array("name" => "筹资失败"), 3 => array("name" => "筹资中"));
     foreach ($state_list as $k => $v) {
         $temp_param = $param;
         $temp_param['state'] = $k;
         $state_list[$k]['url'] = url_wap("deals", $temp_param);
     }
     if ($state == 0) {
         $GLOBALS['tmpl']->assign("state_name", "所有项目");
     } else {
         $GLOBALS['tmpl']->assign("state_name", $state_list[$state]['name']);
     }
     $GLOBALS['tmpl']->assign("state_list", $state_list);
     $page_size = PAGE_SIZE;
     $step_size = PAGE_SIZE;
     $step = intval($_REQUEST['step']);
     if ($step == 0) {
         $step = 1;
     }
     $page = intval($_REQUEST['p']);
     if ($page == 0) {
         $page = 1;
     }
     $limit = ($page - 1) * $page_size + ($step - 1) * $step_size . "," . $step_size;
     $GLOBALS['tmpl']->assign("current_page", $page);
     $condition = " d.is_delete = 0 and d.is_effect = 1 ";
     if ($r != "") {
         if ($r == "new") {
             $condition .= " and " . NOW_TIME . " - d.begin_time < " . 7 * 24 * 3600 . " and " . NOW_TIME . " - d.begin_time > 0 ";
             //上线不超过一天
             $GLOBALS['tmpl']->assign("page_title", "最新上线");
         } elseif ($r == "rec") {
             $condition .= " and d.is_recommend = 1 ";
             $GLOBALS['tmpl']->assign("page_title", "推荐项目");
         } elseif ($r == "yure") {
             $condition .= "   and " . NOW_TIME . " <  d.begin_time ";
             $GLOBALS['tmpl']->assign("page_title", "正在预热");
         } elseif ($r == "nend") {
             $condition .= " and d.end_time - " . NOW_TIME . " < " . 7 * 24 * 3600 . " and d.end_time - " . NOW_TIME . " > 0 ";
             //三天就要结束
             $GLOBALS['tmpl']->assign("page_title", "即将结束");
         } elseif ($r == "classic") {
             $condition .= " and d.is_classic = 1 ";
             $GLOBALS['tmpl']->assign("page_title", "经典项目");
             $GLOBALS['tmpl']->assign("is_classic", true);
         } elseif ($r == "limit_price") {
             $condition .= " and max(d.limit_price) ";
             $GLOBALS['tmpl']->assign("page_title", "最高目标金额");
         }
     }
     switch ($state) {
         //筹资成功
         case 1:
             $condition .= " and d.is_success=1  and d.end_time < " . NOW_TIME;
             $GLOBALS['tmpl']->assign("page_title", "筹资成功");
             break;
             //筹资失败
         //筹资失败
         case 2:
             $condition .= " and d.end_time < " . NOW_TIME . " and d.end_time!=0  and d.is_success=0  ";
             $GLOBALS['tmpl']->assign("page_title", "筹资失败");
             break;
             //筹资中
         //筹资中
         case 3:
             $condition .= " and (d.end_time > " . NOW_TIME . " or d.end_time=0 ) and d.begin_time < " . NOW_TIME . "   ";
             $GLOBALS['tmpl']->assign("page_title", "筹资中");
             break;
     }
     if (count($cate_ids) > 0) {
         $condition .= " and d.cate_id in (" . implode(",", $cate_ids) . ")";
         $GLOBALS['tmpl']->assign("page_title", $cate_result[$id]['name']);
     }
     if ($loc != "") {
         $condition .= " and (d.province = '" . $loc . "' or city = '" . $loc . "') ";
         $GLOBALS['tmpl']->assign("page_title", $loc);
     }
     if ($tag != "") {
         $unicode_tag = str_to_unicode_string($tag);
         $condition .= " and match(d.tags_match) against('" . $unicode_tag . "'  IN BOOLEAN MODE) ";
         $GLOBALS['tmpl']->assign("page_title", $tag);
     }
     if ($type !== "") {
         $type = intval($type);
         $condition .= " and type={$type} ";
     }
     if ($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.name_match) against('" . $ukeyword . "'  IN BOOLEAN MODE) or match(d.tags_match) against('" . $ukeyword . "'  IN BOOLEAN MODE)  or d.name like '%" . $kw . "%') ";
         $GLOBALS['tmpl']->assign("page_title", $kw);
     }
     $result = get_deal_list($limit, $condition);
     foreach ($result['list'] as $k => $v) {
     }
     $GLOBALS['tmpl']->assign("deal_list", $result['list']);
     $GLOBALS['tmpl']->assign("deal_count", intval($result['rs_count']));
     $page = new Page($result['rs_count'], $page_size);
     //初始化分页对象
     $p = $page->show();
     $GLOBALS['tmpl']->assign('pages', $p);
     $GLOBALS['tmpl']->assign("usermessage_url", url_wap("ajax#usermessage", array("id" => intval($GLOBALS['user_info']['id']))));
     $GLOBALS['tmpl']->display("deals_index.html");
 }
 public function index()
 {
     convert_req($_REQUEST);
     $_REQUEST['cid'] = intval($_REQUEST['cid']);
     $keyword = addslashes(htmlspecialchars(trim($_REQUEST['keyword'])));
     //获取当前页的团购商品列表
     require_once APP_ROOT_PATH . 'app/Lib/page.php';
     $city_id = intval($GLOBALS['deal_city']['id']);
     //分页
     $page = intval($_REQUEST['p']);
     if ($page == 0) {
         $page = 1;
     }
     $limit = ($page - 1) * app_conf("DEAL_PAGE_SIZE") . "," . app_conf("DEAL_PAGE_SIZE");
     $cate_list = load_auto_cache("cache_deal_cate");
     $cid = intval($_REQUEST['cid']);
     $uname = addslashes(trim($_REQUEST['cid']));
     //$cate_item = $GLOBALS['db']->getRow("select * from ".DB_PREFIX."deal_cate where id = ".$cid." or (uname = '".$uname."' and uname <> '')");
     $cate_item = $cate_list[$cid];
     $condition = " 1=1 ";
     //条件
     $base_param = $url_param = array("cid" => $_REQUEST['cid'], "aid" => intval($_REQUEST['aid']), "tid" => intval($_REQUEST['tid']), "qid" => intval($_REQUEST['qid']), "keyword" => $keyword, "minprice" => $minprice = doubleval($_REQUEST['minprice']) > 0 ? doubleval($_REQUEST['minprice']) : 0, "maxprice" => $maxprice = doubleval($_REQUEST['maxprice']) > 0 ? doubleval($_REQUEST['maxprice']) : 0);
     //组装分组筛选
     if ($_REQUEST['g'] && is_array($_REQUEST['g'])) {
         foreach ($_REQUEST['g'] as $k => $v) {
             $url_param["g[" . $k . "]"] = addslashes(trim($v));
         }
     }
     if (intval($_REQUEST['is_redirect']) == 1) {
         app_redirect(url("youhui", "store", $url_param));
     }
     $GLOBALS['tmpl']->assign("url_param", $url_param);
     //将变量输出到模板
     unset($url_param['keyword']);
     unset($url_param['minprice']);
     unset($url_param['maxprice']);
     $cache_param = $url_param;
     $cache_param['cid'] = $cate_item['id'];
     $cache_param['city_id'] = $city_id;
     $result = load_auto_cache("store_filter_nav_cache", $cache_param);
     $filter_url_param = $base_param;
     $filter_url_param['has_tuan'] = intval($_REQUEST['has_tuan']);
     $filter_url_param['has_daijin'] = intval($_REQUEST['has_daijin']);
     $filter_url_param['has_youhui'] = intval($_REQUEST['has_youhui']);
     $filter_url_param['has_event'] = intval($_REQUEST['has_event']);
     $filter_url_param['has_goods'] = intval($_REQUEST['has_goods']);
     $filter_url_param['is_verify'] = intval($_REQUEST['is_verify']);
     $GLOBALS['tmpl']->assign("filter_url_param", $filter_url_param);
     $tmpfilter_url_param = $filter_url_param;
     if ($filter_url_param['has_tuan'] == 1) {
         $tmpfilter_url_param['has_tuan'] = 0;
     } else {
         $tmpfilter_url_param['has_tuan'] = 1;
     }
     $filter_url['has_tuan'] = url("youhui", "store", $tmpfilter_url_param);
     $tmpfilter_url_param = $filter_url_param;
     if ($filter_url_param['has_daijin'] == 1) {
         $tmpfilter_url_param['has_daijin'] = 0;
     } else {
         $tmpfilter_url_param['has_daijin'] = 1;
     }
     $filter_url['has_daijin'] = url("youhui", "store", $tmpfilter_url_param);
     $tmpfilter_url_param = $filter_url_param;
     if ($filter_url_param['has_youhui'] == 1) {
         $tmpfilter_url_param['has_youhui'] = 0;
     } else {
         $tmpfilter_url_param['has_youhui'] = 1;
     }
     $filter_url['has_youhui'] = url("youhui", "store", $tmpfilter_url_param);
     $tmpfilter_url_param = $filter_url_param;
     if ($filter_url_param['has_event'] == 1) {
         $tmpfilter_url_param['has_event'] = 0;
     } else {
         $tmpfilter_url_param['has_event'] = 1;
     }
     $filter_url['has_event'] = url("youhui", "store", $tmpfilter_url_param);
     $tmpfilter_url_param = $filter_url_param;
     if ($filter_url_param['has_goods'] == 1) {
         $tmpfilter_url_param['has_goods'] = 0;
     } else {
         $tmpfilter_url_param['has_goods'] = 1;
     }
     $filter_url['has_goods'] = url("youhui", "store", $tmpfilter_url_param);
     $tmpfilter_url_param = $filter_url_param;
     if ($filter_url_param['is_verify'] == 1) {
         $tmpfilter_url_param['is_verify'] = 0;
     } else {
         $tmpfilter_url_param['is_verify'] = 1;
     }
     $filter_url['is_verify'] = url("youhui", "store", $tmpfilter_url_param);
     $GLOBALS['tmpl']->assign("filter_url", $filter_url);
     //输出大区
     $seo_title = $GLOBALS['lang']['STORE_LIST'];
     $seo_keyword = $GLOBALS['lang']['STORE_LIST'];
     $seo_description = $GLOBALS['lang']['STORE_LIST'];
     $append_seo = "";
     $area_id = intval($_REQUEST['aid']);
     $quan_id = intval($_REQUEST['qid']);
     $area_result = load_auto_cache("cache_area", array("city_id" => $GLOBALS['deal_city']['id']));
     if ($area_id > 0) {
         // 			$area_name = $GLOBALS['db']->getOne("select name from ".DB_PREFIX."area where id = ".$area_id);
         $area_name = $area_result[$area_id]['name'];
         $append_seo = $area_name;
         if ($quan_id > 0) {
             $kw_unicode = str_to_unicode_string($area_name);
             //有筛选
             $condition .= " and (match(locate_match) against('" . $kw_unicode . "' IN BOOLEAN MODE))";
         } else {
             $ids = load_auto_cache("deal_quan_ids", array("quan_id" => $area_id));
             //$quan_list = $GLOBALS['db']->getAll("select `name` from ".DB_PREFIX."area where id in (".implode(",",$ids).")");
             $unicode_quans = array();
             foreach ($ids as $k => $v) {
                 $unicode_quans[] = str_to_unicode_string($area_result[$v]['name']);
             }
             $kw_unicode = implode(" ", $unicode_quans);
             $condition .= " and (match(locate_match) against('" . $kw_unicode . "' IN BOOLEAN MODE))";
         }
     }
     $GLOBALS['tmpl']->assign("area_list", $result['area_list']);
     if ($area_id > 0) {
         //输出商圈
         if ($quan_id > 0) {
             // 					$area_name = $GLOBALS['db']->getOne("select name from ".DB_PREFIX."area where id = ".$quan_id);
             $area_name = $area_result[$quan_id]['name'];
             $kw_unicode = str_to_unicode_string($area_name);
             //有筛选
             $condition .= " and (match(locate_match) against('" . $kw_unicode . "' IN BOOLEAN MODE)) ";
             $append_seo = $append_seo . $area_name;
         }
         $GLOBALS['tmpl']->assign("quan_list", $result['quan_list']);
     }
     //输出分类
     $cate_id = $cate_item['id'];
     $GLOBALS['tmpl']->assign("cate_list", $result['cate_list']);
     //输出小分类
     $deal_type_id = intval($_REQUEST['tid']);
     $deal_cate_id = $cate_id;
     if ($deal_cate_id > 0) {
         $GLOBALS['tmpl']->assign("scate_list", $result['scate_list']);
         $GLOBALS['tmpl']->assign("tag_group", $result['tag_group']);
         //$deal_cate_name = $GLOBALS['db']->getOne("select name from ".DB_PREFIX."deal_cate where id = ".$deal_cate_id);
         $deal_cate_name = $cate_list[$deal_cate_id]['name'];
         $deal_cate_name_unicode = str_to_unicode_string($deal_cate_name);
         $condition .= " and (match(deal_cate_match) against('" . $deal_cate_name_unicode . "' IN BOOLEAN MODE)) ";
         $cate_condition = " (match(deal_cate_match) against('" . $deal_cate_name_unicode . "' IN BOOLEAN MODE)) ";
         if ($append_seo != "") {
             $append_seo .= " - ";
         }
         $append_seo .= $cate_item['name'];
     }
     if ($deal_type_id > 0) {
         $type_list = load_auto_cache("cache_deal_cate_type", array("cate_id" => $deal_cate_id));
         // 			$deal_type_name = $GLOBALS['db']->getOne("select name from ".DB_PREFIX."deal_cate_type where id = ".$deal_type_id);
         $deal_type_name = $type_list[$deal_type_id]['name'];
         $deal_type_name_unicode = str_to_unicode_string($deal_type_name);
         $condition .= " and (match(deal_cate_match) against('" . $deal_type_name_unicode . "' IN BOOLEAN MODE)) ";
         $append_seo .= $deal_type_name;
     }
     $seo_title = $append_seo . $seo_title;
     $seo_keyword = $append_seo . $seo_keyword;
     $seo_description = $append_seo . $seo_keyword;
     $supplier_id = intval($_REQUEST['id']);
     if ($supplier_id > 0) {
         $supplier_info = $GLOBALS['db']->getRow("select * from " . DB_PREFIX . "supplier where id = " . $supplier_id);
         if ($supplier_info) {
             $GLOBALS['tmpl']->assign("supplier_info", $supplier_info);
             $condition .= " and supplier_id = " . $supplier_id;
         }
     }
     $url_param['tag'] = addslashes($_REQUEST['tag']);
     if ($url_param['tag']) {
         $kw_unicode = str_to_unicode_string($url_param['tag']);
         //有筛选
         $condition .= " and (match(tags_match) against('" . $kw_unicode . "' IN BOOLEAN MODE))";
     }
     if ($_REQUEST['g'] && is_array($_REQUEST['g'])) {
         foreach ($_REQUEST['g'] as $k => $v) {
             if (trim($v) != "") {
                 $kw_unicode = str_to_unicode_string($v);
                 $condition .= " and (match(tags_match) against('" . $kw_unicode . "' IN BOOLEAN MODE))";
             }
         }
     }
     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);
         //有筛选
         $condition .= " and (locate_match_row like '%" . $keyword . "%' or name like '%" . $keyword . "%') ";
     }
     if ($minprice > 0) {
         $condition .= " and ref_avg_price >= " . $minprice;
         $GLOBALS['tmpl']->assign("minprice", round($minprice));
     }
     if ($maxprice > 0) {
         $condition .= " and ref_avg_price <= " . $maxprice;
         $GLOBALS['tmpl']->assign("maxprice", round($maxprice));
     }
     if ($filter_url_param['has_tuan'] > 0) {
         $condition .= " and tuan_count > 0 ";
     }
     if ($filter_url_param['has_daijin'] > 0) {
         $condition .= " and daijin_count > 0 ";
     }
     if ($filter_url_param['has_youhui'] > 0) {
         $condition .= " and youhui_count > 0 ";
     }
     if ($filter_url_param['has_event'] > 0) {
         $condition .= " and event_count > 0 ";
     }
     if ($filter_url_param['has_goods'] > 0) {
         $condition .= " and shop_count > 0 ";
     }
     if ($filter_url_param['is_verify'] > 0) {
         $condition .= " and is_verify = 1 ";
     }
     $sort_field = es_cookie::get("store_sort_field");
     $sort_type = es_cookie::get("store_sort_type");
     if ($sort_type != "desc" && $sort_type != "asc") {
         $sort_type = "desc";
     }
     if ($sort_field != "default" && $sort_field != "dp_count" && $sort_field != "avg_point" && $sort_field != "ref_avg_price") {
         $sort_field = "default";
     }
     if ($sort_field == 'default') {
         $sortby = " sort desc, id desc,is_verify desc,dp_count desc ";
     } else {
         $sortby = $sort_field . " " . $sort_type;
     }
     $GLOBALS['tmpl']->assign('sort_field', $sort_field);
     $GLOBALS['tmpl']->assign('sort_type', $sort_type);
     $result = get_store_list($limit, 0, $condition, $sortby, false);
     $GLOBALS['tmpl']->assign("list", $result['list']);
     $page = new Page($result['count'], app_conf("DEAL_PAGE_SIZE"));
     //初始化分页对象
     $p = $page->show();
     $GLOBALS['tmpl']->assign('pages', $p);
     $site_nav[] = array('name' => $GLOBALS['lang']['HOME_PAGE'], 'url' => url("index", "index"));
     $site_nav[] = array('name' => $GLOBALS['lang']['STORE_LIST'], 'url' => url("youhui", "store"));
     $GLOBALS['tmpl']->assign("site_nav", $site_nav);
     //输出最新加入的商家
     $new_stores = get_store_list(5, 0, $cate_condition, " id desc ", false, false);
     $GLOBALS['tmpl']->assign("new_stores", $new_stores['list']);
     if (trim($cate_condition) != '') {
         $rec_stores = get_store_list(5, 0, $cate_condition . " and is_recommend = 1 ", " id desc ", false, false);
     } else {
         $rec_stores = get_store_list(5, 0, " is_recommend = 1 ", " id desc ", false, false);
     }
     $GLOBALS['tmpl']->assign("rec_stores", $rec_stores['list']);
     $GLOBALS['tmpl']->assign("page_title", $seo_title);
     $GLOBALS['tmpl']->assign("page_keyword", $seo_keyword . ",");
     $GLOBALS['tmpl']->assign("page_description", $seo_description . ",");
     $GLOBALS['tmpl']->display("store_index.html");
 }
Example #28
0
 public function deals()
 {
     $r = strim($_REQUEST['r']);
     //推荐类型
     $id = intval($_REQUEST['id']);
     //分类id
     $loc = strim($_REQUEST['loc']);
     //地区
     $tag = strim($_REQUEST['tag']);
     //标签
     $kw = strim($_REQUEST['k']);
     //关键词
     $state = intval($_REQUEST['state']);
     //状态
     $step = intval($_REQUEST['step']);
     $page_size = DEAL_PAGE_SIZE;
     $step_size = DEAL_STEP_SIZE;
     if ($step == 0) {
         $step = 1;
     }
     $page = intval($_REQUEST['p']);
     if ($page == 0) {
         $page = 1;
     }
     $limit = ($page - 1) * $page_size + ($step - 1) * $step_size . "," . $step_size;
     $condition = " is_delete = 0 and is_effect = 1 ";
     if ($r != "") {
         if ($r == "new") {
             $condition .= " and " . NOW_TIME . " - begin_time < " . 24 * 3600 . " and " . NOW_TIME . " - begin_time > 0 ";
             //上线不超过一天
         }
         if ($r == "rec") {
             $condition .= " and " . NOW_TIME . " <= end_time AND " . NOW_TIME . " >= begin_time and is_recommend = 1 ";
         }
         if ($r == "yure") {
             $condition .= " and " . NOW_TIME . " - begin_time < " . 24 * 3600 . " and " . NOW_TIME . " - begin_time <  0 ";
             //上线不超过一天
         }
         if ($r == "nend") {
             $condition .= " and end_time - " . NOW_TIME . " < " . 24 * 3600 . " and end_time - " . NOW_TIME . " > 0 ";
             //当天就要结束
         }
         if ($r == "classic") {
             $condition .= " and is_classic = 1 ";
         }
         if ($r == "limit_price") {
             $condition .= " and max(limit_price) ";
         }
     }
     switch ($state) {
         //筹资成功
         case 1:
             $condition .= " and end_time < " . NOW_TIME . "  and support_amount >= limit_price";
             $GLOBALS['tmpl']->assign("page_title", "筹资成功");
             break;
             //筹资失败
         //筹资失败
         case 2:
             $condition .= " and end_time < " . NOW_TIME . "  and  support_amount < limit_price ";
             $GLOBALS['tmpl']->assign("page_title", "筹资失败");
             break;
             //筹资中
         //筹资中
         case 3:
             $condition .= " and end_time > " . NOW_TIME . "  and begin_time < " . NOW_TIME . " ";
             $GLOBALS['tmpl']->assign("page_title", "筹资中");
             break;
     }
     $cate_list = load_dynamic_cache("INDEX_CATE_LIST");
     if (!$cate_list) {
         $cate_list = $GLOBALS['db']->getAll("select * from " . DB_PREFIX . "deal_cate order by sort asc");
         set_dynamic_cache("INDEX_CATE_LIST", $cate_list);
     }
     $cate_result = array();
     $kk = 0;
     foreach ($cate_list as $k => $v) {
         if ($v['pid'] == 0) {
             $temp_param = $param;
             $cate_result[$k + 1]['id'] = $v['id'];
             $cate_result[$k + 1]['name'] = $v['name'];
             $temp_param['id'] = $v['id'];
             $cate_result[$k + 1]['url'] = url("deals", $temp_param);
             $kk++;
         }
     }
     $GLOBALS['tmpl']->assign("cate_list", $cate_result);
     $pid = 0;
     //获取父类id
     if ($cate_list) {
         foreach ($cate_list as $k => $v) {
             if ($v['id'] == $id) {
                 if ($v['pid'] > 0) {
                     $pid = $v['pid'];
                 } else {
                     $pid = $id;
                 }
             }
         }
     }
     /*子分类 start*/
     $cate_ids = array();
     $is_has_child = false;
     $temp_cate_ids = array();
     if ($cate_list) {
         $child_cate_result = array();
         foreach ($cate_list as $k => $v) {
             if ($v['pid'] == $pid) {
                 if ($v['pid'] > 0) {
                     $temp_param = $param;
                     $child_cate_result[$v['id']]['id'] = $v['id'];
                     $child_cate_result[$v['id']]['name'] = $v['name'];
                     $temp_param['id'] = $v['id'];
                     $child_cate_result[$v['id']]['url'] = url("deals", $temp_param);
                     if ($v['id'] == $id) {
                         $is_has_child = true;
                     }
                 }
             }
             if ($v['pid'] == $pid || $pid == 0) {
                 $temp_cate_ids[] = $v['id'];
             }
         }
     }
     //假如选择了子类 那么使用子类ID  否则使用 父类和其子类
     if ($is_has_child) {
         $cate_ids[] = $id;
     } else {
         $cate_ids[] = $pid;
         $cate_ids = array_merge($cate_ids, $temp_cate_ids);
     }
     if (count($cate_ids) > 0) {
         $condition .= " and cate_id in (" . implode(",", $cate_ids) . ")";
     }
     if ($loc != "") {
         $condition .= " and (province = '" . $loc . "' or city = '" . $loc . "') ";
     }
     if ($tag != "") {
         $unicode_tag = str_to_unicode_string($tag);
         $condition .= " and match(tags_match) against('" . $unicode_tag . "'  IN BOOLEAN MODE) ";
     }
     if ($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(name_match) against('" . $ukeyword . "'  IN BOOLEAN MODE) or match(tags_match) against('" . $ukeyword . "'  IN BOOLEAN MODE)  or name like '%" . $kw . "%') ";
     }
     $result = get_deal_list($limit, $condition);
     $GLOBALS['tmpl']->assign("deal_list", $result['list']);
     $data['html'] = $GLOBALS['tmpl']->fetch("inc/deal_list.html");
     if ($step * $step_size < $page_size) {
         if ($result['rs_count'] <= ($page - 1) * $page_size + ($step - 1) * $step_size + $step_size) {
             $data['step'] = 0;
             ajax_return($data);
         } else {
             $data['step'] = $step + 1;
             ajax_return($data);
         }
     } else {
         $data['step'] = 0;
         ajax_return($data);
     }
 }
 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);
 }
Example #30
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);
 }