ticket(电子票) 应用于电影院
1.
languages/zh_cn/admin/common.php文件,添加语言
//菜单—添加
$_LANG['18_ticket_manage'] = '电子票管理';
//电子票管理
$_LANG['01_ticket_list'] = '电子票列表';
$_LANG['02_ticket_add'] = '添加电子票';
2.
$modules['18_ticket_manage']['01_ticket_list'] = 'ticket.php?act=list';
$modules['18_ticket_manage']['02_ticket_add'] = 'ticket.php?act=add';
这样我们就在后台写上了 "电子票"的按钮
3.在upload\data\创建ticket_pic文件夹,图片上传路径
4. 建立ecs_ticket表 与 ecs_ticket_cart
5.添加电子票的列表(upload\admin\templates\ticket_add.htm)
SHOP 管理中心 - 品牌管理
电子票列表
SHOP 管理中心 - 添加电子票
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']) ? '' :
'';
$site_url = empty($rows['site_url']) ? 'N/A' : ''.$rows['site_url'].'';
$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']);
}
?>
{if $full_page}
{include file="pageheader.htm"}
{insert_scripts files="../js/utils.js,listtable.js"}
{include file="brand_search.htm"}
{include file="pagefooter.htm"}
{/if}
这样我们后台的功能就完成了 那我们看前台的
1.打开后台---系统设置—自定义导航栏--添加导航
2.在seat文件夹中找到
3.在upload\themes\default\ticket_info.dwt
{$page_title}
{$lang.ticket_info}
{$ticket.film_name}
开始时间{$lang.film_start_c}:{$ticket.run_time}2016-05-18
结束时间{$lang.film_end_c}:{$ticket.ban_time}2016-05-18
演员{$lang.film_act_er}:巴巴克·纳加非/杰拉德·巴特勒 / 摩根·弗里曼 / 安吉拉·贝塞特 / 艾伦·艾克哈特 / 拉妲·米契尔 / 杰基·厄尔·哈利 / 夏洛特·莱利 / 梅丽莎·里奥
{$lang.film_type_c}:{$ticket.t_id}
{$lang.film_price_c}:{$ticket.ticket_price}{$lang.film_unit}
{$lang.film_remain}:{$surplus_num}{$lang.film_spread}
{$lang.film_check_seat}
{$lang.film_pm_1}
选择座位{$lang.film_check_seat}:
选择张数{$lang.film_checked_seat}:
票价{$lang.film_all}:0{$lang.film_unit}
{insert_scripts files='js/seat/jquery-1.8.3.min.js,seat/jquery.seat-charts.min.js'}
4.upload\flow.php (以下内容添加if ($_REQUEST['step'] == 'add_to_cart')前ss)
/* 购买电子票 */
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');
//print_r($p);die;
//购买过的票 入库 前台显示不可选择
$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);
}
//电子票结束
5.
themes\default\flow.dwt(生成订单列表)
{$page_title}
{* 包含脚本文件 *}
{insert_scripts files='common.js,shopping_flow.js'}
{* 包含脚本文件 *}
{insert_scripts files='showdiv.js'}
{$lang.label_collection}
{$goods.goods_name}
{$lang.collect_to_flow}
{insert_scripts files='transport_jquery.js'}
{$lang.goods_fittings}
{$lang.label_favourable}
{insert_scripts files='region.js,utils.js'}
{$lang.remember_order_number}: {$order.order_sn}
{$lang.select_shipping}: {$order.shipping_name},{$lang.select_payment}: {$order.pay_name}。{$lang.order_amount}: {$total.amount_formated}
{$order.pay_desc}
{$pay_online}
{$order_submit_back}
{$lang.remember_order_number}:
票号
电影名称
座位号
{$cart.ticket_order}
{$cart.film_name}
{$cart.seat}
总票数:{$num}
总金额:{$total_price} 元
{insert_scripts files='utils.js,user.js'}
用户登录:
用户注册:
{if $need_rechoose_gift}
{$lang.gift_remainder}
{/if}