本补丁是ECSHOP报价单程序的扩展,可根据查询条件导出报价单为EXCEL格式。
一、新建/quotation.php
<?php
/**
* ECSHOP 报价单
* ----------------------------------------------------------------------------
* A5源码Php技术
* http://down.vevb.com
* ----------------------------------------------------------------------------
* @author: A5源码
* @email: 1206888777#qq.com
*/
define('IN_ECS', true);
require(dirname(__FILE__) . '/includes/init.php');
$action = isset($_REQUEST['act']) ? trim($_REQUEST['act']) : 'default';
$where = get_quotation_where($_POST);
$sql = "SELECT g.goods_id, g.goods_name, g.shop_price, g.goods_number, c.cat_name AS goods_category,p.product_id,p.product_number,p.goods_attr".
" FROM " . $ecs->table('goods') . " AS g LEFT JOIN " . $ecs->table('category') . " AS c ON g.cat_id = c.cat_id LEFT JOIN ".$ecs->table('products')."as p On g.goods_id=p.goods_id" . $where . " AND is_on_sale = 1 AND is_alone_sale = 1 ";
/* 打印报价单 */
if ($action == 'print_quotation')
{
$smarty->template_dir = DATA_DIR;
$smarty->assign('shop_name', $_CFG['shop_title']);
$smarty->assign('cfg', $_CFG);
$goods_list = $db->getAll($sql);
foreach($goods_list as $key=>$val)
{
if(!empty($val['product_id']))
{
$goods_list[$key]['goods_number']=$val['product_number'];
$product_info=product_info($val['goods_attr'],$val['goods_id']);
$goods_list[$key]['members_price'] = $val['shop_price'];
$goods_list[$key]['shop_price'] += $product_info['attr_price'];
$goods_list[$key]['product_name']=$product_info['attr_value'];
$goods_list[$key]['attr_price'] =$product_info['attr_price'];
}
else
{
$goods_list[$key]['members_price'] = $val['shop_price'];
$goods_list[$key]['product_name']=' ';
$goods_list[$key]['product_price']=0;
}
$goods_list[$key]['goods_key']=$key;
}
$user_rank = $db->getAll("SELECT * FROM " .$ecs->table('user_rank') . "WHERE show_price = 1 OR rank_id = '$_SESSION[user_rank]'");
$rank_point = 0;
if (!empty($_SESSION['user_id']))
{
$rank_point = $db->getOne("SELECT rank_points FROM " . $ecs->table('users') . " WHERE user_id = '$_SESSION[user_id]'");
}
$user_rank = calc_user_rank($user_rank, $rank_point);
$user_men = serve_user($goods_list);
$smarty->assign('extend_price', $user_rank['ext_price']);
$smarty->assign('extend_rank', $user_men);
$smarty->assign('goods_list', $goods_list);
$html = $smarty->fetch('quotation_print.html');
exit($html);
}
assign_template();
/* 导出报价单 */
if ($action == 'export_quotation')
{
$goods_list = $db->getAll($sql);
foreach($goods_list as $key=>$val)
{
if(!empty($val['product_id']))
{
$goods_list[$key]['goods_number']=$val['product_number'];
$product_info=product_info($val['goods_attr'],$val['goods_id']);
$goods_list[$key]['members_price'] = $val['shop_price'];
$goods_list[$key]['shop_price'] += $product_info['attr_price'];
$goods_list[$key]['product_name']=$product_info['attr_value'];
$goods_list[$key]['attr_price'] =$product_info['attr_price'];
}
else
{
$goods_list[$key]['members_price'] = $val['shop_price'];
$goods_list[$key]['product_name']=' ';
$goods_list[$key]['product_price']=0;
}
$goods_list[$key]['goods_key']=$key;
}
$user_rank = $db->getAll("SELECT * FROM " .$ecs->table('user_rank') . "WHERE show_price = 1 OR rank_id = '$_SESSION[user_rank]'");
$rank_point = 0;
if (!empty($_SESSION['user_id']))
{
$rank_point = $db->getOne("SELECT rank_points FROM " . $ecs->table('users') . " WHERE user_id = '$_SESSION[user_id]'");
}
$user_rank = calc_user_rank($user_rank, $rank_point);
$user_men = serve_user($goods_list);
$file_name = $_SERVER['SERVER_NAME'] . '_quotation';
header("Content-type: application/vnd.ms-excel; charset=utf-8");
header("Content-Disposition: attachment; filename=$file_name.xls");
echo ecs_iconv(EC_CHARSET, 'UTF-8', $_LANG['goods_name']) . "/t";
echo ecs_iconv(EC_CHARSET, 'UTF-8', $_LANG['specifications']) . "/t";
echo ecs_iconv(EC_CHARSET, 'UTF-8', $_LANG['goods_category']) . "/t";
/* 是否启用库存管理、是否显示库存 */
if($_CFG['use_storage'] && $_CFG['show_goodsnumber'])
{
echo ecs_iconv(EC_CHARSET, 'UTF-8', $_LANG['goods_inventory']) . "/t";
}
echo ecs_iconv(EC_CHARSET, 'UTF-8', $_LANG['price']) . "/t";
/* 会员等级价格 */
foreach($user_rank['ext_price'] as $value)
{
echo ecs_iconv(EC_CHARSET, 'UTF-8', $value) . "/t";
}
echo "/n";
foreach($goods_list as $key=>$val)
{
echo ecs_iconv(EC_CHARSET, 'UTF-8', $goods_list[$key]['goods_name']) . "/t";
echo ecs_iconv(EC_CHARSET, 'UTF-8', $goods_list[$key]['product_name'] != ' ' ? $goods_list[$key]['product_name'] : NULL) . "/t"; //空格处理
echo ecs_iconv(EC_CHARSET, 'UTF-8', $goods_list[$key]['goods_category']) . "/t";
if($_CFG['use_storage'] && $_CFG['show_goodsnumber'])
{
echo ecs_iconv(EC_CHARSET, 'UTF-8', $goods_list[$key]['goods_number']) . "/t";
}
echo ecs_iconv(EC_CHARSET, 'UTF-8', $goods_list[$key]['shop_price']) . "/t";
foreach($user_men[$goods_list[$key]['goods_key']] as $value)
{
echo ecs_iconv(EC_CHARSET, 'UTF-8', $value['price']) . "/t";
}
echo "/n";
}
exit;
}
$position = assign_ur_here(0, $_LANG['quotation']);
$smarty->assign('page_title', $position['title']); // 页面标题
$smarty->assign('ur_here', $position['ur_here']); // 当前位置
$smarty->assign('cat_list', cat_list());
$smarty->assign('brand_list', get_brand_list());
if (is_null($smarty->get_template_vars('helps')))
{
$smarty->assign('helps', get_shop_help()); // 网店帮助
}
$smarty->display('quotation.dwt');
function get_quotation_where($filter)
{
include_once(ROOT_PATH . ADMIN_PATH . '/includes/lib_main.php');
$_filter = new StdClass();
$_filter->cat_id = $filter['cat_id'];
$_filter->brand_id = $filter['brand_id'];
$where = get_where_sql($_filter);
$_filter->keyword = $filter['keyword'];
$where .= isset($_filter->keyword) && trim($_filter->keyword) != '' ? " AND (g.goods_name LIKE '%" . mysql_like_quote($_filter->keyword) . "%' OR g.goods_sn LIKE '%" . mysql_like_quote($_filter->keyword) . "%' OR g.goods_id LIKE '%" . mysql_like_quote($_filter->keyword) . "%') " : '';
return $where;
}
function calc_user_rank($rank, $rank_point)
{
$_tmprank = array();
foreach($rank as $_rank)
{
if ($_rank['show_price'])
{
$_tmprank['ext_price'][] = $_rank['rank_name'];
$_tmprank['ext_rank'][] = $_rank['discount'];
}
else
{
if (!empty($_SESSION['user_id']) && ($rank_point >= $_rank['min_points']))
{
$_tmprank['ext_price'][] = $_rank['rank_name'];
$_tmprank['ext_rank'][] = $_rank['discount'];
}
}
}
return $_tmprank;
}
function serve_user($goods_list)
{
foreach ( $goods_list as $key=> $all_list )
{
$goods_id = $all_list['goods_id'];
$goods_key =$all_list['goods_key'];
$price = $all_list['members_price'];
$sql = "SELECT rank_id, IFNULL(mp.user_price, r.discount * $price / 100) AS price, r.rank_name, r.discount " .
'FROM ' . $GLOBALS['ecs']->table('user_rank') . ' AS r ' .
'LEFT JOIN ' . $GLOBALS['ecs']->table('member_price') . " AS mp ".
"ON mp.goods_id = '$goods_id' AND mp.user_rank = r.rank_id " .
"WHERE r.show_price = 1 OR r.rank_id = '$_SESSION[user_rank]'";
$res = $GLOBALS['db']->getAll($sql);
foreach ( $res as $row )
{
$arr[$row['rank_id']] = array(
'rank_name' => htmlspecialchars($row['rank_name']),
'price' => price_format($row['price']+$all_list['attr_price']));
}
$arr_list[$goods_key] = $arr;
}
return $arr_list;
}
function product_info($goods_attr,$goods_id)
{
$goods_attr=str_replace('|',' OR goods_attr_id=',$goods_attr);
$sql="SELECT attr_value,attr_price FROM ". $GLOBALS['ecs']->table('goods_attr') ." WHERE goods_id='$goods_id' AND (goods_attr_id = $goods_attr)";
$result =$GLOBALS['db']->getAll($sql);
$i=1;
$count=count($result);
foreach ($result as $val)
{
$i==$count?$f='':$f='<br/>';
$product_info['attr_value'].=$val['attr_value'].$f;
$product_info['attr_price']+=$val['attr_price'];
$i++;
}
return($product_info);
}
?>
二、编辑/languages/zh_cn/common.php,添加
$_LANG['export_quotation'] = "导出报价单";
三、编辑模板文件quotation.dwt
<h6><span>{$lang.print_quotation}</span></h6>
<form action="quotation.php" method="post" name="searchForm" target="_blank" class="quotation">
<!-- 分类 -->
<select name="cat_id"><option value="0">{$lang.all_category}</option>{$cat_list}</select>
<!-- 品牌 -->
<select name="brand_id"><option value="0">{$lang.all_brand}</option>{html_options options=$brand_list}</select>
<!-- 关键字 -->
{$lang.keywords} <input type="text" name="keyword" class="inputBg"/>
<!-- 搜索 -->
<input name="act" type="hidden" value="print_quotation" />
<input type="submit" name="print_quotation" id="print_quotation" value="{$lang.print_quotation}" style="vertical-align:middle;" class="bnt_blue_1" />
</form>
下面添加
<h6><span>{$lang.export_quotation}</span></h6>
<form action="quotation.php" method="post" name="searchForm" target="_blank" class="quotation">
<!-- 分类 -->
<select name="cat_id"><option value="0">{$lang.all_category}</option>{$cat_list}</select>
<!-- 品牌 -->
<select name="brand_id"><option value="0">{$lang.all_brand}</option>{html_options options=$brand_list}</select>
<!-- 关键字 -->
{$lang.keywords} <input type="text" name="keyword" class="inputBg"/>
<!-- 搜索 -->
<input name="act" type="hidden" value="export_quotation" />
<input type="submit" name="export_quotation" id="export" value="{$lang.export_quotation}" style="vertical-align:middle;" class="bnt_blue_1" />
</form>
新闻热点
疑难解答