You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

3995 lines
152 KiB

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

<?php
define('IN_ASC', true);
require(dirname(__FILE__) . '/includes/init.php');
require(ROOT_PATH . 'includes/lib_order.php');
/* 載入語言文件 */
require_once(ROOT_PATH . 'languages/' .$_CFG['lang']. '/user.php');
require_once(ROOT_PATH . 'languages/' .$_CFG['lang']. '/shopping_flow.php');
/*------------------------------------------------------ */
//-- INPUT
/*------------------------------------------------------ */
/* 增加購物車選擇性結算--開始 */
if (!empty($_REQUEST['act']) && $_REQUEST['act'] == 'selcart')
{
include('includes/cls_json.php');
$json = new JSON;
$res = array('err_msg' => '', 'result' => '');
if ($_GET['sel_goods'])
{
if($_GET['sel_goods']){
$id_ext = " AND rec_id in (". $_GET['sel_goods'] .") ";
}
$_SESSION['sel_cartgoods'] = $_GET['sel_goods'];
$cart_goods = get_cart_goods($id_ext);
$res['total_number'] = $cart_goods['total']['total_number'];
$res['result'] = $cart_goods['total']['goods_price'];
//折扣活動
$res['your_discount'] = '';
$discount = compute_discount($res['suppid']);
if(is_array($discount)){
$favour_name = empty($discount['name']) ? '' : join(',', $discount['name']);
$res['your_discount'] = sprintf($_LANG['your_discount'], $favour_name, price_format($discount['discount']));
}
}
else
{
$res['total_number'] = 0;
$res['result'] = price_format(0);
}
die($json->encode($res));
}
if (!isset($_REQUEST['step']))
{
$_REQUEST['step'] = "cart";
}
/*------------------------------------------------------ */
//-- PROCESSOR
/*------------------------------------------------------ */
assign_template();
assign_dynamic('flow');
$position = assign_ur_here(0, $_LANG['shopping_flow']);
$smarty->assign('page_title', $position['title']); // 頁面標題
$smarty->assign('ur_here', $position['ur_here']); // 當前位置
$smarty->assign('categories', get_categories_tree()); // 分類樹
$smarty->assign('helps', get_shop_help()); // 網店幫助
$smarty->assign('lang', $_LANG);
$smarty->assign('show_marketprice', $_CFG['show_marketprice']);
$smarty->assign('data_dir', DATA_DIR); // 數據目錄
if (file_exists(ROOT_PATH . 'includes/website/config/qq_config.php')) {
$smarty->assign('qq_login', 1);
}
if (file_exists(ROOT_PATH . 'includes/website/config/weixin_config.php')) {
$smarty->assign('weixin_login', 1);
}
if (file_exists(ROOT_PATH . 'includes/website/config/alipay_config.php')) {
$smarty->assign('alipay_login', 1);
}
if (file_exists(ROOT_PATH . 'includes/website/config/weibo_config.php')) {
$smarty->assign('weibo_login', 1);
}
$smarty->assign('lang', $_LANG);
// 購物流程
if ($_REQUEST['step'] == 'cart')
{
require_once(ROOT_PATH . 'includes/lib_sms.php');
/* 獲取用户手機號 */
$sql = "SELECT user_id, mobile_phone FROM " . $ecs->table('users') . " WHERE user_name='$_SESSION[user_name]' LIMIT 1";
$row = $db->getRow($sql);
/* 是否開啓強制手機綁定 */
if ($_CFG['ecsdxt_mobile_cons'] == '1' && (!$row || !ismobile($row['mobile_phone'])))
{
require_once(ROOT_PATH . 'languages/' .$_CFG['lang']. '/sms.php');
show_message($_LANG['ecsdxt_mobile_cons_notice'], '綁定手機號', 'user.php?act=bindmobile', 'info');
}
}
if ($_REQUEST['act']=='EditAddress')
{
include_once('includes/cls_json.php');
include_once('includes/lib_transaction.php');
$flow_type = isset($_SESSION['flow_type']) ? intval($_SESSION['flow_type']) : CART_GENERAL_GOODS;
$smarty->assign('real_goods_count', exist_real_goods(0, $flow_type) ? 1 : 0);
$result = array('error' => 0, 'message' => '', 'content' => '');
$json = new JSON;
$address_id = intval($_GET['address_id']);
if ($address_id)
{
$sql="select * from ". $ecs->table('user_address') ." where address_id='$address_id' ";
$address_info = $db->getRow($sql);
if ($address_info)
{
$address_info['tel_array'] = explode("-", $address_info['tel']);
}
$smarty->assign('address', $address_info);
$province_list = get_regions(1, $address_info['country']);
$city_list = get_regions(2, $address_info['province']);
$district_list = get_regions(3, $address_info['city']);
$smarty->assign('province_list', $province_list);
$smarty->assign('city_list', $city_list);
$smarty->assign('district_list', $district_list);
}elseif (isset($_SESSION['flow_consignee']) && $address_id==0 && $_SESSION['user_id']<1){
$address_info = get_consignee();
$smarty->assign('address', $address_info);
$province_list = get_regions(1, $address_info['country']);
$city_list = get_regions(2, $address_info['province']);
$district_list = get_regions(3, $address_info['city']);
$smarty->assign('province_list', $province_list);
$smarty->assign('city_list', $city_list);
$smarty->assign('district_list', $district_list);
}else
{
$smarty->assign('province_list', get_regions(1, $_CFG['shop_country']));
}
$result['content'] = $smarty->fetch("library/address_list.lbi");
die($json->encode($result));
}
elseif ($_REQUEST['act']=='selAddress')
{
include_once('includes/cls_json.php');
$order = flow_order_info();
$result = array('error' => 0, 'message' => '', 'content' => '');
$json = new JSON;
$address_id = intval($_GET['address_id']);
$sql = "update ". $GLOBALS['ecs']->table('users') ." set address_id='". $_REQUEST['address_id'] ."' where user_id='".$_SESSION['user_id']."' ";
$db->query($sql);
$sql = "SELECT * ".
" FROM " . $GLOBALS['ecs']->table('user_address') .
" WHERE address_id = '".$_REQUEST['address_id']."' ";
$consignee = $GLOBALS['db']->getRow($sql);
$_SESSION['flow_consignee'] = $consignee;
$flow_type = isset($_SESSION['flow_type']) ? intval($_SESSION['flow_type']) : CART_GENERAL_GOODS;
$region = array($consignee['country'], $consignee['province'], $consignee['city'], $consignee['district']);
$shipping_list = available_shipping_list($region);
$cart_weight_price = cart_weight_price($flow_type);
$insure_disabled = true;
$cod_disabled = true;
$sql_where = $_SESSION['user_id']>0 ? "user_id='". $_SESSION['user_id'] ."' " : "session_id = '" . SESS_ID . "' AND user_id=0 ";//增加購物車選擇性結算--青蜂網絡www.0769web.net
// 查看購物車中是否全為免運費商品,若是則把運費賦為零
$sql = 'SELECT count(*) FROM ' . $ecs->table('cart') . " WHERE $sql_where AND `extension_code` != 'package_buy' AND `is_shipping` = 0";//修改購物車選擇性結算--青蜂網絡www.0769web.net
$shipping_count = $db->getOne($sql);
foreach ($shipping_list AS $key => $val)
{
$shipping_cfg = unserialize_config($val['configure']);
$shipping_fee = ($shipping_count == 0 AND $cart_weight_price['free_shipping'] == 1) ? 0 : shipping_fee($val['shipping_code'], unserialize($val['configure']),
$cart_weight_price['weight'], $cart_weight_price['amount'], $cart_weight_price['number']);
$shipping_list[$key]['format_shipping_fee'] = price_format($shipping_fee, false);
$shipping_list[$key]['shipping_fee'] = $shipping_fee;
$shipping_list[$key]['free_money'] = price_format($shipping_cfg['free_money'], false);
$shipping_list[$key]['insure_formated'] = strpos($val['insure'], '%') === false ?
price_format($val['insure'], false) : $val['insure'];
/* 當前的配送方式是否支持保價 */
if ($val['shipping_id'] == $order['shipping_id'])
{
$insure_disabled = ($val['insure'] == 0);
$cod_disabled = ($val['support_cod'] == 0);
}
}
$smarty->assign('shipping_list', $shipping_list);
$smarty->assign('insure_disabled', $insure_disabled);
$smarty->assign('cod_disabled', $cod_disabled);
die($json->encode($result));
}
elseif ($_REQUEST['act']=='delAddress')
{
include_once('includes/cls_json.php');
include_once('includes/lib_transaction.php');
$flow_type = isset($_SESSION['flow_type']) ? intval($_SESSION['flow_type']) : CART_GENERAL_GOODS;
$smarty->assign('real_goods_count', exist_real_goods(0, $flow_type) ? 1 : 0);
$order = flow_order_info();
$result = array('error' => 0, 'message' => '', 'content' => '', 'content2'=>'');
$json = new JSON;
$address_id = intval($_GET['address_id']);
if($address_id){
drop_consignee($address_id);
}else{
/* 保存到session */
$_SESSION['flow_consignee'] = '';
}
$consignee_list = get_consignee_list_mb5();
if($_SESSION['flow_consignee']['address_id']==$address_id)
{
if ($consignee_list)
{
$_SESSION['flow_consignee'] = $consignee_list[0];
$region = array($consignee_list[0]['country'], $consignee_list[0]['province'], $consignee_list[0]['city'], $consignee_list[0]['district']);
}
else
{
$_SESSION['flow_consignee']="";
$region = array(1, 0, 0, 0);
}
}
$smarty->assign('consignee_list', $consignee_list);
$smarty->assign('name_of_region', array($_CFG['name_of_region_1'], $_CFG['name_of_region_2'], $_CFG['name_of_region_3'], $_CFG['name_of_region_4']));
$smarty->assign('shop_province_list', get_regions(1, $_CFG['shop_country']));
$smarty->assign('province_list', get_regions(1, $_CFG['shop_country']));
$result['content'] = $smarty->fetch("library/address_list.lbi");
if ($consignee_list)
{
$result['have_consignee'] = '1';
}
else
{
$result['have_consignee'] = '0';
}
die($json->encode($result));
}
elseif ($_REQUEST['act']=='saveAddress')
{
$request_body = file_get_contents('php://input');
$_POST = json_decode($request_body, true);
include_once('includes/cls_json.php');
include_once('includes/lib_transaction.php');
$json = new JSON;
/* 保存收貨地址信息_start */
$_POST['address']=strip_tags(urldecode($_POST['address']));
$_POST['address'] = json_str_iconv($_POST['address']);
$address_mb5 = $json->decode($_POST['address']);
$consignee = array(
'address_id' => empty($address_mb5->address_id) ? '0' : intval($address_mb5->address_id),
'consignee' => empty($address_mb5->consignee) ? '' : compile_str(trim($address_mb5->consignee)),
'country' => empty($address_mb5->country) ? '1' : intval($address_mb5->country),
'province' => empty($address_mb5->province) ? '' : intval($address_mb5->province),
'city' => empty($address_mb5->city) ? '' : intval($address_mb5->city),
'district' => empty($address_mb5->district) ? '' : intval($address_mb5->district),
'email' => empty($address_mb5->email) ? '' : compile_str($address_mb5->email),
'address' => empty($address_mb5->address) ? '' : compile_str($address_mb5->address),
'zipcode' => empty($address_mb5->zipcode) ? '' : compile_str(make_semiangle(trim($address_mb5->zipcode))),
'tel' => empty($address_mb5->tel) ? '' : compile_str(make_semiangle(trim($address_mb5->tel))),
'mobile' => empty($address_mb5->mobile) ? '' : compile_str(make_semiangle(trim($address_mb5->mobile))),
);
if ($_SESSION['user_id'] > 0)
{
/* 如果用户已經登錄,則保存收貨人信息 */
$consignee['user_id'] = $_SESSION['user_id'];
save_consignee($consignee, true);
}
/* 保存到session */
$_SESSION['flow_consignee'] = stripslashes_deep($consignee);
/* 保存收貨地址信息_end */
$result = array('error' => 0, 'message' => '', 'content' => '', 'closediv'=>$address_mb5->closediv);
$consignee_list = get_consignee_list_mb5();
$smarty->assign('consignee_list', $consignee_list);
$result['content'] = $smarty->fetch("library/address_list.lbi");
if($consignee_list && count($consignee_list)==1)
{
$_SESSION['flow_consignee'] = $consignee_list[0];
}
die($json->encode($result));
}
/*------------------------------------------------------ */
//-- 添加商品到購物車
/*------------------------------------------------------ */
if ($_REQUEST['step'] == 'add_to_cart')
{
include_once('includes/cls_json.php');
$request_body = file_get_contents('php://input');
$_POST = json_decode($request_body, true);
$_POST['goods'] = strip_tags(urldecode($_POST['goods']));
$_POST['goods'] = json_str_iconv($_POST['goods']);
if (!empty($_REQUEST['goods_id']) && empty($_POST['goods']))
{
if (!is_numeric($_REQUEST['goods_id']) || intval($_REQUEST['goods_id']) <= 0)
{
ecs_header("Location:./\n");
}
$goods_id = intval($_REQUEST['goods_id']);
exit;
}
$result = array('error' => 0, 'message' => '', 'content' => '', 'content_top' => '', 'goods_id' => '');
$json = new JSON;
if (empty($_POST['goods']))
{
$result['error'] = 1;
die(json_encode($result));
}
$goods = json_decode($_POST['goods']);
$result['goods_id'] = $goods->goods_id;
/* 代碼增加_判斷是否秒殺 */
$time_xg_now=gmtime();
$row_xg= $GLOBALS['db']->getRow("select buymax, sale_start_date, sale_end_date from ". $GLOBALS['ecs']->table('goods') ." where goods_id='".$goods->goods_id."' " );
if ( $row_xg['buymax'] >0 && $row_xg['sale_start_date'] < $time_xg_now && $row_xg['sale_end_date'] > $time_xg_now )
{
if ( !$_SESSION['user_id'] )
{
$result['error'] = 999;
$result['message'] = "此商品為秒殺限購商品,需要登錄後才能繼續購買!";
die($json->encode($result));
}
elseif ( intval($goods->number) > intval($row_xg['buymax']) )
{
$result['error'] = 888;
$result['message'] = "此商品為秒殺限購商品,秒殺限購期間每人最多隻能訂購 ". $row_xg['buymax'] . " 件!";
die($json->encode($result));
}
else
{
$sql_where = $_SESSION['user_id']>0 ? "user_id='". $_SESSION['user_id'] ."' " : "session_id = '" . SESS_ID . "' AND user_id=0 ";//增加購物車選擇性結算--青蜂網絡www.0769web.net
$num_cart_old_1=$GLOBALS['db']->getOne("select sum(goods_number) from ". $GLOBALS['ecs']->table('cart') ." where $sql_where and goods_id= " . $goods->goods_id );//修改購物車選擇性結算--青蜂網絡www.0769web.net
$num_cart_old_2=$GLOBALS['db']->getOne("select sum(og.goods_number) from ". $GLOBALS['ecs']->table('order_goods') ." AS og , ". $GLOBALS['ecs']->table('order_info') ." AS o where o.user_id='$_SESSION[user_id]' and o.order_id = og.order_id and add_time > ". $row_xg['sale_start_date'] ." and add_time < ". $row_xg['sale_end_date'] ." and og.goods_id = " . $goods->goods_id );
$num_cart_old = $num_cart_old_1 + $num_cart_old_2 ;
$num_total = $num_cart_old + intval($goods->number);
if ( $num_total > intval($row_xg['buymax']) )
{
$result['error'] = 888;
$num_else=intval($row_xg['buymax'])-$num_cart_old;
$result['message'] ="注意:\n\r此商品秒殺期間每人限購 ". $row_xg['buymax'] . "\n\r";
if ($num_cart_old_2)
{
$result['message'] .="您之前已經成功購買過 $num_cart_old_2 件!\n\r";
}
if ($num_cart_old_1)
{
$result['message'] .="您的購物車中已經存在 $num_cart_old_1 件!\n\r";
}
if ($num_cart_old_1 or $num_cart_old_2)
{
$result['message'] .="所以,";
}
$result['message'] .= "您只能再買 ". $num_else ."";
die($json->encode($result));
}
}
}
/* 代碼增加_判斷是否秒殺*/
/* 檢查如果商品有規格而post的數據沒有規格把商品的規格屬性通過JSON傳到前台 */
if (empty($goods->spec) AND empty($goods->quick))
{
$sql = "SELECT a.attr_id, a.attr_name, a.attr_type, ".
"g.goods_attr_id, g.attr_value, g.attr_price " .
'FROM ' . $GLOBALS['ecs']->table('goods_attr') . ' AS g ' .
'LEFT JOIN ' . $GLOBALS['ecs']->table('attribute') . ' AS a ON a.attr_id = g.attr_id ' .
"WHERE a.attr_type != 0 AND g.goods_id = '" . $goods->goods_id . "' " .
'ORDER BY a.sort_order, g.attr_price, g.goods_attr_id';
$res = $GLOBALS['db']->getAll($sql);
if (!empty($res))
{
$spe_arr = array();
foreach ($res AS $row)
{
$spe_arr[$row['attr_id']]['attr_type'] = $row['attr_type'];
$spe_arr[$row['attr_id']]['name'] = $row['attr_name'];
$spe_arr[$row['attr_id']]['attr_id'] = $row['attr_id'];
$spe_arr[$row['attr_id']]['values'][] = array(
'label' => $row['attr_value'],
'price' => $row['attr_price'],
'format_price' => price_format($row['attr_price'], false),
'id' => $row['goods_attr_id']);
}
$i = 0;
$spe_array = array();
foreach ($spe_arr AS $row)
{
$spe_array[]=$row;
}
$result['error'] = ERR_NEED_SELECT_ATTR;
$result['goods_id'] = $goods->goods_id;
$result['number'] = $goods->number;
$result['parent'] = $goods->parent;
$result['message'] = $spe_array;
die($json->encode($result));
}
}
/* 更新:如果是一步購物,先清空購物車 */
if ($_CFG['one_step_buy'] == '1')
{
clear_cart();
}
/* 檢查:商品數量是否合法 */
if (!is_numeric($goods->number) || intval($goods->number) <= 0)
{
$result['error'] = 1;
$result['message'] = $_LANG['invalid_number'];
}
/* 更新:購物車 */
else
{
if(!empty($goods->spec))
{
foreach ($goods->spec as $key=>$val )
{
$goods->spec[$key]=intval($val);
}
}
// 更新:添加到購物車
if (addto_cart($goods->goods_id, $goods->number, $goods->spec, $goods->parent))
{
if ($_CFG['cart_confirm'] > 2)
{
$result['message'] = '';
}
else
{
$result['message'] = $_CFG['cart_confirm'] == 1 ? $_LANG['addto_cart_success_1'] : $_LANG['addto_cart_success_2'];
}
$result['content'] = insert_cart_info();
$result['content_top'] = insert_cart_info_top();
$result['one_step_buy'] = $_CFG['one_step_buy'];
}
else
{
$result['message'] = $err->last_message();
$result['error'] = $err->error_no;
$result['goods_id'] = stripslashes($goods->goods_id);
$result['number'] = $goods->number;
if (is_array($goods->spec))
{
$result['product_spec'] = implode(',', $goods->spec);
}
else
{
$result['product_spec'] = $goods->spec;
}
}
}
$result['confirm_type'] = !empty($_CFG['cart_confirm']) ? $_CFG['cart_confirm'] : 2;
die($json->encode($result));
}
elseif ($_REQUEST['step'] == 'add_to_cart_combo') //by mike
{
include_once('includes/cls_json.php');
$_POST['goods']=strip_tags(urldecode($_POST['goods']));
$_POST['goods'] = json_str_iconv($_POST['goods']);
if (!empty($_REQUEST['goods_id']) && empty($_POST['goods']))
{
if (!is_numeric($_REQUEST['goods_id']) || intval($_REQUEST['goods_id']) <= 0)
{
ecs_header("Location:./\n");
}
$goods_id = intval($_REQUEST['goods_id']);
exit;
}
$result = array('error' => 0, 'message' => '', 'content' => '', 'goods_id' => '');
$json = new JSON;
if (empty($_POST['goods']))
{
$result['error'] = 1;
die($json->encode($result));
}
$goods = $json->decode($_POST['goods']);
/* 檢查如果商品有規格而post的數據沒有規格把商品的規格屬性通過JSON傳到前台 */
if (empty($goods->spec) AND empty($goods->quick))
{
$sql = "SELECT a.attr_id, a.attr_name, a.attr_type, ".
"g.goods_attr_id, g.attr_value, g.attr_price " .
'FROM ' . $GLOBALS['ecs']->table('goods_attr') . ' AS g ' .
'LEFT JOIN ' . $GLOBALS['ecs']->table('attribute') . ' AS a ON a.attr_id = g.attr_id ' .
"WHERE a.attr_type != 0 AND g.goods_id = '" . $goods->goods_id . "' " .
'ORDER BY a.sort_order, g.attr_price, g.goods_attr_id';
$res = $GLOBALS['db']->getAll($sql);
if (!empty($res))
{
$spe_arr = array();
foreach ($res AS $row)
{
$spe_arr[$row['attr_id']]['attr_type'] = $row['attr_type'];
$spe_arr[$row['attr_id']]['name'] = $row['attr_name'];
$spe_arr[$row['attr_id']]['attr_id'] = $row['attr_id'];
$spe_arr[$row['attr_id']]['values'][] = array(
'label' => $row['attr_value'],
'price' => $row['attr_price'],
'format_price' => price_format($row['attr_price'], false),
'id' => $row['goods_attr_id']);
}
$i = 0;
$spe_array = array();
foreach ($spe_arr AS $row)
{
$spe_array[]=$row;
}
$result['error'] = ERR_NEED_SELECT_ATTR;
$result['goods_id'] = $goods->goods_id;
$result['parent'] = $goods->parent;
$result['message'] = $spe_array;
$result['group'] = $goods->group;
die($json->encode($result));
}
}
/* 更新:如果是一步購物,先清空購物車 */
if ($_CFG['one_step_buy'] == '1')
{
clear_cart();
}
/* 檢查:商品數量是否合法 */
if (!is_numeric($goods->number) || intval($goods->number) <= 0)
{
$result['error'] = 1;
$result['message'] = $_LANG['invalid_number'];
}
/* 更新:購物車 */
else
{
// 更新:添加到購物車
if (addto_cart_combo($goods->goods_id, $goods->number, $goods->spec, $goods->parent, $goods->group))
{
if ($_CFG['cart_confirm'] > 2)
{
$result['message'] = '';
}
else
{
$result['message'] = $_CFG['cart_confirm'] == 1 ? $_LANG['addto_cart_success_1'] : $_LANG['addto_cart_success_2'];
}
$result['group'] = $goods->group;
$result['goods_id'] = stripslashes($goods->goods_id);
$result['content'] = insert_cart_info();
$result['one_step_buy'] = $_CFG['one_step_buy'];
//返回 原價,配件價,庫存信息
$combo_goods_info = get_combo_goods_info($goods->goods_id, $goods->number, $goods->spec, $goods->parent);
$result['fittings_price'] = $combo_goods_info['fittings_price'];
$result['spec_price'] = $combo_goods_info['spec_price'];
$result['goods_price'] = $combo_goods_info['goods_price'];
$result['stock'] = $combo_goods_info['stock'];
$result['parent'] = $goods->parent;
}
else
{
$result['message'] = $err->last_message();
$result['error'] = $err->error_no;
$result['group'] = $goods->group;
$result['goods_id'] = stripslashes($goods->goods_id);
if (is_array($goods->spec))
{
$result['product_spec'] = implode(',', $goods->spec);
}
else
{
$result['product_spec'] = $goods->spec;
}
}
}
$result['confirm_type'] = !empty($_CFG['cart_confirm']) ? $_CFG['cart_confirm'] : 2;
die($json->encode($result));
}
elseif ($_REQUEST['step'] == 'del_in_cart_combo') //刪除購物車項目 by mike
{
include_once('includes/cls_json.php');
$_POST['goods']=strip_tags(urldecode($_POST['goods']));
$_POST['goods'] = json_str_iconv($_POST['goods']);
if (!empty($_REQUEST['goods_id']) && empty($_POST['goods']))
{
if (!is_numeric($_REQUEST['goods_id']) || intval($_REQUEST['goods_id']) <= 0)
{
ecs_header("Location:./\n");
}
$goods_id = intval($_REQUEST['goods_id']);
exit;
}
$result = array('error' => 0, 'message' => '');
$json = new JSON;
if (empty($_POST['goods']))
{
$result['error'] = 1;
die($json->encode($result));
}
$sql_where = $_SESSION['user_id']>0 ? "user_id='". $_SESSION['user_id'] ."' " : "session_id = '" . SESS_ID . "' AND user_id=0 ";//增加購物車選擇性結算--青蜂網絡www.0769web.net
$goods = $json->decode($_POST['goods']);
if($goods->parent == 0){
//更新臨時購物車(刪除基本件)
$sql = "DELETE FROM " . $GLOBALS['ecs']->table('cart_combo') . " WHERE $sql_where".
" AND goods_id = '" . $goods->goods_id . "' AND group_id = '" . $goods->group . "'";//修改購物車選擇性結算--青蜂網絡www.0769web.net
$GLOBALS['db']->query($sql);
//更新臨時購物車(刪除配件)
$sql = "DELETE FROM " . $GLOBALS['ecs']->table('cart_combo') . " WHERE $sql_where".
" AND parent_id = '".$goods->goods_id."' AND group_id = '" . $goods->group . "'";//修改購物車選擇性結算--青蜂網絡www.0769web.net
$GLOBALS['db']->query($sql);
}else{
//更新臨時購物車(刪除配件)
$sql = "DELETE FROM " . $GLOBALS['ecs']->table('cart_combo') . " WHERE $sql_where".
" AND goods_id = '" . $goods->goods_id . "' AND group_id = '" . $goods->group . "'";//修改購物車選擇性結算--青蜂網絡www.0769web.net
$GLOBALS['db']->query($sql);
}
$result['error'] = 0;
$result['group'] = substr($goods->group, 0, strrpos($goods->group, "_"));
$result['parent'] = $goods->parent;
die($json->encode($result));
}
elseif ($_REQUEST['step'] == 'add_to_cart_group') //套餐添加到購物車 by mike
{
include_once('includes/cls_json.php');
$_POST['goods'] = strip_tags(urldecode($_POST['goods']));
$_POST['goods'] = json_str_iconv($_POST['goods']);
$result = array('error' => 0, 'message' => '');
$json = new JSON;
if (empty($_POST['goods']))
{
$result['error'] = 1;
$result['message'] = '系統無法接收不完整的數據';
die($json->encode($result));
}
$goods = $json->decode($_POST['goods']);
$group = $goods->group ."_". $goods->goods_id;//套餐組
$sql_where = $_SESSION['user_id']>0 ? "user_id='". $_SESSION['user_id'] ."' " : "session_id = '" . SESS_ID . "' AND user_id=0 ";//增加購物車選擇性結算--青蜂網絡www.0769web.net
//批量加入購物車
$sql = "SELECT rec_id FROM " . $GLOBALS['ecs']->table('cart_combo') . " WHERE $sql_where" .//修改購物車選擇性結算--青蜂網絡www.0769web.net
" AND group_id = '". $group ."' ORDER BY parent_id limit 1";
$res = $GLOBALS['db']->getAll($sql);
// var_dump($res);//exit;
if($res){
//清空購物車中的原有數據
$sql = "DELETE FROM " . $GLOBALS['ecs']->table('cart') . " WHERE ".
" $sql_where AND group_id = '" . $group . "'";//修改購物車選擇性結算--青蜂網絡www.0769web.net
$GLOBALS['db']->query($sql);
//插入新的數據
$sql = "INSERT INTO " . $GLOBALS['ecs']->table('cart') . " SELECT * FROM " . $GLOBALS['ecs']->table('cart_combo') . " WHERE ".
" $sql_where AND group_id = '" . $group . "'";//修改購物車選擇性結算--青蜂網絡www.0769web.net
$GLOBALS['db']->query($sql);
//插入更新購物車商品數量
$sql = "UPDATE " . $GLOBALS['ecs']->table('cart') . " set goods_number = '$goods->number' WHERE ".
" $sql_where AND group_id = '" . $group . "'";//修改購物車選擇性結算--青蜂網絡www.0769web.net
$GLOBALS['db']->query($sql);
//清空套餐臨時數據
$sql = "DELETE FROM " . $GLOBALS['ecs']->table('cart_combo') . " WHERE ".
" $sql_where AND group_id = '" . $group . "'";//修改購物車選擇性結算--青蜂網絡www.0769web.net
$GLOBALS['db']->query($sql);
}else{
$result['error'] = 1;
//$result['message'] = '暫無數據可提交,請重新選擇';
$result['message'] = $goods->goods_id;
die($json->encode($result));
}
$result['error'] = 0;
die($json->encode($result));
}
elseif ($_REQUEST['step'] == 'link_buy')
{
$goods_id = intval($_GET['goods_id']);
if (!cart_goods_exists($goods_id,array()))
{
addto_cart($goods_id);
}
ecs_header("Location:./flow.php\n");
exit;
}
elseif ($_REQUEST['step'] == 'login')
{
if (!empty($_SESSION['user_id']))
{
ecs_header("Location:./flow.php\n");
}
include_once('languages/'. $_CFG['lang']. '/user.php');
/*
* 用户登錄註冊
*/
if ($_SERVER['REQUEST_METHOD'] == 'GET')
{
$smarty->assign('anonymous_buy', $_CFG['anonymous_buy']);
/* 檢查是否有贈品,如果有提示登錄後重新選擇贈品 */
$sql_where = $_SESSION['user_id']>0 ? "user_id='". $_SESSION['user_id'] ."' " : "session_id = '" . SESS_ID . "' AND user_id=0 ";//增加購物車選擇性結算--青蜂網絡www.0769web.net
$sql = "SELECT COUNT(*) FROM " . $ecs->table('cart') .
" WHERE $sql_where AND is_gift > 0";//修改購物車選擇性結算--青蜂網絡www.0769web.net
if ($db->getOne($sql) > 0)
{
$smarty->assign('need_rechoose_gift', 1);
}
/* 檢查是否需要註冊碼 */
$captcha = intval($_CFG['captcha']);
if (($captcha & CAPTCHA_LOGIN) && (!($captcha & CAPTCHA_LOGIN_FAIL) || (($captcha & CAPTCHA_LOGIN_FAIL) && $_SESSION['login_fail'] > 2)) && gd_version() > 0)
{
$smarty->assign('enabled_login_captcha', 1);
$smarty->assign('rand', mt_rand());
}
if ($captcha & CAPTCHA_REGISTER)
{
$smarty->assign('enabled_register_captcha', 1);
$smarty->assign('rand', mt_rand());
}
}
else
{
include_once('includes/lib_passport.php');
if (!empty($_POST['act']) && $_POST['act'] == 'signin')
{
$captcha = intval($_CFG['captcha']);
if (($captcha & CAPTCHA_LOGIN) && (!($captcha & CAPTCHA_LOGIN_FAIL) || (($captcha & CAPTCHA_LOGIN_FAIL) && $_SESSION['login_fail'] > 2)) && gd_version() > 0)
{
if (empty($_POST['captcha']))
{
show_message($_LANG['invalid_captcha']);
}
/* 檢查驗證碼 */
include_once('includes/cls_captcha.php');
$validator = new captcha();
$validator->session_word = 'captcha_login';
if (!$validator->check_word($_POST['captcha']))
{
show_message($_LANG['invalid_captcha']);
}
}
if ($user->login($_POST['username'], $_POST['password'],isset($_POST['remember'])))
{
update_user_info(); //更新用户信息
recalculate_price(); // 重新計算購物車中的商品價格
/* 檢查購物車中是否有商品 沒有商品則跳轉到首頁 */
$sql_where = $_SESSION['user_id']>0 ? "user_id='". $_SESSION['user_id'] ."' " : "session_id = '" . SESS_ID . "' AND user_id=0 ";//增加購物車選擇性結算--青蜂網絡www.0769web.net
$sql = "SELECT COUNT(*) FROM " . $ecs->table('cart') . " WHERE $sql_where ";//修改購物車選擇性結算--青蜂網絡www.0769web.net
if ($db->getOne($sql) > 0)
{
ecs_header("Location: flow.php?step=checkout\n");
}
else
{
ecs_header("Location:index.php\n");
}
exit;
}
else
{
$_SESSION['login_fail']++;
show_message($_LANG['signin_failed'], '', 'flow.php?step=login');
}
}
elseif (!empty($_POST['act']) && $_POST['act'] == 'signup')
{
if ((intval($_CFG['captcha']) & CAPTCHA_REGISTER) && gd_version() > 0)
{
if (empty($_POST['captcha']))
{
show_message($_LANG['invalid_captcha']);
}
/* 檢查驗證碼 */
include_once('includes/cls_captcha.php');
$validator = new captcha();
if (!$validator->check_word($_POST['captcha']))
{
show_message($_LANG['invalid_captcha']);
}
}
if (register(trim($_POST['username']), trim($_POST['password']), trim($_POST['email'])))
{
/* 用户註冊成功 */
ecs_header("Location: flow.php?step=consignee\n");
exit;
}
else
{
$err->show();
}
}
else
{
// TODO: 非法訪問的處理
}
}
}
elseif ($_REQUEST['step'] == 'consignee')
{
/*------------------------------------------------------ */
//-- 收貨人信息
/*------------------------------------------------------ */
include_once('includes/lib_transaction.php');
if ($_SERVER['REQUEST_METHOD'] == 'GET')
{
/* 取得購物類型 */
$flow_type = isset($_SESSION['flow_type']) ? intval($_SESSION['flow_type']) : CART_GENERAL_GOODS;
/*
* 收貨人信息填寫界面
*/
if (isset($_REQUEST['direct_shopping']))
{
$_SESSION['direct_shopping'] = 1;
}
/* 取得國家列表、商店所在國家、商店所在國家的省列表 */
$smarty->assign('country_list', get_regions());
$smarty->assign('shop_country', $_CFG['shop_country']);
$smarty->assign('shop_province_list', get_regions(1, $_CFG['shop_country']));
/* 獲得用户所有的收貨人信息 */
if ($_SESSION['user_id'] > 0)
{
$consignee_list = get_consignee_list($_SESSION['user_id']);
if (count($consignee_list) < 5)
{
/* 如果用户收貨人信息的總數小於 5 則增加一個新的收貨人信息 */
$consignee_list[] = array('country' => $_CFG['shop_country'], 'email' => isset($_SESSION['email']) ? $_SESSION['email'] : '');
}
}
else
{
if (isset($_SESSION['flow_consignee'])){
$consignee_list = array($_SESSION['flow_consignee']);
}
else
{
$consignee_list[] = array('country' => $_CFG['shop_country']);
}
}
$smarty->assign('name_of_region', array($_CFG['name_of_region_1'], $_CFG['name_of_region_2'], $_CFG['name_of_region_3'], $_CFG['name_of_region_4']));
$smarty->assign('consignee_list', $consignee_list);
/* 取得每個收貨地址的省市區列表 */
$province_list = array();
$city_list = array();
$district_list = array();
foreach ($consignee_list as $region_id => $consignee)
{
$consignee['country'] = isset($consignee['country']) ? intval($consignee['country']) : 0;
$consignee['province'] = isset($consignee['province']) ? intval($consignee['province']) : 0;
$consignee['city'] = isset($consignee['city']) ? intval($consignee['city']) : 0;
$province_list[$region_id] = get_regions(1, $consignee['country']);
$city_list[$region_id] = get_regions(2, $consignee['province']);
$district_list[$region_id] = get_regions(3, $consignee['city']);
}
$smarty->assign('province_list', $province_list);
$smarty->assign('city_list', $city_list);
$smarty->assign('district_list', $district_list);
/* 返回收貨人頁面代碼 */
$smarty->assign('real_goods_count', exist_real_goods(0, $flow_type) ? 1 : 0);
}
else
{
/*
* 保存收貨人信息
*/
$consignee = array(
'address_id' => empty($_POST['address_id']) ? 0 : intval($_POST['address_id']),
'consignee' => empty($_POST['consignee']) ? '' : compile_str(trim($_POST['consignee'])),
'country' => empty($_POST['country']) ? '' : intval($_POST['country']),
'province' => empty($_POST['province']) ? '' : intval($_POST['province']),
'city' => empty($_POST['city']) ? '' : intval($_POST['city']),
'district' => empty($_POST['district']) ? '' : intval($_POST['district']),
'email' => empty($_POST['email']) ? '' : compile_str($_POST['email']),
'address' => empty($_POST['address']) ? '' : compile_str($_POST['address']),
'zipcode' => empty($_POST['zipcode']) ? '' : compile_str(make_semiangle(trim($_POST['zipcode']))),
'tel' => empty($_POST['tel']) ? '' : compile_str(make_semiangle(trim($_POST['tel']))),
'mobile' => empty($_POST['mobile']) ? '' : compile_str(make_semiangle(trim($_POST['mobile']))),
'sign_building' => empty($_POST['sign_building']) ? '' :compile_str($_POST['sign_building']),
'best_time' => empty($_POST['best_time']) ? '' : compile_str($_POST['best_time']),
);
if ($_SESSION['user_id'] > 0)
{
include_once(ROOT_PATH . 'includes/lib_transaction.php');
/* 如果用户已經登錄,則保存收貨人信息 */
$consignee['user_id'] = $_SESSION['user_id'];
save_consignee($consignee, true);
}
/* 保存到session */
$_SESSION['flow_consignee'] = stripslashes_deep($consignee);
ecs_header("Location: flow.php?step=checkout\n");
exit;
}
}
elseif ($_REQUEST['step'] == 'drop_consignee')
{
/*------------------------------------------------------ */
//-- 刪除收貨人信息
/*------------------------------------------------------ */
include_once('includes/lib_transaction.php');
$consignee_id = intval($_GET['id']);
if (drop_consignee($consignee_id))
{
ecs_header("Location: flow.php?step=consignee\n");
exit;
}
else
{
show_message($_LANG['not_fount_consignee']);
}
}
elseif ($_REQUEST['step'] == 'checkout')
{
/*------------------------------------------------------ */
//-- 訂單確認
/*------------------------------------------------------ */
/* 取得購物類型 */
$flow_type = isset($_SESSION['flow_type']) ? intval($_SESSION['flow_type']) : CART_GENERAL_GOODS;
/* 團購標誌 */
if ($flow_type == CART_GROUP_BUY_GOODS)
{
$smarty->assign('is_group_buy', 1);
}
/* 積分兑換商品 */
elseif ($flow_type == CART_EXCHANGE_GOODS)
{
$smarty->assign('is_exchange_goods', 1);
}
else
{
//正常購物流程 清空其他購物流程情況
$_SESSION['flow_order']['extension_code'] = '';
}
if($flow_type != CART_GROUP_BUY_GOODS && $flow_type != CART_EXCHANGE_GOODS && $flow_type != CART_PRE_SALE_GOODS){
//非積分兑換 團購 預售形式的商品
$sel_cartgoods_count = count($_REQUEST['sel_cartgoods']);
$_SESSION['sel_cartgoods'] = $sel_cartgoods_count>0 ? (implode(",", $_REQUEST['sel_cartgoods'])) : $_SESSION['sel_cartgoods'];
//驗證購物車中提交過來的商品中參加的活動是否都正常start
$_REQUEST['sel_goods'] = $_SESSION['sel_cartgoods'];
if(empty($_REQUEST['sel_goods'])){
ecs_header("Location: flow.php");
exit;
}
$favourable_list = favourable_list($_SESSION['user_rank'],false);
if($favourable_list){
$sql_where = $_SESSION['user_id']>0 ? "user_id='". $_SESSION['user_id'] ."' " : "session_id = '" . SESS_ID . "' AND user_id=0 ";
foreach($favourable_list as $fk=>$fv){
if(!$fv['available']){
$sql = "select count(rec_id) as num from ". $ecs->table('cart') .
" WHERE $sql_where " .
"AND is_gift = ".$fv['act_id']." AND rec_id in (".$_REQUEST['sel_goods'].")";
if($db->getOne($sql) > 0){
show_message('購物車中參加['.$fv['act_name'].']活動的商品未滿足條件,請重新設置或者將其贈品刪除', '', '', 'warning');
}
}
}
unset($sql_where);
}
//驗證購物車中提交過來的商品中參加的活動是否都正常end
}
/* 檢查購物車中是否有商品 */
$sql_where = $_SESSION['user_id']>0 ? "user_id='". $_SESSION['user_id'] ."' " : "session_id = '" . SESS_ID . "' AND user_id=0 ";
$sql = "SELECT COUNT(*) FROM " . $ecs->table('cart') .
" WHERE $sql_where " .
"AND parent_id = 0 AND is_gift = 0 AND rec_type = '$flow_type'";
if ($db->getOne($sql) == 0)
{
show_message($_LANG['no_goods_in_cart'], '', '', 'warning');
}
/* 檢查商品總額是否達到最低限購金額 */
if ($flow_type == CART_GENERAL_GOODS && cart_amount(true, CART_GENERAL_GOODS) < $_CFG['min_goods_amount'])
{
show_message(sprintf($_LANG['goods_amount_not_enough'], price_format($_CFG['min_goods_amount'], false)));
}
/*
* 檢查用户是否已經登錄
* 如果用户已經登錄了則檢查是否有默認的收貨地址
* 如果沒有登錄則跳轉到登錄和註冊頁面
*/
if (isset($_REQUEST['direct_shopping']))
{
$_SESSION['direct_shopping'] = 1;
}
if (empty($_SESSION['direct_shopping']) && $_SESSION['user_id'] == 0)
{
/* 用户沒有登錄且沒有選定匿名購物,轉向到登錄頁面 */
ecs_header("Location: flow.php?step=login\n");
exit;
}
$consignee = get_consignee($_SESSION['user_id']);
/* 檢查收貨人信息是否完整 青蜂網絡開發簡化購物流程
if (!check_consignee_info($consignee, $flow_type))
{
ecs_header("Location: flow.php?step=consignee\n");
exit;
}*/
$_SESSION['flow_consignee'] = $consignee;
$smarty->assign('consignee', $consignee);
/* 代碼增加_start By www.0769web.net */
include_once('includes/lib_transaction.php');
if ($_SESSION['user_id'] > 0)
{
$sql="SELECT * FROM " . $GLOBALS['ecs']->table('user_address') .
" WHERE user_id = '". $_SESSION['user_id'] ."' order by address_id ";
$consignee_list_mb5 = $GLOBALS['db']->getAll($sql);
}else{
if ($_SESSION['flow_consignee']){
$consignee_list_mb5 = array($_SESSION['flow_consignee']);
}
}
foreach ($consignee_list_mb5 as $cons_key => $cons_val)
{
$consignee_list_mb5[$cons_key]['address_short_name'] = $cons_val['consignee']."<br>";
$consignee_list_mb5[$cons_key]['address_short_name'] .= get_region_info($cons_val['province'])."-";
$consignee_list_mb5[$cons_key]['address_short_name'] .= get_region_info($cons_val['city'])."-";
$consignee_list_mb5[$cons_key]['address_short_name'] .= get_region_info($cons_val['district'])."&nbsp;";
$consignee_list_mb5[$cons_key]['address_short_name'] .= sub_str($cons_val['address'],16);
$consignee_list_mb5[$cons_key]['address_short_name'] .= "<br>".$cons_val['mobile'];
if ($consignee['address_id'] == $cons_val['address_id'])
{
$consignee_list_mb5[$cons_key]['def_addr'] =1;
$have_def_addr=1;
}
}
if ( count($consignee_list_mb5) && !$have_def_addr){ $consignee_list_mb5[0]['def_addr'] =1; }
$smarty->assign('name_of_region', array($_CFG['name_of_region_1'], $_CFG['name_of_region_2'], $_CFG['name_of_region_3'], $_CFG['name_of_region_4']));
$smarty->assign('consignee_list', $consignee_list_mb5);
$smarty->assign('countryid', $_CFG['shop_country']);
$smarty->assign('province_list', get_regions(1, $_CFG['shop_country']));
$smarty->assign('real_goods_count', exist_real_goods(0, $flow_type) ? 1 : 0);
/* 代碼增加_end By www.0769web.net */
/* 對商品信息賦值 */
$cart_goods = cart_goods($flow_type); // 取得商品列表,計算合計
$smarty->assign('goods_list', $cart_goods);
/* 對是否允許修改購物車賦值 */
if ($flow_type != CART_GENERAL_GOODS || $_CFG['one_step_buy'] == '1')
{
$smarty->assign('allow_edit_cart', 0);
}
else
{
$smarty->assign('allow_edit_cart', 1);
}
/*
* 取得購物流程設置
*/
$smarty->assign('config', $_CFG);
/*
* 取得訂單信息
*/
$order = flow_order_info();
$smarty->assign('order', $order);
/* 計算折扣 */
if ($flow_type != CART_EXCHANGE_GOODS && $flow_type != CART_GROUP_BUY_GOODS)
{
$discount = compute_discount();
$smarty->assign('discount', $discount['discount']);
$favour_name = empty($discount['name']) ? '' : join(',', $discount['name']);
$smarty->assign('your_discount', sprintf($_LANG['your_discount'], $favour_name, price_format($discount['discount'])));
}
/*
* 計算訂單的費用
*/
$total = order_fee($order, $cart_goods, $consignee);
$smarty->assign('total', $total);
$smarty->assign('shopping_money', sprintf($_LANG['shopping_money'], $total['formated_goods_price']));
$smarty->assign('market_price_desc', sprintf($_LANG['than_market_price'], $total['formated_market_price'], $total['formated_saving'], $total['save_rate']));
/* 取得配送列表 */
$region = array($consignee['country'], $consignee['province'], $consignee['city'], $consignee['district']);
$shipping_list = available_shipping_list($region);
$cart_weight_price = cart_weight_price($flow_type);
$insure_disabled = true;
$cod_disabled = true;
// 查看購物車中是否全為免運費商品,若是則把運費賦為零
$sql_where = $_SESSION['user_id']>0 ? "user_id='". $_SESSION['user_id'] ."' " : "session_id = '" . SESS_ID . "' AND user_id=0 ";//增加購物車選擇性結算--青蜂網絡www.0769web.net
$sql = 'SELECT count(*) FROM ' . $ecs->table('cart') . " WHERE $sql_where AND `extension_code` != 'package_buy' AND `is_shipping` = 0";//修改購物車選擇性結算--青蜂網絡www.0769web.net
$shipping_count = $db->getOne($sql);
foreach ($shipping_list AS $key => $val)
{
$shipping_cfg = unserialize_config($val['configure']);
$shipping_fee = ($shipping_count == 0 AND $cart_weight_price['free_shipping'] == 1) ? 0 : shipping_fee($val['shipping_code'], unserialize($val['configure']),
$cart_weight_price['weight'], $cart_weight_price['amount'], $cart_weight_price['number']);
$shipping_list[$key]['format_shipping_fee'] = price_format($shipping_fee, false);
$shipping_list[$key]['shipping_fee'] = $shipping_fee;
$shipping_list[$key]['free_money'] = price_format($shipping_cfg['free_money'], false);
$shipping_list[$key]['insure_formated'] = strpos($val['insure'], '%') === false ?
price_format($val['insure'], false) : $val['insure'];
/* 當前的配送方式是否支持保價 */
if ($val['shipping_id'] == $order['shipping_id'])
{
$insure_disabled = ($val['insure'] == 0);
$cod_disabled = ($val['support_cod'] == 0);
}
}
$smarty->assign('shipping_list', $shipping_list);
$smarty->assign('insure_disabled', $insure_disabled);
$smarty->assign('cod_disabled', $cod_disabled);
/* 取得支付列表 */
if ($order['shipping_id'] == 0)
{
$cod = true;
$cod_fee = 0;
}
else
{
$shipping = shipping_info($order['shipping_id']);
$cod = $shipping['support_cod'];
if ($cod)
{
/* 如果是團購且保證金大於0不能使用貨到付款 */
if ($flow_type == CART_GROUP_BUY_GOODS)
{
$group_buy_id = $_SESSION['extension_id'];
if ($group_buy_id <= 0)
{
show_message('error group_buy_id');
}
$group_buy = group_buy_info($group_buy_id);
if (empty($group_buy))
{
show_message('group buy not exists: ' . $group_buy_id);
}
if ($group_buy['deposit'] > 0)
{
$cod = false;
$cod_fee = 0;
/* 賦值保證金 */
$smarty->assign('gb_deposit', $group_buy['deposit']);
}
}
if ($cod)
{
$shipping_area_info = shipping_area_info($order['shipping_id'], $region);
$cod_fee = $shipping_area_info['pay_fee'];
}
}
else
{
$cod_fee = 0;
}
}
// 給貨到付款的手續費加<span id>,以便改變配送的時候動態顯示
$payment_list = available_payment_list(1, $cod_fee);
if(isset($payment_list))
{
foreach ($payment_list as $key => $payment)
{
if ($payment['is_cod'] == '1')
{
$payment_list[$key]['format_pay_fee'] = '<span id="ECS_CODFEE">' . $payment['format_pay_fee'] . '</span>';
}
/* 如果有易寶神州行支付 如果訂單金額大於300 則不顯示 */
if ($payment['pay_code'] == 'yeepayszx' && $total['amount'] > 300)
{
unset($payment_list[$key]);
}
/* 如果有餘額支付 */
if ($payment['pay_code'] == 'balance')
{
/* 如果未登錄,不顯示 */
if ($_SESSION['user_id'] == 0)
{
unset($payment_list[$key]);
}
else
{
if ($_SESSION['flow_order']['pay_id'] == $payment['pay_id'])
{
$smarty->assign('disable_surplus', 1);
}
}
}
}
}
$smarty->assign('payment_list', $payment_list);
/* 取得包裝與賀卡 */
if ($total['real_goods_count'] > 0)
{
/* 只有有實體商品,才要判斷包裝和賀卡 */
if (!isset($_CFG['use_package']) || $_CFG['use_package'] == '1')
{
/* 如果使用包裝,取得包裝列表及用户選擇的包裝 */
$smarty->assign('pack_list', pack_list());
}
/* 如果使用賀卡,取得賀卡列表及用户選擇的賀卡 */
if (!isset($_CFG['use_card']) || $_CFG['use_card'] == '1')
{
$smarty->assign('card_list', card_list());
}
}
$user_info = user_info($_SESSION['user_id']);
/* 如果使用餘額,取得用户餘額 */
if ((!isset($_CFG['use_surplus']) || $_CFG['use_surplus'] == '1')
&& $_SESSION['user_id'] > 0
&& $user_info['user_money'] > 0)
{
// 能使用餘額
$smarty->assign('allow_use_surplus', 1);
$smarty->assign('your_surplus', $user_info['user_money']);
}
/* 如果使用積分,取得用户可用積分及本訂單最多可以使用的積分 */
if ((!isset($_CFG['use_integral']) || $_CFG['use_integral'] == '1')
&& $_SESSION['user_id'] > 0
&& $user_info['pay_points'] > 0
&& ($flow_type != CART_GROUP_BUY_GOODS && $flow_type != CART_EXCHANGE_GOODS))
{
// 能使用積分
$smarty->assign('allow_use_integral', 1);
$smarty->assign('order_max_integral', flow_available_points()); // 可用積分
$smarty->assign('your_integral', $user_info['pay_points']); // 用户積分
}
/* 如果使用紅包,取得用户可以使用的紅包及用户選擇的紅包 */
if ((!isset($_CFG['use_bonus']) || $_CFG['use_bonus'] == '1')
&& ($flow_type != CART_GROUP_BUY_GOODS && $flow_type != CART_EXCHANGE_GOODS))
{
// 取得用户可用紅包
$user_bonus = user_bonus($_SESSION['user_id'], $total['goods_price']);
if (!empty($user_bonus))
{
foreach ($user_bonus AS $key => $val)
{
$user_bonus[$key]['bonus_money_formated'] = price_format($val['type_money'], false);
}
$smarty->assign('bonus_list', $user_bonus);
}
// 能使用紅包
$smarty->assign('allow_use_bonus', 1);
}
/* 如果使用缺貨處理,取得缺貨處理列表 */
if (!isset($_CFG['use_how_oos']) || $_CFG['use_how_oos'] == '1')
{
if (is_array($GLOBALS['_LANG']['oos']) && !empty($GLOBALS['_LANG']['oos']))
{
$smarty->assign('how_oos_list', $GLOBALS['_LANG']['oos']);
}
}
/* 如果能開發票,取得發票內容列表 */
if ((!isset($_CFG['can_invoice']) || $_CFG['can_invoice'] == '1')
&& isset($_CFG['invoice_content'])
&& trim($_CFG['invoice_content']) != '' && $flow_type != CART_EXCHANGE_GOODS)
{
$inv_content_list = explode("\n", str_replace("\r", '', $_CFG['invoice_content']));
$smarty->assign('inv_content_list', $inv_content_list);
$inv_type_list = array();
foreach ($_CFG['invoice_type']['type'] as $key => $type)
{
if (!empty($type))
{
$inv_type_list[$type] = $type . ' [' . floatval($_CFG['invoice_type']['rate'][$key]) . '%]';
}
}
$smarty->assign('inv_type_list', $inv_type_list);
}
/* 保存 session */
$_SESSION['flow_order'] = $order;
}
elseif ($_REQUEST['step'] == 'select_shipping')
{
/*------------------------------------------------------ */
//-- 改變配送方式
/*------------------------------------------------------ */
include_once('includes/cls_json.php');
$json = new JSON;
$result = array('error' => '', 'content' => '', 'need_insure' => 0);
/* 取得購物類型 */
$flow_type = isset($_SESSION['flow_type']) ? intval($_SESSION['flow_type']) : CART_GENERAL_GOODS;
/* 獲得收貨人信息 */
$consignee = get_consignee($_SESSION['user_id']);
/* 對商品信息賦值 */
$cart_goods = cart_goods($flow_type); // 取得商品列表,計算合計
if (empty($cart_goods))
{
$result['error'] = $_LANG['no_goods_in_cart'];
}
else
{
/* 取得購物流程設置 */
$smarty->assign('config', $_CFG);
/* 取得訂單信息 */
$order = flow_order_info();
$order['shipping_id'] = intval($_REQUEST['shipping']);
$regions = array($consignee['country'], $consignee['province'], $consignee['city'], $consignee['district']);
$shipping_info = shipping_area_info($order['shipping_id'], $regions);
/* 計算訂單的費用 */
$total = order_fee($order, $cart_goods, $consignee);
$smarty->assign('total', $total);
/* 取得可以得到的積分和紅包 */
$smarty->assign('total_integral', cart_amount(false, $flow_type) - $total['bonus'] - $total['integral_money']);
$smarty->assign('total_bonus', price_format(get_total_bonus(), false));
/* 團購標誌 */
if ($flow_type == CART_GROUP_BUY_GOODS)
{
$smarty->assign('is_group_buy', 1);
}
$result['cod_fee'] = $shipping_info['pay_fee'];
if (strpos($result['cod_fee'], '%') === false)
{
$result['cod_fee'] = price_format($result['cod_fee'], false);
}
$result['need_insure'] = ($shipping_info['insure'] > 0 && !empty($order['need_insure'])) ? 1 : 0;
$result['content'] = $smarty->fetch('library/order_total.lbi');
}
echo $json->encode($result);
exit;
}
elseif ($_REQUEST['step'] == 'select_insure')
{
/*------------------------------------------------------ */
//-- 選定/取消配送的保價
/*------------------------------------------------------ */
include_once('includes/cls_json.php');
$json = new JSON;
$result = array('error' => '', 'content' => '', 'need_insure' => 0);
/* 取得購物類型 */
$flow_type = isset($_SESSION['flow_type']) ? intval($_SESSION['flow_type']) : CART_GENERAL_GOODS;
/* 獲得收貨人信息 */
$consignee = get_consignee($_SESSION['user_id']);
/* 對商品信息賦值 */
$cart_goods = cart_goods($flow_type); // 取得商品列表,計算合計
if (empty($cart_goods))
{
$result['error'] = $_LANG['no_goods_in_cart'];
}
else
{
/* 取得購物流程設置 */
$smarty->assign('config', $_CFG);
/* 取得訂單信息 */
$order = flow_order_info();
$order['need_insure'] = intval($_REQUEST['insure']);
/* 保存 session */
$_SESSION['flow_order'] = $order;
/* 計算訂單的費用 */
$total = order_fee($order, $cart_goods, $consignee);
$smarty->assign('total', $total);
/* 取得可以得到的積分和紅包 */
$smarty->assign('total_integral', cart_amount(false, $flow_type) - $total['bonus'] - $total['integral_money']);
$smarty->assign('total_bonus', price_format(get_total_bonus(), false));
/* 團購標誌 */
if ($flow_type == CART_GROUP_BUY_GOODS)
{
$smarty->assign('is_group_buy', 1);
}
$result['content'] = $smarty->fetch('library/order_total.lbi');
}
echo $json->encode($result);
exit;
}
elseif ($_REQUEST['step'] == 'select_payment')
{
/*------------------------------------------------------ */
//-- 改變支付方式
/*------------------------------------------------------ */
include_once('includes/cls_json.php');
$json = new JSON;
$result = array('error' => '', 'content' => '', 'need_insure' => 0, 'payment' => 1);
/* 取得購物類型 */
$flow_type = isset($_SESSION['flow_type']) ? intval($_SESSION['flow_type']) : CART_GENERAL_GOODS;
/* 獲得收貨人信息 */
$consignee = get_consignee($_SESSION['user_id']);
/* 對商品信息賦值 */
$cart_goods = cart_goods($flow_type); // 取得商品列表,計算合計
if (empty($cart_goods))
{
$result['error'] = $_LANG['no_goods_in_cart'];
}
else
{
/* 取得購物流程設置 */
$smarty->assign('config', $_CFG);
/* 取得訂單信息 */
$order = flow_order_info();
$order['pay_id'] = intval($_REQUEST['payment']);
$payment_info = payment_info($order['pay_id']);
$result['pay_code'] = $payment_info['pay_code'];
/* 保存 session */
$_SESSION['flow_order'] = $order;
/* 計算訂單的費用 */
$total = order_fee($order, $cart_goods, $consignee);
$smarty->assign('total', $total);
/* 取得可以得到的積分和紅包 */
$smarty->assign('total_integral', cart_amount(false, $flow_type) - $total['bonus'] - $total['integral_money']);
$smarty->assign('total_bonus', price_format(get_total_bonus(), false));
/* 團購標誌 */
if ($flow_type == CART_GROUP_BUY_GOODS)
{
$smarty->assign('is_group_buy', 1);
}
$result['content'] = $smarty->fetch('library/order_total.lbi');
}
echo $json->encode($result);
exit;
}
elseif ($_REQUEST['step'] == 'select_pack')
{
/*------------------------------------------------------ */
//-- 改變商品包裝
/*------------------------------------------------------ */
include_once('includes/cls_json.php');
$json = new JSON;
$result = array('error' => '', 'content' => '', 'need_insure' => 0);
/* 取得購物類型 */
$flow_type = isset($_SESSION['flow_type']) ? intval($_SESSION['flow_type']) : CART_GENERAL_GOODS;
/* 獲得收貨人信息 */
$consignee = get_consignee($_SESSION['user_id']);
/* 對商品信息賦值 */
$cart_goods = cart_goods($flow_type); // 取得商品列表,計算合計
if (empty($cart_goods))
{
$result['error'] = $_LANG['no_goods_in_cart'];
}
else
{
/* 取得購物流程設置 */
$smarty->assign('config', $_CFG);
/* 取得訂單信息 */
$order = flow_order_info();
$order['pack_id'] = intval($_REQUEST['pack']);
/* 保存 session */
$_SESSION['flow_order'] = $order;
/* 計算訂單的費用 */
$total = order_fee($order, $cart_goods, $consignee);
$smarty->assign('total', $total);
/* 取得可以得到的積分和紅包 */
$smarty->assign('total_integral', cart_amount(false, $flow_type) - $total['bonus'] - $total['integral_money']);
$smarty->assign('total_bonus', price_format(get_total_bonus(), false));
/* 團購標誌 */
if ($flow_type == CART_GROUP_BUY_GOODS)
{
$smarty->assign('is_group_buy', 1);
}
$result['content'] = $smarty->fetch('library/order_total.lbi');
}
echo $json->encode($result);
exit;
}
elseif ($_REQUEST['step'] == 'select_card')
{
/*------------------------------------------------------ */
//-- 改變賀卡
/*------------------------------------------------------ */
include_once('includes/cls_json.php');
$json = new JSON;
$result = array('error' => '', 'content' => '', 'need_insure' => 0);
/* 取得購物類型 */
$flow_type = isset($_SESSION['flow_type']) ? intval($_SESSION['flow_type']) : CART_GENERAL_GOODS;
/* 獲得收貨人信息 */
$consignee = get_consignee($_SESSION['user_id']);
/* 對商品信息賦值 */
$cart_goods = cart_goods($flow_type); // 取得商品列表,計算合計
if (empty($cart_goods))
{
$result['error'] = $_LANG['no_goods_in_cart'];
}
else
{
/* 取得購物流程設置 */
$smarty->assign('config', $_CFG);
/* 取得訂單信息 */
$order = flow_order_info();
$order['card_id'] = intval($_REQUEST['card']);
/* 保存 session */
$_SESSION['flow_order'] = $order;
/* 計算訂單的費用 */
$total = order_fee($order, $cart_goods, $consignee);
$smarty->assign('total', $total);
/* 取得可以得到的積分和紅包 */
$smarty->assign('total_integral', cart_amount(false, $flow_type) - $order['bonus'] - $total['integral_money']);
$smarty->assign('total_bonus', price_format(get_total_bonus(), false));
/* 團購標誌 */
if ($flow_type == CART_GROUP_BUY_GOODS)
{
$smarty->assign('is_group_buy', 1);
}
$result['content'] = $smarty->fetch('library/order_total.lbi');
}
echo $json->encode($result);
exit;
}
elseif ($_REQUEST['step'] == 'change_surplus')
{
/*------------------------------------------------------ */
//-- 改變餘額
/*------------------------------------------------------ */
include_once('includes/cls_json.php');
$surplus = floatval($_GET['surplus']);
$user_info = user_info($_SESSION['user_id']);
if ($user_info['user_money'] + $user_info['credit_line'] < $surplus)
{
$result['error'] = $_LANG['surplus_not_enough'];
}
else
{
/* 取得購物類型 */
$flow_type = isset($_SESSION['flow_type']) ? intval($_SESSION['flow_type']) : CART_GENERAL_GOODS;
/* 取得購物流程設置 */
$smarty->assign('config', $_CFG);
/* 獲得收貨人信息 */
$consignee = get_consignee($_SESSION['user_id']);
/* 對商品信息賦值 */
$cart_goods = cart_goods($flow_type); // 取得商品列表,計算合計
if (empty($cart_goods))
{
$result['error'] = $_LANG['no_goods_in_cart'];
}
else
{
/* 取得訂單信息 */
$order = flow_order_info();
$order['surplus'] = $surplus;
/* 計算訂單的費用 */
$total = order_fee($order, $cart_goods, $consignee);
$smarty->assign('total', $total);
/* 團購標誌 */
if ($flow_type == CART_GROUP_BUY_GOODS)
{
$smarty->assign('is_group_buy', 1);
}
$result['content'] = $smarty->fetch('library/order_total.lbi');
}
}
$json = new JSON();
die($json->encode($result));
}
elseif ($_REQUEST['step'] == 'change_integral')
{
/*------------------------------------------------------ */
//-- 改變積分
/*------------------------------------------------------ */
include_once('includes/cls_json.php');
$points = floatval($_GET['points']);
$user_info = user_info($_SESSION['user_id']);
/* 取得訂單信息 */
$order = flow_order_info();
$flow_points = flow_available_points(); // 該訂單允許使用的積分
$user_points = $user_info['pay_points']; // 用户的積分總數
if ($points > $user_points)
{
$result['error'] = $_LANG['integral_not_enough'];
}
elseif ($points > $flow_points)
{
$result['error'] = sprintf($_LANG['integral_too_much'], $flow_points);
}
else
{
/* 取得購物類型 */
$flow_type = isset($_SESSION['flow_type']) ? intval($_SESSION['flow_type']) : CART_GENERAL_GOODS;
$order['integral'] = $points;
/* 獲得收貨人信息 */
$consignee = get_consignee($_SESSION['user_id']);
/* 對商品信息賦值 */
$cart_goods = cart_goods($flow_type); // 取得商品列表,計算合計
if (empty($cart_goods))
{
$result['error'] = $_LANG['no_goods_in_cart'];
}
else
{
/* 計算訂單的費用 */
$total = order_fee($order, $cart_goods, $consignee);
$smarty->assign('total', $total);
$smarty->assign('config', $_CFG);
/* 團購標誌 */
if ($flow_type == CART_GROUP_BUY_GOODS)
{
$smarty->assign('is_group_buy', 1);
}
$result['content'] = $smarty->fetch('library/order_total.lbi');
$result['error'] = '';
}
}
$json = new JSON();
die($json->encode($result));
}
elseif ($_REQUEST['step'] == 'change_bonus')
{
/*------------------------------------------------------ */
//-- 改變紅包
/*------------------------------------------------------ */
include_once('includes/cls_json.php');
$result = array('error' => '', 'content' => '');
/* 取得購物類型 */
$flow_type = isset($_SESSION['flow_type']) ? intval($_SESSION['flow_type']) : CART_GENERAL_GOODS;
/* 獲得收貨人信息 */
$consignee = get_consignee($_SESSION['user_id']);
/* 對商品信息賦值 */
$cart_goods = cart_goods($flow_type); // 取得商品列表,計算合計
if (empty($cart_goods))
{
$result['error'] = $_LANG['no_goods_in_cart'];
}
else
{
/* 取得購物流程設置 */
$smarty->assign('config', $_CFG);
/* 取得訂單信息 */
$order = flow_order_info();
$bonus = bonus_info(intval($_GET['bonus']));
if ((!empty($bonus) && $bonus['user_id'] == $_SESSION['user_id']) || $_GET['bonus'] == 0)
{
$order['bonus_id'] = intval($_GET['bonus']);
}
else
{
$order['bonus_id'] = 0;
$result['error'] = $_LANG['invalid_bonus'];
}
/* 計算訂單的費用 */
$total = order_fee($order, $cart_goods, $consignee);
$smarty->assign('total', $total);
/* 團購標誌 */
if ($flow_type == CART_GROUP_BUY_GOODS)
{
$smarty->assign('is_group_buy', 1);
}
$result['content'] = $smarty->fetch('library/order_total.lbi');
}
$json = new JSON();
die($json->encode($result));
}
elseif ($_REQUEST['step'] == 'change_needinv')
{
/*------------------------------------------------------ */
//-- 改變發票的設置
/*------------------------------------------------------ */
include_once('includes/cls_json.php');
$result = array('error' => '', 'content' => '');
$json = new JSON();
$_GET['inv_type'] = !empty($_GET['inv_type']) ? json_str_iconv(urldecode($_GET['inv_type'])) : '';
$_GET['invPayee'] = !empty($_GET['invPayee']) ? json_str_iconv(urldecode($_GET['invPayee'])) : '';
$_GET['inv_content'] = !empty($_GET['inv_content']) ? json_str_iconv(urldecode($_GET['inv_content'])) : '';
/* 取得購物類型 */
$flow_type = isset($_SESSION['flow_type']) ? intval($_SESSION['flow_type']) : CART_GENERAL_GOODS;
/* 獲得收貨人信息 */
$consignee = get_consignee($_SESSION['user_id']);
/* 對商品信息賦值 */
$cart_goods = cart_goods($flow_type); // 取得商品列表,計算合計
if (empty($cart_goods))
{
$result['error'] = $_LANG['no_goods_in_cart'];
die($json->encode($result));
}
else
{
/* 取得購物流程設置 */
$smarty->assign('config', $_CFG);
/* 取得訂單信息 */
$order = flow_order_info();
if (isset($_GET['need_inv']) && intval($_GET['need_inv']) == 1)
{
$order['need_inv'] = 1;
$order['inv_type'] = trim(stripslashes($_GET['inv_type']));
$order['inv_payee'] = trim(stripslashes($_GET['inv_payee']));
$order['inv_content'] = trim(stripslashes($_GET['inv_content']));
}
else
{
$order['need_inv'] = 0;
$order['inv_type'] = '';
$order['inv_payee'] = '';
$order['inv_content'] = '';
}
/* 計算訂單的費用 */
$total = order_fee($order, $cart_goods, $consignee);
$smarty->assign('total', $total);
/* 團購標誌 */
if ($flow_type == CART_GROUP_BUY_GOODS)
{
$smarty->assign('is_group_buy', 1);
}
die($smarty->fetch('library/order_total.lbi'));
}
}
elseif ($_REQUEST['step'] == 'change_oos')
{
/*------------------------------------------------------ */
//-- 改變缺貨處理時的方式
/*------------------------------------------------------ */
/* 取得訂單信息 */
$order = flow_order_info();
$order['how_oos'] = intval($_GET['oos']);
/* 保存 session */
$_SESSION['flow_order'] = $order;
}
elseif ($_REQUEST['step'] == 'check_surplus')
{
/*------------------------------------------------------ */
//-- 檢查用户輸入的餘額
/*------------------------------------------------------ */
$surplus = floatval($_GET['surplus']);
$user_info = user_info($_SESSION['user_id']);
if (($user_info['user_money'] + $user_info['credit_line'] < $surplus))
{
die($_LANG['surplus_not_enough']);
}
exit;
}
elseif ($_REQUEST['step'] == 'check_integral')
{
/*------------------------------------------------------ */
//-- 檢查用户輸入的餘額
/*------------------------------------------------------ */
$points = floatval($_GET['integral']);
$user_info = user_info($_SESSION['user_id']);
$flow_points = flow_available_points(); // 該訂單允許使用的積分
$user_points = $user_info['pay_points']; // 用户的積分總數
if ($points > $user_points)
{
die($_LANG['integral_not_enough']);
}
if ($points > $flow_points)
{
die(sprintf($_LANG['integral_too_much'], $flow_points));
}
exit;
}
/*------------------------------------------------------ */
//-- 完成所有訂單操作,提交到數據庫
/*------------------------------------------------------ */
elseif ($_REQUEST['step'] == 'done')
{
include_once('includes/lib_clips.php');
include_once('includes/lib_payment.php');
/* 選擇性購物車商品*/
$id_ext ="";
if ($_SESSION['sel_cartgoods'])
{
$id_ext = " AND rec_id in (". $_SESSION['sel_cartgoods'] .") ";
}
/* 取得購物類型 團購,一般...*/
$flow_type = isset($_SESSION['flow_type']) ? intval($_SESSION['flow_type']) : CART_GENERAL_GOODS;
$sql_where = $_SESSION['user_id']>0 ? "user_id='". $_SESSION['user_id'] ."' " : "session_id = '" . SESS_ID . "' AND user_id=0 ";
$sql_where .= $id_ext;
/* 檢查購物車中是否有商品 */
$sql = "SELECT COUNT(*) FROM " . $ecs->table('cart') .
" WHERE $sql_where " .//增加購物車選擇性結算
"AND parent_id = 0 AND is_gift = 0 AND rec_type = '$flow_type'";
if ($db->getOne($sql) == 0)
{
show_message($_LANG['no_goods_in_cart'], '', '', 'warning');
}
/* 檢查商品庫存 */
/* 如果使用庫存,且下訂單時減庫存,則減少庫存 */
if ($_CFG['use_storage'] == '1' && $_CFG['stock_dec_time'] == SDT_PLACE)
{
//$cart_goods_stock = get_cart_goods();
$cart_goods_stock = get_cart_goods($id_ext);
$_cart_goods_stock = array();
foreach ($cart_goods_stock['goods_list'] as $value)
{
$_cart_goods_stock[$value['rec_id']] = $value['goods_number'];
}
flow_cart_stock($_cart_goods_stock);
unset($cart_goods_stock, $_cart_goods_stock);
}
/*
* 檢查用户是否已經登錄
* 如果用户已經登錄了則檢查是否有默認的收貨地址
* 如果沒有登錄則跳轉到登錄和註冊頁面
*/
if (empty($_SESSION['direct_shopping']) && $_SESSION['user_id'] == 0)
{
/* 用户沒有登錄且沒有選定匿名購物,轉向到登錄頁面 */
ecs_header("Location: flow.php?step=login\n");
exit;
}
$consignee = get_consignee($_SESSION['user_id']);
/* 檢查收貨人信息是否完整 */
if (!check_consignee_info($consignee, $flow_type))
{
/* 如果不完整則轉向到收貨人信息填寫界面 */
ecs_header("Location: flow.php?step=checkout&direct_shopping=1\n");
exit;
}
$_POST['how_oos'] = isset($_POST['how_oos']) ? intval($_POST['how_oos']) : 0;
$_POST['card_message'] = isset($_POST['card_message']) ? compile_str($_POST['card_message']) : '';
$_POST['inv_type'] = !empty($_POST['inv_type']) ? compile_str($_POST['inv_type']) : '';
$_POST['inv_payee'] = isset($_POST['inv_payee']) ? compile_str($_POST['inv_payee']) : '';
$_POST['inv_content'] = isset($_POST['inv_content']) ? compile_str($_POST['inv_content']) : '';
$_POST['postscript'] = isset($_POST['postscript']) ? compile_str($_POST['postscript']) : '';
$order = array(
'shipping_id' => intval($_POST['shipping']),
'pay_id' => intval($_POST['payment']),
'pack_id' => isset($_POST['pack']) ? intval($_POST['pack']) : 0,
'card_id' => isset($_POST['card']) ? intval($_POST['card']) : 0,
'card_message' => trim($_POST['card_message']),
'surplus' => isset($_POST['surplus']) ? floatval($_POST['surplus']) : 0.00,
'integral' => isset($_POST['integral']) ? intval($_POST['integral']) : 0,
'bonus_id' => isset($_POST['bonus']) ? intval($_POST['bonus']) : 0,
'need_inv' => empty($_POST['need_inv']) ? 0 : 1,
'inv_type' => $_POST['inv_type'],
'inv_payee' => trim($_POST['inv_payee']),
'inv_content' => $_POST['inv_content'],
'postscript' => trim($_POST['postscript']),
'how_oos' => isset($_LANG['oos'][$_POST['how_oos']]) ? addslashes($_LANG['oos'][$_POST['how_oos']]) : '',
'need_insure' => isset($_POST['need_insure']) ? intval($_POST['need_insure']) : 0,
'user_id' => $_SESSION['user_id'],
'add_time' => gmtime(),
'order_status' => OS_UNCONFIRMED,
'shipping_status' => SS_UNSHIPPED,
'pay_status' => PS_UNPAYED,
'agency_id' => get_agency_by_regions(array($consignee['country'], $consignee['province'], $consignee['city'], $consignee['district']))
);
/* 擴展信息 */
if (isset($_SESSION['flow_type']) && intval($_SESSION['flow_type']) != CART_GENERAL_GOODS)
{
$order['extension_code'] = $_SESSION['extension_code'];
$order['extension_id'] = $_SESSION['extension_id'];
}
else
{
$order['extension_code'] = '';
$order['extension_id'] = 0;
}
/* 檢查積分餘額是否合法 */
$user_id = $_SESSION['user_id'];
if ($user_id > 0)
{
$user_info = user_info($user_id);
$order['surplus'] = min($order['surplus'], $user_info['user_money'] + $user_info['credit_line']);
if ($order['surplus'] < 0)
{
$order['surplus'] = 0;
}
// 查詢用户有多少積分
$flow_points = flow_available_points(); // 該訂單允許使用的積分
$user_points = $user_info['pay_points']; // 用户的積分總數
$order['integral'] = min($order['integral'], $user_points, $flow_points);
if ($order['integral'] < 0)
{
$order['integral'] = 0;
}
}
else
{
$order['surplus'] = 0;
$order['integral'] = 0;
}
/* 檢查紅包是否存在 */
if ($order['bonus_id'] > 0)
{
$bonus = bonus_info($order['bonus_id']);
if (empty($bonus) || $bonus['user_id'] != $user_id || $bonus['order_id'] > 0 || $bonus['min_goods_amount'] > cart_amount(true, $flow_type))
{
$order['bonus_id'] = 0;
}
}
elseif (isset($_POST['bonus_sn']))
{
$bonus_sn = trim($_POST['bonus_sn']);
$bonus = bonus_info(0, $bonus_sn);
$now = gmtime();
if (empty($bonus) || $bonus['user_id'] > 0 || $bonus['order_id'] > 0 || $bonus['min_goods_amount'] > cart_amount(true, $flow_type) || $now > $bonus['use_end_date'])
{
}
else
{
if ($user_id > 0)
{
$sql = "UPDATE " . $ecs->table('user_bonus') . " SET user_id = '$user_id' WHERE bonus_id = '$bonus[bonus_id]' LIMIT 1";
$db->query($sql);
}
$order['bonus_id'] = $bonus['bonus_id'];
$order['bonus_sn'] = $bonus_sn;
}
}
/* 訂單中的商品 */
$cart_goods = cart_goods($flow_type);
if (empty($cart_goods))
{
show_message($_LANG['no_goods_in_cart'], $_LANG['back_home'], './', 'warning');
}
/* 檢查商品總額是否達到最低限購金額 */
if ($flow_type == CART_GENERAL_GOODS && cart_amount(true, CART_GENERAL_GOODS) < $_CFG['min_goods_amount'])
{
show_message(sprintf($_LANG['goods_amount_not_enough'], price_format($_CFG['min_goods_amount'], false)));
}
/* 收貨人信息 */
foreach ($consignee as $key => $value)
{
$order[$key] = addslashes($value);
}
/* 判斷是不是實體商品 */
foreach ($cart_goods AS $val)
{
/* 統計實體商品的個數 */
if ($val['is_real'])
{
$is_real_good=1;
}
}
// if(isset($is_real_good))
// {
// $sql="SELECT shipping_id FROM " . $ecs->table('shipping') . " WHERE shipping_id=".$order['shipping_id'] ." AND enabled =1";
// if(!$db->getOne($sql))
// {
// show_message($_LANG['flow_no_shipping']);
// }
// }
/* 訂單中的總額 */
$total = order_fee($order, $cart_goods, $consignee);
$order['bonus'] = $total['bonus'];
$order['goods_amount'] = $total['goods_price'];
$order['fencheng'] = $total['fencheng'];
$order['discount'] = $total['discount'];
$order['surplus'] = $total['surplus'];
$order['tax'] = $total['tax'];
// 購物車中的商品能享受紅包支付的總額
$discount_amout = compute_discount_amount();
// 紅包和積分最多能支付的金額為商品總額
$temp_amout = $order['goods_amount'] - $discount_amout;
if ($temp_amout <= 0)
{
$order['bonus_id'] = 0;
}
/* 配送方式 */
// if ($order['shipping_id'] > 0)
// {
// $shipping = shipping_info($order['shipping_id']);
// $order['shipping_name'] = addslashes($shipping['shipping_name']);
// }
// $order['shipping_fee'] = $total['shipping_fee'];
// $order['insure_fee'] = $total['shipping_insure'];
/* 支付方式 */
if ($order['pay_id'] > 0)
{
$payment = payment_info($order['pay_id']);
$order['pay_name'] = addslashes($payment['pay_name']);
}
$order['pay_fee'] = $total['pay_fee'];
$order['cod_fee'] = $total['cod_fee'];
/* 商品包裝 */
if ($order['pack_id'] > 0)
{
$pack = pack_info($order['pack_id']);
$order['pack_name'] = addslashes($pack['pack_name']);
}
$order['pack_fee'] = $total['pack_fee'];
/* 祝福賀卡 */
if ($order['card_id'] > 0)
{
$card = card_info($order['card_id']);
$order['card_name'] = addslashes($card['card_name']);
}
$order['card_fee'] = $total['card_fee'];
$order['order_amount'] = number_format($total['amount'], 2, '.', '');
$send = false;
/* 如果全部使用餘額支付,檢查餘額是否足夠 */
if ($payment['pay_code'] == 'balance' && $order['order_amount'] > 0)
{
if($order['surplus'] >0) //餘額支付裏如果輸入了一個金額
{
$order['order_amount'] = $order['order_amount'] + $order['surplus'];
$order['surplus'] = 0;
}
if ($order['order_amount'] > ($user_info['user_money'] + $user_info['credit_line']))
{
show_message($_LANG['balance_not_enough']);
}
else
{
$send = true;
$order['surplus'] = $order['order_amount'];
$order['order_amount'] = 0;
}
}
/* 如果訂單金額為0使用餘額或積分或紅包支付修改訂單狀態為已確認、已付款 */
if ($order['order_amount'] <= 0)
{
$order['order_status'] = OS_CONFIRMED;
$order['confirm_time'] = gmtime();
$order['pay_status'] = PS_PAYED;
$order['pay_time'] = gmtime();
$order['order_amount'] = 0;
}
$order['integral_money'] = $total['integral_money'];
$order['integral'] = $total['integral'];
if ($order['extension_code'] == 'exchange_goods')
{
$order['integral_money'] = 0;
$order['integral'] = $total['exchange_integral'];
}
$order['from_ad'] = !empty($_SESSION['from_ad']) ? $_SESSION['from_ad'] : '0';
$order['referer'] = !empty($_SESSION['referer']) ? addslashes($_SESSION['referer']) : '';
/* 記錄擴展信息 */
if ($flow_type != CART_GENERAL_GOODS)
{
$order['extension_code'] = $_SESSION['extension_code'];
$order['extension_id'] = $_SESSION['extension_id'];
}
/* 分成 */
$affiliate = json_decode($_CFG['affiliate'],true);
if(isset($affiliate['on']) && $affiliate['on'] == 1 && $affiliate['config']['separate_by'] == 1)
{
//推薦訂單分成
$parent_id = get_affiliate();
if($user_id == $parent_id)
{
$parent_id = 0;
}
}
elseif(isset($affiliate['on']) && $affiliate['on'] == 1 && $affiliate['config']['separate_by'] == 0)
{
//推薦註冊分成
$parent_id = 0;
}
else
{
//分成功能關閉
$parent_id = 0;
}
$order['parent_id'] = $parent_id;
/* 插入訂單表 */
$error_no = 0;
do
{
$order['order_sn'] = get_order_sn(); //獲取新訂單號
$GLOBALS['db']->autoExecute($GLOBALS['ecs']->table('order_info'), $order, 'INSERT');
$error_no = $GLOBALS['db']->errno();
if ($error_no > 0 && $error_no != 1062)
{
die($GLOBALS['db']->errorMsg());
}
}
while ($error_no == 1062); //如果是訂單號重複則重新提交數據
$new_order_id = $db->insert_id();
$order['order_id'] = $new_order_id;
/* 插入訂單商品 */
$sql = "INSERT INTO " . $ecs->table('order_goods') . "( " .
"order_id, goods_id, goods_name, goods_sn, product_id, goods_number, market_price, ".
"goods_price, goods_attr, is_real, extension_code, parent_id, is_gift, goods_attr_id) ".
" SELECT '$new_order_id', goods_id, goods_name, goods_sn, product_id, goods_number, market_price, ".
"goods_price, goods_attr, is_real, extension_code, parent_id, is_gift, goods_attr_id".
" FROM " .$ecs->table('cart') .
//" WHERE session_id = '".SESS_ID."' AND rec_type = '$flow_type'";//青蜂網絡購物車選擇性結算註釋
" WHERE $sql_where AND rec_type = '$flow_type'";
$db->query($sql);
/* 修改拍賣活動狀態 */
if ($order['extension_code']=='auction')
{
$sql = "UPDATE ". $ecs->table('goods_activity') ." SET is_finished='2' WHERE act_id=".$order['extension_id'];
$db->query($sql);
}
/* 處理餘額、積分、紅包 */
if ($order['user_id'] > 0 && $order['surplus'] > 0)
{
log_account_change($order['user_id'], $order['surplus'] * (-1), 0, 0, 0, sprintf($_LANG['pay_order'], $order['order_sn']));
}
if ($order['user_id'] > 0 && $order['integral'] > 0)
{
log_account_change($order['user_id'], 0, 0, 0, $order['integral'] * (-1), sprintf($_LANG['pay_order'], $order['order_sn']));
}
if ($order['bonus_id'] > 0 && $temp_amout > 0)
{
use_bonus($order['bonus_id'], $new_order_id);
}
/* 如果使用庫存,且下訂單時減庫存,則減少庫存 */
if ($_CFG['use_storage'] == '1' && $_CFG['stock_dec_time'] == SDT_PLACE)
{
change_order_goods_storage($order['order_id'], true, SDT_PLACE);
}
/* 給商家發郵件 */
/* 增加是否給客服發送郵件選項 */
if ($_CFG['send_service_email'] && $_CFG['service_email'] != '')
{
$tpl = get_mail_template('remind_of_new_order');
$smarty->assign('order', $order);
$smarty->assign('goods_list', $cart_goods);
$smarty->assign('shop_name', $_CFG['shop_name']);
$smarty->assign('send_date', date($_CFG['time_format']));
$content = $smarty->fetch('str:' . $tpl['template_content']);
send_mail($_CFG['shop_name'], $_CFG['service_email'], $tpl['template_subject'], $content, $tpl['is_html']);
}
/* 客户下訂單時給商家發送短信提醒 */
if ($_CFG['ecsdxt_order_placed'] == '1' && $_CFG['ecsdxt_shop_mobile'] != '')
{
require_once(ROOT_PATH . 'includes/lib_sms.php');
$smarty->assign('shop_name', $_CFG['shop_name']);
$smarty->assign('order_sn', $order['order_sn']);
$smarty->assign('consignee', $order['consignee']);
$smarty->assign('tel', $order['mobile']);
$content = $smarty->fetch('str:' . $_CFG['ecsdxt_order_placed_value']);
$ret = sendsms($_CFG['ecsdxt_shop_mobile'], $content);
}
/* 客户下訂單時給客户發送短信提醒 */
if ($_CFG['ecsdxt_customer_placed'] == '1' && $order['mobile'] != '')
{
require_once(ROOT_PATH . 'includes/lib_sms.php');
$smarty->assign('shop_name', $_CFG['shop_name']);
$smarty->assign('order_sn', $order['order_sn']);
$smarty->assign('consignee', $order['consignee']);
$smarty->assign('tel', $order['mobile']);
$content = $smarty->fetch('str:' . $_CFG['ecsdxt_customer_placed_value']);
$ret = sendsms($order['mobile'], $content);
}
/* 餘額支付直接發送短信 */
if ($send)
{
/* 客户付款時給商家發送短信提醒 */
if ($_CFG['ecsdxt_order_payed'] == '1' && $_CFG['ecsdxt_shop_mobile'] != '')
{
require_once(ROOT_PATH . 'includes/lib_sms.php');
$smarty->assign('shop_name', $_CFG['shop_name']);
$smarty->assign('order_sn', $order['order_sn']);
$smarty->assign('consignee', $order['consignee']);
$smarty->assign('tel', $order['mobile']);
$content = $smarty->fetch('str:' . $_CFG['ecsdxt_order_payed_value']);
$ret = sendsms($_CFG['ecsdxt_shop_mobile'], $content);
}
/* 客户付款時給客户發送短信提醒 */
if ($_CFG['ecsdxt_customer_payed'] == '1' && $order['mobile'] != '')
{
require_once(ROOT_PATH . 'includes/lib_sms.php');
$smarty->assign('shop_name', $_CFG['shop_name']);
$smarty->assign('order_sn', $order['order_sn']);
$smarty->assign('time', date('Y-m-d H:i:s', time()));
$content = $smarty->fetch('str:' . $_CFG['ecsdxt_customer_payed_value']);
$ret = sendsms($order['mobile'], $content);
}
}
/* 如果訂單金額為0 處理虛擬卡 */
if ($order['order_amount'] <= 0)
{
$sql = "SELECT goods_id, goods_name, goods_number AS num FROM ".
$GLOBALS['ecs']->table('cart') .
" WHERE is_real = 0 AND extension_code = 'virtual_card'".
//" AND session_id = '".SESS_ID."' AND rec_type = '$flow_type'";//青蜂網絡購物車選擇性結算註釋
" AND $sql_where AND rec_type = '$flow_type'";
$res = $GLOBALS['db']->getAll($sql);
$virtual_goods = array();
foreach ($res AS $row)
{
$virtual_goods['virtual_card'][] = array('goods_id' => $row['goods_id'], 'goods_name' => $row['goods_name'], 'num' => $row['num']);
}
if ($virtual_goods AND $flow_type != CART_GROUP_BUY_GOODS)
{
/* 虛擬卡發貨 */
if (virtual_goods_ship($virtual_goods,$msg, $order['order_sn'], true))
{
/* 如果沒有實體商品,修改發貨狀態,送積分和紅包 */
$sql = "SELECT COUNT(*)" .
" FROM " . $ecs->table('order_goods') .
" WHERE order_id = '$order[order_id]' " .
" AND is_real = 1";
if ($db->getOne($sql) <= 0)
{
/* 修改訂單狀態 */
update_order($order['order_id'], array('shipping_status' => SS_SHIPPED, 'shipping_time' => gmtime()));
/* 如果訂單用户不為空,計算積分,併發給用户;發紅包 */
if ($order['user_id'] > 0)
{
/* 取得用户信息 */
$user = user_info($order['user_id']);
/* 計算併發放積分 */
$integral = integral_to_give($order);
log_account_change($order['user_id'], 0, 0, intval($integral['rank_points']), intval($integral['custom_points']), sprintf($_LANG['order_gift_integral'], $order['order_sn']));
/* 發放紅包 */
send_order_bonus($order['order_id']);
}
}
}
}
}
/* 清空購物車 */
//clear_cart($flow_type);//青蜂網絡購物車選擇性結算註釋
clear_cart($flow_type,$id_ext);//新增青蜂網絡購物車選擇性結算
/* 清除緩存,否則買了商品,但是前台頁面讀取緩存,商品數量不減少 */
clear_all_files();
/* 插入支付日誌 */
$order['log_id'] = insert_pay_log($new_order_id, $order['order_amount'], PAY_ORDER);
/* 取得支付信息,生成支付代碼 */
// if ($order['order_amount'] > 0)
// {
// $payment = payment_info($order['pay_id']);
// include_once('includes/modules/payment/' . $payment['pay_code'] . '.php');
// $pay_obj = new $payment['pay_code'];
// $pay_online = $pay_obj->get_code($order, unserialize_config($payment['pay_config']));
// $order['pay_desc'] = $payment['pay_desc'];
// $smarty->assign('pay_online', $pay_online);
// }
if(!empty($order['shipping_name']))
{
$order['shipping_name']=trim(stripcslashes($order['shipping_name']));
}
/* 訂單信息 */
$smarty->assign('order', $order);
$smarty->assign('total', $total);
$smarty->assign('goods_list', $cart_goods);
$smarty->assign('order_submit_back', sprintf($_LANG['order_submit_back'], $_LANG['back_home'], $_LANG['goto_user_center'])); // 返回提示
user_uc_call('add_feed', array($order['order_id'], BUY_GOODS)); //推送feed到uc
unset($_SESSION['flow_consignee']); // 清除session中保存的收貨人信息
unset($_SESSION['flow_order']);
unset($_SESSION['direct_shopping']);
if ($_SESSION['user_id'] > 0){
ecs_header("Location:flow.php?step=payinfo&order_id=$new_order_id\n");
exit;
}
}
elseif ($_REQUEST['step'] == 'payinfo')
{
$order_id = isset($_REQUEST['order_id']) ? intval($_REQUEST['order_id']):0;
if (empty($_SESSION['user_id']))
{
/* 用户沒有登錄且沒有選定匿名購物,轉向到登錄頁面 */
ecs_header("Location: flow.php?step=login\n");
exit;
}
include_once(ROOT_PATH . 'includes/lib_transaction.php');
include_once(ROOT_PATH . 'includes/lib_payment.php');
include_once(ROOT_PATH . 'includes/lib_order.php');
include_once(ROOT_PATH . 'includes/lib_clips.php');
$order = get_order_detail($order_id, $_SESSION['user_id']);
if($order['order_status'] > 1){
/* 無需進入支付流程的訂單 */
ecs_header("Location: user.php?act=order_list\n");
exit;
}
$order_goods_num =0;
$goods_list = order_goods($order['order_id']);
foreach($goods_list as $v)
{
$order_goods_num +=$v['goods_number'];
}
$order['order_goods_num'] = $order_goods_num;
$order['will_get_integral'] = integral_to_give($order);
/* 取得支付信息,生成支付代碼 */
if ($order['order_amount'] > 0 && $order['pay_id'] >0)
{
$payment = payment_info($order['pay_id']);
include_once('includes/modules/payment/' . $payment['pay_code'] . '.php');
$pay_obj = new $payment['pay_code'];
$pay_online = $pay_obj->get_code($order, unserialize_config($payment['pay_config']));
$order['pay_desc'] = $payment['pay_desc'];
$order['pay_code'] = $payment['pay_code'];
$order['pay_name'] = $payment['pay_name'];
$smarty->assign('pay_online', $pay_online);
}
if(!empty($order['shipping_name']))
{
$order['shipping_name']=trim(stripcslashes($order['shipping_name']));
}
$total['amount_formated'] =$order['formated_order_amount'];
$total['money_paid_formated'] =price_format(abs($order['money_paid'] + $order['surplus']), false);
$smarty->assign('total', $total);
$smarty->assign('order', $order);
$sql = "SELECT pay_id FROM " . $ecs->table('payment') . " WHERE pay_code = 'balance' ";
$res = $db->getOne($sql);
$smarty->assign('res', $res);
$payment_list = available_payment_list(1, 0, true);
if(isset($payment_list))
{
foreach ($payment_list as $key => $payment)
{
if ($payment['is_cod'] == '1')
{
$payment_list[$key]['format_pay_fee'] = '<span id="ECS_CODFEE">' . $payment['format_pay_fee'] . '</span>';
}
/* 如果有易寶神州行支付 如果訂單金額大於300 則不顯示 */
if ($payment['pay_code'] == 'yeepayszx' && $total['amount'] > 300)
{
unset($payment_list[$key]);
}
if ($payment['pay_code'] == 'balance')
{
unset($payment_list[$key]);
}
if ($payment['pay_code'] == 'cod')
{
unset($payment_list[$key]);
}
if ($payment['pay_id'] == $order['pay_id'])
{
unset($payment_list[$key]);
}
/* 如果有餘額支付 */
if ($payment['pay_code'] == 'balance')
{
/* 如果未登錄,不顯示 */
if ($_SESSION['user_id'] == 0)
{
unset($payment_list[$key]);
}
else
{
if ($_SESSION['flow_order']['pay_id'] == $payment['pay_id'])
{
$smarty->assign('disable_surplus', 1);
}
}
}
}
}
$smarty->assign('payment_list', $payment_list);
$smarty->assign('bank_payid', $bank_payid);
$smarty->assign('bank_paylist', $bank_paylist);
}
elseif ($_REQUEST['step'] == 'change_payment')
{
/* 檢查是否登錄 */
if ($_SESSION['user_id'] <= 0)
{
ecs_header("Location: ./\n");
exit;
}
/* 檢查支付方式 */
$pay_id = intval($_REQUEST['pay_id']);
if ($pay_id <= 0)
{
ecs_header("Location: ./\n");
exit;
}
include_once(ROOT_PATH . 'includes/lib_order.php');
$payment_info = payment_info($pay_id);
if (empty($payment_info))
{
ecs_header("Location: ./\n");
exit;
}
/* 檢查訂單號 */
$order_id = intval($_REQUEST['order_id']);
if ($order_id <= 0)
{
ecs_header("Location: ./\n");
exit;
}
/* 取得訂單 */
$order = order_info($order_id);
if (empty($order))
{
ecs_header("Location: ./\n");
exit;
}
/* 檢查訂單用户跟當前用户是否一致 */
if ($_SESSION['user_id'] != $order['user_id'])
{
ecs_header("Location: ./\n");
exit;
}
/* 檢查訂單是否未付款和未發貨 以及訂單金額是否為0 和支付id是否為改變*/
if ($order['pay_status'] != PS_UNPAYED || $order['shipping_status'] != SS_UNSHIPPED || $order['goods_amount'] <= 0 )
{
ecs_header("Location: user.php?act=order_detail&order_id=$order_id\n");
exit;
}
$order_amount = $order['order_amount'] - $order['pay_fee'];
$pay_fee = pay_fee($pay_id, $order_amount);
$order_amount += $pay_fee;
$sql = "UPDATE " . $ecs->table('order_info') .
" SET pay_id='$pay_id', pay_name='$payment_info[pay_name]', pay_fee='$pay_fee', order_amount='$order_amount'".
" WHERE order_id = '$order_id'";
$db->query($sql);
$smarty->assign('order_submit_back', sprintf($_LANG['order_submit_back'], $_LANG['back_home'], $_LANG['goto_user_center'])); // 返回提示
/* 跳轉 */
ecs_header("Location: flow.php?step=payinfo&order_id=$order_id\n");
exit;
}
elseif ($_REQUEST['step'] == 'ajax_drop_goods')
{
require_once(ROOT_PATH .'includes/cls_json.php');
$json = new JSON();
$result = array('error' => 0, 'message'=> '');
$drop_id = isset($_POST['drop_arr']) ? explode(',', $_POST['drop_arr']) : array();
if (empty($drop_id))
{
$res['err_msg'] = '參數錯誤';
$res['err_no'] = 1;
}
else
{
foreach($drop_id as $value)
{
$rec_id = intval($value);
flow_drop_cart_goods($rec_id);
}
$cart_goods = get_cart_goods();
foreach ($cart_goods['goods_list'] as $goods )
{
if ($goods['rec_id'] == $key)
{
$result['goods_subtotal'] =$goods['subtotal'];
break;
}
}
$result['total_price'] = $cart_goods['total']['goods_price'];
$result['total_saving'] = $cart_goods['total']['saving'];
$result['total_real_goods_count'] = $cart_goods['total']['real_goods_count'];
$result['total_number'] =$cart_goods['total']['total_number'];//修改青蜂網絡購物車選擇性結算
}
die($json->encode($result));
}
elseif ($_REQUEST['step']== 'ajax_update_cart')
{
$request_body = file_get_contents('php://input');
$_POST = json_decode($request_body, true);
require_once(ROOT_PATH .'includes/cls_json.php');
$json = new JSON();
$result = array('error' => 0, 'message'=> '');
if (isset($_POST['rec_id']) && isset($_POST['goods_number']))
{
$key = $_POST['rec_id'];
$val = $_POST['goods_number'];
$result['rec_id'] = $key;
$val = intval(make_semiangle($val));
if ($val <= 0 && !is_numeric($key))
{
$result['error'] = 99;
$result['message'] = '';
die($json->encode($result));
}
$sql_where = $_SESSION['user_id']>0 ? "user_id='". $_SESSION['user_id'] ."' " : "session_id = '" . SESS_ID . "' AND user_id=0 ";//增加購物車選擇性結算--青蜂網絡www.0769web.net
/* 秒殺代碼增加_start By www.0769web.net */
$time_xg_now=gmtime();
$sql="select g.goods_id, g.goods_name, g.buymax, g.sale_start_date, g.sale_end_date from ".$GLOBALS['ecs']->table('cart'). " AS c left join ".$ecs->table('goods'). " AS g on c.goods_id=g.goods_id where c.rec_id=".$key;
$row=$db->getRow($sql);
if ( $row['buymax'] >0 && $row['sale_start_date'] < $time_xg_now && $row['sale_end_date'] > $time_xg_now )
{
if ( $val > intval($row['buymax']) )
{
$result['error'] = 888;
$result['message'] = "此商品為限購商品,限購期間每人最多隻能訂購 ". $row['buymax'] . " 件!";
die($json->encode($result));
}
else
{
$num_cart_old=$GLOBALS['db']->getOne("select sum(og.goods_number) from ". $GLOBALS['ecs']->table('order_goods') ." AS og , ". $GLOBALS['ecs']->table('order_info') ." AS o where o.user_id='$_SESSION[user_id]' and o.order_id = og.order_id and add_time > ". $row['sale_start_date'] ." and add_time < ". $row['sale_end_date'] ." and og.goods_id = " . $row['goods_id'] );
$num_total = $num_cart_old + intval($val);
if ( $num_total > intval($row['buymax']) )
{
$num_else=intval($row['buymax'])-$num_cart_old;
$message = "注意:\n\r 商品 【".$row['goods_name']."】 促銷期間每人限購 ". $row['buymax'] . "\n\r";
if ($num_cart_old)
{
$message .="您以前已經成功購買過 $num_cart_old 件!\n\r所以,";
}
$message .= "您最多隻能再買 ". $num_else ."";
$result['error'] = 888;
$result['message'] = $message;
die($json->encode($result));
}
}
}
/* 秒殺代碼增加_end By www.0769web.net */
//查詢:
$sql = "SELECT `goods_id`, `goods_attr_id`,`product_id`, `extension_code` FROM" .$GLOBALS['ecs']->table('cart')." WHERE rec_id='$key' AND $sql_where";//修改購物車選擇性結算--青蜂網絡www.0769web.net
$goods =$GLOBALS['db']->getRow($sql);
$sql = "SELECT g.goods_name,g.goods_number "."FROM ".$GLOBALS['ecs']->table('goods'). " AS g, ".$GLOBALS['ecs']->table('cart'). " AS c "."WHERE g.goods_id =c.goods_id AND c.rec_id = '$key'";
$row = $GLOBALS['db']->getRow($sql);
//查詢:系統啓用了庫存,檢查輸入的商品數量是否有效
if(intval($GLOBALS['_CFG']['use_storage']) > 0 && $goods['extension_code'] != 'package_buy')
{
/*是貨品*/
$goods['product_id'] = trim($goods['product_id']);
if (!empty($goods['product_id']))
{
$sql = "SELECT product_number FROM " .$GLOBALS['ecs']->table('products'). " WHERE goods_id = '" . $goods['goods_id'] . "' AND product_id = '" .$goods['product_id'] . "'";
$product_number = $GLOBALS['db']->getOne($sql);
if ($product_number < $val)
{
$result['error'] = 2;
$result['message'] =sprintf($GLOBALS['_LANG']['stock_insufficiency'], $row['goods_name'],$product_number, $product_number);
$result['goods_number'] = $product_number;
die($json->encode($result));
}
}
else
{
if ($row['goods_number'] < $val)
{
$result['error'] = 1;
$result['goods_number'] = $row['goods_number'];
$result['message'] =sprintf($GLOBALS['_LANG']['stock_insufficiency'], $row['goods_name'],$row['goods_number'], $row['goods_number']);
die($json->encode($result));
}
}
}
elseif (intval($GLOBALS['_CFG']['use_storage']) > 0 && $goods['extension_code'] == 'package_buy')
{
if(judge_package_stock($goods['goods_id'], $val))
{
$result['error'] = 3;
$result['message'] =$GLOBALS['_LANG']['package_stock_insufficiency'];
die($json->encode($result));
}
}
$sql_wherea = $_SESSION['user_id']>0 ? "a.user_id='". $_SESSION['user_id'] ."' " : "a.session_id = '" . SESS_ID . "' AND a.user_id=0 ";//增加購物車選擇性結算--青蜂網絡www.0769web.net
$sql_whereb = $_SESSION['user_id']>0 ? "b.user_id='". $_SESSION['user_id'] ."' " : "b.session_id = '" . SESS_ID . "' AND b.user_id=0 ";//增加購物車選擇性結算--青蜂網絡www.0769web.net
/*查詢:檢查該項是否為基本件以及是否存在配件*/
/*此處配件是指添加商品時附加的並且是設置了優惠價格的配件此類配件都有parent_id goods_number為1 */
$sql = "SELECT b.goods_number,b.rec_id FROM ".$GLOBALS['ecs']->table('cart') . " a, ".$GLOBALS['ecs']->table('cart') . " b WHERE a.rec_id = '$key' AND $sql_wherea AND a.extension_code <>'package_buy' AND b.parent_id = a.goods_id AND $sql_whereb";//修改購物車選擇性結算--青蜂網絡www.0769web.net
$offers_accessories_res =$GLOBALS['db']->query($sql);
//訂貨數量大於0
if ($val > 0)
{
/*判斷是否為超出數量的優惠價格的配件刪除*/
$row_num = 1;
while ($offers_accessories_row =$GLOBALS['db']->fetchRow($offers_accessories_res))
{
if ($row_num > $val)
{
$sql = "DELETE FROM" . $GLOBALS['ecs']->table('cart') ." WHERE $sql_where AND rec_id ='" . $offers_accessories_row['rec_id'] ."' LIMIT 1";
$GLOBALS['db']->query($sql);//修改購物車選擇性結算--青蜂網絡www.0769web.net
}
$row_num ++;
}
/*處理超值禮包*/
if ($goods['extension_code'] == 'package_buy')
{
//更新購物車中的商品數量
$sql = "UPDATE ".$GLOBALS['ecs']->table('cart')." SET goods_number= '$val' WHERE rec_id='$key' AND $sql_where";//修改購物車選擇性結算--青蜂網絡www.0769web.net
}
/*處理普通商品或非優惠的配件*/
else
{
$attr_id = empty($goods['goods_attr_id']) ? array(): explode(',', $goods['goods_attr_id']);
$goods_price =get_final_price($goods['goods_id'], $val, true, $attr_id);
//更新購物車中的商品數量
$sql = "UPDATE ".$GLOBALS['ecs']->table('cart')." SET goods_number= '$val', goods_price = '$goods_price' WHERE rec_id='$key' AND $sql_where";//修改購物車選擇性結算--青蜂網絡www.0769web.net
}
}
//訂貨數量等於0
else
{
/*如果是基本件並且有優惠價格的配件則刪除優惠價格的配件*/
while ($offers_accessories_row =$GLOBALS['db']->fetchRow($offers_accessories_res))
{
$sql = "DELETE FROM ". $GLOBALS['ecs']->table('cart') ." WHERE $sql_where AND rec_id ='" . $offers_accessories_row['rec_id'] ."' LIMIT 1";
$GLOBALS['db']->query($sql);//修改購物車選擇性結算--青蜂網絡www.0769web.net
}
$sql = "DELETE FROM ".$GLOBALS['ecs']->table('cart')." WHERE rec_id='$key' AND $sql_where";//修改購物車選擇性結算--青蜂網絡www.0769web.net
}
$GLOBALS['db']->query($sql);
/*刪除所有贈品*/
$sql = "DELETE FROM " .$GLOBALS['ecs']->table('cart') . " WHERE $sql_where AND is_gift <> 0";//修改購物車選擇性結算--青蜂網絡www.0769web.net
$GLOBALS['db']->query($sql);
$result['rec_id'] = $key;
$result['goods_number'] = $val;
$result['goods_subtotal'] = '';
$result['total_desc'] = '';
$cart_goods = get_cart_goods();
foreach ($cart_goods['goods_list'] as $goods )
{
if ($goods['rec_id'] == $key)
{
$result['goods_subtotal'] =$goods['subtotal'];
break;
}
}
$result['total_price'] = $cart_goods['total']['goods_price'];
$result['total_saving'] = $cart_goods['total']['saving'];
$result['total_real_goods_count'] = $cart_goods['total']['real_goods_count'];
$shopping_money =sprintf($_LANG['shopping_money'], $cart_goods['total']['goods_price']);
$market_price_desc =sprintf($_LANG['than_market_price'],$cart_goods['total']['market_price'],$cart_goods['total']['saving'], $cart_goods['total']['save_rate']);
$result['total_info'] = '<strong class="darkgray">&nbsp;&nbsp;商品金額:</strong> <strong class="red f16 yh">&nbsp;'.$result['total_price'].'</strong> <span>&nbsp;元</span> <span class="fl"> <span>&nbsp;&nbsp;&nbsp;&nbsp;共節省'.$result['total_saving'].'元 </span> </span>';
$discount = compute_discount();
$favour_name = empty($discount['name']) ? '' : join(',', $discount['name']);
$your_discount =sprintf($_LANG['your_discount'], $favour_name,price_format($discount['discount']));
if ($discount['discount'] > 0)
{
$result['total_desc'] .= $your_discount . '<br />';
}
$result['total_desc'] .= $shopping_money;
if ($_CFG['show_marketprice'])
{
$result['total_desc'] .= '' .$market_price_desc;
}
$result['total_number'] =$cart_goods['total']['total_number'];
die($json->encode($result));
}
else
{
$result['error'] = 100;
$result['message'] = '';
die($json->encode($result));
}
}
/*------------------------------------------------------ */
//-- 更新購物車
/*------------------------------------------------------ */
elseif ($_REQUEST['step'] == 'update_cart')
{
/* 秒殺代碼增加_start By www.0769web.net */
$time_xg_now=gmtime();
foreach($_POST['goods_number'] as $key=>$val)
{
$sql="select g.goods_id, g.goods_name, g.buymax, g.sale_start_date, g.sale_end_date from ".$ecs->table('cart'). " AS c left join ".$ecs->table('goods'). " AS g on c.goods_id=g.goods_id where c.rec_id=".$key;
$row=$db->getRow($sql);
if ( $row['buymax'] >0 && $row['sale_start_date'] < $time_xg_now && $row['sale_end_date'] > $time_xg_now )
{
if ( $val > intval($row['buymax']) )
{
show_message("此商品為秒殺限購商品,限購期間每人最多隻能訂購". $row['buymax'] . " 件!", $_LANG['back_to_cart'], 'flow.php');
exit;
}
else
{
$num_cart_old=$GLOBALS['db']->getOne("select sum(og.goods_number) from ". $GLOBALS['ecs']->table('order_goods') ." AS og , ". $GLOBALS['ecs']->table('order_info') ." AS o where o.user_id='$_SESSION[user_id]' and o.order_id = og.order_id and add_time > ". $row['sale_start_date'] ." and add_time < ". $row['sale_end_date'] ." and og.goods_id = " . $row['goods_id'] );
$num_total = $num_cart_old + intval($val);
if ( $num_total > intval($row['buymax']) )
{
$num_else=intval($row['buymax'])-$num_cart_old;
$message = "注意:<br> 商品 <font color=#330099>【".$row['goods_name']."】</font> 秒殺期間每人限購 <font color=#330099>". $row['buymax'] . "</font> 件<br>";
if ($num_cart_old)
{
$message .="您以前已經成功購買過 <font color=#330099>$num_cart_old</font> 件!<br>所以,";
}
$message .= "您最多隻能再買 <font color=#330099>". $num_else ."</font> 件";
show_message( $message, $_LANG['back_to_cart'], 'flow.php', 'info', false);
exit;
}
}
}
}
/* 秒殺代碼增加_end By www.0769web.net */
if (isset($_POST['goods_number']) && is_array($_POST['goods_number']))
{
flow_update_cart($_POST['goods_number']);
}
show_message($_LANG['update_cart_notice'], $_LANG['back_to_cart'], 'flow.php');
exit;
}
/*------------------------------------------------------ */
//-- 刪除購物車中的商品
/*------------------------------------------------------ */
elseif ($_REQUEST['step'] == 'drop_goods')
{
$rec_id = intval($_GET['id']);
flow_drop_cart_goods($rec_id);
ecs_header("Location: flow.php\n");
exit;
}
/* 把優惠活動加入購物車 */
elseif ($_REQUEST['step'] == 'add_favourable')
{
/* 取得優惠活動信息 */
$act_id = intval($_POST['act_id']);
$favourable = favourable_info($act_id);
if (empty($favourable))
{
show_message($_LANG['favourable_not_exist']);
}
/* 判斷用户能否享受該優惠 */
if (!favourable_available($favourable))
{
show_message($_LANG['favourable_not_available']);
}
/* 檢查購物車中是否已有該優惠 */
$cart_favourable = cart_favourable();
if (favourable_used($favourable, $cart_favourable))
{
show_message($_LANG['favourable_used']);
}
/* 贈品(特惠品)優惠 */
if ($favourable['act_type'] == FAT_GOODS)
{
/* 檢查是否選擇了贈品 */
if (empty($_POST['gift']))
{
show_message($_LANG['pls_select_gift']);
}
/* 檢查是否已在購物車 */
$sql_where = $_SESSION['user_id']>0 ? "user_id='". $_SESSION['user_id'] ."' " : "session_id = '" . SESS_ID . "' AND user_id=0 ";//增加購物車選擇性結算--青蜂網絡www.0769web.net
$sql = "SELECT goods_name" .
" FROM " . $ecs->table('cart') .
" WHERE $sql_where" .
" AND rec_type = '" . CART_GENERAL_GOODS . "'" .
" AND is_gift = '$act_id'" .
" AND goods_id " . db_create_in($_POST['gift']);
$gift_name = $db->getCol($sql);
if (!empty($gift_name))
{
show_message(sprintf($_LANG['gift_in_cart'], join(',', $gift_name)));
}
/* 檢查數量是否超過上限 */
$count = isset($cart_favourable[$act_id]) ? $cart_favourable[$act_id] : 0;
if ($favourable['act_type_ext'] > 0 && $count + count($_POST['gift']) > $favourable['act_type_ext'])
{
show_message($_LANG['gift_count_exceed']);
}
/* 添加贈品到購物車 */
foreach ($favourable['gift'] as $gift)
{
if (in_array($gift['id'], $_POST['gift']))
{
add_gift_to_cart($act_id, $gift['id'], $gift['price']);
}
}
}
elseif ($favourable['act_type'] == FAT_DISCOUNT)
{
add_favourable_to_cart($act_id, $favourable['act_name'], cart_favourable_amount($favourable) * (100 - $favourable['act_type_ext']) / 100);
}
elseif ($favourable['act_type'] == FAT_PRICE)
{
add_favourable_to_cart($act_id, $favourable['act_name'], $favourable['act_type_ext']);
}
/* 刷新購物車 */
ecs_header("Location: flow.php\n");
exit;
}
elseif ($_REQUEST['step'] == 'clear')
{
//$sql = "DELETE FROM " . $ecs->table('cart') . " WHERE session_id='" . SESS_ID . "'";
$sql_where = $_SESSION['user_id']>0 ? "user_id='". $_SESSION['user_id'] ."' " : "session_id = '" . SESS_ID . "' AND user_id=0 ";
$sql = "DELETE FROM " . $ecs->table('cart') . " WHERE $sql_where";
$db->query($sql);
ecs_header("Location:./\n");
}
elseif ($_REQUEST['step'] == 'drop_to_collect')
{
if ($_SESSION['user_id'] > 0)
{
$sql_where = $_SESSION['user_id']>0 ? "user_id='". $_SESSION['user_id'] ."' " : "session_id = '" . SESS_ID . "' AND user_id=0 ";//增加購物車選擇性結算--青蜂網絡www.0769web.net
$rec_id = intval($_GET['id']);
$goods_id = $db->getOne("SELECT goods_id FROM " .$ecs->table('cart'). " WHERE rec_id = '$rec_id' AND $sql_where ");//修改購物車選擇性結算--青蜂網絡www.0769web.net
$count = $db->getOne("SELECT goods_id FROM " . $ecs->table('collect_goods') . " WHERE user_id = '$_SESSION[user_id]' AND goods_id = '$goods_id'");
if (empty($count))
{
$time = gmtime();
$sql = "INSERT INTO " .$GLOBALS['ecs']->table('collect_goods'). " (user_id, goods_id, add_time)" .
"VALUES ('$_SESSION[user_id]', '$goods_id', '$time')";
$db->query($sql);
}
flow_drop_cart_goods($rec_id);
}
ecs_header("Location: flow.php\n");
exit;
}
/* 驗證紅包序列號 */
elseif ($_REQUEST['step'] == 'validate_bonus')
{
$bonus_sn = trim($_REQUEST['bonus_sn']);
if (is_numeric($bonus_sn))
{
$bonus = bonus_info(0, $bonus_sn);
}
else
{
$bonus = array();
}
$bonus_kill = price_format($bonus['type_money'], false);
include_once('includes/cls_json.php');
$result = array('error' => '', 'content' => '');
/* 取得購物類型 */
$flow_type = isset($_SESSION['flow_type']) ? intval($_SESSION['flow_type']) : CART_GENERAL_GOODS;
/* 獲得收貨人信息 */
$consignee = get_consignee($_SESSION['user_id']);
/* 對商品信息賦值 */
$cart_goods = cart_goods($flow_type); // 取得商品列表,計算合計
if (empty($cart_goods))
{
$result['error'] = $_LANG['no_goods_in_cart'];
}
else
{
/* 取得購物流程設置 */
$smarty->assign('config', $_CFG);
/* 取得訂單信息 */
$order = flow_order_info();
if (((!empty($bonus) && $bonus['user_id'] == $_SESSION['user_id']) || ($bonus['type_money'] > 0 && empty($bonus['user_id']))) && $bonus['order_id'] <= 0)
{
//$order['bonus_kill'] = $bonus['type_money'];
$now = gmtime();
if ($now > $bonus['use_end_date'])
{
$order['bonus_id'] = '';
$result['error']=$_LANG['bonus_use_expire'];
}
else
{
$order['bonus_id'] = $bonus['bonus_id'];
$order['bonus_sn'] = $bonus_sn;
}
}
else
{
//$order['bonus_kill'] = 0;
$order['bonus_id'] = '';
$result['error'] = $_LANG['invalid_bonus'];
}
/* 計算訂單的費用 */
$total = order_fee($order, $cart_goods, $consignee);
if($total['goods_price']<$bonus['min_goods_amount'])
{
$order['bonus_id'] = '';
/* 重新計算訂單 */
$total = order_fee($order, $cart_goods, $consignee);
$result['error'] = sprintf($_LANG['bonus_min_amount_error'], price_format($bonus['min_goods_amount'], false));
}
$smarty->assign('total', $total);
/* 團購標誌 */
if ($flow_type == CART_GROUP_BUY_GOODS)
{
$smarty->assign('is_group_buy', 1);
}
$result['content'] = $smarty->fetch('library/order_total.lbi');
}
$json = new JSON();
die($json->encode($result));
}
/*------------------------------------------------------ */
//-- 添加禮包到購物車
/*------------------------------------------------------ */
elseif ($_REQUEST['step'] == 'add_package_to_cart')
{
include_once('includes/cls_json.php');
$_POST['package_info'] = json_str_iconv($_POST['package_info']);
$result = array('error' => 0, 'message' => '', 'content' => '', 'package_id' => '');
$json = new JSON;
if (empty($_POST['package_info']))
{
$result['error'] = 1;
die($json->encode($result));
}
$package = $json->decode($_POST['package_info']);
/* 如果是一步購物,先清空購物車 */
if ($_CFG['one_step_buy'] == '1')
{
clear_cart();
}
/* 商品數量是否合法 */
if (!is_numeric($package->number) || intval($package->number) <= 0)
{
$result['error'] = 1;
$result['message'] = $_LANG['invalid_number'];
}
else
{
/* 添加到購物車 */
if (add_package_to_cart($package->package_id, $package->number))
{
if ($_CFG['cart_confirm'] > 2)
{
$result['message'] = '';
}
else
{
$result['message'] = $_CFG['cart_confirm'] == 1 ? $_LANG['addto_cart_success_1'] : $_LANG['addto_cart_success_2'];
}
$result['content'] = insert_cart_info();
$result['one_step_buy'] = $_CFG['one_step_buy'];
}
else
{
$result['message'] = $err->last_message();
$result['error'] = $err->error_no;
$result['package_id'] = stripslashes($package->package_id);
}
}
$result['confirm_type'] = !empty($_CFG['cart_confirm']) ? $_CFG['cart_confirm'] : 2;
die($json->encode($result));
}
else
{
/* 標記購物流程為普通商品 */
$_SESSION['flow_type'] = CART_GENERAL_GOODS;
/* 如果是一步購物,跳到結算中心 */
if ($_CFG['one_step_buy'] == '1')
{
ecs_header("Location: flow.php?step=checkout\n");
exit;
}
/* 取得商品列表,計算合計 */
$cart_goods = get_cart_goods();
$smarty->assign('goods_list', $cart_goods['goods_list']);
$smarty->assign('total', $cart_goods['total']);
//購物車的描述的格式化
$smarty->assign('shopping_money', sprintf($_LANG['shopping_money'], $cart_goods['total']['goods_price']));
$smarty->assign('market_price_desc', sprintf($_LANG['than_market_price'], $cart_goods['total']['market_price'], $cart_goods['total']['saving'], $cart_goods['total']['save_rate']));
// 顯示收藏夾內的商品
if ($_SESSION['user_id'] > 0)
{
require_once(ROOT_PATH . 'includes/lib_clips.php');
$collection_goods = get_collection_goods($_SESSION['user_id']);
$smarty->assign('collection_goods', $collection_goods);
}
/* 取得優惠活動 */
$favourable_list = favourable_list($_SESSION['user_rank']);
usort($favourable_list, 'cmp_favourable');
$smarty->assign('favourable_list', $favourable_list);
/* 計算折扣 */
$discount = compute_discount();
$smarty->assign('discount', $discount['discount']);
$favour_name = empty($discount['name']) ? '' : join(',', $discount['name']);
$smarty->assign('your_discount', sprintf($_LANG['your_discount'], $favour_name, price_format($discount['discount'])));
/* 增加是否在購物車裏顯示商品圖 */
$smarty->assign('show_goods_thumb', $GLOBALS['_CFG']['show_goods_in_cart']);
/* 增加是否在購物車裏顯示商品屬性 */
$smarty->assign('show_goods_attribute', $GLOBALS['_CFG']['show_attr_in_cart']);
/* 購物車中商品配件列表 */
//取得購物車中基本件ID
$sql_where = $_SESSION['user_id']>0 ? "user_id='". $_SESSION['user_id'] ."' " : "session_id = '" . SESS_ID . "' AND user_id=0 ";
$sql = "SELECT goods_id " .
"FROM " . $GLOBALS['ecs']->table('cart') .
" WHERE $sql_where " .
"AND rec_type = '" . CART_GENERAL_GOODS . "' " .
"AND is_gift = 0 " .
"AND extension_code <> 'package_buy' " .
"AND parent_id = 0 ";
$parent_list = $GLOBALS['db']->getCol($sql);
$fittings_list = get_goods_fittings($parent_list);
$smarty->assign('fittings_list', $fittings_list);
}
$smarty->assign('currency_format', $_CFG['currency_format']);
$smarty->assign('integral_scale', $_CFG['integral_scale']);
$smarty->assign('step', $_REQUEST['step']);
assign_dynamic('shopping_flow');
if ($_REQUEST['step'] == 'cart'){
$smarty->display('flowcart.html');
}else{
$smarty->display('flow.dwt');
}
/*------------------------------------------------------ */
//-- PRIVATE FUNCTION
/*------------------------------------------------------ */
/**
* 獲得用户的可用積分
*
* @access private
* @return integral
*/
function flow_available_points()
{
$sql_where = $_SESSION['user_id']>0 ? "c.user_id='". $_SESSION['user_id'] ."' " : "c.session_id = '" . SESS_ID . "' AND c.user_id=0 ";//增加購物車選擇性結算--青蜂網絡www.0769web.net
$sql = "SELECT SUM(g.integral * c.goods_number) ".
"FROM " . $GLOBALS['ecs']->table('cart') . " AS c, " . $GLOBALS['ecs']->table('goods') . " AS g " .
//"WHERE c.session_id = '" . SESS_ID . "' AND c.goods_id = g.goods_id AND c.is_gift = 0 AND g.integral > 0 " .//青蜂網絡購物車選擇性結算註釋
"WHERE $sql_where AND c.goods_id = g.goods_id AND c.is_gift = 0 AND g.integral > 0 " .//增加購物車選擇性結算--青蜂網絡www.0769web.net
"AND c.rec_type = '" . CART_GENERAL_GOODS . "'";
$val = intval($GLOBALS['db']->getOne($sql));
return integral_of_value($val);
}
/**
* 更新購物車中的商品數量
*
* @access public
* @param array $arr
* @return void
*/
/**
* 更新購物車中的商品數量
*
* @access public
* @param array $arr
* @return void
*/
function flow_update_cart($arr)
{
/* 處理 */
foreach ($arr AS $key => $val)
{
$val = intval(make_semiangle($val));
if ($val <= 0 || !is_numeric($key))
{
continue;
}
//查詢:
$sql_where = $_SESSION['user_id']>0 ? "user_id='". $_SESSION['user_id'] ."' " : "session_id = '" . SESS_ID . "' AND user_id=0 ";//增加購物車選擇性結算--青蜂網絡www.0769web.net
$sql = "SELECT `goods_id`, `goods_attr_id`, `product_id`, `extension_code` FROM" .$GLOBALS['ecs']->table('cart').
" WHERE rec_id='$key' AND $sql_where";//修改購物車選擇性結算--青蜂網絡www.0769web.net
$goods = $GLOBALS['db']->getRow($sql);
$sql = "SELECT g.goods_name, g.goods_number ".
"FROM " .$GLOBALS['ecs']->table('goods'). " AS g, ".
$GLOBALS['ecs']->table('cart'). " AS c ".
"WHERE g.goods_id = c.goods_id AND c.rec_id = '$key'";
$row = $GLOBALS['db']->getRow($sql);
//查詢:系統啓用了庫存,檢查輸入的商品數量是否有效
if (intval($GLOBALS['_CFG']['use_storage']) > 0 && $goods['extension_code'] != 'package_buy')
{
if ($row['goods_number'] < $val)
{
show_message(sprintf($GLOBALS['_LANG']['stock_insufficiency'], $row['goods_name'],
$row['goods_number'], $row['goods_number']));
exit;
}
/* 是貨品 */
$goods['product_id'] = trim($goods['product_id']);
if (!empty($goods['product_id']))
{
$sql = "SELECT product_number FROM " .$GLOBALS['ecs']->table('products'). " WHERE goods_id = '" . $goods['goods_id'] . "' AND product_id = '" . $goods['product_id'] . "'";
$product_number = $GLOBALS['db']->getOne($sql);
if ($product_number < $val)
{
show_message(sprintf($GLOBALS['_LANG']['stock_insufficiency'], $row['goods_name'],
$product_number['product_number'], $product_number['product_number']));
exit;
}
}
}
elseif (intval($GLOBALS['_CFG']['use_storage']) > 0 && $goods['extension_code'] == 'package_buy')
{
if (judge_package_stock($goods['goods_id'], $val))
{
show_message($GLOBALS['_LANG']['package_stock_insufficiency']);
exit;
}
}
/* 查詢:檢查該項是否為基本件 以及是否存在配件 */
/* 此處配件是指添加商品時附加的並且是設置了優惠價格的配件 此類配件都有parent_id goods_number為1 */
$sql_wherea = $_SESSION['user_id']>0 ? "a.user_id='". $_SESSION['user_id'] ."' " : "a.session_id = '" . SESS_ID . "' AND a.user_id=0 ";
$sql_whereb = $_SESSION['user_id']>0 ? "b.user_id='". $_SESSION['user_id'] ."' " : "b.session_id = '" . SESS_ID . "' AND b.user_id=0 ";
$sql = "SELECT b.goods_number, b.rec_id
FROM " .$GLOBALS['ecs']->table('cart') . " a, " .$GLOBALS['ecs']->table('cart') . " b
WHERE $sql_wherea AND a.rec_id = '$key'
AND a.extension_code <> 'package_buy'
AND b.parent_id = a.goods_id
AND $sql_whereb";
$sql_where1 = $_SESSION['user_id']>0 ? "user_id='". $_SESSION['user_id'] ."' " : "session_id = '" . SESS_ID . "' AND user_id=0 ";
$offers_accessories_res = $GLOBALS['db']->query($sql);
//訂貨數量大於0
if ($val > 0)
{
/* 判斷是否為超出數量的優惠價格的配件 刪除*/
$row_num = 1;
while ($offers_accessories_row = $GLOBALS['db']->fetchRow($offers_accessories_res))
{
if ($row_num > $val)
{
$sql = "DELETE FROM " . $GLOBALS['ecs']->table('cart') .
" WHERE $sql_where1 " .//修改購物車選擇性結算--青蜂網絡www.0769web.net
"AND rec_id = '" . $offers_accessories_row['rec_id'] ."' AND group_id='' LIMIT 1"; //by mike
$GLOBALS['db']->query($sql);
}
$row_num ++;
}
/* 處理超值禮包 */
if ($goods['extension_code'] == 'package_buy')
{
//更新購物車中的商品數量
$sql = "UPDATE " .$GLOBALS['ecs']->table('cart').
//" SET goods_number = '$val' WHERE rec_id='$key' AND session_id='" . SESS_ID . "' AND group_id=''"; //青蜂網絡購物車選擇性結算註釋
" SET goods_number = '$val' WHERE rec_id='$key' AND group_id='' AND $sql_where1"; //增加購物車選擇性結算--青蜂網絡www.0769web.net
}
/* 處理普通商品或非優惠的配件 */
else
{
$attr_id = empty($goods['goods_attr_id']) ? array() : explode(',', $goods['goods_attr_id']);
$goods_price = get_final_price($goods['goods_id'], $val, true, $attr_id);
//更新購物車中的商品數量
$sql = "UPDATE " .$GLOBALS['ecs']->table('cart').
//" SET goods_number = '$val', goods_price = '$goods_price' WHERE rec_id='$key' AND session_id='" . SESS_ID . "' AND group_id=''"; //青蜂網絡購物車選擇性結算註釋
" SET goods_number = '$val', goods_price = '$goods_price' WHERE rec_id='$key' AND group_id='' AND $sql_where1"; //增加購物車選擇性結算--青蜂網絡www.0769web.net
}
}
//訂貨數量等於0
else
{
/* 如果是基本件並且有優惠價格的配件則刪除優惠價格的配件 */
while ($offers_accessories_row = $GLOBALS['db']->fetchRow($offers_accessories_res))
{
$sql = "DELETE FROM " . $GLOBALS['ecs']->table('cart') .
//" WHERE session_id = '" . SESS_ID . "' " .//青蜂網絡購物車選擇性結算註釋
" WHERE $sql_where1 " .//增加購物車選擇性結算--青蜂網絡www.0769web.net
"AND rec_id = '" . $offers_accessories_row['rec_id'] ."' AND group_id='' LIMIT 1"; //by mike
$GLOBALS['db']->query($sql);
}
$sql = "DELETE FROM " .$GLOBALS['ecs']->table('cart').
//" WHERE rec_id='$key' AND session_id='" .SESS_ID. "' AND group_id=''"; //青蜂網絡購物車選擇性結算註釋
" WHERE rec_id='$key' AND group_id='' AND $sql_where1"; //增加購物車選擇性結算--青蜂網絡www.0769web.net
}
$GLOBALS['db']->query($sql);
}
/* 刪除所有贈品 */
//$sql = "DELETE FROM " . $GLOBALS['ecs']->table('cart') . " WHERE session_id = '" .SESS_ID. "' AND is_gift <> 0";//青蜂網絡購物車選擇性結算註釋
$sql = "DELETE FROM " . $GLOBALS['ecs']->table('cart') . " WHERE $sql_where1 AND is_gift <> 0";//修改購物車選擇性結算--青蜂網絡www.0769web.net
$GLOBALS['db']->query($sql);
}
/**
* 檢查訂單中商品庫存
*
* @access public
* @param array $arr
*
* @return void
*/
function flow_cart_stock($arr)
{
foreach ($arr AS $key => $val)
{
$val = intval(make_semiangle($val));
if ($val <= 0 || !is_numeric($key))
{
continue;
}
$sql_where = $_SESSION['user_id']>0 ? "user_id='". $_SESSION['user_id'] ."' " : "session_id = '" . SESS_ID . "' AND user_id=0 ";
$sql = "SELECT `goods_id`, `goods_attr_id`, `extension_code` FROM" .$GLOBALS['ecs']->table('cart').
" WHERE rec_id='$key' AND $sql_where";
$goods = $GLOBALS['db']->getRow($sql);
$sql = "SELECT g.goods_name, g.goods_number, c.product_id ".
"FROM " .$GLOBALS['ecs']->table('goods'). " AS g, ".
$GLOBALS['ecs']->table('cart'). " AS c ".
"WHERE g.goods_id = c.goods_id AND c.rec_id = '$key'";
$row = $GLOBALS['db']->getRow($sql);
//系統啓用了庫存,檢查輸入的商品數量是否有效
if (intval($GLOBALS['_CFG']['use_storage']) > 0 && $goods['extension_code'] != 'package_buy')
{
if ($row['goods_number'] < $val)
{
show_message(sprintf($GLOBALS['_LANG']['stock_insufficiency'], $row['goods_name'],
$row['goods_number'], $row['goods_number']));
exit;
}
/* 是貨品 */
$row['product_id'] = trim($row['product_id']);
if (!empty($row['product_id']))
{
$sql = "SELECT product_number FROM " .$GLOBALS['ecs']->table('products'). " WHERE goods_id = '" . $goods['goods_id'] . "' AND product_id = '" . $row['product_id'] . "'";
$product_number = $GLOBALS['db']->getOne($sql);
if ($product_number < $val)
{
show_message(sprintf($GLOBALS['_LANG']['stock_insufficiency'], $row['goods_name'],
$row['goods_number'], $row['goods_number']));
exit;
}
}
}
elseif (intval($GLOBALS['_CFG']['use_storage']) > 0 && $goods['extension_code'] == 'package_buy')
{
if (judge_package_stock($goods['goods_id'], $val))
{
show_message($GLOBALS['_LANG']['package_stock_insufficiency']);
exit;
}
}
}
}
/**
* 刪除購物車中的商品
*
* @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)
{
$sql_where = $_SESSION['user_id']>0 ? "user_id='". $_SESSION['user_id'] ."' " : "session_id = '" . SESS_ID . "' AND user_id=0 ";//增加購物車選擇性結算--青蜂網絡www.0769web.net
//如果是超值禮包
if ($row['extension_code'] == 'package_buy')
{
$sql = "DELETE FROM " . $GLOBALS['ecs']->table('cart') .
//" WHERE session_id = '" . SESS_ID . "' " .//青蜂網絡購物車選擇性結算註釋
" WHERE $sql_where " .//增加購物車選擇性結算--青蜂網絡www.0769web.net
"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 $sql_where " .//修改購物車選擇性結算--青蜂網絡www.0769web.net
"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 . "' " .//青蜂網絡購物車選擇性結算註釋
" WHERE $sql_where " .//增加購物車選擇性結算--青蜂網絡www.0769web.net
"AND rec_id = '$id' LIMIT 1";
}
$GLOBALS['db']->query($sql);
}
flow_clear_cart_alone();
}
/**
* 刪除購物車中不能單獨銷售的商品
*
* @access public
* @return void
*/
function flow_clear_cart_alone()
{
/* 查詢:購物車中所有不可以單獨銷售的配件 */
$sql_where = $_SESSION['user_id']>0 ? "c.user_id='". $_SESSION['user_id'] ."' " : "c.session_id = '" . SESS_ID . "' AND c.user_id=0 ";//新增青蜂網絡購物車選擇性結算
/* 查詢:購物車中所有不可以單獨銷售的配件 */
$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 $sql_where
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;
}
/* 查詢:購物車中所有商品 */
/* 代碼修改購物車選擇性結算_start By www.0769web.net 將這塊替換掉*/
$sql_where = $_SESSION['user_id']>0 ? "user_id='". $_SESSION['user_id'] ."' " : "session_id = '" . SESS_ID . "' AND user_id=0 ";
$sql = "SELECT DISTINCT goods_id
FROM " . $GLOBALS['ecs']->table('cart') . "
WHERE $sql_where
AND extension_code <> 'package_buy'";
/* 代碼修改購物車選擇性結算_end By www.0769web.net */
$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;
}
/* 刪除 */
/* 代碼修改購物車選擇性結算_start By www.0769web.net 將這塊替換掉*/
if($del_rec_id){
$sql_plus = " AND rec_id IN ($del_rec_id) ";
}
$sql = "DELETE FROM " . $GLOBALS['ecs']->table('cart') ."
WHERE $sql_where
".$sql_plus;
/* 代碼修改購物車選擇性結算_end By www.0769web.net */
$GLOBALS['db']->query($sql);
}
/**
* 比較優惠活動的函數,用於排序(把可用的排在前面)
* @param array $a 優惠活動a
* @param array $b 優惠活動b
* @return int 相等返回0小於返回-1大於返回1
*/
function cmp_favourable($a, $b)
{
if ($a['available'] == $b['available'])
{
if ($a['sort_order'] == $b['sort_order'])
{
return 0;
}
else
{
return $a['sort_order'] < $b['sort_order'] ? -1 : 1;
}
}
else
{
return $a['available'] ? -1 : 1;
}
}
/**
* 取得某用户等級當前時間可以享受的優惠活動
* @param int $user_rank 用户等級id0表示非會員
* @return array
*/
function favourable_list($user_rank)
{
/* 購物車中已有的優惠活動及數量 */
$used_list = cart_favourable();
/* 當前用户可享受的優惠活動 */
$favourable_list = array();
$user_rank = ',' . $user_rank . ',';
$now = gmtime();
$sql = "SELECT * " .
"FROM " . $GLOBALS['ecs']->table('favourable_activity') .
" WHERE CONCAT(',', user_rank, ',') LIKE '%" . $user_rank . "%'" .
" AND start_time <= '$now' AND end_time >= '$now'" .
" AND act_type = '" . FAT_GOODS . "'" .
" ORDER BY sort_order";
$res = $GLOBALS['db']->query($sql);
while ($favourable = $GLOBALS['db']->fetchRow($res))
{
$favourable['start_time'] = local_date($GLOBALS['_CFG']['time_format'], $favourable['start_time']);
$favourable['end_time'] = local_date($GLOBALS['_CFG']['time_format'], $favourable['end_time']);
$favourable['formated_min_amount'] = price_format($favourable['min_amount'], false);
$favourable['formated_max_amount'] = price_format($favourable['max_amount'], false);
$favourable['gift'] = unserialize($favourable['gift']);
foreach ($favourable['gift'] as $key => $value)
{
$favourable['gift'][$key]['formated_price'] = price_format($value['price'], false);
$sql = "SELECT COUNT(*) FROM " . $GLOBALS['ecs']->table('goods') . " WHERE is_on_sale = 1 AND goods_id = ".$value['id'];
$is_sale = $GLOBALS['db']->getOne($sql);
if(!$is_sale)
{
unset($favourable['gift'][$key]);
}
}
$favourable['act_range_desc'] = act_range_desc($favourable);
$favourable['act_type_desc'] = sprintf($GLOBALS['_LANG']['fat_ext'][$favourable['act_type']], $favourable['act_type_ext']);
/* 是否能享受 */
$favourable['available'] = favourable_available($favourable);
if ($favourable['available'])
{
/* 是否尚未享受 */
$favourable['available'] = !favourable_used($favourable, $used_list);
}
$favourable_list[] = $favourable;
}
return $favourable_list;
}
/**
* 根據購物車判斷是否可以享受某優惠活動
* @param array $favourable 優惠活動信息
* @return bool
*/
function favourable_available($favourable)
{
/* 會員等級是否符合 */
$user_rank = $_SESSION['user_rank'];
if (strpos(',' . $favourable['user_rank'] . ',', ',' . $user_rank . ',') === false)
{
return false;
}
/* 優惠範圍內的商品總額 */
$amount = cart_favourable_amount($favourable);
/* 金額上限為0表示沒有上限 */
return $amount >= $favourable['min_amount'] &&
($amount <= $favourable['max_amount'] || $favourable['max_amount'] == 0);
}
/**
* 取得優惠範圍描述
* @param array $favourable 優惠活動
* @return string
*/
function act_range_desc($favourable)
{
if ($favourable['act_range'] == FAR_BRAND)
{
$sql = "SELECT brand_name FROM " . $GLOBALS['ecs']->table('brand') .
" WHERE brand_id " . db_create_in($favourable['act_range_ext']);
return join(',', $GLOBALS['db']->getCol($sql));
}
elseif ($favourable['act_range'] == FAR_CATEGORY)
{
$sql = "SELECT cat_name FROM " . $GLOBALS['ecs']->table('category') .
" WHERE cat_id " . db_create_in($favourable['act_range_ext']);
return join(',', $GLOBALS['db']->getCol($sql));
}
elseif ($favourable['act_range'] == FAR_GOODS)
{
$sql = "SELECT goods_name FROM " . $GLOBALS['ecs']->table('goods') .
" WHERE goods_id " . db_create_in($favourable['act_range_ext']);
return join(',', $GLOBALS['db']->getCol($sql));
}
else
{
return '';
}
}
/**
* 取得購物車中已有的優惠活動及數量
* @return array
*/
function cart_favourable()
{
$sql_where = $_SESSION['user_id']>0 ? "user_id='". $_SESSION['user_id'] ."' " : "session_id = '" . SESS_ID . "' AND user_id=0 ";
$list = array();
/* 代碼修改購物車選擇性結算_start By www.0769web.net 將這塊替換掉*/
$sql = "SELECT is_gift, COUNT(*) AS num " .
"FROM " . $GLOBALS['ecs']->table('cart') .
" WHERE $sql_where " .
" AND rec_type = '" . CART_GENERAL_GOODS . "'" .
" AND is_gift > 0" .
" GROUP BY is_gift";
/* 代碼修改購物車選擇性結算_end By www.0769web.net */
$res = $GLOBALS['db']->query($sql);
while ($row = $GLOBALS['db']->fetchRow($res))
{
$list[$row['is_gift']] = $row['num'];
}
return $list;
}
/**
* 購物車中是否已經有某優惠
* @param array $favourable 優惠活動
* @param array $cart_favourable購物車中已有的優惠活動及數量
*/
function favourable_used($favourable, $cart_favourable)
{
if ($favourable['act_type'] == FAT_GOODS)
{
return isset($cart_favourable[$favourable['act_id']]) &&
$cart_favourable[$favourable['act_id']] >= $favourable['act_type_ext'] &&
$favourable['act_type_ext'] > 0;
}
else
{
return isset($cart_favourable[$favourable['act_id']]);
}
}
/**
* 添加優惠活動(贈品)到購物車
* @param int $act_id 優惠活動id
* @param int $id 贈品id
* @param float $price 贈品價格
*/
function add_gift_to_cart($act_id, $id, $price)
{
$sql = "INSERT INTO " . $GLOBALS['ecs']->table('cart') . " (" .
"user_id, session_id, goods_id, goods_sn, goods_name, market_price, goods_price, ".
"goods_number, is_real, extension_code, parent_id, is_gift, rec_type ) ".
"SELECT '$_SESSION[user_id]', '" . SESS_ID . "', goods_id, goods_sn, goods_name, market_price, ".
"'$price', 1, is_real, extension_code, 0, '$act_id', '" . CART_GENERAL_GOODS . "' " .
"FROM " . $GLOBALS['ecs']->table('goods') .
" WHERE goods_id = '$id'";
$GLOBALS['db']->query($sql);
}
/**
* 添加優惠活動(非贈品)到購物車
* @param int $act_id 優惠活動id
* @param string $act_name 優惠活動name
* @param float $amount 優惠金額
*/
function add_favourable_to_cart($act_id, $act_name, $amount)
{
$sql = "INSERT INTO " . $GLOBALS['ecs']->table('cart') . "(" .
"user_id, session_id, goods_id, goods_sn, goods_name, market_price, goods_price, ".
"goods_number, is_real, extension_code, parent_id, is_gift, rec_type ) ".
"VALUES('$_SESSION[user_id]', '" . SESS_ID . "', 0, '', '$act_name', 0, ".
"'" . (-1) * $amount . "', 1, 0, '', 0, '$act_id', '" . CART_GENERAL_GOODS . "')";
$GLOBALS['db']->query($sql);
}
/**
* 取得購物車中某優惠活動範圍內的總金額
* @param array $favourable 優惠活動
* @return float
*/
function cart_favourable_amount($favourable)
{
$sql_where = $_SESSION['user_id']>0 ? "c.user_id='". $_SESSION['user_id'] ."' " : "c.session_id = '" . SESS_ID . "' AND c.user_id=0 ";//增加購物車選擇性結算--開始--青蜂網絡www.0769web.net
/* 查詢優惠範圍內商品總額的sql */
$sql = "SELECT SUM(c.goods_price * c.goods_number) " .
"FROM " . $GLOBALS['ecs']->table('cart') . " AS c, " . $GLOBALS['ecs']->table('goods') . " AS g " .
"WHERE c.goods_id = g.goods_id " .
//"AND c.session_id = '" . SESS_ID . "' " .//青蜂網絡購物車選擇性結算註釋
"AND $sql_where " .//增加購物車選擇性結算--青蜂網絡www.0769web.net
"AND c.rec_type = '" . CART_GENERAL_GOODS . "' " .
"AND c.is_gift = 0 " .
"AND c.goods_id > 0 ";
/* 根據優惠範圍修正sql */
if ($favourable['act_range'] == FAR_ALL)
{
// sql do not change
}
elseif ($favourable['act_range'] == FAR_CATEGORY)
{
/* 取得優惠範圍分類的所有下級分類 */
$id_list = array();
$cat_list = explode(',', $favourable['act_range_ext']);
foreach ($cat_list as $id)
{
$id_list = array_merge($id_list, array_keys(cat_list(intval($id), 0, false)));
}
$sql .= "AND g.cat_id " . db_create_in($id_list);
}
elseif ($favourable['act_range'] == FAR_BRAND)
{
$id_list = explode(',', $favourable['act_range_ext']);
$sql .= "AND g.brand_id " . db_create_in($id_list);
}
else
{
$id_list = explode(',', $favourable['act_range_ext']);
$sql .= "AND g.goods_id " . db_create_in($id_list);
}
/* 優惠範圍內的商品總額 */
return $GLOBALS['db']->getOne($sql);
}
function get_consignee_list_mb5()
{
$consignee = get_consignee($_SESSION['user_id']);
$sql="SELECT * FROM " . $GLOBALS['ecs']->table('user_address') .
" WHERE user_id = '". $_SESSION['user_id'] ."' order by address_id ";
$consignee_list_mb5 = $GLOBALS['db']->getAll($sql);
foreach ($consignee_list_mb5 as $cons_key => $cons_val)
{
$consignee_list_mb5[$cons_key]['address_short_name'] = $cons_val['consignee']."<br>";
$consignee_list_mb5[$cons_key]['address_short_name'] .= get_region_info($cons_val['province'])."-";
$consignee_list_mb5[$cons_key]['address_short_name'] .= get_region_info($cons_val['city'])."-";
$consignee_list_mb5[$cons_key]['address_short_name'] .= get_region_info($cons_val['district'])."&nbsp;";
$consignee_list_mb5[$cons_key]['address_short_name'] .= sub_str($cons_val['address'],16);
$consignee_list_mb5[$cons_key]['address_short_name'] .= $cons_val['zipcode'] ? (",".$cons_val['zipcode']) : "";
$consignee_list_mb5[$cons_key]['address_short_name'] .= "<br>".($cons_val['tel'] != '--' ? $cons_val['tel'] : $cons_val['mobile']);
if ($consignee['address_id'] == $cons_val['address_id'])
{
$consignee_list_mb5[$cons_key]['def_addr'] =1;
$have_def_addr=1;
}
}
if ( count($consignee_list_mb5) && !$have_def_addr){ $consignee_list_mb5[0]['def_addr'] =1; }
return $consignee_list_mb5;
}
?>