前臺效果展現:javascript
![](http://static.javashuo.com/static/loading.gif)
2.php
![](http://static.javashuo.com/static/loading.gif)
3.css
![](http://static.javashuo.com/static/loading.gif)
後臺展現效果:html
![](http://static.javashuo.com/static/loading.gif)
代碼實現:java
1、 添加菜單項:路徑admin\includes\inc_menu.PHPnode
- $modules['18_ticket_manage']['01_ticket_list'] = 'ticket.php?act=list';
-
- $modules['18_ticket_manage']['02_ticket_add'] = 'ticket.php?act=add';
配置菜單語言python
打開 /languages/zh_cn/admin/common.php文件,添加語言mysql
- //菜單—添加
-
- $_LANG['18_ticket_manage'] = '電子票管理';
-
- //電子票管理
-
- $_LANG['01_ticket_list'] = '電子票列表';
-
- $_LANG['02_ticket_add'] = '添加電子票';
2、上傳圖片路徑:在upload\data\建立ticket_pic文件夾,圖片上傳路徑jquery
三:數據庫:web
創建ecs_ticket表
![](http://static.javashuo.com/static/loading.gif)
創建ecs_ticket_cart
![](http://static.javashuo.com/static/loading.gif)
四、添加電子票(upload\admin\templates\ticket_add.htm)
一、建立添加電子票模板ticket_add.htm(本身按照ticket表更改佈局);
(複製品牌模板upload\admin\templates\brand_info.htm);
如下是修改事後的ticket_add.html
- <!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>
4、建立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']);
- }
-
- ?>
如下代碼是ticket_list.html用來顯示電子票
- <!-- $Id: brand_list.htm 15898 2009-05-04 07:25:41Z liuhui $ -->
-
- {if $full_page}
- {include file="pageheader.htm"}
- {insert_scripts files="../js/utils.js,listtable.js"}
- <!-- 品牌搜索 -->
- {include file="brand_search.htm"}
- <form method="post" action="" name="listForm">
- <!-- start brand list -->
- <div class="list-div" id="listDiv">
- {/if}
-
- <table cellpadding="3" cellspacing="1">
- <tr>
- <th>電影名稱</th>
- <th>開場時間</th>
- <th>禁止時間</th>
- <th>總票數</th>
- <th>票價</th>
- <th>操做</th>
- </tr>
- {foreach from=$ticket_list item=ticket}
- <tr>
- <td class="first-cell">
- <span>{$ticket.film_name}</span>
- <span onclick="javascript:listTable.edit(this, 'edit_brand_name', {$brand.brand_id})">{$brand.brand_name|escape:html}</span>
- </td>
- <td align="center">{$ticket.run_time}</td>
- <td align="center">{$ticket.ban_time}</td>
- <td align="center"><span onclick="javascript:listTable.edit(this, 'edit_sort_order', {$brand.brand_id})">{$ticket.ticket_num}</span></td>
- <td align="center">{$ticket.ticket_price}</td>
- <td align="center">
- <a href="brand.php?act=edit&id={$brand.brand_id}" title="{$lang.edit}">編輯</a> |
- <a href="javascript:;" onclick="listTable.remove({$brand.brand_id}, '{$lang.drop_confirm}')" title="{$lang.edit}">刪除</a>
- </td>
- </tr>
- {/foreach}
- <tr>
- <td align="right" nowrap="true" colspan="6">
- {include file="page.htm"}
- </td>
- </tr>
- </table>
-
- {if $full_page}
- <!-- end brand list -->
- </div>
- </form>
- <script type="text/javascript" language="javascript">
- <!--
- listTable.recordCount = {$record_count};
- listTable.pageCount = {$page_count};
- {foreach from=$filter item=item key=key}
- listTable.filter.{$key} = '{$item}';
- {/foreach}
- {literal}
- onload = function()
- {
- // 開始檢查訂單
- startCheckOrder();
- }
- {/literal}
- //-->
- </script>
- {include file="pagefooter.htm"}
- {/if}
到達這裏以後,後臺添加也就完成了下面是前臺的展現效果代碼:
1、添加導航欄 :電子票
打開後臺---系統設置—自定義導航欄--添加導航
![](http://static.javashuo.com/static/loading.gif)
2、在upload下創建一個控制器ticket.php
如下代碼是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']);
- $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->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'";
- $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;
- }
- ?>
3、電子票列表模板
一、新建upload\themes\default\ticket_list.dwt(本身佈局)
如下是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'}
- </head>
- <body>
- <!--
- <!--當前位置 start-->
- <div class="block box">
- <div id="ur_here">
- <!--
- </div>
- </div>
- <!--當前位置 end-->
- <div class="blank"></div>
- <div class="block clearfix">
- <!--left start-->
- <div class="AreaL">
- <!-- TemplateBeginEditable name="左邊區域" -->
- <!--
- <!--
- <!--
- <!--
- <!--
- <!--
- <!-- TemplateEndEditable -->
- <!-- TemplateBeginEditable name="左邊廣告區域(寬200px)" -->
- <!-- TemplateEndEditable -->
- <!--AD end-->
- <!--
- </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">
- <!--
- </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>
- <!--
- </body>
- </html>
建立電子票詳情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:
- .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:
- .booking-details p span{color:
- div.seatCharts-cell {color:
- div.seatCharts-seat {color:
- div.seatCharts-row {height: 35px;}
- div.seatCharts-seat.available {background-color:
- div.seatCharts-seat.focused {background-color:
- div.seatCharts-seat.selected {background-color:
- div.seatCharts-seat.unavailable {background-color:
- div.seatCharts-container {border-right: 1px dotted
- 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
-
-
- .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
- 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>
- <!--
- <!--當前位置 start-->
- <div class="block box">
- <div id="ur_here">
- <!--
- </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>{$ticket.film_desc}</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">
- <!--
- </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>
- <!--
-
-
- {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>
三、找到seat插件,總體文件夾放到upload/js中;
![](http://static.javashuo.com/static/loading.gif)
生成訂單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 ."'"
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- ;
- $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');
- $sql_select="select unavailable from ".$GLOBALS['ecs']->table('ticket')."where ticket_id='$p[ticket_id]'";
- $str=$GLOBALS['db']->getOne($sql_select);
- //$seat接過來的值 若是數據庫爲空則添加數據 不然 就拼接原數據+,+新數據
- if(empty($str)){
- $seat=$p['seat'];
- }else{
- $seat=$str.",".$p['seat'];
- }
- $sql_update="update".$GLOBALS['ecs']->table('ticket')."set unavailable='$seat' where ticket_id='$p[ticket_id]'";
- $GLOBALS['db']->getAll($sql_update);
- $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);
- }
六、找到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} -->
ok,一切完成。