/* 插入订单商品 */ $sql = "INSERT INTO " . $ecs->table('order_goods') . "( " . "order_id, goods_id, goods_name, goods_sn, 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, 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}'"; $db->query($sql); /* 处理余额、积分、红包 */ if ($order['user_id'] > 0 && $order['surplus'] > 0) { log_account_change($order['user_id'], $order['surplus'] * -1, 0, 0, 0, sprintf('支付订单 %s', $order['order_sn'])); } if ($order['user_id'] > 0 && $order['integral'] > 0) { log_account_change($order['user_id'], 0, 0, 0, $order['integral'] * -1, sprintf('支付订单 %s', $order['order_sn'])); } /* 如果使用库存,且下订单时减库存,则减少库存 */ if ($_CFG['use_storage'] == '1' && $_CFG['stock_dec_time'] == SDT_PLACE) { change_order_goods_storage($order['order_id'], true, SDT_PLACE); } /* 清空购物车 */ clear_cart($flow_type); /* 清除缓存,否则买了商品,但是前台页面读取缓存,商品数量不减少 */ clear_all_files(); if (!empty($order['shipping_name'])) { $order['shipping_name'] = trim(stripcslashes($order['shipping_name'])); } /* 取得支付信息,生成支付代码 */ 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'](); $order['log_id'] = insert_pay_log($new_order_id, $order['order_amount'], PAY_ORDER); $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($specs) && $product_info['product_number'] == 0 && $_CFG['use_storage'] == 1) { show_message($_LANG['eg_error_number'], array($_LANG['back_up_page']), array($back_act), 'error'); } /* 查询:查询规格名称和值,不考虑价格 */ $attr_list = array(); $sql = "SELECT a.attr_name, g.attr_value " . "FROM " . $ecs->table('goods_attr') . " AS g, " . $ecs->table('attribute') . " AS a " . "WHERE g.attr_id = a.attr_id " . "AND g.goods_attr_id " . db_create_in($specs); $res = $db->query($sql); while ($row = $db->fetchRow($res)) { $attr_list[] = $row['attr_name'] . ': ' . $row['attr_value']; } $goods_attr = join(chr(13) . chr(10), $attr_list); /* 更新:清空购物车中所有团购商品 */ include_once ROOT_PATH . 'includes/lib_order.php'; clear_cart(CART_EXCHANGE_GOODS); /* 更新:加入购物车 */ $number = 1; $cart = array('user_id' => $_SESSION['user_id'], 'session_id' => SESS_ID, 'goods_id' => $goods['goods_id'], 'product_id' => $product_info['product_id'], 'goods_sn' => addslashes($goods['goods_sn']), 'goods_name' => addslashes($goods['goods_name']), 'market_price' => $goods['market_price'], 'goods_price' => 0, 'goods_number' => $number, 'goods_attr' => addslashes($goods_attr), 'goods_attr_id' => $specs, 'is_real' => $goods['is_real'], 'extension_code' => addslashes($goods['extension_code']), 'parent_id' => 0, 'rec_type' => CART_EXCHANGE_GOODS, 'is_gift' => 0); $db->autoExecute($ecs->table('cart'), $cart, 'INSERT'); /* 记录购物流程类型:团购 */ $_SESSION['flow_type'] = CART_EXCHANGE_GOODS; $_SESSION['extension_code'] = 'exchange_goods'; $_SESSION['extension_id'] = $goods_id; /* 进入收货人页面 */ ecs_header("Location: ./flow.php?step=consignee\n"); exit; } /*------------------------------------------------------ */ //-- PRIVATE FUNCTION /*------------------------------------------------------ */
if ($snatch['product_id'] > 0) { $product_info = get_good_products($snatch['goods_id'], 'AND product_id = ' . $snatch['product_id']); $goods_attr_id = str_replace('|', ',', $product_info[0]['goods_attr']); $attr_list = array(); $sql = "SELECT a.attr_name, g.attr_value " . "FROM " . $ecs->table('goods_attr') . " AS g, " . $ecs->table('attribute') . " AS a " . "WHERE g.attr_id = a.attr_id " . "AND g.goods_attr_id " . db_create_in($goods_attr_id); $res = $db->query($sql); while ($row = $db->fetchRow($res)) { $attr_list[] = $row['attr_name'] . ': ' . $row['attr_value']; } $goods_attr = join('', $attr_list); } else { $snatch['product_id'] = 0; } /* 清空购物车中所有商品 */ include_once ROOT_PATH . 'includes/lib_order.php'; clear_cart(CART_SNATCH_GOODS); /* 加入购物车 */ $cart = array('user_id' => $_SESSION['user_id'], 'session_id' => SESS_ID, 'goods_id' => $snatch['goods_id'], 'product_id' => $snatch['product_id'], 'goods_sn' => addslashes($snatch['goods_sn']), 'goods_name' => addslashes($snatch['goods_name']), 'market_price' => $snatch['market_price'], 'goods_price' => $result['buy_price'], 'goods_number' => 1, 'goods_attr' => $goods_attr, 'goods_attr_id' => $goods_attr_id, 'is_real' => $snatch['is_real'], 'extension_code' => addslashes($snatch['extension_code']), 'parent_id' => 0, 'rec_type' => CART_SNATCH_GOODS, 'is_gift' => 0); $db->autoExecute($ecs->table('cart'), $cart, 'INSERT'); /* 记录购物流程类型:夺宝奇兵 */ $_SESSION['flow_type'] = CART_SNATCH_GOODS; $_SESSION['extension_code'] = 'snatch'; $_SESSION['extension_id'] = $id; /* 进入收货人页面 */ ecs_header("Location: ./flow.php?step=consignee\n"); exit; } /** * 取得用户对当前活动的所出过的价格 * * @access public
$attr_list = array(); $sql = "SELECT a.attr_name, g.attr_value " . "FROM " . $ecs->table('goods_attr') . " AS g, " . $ecs->table('attribute') . " AS a " . "WHERE g.attr_id = a.attr_id " . "AND g.goods_attr_id " . db_create_in($specs); $res = $db->query($sql); while ($row = $db->fetchRow($res)) { $attr_list[] = $row['attr_name'] . ': ' . $row['attr_value']; } $goods_attr = join(chr(13) . chr(10), $attr_list); /* 更新:清空购物车中所有团购商品 */ include_once(ROOT_PATH . 'includes/lib_order.php'); clear_cart(CART_GROUP_BUY_GOODS); /* 更新:加入购物车 */ $goods_price = $group_buy['deposit'] > 0 ? $group_buy['deposit'] : $group_buy['cur_price']; $cart = array( 'user_id' => $_SESSION['user_id'], 'session_id' => SESS_ID, 'goods_id' => $group_buy['goods_id'], 'product_id' => $product_info['product_id'], 'goods_sn' => addslashes($goods['goods_sn']), 'goods_name' => addslashes($goods['goods_name']), 'market_price' => $goods['market_price'], 'goods_price' => $goods_price, 'goods_number' => $number, 'goods_attr' => addslashes($goods_attr), 'goods_attr_id' => $specs,
// Unset all orders left in the cart after the restaurant is closed clear_cart(); if ($restaurant_closed === 1) { echo '<p class="notice">We\'re sorry but it has already passed the last call</p>'; } elseif ($restaurant_closed === 2) { echo '<p class="notice">We\'re sorry but the restaurant is closed</p>'; } echo '</div>'; include "_includes/bottomBar.php"; require_once "_includes/bottom_bar_jquery_script.php"; exit; } // end if the restaurant is closed //Querying server status if (get_server_value("online_ordering_available") == 0) { clear_cart(); echo '<p class="notice">We\'re sorry, online ordering is temporarily seized by the management team</p>'; echo '</div>'; include "_includes/bottomBar.php"; require_once "_includes/bottom_bar_jquery_script.php"; exit; } //End Querying server status ?> <?php if (isset($alert)) { echo "<p class='notice'>" . $alert . "</p>"; } ?>
function if_cust_not_login_then_redirect() { //query for url set $url_set = get_server_value("url_set"); // check if logged in if (check_cust_login() === false) { if ($url_set == 1 || $url_set == 2) { $location = "login.php"; } elseif ($url_set == 3) { $location = "https://www.nayadathai.com/login.php"; } redirect($location); } elseif (get_server_value("login") != 1) { clear_cart(); if ($url_set == 1 || $url_set == 2) { $location = "login.php?action=logout"; } elseif ($url_set == 3) { $location = "https://www.nayadathai.com/login.php?action=logout"; } redirect($location); } else { return true; } }
if ($auction['product_id'] > 0) { $product_info = get_good_products($auction['goods_id'], 'AND product_id = ' . $auction['product_id']); $goods_attr_id = str_replace('|', ',', $product_info[0]['goods_attr']); $attr_list = array(); $sql = "SELECT a.attr_name, g.attr_value " . "FROM " . $ecs->table('goods_attr') . " AS g, " . $ecs->table('attribute') . " AS a " . "WHERE g.attr_id = a.attr_id " . "AND g.goods_attr_id " . db_create_in($goods_attr_id); $res = $db->query($sql); while ($row = $db->fetchRow($res)) { $attr_list[] = $row['attr_name'] . ': ' . $row['attr_value']; } $goods_attr = join(chr(13) . chr(10), $attr_list); } else { $auction['product_id'] = 0; } /* 清空购物车中所有拍卖商品 */ include_once ROOT_PATH . 'includes/lib_order.php'; clear_cart(CART_AUCTION_GOODS); /* 加入购物车 */ $cart = array('user_id' => $user_id, 'session_id' => SESS_ID, 'goods_id' => $auction['goods_id'], 'goods_sn' => addslashes($goods['goods_sn']), 'goods_name' => addslashes($goods['goods_name']), 'market_price' => $goods['market_price'], 'goods_price' => $auction['last_bid']['bid_price'], 'goods_number' => 1, 'goods_attr' => $goods_attr, 'goods_attr_id' => $goods_attr_id, 'is_real' => $goods['is_real'], 'extension_code' => addslashes($goods['extension_code']), 'parent_id' => 0, 'rec_type' => CART_AUCTION_GOODS, 'is_gift' => 0); $db->autoExecute($ecs->table('cart'), $cart, 'INSERT'); /* 记录购物流程类型:团购 */ $_SESSION['flow_type'] = CART_AUCTION_GOODS; $_SESSION['extension_code'] = 'auction'; $_SESSION['extension_id'] = $id; /* 进入收货人页面 */ ecs_header("Location: ./flow.php?step=consignee\n"); exit; } /** * 取得拍卖活动数量 * @return int */
public static function add_to_cart($goods, $goods_id) { global $db; global $ecs; include_once 'includes/cls_json.php'; include_once 'includes/lib_order.php'; $result = array('error' => 0, 'message' => '', 'content' => '', 'goods_id' => ''); if (empty($goods)) { $result['error'] = 1; return json_encode($result); } $json = new JSON(); $goods = $json->decode($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 = $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; return 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($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['goods_id'] = stripslashes($goods->goods_id); $result['content'] = insert_right_cart_info(); $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); if (is_array($goods->spec)) { $result['product_spec'] = implode(',', $goods->spec); } else { $result['product_spec'] = $goods->spec; } } } $sql = "select * from " . $ecs->table('cart') . " WHERE session_id='" . SESS_ID . "'"; $goods = $db->getAll($sql); foreach ($goods as $val) { $total += $val['goods_price'] * $val['goods_number']; //计算额外餐具的价格 if ($_SESSION['extra_fork'][$val['goods_id']]) { $total += $_SESSION['extra_fork'][$val['goods_id']] / 2; } //蜡烛这玩意 需要在order页面返回给前端添加到订单里,其他商品不需要这么做 if ($val['goods_id'] == 61) { $result['data'] = $val; } } $result['confirm_type'] = !empty($_CFG['cart_confirm']) ? $_CFG['cart_confirm'] : 2; $result['order_total'] = MES_Order::get_total_price_in_cart(); return json_encode($result); }
public function done () { global $ecs,$db,$_CFG; include_once(RPC_ROOT.'includes/lib_clips_ec.php'); include_once(RPC_ROOT.'includes/lib_payment.php'); /* 取得购物类型 */ $flow_type = isset($_SESSION['flow_type']) ? intval($_SESSION['flow_type']) : CART_GENERAL_GOODS; /* 检查购物车中是否有商品 */ $sql = "SELECT COUNT(*) FROM " . $ecs->table('cart') ." WHERE session_id = '" . SESS_ID . "' " . "AND parent_id = 0 AND is_gift = 0 AND rec_type = '$flow_type'"; if ($db->getOne($sql) == 0) { $msg = rpcLang('flow.php', 'no_goods_in_cart'); jsonExit("{\"status\":\"$msg\"}"); } /* 检查商品库存,如果使用库存,且下订单时减库存,则减少库存 */ if ($_CFG['use_storage'] == '1' && $_CFG['stock_dec_time'] == SDT_PLACE) { $cart_goods_stock = get_cart_goods(); $_cart_goods_stock = array(); foreach ($cart_goods_stock['goods_list'] as $value) { $_cart_goods_stock[$value['rec_id']] = $value['goods_number']; } zy_flow_cart_stock($_cart_goods_stock); unset($cart_goods_stock, $_cart_goods_stock); } /* * 检查用户是否已经登录 * 如果用户已经登录了则检查是否有默认的收货地址 * 如果没有登录则跳转到登录和注册页面 */ if (empty($_SESSION['direct_shopping']) && $_SESSION['user_id'] == 0) { /* 用户没有登录且没有选定匿名购物,转向到登录页面 */ $msg = rpcLang('user.php', 'nologin'); jsonExit("{\"status\":\"$msg\"}"); } $consignee = get_consignee($_SESSION['user_id']); /* 检查收货人信息是否完整 */ if (!check_consignee_info($consignee, $flow_type)) { $msg = rpcLang('flow.php', 'user_address_not_full'); jsonExit("{\"status\":\"$msg\"}"); } $_GET['how_oos'] = isset($_GET['how_oos']) ? intval($_GET['how_oos']) : 0; $_GET['card_message'] = isset($_GET['card_message']) ? htmlspecialchars($_GET['card_message']) : ''; $_GET['inv_type'] = !empty($_GET['inv_type']) ? htmlspecialchars($_GET['inv_type']) : ''; $_GET['inv_payee'] = isset($_GET['inv_payee']) ? htmlspecialchars($_GET['inv_payee']) : ''; $_GET['inv_content'] = isset($_GET['inv_content']) ? htmlspecialchars($_GET['inv_content']) : ''; $_GET['postscript'] = isset($_GET['postscript']) ? htmlspecialchars($_GET['postscript']) : ''; $referer = empty($_GET['referer']) ? 'Android':trim($_GET['referer']); $order = array( //'shipping_id' => intval($_POST['shipping']), 'shipping_id' => intval($_GET['shipping']),//快递id 'pay_id' => intval($_GET['payment']),//支付方式id 'pack_id' => isset($_GET['pack']) ? intval($_GET['pack']) : 0,//包装 'card_id' => isset($_GET['card']) ? intval($_GET['card']) : 0,//贺卡 'card_message' => trim($_GET['card_message']), 'surplus' => isset($_POST['surplus']) ? floatval($_POST['surplus']) : 0.00, 'integral' => isset($_POST['integral']) ? intval($_POST['integral']) : 0, 'bonus_id' => isset($_GET['bonus']) ? intval($_GET['bonus']) : 0, 'need_inv' => empty($_POST['need_inv']) ? 0 : 1, '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(EC_CHARSET == 'utf-8'){ $order['inv_type'] = gbktoutf8($_GET['inv_type']); $order['inv_payee'] = gbktoutf8(trim($_GET['inv_payee'])); $order['inv_content'] = gbktoutf8($_GET['inv_content']); }else{ $order['inv_type'] = utf8togbk($_GET['inv_type']); $order['inv_payee'] = utf8togbk(trim($_GET['inv_payee'])); $order['inv_content'] = utf8togbk($_GET['inv_content']); } /* 扩展信息 */ 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']; /* #检查积分余额是否合法 $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)) { $msg = rpcLang('flow.php', 'no_goods_in_cart'); jsonExit("{\"status\":\"$msg\"}"); } /* 检查商品总额是否达到最低限购金额 */ if ($flow_type == CART_GENERAL_GOODS && cart_amount(true, CART_GENERAL_GOODS) < $_CFG['min_goods_amount']) { $msg = rpcLang('flow.php', 'goods_amount_not_enough'); jsonExit("{\"status\":\"$msg\"}"); } /* 收货人信息 */ foreach ($consignee as $key => $value) { $order[$key] = addslashes($value); } /* 订单中的总额 */ $total = order_fee($order, $cart_goods, $consignee); $order['bonus'] = $total['bonus']; $order['goods_amount'] = $total['goods_price']; $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, '.', ''); /* 如果全部使用余额支付,检查余额是否足够 */ 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 { $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 = unserialize($_CFG['affiliate']); 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, 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, 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'"; $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); } error_log('1',3,'flow.log'); /* 给商家发邮件 */ /* 增加是否给客服发送邮件选项 */ if ($_CFG['send_service_email'] && $_CFG['service_email'] != '') { error_log('2',3,'flow.log'); $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']); } error_log('2',3,'flow.log'); /* 如果需要,发短信 */ if ($_CFG['sms_order_placed'] == '1' && $_CFG['sms_shop_mobile'] != '') { include_once(RPC_ROOT.'includes/cls_sms.php'); $sms = new sms(); $msg = $order['pay_status'] == PS_UNPAYED ? $_LANG['order_placed_sms'] : $_LANG['order_placed_sms'] . '[' . $_LANG['sms_paid'] . ']'; $sms->send($_CFG['sms_shop_mobile'], sprintf($msg, $order['consignee'], $order['tel']), 0); } error_log('3',3,'flow.log'); /* 如果订单金额为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'"; $res = $GLOBALS['db']->getAll($sql); error_log('4',3,'flow.log'); $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())); error_log('5',3,'flow.log'); /* 如果订单用户不为空,计算积分,并发给用户;发红包 */ 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'])); error_log('6',3,'flow.log'); /* 发放红包 */ send_order_bonus($order['order_id']); } } } } } /* 清空购物车 */ clear_cart($flow_type); error_log('7',3,'flow.log'); /* 清除缓存,否则买了商品,但是前台页面读取缓存,商品数量不减少 */ clear_all_files(); /* 插入支付日志 */ //$order['log_id'] = insert_pay_log($new_order_id, $order['order_amount'], PAY_ORDER); error_log('8',3,'flow.log'); /*取得支付代码 #取得支付信息,生成支付代码 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'])); } error_log('9',3,'flow.log'); /* #订单信息 $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']); $order_done = array('order'=>$order,'total'=>$total,'cart_goods'=>$cart_goods); //var_dump($order_done);exit; error_log('10',3,'flow.log'); $order_id = $order['order_id']; $price = $order['order_amount']; $order = array ('order_id'=>$order_id,'order_number'=>$order['order_sn'],'price'=>$price) ; error_log('11',3,'flow.log'); //print_r($order);die; jsonExit($order); }
// CONGRATULATE THE USER WITH FLASH MESSAGE (NO IDEA HOW FOR NOW) //redirect_to("index.php"); //update history (names of products , time of purchase , amount paid) as a batch } else { // clear the cart from the invalid cart_items clear_invalid_items($cart_id, $invalid_items); echo "<body onload='myFunction()'>"; // redirect foreach ($invalid_items as $invalid_item) { $item_name = get_item($invalid_item)[1]; $_SESSION['message'] = "Sorry {$item_name} Just Got Out of Stock!!"; } } mysqli_free_result($results); // free some memory } } if (isset($_POST['remove'])) { remove_item_from_cart($_POST['id']); } if (isset($_POST['clear'])) { clear_cart($cart_id); } ?> <script> function myFunction() { window.location.replace("http://localhost/index.php"); } </script>
function action_buy() { $smarty = $GLOBALS['smarty']; $db = $GLOBALS['db']; $ecs = $GLOBALS['ecs']; /* 查询:判断是否登录 */ if ($_SESSION['user_id'] <= 0) { show_message($_LANG['ps_error_login'], '', '', 'error'); } /* 查询:取得参数:预售活动id */ $pre_sale_id = isset($_POST['pre_sale_id']) ? intval($_POST['pre_sale_id']) : 0; if ($pre_sale_id <= 0) { ecs_header("Location: pre_sale.php\n"); exit; } /* 查询:取得数量 */ $number = isset($_POST['number']) ? intval($_POST['number']) : 1; $number = $number < 1 ? 1 : $number; /* 查询:取得预售活动信息 */ $pre_sale = pre_sale_info($pre_sale_id, $number); if (empty($pre_sale)) { ecs_header("Location: pre_sale.php\n"); exit; } /* 查询:检查预售活动是否是进行中 */ if ($pre_sale['status'] != PSS_UNDER_WAY) { show_message($_LANG['ps_error_status'], '', '', 'error'); } /* 查询:取得预售商品信息 */ $goods = goods_info($pre_sale['goods_id']); if (empty($goods)) { ecs_header("Location: pre_sale.php\n"); exit; } /* 查询:判断数量是否足够 */ if ($pre_sale['restrict_amount'] > 0 && $number > $pre_sale['restrict_amount'] - $pre_sale['valid_goods'] || $number > $goods['goods_number']) { show_message($_LANG['ps_error_goods_lacking'], '', '', 'error'); } /* 查询:取得规格 */ $specs = ''; foreach ($_POST as $key => $value) { if (strpos($key, 'spec_') !== false) { $specs .= ',' . intval($value); } } $specs = trim($specs, ','); /* 查询:如果商品有规格则取规格商品信息 配件除外 */ if ($specs) { $_specs = explode(',', $specs); $product_info = get_products_info($goods['goods_id'], $_specs); } empty($product_info) ? $product_info = array('product_number' => 0, 'product_id' => 0) : ''; /* 查询:判断指定规格的货品数量是否足够 */ if ($specs && $number > $product_info['product_number'] && false) { show_message($_LANG['ps_error_goods_lacking'], '', '', 'error'); } /* 查询:查询规格名称和值,不考虑价格 */ $attr_list = array(); $sql = "SELECT a.attr_name, g.attr_value " . "FROM " . $ecs->table('goods_attr') . " AS g, " . $ecs->table('attribute') . " AS a " . "WHERE g.attr_id = a.attr_id " . "AND g.goods_attr_id " . db_create_in($specs); $res = $db->query($sql); while ($row = $db->fetchRow($res)) { $attr_list[] = $row['attr_name'] . ': ' . $row['attr_value']; } $goods_attr = join(chr(13) . chr(10), $attr_list); /* 更新:清空购物车中所有预售商品 */ include_once ROOT_PATH . 'includes/lib_order.php'; clear_cart(CART_pre_sale_GOODS); /* 更新:加入购物车 */ $goods_price = $pre_sale['deposit'] > 0 ? $pre_sale['deposit'] : $pre_sale['cur_price']; $cart = array('user_id' => $_SESSION['user_id'], 'session_id' => SESS_ID, 'goods_id' => $pre_sale['goods_id'], 'product_id' => $product_info['product_id'], 'goods_sn' => addslashes($goods['goods_sn']), 'goods_name' => addslashes($goods['goods_name']), 'market_price' => $goods['market_price'], 'goods_price' => $goods_price, 'goods_number' => $number, 'goods_attr' => addslashes($goods_attr), 'goods_attr_id' => $specs, 'is_real' => $goods['is_real'], 'extension_code' => addslashes($goods['extension_code']), 'parent_id' => 0, 'rec_type' => CART_PRE_SALE_GOODS, 'is_gift' => 0); $db->autoExecute($ecs->table('cart'), $cart, 'INSERT'); $_SESSION['sel_cartgoods'] = $db->insert_id(); $_SESSION['pre_sale_cart'] = $cart; /* 更新:记录购物流程类型:预售 */ $_SESSION['flow_type'] = CART_PRE_SALE_GOODS; $_SESSION['extension_code'] = PRE_SALE_CODE; $_SESSION['extension_id'] = $pre_sale_id; /* 进入收货人页面 */ ecs_header("Location: ./flow.php?step=checkout\n"); exit; }
function action_signin() { // 全局变量 // $user = $GLOBALS['user']; $_CFG = $GLOBALS['_CFG']; $_LANG = $GLOBALS['_LANG']; $smarty = $GLOBALS['smarty']; $db = $GLOBALS['db']; $ecs = $GLOBALS['ecs']; if (!empty($_SESSION['captcha_word']) && intval($_CFG['captcha']) & CAPTCHA_ADMIN) { include_once ROOT_PATH . 'includes/cls_captcha.php'; /* 检查验证码是否正确 */ $validator = new captcha(); if (!empty($_POST['captcha']) && !$validator->check_word($_POST['captcha'])) { sys_msg($_LANG['captcha_error'], 1); } } $_POST['username'] = isset($_POST['username']) ? trim($_POST['username']) : ''; $_POST['password'] = isset($_POST['password']) ? trim($_POST['password']) : ''; $user_name = $_POST['username']; if (is_email($user_name)) { $sql = "select user_name from " . $ecs->table('supplier_admin_user') . " where email='" . $user_name . "'"; $username_email = $db->getOne($sql); if ($username_email) { $user_name = $username_email; } } else { if (is_mobile_phone($user_name)) { $sql = "select user_name from " . $ecs->table('supplier_admin_user') . " where mobile_phone='" . $user_name . "'"; $rows = $db->query($sql); $i = 0; while ($row = $db->fetchRow($rows)) { $username_mobile = $row['user_name']; $i = $i + 1; } if ($i > 1) { show_message('本网站有多个会员ID绑定了和您相同的手机号,请使用其他登录方式,如:邮箱或用户名。', $_LANG['relogin_lnk'], 'user.php', 'error'); } if (isset($username_mobile)) { $user_name = $username_mobile; } } } $sql = "SELECT `ec_salt` FROM " . $ecs->table('supplier_admin_user') . " WHERE user_name = '" . $user_name . "'"; $ec_salt = $db->getOne($sql); if (!empty($ec_salt)) { /* 检查密码是否正确 */ $sql = "SELECT user_id, user_name, password, last_login, action_list, last_login,supplier_id,ec_salt" . " FROM " . $ecs->table('supplier_admin_user') . " WHERE user_name = '" . $user_name . "' AND password = '******'password']) . $ec_salt) . "' AND checked=1"; } else { /* 检查密码是否正确 */ $sql = "SELECT user_id, user_name, password, last_login, action_list, last_login,supplier_id,ec_salt" . " FROM " . $ecs->table('supplier_admin_user') . " WHERE user_name = '" . $user_name . "' AND password = '******'password']) . "' AND checked=1"; } $row = $db->getRow($sql); if ($row) { // 登录成功 // set_admin_session($row['user_id'], $row['user_name'], // $row['action_list'], $row['last_login']); $_SESSION['supplier_id'] = $row['supplier_id']; // 店铺的id $_SESSION['supplier_user_id'] = $row['user_id']; // 管理员id $_SESSION['supplier_name'] = $row['user_name']; // 管理员名称 $_SESSION['supplier_action_list'] = $row['action_list']; // 管理员权限 $_SESSION['supplier_last_check'] = $row['last_login']; // 用于保存最后一次检查订单的时间 $new_possword = $row['password']; if (empty($row['ec_salt'])) { $ec_salt = rand(1, 9999); $new_possword = md5(md5($_POST['password']) . $ec_salt); $db->query("UPDATE " . $ecs->table('supplier_admin_user') . " SET ec_salt='" . $ec_salt . "', password='******'" . " WHERE user_id='{$_SESSION['admin_id']}'"); } if ($row['action_list'] == 'all') { $_SESSION['supplier_admin_id'] = $row['user_id']; // 超级管理员的标识管理员id $_SESSION['supplier_shop_guide'] = true; // 超级管理员标识 } // 更新最后登录时间和IP $db->query("UPDATE " . $ecs->table('supplier_admin_user') . " SET last_login='******', last_ip='" . real_ip() . "'" . " WHERE user_id='{$_SESSION['supplier_user_id']}'"); if (isset($_POST['remember'])) { $time = gmtime() + 3600 * 24 * 365; setcookie('ECSCP[supplier_id]', $row['supplier_id'], $time); setcookie('ECSCP[supplier_user_id]', $row['user_id'], $time); setcookie('ECSCP[supplier_pass]', md5($new_possword . $_CFG['hash_code']), $time); } // 清除购物车中过期的数据 clear_cart(); ecs_header("Location: ./index.php\n"); exit; } else { sys_msg($_LANG['login_faild'], 1); } /* * * $sql="SELECT `ec_salt` FROM ". $ecs->table('users') ."WHERE user_name = * '" . $_POST['username']."'"; * $ec_salt =$db->getOne($sql); * if(!empty($ec_salt)) * { * // 检查密码是否正确 * $sql = "SELECT user_id, user_name, password, last_login, ec_salt". * " FROM " . $ecs->table('users') . * " WHERE user_name = '" . $_POST['username']. "' AND password = '******'password']).$ec_salt) . "'"; * } * else * { * // 检查密码是否正确 * $sql = "SELECT user_id, user_name, password, last_login, ec_salt". * " FROM " . $ecs->table('users') . * " WHERE user_name = '" . $_POST['username']. "' AND password = '******'password']) . "'"; * } * $row = $db->getRow($sql); * if ($row) * { * // 检查是否为供货商的管理员 * if (!empty($row['user_id'])) * { * $supplier_id = $db->getOne( "select supplier_id from ". * $ecs->table("supplier") ." where status='1' and user_id=" . * $row['user_id']); * if (empty($supplier_id)) * { * sys_msg("对不起,无效的供货商用户!", 1); * } * } * * // 登录成功 * $_SESSION['supplier_id'] = $supplier_id; * $_SESSION['supplier_user_id'] = $row['user_id']; * $_SESSION['supplier_name'] = $row['user_name']; * * * if (isset($_POST['remember'])) * { * $time = gmtime() + 3600 * 24 * 365; * setcookie('ECSCP[supplier_id]', $supplier_id, $time); * setcookie('ECSCP[supplier_user_id]', $row['user_id'], $time); * setcookie('ECSCP[supplier_pass]', md5($row['password'] . * $_CFG['hash_code']), $time); * } * * // 清除购物车中过期的数据 * clear_cart(); * * ecs_header("Location: ./index.php\n"); * * exit; * } * else * { * sys_msg($_LANG['login_faild'], 1); * } */ }
/** * 添加商品到购物车 * * @access public * @param integer $goods_id 商品编号 * @param integer $num 商品数量 * @param array $spec 规格值对应的id数组 * @param integer $parent 基本件 * @return boolean */ function addto_cart($goods_id, $num = 1, $spec = array(), $parent = 0, $rec_type = 0, $team_sign = 0) { $GLOBALS['err']->clean(); $_parent_id = $parent; //clear_cart(0); clear_cart(5); /* 取得商品信息 */ $sql = "SELECT g.team_num,g.team_price,g.goods_name, g.goods_sn, g.is_on_sale, g.is_real, " . "g.market_price, g.shop_price AS org_price, g.promote_price, g.promote_start_date, " . "g.promote_end_date, g.goods_weight, g.integral, g.extension_code, " . "g.goods_number, g.is_alone_sale, g.is_shipping," . "IFNULL(mp.user_price, g.shop_price * '{$_SESSION['discount']}') AS shop_price " . " FROM " . $GLOBALS['hhs']->table('goods') . " AS g " . " LEFT JOIN " . $GLOBALS['hhs']->table('member_price') . " AS mp " . "ON mp.goods_id = g.goods_id AND mp.user_rank = '{$_SESSION['user_rank']}' " . " WHERE g.goods_id = '{$goods_id}'" . " AND g.is_delete = 0"; $goods = $GLOBALS['db']->getRow($sql); if (empty($goods)) { $GLOBALS['err']->add($GLOBALS['_LANG']['goods_not_exists'], ERR_NOT_EXISTS); return false; } /* 如果是作为配件添加到购物车的,需要先检查购物车里面是否已经有基本件 */ if ($parent > 0) { $sql = "SELECT COUNT(*) FROM " . $GLOBALS['hhs']->table('cart') . " WHERE goods_id='{$parent}' AND session_id='" . SESS_ID . "' AND extension_code <> 'package_buy'"; if ($GLOBALS['db']->getOne($sql) == 0) { $GLOBALS['err']->add($GLOBALS['_LANG']['no_basic_goods'], ERR_NO_BASIC_GOODS); return false; } } /* 是否正在销售 */ if ($goods['is_on_sale'] == 0) { $GLOBALS['err']->add($GLOBALS['_LANG']['not_on_sale'], ERR_NOT_ON_SALE); return false; } /* 不是配件时检查是否允许单独销售 */ if (empty($parent) && $goods['is_alone_sale'] == 0) { $GLOBALS['err']->add($GLOBALS['_LANG']['cannt_alone_sale'], ERR_CANNT_ALONE_SALE); return false; } /* 如果商品有规格则取规格商品信息 配件除外 */ $sql = "SELECT * FROM " . $GLOBALS['hhs']->table('products') . " WHERE goods_id = '{$goods_id}' LIMIT 0, 1"; $prod = $GLOBALS['db']->getRow($sql); if (is_spec($spec) && !empty($prod)) { $product_info = get_products_info($goods_id, $spec); } if (empty($product_info)) { $product_info = array('product_number' => '', 'product_id' => 0); } /* 检查:库存 */ if ($GLOBALS['_CFG']['use_storage'] == 1) { //检查:商品购买数量是否大于总库存 if ($num > $goods['goods_number']) { $GLOBALS['err']->add(sprintf($GLOBALS['_LANG']['shortage'], $goods['goods_number']), ERR_OUT_OF_STOCK); return false; } //商品存在规格 是货品 检查该货品库存 if (is_spec($spec) && !empty($prod)) { if (!empty($spec)) { /* 取规格的货品库存 */ if ($num > $product_info['product_number']) { $GLOBALS['err']->add(sprintf($GLOBALS['_LANG']['shortage'], $product_info['product_number']), ERR_OUT_OF_STOCK); return false; } } } } /* 计算商品的促销价格 */ $spec_price = spec_price($spec); $goods_price = get_final_price($goods_id, $num, true, $spec); $goods['market_price'] += $spec_price; $goods_attr = get_goods_attr_info($spec); $goods_attr_id = join(',', $spec); /* 初始化要插入购物车的基本件数据 */ $parent = array('user_id' => $_SESSION['user_id'], 'session_id' => SESS_ID, 'goods_id' => $goods_id, 'goods_sn' => addslashes($goods['goods_sn']), 'product_id' => $product_info['product_id'], 'goods_name' => addslashes($goods['goods_name']), 'market_price' => $goods['market_price'], 'goods_attr' => addslashes($goods_attr), 'goods_attr_id' => $goods_attr_id, 'is_real' => $goods['is_real'], 'extension_code' => $goods['extension_code'], 'is_gift' => 0, 'is_shipping' => $goods['is_shipping'], 'rec_type' => $rec_type, 'team_sign' => $team_sign); /* 如果该配件在添加为基本件的配件时,所设置的“配件价格”比原价低,即此配件在价格上提供了优惠, */ /* 则按照该配件的优惠价格卖,但是每一个基本件只能购买一个优惠价格的“该配件”,多买的“该配件”不享 */ /* 受此优惠 */ $basic_list = array(); $sql = "SELECT parent_id, goods_price " . "FROM " . $GLOBALS['hhs']->table('group_goods') . " WHERE goods_id = '{$goods_id}'" . " AND goods_price < '{$goods_price}'" . " AND parent_id = '{$_parent_id}'" . " ORDER BY goods_price"; $res = $GLOBALS['db']->query($sql); while ($row = $GLOBALS['db']->fetchRow($res)) { $basic_list[$row['parent_id']] = $row['goods_price']; } /* 取得购物车中该商品每个基本件的数量 */ $basic_count_list = array(); if ($basic_list) { $sql = "SELECT goods_id, SUM(goods_number) AS count " . "FROM " . $GLOBALS['hhs']->table('cart') . " WHERE session_id = '" . SESS_ID . "'" . " AND parent_id = 0" . " AND extension_code <> 'package_buy' " . " AND goods_id " . db_create_in(array_keys($basic_list)) . " GROUP BY goods_id"; $res = $GLOBALS['db']->query($sql); while ($row = $GLOBALS['db']->fetchRow($res)) { $basic_count_list[$row['goods_id']] = $row['count']; } } /* 取得购物车中该商品每个基本件已有该商品配件数量,计算出每个基本件还能有几个该商品配件 */ /* 一个基本件对应一个该商品配件 */ if ($basic_count_list) { $sql = "SELECT parent_id, SUM(goods_number) AS count " . "FROM " . $GLOBALS['hhs']->table('cart') . " WHERE session_id = '" . SESS_ID . "'" . " AND goods_id = '{$goods_id}'" . " AND extension_code <> 'package_buy' " . " AND parent_id " . db_create_in(array_keys($basic_count_list)) . " GROUP BY parent_id"; $res = $GLOBALS['db']->query($sql); while ($row = $GLOBALS['db']->fetchRow($res)) { $basic_count_list[$row['parent_id']] -= $row['count']; } } /* 循环插入配件 如果是配件则用其添加数量依次为购物车中所有属于其的基本件添加足够数量的该配件 */ foreach ($basic_list as $parent_id => $fitting_price) { /* 如果已全部插入,退出 */ if ($num <= 0) { break; } /* 如果该基本件不再购物车中,执行下一个 */ if (!isset($basic_count_list[$parent_id])) { continue; } /* 如果该基本件的配件数量已满,执行下一个基本件 */ if ($basic_count_list[$parent_id] <= 0) { continue; } /* 作为该基本件的配件插入 */ $parent['goods_price'] = max($fitting_price, 0) + $spec_price; //允许该配件优惠价格为0 $parent['goods_number'] = min($num, $basic_count_list[$parent_id]); $parent['parent_id'] = $parent_id; /* 添加 */ $GLOBALS['db']->autoExecute($GLOBALS['hhs']->table('cart'), $parent, 'INSERT'); /* 改变数量 */ $num -= $parent['goods_number']; } /* 如果数量不为0,作为基本件插入 */ if ($num > 0) { /* 检查该商品是否已经存在在购物车中 */ $sql = "SELECT goods_number FROM " . $GLOBALS['hhs']->table('cart') . " WHERE session_id = '" . SESS_ID . "' AND goods_id = '{$goods_id}' " . " AND parent_id = 0 AND goods_attr = '" . get_goods_attr_info($spec) . "' " . " AND extension_code <> 'package_buy' " . " AND rec_type = '{$rec_type}'"; $row = $GLOBALS['db']->getRow($sql); if ($row) { $num += $row['goods_number']; if (is_spec($spec) && !empty($prod)) { $goods_storage = $product_info['product_number']; } else { $goods_storage = $goods['goods_number']; } if ($GLOBALS['_CFG']['use_storage'] == 0 || $num <= $goods_storage) { //下面的不执行 $goods_price = get_final_price($goods_id, $num, true, $spec); $sql = "UPDATE " . $GLOBALS['hhs']->table('cart') . " SET goods_number = '{$num}'" . " , goods_price = '{$goods_price}'" . " WHERE session_id = '" . SESS_ID . "' AND goods_id = '{$goods_id}' " . " AND parent_id = 0 AND goods_attr = '" . get_goods_attr_info($spec) . "' " . " AND extension_code <> 'package_buy' " . "AND rec_type = '{$rec_type}'"; $GLOBALS['db']->query($sql); } else { $GLOBALS['err']->add(sprintf($GLOBALS['_LANG']['shortage'], $num), ERR_OUT_OF_STOCK); return false; } } else { $goods_price = get_final_price($goods_id, $num, true, $spec); $parent['goods_price'] = max($goods_price, 0); if ($rec_type == 5) { $parent['goods_price'] = $goods['team_price']; } $parent['goods_number'] = $num; $parent['parent_id'] = 0; $GLOBALS['db']->autoExecute($GLOBALS['hhs']->table('cart'), $parent, 'INSERT'); } } /* 把赠品删除 */ $sql = "DELETE FROM " . $GLOBALS['hhs']->table('cart') . " WHERE session_id = '" . SESS_ID . "' AND is_gift <> 0"; $GLOBALS['db']->query($sql); return true; }
$user_bargain_id = check_user_bargain($bargain_id, $_SESSION['user_id']); if (empty($user_bargain_id)) { show_message('您还没有参加当前砍价活动', '参加活动', 'bargain.php?id=' . $bargain_id, 'error'); } $bargain = get_user_bargain_detail($user_bargain_id); // 检查活动状态 if ($bargain['user_bargain_status'] == 2) { $sql = "SELECT order_id FROM " . $ecs->table('order_info') . " WHERE user_id = {$_SESSION['user_id']} AND extension_code = 'bargain' AND extension_id = {$bargain_id}"; $order_id = $db->getOne($sql); show_message('您已经参与过这个活动了', '查看订单', 'user.php?act=order_detail&order_id=' . $order_id, 'error'); } elseif ($bargain['user_bargain_status'] == 3) { show_message('当前活动已过期', '返回首页', 'index.php', 'error'); } // 清空购物车中所有拍卖商品 include_once ROOT_PATH . 'include/lib_order.php'; clear_cart(CART_BARGAIN_GOODS); // 加入购物车 $cart = array('user_id' => $_SESSION['user_id'], 'session_id' => SESS_ID, 'goods_id' => $bargain['goods_id'], 'goods_sn' => addslashes($bargain['goods_sn']), 'goods_name' => addslashes($bargain['goods_name']), 'market_price' => $bargain['shop_price'], 'goods_price' => $bargain['shop_price'], 'goods_number' => 1, 'goods_attr' => $bargain['amount_desc'], 'is_real' => 1, 'extension_code' => 'bargain', 'extension_id' => $bargain_id, 'rec_type' => CART_BARGAIN_GOODS, 'is_gift' => 0, 'add_time' => time()); $db->autoExecute($ecs->table('cart'), $cart, 'INSERT'); $_SESSION['extension_code'] = 'bargain'; $_SESSION['extension_id'] = $bargain_id; // 跳转到订单确认页面 ecs_header("Location: ./flow.php?step=checkout&flow_type=" . CART_BARGAIN_GOODS . "\n"); exit; } // 获取当前用户的砍价结果 if (!empty($bargain['detail'])) { foreach ($bargain['detail'] as &$item) { $item['formated_price'] = abs($item['price']); if ($item['friend_id'] == $_SESSION['user_id']) { $bargain['my_bargain_price'] = $item['price'];