public function load($param) { $key = $this->build_key(__CLASS__, $param); //传入参数 city_id(城市) id(分类ID) tid(子分类ID) qid(商圈ID) $end_time = get_gmtime() - 3600 * 24; $result = unserialize($GLOBALS['db']->getOne("select cache_data from " . DB_PREFIX . "auto_cache where cache_type = '" . __CLASS__ . "' and cache_key = '" . $key . "' and cache_time > " . $end_time)); if ($result === false) { $GLOBALS['db']->query("delete from " . DB_PREFIX . "auto_cache where cache_type = '" . __CLASS__ . "' and cache_key = '" . $key . "'"); $deal_quan_id = intval($param['qid']); $city_id = intval($param['city_id']); $url_param = array("id" => $param['id'], "tid" => $param['tid'], "qid" => $param['qid']); $deal_cate_id = intval($param['id']); $deal_type_id = intval($param['tid']); //大区 $qpid = $GLOBALS['db']->getOne("select pid from " . DB_PREFIX . "area where id = " . $deal_quan_id); $bdeal_quan_id = $qpid == 0 ? $deal_quan_id : $qpid; //大分类ID if ($bdeal_quan_id > 0) { $sdeal_quan_id = 0; } else { $sdeal_quan_id = $deal_quan_id; } $c_param = array("cid" => $deal_cate_id, "tid" => $deal_type_id, "aid" => $bdeal_quan_id, "qid" => $sdeal_quan_id); $bquan_list = $GLOBALS['db']->getAll("select id,name from " . DB_PREFIX . "area WHERE pid=0 AND city_id=" . $city_id . " ORDER BY `sort` DESC "); foreach ($bquan_list as $k => $v) { $bquan_list[$k + 1]['name'] = $v['name']; if ($deal_quan_id == $v['id'] || $bdeal_quan_id == $v['id']) { $bquan_list[$k + 1]['current'] = 1; } $tmp_url_param = $url_param; $tmp_url_param['qid'] = $v['id']; $durl = url("tuan", "index", $tmp_url_param); $bquan_list[$k + 1]['url'] = $durl; $tmp_url_p = $c_param; $tmp_url_p['aid'] = $v['id']; $condition = build_deal_filter_condition($tmp_url_p); $bquan_list[$k + 1]['count'] = $GLOBALS['db']->getOne("select count(*) from " . DB_PREFIX . "deal where is_effect = 1 and is_delete = 0 and is_shop = 0 and (end_time = 0 or end_time > '" . get_gmtime() . "') {$condition} "); } $all_current = 0; if ($deal_quan_id == 0) { $all_current = 1; } $tmp_url_param = $url_param; $tmp_url_param['qid'] = 0; $bquan_list[0] = array("url" => url("tuan", "index", $tmp_url_param), "name" => $GLOBALS['lang']['ALL'], "current" => $all_current); $tmp_url_p = $c_param; $tmp_url_p['aid'] = 0; $condition = build_deal_filter_condition($tmp_url_p); $bquan_list[0]['count'] = $GLOBALS['db']->getOne("select count(*) from " . DB_PREFIX . "deal where is_effect = 1 and is_delete = 0 and is_shop = 0 and (end_time = 0 or end_time > '" . get_gmtime() . "') {$condition} "); $result['bquan_list'] = $bquan_list; //当前城市的二级商圈 if ($bdeal_quan_id != $qpid && $qpid == 0 || $bdeal_quan_id == $qpid && $qpid != 0) { $squan_list = $GLOBALS['db']->getAll("select id,name from " . DB_PREFIX . "area WHERE pid=" . $bdeal_quan_id . " AND city_id=" . $city_id . " ORDER BY `sort` DESC "); foreach ($squan_list as $k => $v) { $squan_list[$k]['name'] = $v['name']; if ($deal_quan_id == $v['id']) { $squan_list[$k]['current'] = 1; } $tmp_url_param = $url_param; $tmp_url_param['qid'] = $v['id']; $durl = url("tuan", "index", $tmp_url_param); $squan_list[$k]['url'] = $durl; $tmp_url_p = $c_param; $tmp_url_p['qid'] = $v['id']; $condition = build_deal_filter_condition($tmp_url_p); $squan_list[$k]['count'] = $GLOBALS['db']->getOne("select count(*) from " . DB_PREFIX . "deal where is_effect = 1 and is_delete = 0 and is_shop = 0 and (end_time = 0 or end_time > '" . get_gmtime() . "') {$condition} "); } } $result['squan_list'] = $squan_list; //大类 $bcate_list[] = array("name" => $GLOBALS['lang']['ALL'], "qid" => $deal_quan_id); $bcate_list = $GLOBALS['db']->getAll("select id,name,uname from " . DB_PREFIX . "deal_cate where is_delete = 0 and is_effect = 1 and pid = 0 order by sort desc"); foreach ($bcate_list as $k => $v) { $bcate_list[$k + 1]['name'] = $v['name']; if ($deal_cate_id == $v['id']) { $bcate_list[$k + 1]['current'] = 1; } if ($v['uname'] != '') { $durl = url("tuan", "index", array("id" => $v['uname'], "qid" => $deal_quan_id)); } else { $durl = url("tuan", "index", array("id" => $v['id'], "qid" => $deal_quan_id)); } $bcate_list[$k + 1]['url'] = $durl; $tmp_url_p = $c_param; $tmp_url_p['cid'] = $v['id']; $tmp_url_p['tid'] = 0; $condition = build_deal_filter_condition($tmp_url_p); $bcate_list[$k + 1]['count'] = $GLOBALS['db']->getOne("select count(*) from " . DB_PREFIX . "deal where is_effect = 1 and is_delete = 0 and is_shop = 0 and (end_time = 0 or end_time > '" . get_gmtime() . "') {$condition} "); } $all_current = 0; if ($deal_cate_id == 0) { $all_current = 1; } $tmp_url_param = $url_param; $tmp_url_param['id'] = 0; $bcate_list[0] = array("url" => url("tuan", "index", $tmp_url_param), "name" => $GLOBALS['lang']['ALL'], "current" => $all_current); $tmp_url_p = $c_param; $tmp_url_p['cid'] = 0; $condition = build_deal_filter_condition($tmp_url_p); $bcate_list[0]['count'] = $GLOBALS['db']->getOne("select count(*) from " . DB_PREFIX . "deal where is_effect = 1 and is_delete = 0 and is_shop = 0 and (end_time = 0 or end_time > '" . get_gmtime() . "') {$condition} "); $result['bcate_list'] = $bcate_list; //小类 if ($deal_cate_id > 0) { //$scate_list = $GLOBALS['db']->getAll("select id,name,uname from ".DB_PREFIX."deal_cate where is_delete = 0 and is_effect = 1 and pid = ".$bdeal_cate_id." order by sort desc"); $scate_list = $GLOBALS['db']->getAll("select t.id,t.name from " . DB_PREFIX . "deal_cate_type as t left join " . DB_PREFIX . "deal_cate_type_link as l on l.deal_cate_type_id = t.id where l.cate_id = " . $deal_cate_id . " order by t.sort desc"); foreach ($scate_list as $k => $v) { //$cate_deal_list_rs = get_deal_list(1,$v['id'],$city_id=0, $type=array(DEAL_ONLINE,DEAL_NOTICE), $where='buy_type<>1',$orderby = '',$deal_quan_id); //$scate_list[$k]['count'] = $cate_deal_list_rs['count']; if ($deal_type_id == $v['id']) { $scate_list[$k]['current'] = 1; } $tmp_url_param = $url_param; $tmp_url_param['tid'] = $v['id']; $durl = url("tuan", "index", $tmp_url_param); $scate_list[$k]['url'] = $durl; $tmp_url_p = $c_param; $tmp_url_p['cid'] = $deal_cate_id; $tmp_url_p['tid'] = $v['id']; $condition = build_deal_filter_condition($tmp_url_p); $scate_list[$k]['count'] = $GLOBALS['db']->getOne("select count(*) from " . DB_PREFIX . "deal where is_effect = 1 and is_delete = 0 and is_shop = 0 and (end_time = 0 or end_time > '" . get_gmtime() . "') {$condition} "); } } $result['scate_list'] = $scate_list; $db_data['cache_key'] = $key; $db_data['cache_type'] = __CLASS__; $db_data['cache_time'] = get_gmtime(); $db_data['cache_data'] = serialize($result); $GLOBALS['db']->autoExecute(DB_PREFIX . "auto_cache", $db_data); } return $result; }
public function load($param) { $key = $this->build_key(__CLASS__, $param); //传入参数 city_id(城市) cid(分类ID) tid(子分类ID) aid(行政区) qid(商圈ID) // $GLOBALS['fcache']->set_dir(APP_ROOT_PATH."public/runtime/data/".__CLASS__."/"); $end_time = get_gmtime() - 3600 * 24; $result = unserialize($GLOBALS['db']->getOne("select cache_data from " . DB_PREFIX . "auto_cache where cache_type = '" . __CLASS__ . "' and cache_key = '" . $key . "' and cache_time > " . $end_time)); if ($result === false) { $GLOBALS['db']->query("delete from " . DB_PREFIX . "auto_cache where cache_type = '" . __CLASS__ . "' and cache_key = '" . $key . "'"); $city_id = intval($param['city_id']); $url_param = $param; unset($url_param['city_id']); $area_id = intval($param['aid']); $quan_id = intval($param['qid']); $cate_id = intval($param['cid']); $deal_type_id = intval($param['tid']); //大区 $area_list = $GLOBALS['db']->getAll("select * from " . DB_PREFIX . "area where city_id = " . $city_id . " and pid = 0 order by sort desc"); $area_list[] = array("name" => $GLOBALS['lang']['ALL'], "id" => 0); foreach ($area_list as $k => $v) { if ($area_id == $v['id']) { $area_list[$k]['act'] = 1; } $tmp_url_param = $url_param; unset($tmp_url_param['qid']); $tmp_url_param['aid'] = $v['id']; $area_list[$k]['url'] = url("youhui", "store", $tmp_url_param); $condition = build_deal_filter_condition($tmp_url_param); $area_list[$k]['count'] = $GLOBALS['db']->getOne("select count(*) from " . DB_PREFIX . "supplier_location where is_effect=1 {$condition} "); } $result['area_list'] = $area_list; //小区 if ($area_id > 0) { $quan_list = $GLOBALS['db']->getAll("select * from " . DB_PREFIX . "area where city_id = " . $city_id . " and pid = " . $area_id . " order by sort desc"); $quan_list[] = array("name" => $GLOBALS['lang']['ALL'], "id" => 0); foreach ($quan_list as $k => $v) { if ($quan_id == $v['id']) { $quan_list[$k]['act'] = 1; } $tmp_url_param = $url_param; $tmp_url_param['qid'] = $v['id']; $quan_list[$k]['url'] = url("youhui", "store", $tmp_url_param); $condition = build_deal_filter_condition($tmp_url_param); $quan_list[$k]['count'] = $GLOBALS['db']->getOne("select count(*) from " . DB_PREFIX . "supplier_location where is_effect=1 {$condition} "); } } $result['quan_list'] = $quan_list; //大类 //输出分类 $cate_list = $GLOBALS['db']->getAll("select * from " . DB_PREFIX . "deal_cate where is_effect = 1 and is_delete = 0 and pid = 0 order by sort desc"); $cate_list[] = array("name" => $GLOBALS['lang']['ALL'], "cid" => 0); foreach ($cate_list as $k => $v) { if ($cate_id == $v['id']) { $cate_list[$k]['act'] = 1; } $tmp_url_param = $url_param; unset($tmp_url_param['tid']); if ($v['uname'] != '') { $tmp_url_param['cid'] = $v['uname']; } else { $tmp_url_param['cid'] = $v['id']; } $cate_list[$k]['url'] = url("youhui", "store", $tmp_url_param); $condition = build_deal_filter_condition($tmp_url_param); $cate_list[$k]['count'] = $GLOBALS['db']->getOne("select count(*) from " . DB_PREFIX . "supplier_location where is_effect=1 {$condition} "); } $result['cate_list'] = $cate_list; //小类 $deal_cate_id = $cate_id; if ($deal_cate_id > 0) { $scate_list = $GLOBALS['db']->getAll("select t.id,t.name from " . DB_PREFIX . "deal_cate_type as t left join " . DB_PREFIX . "deal_cate_type_link as l on l.deal_cate_type_id = t.id where l.cate_id = " . $deal_cate_id . " order by t.sort desc"); foreach ($scate_list as $k => $v) { if ($deal_type_id == $v['id']) { $scate_list[$k]['act'] = 1; } $tmp_url_param = $url_param; $tmp_url_param['tid'] = $v['id']; $durl = url("youhui", "store", $tmp_url_param); $scate_list[$k]['url'] = $durl; $condition = build_deal_filter_condition($tmp_url_param); $scate_list[$k]['count'] = $GLOBALS['db']->getOne("select count(*) from " . DB_PREFIX . "supplier_location where is_effect=1 {$condition} "); } } $result['scate_list'] = $scate_list; //分组筛选 $tag_group = $GLOBALS['db']->getAll("select g.* from " . DB_PREFIX . "tag_group as g left join " . DB_PREFIX . "tag_group_link as l on l.tag_group_id = g.id where l.category_id = " . $deal_cate_id . " and g.allow_search = 1 order by g.sort desc"); if ($tag_group) { foreach ($tag_group as $k => $v) { $arr = explode(" ", $v['tags']); $group_tags = array(); foreach ($arr as $kk => $vv) { if (trim($vv) != "") { $group_tags[$kk]['name'] = $vv; $tmp_url_param = $url_param; $tmp_url_param['g[' . $v['id'] . ']'] = $vv; $group_tags[$kk]['url'] = url("youhui", "store", $tmp_url_param); if ($vv == addslashes(trim($_REQUEST['g'][$v['id']]))) { $group_tags[$kk]['act'] = 1; } } } $tmp_url_param = $url_param; $tmp_url_param['g[' . $v['id'] . ']'] = ""; $group_tags[] = array("name" => "全部", "url" => url("youhui", "store", $tmp_url_param), "act" => addslashes(trim($_REQUEST['g'][$v['id']])) == "" ? 1 : 0); $tag_group[$k]["tags"] = $group_tags; } $result['tag_group'] = $tag_group; } $db_data['cache_key'] = $key; $db_data['cache_type'] = __CLASS__; $db_data['cache_time'] = get_gmtime(); $db_data['cache_data'] = serialize($result); $GLOBALS['db']->autoExecute(DB_PREFIX . "auto_cache", $db_data); } return $result; }
/** * 获取正在团购的产品列表 */ function get_deal_list($limit, $type = array(DEAL_ONLINE, DEAL_HISTORY, DEAL_NOTICE), $param = array("cid" => 0, "tid" => 0, "aid" => 0, "qid" => 0, "city_id" => 0), $join = '', $where = '', $orderby = '', $append_field = "") { if (empty($param)) { $param = array("cid" => 0, "tid" => 0, "aid" => 0, "qid" => 0, "city_id" => 0); } $tname = "d"; $time = $GLOBALS['db']->getCacheTime(NOW_TIME); $condition = ' ' . $tname . '.is_effect = 1 and ' . $tname . '.is_delete = 0 and ( 1<>1 '; if (in_array(DEAL_ONLINE, $type)) { //进行中的团购 $condition .= " or ((" . $time . ">= " . $tname . ".begin_time or " . $tname . ".begin_time = 0) and (" . $time . "< " . $tname . ".end_time or " . $tname . ".end_time = 0) and " . $tname . ".buy_status <> 2) "; } if (in_array(DEAL_HISTORY, $type)) { //往期团购 $condition .= " or ((" . $time . ">=" . $tname . ".end_time and " . $tname . ".end_time <> 0) or " . $tname . ".buy_status = 2) "; } if (in_array(DEAL_NOTICE, $type)) { //预告 $condition .= " or ((" . $time . " < " . $tname . ".begin_time and " . $tname . ".begin_time <> 0 and " . $tname . ".notice = 1)) "; } $condition .= ')'; $param_condition = build_deal_filter_condition($param, $tname); $condition .= " " . $param_condition; if ($where != '') { $condition .= " and " . $where; } if ($join) { $sql = "select " . $tname . ".*" . $append_field . " from " . DB_PREFIX . "deal as " . $tname . " " . $join . " where " . $condition; } else { $sql = "select " . $tname . ".*" . $append_field . " from " . DB_PREFIX . "deal as " . $tname . " where " . $condition; } if ($orderby == '') { $sql .= " order by " . $tname . ".sort desc limit " . $limit; } else { $sql .= " order by " . $orderby . " limit " . $limit; } $deals = $GLOBALS['db']->getAll($sql, false); if ($deals) { foreach ($deals as $k => $deal) { //格式化数据 $deal['begin_time_format'] = to_date($deal['begin_time']); $deal['end_time_format'] = to_date($deal['end_time']); $deal['origin_price_format'] = format_price($deal['origin_price']); $deal['current_price_format'] = format_price($deal['current_price']); $deal['success_time_format'] = to_date($deal['success_time']); if ($deal['origin_price'] > 0 && floatval($deal['discount']) == 0) { //手动折扣 $deal['save_price'] = $deal['origin_price'] - $deal['current_price']; } else { $deal['save_price'] = $deal['origin_price'] * ((10 - $deal['discount']) / 10); } if ($deal['origin_price'] > 0 && floatval($deal['discount']) == 0) { $deal['discount'] = round($deal['current_price'] / $deal['origin_price'] * 10, 2); } $deal['discount'] = round($deal['discount'], 2); if ($deal['uname'] != '') { $durl = url("index", "deal#" . $deal['uname']); } else { $durl = url("index", "deal#" . $deal['id']); } $deal['share_url'] = SITE_DOMAIN . $durl; $deal['url'] = $durl; if ($GLOBALS['user_info']) { if (app_conf("URL_MODEL") == 0) { $deal['share_url'] .= "&r=" . base64_encode(intval($GLOBALS['user_info']['id'])); } else { $deal['share_url'] .= "?r=" . base64_encode(intval($GLOBALS['user_info']['id'])); } } //$deal['is_today'] = get_is_today($deal); $deal['save_price_format'] = format_price($deal['save_price']); $deal['deal_success_num'] = sprintf($GLOBALS['lang']['SUCCESS_BUY_COUNT'], $deal['buy_count']); $deal['current_bought'] = $deal['buy_count']; //开始解析商品标签 for ($tt = 0; $tt < 10; $tt++) { if (($deal['deal_tag'] & pow(2, $tt)) == pow(2, $tt)) { $deal['deal_tags'][] = $tt; } } $deal['percent'] = $deal['avg_point'] / 5.0 * 100.0; $deals[$k] = $deal; } } return array('list' => $deals, 'condition' => $condition); }
public function load($param) { $key = $this->build_key(__CLASS__, $param); //传入参数 city_id(城市) cid(分类ID) tid(子分类ID) aid(行政区) qid(商圈ID) $end_time = get_gmtime() - 3600 * 24; $result = unserialize($GLOBALS['db']->getOne("select cache_data from " . DB_PREFIX . "auto_cache where cache_type = '" . __CLASS__ . "' and cache_key = '" . $key . "' and cache_time > " . $end_time)); if ($result === false) { $GLOBALS['db']->query("delete from " . DB_PREFIX . "auto_cache where cache_type = '" . __CLASS__ . "' and cache_key = '" . $key . "'"); $city_id = intval($param['city_id']); $url_param = $param; unset($url_param['city_id']); $area_id = intval($param['aid']); $quan_id = intval($param['qid']); $cate_id = intval($param['cid']); $deal_type_id = intval($param['tid']); //大区 $area_list = $GLOBALS['db']->getAll("select * from " . DB_PREFIX . "area where city_id = " . $city_id . " and pid = 0 order by sort desc"); $area_list[] = array("name" => $GLOBALS['lang']['ALL'], "id" => 0); foreach ($area_list as $k => $v) { if ($area_id == $v['id']) { $area_list[$k]['act'] = 1; } $tmp_url_param = $url_param; unset($tmp_url_param['qid']); $tmp_url_param['aid'] = $v['id']; $area_list[$k]['url'] = url("youhui", "fcate", $tmp_url_param); $condition = build_deal_filter_condition($tmp_url_param); $area_list[$k]['count'] = $GLOBALS['db']->getOne("select count(*) from " . DB_PREFIX . "youhui where is_effect=1 {$condition} "); } $result['area_list'] = $area_list; //小区 if ($area_id > 0) { $quan_list = $GLOBALS['db']->getAll("select * from " . DB_PREFIX . "area where city_id = " . $city_id . " and pid = " . $area_id . " order by sort desc"); $quan_list[] = array("name" => $GLOBALS['lang']['ALL'], "id" => 0); foreach ($quan_list as $k => $v) { if ($quan_id == $v['id']) { $quan_list[$k]['act'] = 1; } $tmp_url_param = $url_param; $tmp_url_param['qid'] = $v['id']; $quan_list[$k]['url'] = url("youhui", "fcate", $tmp_url_param); $condition = build_deal_filter_condition($tmp_url_param); $quan_list[$k]['count'] = $GLOBALS['db']->getOne("select count(*) from " . DB_PREFIX . "youhui where is_effect=1 {$condition} "); } } $result['quan_list'] = $quan_list; //大类 //输出分类 $cate_list = $GLOBALS['db']->getAll("select * from " . DB_PREFIX . "deal_cate where is_effect = 1 and is_delete = 0 and pid = 0 order by sort desc"); $cate_list[] = array("name" => $GLOBALS['lang']['ALL'], "cid" => 0); foreach ($cate_list as $k => $v) { if ($cate_id == $v['id']) { $cate_list[$k]['act'] = 1; } $tmp_url_param = $url_param; unset($tmp_url_param['tid']); if ($v['uname'] != '') { $tmp_url_param['cid'] = $v['uname']; } else { $tmp_url_param['cid'] = $v['id']; } $cate_list[$k]['url'] = url("youhui", "fcate", $tmp_url_param); $condition = build_deal_filter_condition($tmp_url_param); $cate_list[$k]['count'] = $GLOBALS['db']->getOne("select count(*) from " . DB_PREFIX . "youhui where is_effect=1 {$condition} "); } $result['cate_list'] = $cate_list; //小类 $deal_cate_id = $cate_id; if ($deal_cate_id > 0) { $scate_list = $GLOBALS['db']->getAll("select t.id,t.name from " . DB_PREFIX . "deal_cate_type as t left join " . DB_PREFIX . "deal_cate_type_link as l on l.deal_cate_type_id = t.id where l.cate_id = " . $deal_cate_id . " order by t.sort desc"); foreach ($scate_list as $k => $v) { if ($deal_type_id == $v['id']) { $scate_list[$k]['act'] = 1; } $tmp_url_param = $url_param; $tmp_url_param['tid'] = $v['id']; $durl = url("youhui", "fcate", $tmp_url_param); $scate_list[$k]['url'] = $durl; $condition = build_deal_filter_condition($tmp_url_param); $scate_list[$k]['count'] = $GLOBALS['db']->getOne("select count(*) from " . DB_PREFIX . "youhui where is_effect=1 {$condition} "); } } $result['scate_list'] = $scate_list; $db_data['cache_key'] = $key; $db_data['cache_type'] = __CLASS__; $db_data['cache_time'] = get_gmtime(); $db_data['cache_data'] = serialize($result); $GLOBALS['db']->autoExecute(DB_PREFIX . "auto_cache", $db_data); } return $result; }