-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathupdate_cart_goods.php
92 lines (76 loc) · 3.43 KB
/
update_cart_goods.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
<?php
/**
* ECSHOP 购物流程
* ============================================================================
* 版权所有 2005-2008 上海商派网络科技有限公司,并保留所有权利。
* 网站地址: http://www.ecshop.com;
* ----------------------------------------------------------------------------
* 这不是一个自由软件!您只能在不用于商业目的的前提下对程序代码进行修改和
* 使用;不允许对程序代码以任何形式任何目的的再发布。
* ============================================================================
* $Author: zblikai $
* $Id: flow.php 15632 2009-02-20 03:58:31Z zblikai $
*/
define('IN_ECS', true);
require(dirname(__FILE__) . '/includes/init.php');
include_once('includes/cls_json.php');
$result = array('error' => 0, 'message' => '', 'content' => '', 'goods_id' => '');
$json = new JSON;
if($_POST['id'])
{
//查询商品id
$sql = "select goods_id from ".$GLOBALS['ecs']->table('cart')." where rec_id = ". $_POST['id'];
$goods_id = $GLOBALS['db']->getOne($sql);
//验证库存 by mike
$sql = "select goods_number from ".$GLOBALS['ecs']->table('goods')." where goods_id = ". $goods_id;
$goods_stock_number = $GLOBALS['db']->getOne($sql);
if($_POST['number'] > $goods_stock_number){
$result['rec_id'] = $_POST['id'];
$result['error'] = 1;
$result['message'] = '库存不足';
$result['stock'] = $goods_stock_number;
die($json->encode($result));
}
$sql = 'UPDATE '.$GLOBALS['ecs']->table('cart')." SET goods_number = '". $_POST['number'] ."' WHERE rec_id=".$_POST['id'];
$GLOBALS['db']->query($sql);
}
$sql = 'SELECT c.*,g.goods_name,g.goods_thumb,g.goods_id,c.goods_number,c.goods_price' .
' FROM ' . $GLOBALS['ecs']->table('cart') ." AS c ".
" LEFT JOIN ".$GLOBALS['ecs']->table('goods')." AS g ON g.goods_id=c.goods_id ".
" WHERE session_id = '" . SESS_ID . "' AND rec_type = '" . CART_GENERAL_GOODS . "'";
$row = $GLOBALS['db']->GetAll($sql);
$arr = array();
foreach($row AS $k=>$v)
{
$arr[$k]['goods_thumb'] =get_image_path($v['goods_id'], $v['goods_thumb'], true);
$arr[$k]['short_name'] = $GLOBALS['_CFG']['goods_name_length'] > 0 ?
sub_str($v['goods_name'], $GLOBALS['_CFG']['goods_name_length']) : $v['goods_name'];
$arr[$k]['url'] = build_uri('goods', array('gid' => $v['goods_id']), $v['goods_name']);
$arr[$k]['goods_number'] = $v['goods_number'];
$arr[$k]['goods_name'] = $v['goods_name'];
$arr[$k]['goods_price'] = price_format($v['goods_price']);
$arr[$k]['goods_amount_price'] = price_format($v['goods_price']*$v['goods_number']);
$arr[$k]['rec_id'] = $v['rec_id'];
}
$sql = 'SELECT SUM(goods_number) AS number, SUM(goods_price * goods_number) AS amount' .
' FROM ' . $GLOBALS['ecs']->table('cart') .
" WHERE session_id = '" . SESS_ID . "' AND rec_type = '" . CART_GENERAL_GOODS . "'";
$row = $GLOBALS['db']->GetRow($sql);
if ($row)
{
$number = intval($row['number']);
$amount = floatval($row['amount']);
}
else
{
$number = 0;
$amount = 0;
}
$GLOBALS['smarty']->assign('str',sprintf($GLOBALS['_LANG']['cart_info'], $number, price_format($amount, false)));
$GLOBALS['smarty']->assign('cart_list_number',$number);
$GLOBALS['smarty']->assign('cart_list_amount',price_format($amount));
$GLOBALS['smarty']->assign('goods',$arr);
$result['content'] = $GLOBALS['smarty']->fetch('library/cart_info.lbi');
//$smarty->assign('order',$order);
die($json->encode($result));
?>