码迷,mamicode.com
首页 > 其他好文 > 详细

echop二次开发——电子票

时间:2016-05-18 18:08:01      阅读:311      评论:0      收藏:0      [点我收藏+]

标签:

 先展示下效果:

技术分享技术分享

后台实现过程

一、             添加菜单项:路径admin\includes\inc_menu.php

$modules[‘18_ticket_manage‘][‘01_ticket_list‘]  = ‘ticket.php?act=list‘;

$modules[‘18_ticket_manage‘][‘02_ticket_add‘]  = ‘ticket.php?act=add‘; 

配置菜单语言

打开 /languages/zh_cn/admin/common.php文件,添加语言

//菜单—添加

$_LANG[‘18_ticket_manage‘] = ‘电子票管理‘;

//电子票管理

$_LANG[‘01_ticket_list‘] = ‘电子票列表‘;

$_LANG[‘02_ticket_add‘] = ‘添加电子票‘;

二、上传图片路径:在upload\data\创建ticket_pic文件夹,图片上传路径

三:数据库:

ecs_ticket

技术分享

ecs_ticket_cart

技术分享

、添加电子票(upload\admin\templates\ticket_add.htm)

1、创建添加电子票模板ticket_add.htm(自己按照ticket表更改布局);
(复制品牌模板upload\admin\templates\brand_info.htm);

ticket_add.htm代码如下

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title>SHOP 管理中心 - 品牌管理 </title>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <link href="styles/general.css" rel="stylesheet" type="text/css" />
    <link href="styles/main.css" rel="stylesheet" type="text/css" />

    <script type="text/javascript" src="../js/calendar.php?lang={$cfg_lang}"></script>
    <link href="../js/calendar/calendar.css" rel="stylesheet" type="text/css" />

</head>
<body>

<h1>
    <span class="action-span"><a href="ticket.php?act=list">电子票列表</a></span>
    <span class="action-span1"><a href="index.php?act=main">SHOP 管理中心</a> </span><span id="search_id" class="action-span1"> - 添加电子票 </span>
    <div style="clear:both"></div>
</h1>

<div class="main-div">
    <form method="post" action="ticket.php" name="theForm" enctype="multipart/form-data" onsubmit="return validate()">
        <table cellspacing="1" cellpadding="3" width="100%">
            <tbody><tr>
                <td class="label">电影名称</td>
                <td><input type="text" name="film_name" maxlength="60" value=""><span class="require-field">*</span></td>
            </tr>
            <tr>
                <td class="label"><a href="javascript:showNotice('warn_brandlogo');" title="点击此处查看提示信息">
                    <img src="images/notice.gif" width="16" height="16" border="0" alt="点击此处查看提示信息"></a>电影海报</td>
                <td><input type="file" name="film_pic" id="logo" size="45">    <br><span class="notice-span" style="display:block" id="warn_brandlogo">
        请上传图片,做为影片宣传海报!        </span>
                </td>
            </tr>
            <tr>
                <td class="label">开场时间</td>
                <td><input name="start_time" type="text" id="start_time" value="{$auction.start_time}" readonly="readonly" />
                    <input name="selbtn1" type="button" id="selbtn1" onclick="return showCalendar('start_time', '%Y-%m-%d %H:%M', '24', false, 'selbtn1');" value="{$lang.btn_select}" class="button" />
                </td>
            </tr>
            <tr>
                <td class="label">禁止入场时间</td>
                <td><input name="end_time" type="text" id="end_time" value="{$auction.end_time}" readonly="readonly" />
                    <input name="selbtn2" type="button" id="selbtn2" onclick="return showCalendar('end_time', '%Y-%m-%d %H:%M', '24', false, 'selbtn2');" value="{$lang.btn_select}" class="button" />
                </td>
            </tr>
            <tr>
                <td class="label">座位数量</td>
                <td><input type="text" name="ticket_num" maxlength="40" size="15" value="50"></td>
            </tr>
            <tr>
                <td class="label">票价</td>
                <td><input type="text" name="ticket_price" maxlength="40" size="15" value="50"></td>
            </tr>
            <tr>
                <td class="label">影片描述</td>
                <td><textarea name="film_desc" cols="60" rows="4"></textarea></td>
            </tr>
            <tr>
                <td colspan="2" align="center"><br>
                    <input type="submit" class="button" value=" 确定 ">
                    <input type="reset" class="button" value=" 重置 ">
                    <input type="hidden" name="act" value="{$form_action}">
                </td>
            </tr>
            </tbody></table>
    </form>
</div>

</body>
</html>
四、创建upload\admin\ticket.php (复制品牌控制器upload\admin\brand.php)

ticket.php      代码如下:

<?php

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

define('IN_ECS', true);

require(dirname(__FILE__) . '/includes/init.php');
include_once(ROOT_PATH . 'includes/cls_image.php');
$image = new cls_image($_CFG['bgcolor']);
$exc = new exchange($ecs->table("ticket"), $db, 'ticket_id', 'file_name');

/*------------------------------------------------------ */
//-- 电子票列表
/*------------------------------------------------------ */
if ($_REQUEST['act'] == 'list')
{
    $smarty->assign('ur_here',      '电子票列表');
    $smarty->assign('action_link',  array('text' =>$_LANG['02_ticket_add'] , 'href' => 'ticket.php?act=add'));
    $smarty->assign('full_page',    1);

   //查询电子票信息(改动的部分)
    $sql = "select * from ". $GLOBALS['ecs']->table('ticket');
    $res = $GLOBALS['db']->query($sql); //$res资源类型
    $list = array();
    while($row = $GLOBALS['db']->fetchRow($res))
    {

        $row['run_time'] = local_date('Y-m-d H:i',$row['run_time']);
        $row['ban_time'] = local_date('Y-m-d H:i',$row['ban_time']);

        $list[] = $row;
    }
    $smarty->assign('ticket_list',$list);
    assign_query_info();
    $smarty->display('ticket_list.htm');
}

/*------------------------------------------------------ */
//-- 添加电子票
/*------------------------------------------------------ */
elseif ($_REQUEST['act'] == 'add')
{
    /* 权限判断 */
    admin_priv('goods_manage');
    $smarty->assign('ur_here',    '电子票添加');
    $smarty->assign('action_link', array('text' => $_LANG['01_ticket_list'], 'href' => 'ticket.php?act=list'));
    $smarty->assign('form_action', 'insert');
    $smarty->display('ticket_add.htm');
}
elseif ($_REQUEST['act'] == 'insert')
{
    /*检查电影名称是否重复*/
    admin_priv('ticket_manage');
    $is_only = $exc->is_only('film_name', $_POST['film_name']);
    if (!$is_only)
    {
        sys_msg(sprintf('已存在', stripslashes($_POST['film_name'])), 1);
    }
    //时间处理
    $run_time = local_strtotime($_POST['start_time']);
    $ban_time = local_strtotime($_POST['end_time']);
    /*处理图片*/
    $img_name = basename($image->upload_image($_FILES['film_pic'],'ticket_pic'));

    /*插入数据*/
    $sql = "INSERT INTO ".$ecs->table('ticket')."(film_name, film_pic, run_time, ban_time,ticket_num,ticket_price,film_desc) ".
        "VALUES ('$_POST[film_name]', '$img_name', '$run_time', '$ban_time', '$_POST[ticket_num]', '$_POST[ticket_price]', '$_POST[film_desc]')";
    $db->query($sql);

    admin_log($_POST['film_name'],'add','ticket');

    /* 清除缓存 */
    clear_cache_files();

    $link[0]['text'] ='继续添加';
    $link[0]['href'] = 'ticket.php?act=add';

    $link[1]['text'] = '返回列表';
    $link[1]['href'] = 'ticket.php?act=list';

    sys_msg('添加成功', 0, $link);
}

/*------------------------------------------------------ */
//-- 编辑品牌
/*------------------------------------------------------ */
elseif ($_REQUEST['act'] == 'edit')
{
    /* 权限判断 */
    admin_priv('brand_manage');
    $sql = "SELECT brand_id, brand_name, site_url, brand_logo, brand_desc, brand_logo, is_show, sort_order ".
        "FROM " .$ecs->table('brand'). " WHERE brand_id='$_REQUEST[id]'";
    $brand = $db->GetRow($sql);

    $smarty->assign('ur_here',     $_LANG['brand_edit']);
    $smarty->assign('action_link', array('text' => $_LANG['06_goods_brand_list'], 'href' => 'brand.php?act=list&' . list_link_postfix()));
    $smarty->assign('brand',       $brand);
    $smarty->assign('form_action', 'updata');

    assign_query_info();
    $smarty->display('brand_info.htm');
}
elseif ($_REQUEST['act'] == 'updata')
{
    admin_priv('brand_manage');
    if ($_POST['brand_name'] != $_POST['old_brandname'])
    {
        /*检查品牌名是否相同*/
        $is_only = $exc->is_only('brand_name', $_POST['brand_name'], $_POST['id']);

        if (!$is_only)
        {
            sys_msg(sprintf($_LANG['brandname_exist'], stripslashes($_POST['brand_name'])), 1);
        }
    }

    /*对描述处理*/
    if (!empty($_POST['brand_desc']))
    {
        $_POST['brand_desc'] = $_POST['brand_desc'];
    }

    $is_show = isset($_REQUEST['is_show']) ? intval($_REQUEST['is_show']) : 0;
    /*处理URL*/
    $site_url = sanitize_url( $_POST['site_url'] );

    /* 处理图片 */
    $img_name = basename($image->upload_image($_FILES['brand_logo'],'brandlogo'));
    $param = "brand_name = '$_POST[brand_name]',  site_url='$site_url', brand_desc='$_POST[brand_desc]', is_show='$is_show', sort_order='$_POST[sort_order]' ";
    if (!empty($img_name))
    {
        //有图片上传
        $param .= " ,brand_logo = '$img_name' ";
    }

    if ($exc->edit($param,  $_POST['id']))
    {
        /* 清除缓存 */
        clear_cache_files();

        admin_log($_POST['brand_name'], 'edit', 'brand');

        $link[0]['text'] = $_LANG['back_list'];
        $link[0]['href'] = 'brand.php?act=list&' . list_link_postfix();
        $note = vsprintf($_LANG['brandedit_succed'], $_POST['brand_name']);
        sys_msg($note, 0, $link);
    }
    else
    {
        die($db->error());
    }
}

/*------------------------------------------------------ */
//-- 编辑品牌名称
/*------------------------------------------------------ */
elseif ($_REQUEST['act'] == 'edit_brand_name')
{
    check_authz_json('brand_manage');

    $id     = intval($_POST['id']);
    $name   = json_str_iconv(trim($_POST['val']));

    /* 检查名称是否重复 */
    if ($exc->num("brand_name",$name, $id) != 0)
    {
        make_json_error(sprintf($_LANG['brandname_exist'], $name));
    }
    else
    {
        if ($exc->edit("brand_name = '$name'", $id))
        {
            admin_log($name,'edit','brand');
            make_json_result(stripslashes($name));
        }
        else
        {
            make_json_result(sprintf($_LANG['brandedit_fail'], $name));
        }
    }
}

elseif($_REQUEST['act'] == 'add_brand')
{
    $brand = empty($_REQUEST['brand']) ? '' : json_str_iconv(trim($_REQUEST['brand']));

    if(brand_exists($brand))
    {
        make_json_error($_LANG['brand_name_exist']);
    }
    else
    {
        $sql = "INSERT INTO " . $ecs->table('brand') . "(brand_name)" .
            "VALUES ( '$brand')";

        $db->query($sql);
        $brand_id = $db->insert_id();

        $arr = array("id"=>$brand_id, "brand"=>$brand);

        make_json_result($arr);
    }
}
/*------------------------------------------------------ */
//-- 编辑排序序号
/*------------------------------------------------------ */
elseif ($_REQUEST['act'] == 'edit_sort_order')
{
    check_authz_json('brand_manage');

    $id     = intval($_POST['id']);
    $order  = intval($_POST['val']);
    $name   = $exc->get_name($id);

    if ($exc->edit("sort_order = '$order'", $id))
    {
        admin_log(addslashes($name),'edit','brand');

        make_json_result($order);
    }
    else
    {
        make_json_error(sprintf($_LANG['brandedit_fail'], $name));
    }
}

/*------------------------------------------------------ */
//-- 切换是否显示
/*------------------------------------------------------ */
elseif ($_REQUEST['act'] == 'toggle_show')
{
    check_authz_json('brand_manage');

    $id     = intval($_POST['id']);
    $val    = intval($_POST['val']);

    $exc->edit("is_show='$val'", $id);

    make_json_result($val);
}

/*------------------------------------------------------ */
//-- 删除品牌
/*------------------------------------------------------ */
elseif ($_REQUEST['act'] == 'remove')
{
    check_authz_json('brand_manage');

    $id = intval($_GET['id']);

    /* 删除该品牌的图标 */
    $sql = "SELECT brand_logo FROM " .$ecs->table('brand'). " WHERE brand_id = '$id'";
    $logo_name = $db->getOne($sql);
    if (!empty($logo_name))
    {
        @unlink(ROOT_PATH . DATA_DIR . '/brandlogo/' .$logo_name);
    }

    $exc->drop($id);

    /* 更新商品的品牌编号 */
    $sql = "UPDATE " .$ecs->table('goods'). " SET brand_id=0 WHERE brand_id='$id'";
    $db->query($sql);

    $url = 'brand.php?act=query&' . str_replace('act=remove', '', $_SERVER['QUERY_STRING']);

    ecs_header("Location: $url\n");
    exit;
}

/*------------------------------------------------------ */
//-- 删除品牌图片
/*------------------------------------------------------ */
elseif ($_REQUEST['act'] == 'drop_logo')
{
    /* 权限判断 */
    admin_priv('brand_manage');
    $brand_id = isset($_GET['id']) ? intval($_GET['id']) : 0;

    /* 取得logo名称 */
    $sql = "SELECT brand_logo FROM " .$ecs->table('brand'). " WHERE brand_id = '$brand_id'";
    $logo_name = $db->getOne($sql);

    if (!empty($logo_name))
    {
        @unlink(ROOT_PATH . DATA_DIR . '/brandlogo/' .$logo_name);
        $sql = "UPDATE " .$ecs->table('brand'). " SET brand_logo = '' WHERE brand_id = '$brand_id'";
        $db->query($sql);
    }
    $link= array(array('text' => $_LANG['brand_edit_lnk'], 'href' => 'brand.php?act=edit&id=' . $brand_id), array('text' => $_LANG['brand_list_lnk'], 'href' => 'brand.php?act=list'));
    sys_msg($_LANG['drop_brand_logo_success'], 0, $link);
}

/*------------------------------------------------------ */
//-- 排序、分页、查询
/*------------------------------------------------------ */
elseif ($_REQUEST['act'] == 'query')
{
    $brand_list = get_brandlist();
    $smarty->assign('brand_list',   $brand_list['brand']);
    $smarty->assign('filter',       $brand_list['filter']);
    $smarty->assign('record_count', $brand_list['record_count']);
    $smarty->assign('page_count',   $brand_list['page_count']);

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

/**
 * 获取品牌列表
 *
 * @access  public
 * @return  array
 */
function get_brandlist()
{
    $result = get_filter();
    if ($result === false)
    {
        /* 分页大小 */
        $filter = array();

        /* 记录总数以及页数 */
        if (isset($_POST['brand_name']))
        {
            $sql = "SELECT COUNT(*) FROM ".$GLOBALS['ecs']->table('brand') .' WHERE brand_name = \''.$_POST['brand_name'].'\'';
        }
        else
        {
            $sql = "SELECT COUNT(*) FROM ".$GLOBALS['ecs']->table('brand');
        }

        $filter['record_count'] = $GLOBALS['db']->getOne($sql);

        $filter = page_and_size($filter);

        /* 查询记录 */
        if (isset($_POST['brand_name']))
        {
            if(strtoupper(EC_CHARSET) == 'GBK')
            {
                $keyword = iconv("UTF-8", "gb2312", $_POST['brand_name']);
            }
            else
            {
                $keyword = $_POST['brand_name'];
            }
            $sql = "SELECT * FROM ".$GLOBALS['ecs']->table('brand')." WHERE brand_name like '%{$keyword}%' ORDER BY sort_order ASC";
        }
        else
        {
            $sql = "SELECT * FROM ".$GLOBALS['ecs']->table('brand')." ORDER BY sort_order ASC";
        }

        set_filter($filter, $sql);
    }
    else
    {
        $sql    = $result['sql'];
        $filter = $result['filter'];
    }
    $res = $GLOBALS['db']->selectLimit($sql, $filter['page_size'], $filter['start']);

    $arr = array();
    while ($rows = $GLOBALS['db']->fetchRow($res))
    {
        $brand_logo = empty($rows['brand_logo']) ? '' :
            '<a href="../' . DATA_DIR . '/brandlogo/'.$rows['brand_logo'].'" target="_brank"><img src="images/picflag.gif" width="16" height="16" border="0" alt='.$GLOBALS['_LANG']['brand_logo'].' /></a>';
        $site_url   = empty($rows['site_url']) ? 'N/A' : '<a href="'.$rows['site_url'].'" target="_brank">'.$rows['site_url'].'</a>';

        $rows['brand_logo'] = $brand_logo;
        $rows['site_url']   = $site_url;

        $arr[] = $rows;
    }

    return array('brand' => $arr, 'filter' => $filter, 'page_count' => $filter['page_count'], 'record_count' => $filter['record_count']);
}

?>

前台实现过程

一、添加导航栏 :电子票
         打开后台---系统设置—自定义导航栏--添加导航

二、前台控制器

新建upload\ticket.php

upload\ticket.php代码如下

<?php
/**
 * ECSHOP 前台电子票列表
 */


define('IN_ECS', true);
require(dirname(__FILE__) . '/includes/init.php');

if ((DEBUG_MODE & 2) != 2)
{
    $smarty->caching = true;
}

/*------------------------------------------------------ */
//-- INPUT
/*------------------------------------------------------ */



/* 获得请求的分类 ID */
if (!empty($_REQUEST['id']))
{
    $ticket_id = intval($_REQUEST['id']);
    //echo $ticket_id;die;
}



if (empty($ticket_id))
{
    assign_template();
    $position = assign_ur_here('', $_LANG['all_ticket']);
    $smarty->assign('page_title',      $position['title']);    // 页面标题
    $smarty->assign('ur_here',         $position['ur_here']);  // 当前位置
    $smarty->assign('categories',      get_categories_tree()); // 分类树
    $smarty->assign('helps',            get_shop_help());       // 网店帮助
    $smarty->assign('top_goods',        get_top10());           // 销售排行


    $sql ="select * from " . $GLOBALS['ecs']->table('ticket');
    $res = $GLOBALS['db']->query($sql);

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


    $smarty->assign('ticket_list', $ticket_list);

    $smarty->display('ticket_list.dwt');

    exit();

}


$ticket_info = get_ticket_info($ticket_id); // 电子票列表


$seats = str_replace('排', '_', $ticket_info['unavailable']);

$arr = explode(',', str_replace('座', '', $seats));

$ticket_info['unavailable'] = json_encode($arr, true);


//print_r($ticket_info);die;

if (empty($ticket_info))
{

    ecs_header("Location: ./\n");

    exit;

}

$smarty->assign('data_dir',    DATA_DIR);



// 赋值固定内容

assign_template();

$position = assign_ur_here($cate, $ticket_info['ticket_name']);

//查询已售出电子票的数量
$saled_num = $GLOBALS['db']->getOne('SELECT COUNT(*) FROM ' . $GLOBALS['ecs']->table('ticket_cart') . " WHERE ticket_id = '".$_GET['id']."'"   ) ;
$surplus_num = $ticket_info['ticket_num'] - $saled_num;
//print_r($surplus_num) ;die;

$smarty->assign('page_title',     $position['title']);   // 页面标题
$smarty->assign('ur_here',        $position['ur_here']); // 当前位置
//print_r($position);die;
$smarty->assign('categories',     get_categories_tree());        // 分类树
$smarty->assign('helps',          get_shop_help());              // 网店帮助
$smarty->assign('top_goods',      get_top10());                  // 销售排行
$smarty->assign('show_marketprice', $_CFG['show_marketprice']);
$smarty->assign('ticket', $ticket_info);
$smarty->assign('surplus_num', $surplus_num);  //剩余影票数量



$smarty->display('ticket_info.dwt');



/*------------------------------------------------------ */
//-- PRIVATE FUNCTION
/*------------------------------------------------------ */



/**

 * 获得指定电子票的详细信息

 *

 * @access  private

 * @param   integer $id

 * @return  void

 */

function get_ticket_info($id)
{

    $sql = 'SELECT * FROM ' . $GLOBALS['ecs']->table('ticket') . " WHERE ticket_id = '$id'";

    //echo $sql;die;

    $row = $GLOBALS['db']->getRow($sql);



    $row['run_time'] = local_date('Y-m-d H:i', $row['run_time']);

    $row['ban_time'] = local_date('Y-m-d H:i', $row['ban_time']);



    return $row;

}



?>

三、电子票列表模板

1、新建upload\themes\default\ticket_list.dwt(自己布局)(搜索<div class="AreaR">,修改)

ticket_list.dwt代码如下:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="Keywords" content="{$keywords}" />
<meta name="Description" content="{$description}" />
<!-- TemplateBeginEditable name="doctitle" -->
<title>{$page_title}</title>
<!-- TemplateEndEditable --><!-- TemplateBeginEditable name="head" --><!-- TemplateEndEditable -->
<link rel="shortcut icon" href="favicon.ico" />
<link rel="icon" href="animated_favicon.gif" type="image/gif" />
<link href="{$ecs_css_path}" rel="stylesheet" type="text/css" />
{* 包含脚本文件 *}
{insert_scripts files='common.js,global.js,compare.js'}
{insert_scripts files='jquery-1.9.1.min.js,jquery.json.js'}
</head>
<body>
<!-- #BeginLibraryItem "/library/page_header.lbi" --><!-- #EndLibraryItem -->
<!--当前位置 start-->
<div class="block box">
 <div id="ur_here">
  <!-- #BeginLibraryItem "/library/ur_here.lbi" --><!-- #EndLibraryItem -->
 </div>
</div>
<!--当前位置 end-->
<div class="blank"></div>
<div class="block clearfix">
  <!--left start-->
  <div class="AreaL">
   <!-- TemplateBeginEditable name="左边区域" -->
<!-- #BeginLibraryItem "/library/cart.lbi" -->

{insert_scripts files='transport_jquery.js'}
<div class="cart" id="ECS_CARTINFO">
 {insert name='cart_info'}
</div>
<div class="blank5"></div>

 <!-- #EndLibraryItem -->
<!-- #BeginLibraryItem "/library/category_tree.lbi" -->

<div class="box">
 <div class="box_1">
  <div id="category_tree">
   <!--{foreach from=$categories item=cat}-->
    <dl>
    <dt><a href="{$cat.url}">{$cat.name|escape:html}</a></dt>
    <!--{foreach from=$cat.children item=child}-->
    <dd><a href="{$child.url}">{$child.name|escape:html}</a></dd>
    <!--{/foreach}-->
    </dl>
    <!--{/foreach}-->
  </div>
 </div>
</div>
<div class="blank5"></div>

 <!-- #EndLibraryItem -->
 <!-- #BeginLibraryItem "/library/filter_attr.lbi" --><!-- #EndLibraryItem -->
 <!-- #BeginLibraryItem "/library/price_grade.lbi" --><!-- #EndLibraryItem -->
<!-- TemplateEndEditable -->
<!-- TemplateBeginEditable name="左边广告区域(宽200px)" -->
<!-- TemplateEndEditable -->
    <!--AD end-->
    <!-- #BeginLibraryItem "/library/history.lbi" --><!-- #EndLibraryItem -->
  </div>
  <!--left end-->
  <!--right start-->



<div class="AreaR">

    <!-- TemplateBeginEditable name="通栏广告区域(宽750px)" -->
    <!-- TemplateEndEditable -->
    <div class="blank5"></div>
    <h3 class="border"><span><!--{$lang.all_ticket}--></span></h3>
    <!-- {foreach from=$ticket_list name="ticket_list_foreach" item=ticket_data} -->
                       <dl style="margin:20px; height:300px; text-align:center;float:left;">
                                <dt><a href="ticket.php?id={$ticket_data.ticket_id}">
                                <img src="data/ticket_pic/{$ticket_data.film_pic}" alt="{$ticket_data.ticket_pic|escape:html}" height="270" width="200" /></a></dt>
                                <dd>余票:{$ticket_data.ticket_num}张|价格:{$ticket_data.ticket_price}元|<a href="ticket.php?id={$ticket_data.ticket_id}">购买</a></dd>
                       </dl>
             <!-- {/foreach} -->
    <div class="blank5"></div>

</div>




  <!--right end-->
</div>
<div class="blank5"></div>
<!--帮助-->
<div class="block">
  <div class="box">
   <div class="helpTitBg clearfix">
    <!-- #BeginLibraryItem "/library/help.lbi" --><!-- #EndLibraryItem -->
   </div>
  </div>
</div>
<div class="blank"></div>
<!--帮助-->
<!--友情链接 start-->
<!--{if $img_links  or $txt_links }-->
<div id="bottomNav" class="box">
 <div class="box_1">
  <div class="links clearfix">
   <!--开始图片类型的友情链接{foreach from=$img_links item=link}-->
    <a href="{$link.url}" target="_blank" title="{$link.name}"><img src="{$link.logo}" alt="{$link.name}" border="0" /></a>
    <!--结束图片类型的友情链接{/foreach}-->
    <!-- {if $txt_links} -->
    <!--开始文字类型的友情链接{foreach from=$txt_links item=link}-->
    [<a href="{$link.url}" target="_blank" title="{$link.name}">{$link.name}</a>]
    <!--结束文字类型的友情链接{/foreach}-->
    <!-- {/if} -->
  </div>
 </div>
</div>
<!--{/if}-->
<!--友情链接 end-->
<div class="blank"></div>
<!-- #BeginLibraryItem "/library/page_footer.lbi" --><!-- #EndLibraryItem -->
</body>
</html>
2、创建电子票详情ticket_info.dwt(自己布局);
(复制 goods.dwt模板upload\themes\default\goods.dwt);

ticket_info.dwt代码如下:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="Keywords" content="{$keywords}" />
<meta name="Description" content="{$description}" />
	<style type="text/css">
		.demo{width:700px; margin:40px auto 0 auto; min-height:450px;}
		@media screen and (max-width: 360px) {.demo {width:340px}}
		ul,li{
		list-style:none;
		}
		.front{width: 300px;margin: 5px 32px 45px 32px;background-color: #f0f0f0;	color: #666;text-align: center;padding: 3px;border-radius: 5px;}
		.booking-details {float: right;position: relative;width:200px;height: 400px; }
		.booking-details h3 {margin: 5px 5px 0 0;font-size: 16px;}
		.booking-details p{line-height:26px; font-size:16px; color:#999;width:300px;}
		.booking-details p span{color:#666}
		div.seatCharts-cell {color: #182C4E;height: 25px;width: 25px;line-height: 25px;margin: 3px;float: left;text-align: center;outline: none;font-size: 13px;}
		div.seatCharts-seat {color: #fff;cursor: pointer;-webkit-border-radius: 5px;-moz-border-radius: 5px;border-radius: 5px;}
		div.seatCharts-row {height: 35px;}
		div.seatCharts-seat.available {background-color: #B9DEA0;}
		div.seatCharts-seat.focused {background-color: #76B474;border: none;}
		div.seatCharts-seat.selected {background-color: #E6CAC4;}
		div.seatCharts-seat.unavailable {background-color: #472B34;cursor: not-allowed;}
		div.seatCharts-container {border-right: 1px dotted #adadad;width: 400px;padding: 20px;float: left;}
		div.seatCharts-legend {padding-left: 0px;position: absolute;bottom: 16px;}
		ul.seatCharts-legendList {padding-left: 0px;}
		.seatCharts-legendItem{float:left; width:90px;margin-top: 10px;line-height: 2;}
		span.seatCharts-legendDescription {margin-left: 5px;line-height: 30px;}
		.checkout-button {display: block;width:80px; height:24px; line-height:20px;margin: 10px auto;border:1px solid #999;font-size: 14px; cursor:pointer}
		#selected-seats {max-height: 200px;overflow-y: auto;overflow-x: none;width: 200px;}
		#selected-seats li{float:left; width:72px; height:26px; line-height:26px; border:1px solid #d3d3d3; background:#f7f7f7; margin:6px; font-size:14px; font-weight:bold; text-align:center}
		.checkout{
		float:right;
		}
	</style>
<!-- TemplateBeginEditable name="doctitle" -->
<title>{$page_title}</title>
<!-- TemplateEndEditable --><!-- TemplateBeginEditable name="head" --><!-- TemplateEndEditable -->
<style>
	.p_t{
		margin-top:10px;
	}
	b{
		width:100px;
	}
	a.info{
		text-decoration:none;
		display:inline-block;
		width:75px;
		line-height:25px;
		border:1px #CCC solid;
		text-align:center;
	}
</style>
<link rel="shortcut icon" href="favicon.ico" />
<link rel="icon" href="animated_favicon.gif" type="image/gif" />
<link href="{$ecs_css_path}" rel="stylesheet" type="text/css" />


</head>


<body>
	<!-- #BeginLibraryItem "/library/page_header.lbi" --><!-- #EndLibraryItem -->
	<!--当前位置 start-->
	<div class="block box">
		<div id="ur_here">
		<!-- #BeginLibraryItem "/library/ur_here.lbi" --><!-- #EndLibraryItem -->
		</div>
	</div>
	<!--当前位置 end-->
	<div class="blank"></div>

	
  
  
	<!-- 电子票 详情 start-->
  	<div class="block box">
    	<div class="box">
     	<div class="box_1">
      	<h3><span>{$lang.ticket_info}</span></h3>
	      	<div class="boxCenterList">
	        	<table width="100%" border="0" cellpadding="5" cellspacing="1" bgcolor="#dddddd">
		        	<tr>
						<td bgcolor="#ffffff" width="200">
							<div style="width:300px;text-align: center;">
								<img src="data/ticket_pic/{$ticket.film_pic}" width="200" />
							</div>
						</td>
						<td bgcolor="#ffffff" valign="top" style="padding:20px;">
							<h1 style="margin-top:10px;line-height:50px;" ><span id="film_name">{$ticket.film_name}</span></h1>
							<div style="height:200px;">	
								<p class="p_t"><b>{$lang.film_start_c}:</b>{$ticket.run_time}</p>
								<p class="p_t"><b>{$lang.film_end_c}:</b>{$ticket.ban_time}</p>
								<p class="p_t"><b>{$lang.film_act_er}:</b>巴巴克·纳加非/杰拉德·巴特勒 / 摩根·弗里曼 / 安吉拉·贝塞特 / 艾伦·艾克哈特 / 拉妲·米契尔 / 杰基·厄尔·哈利 / 夏洛特·莱利 / 梅丽莎·里奥</p>
								<p class="p_t"><b>{$lang.film_type_c}:</b>{$ticket.t_id}</p>
								<p class="p_t"><b>{$lang.film_price_c}:</b><span id="ticket_price">{$ticket.ticket_price}</span>{$lang.film_unit}
								<b>{$lang.film_remain}:</b>{$surplus_num}{$lang.film_spread}</p>
							</div>

						</td>
		        	</tr>
	      		</table>

	     	</div>
     	</div>
    	</div>
    	<div class="blank5"></div>

		<!-- 电影 start-->
		<div class="box_1">
		  	<h3 style="padding:0 5px;">
			  	<div id="com_b" class="history clearfix">
					<h2 class="h2bg">{$lang.film_check_seat}</h2> <!--- 选座 -->
			  	</div>
 		 	</h3>
			<!--- 电影选座str -->
			<div id="com_h" style="display:;">
			  	<div id="main">
				  	<div class="demo">
					  	<div id="seat-map">
						  	<div class="front">{$lang.film_pm_1}</div>
					  	</div>
					  	<div class="booking-details">

						  	<p>{$lang.film_check_seat}:</p>
						  	<ul id="selected-seats"></ul>
						  	<p>{$lang.film_checked_seat}:<span id="counter"></span></p>
						  	<p>{$lang.film_all}:<b><span id="total">0</span></b>{$lang.film_unit}</p>
						  	<div id="legend"></div>

					  	</div>
					  	<div style="text-align: center;">
					  		<input type="button" onclick="checkout({$ticket.ticket_id})" value="确定购买" style="border-radius:5px;width:200px;height:40px;background: #ff6600;border: none;">
					  	</div>
					  	<div style="clear:both;"></div>
			  		</div>

			  	</div>
			</div>
		</div>
		<!-- 电影选作 end -->
	
  </div>  
<!--电子票 详情 end-->

<div class="blank5"></div>





<!--帮助-->
<div class="block">
  <div class="box">
   <div class="helpTitBg clearfix">
    <!-- #BeginLibraryItem "/library/help.lbi" --><!-- #EndLibraryItem -->
   </div>
  </div>  
</div>
<div class="blank"></div>
<!--帮助-->
<!--友情链接 start-->
<!--{if $img_links  or $txt_links }-->
<div id="bottomNav" class="box">
 <div class="box_1">
  <div class="links clearfix">
    <!--开始图片类型的友情链接{foreach from=$img_links item=link}-->
    <a href="{$link.url}" target="_blank" title="{$link.name}"><img src="{$link.logo}" alt="{$link.name}" border="0" /></a>
    <!--结束图片类型的友情链接{/foreach}-->
    <!-- {if $txt_links} -->
    <!--开始文字类型的友情链接{foreach from=$txt_links item=link}-->
    [<a href="{$link.url}" target="_blank" title="{$link.name}">{$link.name}</a>] 
    <!--结束文字类型的友情链接{/foreach}-->
    <!-- {/if} -->
  </div>
 </div>
</div>
<!--{/if}-->
<!--友情链接 end-->
<div class="blank"></div>
<!-- #BeginLibraryItem "/library/page_footer.lbi" --><!-- #EndLibraryItem -->


	{insert_scripts files='js/seat/jquery-1.8.3.min.js,seat/jquery.seat-charts.min.js'}
	<script type="text/javascript">
			$(function() {
				window.__Object_toJSONString = Object.prototype.toJSONString;
				delete Object.prototype.toJSONString;
			});
		</script>
		<script type="text/javascript">
			var price = {$ticket.ticket_price}; //票价
	        // alert(price)
			$(document).ready(function() {
				var $cart = $('#selected-seats'); //座位区
				$counter = $('#counter'); //票数
				$total = $('#total'); //总计金额
				
				var sc = $('#seat-map').seatCharts({
					map: [  //座位图
					'aaaaaaaaaa',
					'aaaaaaaaaa',
					'__________',
					'aaaaaaaa__',
					'aaaaaaaaaa',
					'aaaaaaaaaa',
					'aaaaaaaaaa',
					'aaaaaaaaaa',
					'aaaaaaaaaa',
					'aa__aa__aa'
					],
					naming : {
						top : false,
						getLabel : function (character, row, column) {
							return column;
						}
					},
					legend : { //定义图例
						node : $('#legend'),
						items : [
						[ 'a', 'available',   '可选座' ],
						[ 'a', 'unavailable', '已售出']
						]					
					},
					click: function () { //点击事件
						//seat_id = this.settings.id;
						if (this.status() == 'available') { //可选座
							$('<li>'+(this.settings.row+1)+'排'+this.settings.label+'座</li>').attr('id', 'cart-item-'+this.settings.id).data('seatId', this.settings.id).appendTo($cart);
							
							$counter.text(sc.find('selected').length+1); // 总票数
							$total.text(recalculateTotal(sc)); // 总价格	
							
							return 'selected';
						} else if (this.status() == 'selected') { //已选中
							//更新数量
							$counter.text(sc.find('selected').length-1);
							//更新总计
							$total.text(recalculateTotal(sc)-price-price);
							
							
							//删除已预订座位
							$('#cart-item-'+this.settings.id).remove();
							//可选座
							return 'available';
						} else if (this.status() == 'unavailable') { //已售出
							return 'unavailable';
						} else {
							return this.style();
						}
						
					}
					
				});
				//已售出的座位
				sc.get({$ticket.unavailable}).status('unavailable');
				
				
			});
			//计算总金额
			function recalculateTotal(sc) {
				var total = 0;
				sc.find('selected').each(function () {
					total += price;
				});
				return total += price;
			}
			
			
			function checkout(goodsId, parentId)
			{
			  var goods        = new Object();
			  var spec_arr     = $('#selected-seats').text(); // 座位
			  var fittings_arr = new Array();
			  var number       = $('#counter').html(); // 所选票数
			  //var formBuy      = document.forms['ECS_FORMBUY'];
			  var quick		   = 0;
				//alert(spec_arr);return false;
			  
			  goods.quick    = quick;
			  goods.spec     = spec_arr;
			  goods.goods_id = goodsId;
			  goods.number   = number;
			  goods.parent   = (typeof(parentId) == "undefined") ? 0 : parseInt(parentId);

			  Ajax.call('flow.php?step=ticket', 'goods=' + JSON.stringify(goods), addToCartResponse, 'POST', 'JSON');

			}

			/* *
			 * 处理添加商品到购物车的反馈信息
			 */
			function addToCartResponse(result)
			{
				if(result.error == 1)
				{
					alert(result.message);
					location.href = 'flow.php?step=login';
				}
				else if(result.error == 2)
				{
					alert(result.message);
				}
				else if(result.error == 3)
				{
					alert(result.message);
					location.href = 'flow.php?step=ticket_done';
				}
				else if(result.error == 4)
				{
					alert(result.message);
				}
				else if(result.error == 5)
				{
					alert(result.message);
				}
				console.log(result);return false;
			}
			
		</script>
</body>
</html>
3、找到seat插件,整体文件夹放到upload/js中;

在index.html中有style放入到模板ticket_info.dwt中相应位置(自行调整布局);

4、解决jquery冲突

5、生成订单upload\flow.php

把以下代码放到if ($_REQUEST[‘step‘] == ‘add_to_cart‘)前面

      

/* 购买电子票

* */

 

if ($_REQUEST[‘step‘] == ‘ticket‘)

{  

              include_once(‘includes/cls_json.php‘);

              $json  = new JSON;

             

              $_POST[‘goods‘] = strip_tags(urldecode($_POST[‘goods‘]));

              $_POST[‘goods‘] = json_str_iconv($_POST[‘goods‘]);

              $goods = $json->decode($_POST[‘goods‘]);

              //print_r($goods);die;

       /*

     * 检查用户是否已经登录

     * 如果用户已经登录了则检查是否有默认的收货地址

     * 如果没有登录则跳转到登录和注册页面

     */

    if (empty($_SESSION[‘direct_shopping‘]) && $_SESSION[‘user_id‘] == 0)

    {

              $result[‘error‘] = 1;

              $result[‘message‘] = "请先登录";

             

        die($json->encode($result));

    }

 

      

      

       /* 检查:商品数量是否合法 */

       if (empty($goods->number))

       {

              $result[‘error‘]   = 2;

              $result[‘message‘] = ‘还没有选座‘;

             

               echo  $json->encode($result);die;

       }

 

       /* 检查:商品数量是否合法*/

       if ($goods->number > 1)

       {

              $result[‘error‘]   = 5;

              $result[‘message‘] = ‘系统正在升级,只能选一张票‘;

             

              echo  $json->encode($result);die;

       }

       $spec = explode(‘,‘, trim(str_replace(‘座‘, ‘座,‘, $goods->spec), ‘,‘)); // 座位转换成数组格式

      

      

       // 随机生成票号

       $string = ‘abcdefghkmnprstuvwxyzABCDEFGHKMNPRSTUVWXYZ23456789‘;

       $uid = $_SESSION[‘user_id‘];

      

       for($j = 0; $j < count($spec); $j++){

              $str = ‘‘;

              for ($i=0; $i < 10; $i++) {

                     $str.= $string[rand(0,strlen($string)-1)];

              }     

             

              $data[] = $uid.$str;

       }

      

      

    /* 取得商品信息 */

    $ticket_info = "SELECT * FROM " .$GLOBALS[‘ecs‘]->table(‘ticket‘). " WHERE ticket_id = ‘".$goods->goods_id ."‘";

    $ticket = $GLOBALS[‘db‘]->getRow($ticket_info);

      

      

    //此处出现问题bug未解决

       foreach($spec as $key => $val)

       {

             

              /* 初始化要插入购物车的基本件数据 */

              $parent[] = array(

                     ‘user_id‘        => $_SESSION[‘user_id‘],

                     ‘ticket_order‘   => $data[$key],

                     ‘ticket_id‘      => $goods->goods_id,

                     ‘film_name‘      => $ticket[‘film_name‘],

                     ‘ticket_price‘   => $ticket[‘ticket_price‘],

                     ‘seat‘           =>  $val

              );    

       }

 

       foreach($spec as $sp) // 查询其他人是否已购买

       {

              $seat = "SELECT seat FROM " .$GLOBALS[‘ecs‘]->table(‘ticket_cart‘). " WHERE seat = ‘".$sp."‘ AND ticket_id = ‘" . $goods->goods_id ."‘";

      

              $one = $GLOBALS[‘db‘]->getOne($seat);

             

              if($one)

              {

                     $result[‘error‘] = 4;

                     $result[‘message‘] = ‘座位已被预定‘;

                    

              }

              else

              {

                     //购物车没有此物品,则插入

                     foreach($parent as $p)

                     {

                                   $GLOBALS[‘db‘]->autoExecute($GLOBALS[‘ecs‘]->table(‘ticket_cart‘), $p, ‘INSERT‘);

                    

                                   $result[‘error‘] = 3;

                                   $result[‘message‘] = "购买成功";

                     }     

                    

              }

       }

       echo  $json->encode($result);die;

 

}

elseif($_REQUEST[‘step‘] == ‘ticket_done‘)

{

              $sql = " select * from ". $GLOBALS[‘ecs‘]->table(‘ticket_cart‘).

              " where user_id = ".$_SESSION[‘user_id‘];

             

              $carts = $GLOBALS[‘db‘]->getAll($sql);

              $smarty->assign(‘carts‘, $carts);

             

             

              $num = count($carts); // 总票数

              $smarty->assign(‘num‘, $num);

             

              $price = ‘‘;

              foreach ($carts as $key => $val)

              {

                     $price    +=  $val[‘ticket_price‘];

              }

              $smarty->assign(‘total_price‘, $price);

             

}


6、找到themes\default\flow.dwt(生成订单列表)

(搜索<!-- {if $step eq "login"} -->)把以下代码放到其前面

 

                  

         <!-- {if $step eq "ticket_done"} -->

         <div class="flowBox" style="margin:30px auto 70px auto;">

        

                   <h6 style="text-align:center; height:30px; line-height:30px;">{$lang.remember_order_number}:</h6>

        

                   <table width="99%" align="center" cellpadding="20" cellspacing="0" bgcolor="#fff" style="border:1px solid #ddd; margin:20px auto;" >

<tr>

                                     <td align="center" bgcolor="#FFFFFF">票号</td>

                                     <td align="center" bgcolor="#FFFFFF">电影名称</td>

                                     <td align="center" bgcolor="#FFFFFF">座位号</td>

</tr>

                            <!--{foreach from=$carts item=cart}-->

<tr>

                                     <td align="center" bgcolor="#FFFFFF">{$cart.ticket_order}</td>

                                     <td align="center" bgcolor="#FFFFFF">{$cart.film_name}</td>

                                     <td align="center" bgcolor="#FFFFFF">{$cart.seat}</td>

</tr>

<!--{/foreach}-->

                   </table>

                   <table width="99%" align="center" cellpadding="20" cellspacing="0" bgcolor="#fff" style="border:1px solid #ddd; margin:20px auto;" >

                            <tr>

                                     <td align="center" bgcolor="#FFFFFF">总票数:{$num}</td>

                                     <td align="center" bgcolor="#FFFFFF"></td>

                                     <td align="center" bgcolor="#FFFFFF">总金额:{$total_price} 元</td>

                            </tr>

                   </table>

         </div>      

         <!-- {/if} -->












echop二次开发——电子票

标签:

原文地址:http://blog.csdn.net/fyx708711/article/details/51443996

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!