1.把order_quick.php放到ecshop系统的目录下。
2.把order.lbi放到模板我文件的library目录下。
3.在把模板目录下的goods.dwt,适当的位置引用库order.lbi
大概可以看到雏形了,不过样式上还得自己修改。
4.本插件使用于包含ecshop2.6.2以上版本
其中order_quick.php文件的内容:
<?php
define('IN_ECS', true);
require(dirname(__FILE__) . '/includes/init.php');
require(ROOT_PATH . 'includes/lib_order.php');
require_once(ROOT_PATH . 'languages/' .$_CFG['lang']. '/shopping_flow.php');
//-- PROCESSOR
if ($_GET['act'] == 'order')
{
//-- 添加商品到购物车
include_once('includes/cls_json.php');
$_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;
$goods = $json->decode($_POST['goods']);
$spec_arr = $goods->spec_arr;
$goods_id = $goods->goods_id;
$number = $goods->number;
$country = $goods->country;
$province = $goods->province;
$city = $goods->city;
$consignee = $goods->consignee;
$email = $goods->email;
$address = $goods->address;
$zipcode = $goods->zipcode;
$tel = $goods->tel;
$mobile = $goods->mobile;
$sign_building = $goods->sign_building;
$best_time = $goods->best_time;
$postscript = $goods->postscript;
$shipping_add = $goods->shipping;
$fee = $goods->fee;
$payment_add = $goods->payment;
$sql = "SELECT goods_number,goods_name,goods_sn,market_price,shop_price "." FROM " .$GLOBALS['ecs']->table('goods'). " WHERE goods_id = ".$goods_id;
$row = $GLOBALS['db']->getRow($sql);
if ($goods->number > $row['goods_number'])
{
$result['error'] = ERR_OUT_OF_STOCK;
$result['goods_id'] = $goods->goods_id;
$result['error'] = 2;
$result['message'] = $_LANG['shortage'];
die($json->encode($result));
}
else
{
// $spec_price = spec_price($spec);
$goods_price = get_final_price($goods_id, 1, true, $spec_arr);
$goods_amount = $goods_price*$number;
// $goods['market_price'] += $spec_price;
$goods_attr = get_goods_attr_info($spec_arr);
$goods_attr_id = join(',', $spec_arr);
$order = array(
'order_sn' => get_order_sn(),
'order_status' => 0,
'pay_status' => 0,
'user_id' => 0,
'consignee' => $consignee,
'country' => $country,
'province' => $province,
'city' => $city,
'email' => $email,
'address' => $address,
'zipcode' => $zipcode,
'tel' => $tel,
'mobile' => $mobile,
'sign_building' => $sign_building,
'best_time' => $best_time,
'add_time' => gmtime(),
'goods_amount' => $goods_amount,
'goods_id' => $goods_id, //
'goods_name' => $row['goods_name'],
'goods_sn' => $row['goods_sn'],
'goods_number' => $number,
'market_price' => $row['market_price'],
'goods_price' => $goods_price,
'goods_attr' => $goods_attr,
'postscript' => $postscript
);
$order['order_sn'] = get_order_sn(); //获取新订单号
$GLOBALS['db']->autoExecute($GLOBALS['ecs']->table('order_info'), $order, 'INSERT');
while ($error_no == 1062); //如果是订单号重复则重新提交数据
$new_order_id = $db->insert_id();
$order['order_id'] = $new_order_id;
$GLOBALS['db']->autoExecute($GLOBALS['ecs']->table('order_goods'), $order, 'INSERT');
$sql="select pay_fee,pay_id,pay_name from " . $GLOBALS['ecs']->table('payment') . " where pay_id=".$payment_add;
//配送方式
$sql = 'SELECT s.shipping_id,s.shipping_code, s.shipping_name, ' .
's.shipping_desc, s.insure, s.support_cod, a.configure ' .
'FROM ' . $GLOBALS['ecs']->table('shipping') . ' AS s, ' .
$GLOBALS['ecs']->table('shipping_area') . ' AS a, ' .
$GLOBALS['ecs']->table('area_region') . ' AS r ' .
"WHERE s.shipping_id = '$shipping_add' " .
'AND r.shipping_area_id = a.shipping_area_id AND a.shipping_id = s.shipping_id AND s.enabled = 1';
$row = $GLOBALS['db']->getRow($sql);
if (!empty($row))
{
$s_config['shipping_id']=$shipping_add;
$s_config['fee']=$fee;
$sql="select shipping_name from " . $GLOBALS['ecs']->table('shipping') . " where shipping_id=".$shipping_add;
$s_config['shipping_name']=$GLOBALS['db']->getOne($sql);
$shipping_config = unserialize_config($row['configure']);
if (isset($shipping_config['pay_fee']))
{
if (strpos($shipping_config['pay_fee'], '%') !== false)
{
$row['pay_fee'] = floatval($shipping_config['pay_fee']) . '%';
}
else
{
$row['pay_fee'] = floatval($shipping_config['pay_fee']);
}
}
else
{
$row['pay_fee'] = 0.00;
}
$s_config['pay_fee']=$row['pay_fee'];
}
$sql="update " . $GLOBALS['ecs']->table('order_info') . " set shipping_name='" . $s_config['shipping_name'] . "' , shipping_id =" . $s_config['shipping_id'] . " , shipping_fee=". $s_config['fee'] . " where order_sn=".$order['order_sn'];
$res = $GLOBALS['db']->query($sql);
//支付方式
$sql="select * from " . $GLOBALS['ecs']->table('payment') . " where pay_id=".$payment_add;
$p_ment=$GLOBALS['db']->getRow($sql);
$p_ment_row['pay_fee'] = $p_ment['pay_fee'];
$p_ment_row['pay_id'] = $p_ment['pay_id'];
$p_ment_row['pay_name'] = $p_ment['pay_name'];
$sql="select shipping_fee,goods_amount from " . $GLOBALS['ecs']->table('order_info') . " where order_sn=".$order['order_sn'];
$p_info=$GLOBALS['db']->getRow($sql);
$p_info_row['shipping_fee'] = $p_info['shipping_fee'];
$p_info_row['goods_amount'] = $p_info['goods_amount'];
if(mb_substr($p_ment['pay_fee'],-1,1)=='%')
{
$pay_fee_bai=mb_substr($p_ment['pay_fee'],0,-1);
$p_ment_row['pay_fee']=round(($p_info_row['shipping_fee']+$p_info_row['goods_amount'])*(($pay_fee_bai+0.023)/100),2);
}
else
{$p_ment_row['pay_fee']=$p_ment_row['pay_fee'];}
$sql="update " . $GLOBALS['ecs']->table('order_info') . " set pay_id=" . $p_ment_row['pay_id'] . " , pay_name ='" . $p_ment_row['pay_name'] . "' , pay_fee=". $p_ment_row['pay_fee'] . " , goods_amount =".$p_info_row['goods_amount'] . " where order_sn=".$order['order_sn'];
$res = $GLOBALS['db']->query($sql);
$orderid="select order_id from " .$GLOBALS['ecs']->table('order_info') . " where order_sn=".$order['order_sn'];
$order_id=$GLOBALS['db']->getOne($orderid);
$sql="update " . $GLOBALS['ecs']->table('order_goods') . " set is_real=1 where order_id=" . $order_id;
$order_query=$GLOBALS['db']->query($sql);
$result['message'] = '<div style="text-align:center;padding:30px;" class="textStrong">您的订单已提交成功,请记住您的订单号:'.$order['order_sn'];
die($json->encode($result));
}
}
?>
goods.php文件的内容:
<?php
define('IN_ECS', true);
require(dirname(__FILE__) . '/includes/init.php');
if ((DEBUG_MODE & 2) != 2)
{
$smarty->caching = true;
}
$affiliate = unserialize($GLOBALS['_CFG']['affiliate']);
$smarty->assign('affiliate', $affiliate);
//-- INPUT
$goods_id = isset($_REQUEST['id']) ? intval($_REQUEST['id']) : 0;
$region = array($consignee['country'], $consignee['province'], $consignee['city'], $consignee['district']);
$shipping_list = available_shipping_list($region);
foreach ($shipping_list AS $key => $val)
{
$shipping_cfg = unserialize_config($val['configure']);
$shipping_fee = 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'] = $shipping_fee;
$shipping_list[$key]['shipping_fee'] = (float)$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);
if ($order['shipping_id'] == 0)
{
$cod = true;
$cod_fee = 0;
}
else
{
$shipping = shipping_info($order['shipping_id']);
$cod = $shipping['support_cod'];
if ($cod)
{
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;
}
}
$payment_list = available_payment_list(1, $cod_fee);
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>';
}
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);
function shipping_info($shipping_id)
{
$sql = 'SELECT * FROM ' . $GLOBALS['ecs']->table('shipping') .
" WHERE shipping_id = '$shipping_id' " .
'AND enabled = 1';
return $GLOBALS['db']->getRow($sql);
}
function available_payment_list($support_cod, $cod_fee = 0, $is_online = false)
{
$sql = 'SELECT pay_id, pay_code, pay_name, pay_fee, pay_desc, pay_config, is_cod' .
' FROM ' . $GLOBALS['ecs']->table('payment') .
' WHERE enabled = 1 ';
if (!$support_cod)
{
$sql .= 'AND is_cod = 0 '; // 如果不支持货到付款
}
if ($is_online)
{
$sql .= "AND is_online = '1' ";
}
$sql .= 'ORDER BY pay_order'; // 排序
$res = $GLOBALS['db']->query($sql);
$list = array();
while ($row = $GLOBALS['db']->fetchRow($res))
{
if ($row['is_cod'] == '1')
{
$row['pay_fee'] = $cod_fee;
}
$row['format_pay_fee'] = strpos($row['pay_fee'], '%') !== false ? $row['pay_fee'] :
price_format($row['pay_fee'], false);
$list[] = $row;
}
//将财付通提升至第二个显示
foreach ($list as $k =>$v)
{
if($v['pay_code'] == 'tenpay')
{
$tenpay = $list[$k];
unset($list[$k]);
array_unshift($list, $tenpay);
}
}
//将快钱提升至第一个显示
foreach ($list as $k =>$v)
{
if($v['pay_code'] == 'kuaiqian')
{
$tenpay = $list[$k];
unset($list[$k]);
array_unshift($list, $tenpay);
}
}
return $list;
}
function available_shipping_list($region_id_list)
{
$sql = 'SELECT distinct s.shipping_id, s.shipping_code, s.shipping_name, ' .
's.shipping_desc, s.insure, s.support_cod, a.configure ' .
'FROM ' . $GLOBALS['ecs']->table('shipping') . ' AS s, ' .
$GLOBALS['ecs']->table('shipping_area') . ' AS a, ' .
$GLOBALS['ecs']->table('area_region') . ' AS r ' .
'WHERE r.shipping_area_id = a.shipping_area_id AND a.shipping_id = s.shipping_id AND s.enabled = 1';
return $GLOBALS['db']->getAll($sql);
}
function unserialize_config($cfg)
{
if (is_string($cfg) && ($arr = unserialize($cfg)) !== false)
{
$config = array();
foreach ($arr AS $key => $val)
{
$config[$val['name']] = $val['value'];
}
return $config;
}
else
{
return false;
}
}
function shipping_fee($shipping_code, $shipping_config, $goods_weight, $goods_amount, $goods_number='')
{
if (!is_array($shipping_config))
{
$shipping_config = unserialize($shipping_config);
}
$filename = ROOT_PATH . 'includes/modules/shipping/' . $shipping_code . '.php';
if (file_exists($filename))
{
include_once($filename);
$obj = new $shipping_code($shipping_config);
return $obj->calculate($goods_weight, $goods_amount, $goods_number);
}
else
{
return 0;
}
}
function shipping_area_info($shipping_id, $region_id_list)
{
$sql = 'SELECT s.shipping_code, s.shipping_name, ' .
's.shipping_desc, s.insure, s.support_cod, a.configure ' .
'FROM ' . $GLOBALS['ecs']->table('shipping') . ' AS s, ' .
$GLOBALS['ecs']->table('shipping_area') . ' AS a, ' .
$GLOBALS['ecs']->table('area_region') . ' AS r ' .
"WHERE s.shipping_id = '$shipping_id' " .
'AND r.shipping_area_id = a.shipping_area_id AND a.shipping_id = s.shipping_id AND s.enabled = 1';
$row = $GLOBALS['db']->getRow($sql);
if (!empty($row))
{
$shipping_config = unserialize_config($row['configure']);
if (isset($shipping_config['pay_fee']))
{
if (strpos($shipping_config['pay_fee'], '%') !== false)
{
$row['pay_fee'] = floatval($shipping_config['pay_fee']) . '%';
}
else
{
$row['pay_fee'] = floatval($shipping_config['pay_fee']);
}
}
else
{
$row['pay_fee'] = 0.00;
}
}
return $row;
}
//-- 改变属性、数量时重新计算商品价格
if (!empty($_REQUEST['act']) && $_REQUEST['act'] == 'price')
{
include('includes/cls_json.php');
$json = new JSON;
$res = array('err_msg' => '', 'result' => '', 'qty' => 1);
$attr_id = isset($_REQUEST['attr']) ? explode(',', $_REQUEST['attr']) : array();
$number = (isset($_REQUEST['number'])) ? intval($_REQUEST['number']) : 1;
if ($goods_id == 0)
{
$res['err_msg'] = $_LANG['err_change_attr'];
$res['err_no'] = 1;
}
else
{
if ($number == 0)
{
$res['qty'] = $number = 1;
}
else
{
$res['qty'] = $number;
}
$shop_price = get_final_price($goods_id, $number, true, $attr_id);
$res['result'] = price_format($shop_price * $number);
}
die($json->encode($res));
}
//-- PROCESSOR
$cache_id = $goods_id . '-' . $_SESSION['user_rank'].'-'.$_CFG['lang'];
$cache_id = sprintf('%X', crc32($cache_id));
if (!$smarty->is_cached('goods.dwt', $cache_id))
{
$smarty->assign('image_width', $_CFG['image_width']);
$smarty->assign('image_height', $_CFG['image_height']);
$smarty->assign('helps', get_shop_help()); // 网店帮助
$smarty->assign('id', $goods_id);
$smarty->assign('type', 0);
$smarty->assign('cfg', $_CFG);
$smarty->assign('promotion', get_promotion_info($goods_id));//促销信息
$smarty->assign('promotion_info', get_promotion_info());
$goods = get_goods_info($goods_id);
if ($goods === false)
{
ecs_header("Location: ./n");
exit;
}
else
{
if ($goods['brand_id'] > 0)
{
$goods['goods_brand_url'] = build_uri('brand', array('bid'=>$goods['brand_id']), $goods['goods_brand']);
}
$shop_price = $goods['shop_price'];
$linked_goods = get_linked_goods($goods_id);
$goods['goods_style_name'] = add_style($goods['goods_name'], $goods['goods_name_style']);
if ($goods['bonus_type_id'] > 0)
{
$time = gmtime();
$sql = "SELECT type_money FROM " . $ecs->table('bonus_type') .
" WHERE type_id = '$goods[bonus_type_id]' " .
" AND send_type = '" . SEND_BY_GOODS . "' " .
" AND send_start_date <= '$time'" .
" AND send_end_date >= '$time'";
$goods['bonus_money'] = floatval($db->getOne($sql));
if ($goods['bonus_money'] > 0)
{
$goods['bonus_money'] = price_format($goods['bonus_money']);
}
}
$smarty->assign('goods', $goods);
$smarty->assign('goods_id', $goods['goods_id']);
$smarty->assign('promote_end_time', $goods['gmt_end_time']);
$smarty->assign('categories', get_categories_tree($goods['cat_id'])); // 分类树
$smarty->assign('keywords', htmlspecialchars($goods['keywords']));
$smarty->assign('description', htmlspecialchars($goods['goods_brief']));
$catlist = array();
foreach(get_parent_cats($goods['cat_id']) as $k=>$v)
{
$catlist[] = $v['cat_id'];
}
assign_template('c', $catlist);
$prev_gid = $db->getOne("SELECT goods_id FROM " .$ecs->table('goods'). " WHERE cat_id=" . $goods['cat_id'] . " AND goods_id > " . $goods['goods_id'] . " AND is_on_sale = 1 AND is_alone_sale = 1 AND is_delete = 0 LIMIT 1");
if (!empty($prev_gid))
{
$prev_good['url'] = build_uri('goods', array('gid' => $prev_gid));
$smarty->assign('prev_good', $prev_good);//上一个商品
}
$next_gid = $db->getOne("SELECT max(goods_id) FROM " . $ecs->table('goods') . " WHERE cat_id=".$goods['cat_id']." AND goods_id < ".$goods['goods_id'] . " AND is_on_sale = 1 AND is_alone_sale = 1 AND is_delete = 0");
if (!empty($next_gid))
{
$next_good['url'] = build_uri('goods', array('gid' => $next_gid));
$smarty->assign('next_good', $next_good);//下一个商品
}
$position = assign_ur_here($goods['cat_id'], $goods['goods_name']);
$smarty->assign('page_title', $position['title']); // 页面标题
$smarty->assign('ur_here', $position['ur_here']); // 当前位置
$properties = get_goods_properties($goods_id); // 获得商品的规格和属性
$sql="SELECT a.attr_id, a.attr_name, a.attr_group, a.is_linked, 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 g.goods_id = '$goods_id' and a.attr_type=3 " .
'ORDER BY a.sort_order, g.attr_price, g.goods_attr_id';
$goods_attr_add = $GLOBALS['db']->getAll($sql);
$goods_arr_add=array();
foreach ($goods_attr_add AS $row)
{
$goods_arr_add[$row['attr_id']]['attr_name'] = $row['attr_name'];
if($row['attr_name']!=NULL)
{
$goods_arr_add[$row['attr_id']]['child'][$row['goods_attr_id']]['attr_value'] = $row['attr_value'];
}
}
$smarty->assign('goods_attr_add', $goods_arr_add);
$smarty->assign('properties', $properties['pro']); // 商品属性
$smarty->assign('specification', $properties['spe']); // 商品规格
$smarty->assign('attribute_linked', get_same_attribute_goods($properties)); // 相同属性的关联商品
$smarty->assign('related_goods', $linked_goods); // 关联商品
$smarty->assign('goods_article_list', get_linked_articles($goods_id)); // 关联文章
$smarty->assign('fittings', get_goods_fittings(array($goods_id))); // 配件
$smarty->assign('rank_prices', get_user_rank_prices($goods_id, $shop_price)); // 会员等级价格
$smarty->assign('pictures', get_goods_gallery($goods_id)); // 商品相册
$smarty->assign('bought_goods', get_also_bought($goods_id)); // 购买了该商品的用户还购买了哪些商品
$smarty->assign('goods_rank', get_goods_rank($goods_id)); // 商品的销售排名
//获取tag
$tag_array = get_tags($goods_id);
$smarty->assign('tags', $tag_array); // 商品的标记
//获取关联tag
$tag_data = "";
foreach($tag_array as $temp_data)
{
$tag_data[] = $temp_data['tag_words'];
}
$tag_linked_data = user_uc_call('get_linked_tags', array($tag_data));
$smarty->assign('tag_linked_data', $tag_linked_data);
//获取关联礼包
$package_goods_list = get_package_goods_list($goods['goods_id']);
$smarty->assign('package_goods_list',$package_goods_list); // 获取关联礼包
assign_dynamic('goods');
$volume_price_list = get_volume_price_list($goods['goods_id'], '1');
$smarty->assign('volume_price_list',$volume_price_list); // 商品优惠价格区间
}
}
if (!empty($_COOKIE['ECS']['history']))
{
$history = explode(',', $_COOKIE['ECS']['history']);
array_unshift($history, $goods_id);
$history = array_unique($history);
while (count($history) > $_CFG['history_number'])
{
array_pop($history);
}
setcookie('ECS[history]', implode(',', $history), gmtime() + 3600 * 24 * 30);
}
else
{
setcookie('ECS[history]', $goods_id, gmtime() + 3600 * 24 * 30);
}
$db->query('UPDATE ' . $ecs->table('goods') . " SET click_count = click_count + 1 WHERE goods_id = '$_REQUEST[id]'");
$smarty->assign('now_time', gmtime()); // 当前系统时间
$smarty->display('goods.dwt', $cache_id);
//-- PRIVATE FUNCTION
function get_linked_goods($goods_id)
{
$sql = 'SELECT g.goods_id, g.goods_name, g.goods_thumb, g.goods_img, g.shop_price AS org_price, ' .
"IFNULL(mp.user_price, g.shop_price * '$_SESSION[discount]') AS shop_price, ".
'g.market_price, g.promote_price, g.promote_start_date, g.promote_end_date ' .
'FROM ' . $GLOBALS['ecs']->table('link_goods') . ' lg ' .
'LEFT JOIN ' . $GLOBALS['ecs']->table('goods') . ' AS g ON g.goods_id = lg.link_goods_id ' .
"LEFT JOIN " . $GLOBALS['ecs']->table('member_price') . " AS mp ".
"ON mp.goods_id = g.goods_id AND mp.user_rank = '$_SESSION[user_rank]' ".
"WHERE lg.goods_id = '$goods_id' AND g.is_on_sale = 1 AND g.is_alone_sale = 1 AND g.is_delete = 0 ".
"LIMIT " . $GLOBALS['_CFG']['related_goods_number'];
$res = $GLOBALS['db']->query($sql);
$arr = array();
while ($row = $GLOBALS['db']->fetchRow($res))
{
$arr[$row['goods_id']]['goods_id'] = $row['goods_id'];
$arr[$row['goods_id']]['goods_name'] = $row['goods_name'];
$arr[$row['goods_id']]['short_name'] = $GLOBALS['_CFG']['goods_name_length'] > 0 ?
sub_str($row['goods_name'], $GLOBALS['_CFG']['goods_name_length']) : $row['goods_name'];
$arr[$row['goods_id']]['goods_thumb'] = get_image_path($row['goods_id'], $row['goods_thumb'], true);
$arr[$row['goods_id']]['goods_img'] = get_image_path($row['goods_id'], $row['goods_img']);
$arr[$row['goods_id']]['market_price'] = price_format($row['market_price']);
$arr[$row['goods_id']]['shop_price'] = price_format($row['shop_price']);
$arr[$row['goods_id']]['url'] = build_uri('goods', array('gid'=>$row['goods_id']), $row['goods_name']);
if ($row['promote_price'] > 0)
{
$arr[$row['goods_id']]['promote_price'] = bargain_price($row['promote_price'], $row['promote_start_date'], $row['promote_end_date']);
$arr[$row['goods_id']]['formated_promote_price'] = price_format($arr[$row['goods_id']]['promote_price']);
}
else
{
$arr[$row['goods_id']]['promote_price'] = 0;
}
}
return $arr;
}
function get_linked_articles($goods_id)
{
$sql = 'SELECT a.article_id, a.title, a.file_url, a.open_type, a.add_time ' .
'FROM ' . $GLOBALS['ecs']->table('goods_article') . ' AS g, ' .
$GLOBALS['ecs']->table('article') . ' AS a ' .
"WHERE g.article_id = a.article_id AND g.goods_id = '$goods_id' AND a.is_open = 1 " .
'ORDER BY a.add_time DESC';
$res = $GLOBALS['db']->query($sql);
$arr = array();
while ($row = $GLOBALS['db']->fetchRow($res))
{
$row['url'] = $row['open_type'] != 1 ?
build_uri('article', array('aid'=>$row['article_id']), $row['title']) : trim($row['file_url']);
$row['add_time'] = local_date($GLOBALS['_CFG']['date_format'], $row['add_time']);
$row['short_title'] = $GLOBALS['_CFG']['article_title_length'] > 0 ?
sub_str($row['title'], $GLOBALS['_CFG']['article_title_length']) : $row['title'];
$arr[] = $row;
}
return $arr;
}
function get_user_rank_prices($goods_id, $shop_price)
{
$sql = "SELECT rank_id, IFNULL(mp.user_price, r.discount * $shop_price / 100) AS price, r.rank_name, r.discount " .
'FROM ' . $GLOBALS['ecs']->table('user_rank') . ' AS r ' .
'LEFT JOIN ' . $GLOBALS['ecs']->table('member_price') . " AS mp ".
"ON mp.goods_id = '$goods_id' AND mp.user_rank = r.rank_id " .
"WHERE r.show_price = 1 OR r.rank_id = '$_SESSION[user_rank]'";
$res = $GLOBALS['db']->query($sql);
$arr = array();
while ($row = $GLOBALS['db']->fetchRow($res))
{
$arr[$row['rank_id']] = array(
'rank_name' => htmlspecialchars($row['rank_name']),
'price' => price_format($row['price']));
}
return $arr;
}
function get_also_bought($goods_id)
{
$sql = 'SELECT COUNT(b.goods_id ) AS num, g.goods_id, g.goods_name, g.goods_thumb, g.goods_img, g.shop_price, g.promote_price, g.promote_start_date, g.promote_end_date ' .
'FROM ' . $GLOBALS['ecs']->table('order_goods') . ' AS a ' .
'LEFT JOIN ' . $GLOBALS['ecs']->table('order_goods') . ' AS b ON b.order_id = a.order_id ' .
'LEFT JOIN ' . $GLOBALS['ecs']->table('goods') . ' AS g ON g.goods_id = b.goods_id ' .
"WHERE a.goods_id = '$goods_id' AND b.goods_id <> '$goods_id' AND g.is_on_sale = 1 AND g.is_alone_sale = 1 AND g.is_delete = 0 " .
'GROUP BY b.goods_id ' .
'ORDER BY num DESC ' .
'LIMIT ' . $GLOBALS['_CFG']['bought_goods'];
$res = $GLOBALS['db']->query($sql);
$key = 0;
$arr = array();
while ($row = $GLOBALS['db']->fetchRow($res))
{
$arr[$key]['goods_id'] = $row['goods_id'];
$arr[$key]['goods_name'] = $row['goods_name'];
$arr[$key]['short_name'] = $GLOBALS['_CFG']['goods_name_length'] > 0 ?
sub_str($row['goods_name'], $GLOBALS['_CFG']['goods_name_length']) : $row['goods_name'];
$arr[$key]['goods_thumb'] = get_image_path($row['goods_id'], $row['goods_thumb'], true);
$arr[$key]['goods_img'] = get_image_path($row['goods_id'], $row['goods_img']);
$arr[$key]['shop_price'] = price_format($row['shop_price']);
$arr[$key]['url'] = build_uri('goods', array('gid'=>$row['goods_id']), $row['goods_name']);
if ($row['promote_price'] > 0)
{
$arr[$key]['promote_price'] = bargain_price($row['promote_price'], $row['promote_start_date'], $row['promote_end_date']);
$arr[$key]['formated_promote_price'] = price_format($arr[$key]['promote_price']);
}
else
{
$arr[$key]['promote_price'] = 0;
}
$key++;
}
return $arr;
}
function get_goods_rank($goods_id)
{
$period = intval($GLOBALS['_CFG']['top10_time']);
if ($period == 1) // 一年
{
$ext = " AND o.add_time > '" . local_strtotime('-1 years') . "'";
}
elseif ($period == 2) // 半年
{
$ext = " AND o.add_time > '" . local_strtotime('-6 months') . "'";
}
elseif ($period == 3) // 三个月
{
$ext = " AND o.add_time > '" . local_strtotime('-3 months') . "'";
}
elseif ($period == 4) // 一个月
{
$ext = " AND o.add_time > '" . local_strtotime('-1 months') . "'";
}
else
{
$ext = '';
}
$sql = 'SELECT IFNULL(SUM(g.goods_number), 0) ' .
'FROM ' . $GLOBALS['ecs']->table('order_info') . ' AS o, ' .
$GLOBALS['ecs']->table('order_goods') . ' AS g ' .
"WHERE o.order_id = g.order_id " .
"AND o.order_status = '" . OS_CONFIRMED . "' " .
"AND o.shipping_status " . db_create_in(array(SS_SHIPPED, SS_RECEIVED)) .
" AND o.pay_status " . db_create_in(array(PS_PAYED, PS_PAYING)) .
" AND g.goods_id = '$goods_id'" . $ext;
$sales_count = $GLOBALS['db']->getOne($sql);
if ($sales_count > 0)
{
$sql = 'SELECT DISTINCT SUM(goods_number) AS num ' .
'FROM ' . $GLOBALS['ecs']->table('order_info') . ' AS o, ' .
$GLOBALS['ecs']->table('order_goods') . ' AS g ' .
"WHERE o.order_id = g.order_id " .
"AND o.order_status = '" . OS_CONFIRMED . "' " .
"AND o.shipping_status " . db_create_in(array(SS_SHIPPED, SS_RECEIVED)) .
" AND o.pay_status " . db_create_in(array(PS_PAYED, PS_PAYING)) . $ext .
" GROUP BY g.goods_id HAVING num > $sales_count";
$res = $GLOBALS['db']->query($sql);
$rank = $GLOBALS['db']->num_rows($res) + 1;
if ($rank > 10)
{
$rank = 0;
}
}
else
{
$rank = 0;
}
return $rank;
}
function get_attr_amount($goods_id, $attr)
{
$sql = "SELECT SUM(attr_price) FROM " . $GLOBALS['ecs']->table('goods_attr') .
" WHERE goods_id='$goods_id' AND " . db_create_in($attr, 'goods_attr_id');
return $GLOBALS['db']->getOne($sql);
}
function get_package_goods_list($goods_id)
{
$now = gmtime();
$sql = "SELECT ga.act_id, ga.act_name, ga.act_desc, ga.goods_id, ga.goods_name, ga.start_time, ".
" ga.end_time, ga.is_finished, ga.ext_info ".
" FROM " . $GLOBALS['ecs']->table('goods_activity') . " AS ga".
", " . $GLOBALS['ecs']->table('package_goods') . " AS pg".
" WHERE pg.package_id = ga.act_id AND ga.start_time <= '" . $now . "' AND ga.end_time >= '" . $now . "' AND pg.goods_id = " . $goods_id .
" ORDER BY ga.act_id";
$res = $GLOBALS['db']->getAll($sql);
foreach ($res as $tempkey => $value)
{
$subtotal = 0;
$row = unserialize($value['ext_info']);
unset($value['ext_info']);
if ($row)
{
foreach ($row as $key=>$val)
{
$res[$tempkey][$key] = $val;
}
}
$sql = "SELECT pg.package_id, pg.goods_id, pg.goods_number, pg.admin_id, ".
" g.goods_sn, g.goods_name, g.market_price, g.goods_thumb, ".
" IFNULL(mp.user_price, g.shop_price * '$_SESSION[discount]') AS rank_price " .
" FROM " . $GLOBALS['ecs']->table('package_goods') . " AS pg ".
" LEFT JOIN ". $GLOBALS['ecs']->table('goods') . " AS g ".
" ON g.goods_id = pg.goods_id ".
" LEFT JOIN " . $GLOBALS['ecs']->table('member_price') . " AS mp ".
"ON mp.goods_id = g.goods_id AND mp.user_rank = '$_SESSION[user_rank]' ".
" WHERE pg.package_id = " . $value['act_id']. " ".
" ORDER BY pg.package_id, pg.goods_id";
$goods_res = $GLOBALS['db']->getAll($sql);
foreach($goods_res as $key => $val)
{
$goods_res[$key]['goods_thumb'] = get_image_path($val['goods_id'], $val['goods_thumb'], true);
$goods_res[$key]['market_price'] = price_format($val['market_price']);
$goods_res[$key]['rank_price'] = price_format($val['rank_price']);
$subtotal += $val['rank_price'] * $val['goods_number'];
}
$res[$tempkey]['goods_list'] = $goods_res;
$res[$tempkey]['subtotal'] = price_format($subtotal);
$res[$tempkey]['saving'] = price_format(($subtotal - $res[$tempkey]['package_price']));
$res[$tempkey]['package_price'] = price_format($res[$tempkey]['package_price']);
}
return $res;
}
?>
order.lbi文件内容:
<meta http-equiv="Content-Type" content="text/html; charset=gbk">
<?php
$_CFG = load_config();
require(ROOT_PATH . 'languages/' . $_CFG['lang'] . '/common.php');
require_once(ROOT_PATH . 'languages/' .$_CFG['lang']. '/shopping_flow.php');
$_LANG['require_field'] = '必填';
$this->assign('lang', $_LANG);
$this->assign('country_list', get_regions());
$this->assign('shop_country', $_CFG['shop_country']);
$this->assign('shop_province_list', get_regions(1, $_CFG['shop_country']));
?>
<div id="order">
<h3 class="h3goods" style="color:#Da251d; padding-left:0px;"><span class="text">快速购物通道</span></h3>
{insert_scripts files='utils.js,region.js,transport.js,shopping_flow.js'}
<script type="text/javascript">
//<![CDATA[
region.isAdmin = false;
{foreach from=$lang.flow_js item=item key=key}
var {$key} = "{$item}";
{/foreach}
{literal}
onload = function() {
if (!document.all)
{
document.forms['theForm'].reset();
}
}
{/literal}
//]]>
</script>
<div class="blank"></div>
<div id="ESC_ORDER">
<form action="javascript:orderQuick({$goods.goods_id})" method="post" name="ECS_FORMORDER" onsubmit="return checkOrderForm_goods(this)" id="ECS_FORMORDER">
<table width="99%" align="center" border="0" cellpadding="5" cellspacing="1" bgcolor="#dddddd" style="margin-top:10px;">
<tr><td colspan="4" bgcolor="#ffffff">{$lang.goods_sn}{$goods.goods_sn} 商品名称:{$goods.goods_style_name} {$lang.shop_price}{$goods.shop_price_formated}</td></tr>
<tr>
<td bgcolor="#ffffff">{$lang.country_province}:</td>
<td colspan="3" bgcolor="#ffffff">
<select name="country" id="selCountries_{$sn}" onchange="region.changed(this, 1, 'selProvinces_{$sn}')" style="border:1px solid #ccc;">
<option value="0">{$lang.please_select}{$name_of_region[0]}</option>
<!-- {foreach from=$country_list item=country} -->
<option value="{$country.region_id}" {if $consignee.country eq $country.region_id}selected{/if}>{$country.region_name}</option>
<!-- {/foreach} -->
</select>
<select name="province" id="selProvinces_{$sn}" onchange="region.changed(this, 2, 'selCities_{$sn}')" style="border:1px solid #ccc;">
<option value="0">{$lang.please_select}{$name_of_region[1]}</option>
<!-- {foreach from=$province_list.$sn item=province} -->
<option value="{$province.region_id}" {if $consignee.province eq $province.region_id}selected{/if}>{$province.region_name}</option>
<!-- {/foreach} -->
</select>
<select name="city" id="selCities_{$sn}" onchange="region.changed(this, 3, 'selDistricts_{$sn}')" style="border:1px solid #ccc;">
<option value="0">{$lang.please_select}{$name_of_region[2]}</option>
<!-- {foreach from=$city_list.$sn item=city} -->
<option value="{$city.region_id}" {if $consignee.city eq $city.region_id}selected{/if}>{$city.region_name}</option>
<!-- {/foreach} -->
</select>
<select name="district" id="selDistricts_{$sn}" {if !$district_list.$sn}style="display:none"{/if} style="border:1px solid #ccc;">
<option value="0">{$lang.please_select}{$name_of_region[3]}</option>
<!-- {foreach from=$district_list.$sn item=district} -->
<option value="{$district.region_id}" {if $consignee.district eq $district.region_id}selected{/if}>{$district.region_name}</option>
<!-- {/foreach} -->
</select>
<span class="textStrong">{$lang.require_field}</span> </td>
</tr>
<tr>
<td bgcolor="#ffffff">{$lang.consignee_name}:</td>
<td bgcolor="#ffffff"><input name="consignee" type="text" class="inputBg" id="consignee_{$sn}" value="{$consignee.consignee|escape}" />
<span class="textStrong">{$lang.require_field} </span></td>
<td bgcolor="#ffffff">数量:</td>
<td bgcolor="#ffffff"><input name="number" type="text" id="number" value="1" size="4" class="inputBg"/></td>
</tr>
<tr>
<td bgcolor="#ffffff">{$lang.phone}:</td>
<td bgcolor="#ffffff"><input name="tel" type="text" class="inputBg" id="tel_{$sn}" value="{$consignee.tel|escape}" />
<span class="textStrong">{$lang.require_field}</span></td>
<td bgcolor="#ffffff">{$lang.backup_phone}:</td>
<td bgcolor="#ffffff"><input name="mobile" type="text" class="inputBg" id="mobile_{$sn}" value="{$consignee.mobile|escape}" /><span class="textStrong"> 选填</span></td>
</tr>
<tr>
<td bgcolor="#ffffff">{$lang.detailed_address}:</td>
<td bgcolor="#ffffff" colspan="3"><input name="address" type="text" class="inputBg" style="width:250px" id="address_{$sn}" value="{$consignee.address|escape}" /><input name="email" type="hidden" class="inputBg" id="email_{$sn}" value="[email protected]" />
<span class="textStrong">{$lang.require_field}</span></td>
</tr>
<tr>
<td bgcolor="#ffffff">{$lang.order_postscript}:</td>
<td colspan="3" bgcolor="#ffffff"><textarea name="postscript" cols="80" style="border:1px solid #ddd;" rows="2" id="postscript">请备注您所选的产品规格以及颜色{$order.postscript|escape}</textarea></td>
</tr>
</table>
<table width="99%" align="center" border="0" cellpadding="5" cellspacing="1" bgcolor="#dddddd" style="margin-top:10px;">
<tr><td colspan="6" bgcolor="#ffffff" style="font-weight:bold;">配送方式</td></tr>
<tr>
<th bgcolor="#ffffff" width="5%"> </th>
<th bgcolor="#ffffff" width="25%">{$lang.name}</th>
<th bgcolor="#ffffff">{$lang.describe}</th>
<th bgcolor="#ffffff" width="15%">{$lang.fee}</th>
<th bgcolor="#ffffff" width="15%">{$lang.free_money}</th>
<th bgcolor="#ffffff" width="15%">{$lang.insure_fee}</th>
</tr>
<!-- {foreach from=$shipping_list item=shipping} 循环配送方式 -->
<tr>
<td bgcolor="#ffffff" valign="top">
<input name="shipping" type="radio" value="{$shipping.shipping_id}" {if $order.shipping_id eq $shipping.shipping_id}checked="true"{/if} supportCod="{$shipping.support_cod}" insure="{$shipping.insure}" onmousedown="select_shipping({$shipping.shipping_id})" onClick="show_shipping_all({$shipping.format_shipping_fee})" />
</td>
<td bgcolor="#ffffff" valign="top"><strong>{$shipping.shipping_name}</strong></td>
<td bgcolor="#ffffff" valign="top">{$shipping.shipping_desc}</td>
<td bgcolor="#ffffff" align="right" valign="top">{$shipping.format_shipping_fee}</td>
<td bgcolor="#ffffff" align="right" valign="top">{$shipping.free_money}</td>
<td bgcolor="#ffffff" align="right" valign="top">{if $shipping.insure neq 0}{$shipping.insure_formated}{else}{$lang.not_support_insure}{/if}</td>
</tr>
<!-- {/foreach} 循环配送方式 -->
<input name="shipping_add" id="shipping_add" type="hidden" value="">
<input name="format_shipping_fee" id="format_shipping_fee" type="hidden" value="">
<script type="text/javascript">
function show_shipping_all(fee)
{
document.getElementByIdx_x_x_x("format_shipping_fee").value=fee;
}
function select_shipping(id)
{
document.getElementByIdx_x_x_x("shipping_add").value=id;
}
</script>
<tr>
<td colspan="6" bgcolor="#ffffff" align="right"><label for="ECS_NEEDINSURE">
<input name="need_insure" id="ECS_NEEDINSURE" type="checkbox" onclick="selectInsure(this.checked)" value="1" {if $order.need_insure}checked="true"{/if} {if $insure_disabled}disabled="true"{/if} />
{$lang.need_insure} </label></td>
</tr>
<tr><td colspan="6" bgcolor="#ffffff" style="font-weight:bold;">支付方式</td></tr>
<tr>
<th width="5%" bgcolor="#ffffff"> </th>
<th width="20%" bgcolor="#ffffff">{$lang.name}</th>
<th bgcolor="#ffffff" colspan="3">{$lang.describe}</th>
<th bgcolor="#ffffff" width="15%">{$lang.pay_fee}</th>
</tr>
<!-- {foreach from=$payment_list item=payment} -->
<!-- 循环支付方式 -->
<tr>
<td valign="top" bgcolor="#ffffff"><input type="radio" name="payment" value="{$payment.pay_id}" {if $order.pay_id eq $payment.pay_id}checked{/if} isCod="{$payment.is_cod}" {if $cod_disabled and $payment.is_cod eq "1"}disabled="true"{/if} onmousedown="select_payment({$payment.pay_id})"/></td>
<td valign="top" bgcolor="#ffffff"><strong>{$payment.pay_name}</strong></td>
<td valign="top" bgcolor="#ffffff" colspan="3">{$payment.pay_desc}</td>
<td align="right" bgcolor="#ffffff" valign="top">{$payment.format_pay_fee}</td>
</tr>
<!-- {/foreach} 循环支付方式 -->
<input name="payment_add" id="payment_add" type="hidden" value="">
<script type="text/javascript">
function select_payment(id)
{
document.getElementByIdx_x_x_x("payment_add").value=id;
}
</script>
<tr>
<td colspan="6" align="center" bgcolor="#ffffff">
<input type="submit" name="Submit" class="bnt_blue_2" value="立即订购" />
<input type="hidden" name="step" value="consignee" />
<input type="hidden" name="act" value="checkout" />
<input name="address_id" type="hidden" value="{$consignee.address_id}" />
</td>
</tr>
</table>
</form>
</div>
</div>
<div class="blank"></div>
<script type="text/javascript">
function orderQuick(goodsId)
{
var goods = new Object();
var spec_arr = new Array();
var fittings_arr = new Array();
var number = 1;
var formOrder = document.forms['ECS_FORMORDER'];
if (formOrder)
{
goods.spec_arr = getSelectedAttributes(formOrder);
goods.goods_id = goodsId;
goods.number = formOrder.elements['number'].value;
goods.country = formOrder.elements['country'].value;
goods.province = formOrder.elements['province'].value;
goods.city = formOrder.elements['city'].value;
goods.consignee = formOrder.elements['consignee'].value;
goods.address = formOrder.elements['address'].value;
goods.tel = formOrder.elements['tel'].value;
goods.shipping = formOrder.elements['shipping_add'].value;
goods.fee = formOrder.elements['format_shipping_fee'].value;
goods.payment = formOrder.elements['payment_add'].value;
if (formOrder.elements['zipcode']){goods.zipcode = formOrder.elements['zipcode'].value;}
if (formOrder.elements['mobile']){goods.mobile = formOrder.elements['mobile'].value;}
if (formOrder.elements['sign_building']){goods.sign_building = formOrder.elements['sign_building'].value;}
if (formOrder.elements['best_time']){goods.best_time = formOrder.elements['best_time'].value;}
if (formOrder.elements['postscript']){goods.postscript = formOrder.elements['postscript'].value;}
}
Ajax.call('order_quick.php?act=order', 'goods=' + goods.toJSONString(), orderQuickResponse, 'POST', 'JSON');
}
function orderQuickResponse(result)
{
if (result.error == 2)
{
if (confirm(result.message))
{
location.href = 'user.php?act=add_booking&id=' + result.goods_id;
}
}
else
{
document.getElementByIdx_x_x_x('ESC_ORDER').innerHTML = result.message;
}
}
function checkOrderForm_goods(frm)
{
var paymentSelected = false;
var shippingSelected = false;
var msg = new Array();
var err = false;
if (frm.elements['country'] && frm.elements['country'].value == 0)
{
msg.push(country_not_null);
err = true;
}
if (frm.elements['province'] && frm.elements['province'].value == 0 && frm.elements['province'].length > 1)
{
err = true;
msg.push(province_not_null);
}
if (frm.elements['city'] && frm.elements['city'].value == 0 && frm.elements['city'].length > 1)
{
err = true;
msg.push(city_not_null);
}
if (frm.elements['district'] && frm.elements['district'].length > 1)
{
if (frm.elements['district'].value == 0)
{
err = true;
msg.push(district_not_null);
}
}
if (Utils.isEmpty(frm.elements['consignee'].value))
{
err = true;
msg.push(consignee_not_null);
}
if ( ! Utils.isEmail(frm.elements['email'].value))
{
err = true;
msg.push(invalid_email);
}
if (frm.elements['address'] && Utils.isEmpty(frm.elements['address'].value))
{
err = true;
msg.push(address_not_null);
}
if (frm.elements['zipcode'] && frm.elements['zipcode'].value.length > 0 && (!Utils.isNumber(frm.elements['zipcode'].value)))
{
err = true;
msg.push(zip_not_num);
}
if (Utils.isEmpty(frm.elements['tel'].value))
{
err = true;
msg.push(tele_not_null);
}
else
{
if (!Utils.isTel(frm.elements['tel'].value))
{
err = true;
msg.push(tele_invaild);
}
}
if (frm.elements['mobile'] && frm.elements['mobile'].value.length > 0 && (!Utils.isTel(frm.elements['mobile'].value)))
{
err = true;
msg.push(mobile_invaild);
}
if (err)
{
message = msg.join("n");
alert(message);
return false;
}
// 检查是否选择了支付配送方式
for (i = 0; i < frm.elements.length; i ++ )
{
if (frm.elements[i].name == 'shipping' && frm.elements[i].checked)
{
shippingSelected = true;
}
if (frm.elements[i].name == 'payment' && frm.elements[i].checked)
{
paymentSelected = true;
}
}
if (! shippingSelected)
{
alert("你必须选定一个配送方式!");
return false;
}
if ( ! paymentSelected)
{
alert("你必须选定一个支付方式!");
return false;
}
return ! err;
}
</script>