首頁 >後端開發 >php教程 >ecshop给虚拟商品平添出售和未出售的导出xlc

ecshop给虚拟商品平添出售和未出售的导出xlc

WBOY
WBOY原創
2016-06-13 12:17:05978瀏覽

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

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

<span style="color: #800080;">$smarty</span>->assign('action_link',  <span style="color: #0000ff;">array</span>('text'    => <span style="color: #800080;">$_LANG</span>['replenish'],                                            'href'  => 'virtual_card.php?act=replenish&goods_id='.<span style="color: #800080;">$_REQUEST</span>['goods_id']));

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

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

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

<span style="color: #800080;">$smarty</span>->assign('Notforsale',  <span style="color: #0000ff;">array</span>('text'    => <span style="color: #800080;">$_LANG</span>['Notforsale'],                                            'href'  => 'virtual_card.php?act=forsale&forsale=not&goods_id='.<span style="color: #800080;">$_REQUEST</span>['goods_id'<span style="color: #000000;">]));</span><span style="color: #800080;">$smarty</span>->assign('Hasforsale',  <span style="color: #0000ff;">array</span>('text'    => <span style="color: #800080;">$_LANG</span>['Hasforsale'],                                            'href'  => 'virtual_card.php?act=forsale&forsale=has&goods_id='.<span style="color: #800080;">$_REQUEST</span>['goods_id']));

具体代码如下:

<span style="color: #008000;">/*</span><span style="color: #008000;">------------------------------------------------------ </span><span style="color: #008000;">*/</span><span style="color: #008000;">//</span><span style="color: #008000;">-- 导出未出售或已出售的虚拟商品到xls</span><span style="color: #008000;">/*</span><span style="color: #008000;">------------------------------------------------------ </span><span style="color: #008000;">*/</span><span style="color: #0000ff;">elseif</span> (<span style="color: #800080;">$_REQUEST</span>['act'] == 'forsale'<span style="color: #000000;">){    </span><span style="color: #800080;">$forsale</span> = <span style="color: #0000ff;">empty</span>(<span style="color: #800080;">$_REQUEST</span>['forsale']) ? "" : <span style="color: #008080;">trim</span>(<span style="color: #800080;">$_REQUEST</span>['forsale'<span style="color: #000000;">]);    </span><span style="color: #008000;">//</span><span style="color: #008000;">首先判断$forsale是否有值被传入</span>       <span style="color: #0000ff;">if</span>(<span style="color: #800080;">$forsale</span> != ""<span style="color: #000000;">){        </span><span style="color: #800080;">$fielname</span> = ""<span style="color: #000000;">;        </span><span style="color: #800080;">$goods_id</span> = <span style="color: #0000ff;">empty</span>(<span style="color: #800080;">$_REQUEST</span>['goods_id']) ? 0 : <span style="color: #008080;">intval</span>(<span style="color: #800080;">$_REQUEST</span>['goods_id'<span style="color: #000000;">]);        </span><span style="color: #008000;">//</span><span style="color: #008000;">has为已出售,not为未出售</span>        <span style="color: #0000ff;">if</span>(<span style="color: #800080;">$forsale</span> == 'has'<span style="color: #000000;">){            </span><span style="color: #800080;">$fielname</span> = "已出售商品"<span style="color: #000000;">;            </span><span style="color: #800080;">$getCurrentGoodsListsql</span> = "SELECT card_id, goods_id, card_sn, card_password, end_date, is_saled, order_sn, crc32 FROM " . <span style="color: #800080;">$GLOBALS</span>['ecs']->table('virtual_card') . " WHERE goods_id = " . <span style="color: #800080;">$goods_id</span> . " and is_saled = 1"<span style="color: #000000;"> ;        }        </span><span style="color: #0000ff;">else</span> <span style="color: #0000ff;">if</span>(<span style="color: #800080;">$forsale</span> == 'not'<span style="color: #000000;">){            </span><span style="color: #800080;">$fielname</span> = "未出售商品"<span style="color: #000000;">;            </span><span style="color: #800080;">$getCurrentGoodsListsql</span> = "SELECT card_id, goods_id, card_sn, card_password, end_date, is_saled, order_sn, crc32 FROM " . <span style="color: #800080;">$GLOBALS</span>['ecs']->table('virtual_card') . " WHERE goods_id = " . <span style="color: #800080;">$goods_id</span> . " and is_saled = 0"<span style="color: #000000;"> ;        }        </span><span style="color: #800080;">$currentGoodsList</span> = <span style="color: #800080;">$GLOBALS</span>['db']->getAll(<span style="color: #800080;">$getCurrentGoodsListsql</span><span style="color: #000000;">);        </span><span style="color: #800080;">$arr</span> = <span style="color: #0000ff;">array</span><span style="color: #000000;">();        </span><span style="color: #0000ff;">foreach</span> (<span style="color: #800080;">$currentGoodsList</span> <span style="color: #0000ff;">AS</span> <span style="color: #800080;">$key</span> => <span style="color: #800080;">$row</span><span style="color: #000000;">)        {            </span><span style="color: #0000ff;">if</span> (<span style="color: #800080;">$row</span>['crc32'] == 0 || <span style="color: #800080;">$row</span>['crc32'] == <span style="color: #008080;">crc32</span><span style="color: #000000;">(AUTH_KEY))            {                </span><span style="color: #800080;">$row</span>['card_sn']       = decrypt(<span style="color: #800080;">$row</span>['card_sn'<span style="color: #000000;">]);                </span><span style="color: #800080;">$row</span>['card_password'] = decrypt(<span style="color: #800080;">$row</span>['card_password'<span style="color: #000000;">]);            }            </span><span style="color: #0000ff;">elseif</span> (<span style="color: #800080;">$row</span>['crc32'] == <span style="color: #008080;">crc32</span><span style="color: #000000;">(OLD_AUTH_KEY))            {                </span><span style="color: #800080;">$row</span>['card_sn']       = decrypt(<span style="color: #800080;">$row</span>['card_sn'],<span style="color: #000000;"> OLD_AUTH_KEY);                </span><span style="color: #800080;">$row</span>['card_password'] = decrypt(<span style="color: #800080;">$row</span>['card_password'],<span style="color: #000000;"> OLD_AUTH_KEY);            }            </span><span style="color: #0000ff;">else</span><span style="color: #000000;">            {                </span><span style="color: #800080;">$row</span>['card_sn']       = '***'<span style="color: #000000;">;                </span><span style="color: #800080;">$row</span>['card_password'] = '***'<span style="color: #000000;">;            }            </span><span style="color: #800080;">$row</span>['end_date'] = <span style="color: #800080;">$row</span>['end_date'] == 0 ? '' : <span style="color: #008080;">date</span>(<span style="color: #800080;">$GLOBALS</span>['_CFG']['date_format'], <span style="color: #800080;">$row</span>['end_date'<span style="color: #000000;">]);            </span><span style="color: #800080;">$arr</span>[] = <span style="color: #800080;">$row</span><span style="color: #000000;">;        }        </span><span style="color: #008080;">header</span>("Content-Type: application/vnd.ms-execl"); <span style="color: #008000;">//</span><span style="color: #008000;">定义文件的内容类型</span>        <span style="color: #008080;">header</span>("Content-Disposition: attachment; filename={<span style="color: #800080;">$fielname</span>}.xls"<span style="color: #000000;">);         </span><span style="color: #008080;">header</span>("Pragma: no-cache");  <span style="color: #008000;">//</span><span style="color: #008000;">不缓存</span>        <span style="color: #008080;">header</span>("Expires: 0");<span style="color: #008000;">//</span><span style="color: #008000;">将内容输出到第一个工作簿</span>        <span style="color: #800080;">$data</span> = "数据库编号\t商品编号\t卡片序号\t卡片密码\t截止使用日期\t是否已经出售(1:已经出售0:未出售)\t订单号\t加密编码(客户无用,可删除)\t\n"<span style="color: #000000;">;        </span><span style="color: #0000ff;">foreach</span>(<span style="color: #800080;">$arr</span> <span style="color: #0000ff;">as</span> <span style="color: #800080;">$key</span>=><span style="color: #800080;">$val</span><span style="color: #000000;">){            </span><span style="color: #0000ff;">foreach</span> (<span style="color: #800080;">$val</span> <span style="color: #0000ff;">as</span> <span style="color: #800080;">$k</span> => <span style="color: #800080;">$v</span><span style="color: #000000;">) {                </span><span style="color: #800080;">$data</span> .= <span style="color: #800080;">$v</span> . "\t"<span style="color: #000000;">;            }            </span><span style="color: #800080;">$data</span> .= "\n"<span style="color: #000000;">;        }        </span><span style="color: #0000ff;">echo</span> <span style="color: #008080;">iconv</span>("UTF-8","GB2312//IGNORE",<span style="color: #800080;">$data</span><span style="color: #000000;">);        </span><span style="color: #008000;">//</span><span style="color: #008000;">echo "<pre class="brush:php;toolbar:false">";var_dump($data);echo "
";exit(); } }

 

陳述:
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn