ecshop/flow.php

购物流程

Table of Contents

include ecshop/includes/init.php
include ecshop/includes/lib_order.php

include ecshop/languages/<lang>/user.php
include ecshop/languages/<lang>/shopping_flow.php

INPUT

$_REQUEST['step'] default 'cart'

PROCESSOR

assign_template()
assign_dynamic('flow')

assign_ur_here(0, $_LANG['shopping_flow'])

smarty variables:
page_title 页面标题
ur_here 当前位置
categories 分类树 get_categories_tree()
helps 网店帮助 get_shop_help()
lang
show_marketprice $_CFG['show_marketprice']
data_dir

$_CFG['show_marketprice']

添加商品到购物车

当$_REQUEST['step'] == 'add_to_cart'

include ecshop/includes/cls_json.php

  • Input

$_POST['goods']
$_REQUEST['goods_id']

  • Processing

检查:如果商品有规格,而post的数据没有规格,把商品的规格属性通过JSON传到前台

tab:goods_attr, attribute

  • Output
  • $result
    • goods_id
    • parent
    • message
      • attr_type
      • name
      • attr_id
      • values (label, price, format_price, id)
购物车

更新:如果是一步购物,先清空购物车
检查:商品数量是否合法
更新:添加到购物车
addto_cart($goods->goods_id, $goods->number, $goods->spec, $goods->parent)
当正确时

  • $result
    • message = $_LANG['addto_cart_success_1'] or $_LANG['addto_cart_success_2']
    • content insert_cart_info()
    • one_step_buy

当错误时

  • $result
    • message
    • error
    • goods_id
    • product_spec = $goods->spec
    • confirm_type

link_buy

$_REQUEST['step'] == 'link_buy'

  • Input
    • $_GET['goods_id']
  • Processing
    • addto_cart($goods_id)
  • Output
    • Location:./flow.php

login 用户登录注册

$_REQUEST['step'] == 'login'

include languages/<lang>/user.php

$_SERVER['REQUEST_METHOD'] == 'GET'

anonymous_buy

检查是否有赠品,如果有提示登录后重新选择赠品 tab:cart

  • smarty
    • need_rechoose_gift

检查是否需要注册码 cfg:captcha

  • smarty
    • enabled_login_captcha
    • rand

include ecshop/includes/lib_passport.php

登录

$_POST['act'] == 'signin'

检查验证码

$_POST['captcha']

include ecshop/includes/cls_captcha.php

new captcha()->check_word($_POST['captcha'])

用户登录

$user->login($_POST['username'], $_POST['password'],isset($_POST['remember'])

update_user_info() 更新用户信息
recalculate_price() 重新计算购物车中的商品价格

检查购物车中是否有商品 有商品则checkout,没有商品则跳转到首页 tab:cart
flow.php?step=checkout
index.php

若登陆失败,则继续登陆
flow.php?step=login

用户注册

$_POST['act'] == 'signup'

检查验证码

include ecshop/includes/cls_captcha.php
new captcha()->check_word($_POST['captcha'])

注册
register($_POST['username'], $_POST['password'], $_POST['email'])

用户注册成功 继续flow.php?step=consignee

继续确认流程

$_REQUEST['step'] == 'consignee'

收货人信息

include ecshop/includes/lib_transaction.php

$_SERVER['REQUEST_METHOD'] == 'GET'

取得购物类型 sess:flow_type

收货人信息填写界面

$_SESSION['direct_shopping'] = $_REQUEST['direct_shopping']

取得国家列表、商店所在国家、商店所在国家的省列表

  • $smarty
    • country_list get_regions()
    • shop_country cfg:shop_country
    • shop_province_list

获得用户所有的收货人信息
$consignee_list = get_consignee_list($_SESSION['user_id'])

如果用户收货人信息的总数小于 5 则增加一个新的收货人信息
country
email

  • $smarty
    • name_of_region
    • consignee_list

取得每个收货地址的省市区列表

  • $smarty
    • province_list
    • city_list
    • district_list

返回收货人页面代码

  • $smarty
    • real_goods_count

sess:flow_consignee

保存收货人信息
$consignee

  • $smarty
    • name_of_region
    • consignee_list

取得每个收货地址的省市区列表

  • $smarty
    • province_list
    • city_list
    • district_list
    • real_goods_count 返回收货人页面代码

保存收货人信息

  • $consignee
    • address_id $_POST['address_id']
    • consignee $_POST['consignee']
    • country $_POST['country']
    • province $_POST['province']
    • city $_POST['city']
    • district $_POST['district']
    • email $_POST['email']
    • address $_POST['address']
    • zipcode $_POST['zipcode']
    • tel $_POST['tel']
    • mobile $_POST['mobile']
    • sign_building $_POST['mobile']
    • best_time $_POST['sign_building']

ecshop/includes/lib_transaction.php

如果用户已经登录,则保存收货人信息

$_SESSION['user_id']

save_consignee($consignee, true)

保存到session $_SESSION['flow_consignee']

flow.php?step=checkout

删除收货人信息

$_REQUEST['step'] == 'drop_consignee'

ecshop/includes/lib_transaction.php

$_GET['id']

drop_consignee($consignee_id)

Location: flow.php?step=consignee

订单确认

$_REQUEST['step'] == 'checkout'

取得购物类型

$_SESSION['flow_type']

团购标志 $flow_type == CART_GROUP_BUY_GOODS

积分兑换商品 $flow_type == CART_EXCHANGE_GOODS

正常购物流程 清空其他购物流程情况
$_SESSION['flow_order']['extension_code']

检查购物车中是否有商品 tab:cart

检查用户是否已经登录
如果用户已经登录了则检查是否有默认的收货地址
如果没有登录则跳转到登录和注册页面

$_SESSION['direct_shopping']
$_SESSION['user_id']

用户没有登录且没有选定匿名购物,转向到登录页面
Location: flow.php?step=login

$consignee = get_consignee($_SESSION['user_id'])

检查收货人信息是否完整
check_consignee_info($consignee, $flow_type)

如果不完整则转向到收货人信息填写界面
flow.php?step=consignee

  • $smarty
    • consignee

对商品信息赋值
cart_goods($flow_type) 取得商品列表,计算合计

  • $smarty
    • goods_list

对是否允许修改购物车赋值 $flow_type != CART_GENERAL_GOODS cfg:one_step_buy

  • $smarty
    • allow_edit_cart

取得购物流程设置

  • $smarty
    • config $_CFG

取得订单信息

  • $smarty
    • order flow_order_info()

计算折扣 $flow_type != CART_EXCHANGE_GOODS && $flow_type != CART_GROUP_BUY_GOODS

  • $smarty
    • discount compute_discount()
    • your_discount

计算订单的费用

  • $smarty
    • total order_fee($order, $cart_goods, $consignee)
    • shopping_money
    • market_price_desc
    • formated_saving

取得配送列表
available_shipping_list($region)
cart_weight_price($flow_type)

查看购物车中是否全为免运费商品,若是则把运费赋为零 tab:cart
shipping_fee($val['shipping_code'], unserialize($val['configure']), $cart_weight_price['weight'], $cart_weight_price['amount'], $cart_weight_price['number'])

当前的配送方式是否支持保价
$val['shipping_id'] == $order['shipping_id']
insure == 0
support_cod == 0

  • $smarty
    • shipping_list
    • insure_disabled
    • cod_disabled

取得支付列表
当$order['shipping_id'] == 0 $cod $cod_fee
否则
$shipping shipping_info($order['shipping_id'])
$cod $shipping['support_cod']
如果是团购,且保证金大于0,不能使用货到付款
$flow_type == CART_GROUP_BUY_GOODS

赋值保证金

  • $smarty
    • gb_deposit group_buy_info(sess:extension_id])['deposit']
  • shipping_area_info($order['shipping_id'], $region)['pay_fee']

给货到付款的手续费加<span id>,以便改变配送的时候动态显示

  • $smarty
    • payment_list <span id="ECS_CODFEE">available_payment_list(1, $cod_fee)</span>

如果有易宝神州行支付 如果订单金额大于300 则不显示
如果有余额支付
如果未登录,不显示

  • $smarty
    • disable_surplus

取得包装与贺卡
$total['real_goods_count'] > 0

只有有实体商品,才要判断包装和贺卡
如果使用包装,取得包装列表及用户选择的包装 $smarty->pack_list pack_list()
如果使用贺卡,取得贺卡列表及用户选择的贺卡 $smarty->card_list card_list()

如果使用余额,取得用户余额
能使用余额
allow_use_surplus
your_surplus user_info($_SESSION['user_id'])['user_money']

如果使用积分,取得用户可用积分及本订单最多可以使用的积分
$_CFG['use_integral'] == '1' && $flow_type != CART_GROUP_BUY_GOODS && $flow_type != CART_EXCHANGE_GOODS

能使用积分
allow_use_integral
order_max_integral 可用积分 flow_available_points()
your_integral 用户积分 $user_info['pay_points']

如果使用红包,取得用户可以使用的红包及用户选择的红包
$_CFG['use_bonus'] == '1' && $flow_type != CART_GROUP_BUY_GOODS && $flow_type != CART_EXCHANGE_GOODS

取得用户可用红包
$smarty->bonus_list user_bonus($_SESSION['user_id'], $total['goods_price'])

能使用红包
$smarty->allow_use_bonus

如果使用缺货处理,取得缺货处理列表
$smarty->how_oos_list $GLOBALS['_LANG']['oos']

如果能开发票,取得发票内容列表
$_CFG['can_invoice'] && $flow_type != CART_EXCHANGE_GOODS
$smarty->inv_content_list $_CFG['invoice_content']
$smarty->inv_type_list $_CFG['invoice_type']['rate']

保存 session
$_SESSION['flow_order'] = $order

改变配送方式

$_REQUEST['step'] == 'select_shipping'

include ecshop/includes/cls_json.php

取得购物类型
$_SESSION['flow_type']

获得收货人信息
get_consignee($_SESSION['user_id']);

对商品信息赋值
cart_goods($flow_type) 取得商品列表,计算合计

当check_consignee_info($consignee, $flow_type)
则$result['error'] = $_LANG['no_goods_in_cart']
否则

取得购物流程设置
$smarty->config $_CFG

取得订单信息
flow_order_info();

$_REQUEST['shipping']
shipping_area_info($order['shipping_id'], $regions)

计算订单的费用
$smarty->total order_fee($order, $cart_goods, $consignee)

取得可以得到的积分和红包
$smarty->total_integral
$smarty->total_bonus

团购标志
$flow_type == CART_GROUP_BUY_GOODS
$smarty->is_group_buy

  • $result
    • cod_fee = price_format($result['cod_fee'], false)
    • need_insure = $shipping_info['insure'] > 0 && $order['need_insure']
    • content = $smarty->fetch('library/order_total.lbi')

$json->encode($result)

选定/取消配送的保价

$_REQUEST['step'] == 'select_insure'

取得购物类型 $_SESSION['flow_type']

获得收货人信息 get_consignee($_SESSION['user_id'])

对商品信息赋值 cart_goods($flow_type) 取得商品列表,计算合计

check_consignee_info($consignee, $flow_type)

取得购物流程设置 $smarty->config $_CFG

取得订单信息 flow_order_info()

$_REQUEST['insure']

保存 session
$_SESSION['flow_order'] = flow_order_info()

计算订单的费用
$smarty->total order_fee($order, $cart_goods, $consignee)

取得可以得到的积分和红包
$smarty->total_integral cart_amount(false, $flow_type) - $total['bonus'] - $total['integral_money']
$smarty->total_bonus price_format(get_total_bonus(), false)

团购标志
$flow_type == CART_GROUP_BUY_GOODS

$smarty->is_group_buy

$result['content'] = $smarty->fetch('library/order_total.lbi')

$json->encode($result)

改变支付方式

$_REQUEST['step'] == 'select_payment'

include ecshop/includes/cls_json.php

取得购物类型 $_SESSION['flow_type']

获得收货人信息 get_consignee($_SESSION['user_id'])

对商品信息赋值 cart_goods($flow_type) 取得商品列表,计算合计

!check_consignee_info($consignee, $flow_type)

取得购物流程设置
$smarty->config' $_CFG

取得订单信息
payment_info($_REQUEST['payment'])['pay_code']

保存 session $_SESSION['flow_order'] flow_order_info()

计算订单的费用
order_fee($order, $cart_goods, $consignee)
$smarty->total

取得可以得到的积分和红包
$smarty->total_integral cart_amount(false, $flow_type) - $total['bonus'] - $total['integral_money']
$smarty->total_bonus price_format(get_total_bonus(), false)

团购标志
$flow_type == CART_GROUP_BUY_GOODS
$smarty->is_group_buy

$result['content'] = $smarty->fetch('library/order_total.lbi')

$json->encode($result)

改变商品包装

$_REQUEST['step'] == 'select_pack'

include ecshop/includes/cls_json.php

取得购物类型 $_SESSION['flow_type']

获得收货人信息 get_consignee($_SESSION['user_id'])

对商品信息赋值 cart_goods($flow_type) 取得商品列表,计算合计

check_consignee_info($consignee, $flow_type)

取得购物流程设置
$smarty->config $_CFG

取得订单信息 flow_order_info()

$order['pack_id'] $_REQUEST['pack']

保存 session
$_SESSION['flow_order'] = $order

计算订单的费用
$smarty->total order_fee($order, $cart_goods, $consignee)

取得可以得到的积分和红包
$smarty->total_integral cart_amount(false, $flow_type) - $total['bonus'] - $total['integral_money']
$smarty->total_bonus price_format(get_total_bonus(), false)

团购标志 $flow_type == CART_GROUP_BUY_GOODS
$smarty->is_group_buy

$result['content'] = $smarty->fetch('library/order_total.lbi')

$json->encode($result)

改变贺卡
$_REQUEST['step'] == 'select_card'

取得购物类型

获得收货人信息

对商品信息赋值

取得购物流程设置

取得订单信息

保存 session

取得可以得到的积分和红包

团购标志

$smarty->fetch('library/order_total.lbi')

$json->encode($result)

改变余额

$_REQUEST['step'] == 'change_surplus'

$_GET['surplus']
user_info($_SESSION['user_id'])

$user_info['user_money'] + $user_info['credit_line'] >= $surplus

取得购物类型

取得购物流程设置

获得收货人信息

对商品信息赋值

取得订单信息

计算订单的费用

团购标志

$smarty->fetch('library/order_total.lbi')

$json->encode($result)

改变积分

$_REQUEST['step'] == 'change_integral'

$_GET['points']

取得订单信息 flow_order_info()

该订单允许使用的积分
flow_available_points()

用户的积分总数 $user_info['pay_points']

$order['integral'] = $points;

取得购物类型

获得收货人信息

对商品信息赋值

计算订单的费用

团购标志

$smarty->fetch('library/order_total.lbi')

改变红包

$_REQUEST['step'] == 'change_bonus'

取得购物类型

获得收货人信息

对商品信息赋值

取得购物流程设置

取得订单信息

$order['bonus_id'] = $_GET['bonus']

计算订单的费用

团购标志

$smarty->fetch('library/order_total.lbi')

$json->encode($result)

改变发票的设置

$_REQUEST['step'] == 'change_needinv'

$_GET['inv_type']
$_GET['invPayee']
$_GET['inv_content']

取得购物类型

获得收货人信息

对商品信息赋值

取得购物流程设置

取得订单信息

  • $order
    • need_inv
    • inv_type
    • inv_payee
    • inv_content

计算订单的费用
order_fee($order, $cart_goods, $consignee)
$smarty->total $total

团购标志
$smarty->is_group_buy

$smarty->fetch('library/order_total.lbi')

改变缺货处理时的方式

$_REQUEST['step'] == 'change_oos'

取得订单信息

$order['how_oos'] = intval($_GET['oos'])

保存 session

检查用户输入的余额

$_REQUEST['step'] == 'check_surplus'

$_GET['surplus']

($user_info['user_money'] + $user_info['credit_line'] < $surplus)

检查用户输入的余额

$_REQUEST['step'] == 'check_integral'

$_GET['integral']
user_info($_SESSION['user_id'])
flow_available_points() 该订单允许使用的积分
$user_info['pay_points'] 用户的积分总数

$points > $user_points

$points > $flow_points

完成所有订单操作,提交到数据库

$_REQUEST['step'] == 'done'

include ecshop/includes/lib_clips.php
include ecshop/includes/lib_payment.php

取得购物类型

检查购物车中是否有商品 tab:cart

检查商品库存

如果使用库存,且下订单时减库存,则减少库存 $_CFG['use_storage'] == '1' && $_CFG['stock_dec_time'] == SDT_PLACE

$cart_goods_stock = get_cart_goods()

flow_cart_stock($_cart_goods_stock)

检查用户是否已经登录
如果用户已经登录了则检查是否有默认的收货地址
如果没有登录则跳转到登录和注册页面

用户没有登录且没有选定匿名购物,转向到登录页面
ecs_header("Location: flow.php?step=login\n")

get_consignee($_SESSION['user_id'])

检查收货人信息是否完整
!check_consignee_info($consignee, $flow_type)

如果不完整则转向到收货人信息填写界面
flow.php?step=consignee

$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']))
);

扩展信息
$order['extension_code'] = $_SESSION['extension_code'];
$order['extension_id'] = $_SESSION['extension_id'];

检查积分余额是否合法
$order['surplus'] = min($order['surplus'], $user_info['user_money'] + $user_info['credit_line'])

查询用户有多少积分
flow_available_points()
$order['integral'] = min($order['integral'], $user_points, $flow_points)

检查红包是否存在
$bonus['user_id'] != $user_id || $bonus['order_id'] > 0 || $bonus['min_goods_amount'] > cart_amount(true, $flow_type)

$_POST['bonus_sn']

bonus_info(0, $bonus_sn)

$bonus['user_id'] > 0 || $bonus['order_id'] > 0 || $bonus['min_goods_amount'] > cart_amount(true, $flow_type) || $now > $bonus['use_end_date']

tab:user_bonus

$order['bonus_id'] = $bonus['bonus_id'];
$order['bonus_sn'] = $bonus_sn;

订单中的商品
cart_goods($flow_type)

检查商品总额是否达到最低限购金额
$flow_type == CART_GENERAL_GOODS && cart_amount(true, CART_GENERAL_GOODS) < $_CFG['min_goods_amount']

收货人信息

订单中的总额 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'];

购物车中的商品能享受红包支付的总额
compute_discount_amount()

红包和积分最多能支付的金额为商品总额
$order['goods_amount'] - $discount_amout

配送方式
$order['shipping_id']
shipping_info($order['shipping_id'])

$order['shipping_fee'] = $total['shipping_fee'];
$order['insure_fee'] = $total['shipping_insure'];

支付方式
payment_info($order['pay_id'])
$order['pay_fee'] = $total['pay_fee'];
$order['cod_fee'] = $total['cod_fee'];

商品包装
pack_info($order['pack_id'])

祝福贺卡 card_info($order['card_id'])

如果全部使用余额支付,检查余额是否足够

如果订单金额为0(使用余额或积分或红包支付),修改订单状态为已确认、已付款

$order['order_amount'] > ($user_info['user_money'] + $user_info['credit_line'])

$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'];

$order['extension_code'] == 'exchange_goods'
$order['integral_money'] = 0;
$order['integral'] = $total['exchange_integral'];

$order['from_ad']
$order['referer']

记录扩展信息
$order['extension_code'] = $_SESSION['extension_code'];
$order['extension_id'] = $_SESSION['extension_id'];

$affiliate['on'] == 1 && $affiliate['config']['separate_by'] == 1
推荐订单分成
get_affiliate();

$affiliate['on']) && $affiliate['on'] == 1 && $affiliate['config']['separate_by'] == 0
推荐注册分成

$order['parent_id'] = $parent_id

插入订单表
$order['order_sn'] = get_order_sn()
$GLOBALS['db']->autoExecute($GLOBALS['ecs']->table('order_info'), $order, 'INSERT')

//如果是订单号重复则重新提交数据

$db->insert_id()

插入订单商品 tab:order_goods

修改拍卖活动状态 tab:goods_activity

处理余额、积分、红包
log_account_change($order['user_id'], $order['surplus'] * (-1), 0, 0, 0, sprintf($_LANG['pay_order'], $order['order_sn']))

use_bonus($order['bonus_id'], $new_order_id)

如果使用库存,且下订单时减库存,则减少库存
change_order_goods_storage($order['order_id'], true, SDT_PLACE);

给商家发邮件
增加是否给客服发送邮件选项
get_mail_template('remind_of_new_order')

  • $smarty
    • order
    • goods_list
    • shop_name
    • send_date
    • ->fetch('str:' . $tpl['template_content'])

send_mail($_CFG['shop_name'], $_CFG['service_email'], $tpl['template_subject'], $content, $tpl['is_html'])

如果需要,发短信

include ecshop/includes/cls_sms.php

$sms->send($_CFG['sms_shop_mobile'], sprintf($msg, $order['consignee'], $order['tel']), 0)

如果订单金额为0 处理虚拟卡 tab:cart

虚拟卡发货
virtual_goods_ship($virtual_goods,$msg, $order['order_sn'], true)

如果没有实体商品,修改发货状态,送积分和红包 tab:order_goods

修改订单状态
update_order($order['order_id'], array('shipping_status' => SS_SHIPPED, 'shipping_time' => gmtime()))

如果订单用户不为空,计算积分,并发给用户;发红包
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_all_files();

插入支付日志
insert_pay_log($new_order_id, $order['order_amount'], PAY_ORDER)

取得支付信息,生成支付代码
payment_info($order['pay_id'])

include ecshop/includes/modules/payment/<pay_code>.php)

$smarty->pay_online (new $payment['pay_code'])->get_code($order, $payment['pay_config'])

$order['pay_desc'] = $payment['pay_desc']

$order['shipping_name']=$order['shipping_name'])

订单信息

$smarty->order, $order
$smarty->total, $total
$smarty->goods_list, $cart_goods
$smarty->order_submit_back, $_LANG['order_submit_back'], $_LANG['back_home'], $_LANG['goto_user_center'] 返回提示
user_uc_call('add_feed', array($order['order_id'], BUY_GOODS))

推送feed到uc
清除session中保存的收货人信息
unset($_SESSION['flow_consignee']); // 清除session中保存的收货人信息
unset($_SESSION['flow_order']);
unset($_SESSION['direct_shopping']);

更新购物车

$_REQUEST['step'] == 'update_cart'

flow_update_cart($_POST['goods_number'])

show_message($_LANG['update_cart_notice'], $_LANG['back_to_cart'], 'flow.php')

删除购物车中的商品

$_REQUEST['step'] == 'drop_goods'

flow_drop_cart_goods($rec_id)

flow.php

把优惠活动加入购物车

$_REQUEST['step'] == 'add_favourable'

取得优惠活动信息
favourable_info($_POST['act_id'])

判断用户能否享受该优惠
favourable_available($favourable)

检查购物车中是否已有该优惠
cart_favourable()
favourable_used($favourable, $cart_favourable)

赠品(特惠品)优惠
$favourable['act_type'] == FAT_GOODS

检查是否选择了赠品
$_POST['gift']

检查是否已在购物车 tab:cart
$gift_name

检查数量是否超过上限
$count + count($_POST['gift']) > $favourable['act_type_ext']

添加赠品到购物车
in_array($gift['id'], $_POST['gift'])
add_gift_to_cart($act_id, $gift['id'], $gift['price'])

if $favourable['act_type'] == FAT_DISCOUNT

add_favourable_to_cart($act_id, $favourable['act_name']
cart_favourable_amount($favourable) * (100 - $favourable['act_type_ext']) / 100)

if $favourable['act_type'] == FAT_PRICE

add_favourable_to_cart($act_id, $favourable['act_name'], $favourable['act_type_ext'])

刷新购物车
flow.php

清空购物车

$_REQUEST['step'] == 'clear'

tab:cart

添加goods到collect_goods

$_GET['id']
tab:cart

tab:collect_goods
$_REQUEST['step'] == 'drop_to_collect'

flow_drop_cart_goods($rec_id)

flow.php

验证红包序列号

$_REQUEST['step'] == 'validate_bonus'

$_REQUEST['bonus_sn']
bonus_info(0, $bonus_sn)

price_format($bonus['type_money'], false)

include ecshop/includes/cls_json.php

取得购物类型
$_SESSION['flow_type']

获得收货人信息
get_consignee($_SESSION['user_id'])

对商品信息赋值
cart_goods($flow_type) 取得商品列表,计算合计

check_consignee_info($consignee, $flow_type)

取得购物流程设置
$smarty->config $_CFG

取得订单信息
flow_order_info()

$bonus['user_id'] == $_SESSION['user_id']) || ($bonus['type_money'] > 0 && empty($bonus['user_id']))) && $bonus['order_id'] <= 0

$order['bonus_id'] = $bonus['bonus_id'];
$order['bonus_sn'] = $bonus_sn;

计算订单的费用
$smarty->total order_fee($order, $cart_goods, $consignee);

团购标志
$flow_type == CART_GROUP_BUY_GOODS
$smarty->is_group_buy

$smarty->library/order_total.lbi

$json->encode($result)

添加礼包到购物车

$_REQUEST['step'] == 'add_package_to_cart'

include ecshop/includes/cls_json.php

$json->decode($_POST['package_info'])

如果是一步购物,先清空购物车
$_CFG['one_step_buy'] == '1'
clear_cart()

商品数量是否合法

添加到购物车
add_package_to_cart($package->package_id, $package->number)

$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'];

$result['confirm_type'] = !empty($_CFG['cart_confirm']) ? $_CFG['cart_confirm'] : 2

$json->encode($result)

正常最终显示

标记购物流程为普通商品
$_SESSION['flow_type'] = CART_GENERAL_GOODS

如果是一步购物,跳到结算中心
flow.php?step=checkout

取得商品列表,计算合计
get_cart_goods()
$smarty->goods_list' $cart_goods['goods_list']
$smarty->total' $cart_goods['total']

购物车的描述的格式化
$smarty->shopping_money $_LANG['shopping_money'], $cart_goods['total']['goods_price']
$smarty->market_price_desc $_LANG['than_market_price'], $cart_goods['total']['market_price'], $cart_goods['total']['saving'], $cart_goods['total']['save_rate']

显示收藏夹内的商品
include ecshop/includes/lib_clips.php
$smarty->collection_goods' get_collection_goods($_SESSION['user_id'])

取得优惠活动
$smarty->favourable_list favourable_list($_SESSION['user_rank'])

计算折扣
$smarty->discount compute_discount()
$smarty->your_discount $discount['discount']

增加是否在购物车里显示商品图
$smarty->show_goods_thumb $GLOBALS['_CFG']['show_goods_in_cart']

增加是否在购物车里显示商品属性
$smarty->show_goods_attribute $GLOBALS['_CFG']['show_attr_in_cart']

购物车中商品配件列表
取得购物车中基本件ID tab:cart

$smarty->fittings_list get_goods_fittings($parent_list)

$smarty->assign('currency_format', $_CFG['currency_format']);
$smarty->assign('integral_scale', $_CFG['integral_scale']);
$smarty->assign('step', $_REQUEST['step']);
assign_dynamic('shopping_flow');

$smarty->display('flow.dwt');

PRIVATE FUNCTION

flow_available_points() 获得用户的可用积分

SUM(g.integral * c.goods_number) tab:cart, goods

flow_update_cart($arr) 更新购物车中的商品数量

* 基本 tab:cart, goods
* 查询:系统启用了库存,检查输入的商品数量是否有效,且是货品 tab:products 调整包 judge_package_stock($goods['goods_id'], $val)
* 查询:检查该项是否为基本件 以及是否存在配件, 此处配件是指添加商品时附加的并且是设置了优惠价格的配件 此类配件都有parent_id goods_number为1 tab:cart
* 订货数量大于0 判断是否为超出数量的优惠价格的配件 删除 tab:cart
* 处理超值礼包 当$goods['extension_code'] == 'package_buy'
* 更新购物车中的商品数量 tab:cart
* 处理普通商品或非优惠的配件 get_final_price($goods['goods_id'], $val, true, $attr_id)
* 更新购物车中的商品数量 tab:cart
* 订货数量等于0
* 如果是基本件并且有优惠价格的配件则删除优惠价格的配件 $GLOBALS['db']->fetchRow($offers_accessories_res) tab:cart
* 删除所有赠品 tab:cart is_gift <> 0

  • flow_cart_stock($arr) 检查订单中商品库存 tab:cart, goods
    • 系统启用了库存,检查输入的商品数量是否有效 $GLOBALS['_CFG']['use_storage'] && $goods['extension_code'] != 'package_buy'
    • $row['goods_number'] < $val
    • 是货品 $row['product_id']
      • tab:products
      • $product_number < $val
    • $GLOBALS['_CFG']['use_storage'] && $goods['extension_code'] == 'package_buy'
      • judge_package_stock($goods['goods_id'], $val)
        • 报告 package_stock_insufficiency
flow_drop_cart_goods($id) 删除购物车中的商品
  • 取得商品id cart
    • 如果是超值礼包 $row['extension_code'] == 'package_buy'
      • 删除 tab:cart
    • 如果是普通商品,同时删除所有赠品及其配件 $row['parent_id'] == 0 && $row['is_gift'] == 0
      • 检查购物车中该普通商品的不可单独销售的配件 tab:cart, group_goods, goods
      • 并删除 tab:cart
    • 如果不是普通商品
      • 只删除该商品即可 tab:cart
    • flow_clear_cart_alone()
flow_clear_cart_alone() 删除购物车中不能单独销售的商品
  • 查询:购物车中所有不可以单独销售的配件 tab:cart, group_goods, goods
  • 查询:购物车中所有商品 tab:cart
  • 如果购物车中不可以单独销售配件的基本件不存在则删除该配件
    • 删除 tab:cart
cmp_favourable($a, $b) 比较优惠活动的函数

用于排序(把可用的排在前面)
相等返回0,小于返回-1,大于返回1

favourable_list($user_rank) 取得某用户等级当前时间可以享受的优惠活动
  • 购物车中已有的优惠活动及数量 cart_favourable()
  • 当前用户可享受的优惠活动 tab:favourable_activity
    • 取得优惠活动对应的商品 favourable_activity.gift tab:goods
    • 是否能享受 favourable_available($favourable)
      • 是否尚未享受 favourable_used($favourable, $used_list)
favourable_available($favourable) 根据购物车判断是否可以享受某优惠活动
  • 会员等级是否符合 $_SESSION['user_rank'] in $favourable['user_rank']
  • 优惠范围内的商品总额 cart_favourable_amount($favourable)
  • 金额上限为0表示没有上限
act_range_desc($favourable) 取得优惠范围描述
  • 当品牌优惠 $favourable['act_range'] == FAR_BRAND
    • 取出品牌 tab:brand
  • 当分类优惠 $favourable['act_range'] == FAR_CATEGORY
    • 取出分类 tab:category
  • 当商品优惠 $favourable['act_range'] == FAR_GOODS
    • 取出商品 tab:goods
cart_favourable() 取得购物车中已有的优惠活动及数量

tab:cart

favourable_used($favourable, $cart_favourable) 购物车中是否已经有某优惠
  • 当商品优惠 $favourable['act_type'] == FAT_GOODS
    • isset($cart_favourable[$favourable['act_id']])
  • 否则
    • isset($cart_favourable[$favourable['act_id']])
add_gift_to_cart($act_id 优惠活动id, $id 赠品id, $price 赠品价格) 添加优惠活动(赠品)到购物车

tab:cart, goods

add_favourable_to_cart($act_id, $act_name, $amount) 添加优惠活动(非赠品)到购物车

tab:cart

cart_favourable_amount($favourable) 取得购物车中某优惠活动范围内的总金额
  • 查询优惠范围内商品总额的sql tab:cart, goods
  • 根据优惠范围修正sql
    • 当分类优惠 $favourable['act_range'] == FAR_CATEGORY
      • 取得优惠范围分类的所有下级分类
      • 设定分类范围
    • 当品牌优惠 $favourable['act_range'] == FAR_BRAND
      • 设定品牌范围
    • 否则为商品分类
      • 设定商品范围
    • 执行sql取得优惠范围内的商品总额