客车网上订票系统项目--购票支付、个人中心我的订单
1、今日完成任务:
(1)购票支付 点击 完成 订单进入个人中心“未出行订单” 点击取消订单进入个人中心“ 未完成订单”。
(2)个人中心 未出行订单,未完成订单界面与数据库关联。
(3)实现改签和退票功能。
2、核心代码
支付:
<?php session_start(); $UserTel=$_SESSION["userAccount"]; $UserPwd=$_SESSION["userPwd"]; require_once 'function.php'; //票 id $id=$_GET['id']; $num=$_GET["num"]; //乘客 id $sPId=$_GET['arr']; //$aPId=explode(",", $sPId); //用户id $sqlU="select userId from userinfo where userTel='$UserTel' and userPass='$UserPwd';"; $rowsU=sel($sqlU); $uId=$rowsU[0]['userId']; //显示对应车票列表 $sql="select * from ticketInfo where ticketStatus=1 and id=$id;"; $rows=sel($sql); ?> <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title>支付-客车网上售票系统</title> <link rel="stylesheet" type="text/css" href="css/base.css"/> <link rel="stylesheet" type="text/css" href="css/others.css"/> </head> <body> <!--头部--> <div class="header"> <div class="container clear"> <div class="left"><a href="index.html"><img src="img/logo_pc.png"/></a></div> <div class="right clear"> <ul class="nav left clear"> <li><a href="home.php">首页</a></li> <li><a href="ticketsOnline.php">在线订票</a></li> <li><a href="newsList.php">新闻公告</a></li> <li class="active"><a href="leftMessage.php">留言中心</a></li> <li><a href="userInfo.php">个人中心</a></li> </ul> <div class="right btns-links"> <a href="login.html">登录</a> <a href="register.html">注册</a> </div> </div> </div> </div> <!--支付--> <div class="payment-box"> <div class="container"> <h3>您的订单提交成功!请在<span style="color: red;"><span id="minute">29</span>分<span id="second">59</span>秒</span>内完成支付,以免订单失效</h3> <table class="ticket-content" border="0" cellspacing="" cellpadding=""> <tr> <th>起始站</th> <th>到达站</th> <th>发车时间</th> <th>车次</th> <th>价格</th> </tr> <tr> <td><?php echo $rows[0]["startPosition"]?></td> <td><?php echo $rows[0]["endPosition"]?></td> <td> <p><?php echo explode(" ", $rows[0]['startTime'])[0]?></p> <p><?php echo explode(" ", $rows[0]['startTime'])[1]?></p> </td> <td><?php echo $rows[0]["carName"]?></td> <td style="color: red;">¥<?php echo $rows[0]["ticketPrice"]*$num;?></td> </tr> </table> <div class="pay-type"> <form class="payment-form" action="" method="post"> <p>第三方支付</p> <label> <input type="radio" name="pay" checked="checked" id="pay" value="支付宝" /> <img src=""/><img src="img/icon_alipay.png"/>支付宝支付 </label> <label> <input type="radio" name="pay" id="pay2" value="微信" /> <img src=""/><img src="img/icon_wechatpay.png"/>微信支付 </label> <p><input type="button" name="submit" onclick="submitOrder('paymentAction.php?id=<?php echo $id;?>&uId=<?php echo $uId?>&pIds=<?php echo $sPId;?>')" id="submit" value="立即支付" /></p> </form> </div> </div> </div> <!--优势--> <div class="register-advantage"> <div class="container"> <ul class="clear"> <li class="clear"> <div class="advantage-img left"><img src="img/icon_pinpaibaozheng.png"/></div> <div class="left"> <h4>品牌保证</h4> <p>提供正规的购票服务</p> </div> </li> <li class="clear"> <div class="advantage-img left"><img src="img/icon_kuaisufankui.png"/></div> <div class="left"> <h4>快速反馈</h4> <p>第一时间短信通知</p> </div> </li> <li class="clear"> <div class="advantage-img left"><img src="img/icon_fangbiankuaijie.png"/></div> <div class="left"> <h4>方便快捷</h4> <p>车站直接取票上车</p> </div> </li> <li class="clear"> <div class="advantage-img left"><img src="img/icon_zhifufangbian.png"/></div> <div class="left"> <h4>支付方便</h4> <p>支付宝微信</p> </div> </li> </ul> </div> </div> <!--底部--> <div class="register-footer"> <p>客车网上售票系统官方电话 400-100-1234 0371-1234567 客车网上售票信息公示</p> <p>客车网上售票系统 Copyright©2020-2030 版权所有 XXXXXX网络科技有限公司 豫ICP备15030935号-1</p> </div> <div class="modal-pay"> <h3>微信支付</h3> <img src="img/icon_wechatpay.png" alt="" /> <p>请打开<span class="color358EEC">手机微信</span>的<span class="color358EEC">扫一扫</span></p> <p>扫描上方二维码进行支付</p> </div> <script src="js/jquery-3.5.1.min.js" type="text/javascript" charset="utf-8"></script> <script src="layer/layer.js" type="text/javascript" charset="utf-8"></script> <script type="text/javascript"> $(function(){ //倒计时 var minute = 29;//29 var second = 59;//59 var timer=null; timer=setInterval(function() { second--; if(second == 00 && minute == 00) { clearInterval(timer); second = 00; minute=00; $("#submit").css("background","#ccc"); $("#submit").click(function(){ layer.alert("时间已过期请重新选择!"); return false; }); }; //当分钟和秒钟都为00时,重新给值 if(second == 00) { if(minute>0){ second = 59; minute--; } if(minute < 10) minute = "0" + minute; }; //当秒钟为00时,秒数重新给值 if(second < 10) second = "0" + second; $("#minute").text(minute); $("#second").text(second); }, 1000); }); function submitOrder(url){ if($("#second").text()>0){ layer.open({ type: 1, title:"支付", area: ['500px', '360px'], content: $('.modal-pay'), //这里content是一个DOM,注意:最好该元素要存放在body最外层,否则可能被其它的相对元素所影响 btn:['完成','取消'], btnAlign: 'c', yes:function(index, layero){ //添加已购买未出行订单 //alert('yes'); //添加 未出行 票据信息 //此处请求后台程序,下方是成功后的前台处理…… window.location.href=url+"&status=1"; }, btn2:function(index, layero){ //添加未完成订单 //alert("cancel"); // 添加 未完成 票据信息 window.location.href=url+"&status=2"; }, cancel: function(){ //右上角关闭回调 //alert('close'); //return false 开启该代码可禁止点击该按钮关闭 window.location.href=url+"&status=2"; } }); } } </script> </body> </html>
(2)个人中心 未出行订单,未完成订单界面与数据库关联
<?php session_start(); //需要判读一下有没有进行登录 如果有登录进行显示下面的页面 如果没有登录则进入登录界面 if(!isset($_SESSION["userAccount"])){ //存储一下当前url 用于登录成功之后跳回 $_SESSION["userUrl"]=$_SERVER['REQUEST_URI']; header("location:login.php"); die();//下面的代码不在执行 } //显示个人信息 require_once 'function.php'; $status=$_GET['status']; $UserTel=$_SESSION["userAccount"]; $UserPwd=$_SESSION["userPwd"]; if($status==5){ $sql="select * from myTickets mt,passengers p,ticketinfo t,userinfo u where mt.passengersId=p.passengersId and mt.id=t.id and mt.userId=u.userId and u.userTel='$UserTel' and u.userPass='$UserPwd' and t.endTime<now() order by myTaddTime desc;"; $rows=sel($sql); }else{ $sql="select * from myTickets mt,passengers p,ticketinfo t,userinfo u where mt.passengersId=p.passengersId and mt.id=t.id and mt.userId=u.userId and mt.myTicketsStatus='$status' and u.userTel='$UserTel' and u.userPass='$UserPwd' and t.endTime>now() order by myTaddTime desc;"; $rows=sel($sql); } ?> <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title>未完成订单-客车网上售票系统</title> <link rel="stylesheet" type="text/css" href="css/base.css"/> <link rel="stylesheet" type="text/css" href="css/userInfo.css"/> </head> <body> <!--头部--> <div class="header"> <div class="container clear"> <div class="left"><a href="index.html"><img src="img/logo_pc.png"/></a></div> <div class="right clear"> <ul class="nav left clear"> <li><a href="home.php">首页</a></li> <li><a href="ticketsOnline.php">在线订票</a></li> <li><a href="newsList.php">新闻公告</a></li> <li><a href="leftMessage.php">留言中心</a></li> <li class="active"><a href="userInfo.php">个人中心</a></li> </ul> <div class="right btns-links"> <a href="login.html">登录</a> <a href="register.html">注册</a> </div> </div> </div> </div> <!--个人中心--> <div class="userInfo-box"> <div class="container clear"> <div class="left w18"> <ul> <li> <h3>资料设置</h3> <a href="userInfo.php">个人资料</a> <a href="passengers.php">常用旅客</a> <!--<a href="editPass.html">修改密码</a>--> </li> <li> <h3>我的订单</h3> <a href="orderUnfinished.php?status=2">未完成订单</a> <a href="orderUnfinished.php?status=1">未出行订单</a> <a href="orderUnfinished.php?status=5">历史订单</a> </li> </ul> </div> <div class="right w80"> <div class="userInfo-ctn orderUnfished-box"> <h3> <?php if($status==2){echo "未完成订单";}?> <?php if($status==1){echo "未出行订单";}?> <?php if($status==5){echo "历史订单";}?> </h3> <div class="orderUnfished-content"> <?php if($rows){?> <?php foreach ($rows as $key=>$value){?> <table border="0" cellspacing="" cellpadding=""> <tr> <td colspan="3">预定时间:<?php echo $rows[$key]["myTaddTime"]?></td> <td colspan="3">订单号:B2020<?php echo $rows[$key]["myTicketsId"]?></td> </tr> <tr> <td colspan="2"><?php echo $rows[$key]["startPosition"]?>---><?php echo $rows[$key]["endPosition"]?></td> <td><p><?php echo explode(" ", $rows[$key]["startTime"])[0]?></p><p><?php echo explode(" ", $rows[$key]["startTime"])[1]?></p></td> <td style="color: red;">¥<?php echo $rows[$key]["ticketPrice"]?></td> <td> <p>车票状态</p> <p style="color:#fd982b;font-weight:bold;"> <?php if($status==2){echo "已取消";}?> <?php if($status==1){echo "已支付";}?> <?php if($status==5){echo "历史订单";}?> </p> </td> <td> <?php if($status==2){?> <a href="ticketsOnline.php?tips=1&startPosition=<?php echo $rows[$key]['startPosition']?>&endposition=<?php echo $rows[$key]['endPosition']?>&startTime=<?php echo explode(" ", $rows[$key]["startTime"])[0]?>">重新购买</a><br /> <a href="orderDetail.php?myTicketsId=<?php echo $rows[$key]['myTicketsId']?>">查看详情</a> <?php }?> <?php if($status==1){?> <a href="ticketsOnline.php?tips=1&gq=1&mytId=<?php echo $rows[$key]["myTicketsId"]?>&startPosition=<?php echo $rows[$key]['startPosition']?>&endposition=<?php echo $rows[$key]['endPosition']?>&startTime=<?php echo explode(" ", $rows[$key]["startTime"])[0]?>">改签</a><br /> <a href="javascript:;" onclick="order_Tp('orderTp.php?mytId=<?php echo $rows[$key]["myTicketsId"]?>&id=<?php echo $rows[$key]["id"]?>');">退票</a><br/> <a href="orderDetail.php?myTicketsId=<?php echo $rows[$key]['myTicketsId']?>">查看详情</a> <?php }?> <?php if($status==5){?> <a href="orderDetail.php">删除</a> <?php }?> </td> </tr> </table> <?php }?> <?php }else{?> <p style="color:#666;font-size:16px;">暂无信息</p> <?php }?> </div> </div> </div> </div> </div> <!--优势--> <div class="register-advantage"> <div class="container"> <ul class="clear"> <li class="clear"> <div class="advantage-img left"><img src="img/icon_pinpaibaozheng.png"/></div> <div class="left"> <h4>品牌保证</h4> <p>提供正规的购票服务</p> </div> </li> <li class="clear"> <div class="advantage-img left"><img src="img/icon_kuaisufankui.png"/></div> <div class="left"> <h4>快速反馈</h4> <p>第一时间短信通知</p> </div> </li> <li class="clear"> <div class="advantage-img left"><img src="img/icon_fangbiankuaijie.png"/></div> <div class="left"> <h4>方便快捷</h4> <p>车站直接取票上车</p> </div> </li> <li class="clear"> <div class="advantage-img left"><img src="img/icon_zhifufangbian.png"/></div> <div class="left"> <h4>支付方便</h4> <p>支付宝微信</p> </div> </li> </ul> </div> </div> <!--底部--> <div class="register-footer"> <p>客车网上售票系统官方电话 400-100-1234 0371-1234567 客车网上售票信息公示</p> <p>客车网上售票系统 Copyright©2020-2030 版权所有 XXXXXX网络科技有限公司 豫ICP备15030935号-1</p> </div> <script src="js/jquery-3.5.1.min.js" type="text/javascript" charset="utf-8"></script> <script src="layer/layer.js"></script> <script> function order_Tp(url){// obj 票据id 票id layer.confirm("确认要退票吗?",function(){ //此处请求后台程序,下方是成功后的前台处理…… window.location.href=url; layer.msg('已成功!',{icon:1,time:1000}); }); } </script> </body> </html>
改签:
<?php require_once 'function.php'; $id=$_GET['id']; $mytId=$_GET['mytid']; //改签 修改订单信息 $sql="update myTickets set id=$id where myTicketsId=$mytId;"; $result=oper($sql); $sqlYT="select id from myTickets where myTicketsId=$mytId;"; $rowsYT=sel($sqlYT); $YTId=$rowsYT[0]['id']; // 修改 原 车票信息 $sqlT0="select soldTicket from ticketinfo where id=$YTId;"; $rowsT0=sel($sqlT1); $soldT0=$rowsT1[0]['soldTicket']; echo $soldT0; //更新余票 $sqlT1Up0="update ticketinfo set soldTicket=($soldT10-1) where id=$YTId;"; $resultUp0=oper($sqlT1Up); // 修改 新 车票信息 $sqlT1="select soldTicket from ticketinfo where id=$id;"; $rowsT1=sel($sqlT1); $soldT1=$rowsT1[0]['soldTicket']; //更新余票 $sqlT1Up="update ticketinfo set soldTicket=($soldT1+1) where id=$id;"; $resultUp=oper($sqlT1Up); header("location:orderUnfinished.php?status=1"); ?>
退票:
<?php require_once 'function.php'; $mytId=$_GET['mytId']; $id=$_GET['id']; //退票 删除票据 更改票据状态 原票数量增加 $sqlmyT="update myTickets set myTicketsStatus=3 where myTicketsId=$mytId;"; $resultMyT=oper($sqlmyT); //乘客id 增加票的数量 $sqlPid="select passengersId from myTickets where id=$tId;"; $rowsPId=sel($sqlPid); $count=count($rowsPId); // 修改车票信息 $sqlT1="select soldTicket from ticketinfo where id=$id;"; $rowsT1=sel($sqlT1); $soldT1=$rowsT1[0]['soldTicket']; //更新余票 $sqlT1Up="update ticketinfo set soldTicket=($soldT1-1) where id=$id;"; $resultUp=oper($sqlT1Up); header("location:orderUnfinished.php?status=1"); ?>