commit | author | age
|
3e083b
|
1 |
<?php |
B |
2 |
|
|
3 |
/** |
|
4 |
* 首页文件 |
|
5 |
*/ |
|
6 |
|
|
7 |
define('IN_ECS', true); |
|
8 |
|
|
9 |
require(dirname(__FILE__) . '/includes/init.php'); |
|
10 |
|
|
11 |
if ((DEBUG_MODE & 2) != 2) |
|
12 |
{ |
|
13 |
$smarty->caching = true; |
|
14 |
} |
|
15 |
|
|
16 |
if (isset($_REQUEST['is_c'])) |
|
17 |
{ |
|
18 |
$is_c = intval($_REQUEST['is_c']); |
|
19 |
} |
|
20 |
if($is_c == 1){ |
|
21 |
|
|
22 |
}else |
|
23 |
{ |
|
24 |
//$ua = strtolower($_SERVER['HTTP_USER_AGENT']); |
|
25 |
|
|
26 |
//$uachar = "/(nokia|sony|ericsson|mot|samsung|sgh|lg|philips|panasonic|alcatel|lenovo|cldc|midp|mobile)/i"; |
|
27 |
|
|
28 |
//if(($ua == '' || preg_match($uachar, $ua))&& !strpos(strtolower($_SERVER['REQUEST_URI']),'wap')) |
|
29 |
$ua = strtolower($_SERVER['HTTP_USER_AGENT']); |
|
30 |
|
|
31 |
$uachar = "/(nokia|sony|ericsson|mot|samsung|sgh|lg|philips|panasonic|alcatel|lenovo|cldc|midp|mobile)/i"; |
|
32 |
$smartuachar = "/(ipad)/i"; |
|
33 |
|
|
34 |
//if(($ua == '' || preg_match($uachar, $ua))&& !strpos(strtolower($_SERVER['REQUEST_URI']),'wap')) |
|
35 |
if(!(preg_match($smartuachar, $ua)) && ($ua == '' || preg_match($uachar, $ua))&& !strpos(strtolower($_SERVER['REQUEST_URI']),'wap')) |
|
36 |
{ |
|
37 |
$Loaction = 'mobile/'; |
|
38 |
|
|
39 |
if (!empty($Loaction)) |
|
40 |
{ |
|
41 |
ecs_header("Location: $Loaction\n"); |
|
42 |
|
|
43 |
exit; |
|
44 |
} |
|
45 |
|
|
46 |
} |
|
47 |
|
|
48 |
} |
|
49 |
/*------------------------------------------------------ */ |
|
50 |
//-- 系统地址转换 |
|
51 |
/*------------------------------------------------------ */ |
|
52 |
if (!empty($_GET['gOo'])) |
|
53 |
{ |
|
54 |
if (!empty($_GET['gcat'])) |
|
55 |
{ |
|
56 |
/* 商品分类。*/ |
|
57 |
$Loaction = 'category.php?id=' . $_GET['gcat']; |
|
58 |
} |
|
59 |
elseif (!empty($_GET['acat'])) |
|
60 |
{ |
|
61 |
/* 文章分类。*/ |
|
62 |
$Loaction = 'article_cat.php?id=' . $_GET['acat']; |
|
63 |
} |
|
64 |
elseif (!empty($_GET['goodsid'])) |
|
65 |
{ |
|
66 |
/* 商品详情。*/ |
|
67 |
$Loaction = 'goods.php?id=' . $_GET['goodsid']; |
|
68 |
} |
|
69 |
elseif (!empty($_GET['articleid'])) |
|
70 |
{ |
|
71 |
/* 文章详情。*/ |
|
72 |
$Loaction = 'article.php?id=' . $_GET['articleid']; |
|
73 |
} |
|
74 |
|
|
75 |
if (!empty($Loaction)) |
|
76 |
{ |
|
77 |
ecs_header("Location: $Loaction\n"); |
|
78 |
|
|
79 |
exit; |
|
80 |
} |
|
81 |
} |
|
82 |
|
|
83 |
//判断是否有ajax请求 |
|
84 |
$act = !empty($_GET['act']) ? $_GET['act'] : ''; |
|
85 |
if ($act == 'cat_rec') |
|
86 |
{ |
|
87 |
$rec_array = array(1 => 'best', 2 => 'new', 3 => 'hot'); |
|
88 |
$rec_type = !empty($_REQUEST['rec_type']) ? intval($_REQUEST['rec_type']) : '1'; |
|
89 |
$cat_id = !empty($_REQUEST['cid']) ? intval($_REQUEST['cid']) : '0'; |
|
90 |
include_once('includes/cls_json.php'); |
|
91 |
$json = new JSON; |
|
92 |
$result = array('error' => 0, 'content' => '', 'type' => $rec_type, 'cat_id' => $cat_id); |
|
93 |
|
|
94 |
$children = get_children($cat_id); |
|
95 |
$smarty->assign($rec_array[$rec_type] . '_goods', get_category_recommend_goods($rec_array[$rec_type], $children)); // 推荐商品 |
|
96 |
$smarty->assign('cat_rec_sign', 1); |
|
97 |
$result['content'] = $smarty->fetch('library/recommend_' . $rec_array[$rec_type] . '.lbi'); |
|
98 |
die($json->encode($result)); |
|
99 |
} |
|
100 |
|
|
101 |
/*------------------------------------------------------ */ |
|
102 |
//-- 判断是否存在缓存,如果存在则调用缓存,反之读取相应内容 |
|
103 |
/*------------------------------------------------------ */ |
|
104 |
/* 缓存编号 */ |
|
105 |
$cache_id = sprintf('%X', crc32($_SESSION['user_rank'] . '-' . $_CFG['lang'])); |
|
106 |
|
|
107 |
if (!$smarty->is_cached('index.dwt', $cache_id)) |
|
108 |
{ |
|
109 |
assign_template(); |
|
110 |
|
|
111 |
$position = assign_ur_here(); |
|
112 |
$smarty->assign('page_title', $position['title']); // 页面标题 |
|
113 |
$smarty->assign('ur_here', $position['ur_here']); // 当前位置 |
|
114 |
|
|
115 |
/* meta information */ |
|
116 |
$smarty->assign('keywords', htmlspecialchars($_CFG['shop_keywords'])); |
|
117 |
$smarty->assign('description', htmlspecialchars($_CFG['shop_desc'])); |
|
118 |
$smarty->assign('flash_theme', $_CFG['flash_theme']); // Flash轮播图片模板 |
|
119 |
|
|
120 |
$smarty->assign('feed_url', ($_CFG['rewrite'] == 1) ? 'feed.xml' : 'feed.php'); // RSS URL |
|
121 |
|
|
122 |
$smarty->assign('categories', get_categories_tree()); // 分类树 |
|
123 |
$smarty->assign('helps', get_shop_help()); // 网店帮助 |
|
124 |
$smarty->assign('top_goods', get_top10()); // 销售排行 |
|
125 |
///llx添加start |
|
126 |
$smarty->assign('top_goods1', get_top10(16)); |
|
127 |
$smarty->assign('top_goods2', get_top10(81)); |
|
128 |
$smarty->assign('top_goods3', get_top10(17)); |
|
129 |
$smarty->assign('top_goods4', get_top10(93)); |
|
130 |
///llx添加end |
|
131 |
|
|
132 |
$smarty->assign('best_goods', get_recommend_goods('best')); // 推荐商品 |
|
133 |
$smarty->assign('new_goods', get_recommend_goods('new')); // 最新商品 |
|
134 |
$smarty->assign('hot_goods', get_recommend_goods('hot')); // 热点文章 |
|
135 |
$smarty->assign('promotion_goods', get_promote_goods()); // 特价商品 |
|
136 |
$smarty->assign('brand_list', get_brands()); |
|
137 |
$smarty->assign('promotion_info', get_promotion_info()); // 增加一个动态显示所有促销信息的标签栏 |
|
138 |
|
|
139 |
$smarty->assign('invoice_list', index_get_invoice_query()); // 发货查询 |
|
140 |
$smarty->assign('new_articles', index_get_new_articles()); // 最新文章 |
|
141 |
$smarty->assign('group_buy_goods', index_get_group_buy()); // 团购商品 |
|
142 |
$smarty->assign('auction_list', index_get_auction()); // 拍卖活动 |
|
143 |
$smarty->assign('shop_notice', $_CFG['shop_notice']); // 商店公告 |
|
144 |
$smarty->assign('cat_goods_list', get_cat_goods_list()); |
|
145 |
|
|
146 |
/* 首页主广告设置 */ |
|
147 |
$smarty->assign('index_ad', $_CFG['index_ad']); |
|
148 |
if ($_CFG['index_ad'] == 'cus') |
|
149 |
{ |
|
150 |
$sql = 'SELECT ad_type, content, url FROM ' . $ecs->table("ad_custom") . ' WHERE ad_status = 1'; |
|
151 |
$ad = $db->getRow($sql, true); |
|
152 |
$smarty->assign('ad', $ad); |
|
153 |
} |
|
154 |
|
|
155 |
/* links */ |
|
156 |
$links = index_get_links(); |
|
157 |
$smarty->assign('img_links', $links['img']); |
|
158 |
$smarty->assign('txt_links', $links['txt']); |
|
159 |
$smarty->assign('data_dir', DATA_DIR); // 数据目录 |
|
160 |
|
|
161 |
|
|
162 |
/* 添加首页幻灯插件*/ |
|
163 |
$smarty->assign("flash",get_flash_xml()); |
|
164 |
$smarty->assign('flash_count',count(get_flash_xml())); |
|
165 |
|
|
166 |
/* 首页推荐分类 */ |
|
167 |
$cat_recommend_res = $db->getAll("SELECT c.cat_id, c.cat_name, cr.recommend_type FROM " . $ecs->table("cat_recommend") . " AS cr INNER JOIN " . $ecs->table("category") . " AS c ON cr.cat_id=c.cat_id"); |
|
168 |
if (!empty($cat_recommend_res)) |
|
169 |
{ |
|
170 |
$cat_rec_array = array(); |
|
171 |
foreach($cat_recommend_res as $cat_recommend_data) |
|
172 |
{ |
|
173 |
$cat_rec[$cat_recommend_data['recommend_type']][] = array('cat_id' => $cat_recommend_data['cat_id'], 'cat_name' => $cat_recommend_data['cat_name']); |
|
174 |
} |
|
175 |
$smarty->assign('cat_rec', $cat_rec); |
|
176 |
} |
|
177 |
|
|
178 |
/* 页面中的动态内容 */ |
|
179 |
assign_dynamic('index'); |
|
180 |
} |
|
181 |
//$pro_goods=get_promote_goods(); |
|
182 |
//echo "<pre>"; |
|
183 |
//print_r($pro_goods); |
|
184 |
//线上红包 |
|
185 |
$sql = "SELECT * FROM " .$GLOBALS['ecs']->table('bonus_type') . |
|
186 |
" WHERE send_type = '4'"; |
|
187 |
$row = $GLOBALS['db']->GetAll($sql); |
|
188 |
$time=time(); |
|
189 |
date_default_timezone_set('PRC'); |
|
190 |
$smarty->assign('time',$time); |
|
191 |
$smarty->assign('online_bonus',$row); |
|
192 |
|
|
193 |
//判断 弹框登陆 验证码是否显示 |
|
194 |
$captcha = intval($_CFG['captcha']); |
|
195 |
if(($captcha & CAPTCHA_LOGIN) && (! ($captcha & CAPTCHA_LOGIN_FAIL) || (($captcha & CAPTCHA_LOGIN_FAIL) && $_SESSION['login_fail'] > 2)) && gd_version() > 0) |
|
196 |
{ |
|
197 |
$GLOBALS['smarty']->assign('enabled_captcha', 1); |
|
198 |
$GLOBALS['smarty']->assign('rand', mt_rand()); |
|
199 |
} |
|
200 |
|
|
201 |
|
|
202 |
$smarty->display('index.dwt', $cache_id); |
|
203 |
|
|
204 |
/*------------------------------------------------------ */ |
|
205 |
//-- PRIVATE FUNCTIONS |
|
206 |
/*------------------------------------------------------ */ |
|
207 |
|
|
208 |
/** |
|
209 |
* 调用发货单查询 |
|
210 |
* |
|
211 |
* @access private |
|
212 |
* @return array |
|
213 |
*/ |
|
214 |
function index_get_invoice_query() |
|
215 |
{ |
|
216 |
$sql = 'SELECT o.order_sn, o.invoice_no, s.shipping_code FROM ' . $GLOBALS['ecs']->table('order_info') . ' AS o' . |
|
217 |
' LEFT JOIN ' . $GLOBALS['ecs']->table('shipping') . ' AS s ON s.shipping_id = o.shipping_id' . |
|
218 |
" WHERE invoice_no > '' AND shipping_status = " . SS_SHIPPED . |
|
219 |
' ORDER BY shipping_time DESC LIMIT 10'; |
|
220 |
$all = $GLOBALS['db']->getAll($sql); |
|
221 |
|
|
222 |
foreach ($all AS $key => $row) |
|
223 |
{ |
|
224 |
$plugin = ROOT_PATH . 'includes/modules/shipping/' . $row['shipping_code'] . '.php'; |
|
225 |
|
|
226 |
if (file_exists($plugin)) |
|
227 |
{ |
|
228 |
include_once($plugin); |
|
229 |
|
|
230 |
$shipping = new $row['shipping_code']; |
|
231 |
$all[$key]['invoice_no'] = $shipping->query((string)$row['invoice_no']); |
|
232 |
} |
|
233 |
} |
|
234 |
|
|
235 |
clearstatcache(); |
|
236 |
|
|
237 |
return $all; |
|
238 |
} |
|
239 |
|
|
240 |
/** |
|
241 |
* 获得最新的文章列表。 |
|
242 |
* |
|
243 |
* @access private |
|
244 |
* @return array |
|
245 |
*/ |
|
246 |
function index_get_new_articles() |
|
247 |
{ |
|
248 |
$sql = 'SELECT a.article_id, a.title, ac.cat_name, a.add_time, a.file_url, a.open_type, ac.cat_id, ac.cat_name ' . |
|
249 |
' FROM ' . $GLOBALS['ecs']->table('article') . ' AS a, ' . |
|
250 |
$GLOBALS['ecs']->table('article_cat') . ' AS ac' . |
|
251 |
' WHERE a.is_open = 1 AND a.cat_id = ac.cat_id AND ac.cat_type = 1' . |
|
252 |
' ORDER BY a.article_type DESC, a.add_time DESC LIMIT ' . $GLOBALS['_CFG']['article_number']; |
|
253 |
$res = $GLOBALS['db']->getAll($sql); |
|
254 |
|
|
255 |
$arr = array(); |
|
256 |
foreach ($res AS $idx => $row) |
|
257 |
{ |
|
258 |
$arr[$idx]['id'] = $row['article_id']; |
|
259 |
$arr[$idx]['title'] = $row['title']; |
|
260 |
$arr[$idx]['short_title'] = $GLOBALS['_CFG']['article_title_length'] > 0 ? |
|
261 |
sub_str($row['title'], $GLOBALS['_CFG']['article_title_length']) : $row['title']; |
|
262 |
$arr[$idx]['cat_name'] = $row['cat_name']; |
|
263 |
$arr[$idx]['add_time'] = local_date($GLOBALS['_CFG']['date_format'], $row['add_time']); |
|
264 |
$arr[$idx]['url'] = $row['open_type'] != 1 ? |
|
265 |
build_uri('article', array('aid' => $row['article_id']), $row['title']) : trim($row['file_url']); |
|
266 |
$arr[$idx]['cat_url'] = build_uri('article_cat', array('acid' => $row['cat_id']), $row['cat_name']); |
|
267 |
} |
|
268 |
|
|
269 |
return $arr; |
|
270 |
} |
|
271 |
|
|
272 |
/** |
|
273 |
* 获得最新的团购活动 |
|
274 |
* |
|
275 |
* @access private |
|
276 |
* @return array |
|
277 |
*/ |
|
278 |
function index_get_group_buy() |
|
279 |
{ |
|
280 |
$time = gmtime(); |
|
281 |
$limit = get_library_number('group_buy', 'index'); |
|
282 |
|
|
283 |
$group_buy_list = array(); |
|
284 |
if ($limit > 0) |
|
285 |
{ |
|
286 |
$sql = 'SELECT gb.*,g.*,gb.act_id AS group_buy_id, gb.goods_id, gb.ext_info, gb.goods_name, g.goods_thumb, g.goods_img ' . |
|
287 |
'FROM ' . $GLOBALS['ecs']->table('goods_activity') . ' AS gb, ' . |
|
288 |
$GLOBALS['ecs']->table('goods') . ' AS g ' . |
|
289 |
"WHERE gb.act_type = '" . GAT_GROUP_BUY . "' " . |
|
290 |
"AND g.goods_id = gb.goods_id " . |
|
291 |
"AND gb.start_time <= '" . $time . "' " . |
|
292 |
"AND gb.end_time >= '" . $time . "' " . |
|
293 |
"AND g.is_delete = 0 " . |
|
294 |
"ORDER BY gb.act_id DESC " . |
|
295 |
"LIMIT $limit" ; |
|
296 |
|
|
297 |
$res = $GLOBALS['db']->query($sql); |
|
298 |
|
|
299 |
while ($row = $GLOBALS['db']->fetchRow($res)) |
|
300 |
{ |
|
301 |
/* 如果缩略图为空,使用默认图片 */ |
|
302 |
$row['goods_img'] = get_image_path($row['goods_id'], $row['goods_img']); |
|
303 |
$row['thumb'] = get_image_path($row['goods_id'], $row['goods_thumb'], true); |
|
304 |
|
|
305 |
/* 根据价格阶梯,计算最低价 */ |
|
306 |
$ext_info = unserialize($row['ext_info']); |
|
307 |
$price_ladder = $ext_info['price_ladder']; |
|
308 |
if (!is_array($price_ladder) || empty($price_ladder)) |
|
309 |
{ |
|
310 |
$row['last_price'] = price_format(0); |
|
311 |
} |
|
312 |
else |
|
313 |
{ |
|
314 |
foreach ($price_ladder AS $amount_price) |
|
315 |
{ |
|
316 |
$price_ladder[$amount_price['amount']] = $amount_price['price']; |
|
317 |
} |
|
318 |
} |
|
319 |
ksort($price_ladder); |
|
320 |
$row['last_price'] = price_format(end($price_ladder)); |
|
321 |
$row['url'] = build_uri('group_buy', array('gbid' => $row['group_buy_id'])); |
|
322 |
$row['short_name'] = $GLOBALS['_CFG']['goods_name_length'] > 0 ? |
|
323 |
sub_str($row['goods_name'], $GLOBALS['_CFG']['goods_name_length']) : $row['goods_name']; |
|
324 |
$row['short_style_name'] = add_style($row['short_name'],''); |
|
325 |
|
|
326 |
$stat = group_buy_stat($row['act_id'], $row['deposit']); |
|
327 |
$row['valid_goods'] = $stat['valid_goods']; |
|
328 |
$group_buy_list[] = $row; |
|
329 |
} |
|
330 |
} |
|
331 |
|
|
332 |
return $group_buy_list; |
|
333 |
} |
|
334 |
|
|
335 |
/** |
|
336 |
* 取得拍卖活动列表 |
|
337 |
* @return array |
|
338 |
*/ |
|
339 |
function index_get_auction() |
|
340 |
{ |
|
341 |
$now = gmtime(); |
|
342 |
$limit = get_library_number('auction', 'index'); |
|
343 |
$sql = "SELECT a.act_id, a.goods_id, a.goods_name, a.ext_info, g.goods_thumb ". |
|
344 |
"FROM " . $GLOBALS['ecs']->table('goods_activity') . " AS a," . |
|
345 |
$GLOBALS['ecs']->table('goods') . " AS g" . |
|
346 |
" WHERE a.goods_id = g.goods_id" . |
|
347 |
" AND a.act_type = '" . GAT_AUCTION . "'" . |
|
348 |
" AND a.is_finished = 0" . |
|
349 |
" AND a.start_time <= '$now'" . |
|
350 |
" AND a.end_time >= '$now'" . |
|
351 |
" AND g.is_delete = 0" . |
|
352 |
" ORDER BY a.start_time DESC" . |
|
353 |
" LIMIT $limit"; |
|
354 |
$res = $GLOBALS['db']->query($sql); |
|
355 |
|
|
356 |
$list = array(); |
|
357 |
while ($row = $GLOBALS['db']->fetchRow($res)) |
|
358 |
{ |
|
359 |
$ext_info = unserialize($row['ext_info']); |
|
360 |
$arr = array_merge($row, $ext_info); |
|
361 |
$arr['formated_start_price'] = price_format($arr['start_price']); |
|
362 |
$arr['formated_end_price'] = price_format($arr['end_price']); |
|
363 |
$arr['thumb'] = get_image_path($row['goods_id'], $row['goods_thumb'], true); |
|
364 |
$arr['url'] = build_uri('auction', array('auid' => $arr['act_id'])); |
|
365 |
$arr['short_name'] = $GLOBALS['_CFG']['goods_name_length'] > 0 ? |
|
366 |
sub_str($arr['goods_name'], $GLOBALS['_CFG']['goods_name_length']) : $arr['goods_name']; |
|
367 |
$arr['short_style_name'] = add_style($arr['short_name'],''); |
|
368 |
$list[] = $arr; |
|
369 |
} |
|
370 |
|
|
371 |
return $list; |
|
372 |
} |
|
373 |
|
|
374 |
/** |
|
375 |
* 获得所有的友情链接 |
|
376 |
* |
|
377 |
* @access private |
|
378 |
* @return array |
|
379 |
*/ |
|
380 |
function index_get_links() |
|
381 |
{ |
|
382 |
$sql = 'SELECT link_logo, link_name, link_url FROM ' . $GLOBALS['ecs']->table('friend_link') . ' ORDER BY show_order'; |
|
383 |
$res = $GLOBALS['db']->getAll($sql); |
|
384 |
|
|
385 |
$links['img'] = $links['txt'] = array(); |
|
386 |
|
|
387 |
foreach ($res AS $row) |
|
388 |
{ |
|
389 |
if (!empty($row['link_logo'])) |
|
390 |
{ |
|
391 |
$links['img'][] = array('name' => $row['link_name'], |
|
392 |
'url' => $row['link_url'], |
|
393 |
'logo' => $row['link_logo']); |
|
394 |
} |
|
395 |
else |
|
396 |
{ |
|
397 |
$links['txt'][] = array('name' => $row['link_name'], |
|
398 |
'url' => $row['link_url']); |
|
399 |
} |
|
400 |
} |
|
401 |
|
|
402 |
return $links; |
|
403 |
} |
|
404 |
|
|
405 |
|
|
406 |
function get_flash_xml() |
|
407 |
{ |
|
408 |
$flashdb = array(); |
|
409 |
if (file_exists(ROOT_PATH . DATA_DIR . '/flash_data.xml')) |
|
410 |
{ |
|
411 |
|
|
412 |
|
|
413 |
if (!preg_match_all('/item_url="([^"]+)"\slink="([^"]+)"\stext="([^"]*)"\ssort="([^"]*)"/', file_get_contents(ROOT_PATH . DATA_DIR . '/flash_data.xml'), $t, PREG_SET_ORDER)) |
|
414 |
{ |
|
415 |
preg_match_all('/item_url="([^"]+)"\slink="([^"]+)"\stext="([^"]*)"/', file_get_contents(ROOT_PATH . DATA_DIR . '/flash_data.xml'), $t, PREG_SET_ORDER); |
|
416 |
} |
|
417 |
|
|
418 |
if (!empty($t)) |
|
419 |
{ |
|
420 |
foreach ($t as $key => $val) |
|
421 |
{ |
|
422 |
$val[4] = isset($val[4]) ? $val[4] : 0; |
|
423 |
$flashdb[] = array('src'=>$val[1],'url'=>$val[2],'text'=>$val[3],'sort'=>$val[4]); |
|
424 |
|
|
425 |
//print_r($flashdb); |
|
426 |
} |
|
427 |
} |
|
428 |
} |
|
429 |
return $flashdb; |
|
430 |
} |
|
431 |
|
|
432 |
|
|
433 |
function get_hot_cat_goods($type = '',$cat_id, $num = 7) |
|
434 |
{ |
|
435 |
$children = get_children($cat_id); |
|
436 |
|
|
437 |
$sql = 'SELECT g.goods_id,g.cat_id, g.goods_name, g.market_price, g.shop_price AS org_price, ' . |
|
438 |
"IFNULL(mp.user_price, g.shop_price * '$_SESSION[discount]') AS shop_price, ". |
|
439 |
'g.promote_price, promote_start_date, promote_end_date, g.goods_brief, g.goods_thumb, g.goods_img ' . |
|
440 |
"FROM " . $GLOBALS['ecs']->table('goods') . ' AS g '. |
|
441 |
"LEFT JOIN " . $GLOBALS['ecs']->table('member_price') . " AS mp ". |
|
442 |
"ON mp.goods_id = g.goods_id AND mp.user_rank = '$_SESSION[user_rank]' ". |
|
443 |
'WHERE g.is_on_sale = 1 AND g.is_alone_sale = 1 AND g.is_delete = 0' ; |
|
444 |
|
|
445 |
switch ($type) |
|
446 |
{ |
|
447 |
case 'best': |
|
448 |
$sql .= ' AND is_best = 1'; |
|
449 |
break; |
|
450 |
case 'new': |
|
451 |
$sql .= ' AND is_new = 1'; |
|
452 |
break; |
|
453 |
case 'hot': |
|
454 |
$sql .= ' AND is_hot = 1'; |
|
455 |
break; |
|
456 |
case 'promote': |
|
457 |
$time = gmtime(); |
|
458 |
$sql .= " AND is_promote = 1 AND promote_start_date <= '$time' AND promote_end_date >= '$time'"; |
|
459 |
break; |
|
460 |
} |
|
461 |
|
|
462 |
$sql.=' AND (' . $children . 'OR ' . get_extension_goods($children) . ') ' .'ORDER BY g.sort_order, g.goods_id DESC'; |
|
463 |
|
|
464 |
|
|
465 |
|
|
466 |
if ($num > 0) |
|
467 |
{ |
|
468 |
$sql .= ' LIMIT ' . $num; |
|
469 |
} |
|
470 |
|
|
471 |
//echo $sql; |
|
472 |
|
|
473 |
$res = $GLOBALS['db']->getAll($sql); |
|
474 |
|
|
475 |
$goods = array(); |
|
476 |
foreach ($res AS $idx => $row) |
|
477 |
{ |
|
478 |
if ($row['promote_price'] > 0) |
|
479 |
{ |
|
480 |
$promote_price = bargain_price($row['promote_price'], $row['promote_start_date'], $row['promote_end_date']); |
|
481 |
$goods[$idx]['promote_price'] = $promote_price > 0 ? price_format($promote_price) : ''; |
|
482 |
} |
|
483 |
else |
|
484 |
{ |
|
485 |
$goods[$idx]['promote_price'] = ''; |
|
486 |
} |
|
487 |
|
|
488 |
$temp=$row['cat_id']; |
|
489 |
$cat_info=get_hot_cat_info($temp); |
|
490 |
|
|
491 |
$goods[$idx]['id'] = $row['goods_id']; |
|
492 |
$goods[$idx]['cat_id'] = $row['cat_id']; |
|
493 |
$goods[$idx]['cat_name'] = $cat_info['name']; |
|
494 |
$goods[$idx]['cat_url'] = $cat_info['url']; |
|
495 |
|
|
496 |
|
|
497 |
$goods[$idx]['name'] = $row['goods_name']; |
|
498 |
$goods[$idx]['brief'] = $row['goods_brief']; |
|
499 |
$goods[$idx]['market_price'] = price_format($row['market_price']); |
|
500 |
$goods[$idx]['short_name'] = $GLOBALS['_CFG']['goods_name_length'] > 0 ? |
|
501 |
sub_str($row['goods_name'], $GLOBALS['_CFG']['goods_name_length']) : $row['goods_name']; |
|
502 |
$goods[$idx]['shop_price'] = price_format($row['shop_price']); |
|
503 |
$goods[$idx]['thumb'] = empty($row['goods_thumb']) ? $GLOBALS['_CFG']['no_picture'] : $row['goods_thumb']; |
|
504 |
$goods[$idx]['goods_img'] = empty($row['goods_img']) ? $GLOBALS['_CFG']['no_picture'] : $row['goods_img']; |
|
505 |
$goods[$idx]['url'] = build_uri('goods', array('gid' => $row['goods_id']), $row['goods_name']); |
|
506 |
} |
|
507 |
|
|
508 |
return $goods; |
|
509 |
} |
|
510 |
|
|
511 |
function get_hot_cat_info($cat_id) |
|
512 |
{ |
|
513 |
/* 分类信息 */ |
|
514 |
$sql = 'SELECT cat_name FROM ' . $GLOBALS['ecs']->table('category') . " WHERE cat_id = '$cat_id'"; |
|
515 |
$cat['name'] = $GLOBALS['db']->getOne($sql); |
|
516 |
$cat['url'] = build_uri('category', array('cid' => $cat_id), $cat['name']); |
|
517 |
$cat['id'] = $cat_id; |
|
518 |
|
|
519 |
return $cat; |
|
520 |
} |
|
521 |
|
|
522 |
|
|
523 |
|
|
524 |
|
|
525 |
|
|
526 |
/** |
|
527 |
* ============================================================================ |
|
528 |
* 文章自定义数据调用函数 |
|
529 |
* ============================================================================ |
|
530 |
*/ |
|
531 |
//取得文章里面的图片 |
|
532 |
function GetImageSrc($body) { |
|
533 |
if( !isset($body) ) { |
|
534 |
return ''; |
|
535 |
} |
|
536 |
else { |
|
537 |
preg_match_all ("/<(img|IMG)(.*)(src|SRC)=[\"|'|]{0,}([h|\/].*(jpg|JPG|gif|GIF|png|PNG))[\"|'|\s]{0,}/isU",$body,$out); |
|
538 |
return $out[4]; |
|
539 |
} |
|
540 |
} |
|
541 |
|
|
542 |
//提取文里面的URL |
|
543 |
function GetArticleUrl($body) { |
|
544 |
if( !isset($body) ) { |
|
545 |
return ''; |
|
546 |
} |
|
547 |
else { |
|
548 |
preg_match_all("/<(a|A)(.*)(href|HREF)=[\"|'|](.*)[\"|'|\s]{0,}>(.*)<\/(a|A)>/isU",$body,$out); |
|
549 |
return $out; |
|
550 |
} |
|
551 |
} |
|
552 |
|
|
553 |
function get_article_children_new ($cat = 0) |
|
554 |
{ |
|
555 |
return db_create_in(array_unique(array_merge(array($cat), array_keys(article_cat_list($cat, 0, false)))), 'a.cat_id'); |
|
556 |
} |
|
557 |
|
|
558 |
/** |
|
559 |
* 按文章ID号/分类ID/商品ID号/商品分类ID号取得文章 |
|
560 |
* @param array $id 文章ID或文章分类ID |
|
561 |
* @param string $getwhat 以何种方式取文章其中可选参数有: |
|
562 |
[1]art_cat(以文章分类ID获取) [2]art_id(以文章ID获取) |
|
563 |
[3]goods_cat(以商品分类ID获取) [4]goods_id(以商品ID获取) |
|
564 |
其中的[3]和[4]必须有商品关联文章或文章关联商品 |
|
565 |
* @param integer $num 控制显示多少条文章.当参数为0时则全部显示 |
|
566 |
* @param integer $start 从第几条数据开始取 |
|
567 |
* @param boolean $isrand 是否随机显示文章(默认为不显示) |
|
568 |
* @param boolean $showall 是否显示隐藏的文章(黑认为不显示隐藏文章) |
|
569 |
* @return array |
|
570 |
*/ |
|
571 |
function get_article_new( $id = array(0), $getwhat = 'art_id', $num = 0, $isrand = false, $showall = true, $start = 0 ) { |
|
572 |
$sql = ''; |
|
573 |
$findkey = ''; |
|
574 |
$search = ''; |
|
575 |
$wherestr = ''; |
|
576 |
|
|
577 |
for( $i=0; $i<count($id); $i++ ) { |
|
578 |
if( $i<count($id)-1 ) { |
|
579 |
$findkey .= $id[$i] .','; |
|
580 |
} |
|
581 |
else { |
|
582 |
$findkey .= $id[$i]; |
|
583 |
} |
|
584 |
} |
|
585 |
|
|
586 |
if( $getwhat == 'art_cat' ){ |
|
587 |
for( $i=0; $i<count($id); $i++ ) { |
|
588 |
if( $i<count($id)-1 ) { |
|
589 |
$search .= get_article_children_new($id[$i]) . ' OR '; |
|
590 |
} |
|
591 |
else { |
|
592 |
$search .= get_article_children_new($id[$i]); |
|
593 |
} |
|
594 |
} |
|
595 |
} |
|
596 |
elseif($getwhat == 'goods_cat') { |
|
597 |
for( $i=0; $i<count($id); $i++) { |
|
598 |
if( $i<count($id)-1 ) { |
|
599 |
$search .= get_children($id[$i]) . ' OR '; |
|
600 |
} |
|
601 |
else { |
|
602 |
$search .= get_children($id[$i]); |
|
603 |
} |
|
604 |
} |
|
605 |
} |
|
606 |
elseif( $getwhat == 'art_id' ) { |
|
607 |
$search = 'a.article_id IN' . '(' . $findkey . ')'; |
|
608 |
} |
|
609 |
elseif( $getwhat == 'goods_id' ) { |
|
610 |
$search = 'g.goods_id IN' . '(' . $findkey . ')'; |
|
611 |
} |
|
612 |
$wherestr = '(' . $search . ')'; |
|
613 |
|
|
614 |
if( $getwhat == 'art_cat' || $getwhat == 'art_id' ) { |
|
615 |
$sql = 'SELECT a.*,ac.cat_id,ac.cat_name,ac.keywords as cat_keywords,ac.cat_desc |
|
616 |
FROM ' . $GLOBALS['ecs']->table('article') . ' AS a, ' . |
|
617 |
$GLOBALS['ecs']->table('article_cat') . ' AS ac' . |
|
618 |
' WHERE (a.cat_id = ac.cat_id) AND ' . $wherestr; |
|
619 |
} |
|
620 |
elseif( $getwhat == 'goods_cat' || $getwhat == 'goods_id' ) { |
|
621 |
$sql = 'SELECT DISTINCT a.*,ac.cat_id,ac.cat_name,ac.keywords as cat_keywords,ac.cat_desc FROM ' . |
|
622 |
$GLOBALS['ecs']->table('goods') .' AS g ' . |
|
623 |
'LEFT JOIN ' . $GLOBALS['ecs']->table('goods_article') . ' AS ga ON g.goods_id=ga.goods_id INNER JOIN ' . |
|
624 |
$GLOBALS['ecs']->table('article') . ' AS a ON ga.article_id = a.article_id, ' . |
|
625 |
$GLOBALS['ecs']->table('article_cat') . 'AS ac ' . |
|
626 |
'WHERE (a.cat_id = ac.cat_id) AND ' . $wherestr; |
|
627 |
} |
|
628 |
|
|
629 |
|
|
630 |
if( ($showall == false) && ( $getwhat == 'art_cat' || $getwhat == 'art_id' ) ) { |
|
631 |
$sql .= ' AND a.is_open=1'; |
|
632 |
} |
|
633 |
elseif( ($showall == false) && ( $getwhat == 'goods_cat' || $getwhat == 'goods_id' ) ) { |
|
634 |
$sql .= ' AND a.is_open=1'; |
|
635 |
} |
|
636 |
|
|
637 |
if( $isrand == true ) { |
|
638 |
$sql .= ' ORDER BY rand()'; |
|
639 |
} |
|
640 |
elseif( ($isrand == false) && ( $getwhat == 'art_cat' || $getwhat == 'art_id' ) ) { |
|
641 |
$sql .= ' ORDER BY a.add_time DESC, a.article_id DESC'; |
|
642 |
} |
|
643 |
elseif( ($isrand == false) && ( $getwhat == 'goods_cat' || $getwhat == 'goods_id' ) ) { |
|
644 |
$sql .= ' ORDER BY a.add_time DESC, a.article_id DESC'; |
|
645 |
} |
|
646 |
|
|
647 |
if( $start == 0 && $num>0 ) { |
|
648 |
$sql .= ' LIMIT ' . $num; |
|
649 |
} |
|
650 |
elseif( $start>0 && $num>0 ) { |
|
651 |
$sql .= ' LIMIT ' . $start . ',' . $num; |
|
652 |
} |
|
653 |
|
|
654 |
//开始查询 |
|
655 |
$arr = $GLOBALS['db']->getAll($sql); |
|
656 |
$articles = array(); |
|
657 |
foreach ($arr AS $id => $row) { |
|
658 |
$articles[$id]['cat_id'] = $row['cat_id']; |
|
659 |
$articles[$id]['cat_name'] = $row['cat_name']; |
|
660 |
$articles[$id]['cat_url'] = build_uri('article_cat', array('acid' => $row['cat_id'])); |
|
661 |
$articles[$id]['cat_keywords'] = $row['cat_keywords']; |
|
662 |
$articles[$id]['cat_desc'] = $row['cat_desc']; |
|
663 |
$articles[$id]['title'] = $row['title']; |
|
664 |
$articles[$id]['url'] = build_uri('article', array('aid'=>$row['article_id']), $row['title']); |
|
665 |
$articles[$id]['author'] = $row['author']; |
|
666 |
$articles[$id]['content'] = $row['content']; |
|
667 |
$articles[$id]['keywords'] = $row['keywords']; |
|
668 |
$articles[$id]['description'] = $row['description']; |
|
669 |
$articles[$id]['file_url'] = $row['file_url']; |
|
670 |
$articles[$id]['link'] = $row['link']; |
|
671 |
$articles[$id]['addtime'] = date($GLOBALS['_CFG']['date_format'], $row['add_time']); |
|
672 |
$articles[$id]['content'] = $row['content']; |
|
673 |
$imgsrc = GetImageSrc($row['content']); |
|
674 |
$articles[$id]['img'] = $imgsrc; //提取文章中所有的图片 |
|
675 |
$link = GetArticleUrl($row['content']); |
|
676 |
$articles[$id]['link_url'] = $link[4]; //提取文章中所有的链接地址 |
|
677 |
$articles[$id]['link_title'] = $link[5]; //提取文章中所有的链接名称 |
|
678 |
} |
|
679 |
return $articles; |
|
680 |
} |
|
681 |
|
|
682 |
|
|
683 |
make_html(); |
|
684 |
|
|
685 |
?> |