You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
158 lines
6.6 KiB
158 lines
6.6 KiB
<?php
|
|
|
|
/**
|
|
* 获得指定的文章的详细信息
|
|
*
|
|
* @access private
|
|
* @param integer $article_id
|
|
* @return array
|
|
*/
|
|
function get_article_info($article_id)
|
|
{
|
|
/* 获得文章的信息 */
|
|
$sql = "SELECT a.*, IFNULL(AVG(r.comment_rank), 0) AS comment_rank ".
|
|
"FROM " .$GLOBALS['ecs']->table('article'). " AS a ".
|
|
"LEFT JOIN " .$GLOBALS['ecs']->table('comment'). " AS r ON r.id_value = a.article_id AND comment_type = 1 ".
|
|
"WHERE a.is_open = 1 AND a.article_id = '$article_id' GROUP BY a.article_id";
|
|
$row = $GLOBALS['db']->getRow($sql);
|
|
|
|
if ($row !== false)
|
|
{
|
|
$row['comment_rank'] = ceil($row['comment_rank']); // 用户评论级别取整
|
|
$row['add_time'] = local_date("Y-m-d H-i-s", $row['add_time']); // 修正添加时间显示
|
|
|
|
/* 作者信息如果为空,则用网站名称替换 */
|
|
if (empty($row['author']) || $row['author'] == '_SHOPHELP')
|
|
{
|
|
$row['author'] = $GLOBALS['_CFG']['shop_name'];
|
|
}
|
|
}
|
|
|
|
return $row;
|
|
}
|
|
|
|
|
|
/**
|
|
* 获得文章关联的商品
|
|
*
|
|
* @access public
|
|
* @param integer $id
|
|
* @return array
|
|
*/
|
|
function article_related_goods($id)
|
|
{
|
|
$sql = 'SELECT g.goods_id, g.goods_name, g.goods_thumb, g.goods_img, g.shop_price AS org_price, ' .
|
|
"IFNULL(mp.user_price, g.shop_price * '$_SESSION[discount]') AS shop_price, ".
|
|
'g.market_price, g.promote_price, g.promote_start_date, g.promote_end_date ' .
|
|
'FROM ' . $GLOBALS['ecs']->table('goods_article') . ' ga ' .
|
|
'LEFT JOIN ' . $GLOBALS['ecs']->table('goods') . ' AS g ON g.goods_id = ga.goods_id ' .
|
|
"LEFT JOIN " . $GLOBALS['ecs']->table('member_price') . " AS mp ".
|
|
"ON mp.goods_id = g.goods_id AND mp.user_rank = '$_SESSION[user_rank]' ".
|
|
"WHERE ga.article_id = '$id' AND g.is_on_sale = 1 AND g.is_alone_sale = 1 AND g.is_delete = 0";
|
|
$res = $GLOBALS['db']->query($sql);
|
|
|
|
$arr = array();
|
|
foreach ($res as $row)
|
|
{
|
|
$arr[$row['goods_id']]['goods_id'] = $row['goods_id'];
|
|
$arr[$row['goods_id']]['goods_name'] = $row['goods_name'];
|
|
$arr[$row['goods_id']]['short_name'] = $GLOBALS['_CFG']['goods_name_length'] > 0 ?
|
|
sub_str($row['goods_name'], $GLOBALS['_CFG']['goods_name_length']) : $row['goods_name'];
|
|
$arr[$row['goods_id']]['goods_thumb'] = get_image_path($row['goods_thumb'], true);
|
|
$arr[$row['goods_id']]['goods_img'] = get_image_path($row['goods_img']);
|
|
$arr[$row['goods_id']]['market_price'] = price_format($row['market_price']);
|
|
$arr[$row['goods_id']]['shop_price'] = price_format($row['shop_price']);
|
|
$arr[$row['goods_id']]['url'] = build_uri('goods', array('gid' => $row['goods_id']), $row['goods_name']);
|
|
|
|
if ($row['promote_price'] > 0)
|
|
{
|
|
$arr[$row['goods_id']]['promote_price'] = bargain_price($row['promote_price'], $row['promote_start_date'], $row['promote_end_date']);
|
|
$arr[$row['goods_id']]['formated_promote_price'] = price_format($arr[$row['goods_id']]['promote_price']);
|
|
}
|
|
else
|
|
{
|
|
$arr[$row['goods_id']]['promote_price'] = 0;
|
|
}
|
|
}
|
|
|
|
return $arr;
|
|
}
|
|
/**
|
|
* 获得文章分类下的文章列表
|
|
*
|
|
* @access public
|
|
* @param integer $cat_id
|
|
* @param integer $page
|
|
* @param integer $size
|
|
*
|
|
* @return array
|
|
*/
|
|
function get_cat_articles($cat_id, $page = 1, $size = 20, $requirement = '')
|
|
{
|
|
//取出所有非0的文章
|
|
if ($cat_id == '-1') {
|
|
$cat_str = 'cat_id > 0';
|
|
} else {
|
|
$cat_str = get_article_children($cat_id);
|
|
}
|
|
//增加搜索条件,如果有搜索内容就进行搜索
|
|
if ($requirement != '') {
|
|
$sql = 'SELECT article_id, title, author, add_time, file_url, open_type' .
|
|
' FROM ' . $GLOBALS['ecs']->table('article') .
|
|
' WHERE is_open = 1 AND title like \'%' . $requirement . '%\' ' .
|
|
' ORDER BY article_type DESC, article_id DESC';
|
|
} else {
|
|
$sql = 'SELECT article_id, title, author, add_time, file_url, open_type' .
|
|
' FROM ' . $GLOBALS['ecs']->table('article') .
|
|
' WHERE is_open = 1 AND ' . $cat_str .
|
|
' ORDER BY article_type DESC, article_id DESC';
|
|
}
|
|
$res = $GLOBALS['db']->selectLimit($sql, $size, ($page - 1) * $size);
|
|
|
|
$arr = array();
|
|
foreach ($res as $row) {
|
|
$article_id = $row['article_id'];
|
|
$arr[$article_id]['id'] = $article_id;
|
|
$arr[$article_id]['title'] = $row['title'];
|
|
$arr[$article_id]['short_title'] = $GLOBALS['_CFG']['article_title_length'] > 0 ? sub_str($row['title'], $GLOBALS['_CFG']['article_title_length']) : $row['title'];
|
|
$arr[$article_id]['author'] = empty($row['author']) || $row['author'] == '_SHOPHELP' ? $GLOBALS['_CFG']['shop_name'] : $row['author'];
|
|
$arr[$article_id]['url'] = $row['open_type'] != 1 ? build_uri('article', array('aid' => $article_id), $row['title']) : trim($row['file_url']);
|
|
$arr[$article_id]['add_time'] = date($GLOBALS['_CFG']['date_format'], $row['add_time']);
|
|
}
|
|
return $arr;
|
|
}
|
|
function mdate($time = NULL) {
|
|
$text = '';
|
|
$time = $time === NULL || $time > gmtime() ? gmtime() : intval($time);
|
|
$t = gmtime() - $time; //时间差 (秒)
|
|
$y = date('Y', $time)-date('Y', gmtime());//是否跨年
|
|
switch($t){
|
|
case $t == 0:
|
|
$text = '刚刚';
|
|
break;
|
|
case $t < 60:
|
|
$text = $t . '秒前'; // 一分钟内
|
|
break;
|
|
case $t < 60 * 60:
|
|
$text = floor($t / 60) . '分钟前'; //一小时内
|
|
break;
|
|
case $t < 60 * 60 * 24:
|
|
$text = floor($t / (60 * 60)) . '小时前'; // 一天内
|
|
break;
|
|
case $t < 60 * 60 * 24 * 3:
|
|
$text = floor($time/(60*60*24)) ==1 ?'昨天 ' . date('H:i', $time) : '前天 ' . date('H:i', $time) ; //昨天和前天
|
|
break;
|
|
case $t < 60 * 60 * 24 * 30:
|
|
$text = date('m月d日 H:i', $time); //一个月内
|
|
break;
|
|
case $t < 60 * 60 * 24 * 365&&$y==0:
|
|
$text = date('m月d日', $time); //一年内
|
|
break;
|
|
default:
|
|
$text = date('Y年m月d日', $time); //一年以前
|
|
break;
|
|
}
|
|
|
|
return $text;
|
|
}
|
|
|
|
|