ecshop二次开发--节日关怀

案例效果:(即在指定的节假日的时候会有指定的活动)

ecshop二次开发--节日关怀_第1张图片






案例实现:

1.先找到 ecshop/languages/zh_cn/admin/common.php文件,

然后在文件中加入代码:

$_LANG['17_business_manage'] = '商务管理';
$_LANG['04_festival_list'] = '节日列表';
$_LANG['05_festival_add'] = '添加节日';




2.再找到 ecshop/admin/includes/inc_menu.php文件,

在文件中的最后一行加入代码:

//商务管理
$modules['17_business_manage']['04_festival_list']        = 'festival_list.php?act=list';
$modules['17_business_manage']['05_festival_add']        = 'festival_list.php?act=insert';





3.在ecshop数据库中添加节日表ecs_festival

(其中act_id是优惠活动表ecs_favourable_activity中的 act_id)

ecshop二次开发--节日关怀_第2张图片







4.在 ecshop/admin/ 下建立festival_list.php

<?php

/**
 * ECSHOP 邮件列表管理
 * ===========================================================
 * * 版权所有 2005-2012 上海商派网络科技有限公司,并保留所有权利。
 * 网站地址: http://www.ecshop.com;
 * ----------------------------------------------------------
 * 这不是一个自由软件!您只能在不用于商业目的的前提下对程序代码进行修改和
 * 使用;不允许对程序代码以任何形式任何目的的再发布。
 * ==========================================================
 * $Author: liubo $
 * $Id: email_list.php 17217 2011-01-19 06:29:08Z liubo $
 */
define('IN_ECS', true);
require(dirname(__FILE__) . '/includes/init.php');
admin_priv('email_list');

if ($_REQUEST['act'] == 'list')
{
    $emaildb = get_email_list();
    $smarty->assign('full_page',    1);
    $smarty->assign('ur_here', $_LANG['email_list']);
    $smarty->assign('emaildb',      $emaildb['emaildb']);
    $smarty->assign('filter',       $emaildb['filter']);
    $smarty->assign('record_count', $emaildb['record_count']);
    $smarty->assign('page_count',   $emaildb['page_count']);
    assign_query_info();
    $sql = "select * from ". $ecs->table('festival') ." as a left join ". $ecs->table('favourable_activity') ." as b on a.act_id=b.act_id";
    $fes = $db->getAll($sql);
    $smarty->assign('festival_add', "添加节日");
    $smarty->assign('fes_id', "编号");
    $smarty->assign('fes_name', "节日名称");
    $smarty->assign('fes_date', "节日时间");
    $smarty->assign('fes_addtime', "节日添加时间");
    $smarty->assign('act_name', "活动名称");
    $smarty->assign('fes', $fes);
    $smarty->display('festival_list.htm');
    //$smarty->display('email_list.htm');
}elseif($_REQUEST['act'] == 'insert')
{
    $smarty->assign('fes_name', "节日名称");
    $smarty->assign('fes_date', "节日时间");
    $smarty->assign('act_name', "活动名称");
    $sql = "select act_id,act_name from ". $ecs->table('favourable_activity');
    $act = $db->getAll($sql);
    $smarty->assign('act', $act);
    $smarty->display('festival_add.htm');
}
elseif($_REQUEST['act'] == 'form_pro')
{
    $fes_name = $_POST['fes_name'];
    $fes_date = $_POST['fes_date'];
    $act_id = $_POST['act_id'];
    $fes_addtime = date("Y-m-d H:i:s");
    $sql = "insert into ". $ecs->table('festival') ." values(null,'$fes_name','$fes_date','$fes_addtime','$act_id')";
    $res = $db->query($sql);
    if($res){
        /**
         * start
         */
        $emaildb = get_email_list();
        $smarty->assign('full_page',    1);
        $smarty->assign('ur_here', $_LANG['email_list']);
        $smarty->assign('emaildb',      $emaildb['emaildb']);
        $smarty->assign('filter',       $emaildb['filter']);
        $smarty->assign('record_count', $emaildb['record_count']);
        $smarty->assign('page_count',   $emaildb['page_count']);
        assign_query_info();
        /**
         * end
         */
        $sql = "select * from ". $ecs->table('festival') ." as a left join ". $ecs->table('favourable_activity') ." as b on a.act_id=b.act_id";
        $fes = $db->getAll($sql);
        $smarty->assign('festival_add', "添加节日");
        $smarty->assign('fes_id', "编号");
        $smarty->assign('fes_name', "节日名称");
        $smarty->assign('fes_date', "节日时间");
        $smarty->assign('fes_addtime', "节日添加时间");
        $smarty->assign('act_name', "活动名称");
        $smarty->assign('fes', $fes);
        $smarty->display("festival_list.htm");
    }else{
        $smarty->display("festival_add.htm");
    }
}


elseif ($_REQUEST['act'] == 'export')
{
    $sql = "SELECT email FROM " . $ecs->table('email_list') . "WHERE stat = 1";
    $emails = $db->getAll($sql);
    $out = '';
    foreach ($emails as $key => $val)
    {
        $out .= "$val[email]\n";
    }
    $contentType = 'text/plain';
    $len = strlen($out);
    header('Last-Modified: ' . gmdate('D, d M Y H:i:s',time()+31536000) .' GMT');
    header('Pragma: no-cache');
    header('Content-Encoding: none');
    header('Content-type: ' . $contentType);
    header('Content-Length: ' . $len);
    header('Content-Disposition: attachment; filename="email_list.txt"');
    echo $out;
    exit;
}
elseif ($_REQUEST['act'] == 'query')
{
    $emaildb = get_email_list();
    $smarty->assign('emaildb',      $emaildb['emaildb']);
    $smarty->assign('filter',       $emaildb['filter']);
    $smarty->assign('record_count', $emaildb['record_count']);
    $smarty->assign('page_count',   $emaildb['page_count']);

    $sort_flag  = sort_flag($emaildb['filter']);
    $smarty->assign($sort_flag['tag'], $sort_flag['img']);

    make_json_result($smarty->fetch('email_list.htm'), '',
        array('filter' => $emaildb['filter'], 'page_count' => $emaildb['page_count']));
}

/*------------------------------------------------------ */
//-- 批量删除
/*------------------------------------------------------ */
elseif ($_REQUEST['act'] == 'batch_remove')
{
    if (!isset($_POST['checkboxes']) || !is_array($_POST['checkboxes']))
    {
        sys_msg($_LANG['no_select_email'], 1);
    }

    $sql = "DELETE FROM " . $ecs->table('email_list') .
            " WHERE id " . db_create_in(join(',', $_POST['checkboxes']));
    $db->query($sql);

    $lnk[] = array('text' => $_LANG['back_list'], 'href' => 'email_list.php?act=list');
    sys_msg(sprintf($_LANG['batch_remove_succeed'], $db->affected_rows()), 0, $lnk);
}

/*------------------------------------------------------ */
//-- 批量恢复
/*------------------------------------------------------ */
elseif ($_REQUEST['act'] == 'batch_unremove')
{
    if (!isset($_POST['checkboxes']) || !is_array($_POST['checkboxes']))
    {
        sys_msg($_LANG['no_select_email'], 1);
    }

    $sql = "UPDATE " . $ecs->table('email_list') .
            " SET stat = 1 WHERE stat <> 1 AND id " . db_create_in(join(',', $_POST['checkboxes']));
    $db->query($sql);

    $lnk[] = array('text' => $_LANG['back_list'], 'href' => 'email_list.php?act=list');
    sys_msg(sprintf($_LANG['batch_unremove_succeed'], $db->affected_rows()), 0, $lnk);
}

/*------------------------------------------------------ */
//-- 批量退订
/*------------------------------------------------------ */
elseif ($_REQUEST['act'] == 'batch_exit')
{
    if (!isset($_POST['checkboxes']) || !is_array($_POST['checkboxes']))
    {
        sys_msg($_LANG['no_select_email'], 1);
    }

    $sql = "UPDATE " . $ecs->table('email_list') .
            " SET stat = 2 WHERE stat <> 2 AND id " . db_create_in(join(',', $_POST['checkboxes']));
    $db->query($sql);

    $lnk[] = array('text' => $_LANG['back_list'], 'href' => 'email_list.php?act=list');
    sys_msg(sprintf($_LANG['batch_exit_succeed'], $db->affected_rows()), 0, $lnk);
}

function get_email_list()
{
    $result = get_filter();
    if ($result === false)
    {
        $filter['sort_by']      = empty($_REQUEST['sort_by']) ? 'stat' : trim($_REQUEST['sort_by']);
        $filter['sort_order']   = empty($_REQUEST['sort_order']) ? 'ASC' : trim($_REQUEST['sort_order']);

        $sql = "SELECT COUNT(*) FROM " . $GLOBALS['ecs']->table('email_list');
        $filter['record_count'] = $GLOBALS['db']->getOne($sql);

        /* 分页大小 */
        $filter = page_and_size($filter);

        /* 查询 */

        $sql = "SELECT * FROM " . $GLOBALS['ecs']->table('email_list') .
            " ORDER BY " . $filter['sort_by'] . ' ' . $filter['sort_order'] .
            " LIMIT " . $filter['start'] . ",$filter[page_size]";

        set_filter($filter, $sql);
    }
    else
    {
        $sql    = $result['sql'];
        $filter = $result['filter'];
    }

    $emaildb = $GLOBALS['db']->getAll($sql);

    $arr = array('emaildb' => $emaildb, 'filter' => $filter, 'page_count' => $filter['page_count'], 'record_count' => $filter['record_count']);

    return $arr;


}
?>

7、在ecshop/admin/templates中将user_info.htm文件复制并重命名为festival_add.htm。

<form method="post" action="festival_list.php?act=form_pro" name="theForm" onsubmit="return validate()">
    <table width="100%">
        <tr>
            <td class="label" align="center">{$fes_name}:</td>
            <td><input type="text" name="fes_name" maxlength="60" /></td>
        </tr>
        <tr>
            <td class="label" align="center">{$fes_date}:</td>
            <td><input type="text" name="fes_date" maxlength="60" /></td>
        </tr>
        <tr>
            <td class="label" align="center">{$act_name}:</td>
            <td>
                <select name="act_id">
                    <option value="">======请选择======</option>
                    {foreach from=$act item=val}
                    <option value="{$val.act_id}">{$val.act_name}</option>
                    {/foreach}
                </select>
            </td>
        </tr>
        <tr>
            <td colspan="2" align="center">
                <input type="submit" value="{$lang.button_submit}" class="button" />
                <input type="reset" value="{$lang.button_reset}" class="button" />
            </td>
        </tr>
    </table>
</form>


前台展示

找到前台文件ecshop/index.php

ecshop二次开发--节日关怀_第3张图片






//节日列表
$date=date("m-d",time());
//var_dump($date);die;
$sql = "select * from ". $ecs->table('festival') ." as a left join ". $ecs->table('favourable_activity') ." as b on a.act_id=b.act_id where fes_date = '$date' order by fes_addtime desc limit 5";
$fes = $db->getAll($sql);
$smarty->assign('fes', $fes);


再找到upload\themes\default中的前台模板index.dwt

ecshop二次开发--节日关怀_第4张图片












<style type="text/css">

  #fes_div{padding-left:20px; padding-top:10px; padding-bottom:10px; border-bottom:1px solid gray;}

  #fes_a{text-decoration:none; color:green; font-size:16px; font-family:'楷体';}

  #fes_a:hover{color:red; font-weight:bold; text-decoration:underline;}

  #fes_span{margin-right:10px; color:gray; float:right;}

</style>

 

<div class="box">

<div class="box_1">

<h3><span>节日列表</span></h3>

<div class="boxCenterList RelaArticle">

    {foreach from=$fes item=val}

<div id="fes_div"><a href="javascript:;" id="fes_a">  {$val.fes_name}</a><span id="fes_span">{$val.fes_date}</span></div>

    {/foreach}

</div>

</div>

</div>






你可能感兴趣的:(ecshop二次开发--节日关怀)