代码拉取完成,页面将自动刷新
<?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;
flow_drop_cart_goods($_POST['id']);
$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]['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]['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',$arr);
$GLOBALS['smarty']->assign('number',$number);
$GLOBALS['smarty']->assign('amount',$amount);
$result['content'] = $GLOBALS['smarty']->fetch('library/cart_info.lbi');
//$smarty->assign('order',$order);
die($json->encode($result));
/**
* 删除购物车中的商品
*
* @access public
* @param integer $id
* @return void
*/
function flow_drop_cart_goods($id)
{
/* 取得商品id */
$sql = "SELECT * FROM " .$GLOBALS['ecs']->table('cart'). " WHERE rec_id = '$id'";
$row = $GLOBALS['db']->getRow($sql);
if ($row)
{
//如果是超值礼包
if ($row['extension_code'] == 'package_buy')
{
$sql = "DELETE FROM " . $GLOBALS['ecs']->table('cart') .
" WHERE session_id = '" . SESS_ID . "' " .
"AND rec_id = '$id' LIMIT 1";
}
//如果是普通商品,同时删除所有赠品及其配件
elseif ($row['parent_id'] == 0 && $row['is_gift'] == 0)
{
/* 检查购物车中该普通商品的不可单独销售的配件并删除 */
$sql = "SELECT c.rec_id
FROM " . $GLOBALS['ecs']->table('cart') . " AS c, " . $GLOBALS['ecs']->table('group_goods') . " AS gg, " . $GLOBALS['ecs']->table('goods'). " AS g
WHERE gg.parent_id = '" . $row['goods_id'] . "'
AND c.goods_id = gg.goods_id
AND c.parent_id = '" . $row['goods_id'] . "'
AND c.extension_code <> 'package_buy'
AND gg.goods_id = g.goods_id
AND g.is_alone_sale = 0 AND c.group_id='".$row['group_id']."'";//by mike add
$res = $GLOBALS['db']->query($sql);
$_del_str = $id . ',';
while ($id_alone_sale_goods = $GLOBALS['db']->fetchRow($res))
{
$_del_str .= $id_alone_sale_goods['rec_id'] . ',';
}
$_del_str = trim($_del_str, ',');
$sql = "DELETE FROM " . $GLOBALS['ecs']->table('cart') .
" WHERE session_id = '" . SESS_ID . "' " .
"AND (rec_id IN ($_del_str) OR parent_id = '$row[goods_id]' OR is_gift <> 0) AND group_id='".$row['group_id']."'";
}
//如果不是普通商品,只删除该商品即可
else
{
$sql = "DELETE FROM " . $GLOBALS['ecs']->table('cart') .
" WHERE session_id = '" . SESS_ID . "' " .
"AND rec_id = '$id' LIMIT 1";
}
$GLOBALS['db']->query($sql);
}
flow_clear_cart_alone();
}
/**
* 删除购物车中不能单独销售的商品
*
* @access public
* @return void
*/
function flow_clear_cart_alone()
{
/* 查询:购物车中所有不可以单独销售的配件 */
$sql = "SELECT c.rec_id, gg.parent_id
FROM " . $GLOBALS['ecs']->table('cart') . " AS c
LEFT JOIN " . $GLOBALS['ecs']->table('group_goods') . " AS gg ON c.goods_id = gg.goods_id
LEFT JOIN" . $GLOBALS['ecs']->table('goods') . " AS g ON c.goods_id = g.goods_id
WHERE c.session_id = '" . SESS_ID . "'
AND c.extension_code <> 'package_buy'
AND gg.parent_id > 0
AND g.is_alone_sale = 0";
$res = $GLOBALS['db']->query($sql);
$rec_id = array();
while ($row = $GLOBALS['db']->fetchRow($res))
{
$rec_id[$row['rec_id']][] = $row['parent_id'];
}
if (empty($rec_id))
{
return;
}
/* 查询:购物车中所有商品 */
$sql = "SELECT DISTINCT goods_id
FROM " . $GLOBALS['ecs']->table('cart') . "
WHERE session_id = '" . SESS_ID . "'
AND extension_code <> 'package_buy'";
$res = $GLOBALS['db']->query($sql);
$cart_good = array();
while ($row = $GLOBALS['db']->fetchRow($res))
{
$cart_good[] = $row['goods_id'];
}
if (empty($cart_good))
{
return;
}
/* 如果购物车中不可以单独销售配件的基本件不存在则删除该配件 */
$del_rec_id = '';
foreach ($rec_id as $key => $value)
{
foreach ($value as $v)
{
if (in_array($v, $cart_good))
{
continue 2;
}
}
$del_rec_id = $key . ',';
}
$del_rec_id = trim($del_rec_id, ',');
if ($del_rec_id == '')
{
return;
}
/* 删除 */
$sql = "DELETE FROM " . $GLOBALS['ecs']->table('cart') ."
WHERE session_id = '" . SESS_ID . "'
AND rec_id IN ($del_rec_id)";
$GLOBALS['db']->query($sql);
}
?>
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。