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.
322 lines
9.8 KiB
322 lines
9.8 KiB
<?php
|
|
/**
|
|
* ECSHOP 商品批量上传、修改
|
|
* ============================================================================
|
|
* * 版权所有 2005-2016 上海商创网络科技有限公司,并保留所有权利。
|
|
* 网站地址: http://www.ecmoban.com;
|
|
* ----------------------------------------------------------------------------
|
|
* 这不是一个自由软件!您只能在不用于商业目的的前提下对程序代码进行修改和
|
|
* 使用;不允许对程序代码以任何形式任何目的的再发布。
|
|
* ============================================================================
|
|
* $Author: liubo $
|
|
* $Id: goods_batch.php 17217 2011-01-19 06:29:08Z liubo $
|
|
*/
|
|
|
|
define('IN_ECS', true);
|
|
|
|
require(dirname(__FILE__) . '/includes/init.php');
|
|
require('includes/lib_goods.php');
|
|
|
|
/*------------------------------------------------------ */
|
|
//-- 批量上传
|
|
/*------------------------------------------------------ */
|
|
|
|
if ($_REQUEST['act'] == 'add')
|
|
{
|
|
/* 检查权限 */
|
|
admin_priv('goods_manage');
|
|
|
|
$goods_id = isset($_REQUEST['goods_id']) ? intval($_REQUEST['goods_id']) : 0;
|
|
$warehouse_id = isset($_REQUEST['warehouse_id']) ? intval($_REQUEST['warehouse_id']) : 0; //地区
|
|
|
|
if($goods_id > 0){
|
|
$smarty->assign('action_link', array('text' => '返回商品货品详细页', 'href'=>'goods.php?act=product_list&goods_id=' .$goods_id));
|
|
}
|
|
|
|
/* 取得可选语言 */
|
|
$dir = opendir('../languages');
|
|
$lang_list = array(
|
|
'UTF8' => $_LANG['charset']['utf8'],
|
|
'GB2312' => $_LANG['charset']['zh_cn'],
|
|
'BIG5' => $_LANG['charset']['zh_tw'],
|
|
);
|
|
$download_list = array();
|
|
while (@$file = readdir($dir))
|
|
{
|
|
if ($file != '.' && $file != '..' && $file != ".svn" && $file != "_svn" && is_dir('../languages/' .$file) == true)
|
|
{
|
|
$download_list[$file] = sprintf($_LANG['download_file'], isset($_LANG['charset'][$file]) ? $_LANG['charset'][$file] : $file);
|
|
}
|
|
}
|
|
@closedir($dir);
|
|
$smarty->assign('lang_list', $lang_list);
|
|
$smarty->assign('download_list', $download_list);
|
|
$smarty->assign('goods_id', $goods_id);
|
|
$smarty->assign('warehouse_id', $warehouse_id);
|
|
|
|
$attribute_list = get_attribute_list($goods_id);
|
|
$smarty->assign('attribute_list', $attribute_list);
|
|
|
|
$goods_date = array('goods_name');
|
|
$where = "goods_id = '$goods_id'";
|
|
$goods_name = get_table_date('goods', $where, $goods_date,2);
|
|
$smarty->assign('goods_name', $goods_name);
|
|
|
|
/* 参数赋值 */
|
|
$ur_here = $_LANG['13_batch_add'];
|
|
$smarty->assign('ur_here', $ur_here);
|
|
|
|
/* 显示模板 */
|
|
assign_query_info();
|
|
$smarty->display('goods_produts_area_batch.htm');
|
|
}
|
|
|
|
/*------------------------------------------------------ */
|
|
//-- 批量上传:处理
|
|
/*------------------------------------------------------ */
|
|
|
|
elseif ($_REQUEST['act'] == 'upload')
|
|
{
|
|
/* 检查权限 */
|
|
admin_priv('goods_manage');
|
|
|
|
//ecmoban模板堂 --zhuo start 仓库
|
|
if($_FILES['file']['name']){
|
|
$line_number = 0;
|
|
$arr = array();
|
|
$goods_list = array();
|
|
$field_list = array_keys($_LANG['upload_product']); // 字段列表
|
|
$_POST['charset'] = 'GB2312';
|
|
$data = file($_FILES['file']['tmp_name']);
|
|
|
|
if(count($data) > 0){
|
|
foreach ($data AS $line)
|
|
{
|
|
// 跳过第一行
|
|
if ($line_number == 0)
|
|
{
|
|
$line_number++;
|
|
continue;
|
|
}
|
|
|
|
// 转换编码
|
|
if (($_POST['charset'] != 'UTF8') && (strpos(strtolower(EC_CHARSET), 'utf') === 0))
|
|
{
|
|
$line = ecs_iconv($_POST['charset'], 'UTF8', $line);
|
|
}
|
|
|
|
// 初始化
|
|
$arr = array();
|
|
$buff = '';
|
|
$quote = 0;
|
|
$len = strlen($line);
|
|
for ($i = 0; $i < $len; $i++)
|
|
{
|
|
$char = $line[$i];
|
|
|
|
if ('\\' == $char)
|
|
{
|
|
$i++;
|
|
$char = $line[$i];
|
|
|
|
switch ($char)
|
|
{
|
|
case '"':
|
|
$buff .= '"';
|
|
break;
|
|
case '\'':
|
|
$buff .= '\'';
|
|
break;
|
|
case ',';
|
|
$buff .= ',';
|
|
break;
|
|
default:
|
|
$buff .= '\\' . $char;
|
|
break;
|
|
}
|
|
}
|
|
elseif ('"' == $char)
|
|
{
|
|
if (0 == $quote)
|
|
{
|
|
$quote++;
|
|
}
|
|
else
|
|
{
|
|
$quote = 0;
|
|
}
|
|
}
|
|
elseif (',' == $char)
|
|
{
|
|
if (0 == $quote)
|
|
{
|
|
if (!isset($field_list[count($arr)]))
|
|
{
|
|
continue;
|
|
}
|
|
$field_name = $field_list[count($arr)];
|
|
$arr[$field_name] = trim($buff);
|
|
$buff = '';
|
|
$quote = 0;
|
|
}
|
|
else
|
|
{
|
|
$buff .= $char;
|
|
}
|
|
}
|
|
else
|
|
{
|
|
$buff .= $char;
|
|
}
|
|
|
|
if ($i == $len - 1)
|
|
{
|
|
if (!isset($field_list[count($arr)]))
|
|
{
|
|
continue;
|
|
}
|
|
$field_name = $field_list[count($arr)];
|
|
$arr[$field_name] = trim($buff);
|
|
}
|
|
}
|
|
$goods_list[] = $arr;
|
|
}
|
|
|
|
$goods_list = get_produts_area_list($goods_list);
|
|
$return = get_insert_produts_area($goods_list);
|
|
|
|
if($return == 1){
|
|
$link[] = array('href' => 'goods_area_attr.php?act=product_list&area_id=' . $goods_list[0]['area_id'] . '&goods_id=' . $goods_list[0]['goods_id'], 'text' => $_LANG['18_product_list']);
|
|
sys_msg("仓库货号商品更新成功!", 0, $link);
|
|
}
|
|
|
|
$link[] = array('href' => 'goods.php?act=add', 'text' => $_LANG['02_goods_add']);
|
|
$link[] = array('href' => 'goods.php?act=list', 'text' => $_LANG['01_goods_list']);
|
|
$link[] = array('href' => 'goods_area_attr.php?act=product_list&area_id=' . $goods_list[0]['area_id'] . '&goods_id=' . $goods_list[0]['goods_id'], 'text' => $_LANG['18_product_list']);
|
|
sys_msg($_LANG['save_products'], 0, $link);
|
|
exit;
|
|
}
|
|
}
|
|
}
|
|
|
|
/*------------------------------------------------------ */
|
|
//-- 下载文件
|
|
/*------------------------------------------------------ */
|
|
|
|
elseif ($_REQUEST['act'] == 'download')
|
|
{
|
|
/* 检查权限 */
|
|
admin_priv('goods_manage');
|
|
|
|
$goods_id = isset($_REQUEST['goods_id']) ? intval($_REQUEST['goods_id']) : 0;
|
|
$warehouse_id = isset($_REQUEST['warehouse_id']) ? intval($_REQUEST['warehouse_id']) : 0;
|
|
$goods_attr = isset($_REQUEST['goods_attr']) ? explode(',', $_REQUEST['goods_attr']) : array();
|
|
|
|
// 文件标签
|
|
// Header("Content-type: application/octet-stream");
|
|
header("Content-type: application/vnd.ms-excel; charset=utf-8");
|
|
Header("Content-Disposition: attachment; filename=attr_info_list.csv");
|
|
|
|
// 下载
|
|
if ($_GET['charset'] != $_CFG['lang'])
|
|
{
|
|
$lang_file = '../languages/' . $_GET['charset'] . '/admin/goods_produts_area_batch.php';
|
|
if (file_exists($lang_file))
|
|
{
|
|
unset($_LANG['upload_product']);
|
|
require($lang_file);
|
|
}
|
|
}
|
|
if (isset($_LANG['upload_product']))
|
|
{
|
|
/* 创建字符集转换对象 */
|
|
if ($_GET['charset'] == 'zh_cn' || $_GET['charset'] == 'zh_tw')
|
|
{
|
|
$to_charset = $_GET['charset'] == 'zh_cn' ? 'GB2312' : 'BIG5';
|
|
$data = join(',', $_LANG['upload_product']) . "\t\n";
|
|
|
|
$goods_date = array('goods_name');
|
|
$where = "goods_id = '$goods_id'";
|
|
$goods_name = get_table_date('goods', $where, $goods_date,2);
|
|
|
|
$area_date = array('region_name');
|
|
|
|
$warehouse_where = '';
|
|
if($warehouse_id > 0){
|
|
$warehouse_where = " and region_id = " . $warehouse_id;
|
|
}
|
|
|
|
$where = "region_type = 1" . $warehouse_where;
|
|
$warehouse_info = get_table_date('region_warehouse', $where, $area_date,1);
|
|
|
|
$attr_info = get_list_download($goods_name, $warehouse_info);
|
|
|
|
for($i=0; $i<count($attr_info); $i++){
|
|
$data .= join(',', array($attr_info[$i]['goods_name'], $attr_info[$i]['region_name'], $attr_info[$i]['attr_value'], $attr_info[$i]['product_sn'], $attr_info[$i]['product_number'])) . "\t\n";
|
|
}
|
|
|
|
echo ecs_iconv(EC_CHARSET, $to_charset, $data);
|
|
}
|
|
else
|
|
{
|
|
echo join(',', $_LANG['upload_product']);
|
|
}
|
|
}
|
|
else
|
|
{
|
|
echo 'error: $_LANG[upload_product] not exists';
|
|
}
|
|
}
|
|
|
|
function get_list_download($goods_name = '', $warehouse_info = array()){
|
|
|
|
$goods_date = array('model_attr');
|
|
$where = "goods_name = '$goods_name' and is_delete = 0";
|
|
$model_attr = get_table_date('goods', $where, $goods_date,2);
|
|
|
|
$arr = array();
|
|
|
|
if(count($warehouse_info) > 0 && $model_attr == 2){
|
|
for($i=0; $i <count($warehouse_info); $i++){
|
|
$arr[$i]['goods_name'] = $goods_name;
|
|
$arr[$i]['region_name'] = $warehouse_info[$i]['region_name'];
|
|
$arr[$i]['attr_value'] = $warehouse_info[$i]['attr_value'];
|
|
$arr[$i]['product_sn'] = $warehouse_info[$i]['product_sn'];
|
|
$arr[$i]['product_number'] = $warehouse_info[$i]['product_number'];
|
|
}
|
|
}
|
|
|
|
return $arr;
|
|
}
|
|
|
|
//商品属性 start
|
|
function get_attribute_list($goods_id = 0){
|
|
$sql = "select a.attr_id, a.attr_name from " .$GLOBALS['ecs']->table('goods_attr'). " as ga " .
|
|
" left join " .$GLOBALS['ecs']->table('attribute'). " as a on ga.attr_id = a.attr_id" .
|
|
" where ga.goods_id = '$goods_id' group by ga.attr_id";
|
|
$res = $GLOBALS['db']->getAll($sql);
|
|
|
|
$arr = array();
|
|
foreach($res as $key=>$row){
|
|
$arr[$key]['attr_name']= $row['attr_name'];
|
|
$arr[$key]['goods_attr']= get_goods_attr_list($row['attr_id'], $goods_id);
|
|
}
|
|
|
|
return $arr;
|
|
}
|
|
|
|
function get_goods_attr_list($attr_id = 0, $goods_id = 0){
|
|
$sql = "select goods_attr_id, attr_value from " .$GLOBALS['ecs']->table('goods_attr'). " where goods_id = '$goods_id' and attr_id = '$attr_id' order by goods_attr_id asc";
|
|
$res = $GLOBALS['db']->getAll($sql);
|
|
|
|
$arr = array();
|
|
foreach($res as $key=>$row){
|
|
$arr[$key]['goods_attr_id']= $row['goods_attr_id'];
|
|
$arr[$key]['attr_value']= $row['attr_value'];
|
|
}
|
|
|
|
return $arr;
|
|
}
|
|
|
|
//商品属性 end
|
|
?>
|