1 Star 0 Fork 4

Gangs / myb2c

forked from carlton / myb2c 
加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
cart.php 1.96 KB
一键复制 编辑 原始数据 按行查看 历史
carlton 提交于 2014-02-09 12:57 . init
<?php
include './include/common.inc.php';
if($mkorder){
if (!$U['uid']) {
$help->showmessage("请先登陆");
}
if (!is_array($commo)) {
$help->showmessage("没有检查到合法的购物请求");
}
$t_price = 0;
$items = array();
foreach ($commo as $v) {
$q = $db->fetch_first("select * from commo where id={$v['id']}");
if ($q) {
if (($q['stock'] - $v['count']) < 0) {
$help->showmessage("您所购买的 {$q['name']} 数量不足{$v['count']},库存还剩{$q['stock']}件,请返回购物车修改数量", $C['SITE_URL'] . '/cart.php');
}
if ($q['discount'] > 0) {
$t_price = $t_price + ($q['vprice'] * $v['count'] * $q['discount'] / 10);
} else {
$t_price = $t_price + $q['vprice'] * $v['count'];
}
$items[] = array('id'=>$q['id'],"count"=>$v['count']);
}
}
foreach($items as $v){
$q=$db->fetch_first("select stock from commo where id = {$v['id']}");
$newstock=max(0,($q['stock']-$v['count']));
$db->query("update commo set stock={$newstock} where id ={$v['id']}");
}
$item = serialize($items);
$nowtime = time();
$db->query("INSERT INTO `order` (uid,item,price,time) VALUES ({$U['uid']},'{$item}',{$t_price},{$nowtime})");
setcookie("buycommo",null,-1,'/');
header('Location:'.$C['SITE_URL'].'/order.php?id='.$db->insert_id());
exit;
}
$cookie=$_COOKIE['buycommo'];
$commos=array();
if($cookie){
$arr=unserialize(stripslashes($cookie));
if($arr){
foreach ($arr as $k=>$v){
$q=$db->fetch_first("select * from commo where id={$k}");
if($q){
$q['count']=$v;
$commos[]=$q;
}
}
}
}
$tpl->assign('title','我的购物车');
$tpl->assign("commos",$commos);
$tpl->display("cart.html");
PHP
1
https://gitee.com/Gangs/myb2c.git
git@gitee.com:Gangs/myb2c.git
Gangs
myb2c
myb2c
master

搜索帮助

53164aa7 5694891 3bd8fe86 5694891