zoukankan      html  css  js  c++  java
  • ecshop开发日志之手机端虚拟商品自动发货

    在ecshop官方模版收,web端的虚拟商品购买后不能像pc端那般直接在付款后出现虚拟商品的卡号,密码,截止日期
    一下为让手机购买也可以在付款后自动显示发货并能显示卡号密码截止日期
    首 先找到pc端的flow.php文件中的$_REQUEST['act'] = 'done'  这里面是用来处理订单的最后一步,(具体怎么知道的可以看url后的参数列表),对应手机端处理订单的的文件为 mobile/order.php 文件,这里同样有一个$_REQUEST['act'] = 'done',对比里面的代码发现order.php相比flow.php 缺少了一段处理虚拟商品的代码找到ecshop官方的flow.php文件中大约1677行有一个注释
    /*/* 如果使用库存,且下订单时减库存,则减少库存 */*/下面的if判断语句还是相同
    这句话上面还有一段代码(如下),在手机端不存在,具体功能(追到函数里这段是说:设置红包已经使用,和我们现在需求的功能无关)

    if ($order['bonus_id'] > 0 && $temp_amout > 0)
        {
            use_bonus($order['bonus_id'], $new_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']),'', 13,1);
        }

    下面的关键的代码 ----- 是关系到我们现在的功能是不是能用
    virtual_goods_ship($virtual_goods,$msg, $order['order_sn'], true)这个函数里面会有一个smarty的assign方法就是这里将虚拟商品的卡号密码等信息发送到页面中,并处理发货状态等,有兴趣的童鞋可以进 去看看,

    /* 如果订单金额为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 AND $flow_type != CART_GROUP_BUY_GOODS)
            {
                /* 虚拟卡发货 */
                if (virtual_goods_ship($virtual_goods,$msg, $order['order_sn'], true))
                {
                    /* 如果没有实体商品,修改发货状态,送积分和红包 */
                    $sql = "SELECT COUNT(*)" .
                            " FROM " . $ecs->table('order_goods') .
                            " WHERE order_id = '$order[order_id]' " .
                            " AND is_real = 1";
                    if ($db->getOne($sql) <= 0)
                    {
                        /* 修改订单状态 */
                        update_order($order['order_id'], array('shipping_status' => SS_SHIPPED, 'shipping_time' => gmtime()));
    
                        /* 如果订单用户不为空,计算积分,并发给用户;发红包 */
                        if ($order['user_id'] > 0)
                        {
                            /* 取得用户信息 */
                            $user = user_info($order['user_id']);
    
                            /* 计算并发放积分 */
                            $integral = integral_to_give($order);
                            log_account_change($order['user_id'], 0, 0, intval($integral['rank_points']), intval($integral['custom_points']), sprintf($_LANG['order_gift_integral'], $order['order_sn']));
    
                            /* 发放红包 */
                            send_order_bonus($order['order_id']);
                        }
                    }
                }
            }
        }

    这里的代码添加上以后变量已经发送到页面中了,在手机模版收是order_done.dwt文件来显示最后一步的,这里和pc端的flow.dwt里全是判断的思路不太一样,找到flow.dwt文件中显示虚拟商品信息的那段代码如下(其实可以自己找找)

    <!--{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>卡号:</strong><span style="color:red;">{$card.card_sn}</span> </li>
                <!--{/if}-->
                <!--{if $card.card_password}-->
                <li style="margin-right:50px;float:left;"> <strong>密码:</strong><span style="color:red;">{$card.card_password}</span> </li>
                <!--{/if}-->
                <!--{if $card.end_date}-->
                <li style="float:left;"> <strong>截止日期:</strong>{$card.end_date} </li>
                <!--{/if}-->
            </ul>
            <!--{/foreach}-->
        <!--{/foreach}-->
    </div>
    <!--{/if}-->

    放到order_done.dwt里一个合适的位置,到此这个功能大概就完成了
    但是我目前为止没有的是支付宝付款是不是能自动的返回这些卡号密码,我都是用余额支付的,如有不正确的地方,请不吝指正

  • 相关阅读:
    CSS HACK:IE6、IE7、IE8、Firefox兼容性问题解决方案
    C# @符号的多种使用方法
    16个Javascript的Web UI库、框架及工具包
    【分享】20个很不错的UI图标集资源
    JQuery/AjaX/Javascript/DIV+CSS资源下载地址
    发个csdn泄露账户查询地址,没下数据库的童鞋来查一下自己
    【总结】CSS透明度大汇总
    C#综合揭秘——细说事务
    ASP.NET获取客户端、服务器端基础信息集合
    收集的网络上大型的开源图像处理软件代码(提供下载链接)
  • 原文地址:https://www.cnblogs.com/azhw/p/4379076.html
Copyright © 2011-2022 走看看