加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
goods.php 7.10 KB
一键复制 编辑 原始数据 按行查看 历史
iHesir 提交于 2014-04-14 14:53 . 初始化项目
<?php
/**
* ECSHOP 商品详情
* ============================================================================
* * 版权所有 2005-2012 上海商派网络科技有限公司,并保留所有权利。
* 网站地址: http://www.ecshop.com;
* ----------------------------------------------------------------------------
* 这不是一个自由软件!您只能在不用于商业目的的前提下对程序代码进行修改和
* 使用;不允许对程序代码以任何形式任何目的的再发布。
* ============================================================================
* $Author: liubo $
* $Id: goods.php 17217 2011-01-19 06:29:08Z liubo $
*/
define('IN_ECS', true);
require(dirname(__FILE__) . '/includes/init.php');
if ((DEBUG_MODE & 2) != 2)
{
$smarty->caching = true;
}
$affiliate = unserialize($GLOBALS['_CFG']['affiliate']);
$smarty->assign('affiliate', $affiliate);
/*------------------------------------------------------ */
//-- INPUT
/*------------------------------------------------------ */
$goods_id = isset($_REQUEST['id']) ? intval($_REQUEST['id']) : 0;
/*------------------------------------------------------ */
//-- PROCESSOR
/*------------------------------------------------------ */
$cache_id = $goods_id . '-' . $_SESSION['user_rank'].'-'.$_CFG['lang'];
$cache_id = sprintf('%X', crc32($cache_id));
if (!$smarty->is_cached('goods.dwt', $cache_id))
{
$smarty->assign('image_width', $_CFG['image_width']);
$smarty->assign('image_height', $_CFG['image_height']);
$smarty->assign('id', $goods_id);
$smarty->assign('type', 0);
$smarty->assign('cfg', $_CFG);
$smarty->assign('promotion', get_promotion_info($goods_id));//促销信息
$smarty->assign('promotion_info', get_promotion_info());
/* 获得商品的信息 */
$goods = get_goods_info($goods_id);
if ($goods === false)
{
/* 如果没有找到任何记录则跳回到首页 */
ecs_header("Location: ./\n");
exit;
}
else
{
assign_template('c', $catlist);
if ($goods['brand_id'] > 0)
{
$goods['goods_brand_url'] = build_uri('brand', array('bid'=>$goods['brand_id']), $goods['goods_brand']);
}
$shop_price = $goods['shop_price'];
$linked_goods = get_linked_goods($goods_id); //关联商品
$goods['goods_style_name'] = add_style($goods['goods_name'], $goods['goods_name_style']);
/* 购买该商品可以得到多少钱的红包 */
if ($goods['bonus_type_id'] > 0)
{
$time = gmtime();
$sql = "SELECT type_money FROM " . $ecs->table('bonus_type') .
" WHERE type_id = '$goods[bonus_type_id]' " .
" AND send_type = '" . SEND_BY_GOODS . "' " .
" AND send_start_date <= '$time'" .
" AND send_end_date >= '$time'";
$goods['bonus_money'] = floatval($db->getOne($sql));
if ($goods['bonus_money'] > 0)
{
$goods['bonus_money'] = price_format($goods['bonus_money']);
}
}
$smarty->assign('goods', $goods);
$smarty->assign('goods_id', $goods['goods_id']);
$smarty->assign('promote_end_time', $goods['gmt_end_time']);
$smarty->assign('categories', get_categories_tree($goods['cat_id'])); // 分类树
/* meta */
$smarty->assign('keywords', htmlspecialchars($goods['keywords']));
$smarty->assign('description', htmlspecialchars($goods['goods_brief']));
$position = assign_ur_here($goods['cat_id'], $goods['goods_name']);
/* current position */
$smarty->assign('page_title', $position['title']); // 页面标题
$smarty->assign('ur_here', $position['ur_here']); // 当前位置
$properties = get_goods_properties($goods_id); // 获得商品的规格和属性
$smarty->assign('properties', $properties['pro']); // 商品属性
$smarty->assign('specification', $properties['spe']); // 商品规格
$smarty->assign('pictures', get_goods_gallery($goods_id)); // 商品相册
$smarty->assign('related_goods', $linked_goods); // 关联商品
//获取tag
$tag_array = get_tags($goods_id);
$smarty->assign('tags', $tag_array); // 商品的标记
assign_dynamic('goods');
}
}
$smarty->display('goods.dwt', $cache_id);
/**
* 获得指定商品的关联商品
*
* @access public
* @param integer $goods_id
* @return array
*/
function get_linked_goods($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('link_goods') . ' lg ' .
'LEFT JOIN ' . $GLOBALS['ecs']->table('goods') . ' AS g ON g.goods_id = lg.link_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 lg.goods_id = '$goods_id' AND g.is_on_sale = 1 AND g.is_alone_sale = 1 AND g.is_delete = 0 ".
"LIMIT " . $GLOBALS['_CFG']['related_goods_number'];
$res = $GLOBALS['db']->query($sql);
$arr = array();
while ($row = $GLOBALS['db']->fetchRow($res))
{
$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_id'], $row['goods_thumb'], true);
$arr[$row['goods_id']]['goods_img'] = get_image_path($row['goods_id'], $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;
}
?>
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化