ecshop支付方式含线下自提

用户展示页面模板所在:如ecshop/theme/default/flow.dwt
后台管理展示页面模板所在:如admin/templates/payment_list.htm

ecshop 支付接口函数库:lib_payment.php

支付方式列表展示模板: payment_list.htm  

支付方式以ecshop插件存在,目录所在地includes/modules/payment

 

admin/payment.php调用read_modules函数读取支付插件目录下的文件名进行支付方式页面列表展示,每一个文件表示一个支付模块。
lib_main.php中的read_modules有2个变量,$set_modules起到锁模块作用,保持互斥,$modules在使用include_once包含支付文件时被赋值。
每个支付模块包含在includes/modules/payment。使用通用的模板,我们提取最简单的支付模块货到付款代码cod.php进行展示:

 <?php


if (!defined('IN_ECS'))
{
    die('Hacking attempt');
}

$payment_lang = ROOT_PATH . 'languages/' .$GLOBALS['_CFG']['lang']. '/payment/cod.php';

if (file_exists($payment_lang))
{
    global $_LANG;

    include_once($payment_lang);
}

/* 模块的基本信息 */
if (isset($set_modules) && $set_modules == TRUE)
{
    $i = isset($modules) ? count($modules) : 0;

    /* 代码 */
    $modules[$i]['code']    = basename(__FILE__, '.php');

    /* 描述对应的语言项 */
    $modules[$i]['desc']    = 'cod_desc';

    /* 是否支持货到付款 */
    $modules[$i]['is_cod']  = '1';

    /* 是否支持在线支付 */
    $modules[$i]['is_online']  = '0';

    /* 支付费用,由配送决定 */
    $modules[$i]['pay_fee'] = '0';

    /* 作者 */
    $modules[$i]['author']  = 'ECSHOP TEAM';

    /* 网址 */
    $modules[$i]['website'] = 'http://www.ecshop.com';

    /* 版本号 */
    $modules[$i]['version'] = '1.0.0';

    /* 配置信息 */
    $modules[$i]['config']  = array();

    return;
}

/**
 * 类
 
*/
class cod
{
    /**
     * 构造函数
     *
     * @access  public
     * @param
     *
     * @return void
     
*/
    function cod()
    {
    }

    function __construct()
    {
        $this->cod();
    }

    /**
     * 提交函数,生成支付代码
     
*/
    function get_code()
    {
        return '';
    }

    /**
     * 处理函数
     
*/
    function response()
    {
        return;
    }
}

?>

相对应的支付方式语言所在目录为:ecshop/languages/XXX/payment,主要设置标题名和标题描述 。

payment.php在取得插件文件中的支付方式的同时读取数据库ecs_payment中有没相应数据,有则取数据库中的名称和描述以及相应信息.

payment.php包含下述各种方法和操作:

list :支付方式列表 ?act=list

install:安装支付方式 ?act=install&code=".$code."

get_config:获取配置参数

edit:编辑支付方式 ?act=edit&code={$code}

post:提交支付方式 post 

uninstall:卸载支付方式 ?act=uninstall&code={$code} 

edit_name:修改支付方式名称 

edit_desc:修改支付方式描述 

edit_order:修改支付方式排序 

edit_pay_fee:修改支付方式费用 

 

同样上门自取可通过参考货到付款方式进行编辑,需另外补充的就是上门自取有提取地址需要设置并保存。 

如:在自定义的selfcollection.php(上门自取支付方式)中添加配置参数以便用户选择到哪个地方提取。如下:

  /* 配置信息 */

    $modules[$i]['config']  = array(
        array('name' => 'address', 'type' => 'textarea', 'value' => '北京,北京西单北大街131号
上海,浦东新区陆家嘴西路168号(近东方名珠)
广州,天河区天河路2号
南京,南京市汉中路89号金鹰国际商城1-6楼
杭州,杭州市钱江城富春路701号'),
    );

采用多文本区域输入, 每一行分别表示地区及店面地址,在用户页面展示过程中需处理成多行。

在获取支付方式的过程中判断支付方式如果为上门自取时,处理代码如下:

else if($payment['pay_code'] == 'selfcollection')
            {
                $payment = payment_info($payment['pay_id']);
                if(!empty($payment))
                {
                    $pay_config = unserialize_config($payment['pay_config']);

                    $pay_config['address'] = str_replace("<br />","\r\n",$pay_config['address']);
                    $pay_config_array = explode("\r\n", $pay_config['address']);

                    $pay_array = array();
                    for($index=0;$index<count($pay_config_array);$index++)
                    {
                        $delimiter = explode(',', $pay_config_array[$index]);
                        $pay_array[$index]['id'] = $index;
                        $pay_array[$index]['name'] = $delimiter[0];
                        $pay_array[$index]['addr'] = $delimiter[1];
                    }
                    $smarty->assign('pay_array', $pay_array);
                    $smarty->assign('pay_count',  count($pay_config_array));
                }
            }           

 

同样的在模板展示flow.dwt中的代码如下:

<!--{if $pay_count neq 0}-->
    <div class="flowBox">
    <h6><span>{$lang.selfcollection}</span></h6>
    <table width="99%" align="center" border="0" cellpadding="5" cellspacing="1" bgcolor="#dddddd" id="payArray" {if $order.pay_id neq "4"}style="display:none"{/if}> //order.pay_id 等于4表示上门自取的支付方式,在实际测试建议判断唯一标示pay_code为selfcollection
    
            <tr>
              <th width="5%" bgcolor="#ffffff">&nbsp;</th>
              <th width="20%" bgcolor="#ffffff">{$lang.name}</th>
              <th bgcolor="#ffffff">{$lang.describe}</th>
            </tr>
            <!-- {foreach from=$pay_array item=pay_cod} -->
            <!-- 循环上门自取方式 -->
            <tr>
              <td valign="top" bgcolor="#ffffff"><input type="radio" name="selfcollection" value="{$pay_cod.id}" /></td>
              <td valign="top" bgcolor="#ffffff"><strong>{$pay_cod.name}</strong></td>
              <td valign="top" bgcolor="#ffffff">{$pay_cod.addr}</td>
            </tr>
            <!-- {/foreach} 循环上门自取方式 -->
          </table>
    </div>
    <!--{else}-->
        <input name = "payment" type="radio" value = "-1" checked="checked"  style="display:none"/>
    <!--{/if}-->

 

另外在选择支付方式过程中,使用JS实现上门自取地址动态显示和隐藏:

/* *
 * 改变支付方式
 
*/
function selectPayment(obj)
{
  if (selectedPayment == obj)
  {
    return;
  }
  else
  {
    selectedPayment = obj;
  }
  
  var payCode = obj.attributes['payCode'].value;
  var theForm = obj.form;
  for (i = 0; i < theForm.elements.length; i ++ )
  {
      if(payCode == "selfcollection")
      {
          if (theForm.elements[i].name == 'selfcollection')
          {
                theForm.elements[i].checked = true;
                theForm.elements[i].disabled = false;
                document.getElementById("payArray").style.display = "table";
                //document.getElementById("payArray").style.visibility = "visible";
          }
      }
      else
      {
          if (theForm.elements[i].name == 'selfcollection')
          {
                theForm.elements[i].checked = false;
                theForm.elements[i].disabled = true;
                document.getElementById("payArray").style.display = "none";
                //document.getElementById("payArray").style.visibility = "hidden";
          }
      }
    
  }

  Ajax.call('flow.php?step=select_payment', 'payment=' + obj.value, orderSelectedResponse, 'GET', 'JSON');
}

 

通过查看购物车flow.php中的提交表单流程done,我们可以看到在提交表单之后ecshop分别把$order相应的数据插入到ecs_order_info订单信息表,同时把ecs_cart购物车的物品的部分信息插入到ecs_order_goods商品信息表中 。这边要注意的一个函数调用 $GLOBALS['db']->autoExecute($GLOBALS['ecs']->table('order_info'), $order, 'INSERT');相应的函数声明在cls_mysql609行,主要参数名分别为表单名,数据,以及数据库操作方法,通过读取数据中的字段如果匹配到数据表中的字段名,则执行相应的数据库操作(如insert,update)。

 

同样的我们要把上门自取的地址和ID在提交表单过程中写入到数据表单中, 首先要做的是在ecs_order_goodes中插入2个上门自取的ID和地址name字段名,如下:

ALTER TABLE `ecs_order_info` add column `selfcol_id` TINYINT(3NOT NULL DEFAULT '0';

ALTER TABLE `ecs_order_info` add column `selfcol_name` VARCHAR(120) COLLATE utf8_general_ci NOT NULL DEFAULT '';

然后在执行提交表单操作done过程中,通过判断支付方式为上门自取的时候,提取相应的ID和name保存到$order字段中即可。

/* 支付方式 */
    if ($order['pay_id'] > 0)
    {
        $payment = payment_info($order['pay_id']);
        
        if($payment['pay_code'] == 'selfcollection')
        {
            $order['selfcol_id'] = intval($_POST['selfcollection']);
            
            $pay_config = unserialize_config($payment['pay_config']);
            $pay_config['address'] = str_replace("<br />","\r\n",$pay_config['address']);
            $pay_config_array = explode("\r\n", $pay_config['address']);

            $pay_array = array();
            for($index=0;$index<count($pay_config_array);$index++)
            {
                $delimiter = explode(',', $pay_config_array[$index]);
                $pay_array[$index]['id'] = $index;
                $pay_array[$index]['name'] = $delimiter[0];
                $pay_array[$index]['addr'] = $delimiter[1];
            }
            $order['selfcol_name'] = addslashes($pay_array[$order['selfcol_id']]['addr']);
        }
        
        $order['pay_name'] = addslashes($payment['pay_name']); 
    }

实际演示过程就可以看到ecs_order_goods数据已保存成功。

  

posted @ 2013-07-16 18:44  wang_tale  阅读(2822)  评论(0编辑  收藏  举报