购物车多选提交订单

<!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" />
<title>购物车</title>

<script src="__HJS__jquery-1.8.3.min.js"></script>

<script src="__HJS__cart.js"></script>

<link href="__HCSS__common.css" type="text/css" rel="stylesheet">

<link href="__HCSS__common-content.css" type="text/css" rel="stylesheet">

<link href="__HCSS__cart.css" type="text/css" rel="stylesheet">


</head>

<body>

<div class="bigbg">
<!--这里是头部-->
<div class="header">
<div class="box">
<a class="logo" href="index.html"><img src="__HIMG__logo.png"></a>
<ul class="left">
<if condition="empty($_SESSION['vipname'])">
<li><a href="{:U('Login/index')}">登录</a></li>
<li class="cur"><a href="{:U('Login/register')}">注册</a></li><else/>
<li><a href="{:U('Vipcenter/vip')}">{:session('vipname')}</a></li><li><a href="{:U('Login/out')}">退出</a></li>,欢迎您!</if>
</ul>
<ul class="nav">
<li><a href="{:U('Index/index')}">首页</a></li>
<li><a href="{:U('Index/about')}">品牌介绍</a></li>
<li><a href="{:U('Index/news')}">新闻中心</a></li>
<li><a href="{:U('Index/products')}">产品中心</a></li>
<li><a href="{:U('Index/contact')}">联系我们</a></li>
</ul>
<div class="clear"></div>
</div>
</div>

 

<!--这里是内容区域-->
<div class="content">
<div class="box">
<div class="con">
<div class="title">
<img class="logo" src="__HIMG__conduct-logo.png">
<ul class="tit">
<li class="cur">全部商品</li>
<li>降价商品</li>
<li>库存</li>
</ul>
</div>
<div class="listbox">
<form action="{:U('Vipcenter/cart')}" method="post">
<ul class="list cur">
<volist name="dat" id="do">
<li class='fa' id="row{$do['id']}">
<input type="checkbox" name="check[]" id="check" value="{$do['id']}" />
<a href="product-details.html" class="img"><img src="__ROOT__/Public/Uploads/{$do['image1']}" width="86" height="70"></a>
<a href="product-details.html" class="font">{$do['name']}</a>
<span class="xian">¥:{$do['price']}</span>
<a class="delete" href="javascript:void(0)" onClick="del_cart({$do['id']})">删除</a>
<div class="num">
<span class="down" >-</span>
<input type="text" value="{$do['num']}" name="num{$do['id']}" />
<span class="up" >+</span>
<div class="clear"></div>
</div>
</li>
</volist>
</ul>
<a href="{:U('Vipcenter/pay')}"><button type="submit"> 提交</button></a>
</div>
</div>
</form>
<img src="__HIMG__bg-bottom.png">
</div>



</div>

</div>

<!--这里是底部-->
<include file="Public:footer" />

<script>
function del_cart(id){
if(confirm('是否删除?')){
$.post("{:U('del_cart')}",'id='+id,function(d){
if(d==0){
alert('参数错误!');
}else if(d==1){
alert('删除成功!');
$("#row"+id).remove();
}else{
alert('非法操作!');
}
})
}
}
</script>

后台代码

public function del_cart(){//删除购物车
layout(false);
if(AJAX){
$id=I('post.id');
$data=M('shoppingcar')->where("id='$id'")->delete();
if($data==1){
echo 1;
}else{
echo 0;
}
}else{
echo -5;
}
}

public function cart(){//购物车结算
$scar=M('shoppingcar');
if(IS_POST){
$order=M('orders');
$check=I('post.check');
// $address=M('shipaddress');
// $addr=$address->where('vipname="'.$_SESSION['vipname'].'"')->select();
$data['ordernum']='dd'.time().rand(1000,9999);
foreach ($check as $key => $value) {
$cart=$scar->where('id="'.$value.'"')->find();
$product=M('products')->where('id="'.$cart['pid'].'"')->find();
$data['pid']=$product['id'];
$data['pimg']=$product['image1'];
$data['name']=$product['name'];
$data['state']=0;
$data['price']=$product['price'];
$data['num']=$_POST['num'.$value];
$data['vipid']=$cart['vipid'];
$res=$order->add($data);
$scar->delete($value);
}
if($res){
session('ordernum',$data['ordernum']);

$this->success('正在进入结算页面,请稍后......',U('Vipcenter/pay','or='.$data['ordernum']));
}else{
$this->success('参数错误,请重试');
}
}else{
$scar=M('shoppingcar');
$list=$scar->field('shoppingcar.*,products.name,products.content,products.price,products.image1')->join('products on shoppingcar.pid=products.id')->where('shoppingcar.vipid="'.$_SESSION['vipname'].'"')->select();
$this->assign('dat',$list);
$this->display();
}
}

posted @ 2017-03-06 17:06  思念的色彩  阅读(191)  评论(0编辑  收藏  举报