ecshop為虛擬商品添加出售和未出售的導出xlc

WBOY
發布: 2016-08-08 09:27:03
原創
949 人瀏覽過

在admin/virtral_card.php檔案中找到$_REQUEST['act'] == 'card'
這裡是用來顯示某一個虛擬商品的出售記錄的清單將會傳送到replenish_list.htm
在replenish_list.htm 檔案中最定部分有個引入的檔案叫做pageheader.htm的檔案這裡是用來輸出預設模版裡的補「貨按」鈕
在virtral_card.php檔大約180行有

<span>$smarty</span>->assign('action_link',  <span>array</span>('text'    => <span>$_LANG</span>['replenish'],
                                            'href'  => 'virtual_card.php?act=replenish&goods_id='.<span>$_REQUEST</span>['goods_id']));
登入後複製

依照ecshop的習慣,需要修改語言包檔(語言包檔名和對應的這個php檔名相同,只是在語言包目錄下)

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

在大約180行那句話下面添加如下(主要是修改一下act後的參數,用於到文件中來處理數據)
比較重要的是forsale=has和forsale=not這兩個參數,將用來區別是要導出已經出售還是要導出未出售的

<span>$smarty</span>->assign('Notforsale',  <span>array</span>('text'    => <span>$_LANG</span>['Notforsale'],
                                            'href'  => 'virtual_card.php?act=forsale&forsale=not&goods_id='.<span>$_REQUEST</span>['goods_id'<span>]));
</span><span>$smarty</span>->assign('Hasforsale',  <span>array</span>('text'    => <span>$_LANG</span>['Hasforsale'],
                                            'href'  => 'virtual_card.php?act=forsale&forsale=has&goods_id='.<span>$_REQUEST</span>['goods_id']));
登入後複製

具體程式碼如下:

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

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

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

以上就介紹了ecshop為虛擬商品添加出售和未出售的導出xlc,包括了方面的內容,希望對PHP教程有興趣的朋友有所幫助。

相關標籤:
來源:php.cn
本網站聲明
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn
熱門教學
更多>
最新下載
更多>
網站特效
網站源碼
網站素材
前端模板