ecshop直接购买

2009-09-03 10:56 来源:www.chinab4c.com 作者:ecshop专家

1:本段JS加到需要直接购买的页面

<script type="text/javascript">

function S(i) { return document.getElementById(i); }

function download( evt, fid,gid){

    var _event = evt ? evt : event;

    var _target = evt ? evt.target : event.srcElement;

    var _p = S( "downloadPanel" );

       var formBuy      = document.forms['shop_go'];

         formBuy.elements['goods_id'].value = gid;

    _p.style.top = _event.clientY + document.body.scrollTop ;

    _p.style.left = ( _event.clientX + document.body.scrollLeft < 160 ?

 

_event.clientX + document.body.scrollLeft + 10  : _event.clientX  +

 

document.body.scrollLeft - 120 );

    Show( "downloadPanel" , true );   

    _p.focus();

}

function Show(obj, bShow) {

    obj = (typeof(obj) == "string" ? S(obj) : obj);

    if (obj) obj.style.display= (bShow ? "" : "none");

}

function hideDownloadPanel( evt ){

    Show( "downloadPanel" ,false);   

}

function checkClick(evt){

    var _target = evt ? evt.target : event.srcElement ;

    var _id = _target.id;

    if( _id == "" ){

        _id = _target.parentNode.id;

    }

    if( _id !="downloadDirect" && _id != "downloadAgent" && _id !=

 

"downloadPanel" && _id.indexOf( "downloadFile_" ) < 0 && _id.indexOf(

 

"downloadLink_" ) < 0 ){

        //Show( "downloadPanel" , false );

    }

}

window.onload = function(){

    document.body.onclick=checkClick;

}

</script>

 

 

 

2:在需要直接购买的页面,加入本样式

<style type="text/css">

html,body{

    font-size:12px;

}

img {border:none}

a {color:#4d5d2c;text-decoration:underline;cursor:pointer;}

.pointer {cursor:pointer;}

.right {float:right}

.right img{margin:0 0 0 6px}

.infobar {background:#fff9e3;border:1px solid #fadc80;color:#743e04;margin-

 

bottom:10px;padding:8px 20px 4px 20px;}

</style>

 

 

3:加入第三段JS,用来验证表单数据

  <script>

                     function check_shop(){

                            var formBuy      = document.forms['shop_go'];

                            var consignee =  formBuy.elements

 

['consignee'].value;

                            var address =  formBuy.elements

 

['address'].value;

                            var mobile =  formBuy.elements['mobile'].value;

                            var tel =  formBuy.elements['tel'].value;

                            var email =  formBuy.elements['email'].value;

                           

                            var count =  formBuy.elements['count'].value;

                            var s1 = document.getElementById('s1');

                            var s2 = document.getElementById('s2');

                            var s3 = document.getElementById('s3');

                            var s4 = document.getElementById('s4');           

                            var s5 = document.getElementById('s5');

                            var s6 = document.getElementById('s6');

                            var s7 = document.getElementById('s7');

                                  

                            var msg = '';

                            if(consignee == ''){

                                s1.innerHTML = "<font color=red>收货人姓名

 

不能为空</font>"

                                   msg="1";

                            }else{

                                   s1.innerHTML = "<font

 

color=red></font>"

                                   msg="0";

                            }

                            if(address == ''){

                                   s2.innerHTML = "<font color=red>收货人

 

地址不能为空</font>"

                                   msg="1";

                            }else{

                                   s2.innerHTML = "<font

 

color=red></font>"

                                   msg="0";

                            }

                            if(mobile == ''){

                                   s3.innerHTML = "<font color=red>收货人

 

手机号码不能为空</font>"

                                   msg="1";

                            }else{

                                   if (!(/^(?:13\d|15[89])-?\d{5}(\d{3}

 

|\*{3})$/.test(mobile)))

                                   {

                                         s3.innerHTML = "<font

 

color=red>手机号码格式不对</font>"

                                          msg="1";

                                   } else{

                                          s3.innerHTML = "<font

 

color=red></font>"

                                          msg="0";

                                   }

                                  

                            }

                            if(tel == ''){

                                   s4.innerHTML = "<font color=red>收货人

 

电话不能为空</font>"

                                   msg="1";

                            }else{

                               if(!(/^(([0\+]\d{2,3}-)?(0\d{2,3})-)(\d

 

{7,8})(-(\d{3,}))?$/.test(tel))){

                                         

                                         s4.innerHTML = "<font

 

color=red>输入的电话号码格式不对</font>"

                                          msg="1";

                                   }else{

                                          s4.innerHTML = "<font

 

color=red></font>"

                                          msg="0";

                                   }

                                  

                            }

                            if(email == ''){

                                   s5.innerHTML = "<font color=red>必须输

 

Email</font>"

                                   msg="1";

                            }else{

                                    var reg1 = /([\w-\.]+)@((\[[0-9]{1,3}

 

\.[0-9]{1,3}\.[0-9]{1,3}\.)|(([\w-]+\.)+))([a-zA-Z]{2,4}|[0-9]{1,3})(\]?)/;

                                    if(!reg1.test( email )){

                                          s5.innerHTML = "<font

 

color=red>Email输入格式不对</font>"

                                          msg="1";

                                    }else{

                                          s5.innerHTML = "<font

 

color=red></font>"

                                          msg="0";

                                    }

                                  

                            }

                            if(count == ''){

                                   s6.innerHTML = "<font color=red>必须输

 

入购买数量</font>"

                                   msg="1";

                            }else{

                                   if(!(/(\d)+/.test(count))){

                                          s6.innerHTML = "<font

 

color=red>购买数量必须输入整数</font>"

                                          msg="1";

                                   }else{

                                          s6.innerHTML = "<font

 

color=red></font>"

                                          msg="0";

                                   }

                                  

                            }

                           

                           

                            var payment = document.getElementById

 

("payment");

                            var pv = (payment.options

 

[payment.selectedIndex].value);

                             if(pv == ''){

                                  s7.innerHTML = "<font color=red>请选择

 

支付方式</font>"

                                   msg="1";

                             }else{

                                  s7.innerHTML = "<font

 

color=red></font>"

                                   msg="";

                             }

                            if(msg == '1'){

                                  

                                   return false;

                            }else{

                                  

                                   return true;

                            }

                           

                     }

                           

                    

                     </script>

 

 

 

4:加浮动的层,用于显示直接购买

 

<div id="downloadPanel" style="position:absolute;top:0px;left:0px;width:400px;

 

height:200px;z-index:999;padding:6px 2px 6px 10px;border:1px solid

 

#fb7;display:none;" class="infobar">

    <a src="ico_closetip_gray.gif" class="right pointer"

 

onclick="hideDownloadPanel();" title="关闭" >x</a>

    <div class="">填写直接购买订单信息:</div>

    <div style="padding:6px 0 0 0;">

              <table border="1" width="400">

                  <script>

                     function check_shop(){

                            var formBuy      = document.forms['shop_go'];

                            var consignee =  formBuy.elements

 

['consignee'].value;

                            var address =  formBuy.elements

 

['address'].value;

                            var mobile =  formBuy.elements['mobile'].value;

                            var tel =  formBuy.elements['tel'].value;

                            var email =  formBuy.elements['email'].value;

                           

                            var count =  formBuy.elements['count'].value;

                            var s1 = document.getElementById('s1');

                            var s2 = document.getElementById('s2');

                            var s3 = document.getElementById('s3');

                            var s4 = document.getElementById('s4');           

                            var s5 = document.getElementById('s5');

                            var s6 = document.getElementById('s6');

                            var s7 = document.getElementById('s7');

                                  

                            var msg = '';

                            if(consignee == ''){

                                s1.innerHTML = "<font color=red>收货人姓名

 

不能为空</font>"

                                   msg="1";

                            }else{

                                   s1.innerHTML = "<font

 

color=red></font>"

                                   msg="0";

                            }

                            if(address == ''){

                                   s2.innerHTML = "<font color=red>收货人

 

地址不能为空</font>"

                                   msg="1";

                            }else{

                                   s2.innerHTML = "<font

 

color=red></font>"

                                   msg="0";

                            }

                            if(mobile == ''){

                                   s3.innerHTML = "<font color=red>收货人

 

手机号码不能为空</font>"

                                   msg="1";

                            }else{

                                   if (!(/^(?:13\d|15[89])-?\d{5}(\d{3}

 

|\*{3})$/.test(mobile)))

                                   {

                                         s3.innerHTML = "<font

 

color=red>手机号码格式不对</font>"

                                          msg="1";

                                   } else{

                                          s3.innerHTML = "<font

 

color=red></font>"

                                          msg="0";

                                   }

                                  

                            }

                            if(tel == ''){

                                   s4.innerHTML = "<font color=red>收货人

 

电话不能为空</font>"

                                   msg="1";

                            }else{

                               if(!(/^(([0\+]\d{2,3}-)?(0\d{2,3})-)(\d

 

{7,8})(-(\d{3,}))?$/.test(tel))){

                                         

                                         s4.innerHTML = "<font

 

color=red>输入的电话号码格式不对</font>"

                                          msg="1";

                                   }else{

                                          s4.innerHTML = "<font

 

color=red></font>"

                                          msg="0";

                                   }

                                  

                            }

                            if(email == ''){

                                   s5.innerHTML = "<font color=red>必须输

 

Email</font>"

                                   msg="1";

                            }else{

                                    var reg1 = /([\w-\.]+)@((\[[0-9]{1,3}

 

\.[0-9]{1,3}\.[0-9]{1,3}\.)|(([\w-]+\.)+))([a-zA-Z]{2,4}|[0-9]{1,3})(\]?)/;

                                    if(!reg1.test( email )){

                                          s5.innerHTML = "<font

 

color=red>Email输入格式不对</font>"

                                          msg="1";

                                    }else{

                                          s5.innerHTML = "<font

 

color=red></font>"

                                          msg="0";

                                    }

                                  

                            }

                            if(count == ''){

                                   s6.innerHTML = "<font color=red>必须输

 

入购买数量</font>"

                                   msg="1";

                            }else{

                                   if(!(/(\d)+/.test(count))){

                                          s6.innerHTML = "<font

 

color=red>购买数量必须输入整数</font>"

                                          msg="1";

                                   }else{

                                          s6.innerHTML = "<font

 

color=red></font>"

                                          msg="0";

                                   }

                                  

                            }

                           

                           

                            var payment = document.getElementById

 

("payment");

                            var pv = (payment.options

 

[payment.selectedIndex].value);

                             if(pv == ''){

                                  s7.innerHTML = "<font color=red>请选择

 

支付方式</font>"

                                   msg="1";

                             }else{

                                  s7.innerHTML = "<font

 

color=red></font>"

                                   msg="";

                             }

                            if(msg == '1'){

                                  

                                   return false;

                            }else{

                                  

                                   return true;

                            }

                           

                     }

                           

                    

                     </script>

                     <form method="post" action="flow.php?step=direct_sh"

 

name="shop_go" onsubmit="return check_shop();" >

                            <tr><td>收货人</td><td><input type="text"

 

name="consignee"><font color="#FF0000" id="s1">*</font></td></tr>

                            <tr><td>收货地址</td><td><input type="text"

 

name="address"><font color="#FF0000" id="s2">*</font></td></tr>

                            <tr><td>手机号码</td><td><input type="text"

 

name="mobile"><font color="#FF0000" id="s3">*</font></td></tr>

                            <tr><td>电话号码</td><td><input type="text"

 

name="tel"><font color="#FF0000" id="s4">*(格式:0755-88888888)</font></td></tr>

                            <tr><td>Email</td><td><input type="text"

 

name="email"><font color="#FF0000" id="s5">*</font></td></tr>

                            <tr><td>订购数量</td><td><input type="text"

 

name="count"><font color="#FF0000" id="s6">*</font></td></tr>

                            <tr>

                            <input type="hidden" name="goods_id" value=""

 

id="goods_id">

                                   <td>支付方式</td><td>

                                   <select name="payment" id="payment">

                                          <option value="">请选择支付方式

 

</option>

                                          {foreach from = $payment_list

 

item = item}

                                         

                                          <option

 

value="{$item.pay_id}">{$item.pay_name}</option>

                                          {/foreach}

                                   </select><font color="#FF0000"

 

id="s7">*</font>

                                   </td>

                            </tr>

                           

                            <tr><td colspan="2"><input type="submit"

 

value="提交订单"></td></tr>

                           

                     </form>

              </table>

       </div>

   

</div>

 

 

5:处理定单成,加到flow.php

elseif ($_REQUEST['step'] == 'direct_sh'){

      

       addto_cart($_POST['goods_id'], $_POST['count'] );

      

       include_once('includes/lib_clips.php');

    include_once('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)

    {

        show_message($_LANG['no_goods_in_cart'], '', '', 'warning');

    }

 

  

   

    $_POST['how_oos'] = isset($_POST['how_oos']) ? intval($_POST['how_oos']) :

 

0;

    $_POST['card_message'] = isset($_POST['card_message']) ? htmlspecialchars

 

($_POST['card_message']) : '';

    $_POST['inv_type'] = !empty($_POST['inv_type']) ? htmlspecialchars($_POST

 

['inv_type']) : '';

    $_POST['inv_payee'] = isset($_POST['inv_payee']) ? htmlspecialchars($_POST

 

['inv_payee']) : '';

    $_POST['inv_content'] = isset($_POST['inv_content']) ? htmlspecialchars

 

($_POST['inv_content']) : '';

    $_POST['postscript'] = isset($_POST['postscript']) ? htmlspecialchars

 

($_POST['postscript']) : '';

 

    $order = array(

        'shipping_id'     => intval($_POST['shipping']),

        'pay_id'          => intval($_POST['payment']),

        'pack_id'         => isset($_POST['pack']) ? intval($_POST['pack']) :

 

0,

        'card_id'         => isset($_POST['card']) ? intval($_POST['card']) :

 

0,

        'card_message'    => trim($_POST['card_message']),

        'surplus'         => isset($_POST['surplus']) ? floatval($_POST

 

['surplus']) : 0.00,

        'integral'        => isset($_POST['integral']) ? intval($_POST

 

['integral']) : 0,

        'bonus_id'        => isset($_POST['bonus']) ? intval($_POST['bonus']) :

 

0,

        'need_inv'        => empty($_POST['need_inv']) ? 0 : 1,

        'inv_type'        => $_POST['inv_type'],

        'inv_payee'       => trim($_POST['inv_payee']),

        'inv_content'     => $_POST['inv_content'],

        'consignee'       => $_POST['consignee'],

        'tel'             => $_POST['tel'],

        'mobile'         => $_POST['mobile'],

        'email'           => $_POST['email'],

          'address'           => $_POST['address'],

           'postscript'      => trim($_POST['postscript']),

        'how_oos'         => isset($_LANG['oos'][$_POST['how_oos']]) ?

 

addslashes($_LANG['oos'][$_POST['how_oos']]) : '',

        'need_insure'     => isset($_POST['need_insure']) ? intval($_POST

 

['need_insure']) : 0,

        'user_id'         => $_SESSION['user_id'],

        'add_time'        => gmtime(),

        'order_status'    => OS_UNCONFIRMED,

        'shipping_status' => SS_UNSHIPPED,

        'pay_status'      => PS_UNPAYED,

        'agency_id'       => get_agency_by_regions(array($consignee['country'],

 

$consignee['province'], $consignee['city'], $consignee['district']))

        );

 

    /* 扩展信息 */

    if (isset($_SESSION['flow_type']) && intval($_SESSION['flow_type']) !=

 

CART_GENERAL_GOODS)

    {

        $order['extension_code'] = $_SESSION['extension_code'];

        $order['extension_id'] = $_SESSION['extension_id'];

    }

    else

    {

        $order['extension_code'] = '';

        $order['extension_id'] = 0;

    }

 

    /* 检查积分余额是否合法 */

    $user_id = $_SESSION['user_id'];

    if ($user_id > 0)

    {

        $user_info = user_info($user_id);

 

        $order['surplus'] = min($order['surplus'], $user_info['user_money'] +

 

$user_info['credit_line']);

        if ($order['surplus'] < 0)

        {

            $order['surplus'] = 0;

        }

 

        // 查询用户有多少积分

        $flow_points = flow_available_points();  // 该订单允许使用的积分

        $user_points = $user_info['pay_points']; // 用户的积分总数

 

        $order['integral'] = min($order['integral'], $user_points,

 

$flow_points);

        if ($order['integral'] < 0)

        {

            $order['integral'] = 0;

        }

    }

    else

    {

        $order['surplus']  = 0;

        $order['integral'] = 0;

    }

 

    /* 检查红包是否存在 */

    if ($order['bonus_id'] > 0)

    {

        $bonus = bonus_info($order['bonus_id']);

 

        if (empty($bonus) || $bonus['user_id'] != $user_id || $bonus

 

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

        {

            $order['bonus_id'] = 0;

        }

    }

    elseif (isset($_POST['bonus_sn']))

    {

        $bonus_sn = trim($_POST['bonus_sn']);

        $bonus = bonus_info(0, $bonus_sn);

        if (empty($bonus) || $bonus['user_id'] > 0 || $bonus['order_id'] > 0 ||

 

$bonus['min_goods_amount'] > cart_amount(true, $flow_type))

        {

        }

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

        }

    }

 

    /* 订单中的商品 */

    $cart_goods = cart_goods($flow_type);

 

    if (empty($cart_goods))

    {

        show_message($_LANG['no_goods_in_cart'], $_LANG['back_home'], './',

 

'warning');

    }

 

    /* 检查商品总额是否达到最低限购金额 */

    if (cart_amount(true, CART_GENERAL_GOODS) < $_CFG['min_goods_amount'])

    {

        show_message(sprintf($_LANG['goods_amount_not_enough'], price_format

 

($_CFG['min_goods_amount'], false)));

    }

 

  

 

    /* 订单中的总额 */

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

 

    /* 配送方式 */

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

 

    $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) ".

            " 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 ".

            " 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($_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)

    {

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

    }

 

    /* 给商家发邮件 */

    /* 增加是否给客服发送邮件选项 */

    if ($_CFG['send_service_email'] && $_CFG['service_email'] != '')

    {

        $tpl = get_mail_template('remind_of_new_order');

        $smarty->assign('order', $order);

        $smarty->assign('goods_list', $cart_goods);

        $smarty->assign('shop_name', $_CFG['shop_name']);

        $smarty->assign('send_date', date($_CFG['time_format']));

        $content = $smarty->fetch('str:' . $tpl['template_content']);

        send_mail($_CFG['shop_name'], $_CFG['service_email'], $tpl

 

['template_subject'], $content, $tpl['is_html']);

    }

 

    /* 如果需要,发短信 */

    if ($_CFG['sms_order_placed'] == '1' && $_CFG['sms_shop_mobile'] != '')

    {

        include_once('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);

    }

 

    /* 如果订单金额为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);

 

        $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)

        {

            /* 虚拟卡发货 */

            if (virtual_goods_ship($virtual_goods,$msg, $order['order_sn'],

 

true))

            {

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

                $sql = "SELECT COUNT(*)" .

                        " FROM " . $ecs->table('order_goods') .

                        " WHERE order_id = '$order[order_id]' " .

                        " AND is_real = 1";

                if ($db->getOne($sql) <= 0)

                {

                    /* 修改订单状态 */

                    update_order($order['order_id'], array('shipping_status' =>

 

SS_SHIPPED, 'shipping_time' => gmtime()));

 

                    /* 如果订单用户不为空,计算积分,并发给用户;发红包 */

                    if ($order['user_id'] > 0)

                    {

                        /* 取得用户信息 */

                        $user = user_info($order['user_id']);

 

                        /* 计算并发放积分 */

                        $integral = integral_to_give($order);

                        log_account_change($order['user_id'], 0, 0, intval

 

($integral['rank_points']), intval($integral['custom_points']), sprintf($_LANG

 

['order_gift_integral'], $order['order_sn']));

 

                        /* 发放红包 */

                        send_order_bonus($order['order_id']);

                    }

                }

            }

        };

 

    }

 

    /* 清空购物车 */

    clear_cart($flow_type);

    /* 清除缓存,否则买了商品,但是前台页面读取缓存,商品数量不减少 */

    clear_all_files();

 

    /* 插入支付日志 */

    $order['log_id'] = insert_pay_log($new_order_id, $order['order_amount'],

 

PAY_ORDER);

 

    /* 取得支付信息,生成支付代码 */

    if ($order['order_amount'] > 0)

    {

        $payment = payment_info($order['pay_id']);

 

        include_once('includes/modules/payment/' . $payment['pay_code'] .

 

'.php');

 

        $pay_obj    = new $payment['pay_code'];

 

        $pay_online = $pay_obj->get_code($order, unserialize_config($payment

 

['pay_config']));

 

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

 

        $smarty->assign('pay_online', $pay_online);

    }

 

    /* 订单信息 */

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

}

 

 

6:flow.dwt模板中,加入

 <!-- {if $step eq "direct_sh"} -->

        <!-- 订单提交成功 -->

        <div class="flowBox" style="margin:30px auto 70px auto;">

         <h6 style="text-align:center; height:30px; line-height:30px;">

 

{$lang.remember_order_number}: <font style="color:red">{$order.order_sn}

 

</font></h6>

          <table width="99%" align="center" border="0" cellpadding="15"

 

cellspacing="0" bgcolor="#fff" style="border:1px solid #ddd; margin:20px auto;"

 

> 

            <tr>

              <td align="center" bgcolor="#FFFFFF">

              <!--{if $order.shipping_name}-->{$lang.select_shipping}:

 

<strong>{$order.shipping_name}</strong><!--{/if}-->{$lang.select_payment}:

 

<strong>{$order.pay_name}</strong>{$lang.order_amount}: <strong>

 

{$total.amount_formated}</strong>

              </td>

            </tr>

            <tr>

              <td align="center" bgcolor="#FFFFFF">{$order.pay_desc}</td>

            </tr>

            <!-- {if $pay_online} -->

            <!-- 如果是线上支付则显示支付按钮 -->

            <tr>

              <td align="center" bgcolor="#FFFFFF">{$pay_online}</td>

            </tr>

            <!-- {/if} -->

          </table>

          <!--{if $virtual_card}-->

          <div style="text-align:center;overflow:hidden;border:1px solid

 

#E2C822;background:#FFF9D7;margin:10px;padding:10px 50px 30px;">

          <!--{foreach from=$virtual_card item=vgoods}-->

            <h3 style="color:#2359B1; font-size:12px;">{$vgoods.goods_name}

 

</h3>

            <!--{foreach from=$vgoods.info item=card}-->

              <ul style="list-style:none;padding:0;margin:0;clear:both">

              <!--{if $card.card_sn}-->

              <li style="margin-right:50px;float:left;">

              <strong>{$lang.card_sn}:</strong><span style="color:red;">

 

{$card.card_sn}</span>

              </li><!--{/if}-->

              <!--{if $card.card_password}-->

              <li style="margin-right:50px;float:left;">

              <strong>{$lang.card_password}:</strong><span style="color:red;">

 

{$card.card_password}</span>

              </li><!--{/if}-->

              <!--{if $card.end_date}-->

              <li style="float:left;">

              <strong>{$lang.end_date}:</strong>{$card.end_date}

              </li><!--{/if}-->

              </ul>

            <!--{/foreach}-->

          <!--{/foreach}-->

          </div>

          <!--{/if}-->

          <p style="text-align:center; margin-bottom:20px;">

 

{$order_submit_back}</p>

        </div>

        <!-- {/if} -->