西部数码主机 | 阿里云主机| 虚拟主机 | 服务器 | 返回乐道官网
当前位置: 主页 > php教程 > ecshop教程 >

给ecshop虚拟商品添加出售和未出售的导出xls

时间:2015-04-02 02:31来源:未知 作者:好模板 点击:
在ecshop的后台文件admin/virtral_card.php文件中找到$_REQUEST[act] == card 这里是用来显示某一个虚拟商品的出售记录的列表将会发送到replenish_list.htm 在replenish_list.htm 文件中最定部分有个引入的

在ecshop的后台文件admin/virtral_card.php文件中找到$_REQUEST['act'] == 'card'
这里是用来显示某一个虚拟商品的出售记录的列表将会发送到replenish_list.htm
在replenish_list.htm 文件中最定部分有个引入的文件叫pageheader.htm的文件这里是用于输出默认模版里的补“货按”钮
在virtral_card.php文件大约180行有

$smarty->assign('action_link',  array('text'    => $_LANG['replenish'],
                                            'href'  => 'virtual_card.php?act=replenish&goods_id='.$_REQUEST['goods_id']));

按照ecshop的习惯,需要修改语言包文件(语言包文件名和对应的这个php文件名相同,只是在语言包目录下)

$_LANG['Notforsale'] = '未出售导出xls';
$_LANG['Hasforsale'] = '已出售导出xls';

在大约180行那句话下面添加如下(主要是修改一下act后的参数,用于到文件中来处理数据)
比较重要的是forsale=has和forsale=not这两个参数,将用来区别是要导出已经出售还是要导出未出售的

$smarty->assign('Notforsale',  array('text'    => $_LANG['Notforsale'],
                                            'href'  => 'virtual_card.php?act=forsale&forsale=not&goods_id='.$_REQUEST['goods_id']));
$smarty->assign('Hasforsale',  array('text'    => $_LANG['Hasforsale'],
                                            'href'  => 'virtual_card.php?act=forsale&forsale=has&goods_id='.$_REQUEST['goods_id']));

具体代码如下:

/*------------------------------------------------------ */
//-- 导出未出售或已出售的虚拟商品到xls
/*------------------------------------------------------ */
elseif ($_REQUEST['act'] == 'forsale')
{
    $forsale = empty($_REQUEST['forsale']) ? "" : trim($_REQUEST['forsale']);
    //首先判断$forsale是否有值被传入
   
    if($forsale != ""){
        $fielname = "";
        $goods_id = empty($_REQUEST['goods_id']) ? 0 : intval($_REQUEST['goods_id']);
        //has为已出售,not为未出售
        if($forsale == 'has'){
            $fielname = "已出售商品";
            $getCurrentGoodsListsql = "SELECT card_id, goods_id, card_sn, card_password, end_date, is_saled, order_sn, crc32 FROM " . $GLOBALS['ecs']->table('virtual_card') . " WHERE goods_id = " . $goods_id . " and is_saled = 1" ;
        }
        else if($forsale == 'not'){
            $fielname = "未出售商品";
            $getCurrentGoodsListsql = "SELECT card_id, goods_id, card_sn, card_password, end_date, is_saled, order_sn, crc32 FROM " . $GLOBALS['ecs']->table('virtual_card') . " WHERE goods_id = " . $goods_id . " and is_saled = 0" ;
        }
        $currentGoodsList = $GLOBALS['db']->getAll($getCurrentGoodsListsql);
        $arr = array();
        foreach ($currentGoodsList AS $key => $row) //ldhost.cn
        {
            if ($row['crc32'] == 0 || $row['crc32'] == crc32(AUTH_KEY))
            {
                $row['card_sn']       = decrypt($row['card_sn']);
                $row['card_password'] = decrypt($row['card_password']);
            }
            elseif ($row['crc32'] == crc32(OLD_AUTH_KEY))
            {
                $row['card_sn']       = decrypt($row['card_sn'], OLD_AUTH_KEY);
                $row['card_password'] = decrypt($row['card_password'], OLD_AUTH_KEY);
            }
            else
            {
                $row['card_sn']       = '***';
                $row['card_password'] = '***';
            }

            $row['end_date'] = $row['end_date'] == 0 ? '' : date($GLOBALS['_CFG']['date_format'], $row['end_date']);

            $arr[] = $row;
        }
        header("Content-Type: application/vnd.ms-execl"); //定义文件的内容类型
        header("Content-Disposition: attachment; filename={$fielname}.xls"); 
        header("Pragma: no-cache");  //不缓存
        header("Expires: 0");//将内容输出到第一个工作簿
        $data = "数据库编号\t商品编号\t卡片序号\t卡片密码\t截止使用日期\t是否已经出售(1:已经出售0:未出售)\t订单号\t加密编码(客户无用,可删除)\t\n";
        foreach($arr as $key=>$val){
            foreach ($val as $k => $v) {
                $data .= $v . "\t";
            }
            $data .= "\n";
        }
        echo iconv("UTF-8","GB2312//IGNORE",$data);
        //echo "<pre>";var_dump($data);echo "</pre>";exit();
   
    }
   
}
        

(责任编辑:好模板)
顶一下
(0)
0%
踩一下
(0)
0%
------分隔线----------------------------