技术&教程 < 首页
16 Mar

[转载]EcShop充值卡功能插件

By: Soil 0 COMMENTS
首先在数据库建立礼品卡表名称:***_ks_cardcats


cat_id  分类id    smallint(5)
cat_name    分类名称  varchar(90)
cat_mark    分类标识  varchar(20)
cat_desc    分类描述  varchar(255)
cat_sgn     选择量    smallint(5)


以UTF-8为例  写一段SQL语句创建表
CREATE TABLE `newguo`.`ecs_ks_cardcats` (
`cat_id` SMALLINT( 5 ) UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY ,
`cat_name` VARCHAR( 90 ) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL ,
`cat_mark` VARCHAR( 20 ) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL ,
`cat_desc` VARCHAR( 255 ) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL ,
`cat_sgn` SMALLINT( 5 ) UNSIGNED NOT NULL
) ENGINE = MYISAM ;


礼品卡绑定商品数据表  ***_ks_cardgoods
字段
cg_id       id          smallint(5)
cg_catid    礼品卡分类  smallint(5)
cg_goodid   商品id      smallint(5)

SQL:
CREATE TABLE `newguo`.`ecs_ks_cardgoods` (
`cg_id` SMALLINT( 5 ) UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY ,
`cg_catid` SMALLINT( 5 ) UNSIGNED NOT NULL ,
`cg_goodid` SMALLINT( 5 ) UNSIGNED NOT NULL
) ENGINE = MYISAM ;

礼品卡数据库表名称:   ***_ks_cards
字段
card_id     礼品卡id           smallint(5)
card_type   礼品卡分类         smallint(5)
card_sn     礼品卡序号         varchar(20)
card_pwd    礼品卡密码         int(10)
add_time    创建时间           int(10)
used_time   使用时间           int(10)
order_id    订单id(未使用为0)  smallint(5)

SQL:
CREATE TABLE `newguo`.`ecs_ks_cards` (
`card_id` SMALLINT( 5 ) UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY ,
`card_type` SMALLINT( 5 ) UNSIGNED NOT NULL ,
`card_sn` VARCHAR( 20 ) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL ,
`card_pwd` VARCHAR( 20 ) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL ,
`add_time` INT( 10 ) UNSIGNED NOT NULL ,
`used_time` INT( 10 ) UNSIGNED NOT NULL ,
`order_id` SMALLINT( 5 ) UNSIGNED NOT NULL
) ENGINE = MYISAM ;

礼品卡订单数据表:   ***_ecs_ks_order
字段
order_id          订单id                      smallint(5)
order_sn          订单号                      varchar(20)
card_id           礼品卡id                      smallint(5)
order_goodcatid   礼品卡分类id                smallint(5)
order_user        联系人                      varchar(20)
order_address     订单地址                    varchar(255)
order_tel         联系电话                    varchar(60)
order_phone       移动电话                    varchar(60)
order_bak         特殊要求备注                varchar(255)
shipping_time     配送时间(全天,上午,下午)    varchar(20)
order_time        订单创建时间                int(10)
order_goods       选择的商品                  varchar(20)
order_status      订单状态                    tinyint(1)
ps: order_status 0正常 1确认 2配送 3完成

SQL:
CREATE TABLE `newguo`.`ecs_ks_order` (
`order_id` SMALLINT( 5 ) UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY ,
`order_sn` VARCHAR( 20 ) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL ,
`card_id` SMALLINT( 5 ) UNSIGNED NOT NULL ,
`order_goodcatid` SMALLINT( 5 ) UNSIGNED NOT NULL ,
`order_user` VARCHAR( 20 ) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL ,
`order_address` VARCHAR( 255 ) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL ,
`order_tel` VARCHAR( 60 ) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL ,
`order_phone` VARCHAR( 60 ) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL ,
`order_bak` VARCHAR( 255 ) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL ,
`shipping_time` VARCHAR( 20 ) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL ,
`order_time` INT( 10 ) UNSIGNED NOT NULL ,
`order_goods` VARCHAR( 20 ) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL ,
`order_status` TINYINT( 1 ) UNSIGNED NOT NULL DEFAULT '0'
) ENGINE = MYISAM ;

充值卡数据表:   ***_kt_bcards
字段
card_id     储值卡id        smallint(5)
card_sn     储值卡序号      int(10)
card_pwd    储值卡密码      int(10)
add_time    创建时间        int(10)
used_time   上次使用时间    int(10)
card_type   储值卡初始金额  decimal(10,2)
card_bonus  储值卡内余额    decimal(10,2)

SQL:
CREATE TABLE `newguo`.`ecs_kt_bcards` (
`card_id` SMALLINT( 5 ) UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY ,
`card_sn` VARCHAR( 20 ) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL ,
`card_pwd` VARCHAR( 20 ) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL ,
`add_time` INT( 10 ) UNSIGNED NOT NULL ,
`used_time` INT( 10 ) UNSIGNED NOT NULL ,
`card_type` DECIMAL( 10, 2 ) NOT NULL DEFAULT '0.00',
`card_bonus` DECIMAL( 10, 2 ) NOT NULL DEFAULT '0.00'
) ENGINE = MYISAM ;

储值卡订单:   ***_kt_order
字段:
order_id       订单id                      smallint(5)
card_id        储值卡id                    smallint(5)
order_sn       订单号                      varchar(20)
order_fee      订单总价                    decimal(10,2)
order_exc      还需支付价格                decimal(10,2)   
order_clr      清空储值卡余额赠送礼品      decimal(10,2)       默认0 不赠送不清空
order_user     联系人                      varchar(20)
order_address  订单地址                    varchar(255)
order_tel      联系电话                    varchar(60)
order_phone    移动电话                    varchar(60)
order_bak      特殊要求备注                varchar(255)
shipping_time  配送时间(全天,上午,下午)    varchar(20)
order_time     订单创建时间                int(10)
order_goods    选择的商品                  varchar(255)
order_status   订单状态                    tinyint(1)
ps: order_status 0正常 1确认 2配送 3完成

SQL:
CREATE TABLE `newguo`.`ecs_kt_order` (
`order_id` SMALLINT( 5 ) UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY ,
`card_id` SMALLINT( 5 ) UNSIGNED NOT NULL ,
`order_sn` VARCHAR( 20 ) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL ,
`order_fee` DECIMAL( 10, 2 ) NOT NULL DEFAULT '0.00',
`order_exc` DECIMAL( 10, 2 ) NOT NULL DEFAULT '0.00',
`order_clr` DECIMAL( 10, 2 ) UNSIGNED NOT NULL DEFAULT '0.00',
`order_user` VARCHAR( 20 ) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL ,
`order_address` VARCHAR( 255 ) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL ,
`order_tel` VARCHAR( 60 ) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL ,
`order_phone` VARCHAR( 60 ) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL ,
`order_bak` VARCHAR( 255 ) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL ,
`shipping_time` VARCHAR( 20 ) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL ,
`order_time` INT( 10 ) UNSIGNED NOT NULL ,
`order_goods` VARCHAR( 255 ) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL ,
`order_status` TINYINT( 1 ) UNSIGNED NOT NULL DEFAULT '0'
) ENGINE = MYISAM ;

储值卡绑定订单的商品数据表:   ***_kt_goods

字段:
bg_id        id         smallint(5)
bg_orderid   订单id     smallint(5)
bg_goodid    商品id     smallint(5)
bg_num       商品数量   smallint(5)

SQL:
CREATE TABLE `newguo`.`ecs_kt_goods` (
`bg_id` SMALLINT( 5 ) UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY ,
`bg_orderid` SMALLINT( 5 ) UNSIGNED NOT NULL ,
`bg_goodid` SMALLINT( 5 ) UNSIGNED NOT NULL ,
`bg_num` SMALLINT( 5 ) UNSIGNED NOT NULL
) ENGINE = MYISAM ;

在后台还要加一些权限,目录
主要文件
inc_menu.php
inc_priv.php
priv_action.php

INSERT INTO `newguo`.`ecs_admin_action` (
`action_id` ,
`parent_id` ,
`action_code`
)
VALUES (
'136' , '0', 'card_and_card'
);

INSERT INTO `newguo`.`ecs_admin_action` (
`action_id` ,
`parent_id` ,
`action_code`
)
VALUES (
NULL , '136', 'ks_card_cat'
);

INSERT INTO `newguo`.`ecs_admin_action` (
`action_id` ,
`parent_id` ,
`action_code`
)
VALUES (
NULL , '136', 'ks_card_list'
);

INSERT INTO `newguo`.`ecs_admin_action` (
`action_id` ,
`parent_id` ,
`action_code`
)
VALUES (
NULL , '136', 'ks_card_order'
);

INSERT INTO `newguo`.`ecs_admin_action` (
`action_id` ,
`parent_id` ,
`action_code`
)
VALUES (
NULL , '136', 'kt_card_list'
);

INSERT INTO `newguo`.`ecs_admin_action` (
`action_id` ,
`parent_id` ,
`action_code`
)
VALUES (
NULL , '136', 'kt_card_order'
);

到现在位置  所有的准备工作都已经做完了,下一步就是页面布局,功能的实现了


修改后台目录
admin/includes/inc_menu.php

最下边添加
$modules['17_card_and_card']['ks_card_cat']               = 'ks_card.php?act=cat';
$modules['17_card_and_card']['ks_card_list']              = 'ks_card.php?act=list';
$modules['17_card_and_card']['ks_card_order']             = 'ks_card.php?act=order';
$modules['17_card_and_card']['kt_card_list']              = 'kt_card.php?act=list';
$modules['17_card_and_card']['kt_card_order']             = 'kt_card.php?act=order';


admin/includes/inc_priv.php
添加:

//礼品卡权限管理
$purview['ks_card_cat']             = 'card_and_card';
$purview['ks_card_list']            = 'card_and_card';
$purview['ks_card_order']           = 'card_and_card';
$purview['kt_card_list']            = 'card_and_card';
$purview['kt_card_order']           = 'card_and_card';

在admin下
创建ks_card.php
由于文件比较长,基本都是一些crud 我直接展示代码  不懂的地方留言吧

<?php

define('IN_ECS', true);

require(dirname(__FILE__) . '/includes/init.php');


if (empty($_REQUEST['act']))
{
    $_REQUEST['act'] = 'cat';
}
else
{
    $_REQUEST['act'] = trim($_REQUEST['act']);
}


$exc = new exchange($ecs->table('bonus_type'), $db, 'type_id', 'type_name');


//-- 礼品卡分类列表

if ($_REQUEST['act'] == 'cat')
{
    $smarty->assign('ur_here',     '礼品卡分类');
    $smarty->assign('action_link', array('text' => '添加礼品卡类型', 'href' => 'ks_card.php?act=add'));
    $smarty->assign('full_page',   1);

    $list = get_type_list();

    $smarty->assign('type_list',    $list);

    assign_query_info();
    $smarty->display('ks_card_type.htm');
}


if ($_REQUEST['act'] == 'edit_card_type')
{
      $card_id = !empty($_REQUEST['cid'])    ? intval($_REQUEST['cid'])    : 0;
      $card_type = !empty($_REQUEST['tid'])    ? intval($_REQUEST['tid'])    : 0;
   
    $smarty->assign('lang',         $_LANG);
    $smarty->assign('ur_here',     '编辑礼品卡类别');
    $smarty->assign('action_link', array('text' => '礼品卡列表', 'href' => "ks_card.php?act=list"));
    $smarty->assign('action',       'edit_card_type');
   
    $smarty->assign('card_name',     get_type_name($card_type));
    $smarty->assign('form_act',     'card_type_update');
    $smarty->assign('card_id',     $card_id);
    $smarty->assign('card_type',     $card_type);
    $smarty->assign('cfg_lang',     $_CFG['lang']);
    $list = get_catd_type_list();
    $smarty->assign('type_list',    $list);
    assign_query_info();
    $smarty->display('ks_edit_card_type.htm');

}


//-- 修改礼品卡分类


if ($_REQUEST['act'] == 'card_type_update')
{
    
    $card_id     = !empty($_REQUEST['cid'])    ? intval($_REQUEST['cid'])    : 0;
    $up_card_type     = !empty($_REQUEST['card_type'])    ? intval($_REQUEST['card_type'])    : 0;
    $sql = "UPDATE " .$ecs->table('ks_cards'). " SET ".
           "card_type        = '$up_card_type'".
           "WHERE card_id    = '$card_id'";
    $db->query($sql);
   
    $url = "ks_card.php?act=edit_card_type&cid=$card_id&tid=$up_card_type";

    ecs_header("Location: $url\n");
    exit;
}


//-- 导出线下发放的信息

if ($_REQUEST['act'] == 'excel')
{
    @set_time_limit(0);

   
    $tid  = !empty($_GET['tid']) ? intval($_GET['tid']) : 0;
    $type_name = $db->getOne("SELECT cat_name FROM ".$ecs->table('ks_cardcats')." WHERE cat_id = '$tid'");

   
    $bonus_filename = $type_name .'_bonus_list';
    if (EC_CHARSET != 'gbk')
    {
        $bonus_filename = ecs_iconv('UTF8', 'GB2312',$bonus_filename);
    }

    header("Content-type: application/vnd.ms-excel; charset=utf-8");
    header("Content-Disposition: attachment; filename=$bonus_filename.xls");

   
    if (EC_CHARSET != 'gbk')
    {
        echo ecs_iconv('UTF8', 'GB2312', '礼品卡序号') ."\t";
        echo ecs_iconv('UTF8', 'GB2312', '礼品卡密码') ."\t\n";
    }
    else
    {
        echo "礼品卡序号" ."\t";
        echo "礼品卡密码" ."\t\n";
    }

    $val = array();
    $sql = "SELECT card_sn, card_pwd ".
           "FROM ".$ecs->table('ks_cards').
           "WHERE  card_type = '$tid' ORDER BY card_id";
    $res = $db->query($sql);

    $code_table = array();
    while ($val = $db->fetchRow($res))
    {
        echo $val['card_sn'] . "\t";
        echo $val['card_pwd'] . "\t";
        echo "\t\n";
    }
}



function get_catd_type_list()
{

  
    $sql = "SELECT * FROM " .$GLOBALS['ecs']->table('ks_cardcats');
                           
    $result = $GLOBALS['db']->getAll($sql);
    $goods = array();
   
    foreach ($result AS $idx => $row)
    {
       
          $goods[$idx]['cat_id']           = $row['cat_id'];
        $goods[$idx]['cat_name']           = $row['cat_name'];

    }

return $goods;
}


if ($_REQUEST['act'] == 'edit_card')
{
      $type_id     = !empty($_REQUEST['tid'])    ? intval($_REQUEST['tid'])    : 0;
   
    $smarty->assign('lang',         $_LANG);
    $smarty->assign('ur_here',     '礼品卡列表');
    $smarty->assign('action_link', array('text' => '礼品卡列表', 'href' => "ks_card.php?act=list"));
    $smarty->assign('action',       'edit_card');

    $smarty->assign('form_act',     'card_update');
    $smarty->assign('type_id',     $type_id);
    $smarty->assign('cfg_lang',     $_CFG['lang']);

    assign_query_info();
    $smarty->display('ks_edit_card.htm');

}



//-- 翻页、排序


if ($_REQUEST['act'] == 'query')
{
    $list = get_order_list();

    $smarty->assign('type_list',    $list['item']);
    $smarty->assign('filter',       $list['filter']);
    $smarty->assign('record_count', $list['record_count']);
    $smarty->assign('page_count',   $list['page_count']);

    $sort_flag  = sort_flag($list['filter']);
    $smarty->assign($sort_flag['tag'], $sort_flag['img']);

    make_json_result($smarty->fetch('ks_order_list.htm'), '',
        array('filter' => $list['filter'], 'page_count' => $list['page_count']));
}


//-- 礼品实卡列表


if ($_REQUEST['act'] == 'list')
{
   
     
    $type_id     = !empty($_REQUEST['tid'])    ? intval($_REQUEST['tid'])    : 0;
    $card_id     = !empty($_REQUEST['id'])    ? intval($_REQUEST['id'])    : 0;
    $pageid = !empty($_REQUEST['page'])    ? intval($_REQUEST['page'])    : 1;
      $pagesize = 50;
   
    $smarty->assign('ur_here',     '礼品卡实卡');
    $smarty->assign('action_link', array('text' => '生成礼品卡', 'href' => "ks_card.php?act=edit_card&tid=$type_id"));
    $smarty->assign('full_page',   1);

    $list = get_card_list($type_id,$card_id,$pagesize,$pageid);
   
    $pages = get_card_page($pagesize,$type_id);

    $smarty->assign('type_list',    $list);
    $smarty->assign('pages',    $pages);

    assign_query_info();
    $smarty->display('ks_card_list.htm');
}



function get_card_page($pagesize,$type_id)
{
    if($type_id == 0)
        {
    $sql = "SELECT COUNT(*) FROM " .$GLOBALS['ecs']->table('ks_cards'); 
      }
    else
      {
    $sql = "SELECT COUNT(*) FROM " .$GLOBALS['ecs']->table('ks_cards') . " WHERE card_type = '$type_id'"; 
      }  
    $total = $GLOBALS['db']->getOne($sql);
   
    $total = intval($total);
    $pagesize = intval($pagesize);
   
    $pages = ceil($total/$pagesize); //计算总分页
   
    for ($i = 1; $i <= $pages; $i++)
    {
        if($type_id == 0)
        {
            $pagestr.="<a href="ks_card.php?act=list&page=".$i."">第".$i."页</a>&nbsp;&nbsp;";
        }
        else
        {
        $pagestr.="<a href="ks_card.php?act=list&tid=".$type_id."&page=".$i."">第".$i."页</a>&nbsp;&nbsp;";
      }
    }

return $pagestr;

}


//-- 生成礼品实卡


if ($_REQUEST['act'] == 'card_update')
{
   
     
    $type_id     = !empty($_REQUEST['tid'])    ? intval($_REQUEST['tid'])    : 0;
    $bnum     = !empty($_REQUEST['bnum'])    ? intval($_REQUEST['bnum'])    : 0;
    $cnum     = !empty($_REQUEST['cnum'])    ? intval($_REQUEST['cnum'])    : 0;
   
    if($type_id != 0)
    {
    create_card($type_id,$bnum,$cnum);
    }
 
    $url = "ks_card.php?act=list&tid=$type_id";

    ecs_header("Location: $url\n");
    exit;
}


//-- 删除礼品卡实卡

if ($_REQUEST['act'] == 'delsn')
{
    check_authz_json('card_and_card');

    $id = intval($_GET['id']);
    $tid = intval($_GET['tid']);

//   $exc->drop($id);


   
    $db->query("DELETE FROM " .$ecs->table('ks_cards'). " WHERE card_id = '$id'");

    $url = "ks_card.php?act=list&tid=$tid";

    ecs_header("Location: $url\n");
    exit;

}


//-- 礼品卡订单详情


if ($_REQUEST['act'] == 'order_info')
{
   
     
    $order_id     = !empty($_REQUEST['id'])    ? intval($_REQUEST['id'])    : 0;
   
    $smarty->assign('lang',         $_LANG);
    $smarty->assign('ur_here',     '订单详情');
    $smarty->assign('action_link', array('text' => '订单列表', 'href' => "ks_card.php?act=order"));
    $smarty->assign('action',       'order_info');

    $smarty->assign('form_act',     'order_update');
    $smarty->assign('cfg_lang',     $_CFG['lang']);

    $list = $db->getRow("SELECT * FROM " .$ecs->table('ks_order'). " WHERE order_id = '$order_id'");

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

    assign_query_info();
    $smarty->display('ks_order_info.htm');

}

//-- 订单编辑页面


if ($_REQUEST['act'] == 'order_update')
{

   
    $id        = !empty($_POST['id'])    ? intval($_POST['id'])    : 0;
    $order_user      = !empty($_POST['order_user'])  ? trim($_POST['order_user'])    : '';
    $order_address   = !empty($_POST['order_address'])  ? trim($_POST['order_address'])    : '';
    $order_tel      = !empty($_POST['order_tel'])  ? trim($_POST['order_tel'])    : '';
    $order_phone      = !empty($_POST['order_phone'])  ? trim($_POST['order_phone'])    : '';
    $order_bak      = !empty($_POST['order_bak'])  ? trim($_POST['order_bak'])    : '';
    $shipping_time      = !empty($_POST['shipping_time'])  ? trim($_POST['shipping_time'])    : '';


    $sql = "UPDATE " .$ecs->table('ks_order'). " SET ".
           "order_user        = '$order_user', ".
           "order_address        = '$order_address', ".
           "order_tel        = '$order_tel', ".
           "order_phone         = '$order_phone', ".
           "order_bak         = '$order_bak', ".
           "shipping_time         = '$shipping_time' ".
           "WHERE order_id    = '$id'";

   $db->query($sql);

  
  
   clear_cache_files();

  
   $link[] = array('text' => '返回此订单' , 'href' => "ks_card.php?act=order_info&id=$id");
   sys_msg($_LANG['edit'] .' '.$_POST['type_name'].' '. $_LANG['attradd_succed'], 0, $link);
  
  }


//-- 订单列表

if ($_REQUEST['act'] == 'order')
{
      $keywords      = trim($_POST['keywords']);
      $order_id     = !empty($_REQUEST['id'])    ? intval($_REQUEST['id'])    : 0;
         
    $smarty->assign('ur_here',     '礼品卡订单列表');
    $smarty->assign('action_link', array('text' => '礼品卡类型', 'href' => 'ks_card.php?act=cat'));
    $smarty->assign('full_page',   1);

    $list = get_order_list($keywords,$order_id);

    $smarty->assign('type_list',    $list['item']);
    $smarty->assign('filter',       $list['filter']);
    $smarty->assign('record_count', $list['record_count']);
    $smarty->assign('page_count',   $list['page_count']);

    $sort_flag  = sort_flag($list['filter']);
    $smarty->assign($sort_flag['tag'], $sort_flag['img']);

    assign_query_info();
    $smarty->display('ks_order_list.htm');
}


//-- 礼品卡商品配送信息

if ($_REQUEST['act'] == 'goods')
{
      $id = $_GET['gid'];
     
    $smarty->assign('ur_here',     '礼品卡配送商品');
    $smarty->assign('action_link', array('text' => '礼品卡订单列表', 'href' => 'ks_card.php?act=order'));
    $smarty->assign('full_page',   1);

    $list = get_order_goods_list($id);

    $smarty->assign('type_list',    $list);

    assign_query_info();
    $smarty->display('ks_order_goods.htm');
}


//-- 删除礼品卡类型

if ($_REQUEST['act'] == 'remove')
{
    check_authz_json('card_and_card');

    $id = intval($_GET['tid']);

//   $exc->drop($id);

   
    $db->query("DELETE FROM " .$ecs->table('ks_cardgoods'). " WHERE cg_catid = '$id'");

   
    $db->query("DELETE FROM " .$ecs->table('ks_cardcats'). " WHERE cat_id = '$id'");
   
   
    $db->query("DELETE FROM " .$ecs->table('ks_cards'). " WHERE card_type = '$id'");

    $url = "ks_card.php?act=cat";

    ecs_header("Location: $url\n");
    exit;

}


//-- 礼品卡类型添加

if ($_REQUEST['act'] == 'add')
{
    admin_priv('card_and_card');

    $smarty->assign('lang',         $_LANG);
    $smarty->assign('ur_here',      '添加礼品卡类型');
    $smarty->assign('action_link',  array('href' => 'ks_card.php?act=cat', 'text' => '礼品卡类型列表'));
    $smarty->assign('action',       'add');

    $smarty->assign('form_act',     'insert');
    $smarty->assign('cfg_lang',     $_CFG['lang']);

    $next_month = local_strtotime('+1 months');
    $bonus_arr['send_start_date']   = local_date('Y-m-d');
    $bonus_arr['use_start_date']    = local_date('Y-m-d');
    $bonus_arr['send_end_date']     = local_date('Y-m-d', $next_month);
    $bonus_arr['use_end_date']      = local_date('Y-m-d', $next_month);

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

    assign_query_info();
    $smarty->display('ks_card_type_info.htm');
}


//-- 红包类型添加的处理

if ($_REQUEST['act'] == 'insert')
{
   
    $type_name   = !empty($_POST['type_name']) ? trim($_POST['type_name']) : '';
    $type_mark   = !empty($_POST['type_mark']) ? trim($_POST['type_mark']) : '';
    $type_desc   = !empty($_POST['type_desc']) ? trim($_POST['type_desc']) : '';
    $type_num    = !empty($_POST['type_num']) ? trim($_POST['type_num']) : '';

   
//    $type_id     = !empty($_POST['type_id'])    ? intval($_POST['type_id'])    : 0;
//    $min_amount  = !empty($_POST['min_amount']) ? intval($_POST['min_amount']) : 0;

   


   
    $sql = "INSERT INTO ".$ecs->table('ks_cardcats')." (cat_name, cat_mark, cat_desc, cat_sgn)
    VALUES ('$type_name',
            '$type_mark',
            '$type_desc',
            '$type_num')";

    $db->query($sql);
   
   
//    admin_log($_POST['type_name'], 'add', 'bonustype');

   
    clear_cache_files();

   
    $link[0]['text'] = '添加礼品卡类型';
    $link[0]['href'] = 'ks_card.php?act=add';

    $link[1]['text'] = '礼品卡类型列表';
    $link[1]['href'] = 'ks_card.php?act=cat';

    sys_msg($_LANG['add'] . "&nbsp;" .$_POST['type_name'] . "&nbsp;" . $_LANG['attradd_succed'],0, $link);

}


//-- 礼品卡类型编辑页面

if ($_REQUEST['act'] == 'edit')
{
    admin_priv('card_and_card');

   
    $type_id = !empty($_GET['tid']) ? intval($_GET['tid']) : 0;
    $bonus_arr = $db->getRow("SELECT * FROM " .$ecs->table('ks_cardcats'). " WHERE cat_id = '$type_id'");

//    $bonus_arr['send_start_date']   = local_date('Y-m-d', $bonus_arr['send_start_date']);
//    $bonus_arr['send_end_date']     = local_date('Y-m-d', $bonus_arr['send_end_date']);
//    $bonus_arr['use_start_date']    = local_date('Y-m-d', $bonus_arr['use_start_date']);
//    $bonus_arr['use_end_date']      = local_date('Y-m-d', $bonus_arr['use_end_date']);

    $smarty->assign('lang',        $_LANG);
    $smarty->assign('ur_here',     '礼品卡类型编辑');
    $smarty->assign('action_link', array('href' => 'ks_card.php?act=cat' , 'text' => '返回礼品卡类型列表'));
    $smarty->assign('form_act',    'update');
    $smarty->assign('bonus_arr',   $bonus_arr);

    assign_query_info();
    $smarty->display('ks_card_type_info.htm');
}


//-- 礼品卡类型编辑的处理

if ($_REQUEST['act'] == 'update')
{
   

   
    $type_name   = !empty($_POST['type_name'])  ? trim($_POST['type_name'])    : '';
    $type_mark   = !empty($_POST['type_mark'])  ? trim($_POST['type_mark'])    : '';
    $type_desc   = !empty($_POST['type_desc'])  ? trim($_POST['type_desc'])    : '';
    $type_num    = !empty($_POST['type_num'])   ? intval($_POST['type_num'])   : 0;
    $type_id     = !empty($_POST['type_id'])    ? intval($_POST['type_id'])    : 0;
//    $min_amount  = !empty($_POST['min_amount']) ? intval($_POST['min_amount']) : 0;

    $sql = "UPDATE " .$ecs->table('ks_cardcats'). " SET ".
           "cat_name        = '$type_name', ".
           "cat_mark        = '$type_mark', ".
           "cat_desc        = '$type_desc', ".
           "cat_sgn         = '$type_num' ".
           "WHERE cat_id    = '$type_id'";

   $db->query($sql);
  
  
  
   clear_cache_files();

  
   $link[] = array('text' => '返回礼品卡类型列表' , 'href' => 'ks_card.php?act=cat');
   sys_msg($_LANG['edit'] .' '.$_POST['type_name'].' '. $_LANG['attradd_succed'], 0, $link);

}

//-- 修改订单状态

if ($_REQUEST['act'] == 'order_status')
{
    check_authz_json('card_and_card');

    $id = intval($_GET['id']);
    $stat = intval($_GET['stat']);
   
    switch ($stat)
    {
        case 0:
        $sqlstat = "order_status        = 1 ";
        break;
       
        case 1:
        $sqlstat = "order_status        = 2 ";
        break;
       
        case 2:
        $sqlstat = "order_status        = 3 ";
        break;
       
        case 3:
        $sqlstat = "order_status        = 0 ";
        break;
       
        default:
        $sqlstat = "order_status        = 0 ";
    }
 
   $sql = "UPDATE " .$ecs->table('ks_order'). " SET ".
           $sqlstat .
           "WHERE order_id    = '$id'";

   $db->query($sql);

    $url = "ks_card.php?act=order";

    ecs_header("Location: $url\n");
    exit;

}


//-- 处理红包的发送页面

if ($_REQUEST['act'] == 'send_by_user')
{
    $user_list  = array();
    $start      = empty($_REQUEST['start']) ? 0 : intval($_REQUEST['start']);
    $limit      = empty($_REQUEST['limit']) ? 10 : intval($_REQUEST['limit']);
    $validated_email = empty($_REQUEST['validated_email']) ? 0 : intval($_REQUEST['validated_email']);
    $send_count = 0;

    if (isset($_REQUEST['send_rank']))
    {
       
        $rank_id = intval($_REQUEST['rank_id']);

        if ($rank_id > 0)
        {
            $sql = "SELECT min_points, max_points, special_rank FROM " . $ecs->table('user_rank') . " WHERE rank_id = '$rank_id'";
            $row = $db->getRow($sql);
            if ($row['special_rank'])
            {
               
                $sql = 'SELECT COUNT(*) FROM ' . $ecs->table('users'). " WHERE user_rank = '$rank_id'";
                $send_count = $db->getOne($sql);
                if($validated_email)
                {
                    $sql = 'SELECT user_id, email, user_name FROM ' . $ecs->table('users').
                            " WHERE user_rank = '$rank_id' AND is_validated = 1".
                            " LIMIT $start, $limit";
                }
                else
                {
                     $sql = 'SELECT user_id, email, user_name FROM ' . $ecs->table('users').
                                " WHERE user_rank = '$rank_id'".
                                " LIMIT $start, $limit";
                }
            }
            else
            {
                $sql = 'SELECT COUNT(*) FROM ' . $ecs->table('users').
                       " WHERE rank_points >= " . intval($row['min_points']) . " AND rank_points < " . intval($row['max_points']);
                $send_count = $db->getOne($sql);

                if($validated_email)
                {
                    $sql = 'SELECT user_id, email, user_name FROM ' . $ecs->table('users').
                        " WHERE rank_points >= " . intval($row['min_points']) . " AND rank_points < " . intval($row['max_points']) .
                        " AND is_validated = 1 LIMIT $start, $limit";
                }
                else
                {
                     $sql = 'SELECT user_id, email, user_name FROM ' . $ecs->table('users').
                        " WHERE rank_points >= " . intval($row['min_points']) . " AND rank_points < " . intval($row['max_points']) .
                        " LIMIT $start, $limit";
                }

            }

            $user_list = $db->getAll($sql);
            $count = count($user_list);
        }
    }
    elseif (isset($_REQUEST['send_user']))
    {
       
       
        if (empty($_REQUEST['user']))
        {
            sys_msg($_LANG['send_user_empty'], 1);
        }

        $user_array = (is_array($_REQUEST['user'])) ? $_REQUEST['user'] : explode(',', $_REQUEST['user']);
        $send_count = count($user_array);

        $id_array   = array_slice($user_array, $start, $limit);

       
        $sql = "SELECT user_id, email, user_name FROM " .$ecs->table('users').
               " WHERE user_id " .db_create_in($id_array);
        $user_list  = $db->getAll($sql);
        $count = count($user_list);
    }

   
    $loop       = 0;
    $bonus_type = bonus_type_info($_REQUEST['id']);

    $tpl = get_mail_template('send_bonus');
    $today = local_date($_CFG['date_format']);

    foreach ($user_list AS $key => $val)
    {
       
        $smarty->assign('user_name',    $val['user_name']);
        $smarty->assign('shop_name',    $GLOBALS['_CFG']['shop_name']);
        $smarty->assign('send_date',    $today);
        $smarty->assign('sent_date',    $today);
        $smarty->assign('count',        1);
        $smarty->assign('money',        price_format($bonus_type['type_money']));

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

        if (add_to_maillist($val['user_name'], $val['email'], $tpl['template_subject'], $content, $tpl['is_html']))
        {
            
            $sql = "INSERT INTO " . $ecs->table('user_bonus') .
                    "(bonus_type_id, bonus_sn, user_id, used_time, order_id, emailed) " .
                    "VALUES ('$_REQUEST[id]', 0, '$val[user_id]', 0, 0, " .BONUS_MAIL_SUCCEED. ")";
            $db->query($sql);
        }
        else
        {
           
            $sql = "INSERT INTO " . $ecs->table('user_bonus') .
                    "(bonus_type_id, bonus_sn, user_id, used_time, order_id, emailed) " .
                    "VALUES ('$_REQUEST[id]', 0, '$val[user_id]', 0, 0, " .BONUS_MAIL_FAIL. ")";
            $db->query($sql);
        }

        if ($loop >= $limit)
        {
            break;
        }
        else
        {
            $loop++;
        }
    }

    //admin_log(addslashes($_LANG['send_bonus']), 'add', 'bonustype');
    if ($send_count > ($start + $limit))
    {
       
        $href = "bonus.php?act=send_by_user&start=" . ($start+$limit) . "&limit=$limit&id=$_REQUEST[id]&";

        if (isset($_REQUEST['send_rank']))
        {
            $href .= "send_rank=1&rank_id=$rank_id";
        }

        if (isset($_REQUEST['send_user']))
        {
            $href .= "send_user=1&user=" . implode(',', $user_array);
        }

        $link[] = array('text' => $_LANG['send_continue'], 'href' => $href);
    }

    $link[] = array('text' => $_LANG['back_list'], 'href' => 'bonus.php?act=list');

    sys_msg(sprintf($_LANG['sendbonus_count'], $count), 0, $link);
}


//-- 发送邮件


if ($_REQUEST['act'] == 'send_mail')
{
   
    $bonus_id = intval($_REQUEST['bonus_id']);
    if ($bonus_id <= 0)
    {
        die('invalid params');
    }

   
    include_once(ROOT_PATH . 'includes/lib_order.php');
    $bonus = bonus_info($bonus_id);
    if (empty($bonus))
    {
        sys_msg($_LANG['bonus_not_exist']);
    }

   
    $count = send_bonus_mail($bonus['bonus_type_id'], array($bonus_id));

    $link[0]['text'] = $_LANG['back_bonus_list'];
    $link[0]['href'] = 'bonus.php?act=bonus_list&bonus_type=' . $bonus['bonus_type_id'];

    sys_msg(sprintf($_LANG['success_send_mail'], $count), 0, $link);
}


//-- 按印刷品发放红包


if ($_REQUEST['act'] == 'send_by_print')
{
    @set_time_limit(0);

   
    $bonus_typeid = !empty($_POST['bonus_type_id']) ? $_POST['bonus_type_id'] : 0;
    $bonus_sum    = !empty($_POST['bonus_sum'])     ? $_POST['bonus_sum']     : 1;

   
    $num = $db->getOne("SELECT MAX(bonus_sn) FROM ". $ecs->table('user_bonus'));
    $num = $num ? floor($num / 10000) : 100000;

    for ($i = 0, $j = 0; $i < $bonus_sum; $i++)
    {
        $bonus_sn = ($num + $i) . str_pad(mt_rand(0, 9999), 4, '0', STR_PAD_LEFT);
        $db->query("INSERT INTO ".$ecs->table('user_bonus')." (bonus_type_id, bonus_sn) VALUES('$bonus_typeid', '$bonus_sn')");

        $j++;
    }

   
    admin_log($bonus_sn, 'add', 'userbonus');

   
    clear_cache_files();

   
    $link[0]['text'] = $_LANG['back_bonus_list'];
    $link[0]['href'] = 'bonus.php?act=bonus_list&bonus_type=' . $bonus_typeid;

    sys_msg($_LANG['creat_bonus'] . $j . $_LANG['creat_bonus_num'], 0, $link);
}


//-- 导出线下发放的信息

if ($_REQUEST['act'] == 'gen_excel')
{
    @set_time_limit(0);

   
    $tid  = !empty($_GET['tid']) ? intval($_GET['tid']) : 0;
    $type_name = $db->getOne("SELECT type_name FROM ".$ecs->table('bonus_type')." WHERE type_id = '$tid'");

   
    $bonus_filename = $type_name .'_bonus_list';
    if (EC_CHARSET != 'gbk')
    {
        $bonus_filename = ecs_iconv('UTF8', 'GB2312',$bonus_filename);
    }

    header("Content-type: application/vnd.ms-excel; charset=utf-8");
    header("Content-Disposition: attachment; filename=$bonus_filename.xls");

   
    if (EC_CHARSET != 'gbk')
    {
        echo ecs_iconv('UTF8', 'GB2312', $_LANG['bonus_excel_file']) . "\t\n";
       
        echo ecs_iconv('UTF8', 'GB2312', $_LANG['bonus_sn']) ."\t";
        echo ecs_iconv('UTF8', 'GB2312', $_LANG['type_money']) ."\t";
        echo ecs_iconv('UTF8', 'GB2312', $_LANG['type_name']) ."\t";
        echo ecs_iconv('UTF8', 'GB2312', $_LANG['use_enddate']) ."\t\n";
    }
    else
    {
        echo $_LANG['bonus_excel_file'] . "\t\n";
       
        echo $_LANG['bonus_sn'] ."\t";
        echo $_LANG['type_money'] ."\t";
        echo $_LANG['type_name'] ."\t";
        echo $_LANG['use_enddate'] ."\t\n";
    }

    $val = array();
    $sql = "SELECT ub.bonus_id, ub.bonus_type_id, ub.bonus_sn, bt.type_name, bt.type_money, bt.use_end_date ".
           "FROM ".$ecs->table('user_bonus')." AS ub, ".$ecs->table('bonus_type')." AS bt ".
           "WHERE bt.type_id = ub.bonus_type_id AND ub.bonus_type_id = '$tid' ORDER BY ub.bonus_id DESC";
    $res = $db->query($sql);

    $code_table = array();
    while ($val = $db->fetchRow($res))
    {
        echo $val['bonus_sn'] . "\t";
        echo $val['type_money'] . "\t";
        if (!isset($code_table[$val['type_name']]))
        {
            if (EC_CHARSET != 'gbk')
            {
                $code_table[$val['type_name']] = ecs_iconv('UTF8', 'GB2312', $val['type_name']);
            }
            else
            {
                $code_table[$val['type_name']] = $val['type_name'];
            }
        }
        echo $code_table[$val['type_name']] . "\t";
        echo local_date('Y-m-d', $val['use_end_date']);
        echo "\t\n";
    }
}


//-- 搜索商品

if ($_REQUEST['act'] == 'get_goods_list')
{
    include_once(ROOT_PATH . 'includes/cls_json.php');
    $json = new JSON;

    $filters = $json->decode($_GET['JSON']);

    $arr = get_goods_list($filters);
    $opt = array();

    foreach ($arr AS $key => $val)
    {
        $opt[] = array('value'  => $val['goods_id'],
                        'text'  => $val['goods_name'],
                        'data'  => $val['shop_price']);
    }

    make_json_result($opt);
}


//-- 添加发放红包的商品

if ($_REQUEST['act'] == 'add_bonus_goods')
{
    include_once(ROOT_PATH . 'includes/cls_json.php');
    $json = new JSON;

    check_authz_json('card_and_card');

    $add_ids    = $json->decode($_GET['add_ids']);
    $args       = $json->decode($_GET['JSON']);
    $type_id    = $args[0];

    foreach ($add_ids AS $key => $val)
    {
        $sql = "UPDATE " .$ecs->table('goods'). " SET bonus_type_id='$type_id' WHERE goods_id='$val'";
        $db->query($sql, 'SILENT') or make_json_error($db->error());
    }

   
    $arr = get_bonus_goods($type_id);
    $opt = array();

    foreach ($arr AS $key => $val)
    {
        $opt[] = array('value'  => $val['goods_id'],
                        'text'  => $val['goods_name'],
                        'data'  => '');
    }

    make_json_result($opt);
}


//-- 删除发放红包的商品

if ($_REQUEST['act'] == 'drop_bonus_goods')
{
    include_once(ROOT_PATH . 'includes/cls_json.php');
    $json = new JSON;

    check_authz_json('card_and_card');

    $drop_goods     = $json->decode($_GET['drop_ids']);
    $drop_goods_ids = db_create_in($drop_goods);
    $arguments      = $json->decode($_GET['JSON']);
    $type_id        = $arguments[0];

    $db->query("UPDATE ".$ecs->table('goods')." SET bonus_type_id = 0 ".
                "WHERE bonus_type_id = '$type_id' AND goods_id " .$drop_goods_ids);

   
    $arr = get_bonus_goods($type_id);
    $opt = array();

    foreach ($arr AS $key => $val)
    {
        $opt[] = array('value'  => $val['goods_id'],
                        'text'  => $val['goods_name'],
                        'data'  => '');
    }

    make_json_result($opt);
}


//-- 搜索用户

if ($_REQUEST['act'] == 'search_users')
{
    $keywords = json_str_iconv(trim($_GET['keywords']));

    $sql = "SELECT user_id, user_name FROM " . $ecs->table('users') .
            " WHERE user_name LIKE '%" . mysql_like_quote($keywords) . "%' OR user_id LIKE '%" . mysql_like_quote($keywords) . "%'";
    $row = $db->getAll($sql);

    make_json_result($row);
}


//-- 红包列表


if ($_REQUEST['act'] == 'bonus_list')
{
    $smarty->assign('full_page',    1);
    $smarty->assign('ur_here',      $_LANG['bonus_list']);
    $smarty->assign('action_link',   array('href' => 'bonus.php?act=list', 'text' => $_LANG['04_bonustype_list']));

    $list = get_bonus_list();

   
    $bonus_type = bonus_type_info(intval($_REQUEST['bonus_type']));
    if ($bonus_type['send_type'] == SEND_BY_PRINT)
    {
        $smarty->assign('show_bonus_sn', 1);
    }

   
    elseif ($bonus_type['send_type'] == SEND_BY_USER)
    {
        $smarty->assign('show_mail', 1);
    }

    $smarty->assign('bonus_list',   $list['item']);
    $smarty->assign('filter',       $list['filter']);
    $smarty->assign('record_count', $list['record_count']);
    $smarty->assign('page_count',   $list['page_count']);

    $sort_flag  = sort_flag($list['filter']);
    $smarty->assign($sort_flag['tag'], $sort_flag['img']);

    assign_query_info();
    $smarty->display('bonus_list.htm');
}


//-- 红包列表翻页、排序


if ($_REQUEST['act'] == 'query_bonus')
{
    $list = get_bonus_list();

   
    $bonus_type = bonus_type_info(intval($_REQUEST['bonus_type']));
    if ($bonus_type['send_type'] == SEND_BY_PRINT)
    {
        $smarty->assign('show_bonus_sn', 1);
    }

   
    elseif ($bonus_type['send_type'] == SEND_BY_USER)
    {
        $smarty->assign('show_mail', 1);
    }

    $smarty->assign('bonus_list',   $list['item']);
    $smarty->assign('filter',       $list['filter']);
    $smarty->assign('record_count', $list['record_count']);
    $smarty->assign('page_count',   $list['page_count']);

    $sort_flag  = sort_flag($list['filter']);
    $smarty->assign($sort_flag['tag'], $sort_flag['img']);

    make_json_result($smarty->fetch('bonus_list.htm'), '',
        array('filter' => $list['filter'], 'page_count' => $list['page_count']));
}


//-- 删除红包

elseif ($_REQUEST['act'] == 'remove_bonus')
{
    check_authz_json('card_and_card');

    $id = intval($_GET['id']);

    $db->query("DELETE FROM " .$ecs->table('user_bonus'). " WHERE bonus_id='$id'");

    $url = 'bonus.php?act=query_bonus&' . str_replace('act=remove_bonus', '', $_SERVER['QUERY_STRING']);

    ecs_header("Location: $url\n");
    exit;
}


//-- 批量操作

if ($_REQUEST['act'] == 'batch')
{
   
    admin_priv('card_and_card');

   
    $bonus_type_id = intval($_REQUEST['bonus_type']);

   
    if (isset($_POST['checkboxes']))
    {
        $bonus_id_list = $_POST['checkboxes'];

       
        if (isset($_POST['drop']))
        {
            $sql = "DELETE FROM " . $ecs->table('user_bonus'). " WHERE bonus_id " . db_create_in($bonus_id_list);
            $db->query($sql);

            admin_log(count($bonus_id_list), 'remove', 'userbonus');

            clear_cache_files();

            $link[] = array('text' => $_LANG['back_bonus_list'],
                'href' => 'bonus.php?act=bonus_list&bonus_type='. $bonus_type_id);
            sys_msg(sprintf($_LANG['batch_drop_success'], count($bonus_id_list)), 0, $link);
        }

       
        elseif (isset($_POST['mail']))
        {
            $count = send_bonus_mail($bonus_type_id, $bonus_id_list);
            $link[] = array('text' => $_LANG['back_bonus_list'],
                'href' => 'bonus.php?act=bonus_list&bonus_type='. $bonus_type_id);
            sys_msg(sprintf($_LANG['success_send_mail'], $count), 0, $link);
        }
    }
    else
    {
        sys_msg($_LANG['no_select_bonus'], 1);
    }
}


function get_order_goods_list($id)
{

  
    $sql = "SELECT * FROM " .$GLOBALS['ecs']->table('goods') . " WHERE goods_id in ($id)" ;
                           
    $result = $GLOBALS['db']->getAll($sql);
    $goods = array();
   
    foreach ($result AS $idx => $row)
    {
       
          $goods[$idx]['goods_id']           = $row['goods_id'];
        $goods[$idx]['goods_sn']           = $row['goods_sn'];
        $goods[$idx]['goods_name']         = $row['goods_name'];

    }

return $goods;
}


function get_card_list($type_id,$card_id,$pagesize,$pageid)
{
     $startrow = ($pageid-1)*$pagesize;
     
     if($type_id != 0)
     {
    $sql = "SELECT * FROM " .$GLOBALS['ecs']->table('ks_cards').
               " WHERE card_type = '$type_id' ORDER BY card_id desc LIMIT $startrow,$pagesize";
    }
    else
    {
        $sql = "SELECT * FROM " .$GLOBALS['ecs']->table('ks_cards'). " ORDER BY card_id desc LIMIT $startrow,$pagesize";
    }
    if($card_id != 0)
     {
    $sql = "SELECT * FROM " .$GLOBALS['ecs']->table('ks_cards').
               " WHERE card_id = '$card_id' ";
    }
                   
                           
    $result = $GLOBALS['db']->getAll($sql);
    $cards = array();
   
    foreach ($result AS $idx => $row)
    {
       
          $cards[$idx]['id']           = $row['card_id'];
        $cards[$idx]['type_id']         = $row['card_type'];
        $cards[$idx]['type_name']         = get_type_name($row['card_type']);
        $cards[$idx]['card_sn']        = $row['card_sn'];
        $cards[$idx]['card_pwd']        = $row['card_pwd'];
        $cards[$idx]['add_time']        = local_date($GLOBALS['_CFG']['time_format'],$row['add_time']);
       
        if($row['used_time'] == 0)
        {
        $cards[$idx]['used_time']        = $row['used_time'];
        }
        else
        {
        $cards[$idx]['used_time']        = local_date($GLOBALS['_CFG']['time_format'],$row['used_time']);
        }
       
        $cards[$idx]['order_id']        = $row['order_id'];

    }

return $cards;

}



function get_type_name($card_type)

{
    $sql = "SELECT cat_name FROM " .$GLOBALS['ecs']->table('ks_cardcats').
               " WHERE cat_id = '$card_type'";
  $result = $GLOBALS['db']->getOne($sql);
 
  return $result;
              
}



function create_card($type_id,$bnum,$cnum)

{
    if($type_id != 0)
  {
   
    $add_time = gmtime();
    $sn_head = get_sn_head($type_id);
    $used_time = 0;
    $order_id = 0;
    $cnum = $cnum + $bnum;
   
    for ($i = $bnum; $i < $cnum; $i++)
    {
        $card_sn  = $sn_head . str_pad($i, 6, '0', STR_PAD_LEFT);
        $card_pwd = rancard(10,'0123456789');
       
        $sql = "SELECT * FROM " .$GLOBALS['ecs']->table('ks_cards').
                      " WHERE card_sn = '$card_sn'" .
                      " OR card_pwd = '$card_pwd'";

        $record_arr = $GLOBALS['db']->getRow($sql);
        if (empty($record_arr))

             {
        $GLOBALS['db']->query("INSERT INTO ".$GLOBALS['ecs']->table('ks_cards')." (card_type, card_sn, card_pwd, add_time, used_time, order_id) VALUES('$type_id', '$card_sn','$card_pwd','$add_time','$used_time','$order_id')");
 }
             else
             {
                 break;
             }
    }
  }

}



function get_sn_head($card_type)

{
    $sql = "SELECT cat_mark FROM " .$GLOBALS['ecs']->table('ks_cardcats').
               " WHERE cat_id = '$card_type'";
  $result = $GLOBALS['db']->getOne($sql);
 
  return $result;
              
}



function rancard($length,$string = '0123456789abcdefghijklmnopqrstuvwxyz') {
$rstr = '';
$strlen = strlen($string);
for ($i=0; $i<$length; $i++) {
   $rstr .= $string{mt_rand(0,$strlen-1)};
}
return $rstr;
}


function get_type_list()
{

    $sql = "SELECT * FROM " .$GLOBALS['ecs']->table('ks_cardcats');
                   
                           
    $result = $GLOBALS['db']->getAll($sql);
    $cardtype = array();
   
    foreach ($result AS $idx => $row)
    {
       
          $cardtype[$idx]['cat_id']           = $row['cat_id'];
        $cardtype[$idx]['cat_name']         = $row['cat_name'];
        $cardtype[$idx]['cat_mark']         = $row['cat_mark'];
        $cardtype[$idx]['cat_desc']        = $row['cat_desc'];
        $cardtype[$idx]['cat_sgn']        = $row['cat_sgn'];
       
        $cardtype[$idx]['all_num']        = get_all_num($row['cat_id']);
        $cardtype[$idx]['ok_num']        = get_ok_num($row['cat_id']);

    }

return $cardtype;
}



function get_all_num($card_type)

{
    $sql = "SELECT COUNT(*) FROM " .$GLOBALS['ecs']->table('ks_cards').
               " WHERE card_type = '$card_type'";
  $result = $GLOBALS['db']->getOne($sql);
 
  return $result;
              
}



function get_ok_num($card_type)

{
    $sql = "SELECT COUNT(*) FROM " .$GLOBALS['ecs']->table('ks_cards').
               " WHERE card_type = '$card_type' and order_id <> 0";
  $result = $GLOBALS['db']->getOne($sql);
 
  return $result;
              
}


function get_order_list($keywords,$order_id)
{
  
    $result = get_filter();
    if ($result === false)
    {
       
        $filter['sort_by']    = empty($_REQUEST['sort_by']) ? 'order_id' : trim($_REQUEST['sort_by']);
        $filter['sort_order'] = empty($_REQUEST['sort_order']) ? 'DESC' : trim($_REQUEST['sort_order']);

        $sql = "SELECT COUNT(*) FROM ".$GLOBALS['ecs']->table('ks_order');
        $filter['record_count'] = $GLOBALS['db']->getOne($sql);

       
        $filter = page_and_size($filter);
  
        if(empty($keywords))
        {
        $sql = "SELECT * FROM " .$GLOBALS['ecs']->table('ks_order'). " ORDER BY $filter[sort_by] $filter[sort_order]";
        }
        else
        {
        $card_id = get_card_id($keywords);
        $sql = "SELECT * FROM " .$GLOBALS['ecs']->table('ks_order'). " WHERE card_id = '$card_id' ";
        }    
        if(!empty($order_id))
        {
        $sql = "SELECT * FROM " .$GLOBALS['ecs']->table('ks_order'). " WHERE order_id = '$order_id' ";
        }
        set_filter($filter, $sql);
    }
    else
    {
        $sql    = $result['sql'];
        $filter = $result['filter'];
    }
    $arr = array();
    $res = $GLOBALS['db']->selectLimit($sql, $filter['page_size'], $filter['start']);

    while ($row = $GLOBALS['db']->fetchRow($res))
    {
       
        $row['order_goodcatname'] = get_type_name($row['order_goodcatid']);
        $row['order_time'] = local_date($GLOBALS['_CFG']['time_format'],$row['order_time']);
        $arr[] = $row;
    }

    $arr = array('item' => $arr, 'filter' => $filter, 'page_count' => $filter['page_count'], 'record_count' => $filter['record_count']);

    return $arr;
}



function get_card_id($keywords)

{
    $sql = "SELECT card_id FROM " .$GLOBALS['ecs']->table('ks_cards').
               " WHERE card_sn = '$keywords'";
  $result = $GLOBALS['db']->getOne($sql);
 
  return $result;
              
}


function get_bonus_goods($type_id)
{
    $sql = "SELECT goods_id, goods_name FROM " .$GLOBALS['ecs']->table('goods').
            " WHERE bonus_type_id = '$type_id'";
    $row = $GLOBALS['db']->getAll($sql);

    return $row;
}


function get_bonus_list()
{
   
    $filter['sort_by']    = empty($_REQUEST['sort_by']) ? 'bonus_type_id' : trim($_REQUEST['sort_by']);
    $filter['sort_order'] = empty($_REQUEST['sort_order']) ? 'DESC' : trim($_REQUEST['sort_order']);
    $filter['bonus_type'] = empty($_REQUEST['bonus_type']) ? 0 : intval($_REQUEST['bonus_type']);

    $where = empty($filter['bonus_type']) ? '' : " WHERE bonus_type_id='$filter[bonus_type]'";

    $sql = "SELECT COUNT(*) FROM ".$GLOBALS['ecs']->table('user_bonus'). $where;
    $filter['record_count'] = $GLOBALS['db']->getOne($sql);

   
    $filter = page_and_size($filter);

    $sql = "SELECT ub.*, u.user_name, u.email, o.order_sn, bt.type_name ".
          " FROM ".$GLOBALS['ecs']->table('user_bonus'). " AS ub ".
          " LEFT JOIN " .$GLOBALS['ecs']->table('bonus_type'). " AS bt ON bt.type_id=ub.bonus_type_id ".
          " LEFT JOIN " .$GLOBALS['ecs']->table('users'). " AS u ON u.user_id=ub.user_id ".
          " LEFT JOIN " .$GLOBALS['ecs']->table('order_info'). " AS o ON o.order_id=ub.order_id $where ".
          " ORDER BY ".$filter['sort_by']." ".$filter['sort_order'].
          " LIMIT ". $filter['start'] .", $filter[page_size]";
    $row = $GLOBALS['db']->getAll($sql);

    foreach ($row AS $key => $val)
    {
        $row[$key]['used_time'] = $val['used_time'] == 0 ?
            $GLOBALS['_LANG']['no_use'] : local_date($GLOBALS['_CFG']['date_format'], $val['used_time']);
        $row[$key]['emailed'] = $GLOBALS['_LANG']['mail_status'][$row[$key]['emailed']];
    }

    $arr = array('item' => $row, 'filter' => $filter, 'page_count' => $filter['page_count'], 'record_count' => $filter['record_count']);

    return $arr;
}


function bonus_type_info($bonus_type_id)
{
    $sql = "SELECT * FROM " . $GLOBALS['ecs']->table('bonus_type') .
            " WHERE type_id = '$bonus_type_id'";

    return $GLOBALS['db']->getRow($sql);
}


function send_bonus_mail($bonus_type_id, $bonus_id_list)
{
   
    $bonus_type = bonus_type_info($bonus_type_id);
    if ($bonus_type['send_type'] != SEND_BY_USER)
    {
        return 0;
    }

   
    $sql = "SELECT b.bonus_id, u.user_name, u.email " .
            "FROM " . $GLOBALS['ecs']->table('user_bonus') . " AS b, " .
                $GLOBALS['ecs']->table('users') . " AS u " .
            " WHERE b.user_id = u.user_id " .
            " AND b.bonus_id " . db_create_in($bonus_id_list) .
            " AND b.order_id = 0 " .
            " AND u.email <> ''";
    $bonus_list = $GLOBALS['db']->getAll($sql);
    if (empty($bonus_list))
    {
        return 0;
    }

   
    $send_count = 0;

   
    $tpl   = get_mail_template('send_bonus');
    $today = local_date($GLOBALS['_CFG']['date_format']);
    foreach ($bonus_list AS $bonus)
    {
        $GLOBALS['smarty']->assign('user_name',    $bonus['user_name']);
        $GLOBALS['smarty']->assign('shop_name',    $GLOBALS['_CFG']['shop_name']);
        $GLOBALS['smarty']->assign('send_date',    $today);
        $GLOBALS['smarty']->assign('sent_date',    $today);
        $GLOBALS['smarty']->assign('count',        1);
        $GLOBALS['smarty']->assign('money',        price_format($bonus_type['type_money']));

        $content = $GLOBALS['smarty']->fetch('str:' . $tpl['template_content']);
        if (add_to_maillist($bonus['user_name'], $bonus['email'], $tpl['template_subject'], $content, $tpl['is_html'], false))
        {
            $sql = "UPDATE " . $GLOBALS['ecs']->table('user_bonus') .
                    " SET emailed = '" . BONUS_MAIL_SUCCEED . "'" .
                    " WHERE bonus_id = '$bonus[bonus_id]'";
            $GLOBALS['db']->query($sql);
            $send_count++;
        }
        else
        {
            $sql = "UPDATE " . $GLOBALS['ecs']->table('user_bonus') .
                    " SET emailed = '" . BONUS_MAIL_FAIL . "'" .
                    " WHERE bonus_id = '$bonus[bonus_id]'";
            $GLOBALS['db']->query($sql);
        }
    }

    return $send_count;
}

function add_to_maillist($username, $email, $subject, $content, $is_html)
{
    $time = time();
    $content = addslashes($content);
    $template_id = $GLOBALS['db']->getOne("SELECT template_id FROM " . $GLOBALS['ecs']->table('mail_templates') . " WHERE template_code = 'send_bonus'");
    $sql = "INSERT INTO "  . $GLOBALS['ecs']->table('email_sendlist') . " ( email, template_id, email_content, pri, last_send) VALUES ('$email', $template_id, '$content', 1, '$time')";
    $GLOBALS['db']->query($sql);
    return true;
}

?>


在admin下
创建ks_card_goods.php

粘贴代码
<?php


define('IN_ECS', true);

require(dirname(__FILE__) . '/includes/init.php');


if (empty($_REQUEST['act']))
{
    $_REQUEST['act'] = 'cat';
}
else
{
    $_REQUEST['act'] = trim($_REQUEST['act']);
}


$exc = new exchange($ecs->table('bonus_type'), $db, 'type_id', 'type_name');



//-- 排序、分页、查询

if ($_REQUEST['act'] == 'query')
{
      $type_id     = !empty($_REQUEST['tid'])    ? intval($_REQUEST['tid'])    : 0;
   
    $is_delete = empty($_REQUEST['is_delete']) ? 0 : intval($_REQUEST['is_delete']);
    $code = empty($_REQUEST['extension_code']) ? '' : trim($_REQUEST['extension_code']);
    $goods_list = goods_list($is_delete, ($code=='') ? 1 : 0);

    $handler_list = array();
    $handler_list['virtual_card'][] = array('url'=>'virtual_card.php?act=card', 'title'=>$_LANG['card'], 'img'=>'icon_send_bonus.gif');
    $handler_list['virtual_card'][] = array('url'=>'virtual_card.php?act=replenish', 'title'=>$_LANG['replenish'], 'img'=>'icon_add.gif');
    $handler_list['virtual_card'][] = array('url'=>'virtual_card.php?act=batch_card_add', 'title'=>$_LANG['batch_card_add'], 'img'=>'icon_output.gif');

    if (isset($handler_list[$code]))
    {
        $smarty->assign('add_handler',      $handler_list[$code]);
    }

    $smarty->assign('goods_list',   $goods_list['goods']);
    $smarty->assign('filter',       $goods_list['filter']);
    $smarty->assign('record_count', $goods_list['record_count']);
    $smarty->assign('page_count',   $goods_list['page_count']);
    $smarty->assign('list_type',    $is_delete ? 'trash' : 'goods');
    $smarty->assign('use_storage',  empty($_CFG['use_storage']) ? 0 : 1);
   

   
    $sort_flag  = sort_flag($goods_list['filter']);
    $smarty->assign($sort_flag['tag'], $sort_flag['img']);

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

    $tpl = $is_delete ? 'ks_card_goods_list.htm' : 'ks_card_goods_list.htm';

    make_json_result($smarty->fetch($tpl), '',
        array('filter' => $goods_list['filter'], 'page_count' => $goods_list['page_count']));
}


//-- 添加礼品卡配备商品


if ($_REQUEST['act'] == 'goods')
{
    check_authz_json('card_and_card');

   
    $type_id     = !empty($_REQUEST['tid'])    ? intval($_REQUEST['tid'])    : 0;
   
    $cat_id = empty($_REQUEST['cat_id']) ? 0 : intval($_REQUEST['cat_id']);
    $code   = empty($_REQUEST['extension_code']) ? '' : trim($_REQUEST['extension_code']);

    $handler_list = array();
    $handler_list['virtual_card'][] = array('url'=>'virtual_card.php?act=card', 'title'=>$_LANG['card'], 'img'=>'icon_send_bonus.gif');
    $handler_list['virtual_card'][] = array('url'=>'virtual_card.php?act=replenish', 'title'=>$_LANG['replenish'], 'img'=>'icon_add.gif');
    $handler_list['virtual_card'][] = array('url'=>'virtual_card.php?act=batch_card_add', 'title'=>$_LANG['batch_card_add'], 'img'=>'icon_output.gif');

    if ($_REQUEST['act'] == 'list' && isset($handler_list[$code]))
    {
        $smarty->assign('add_handler',      $handler_list[$code]);
    }

   
    $goods_ur = array('' => $_LANG['01_goods_list'], 'virtual_card'=>$_LANG['50_virtual_card_list']);
    $ur_here = '添加礼品卡关联商品';
    $smarty->assign('ur_here', $ur_here);

    $action_link2  = array('href' => "ks_card_goods.php?act=goods&tid=$type_id", 'text' => '添加关联商品');
    $action_link = array('href' => "ks_card_goods.php?act=vgoods&tid=$type_id", 'text' => '已加关联商品');
   
    $smarty->assign('action_link',  $action_link);
    $smarty->assign('action_link2',  $action_link2);
    $smarty->assign('code',     $code);
    $smarty->assign('cat_list',     cat_list(0, $cat_id));
    $smarty->assign('brand_list',   get_brand_list());
    $smarty->assign('intro_list',   get_intro_list());
    $smarty->assign('lang',         $_LANG);
    $smarty->assign('list_type',    $_REQUEST['act'] == 'list' ? 'goods' : 'trash');
    $smarty->assign('use_storage',  empty($_CFG['use_storage']) ? 0 : 1);

    $goods_list = goods_list($_REQUEST['act'] == 'goods' ? 0 : 1, ($_REQUEST['act'] == 'goods') ? (($code == '') ? 1 : 0) : -1);
    $smarty->assign('goods_list',   $goods_list['goods']);
    $smarty->assign('filter',       $goods_list['filter']);
    $smarty->assign('record_count', $goods_list['record_count']);
    $smarty->assign('page_count',   $goods_list['page_count']);
    $smarty->assign('full_page',    1);

   
    $sort_flag  = sort_flag($goods_list['filter']);
    $smarty->assign($sort_flag['tag'], $sort_flag['img']);
   
    $smarty->assign('type_id',     $type_id);

   
    assign_query_info();
    $smarty->display('ks_card_goods_list.htm');
   
 
}


//-- 关联商品的处理

if ($_REQUEST['act'] == 'addgood')
{
   
   
    $good_id   = !empty($_REQUEST['id']) ? intval($_REQUEST['id']) : 0;
    $type_id   = !empty($_REQUEST['tid']) ? intval($_REQUEST['tid']) : 0;


   


   
    $sql = "INSERT INTO ".$ecs->table('ks_cardgoods')." (cg_catid, cg_goodid)
    VALUES ('$type_id',
            '$good_id')";

    $db->query($sql);
   
   
//    admin_log($_POST['type_name'], 'add', 'bonustype');

   
    clear_cache_files();

   
    $link[0]['text'] = '已经关联商品列表';
    $link[0]['href'] = "ks_card_goods.php?act=vgoods&tid=$type_id";

    $link[1]['text'] = '选择关联商品列表';
    $link[1]['href'] = "ks_card_goods.php?act=goods&tid=$type_id";

    sys_msg($_LANG['add'] . "&nbsp;" .$_POST['type_name'] . "&nbsp;" . $_LANG['attradd_succed'],0, $link);

}


//-- 已关联商品


if ($_REQUEST['act'] == 'vgoods')
{
    check_authz_json('card_and_card');

   
    $type_id     = !empty($_REQUEST['tid'])    ? intval($_REQUEST['tid'])    : 0;
   
    $cat_id = empty($_REQUEST['cat_id']) ? 0 : intval($_REQUEST['cat_id']);
    $code   = empty($_REQUEST['extension_code']) ? '' : trim($_REQUEST['extension_code']);

    $handler_list = array();
    $handler_list['virtual_card'][] = array('url'=>'virtual_card.php?act=card', 'title'=>$_LANG['card'], 'img'=>'icon_send_bonus.gif');
    $handler_list['virtual_card'][] = array('url'=>'virtual_card.php?act=replenish', 'title'=>$_LANG['replenish'], 'img'=>'icon_add.gif');
    $handler_list['virtual_card'][] = array('url'=>'virtual_card.php?act=batch_card_add', 'title'=>$_LANG['batch_card_add'], 'img'=>'icon_output.gif');

    if ($_REQUEST['act'] == 'list' && isset($handler_list[$code]))
    {
        $smarty->assign('add_handler',      $handler_list[$code]);
    }

   
    $goods_ur = array('' => $_LANG['01_goods_list'], 'virtual_card'=>$_LANG['50_virtual_card_list']);
    $ur_here = '已加关联商品';
    $smarty->assign('ur_here', $ur_here);

    $action_link2  = array('href' => "ks_card_goods.php?act=goods&tid=$type_id", 'text' => '添加关联商品');
    $action_link = array('href' => "ks_card_goods.php?act=vgoods&tid=$type_id", 'text' => '已加关联商品');
   
    $smarty->assign('action_link',  $action_link);
    $smarty->assign('action_link2',  $action_link2);
    $smarty->assign('code',     $code);
    $smarty->assign('lang',         $_LANG);
    $smarty->assign('list_type',    $_REQUEST['act'] == 'list' ? 'goods' : 'trash');
    $smarty->assign('use_storage',  empty($_CFG['use_storage']) ? 0 : 1);

    $goods_list = vgoods_list($type_id);
    $smarty->assign('goods_list',   $goods_list);
    $smarty->assign('full_page',    1);

   
    $sort_flag  = sort_flag($goods_list['filter']);
    $smarty->assign($sort_flag['tag'], $sort_flag['img']);
   
    $smarty->assign('type_id',     $type_id);

   
    assign_query_info();
    $smarty->display('ks_card_vgoods_list.htm');
   
}


//-- 删除关联商品

if ($_REQUEST['act'] == 'delgood')
{
    check_authz_json('card_and_card');

    $id          = intval($_GET['id']);
    $type_id     = intval($_GET['tid']);

 //   $exc->drop($id);


   
    $db->query("DELETE FROM " .$ecs->table('ks_cardgoods'). " WHERE cg_id = '$id'");

    $url = "ks_card_goods.php?act=vgoods&tid=$type_id";

    ecs_header("Location: $url\n");
    exit;
}



function get_intro_list()
{
    return array(
        'is_best'    => '精品',
        'is_new'     => '新品',
        'is_hot'     => '热销',
        'is_promote' => '特价',
        'all_type' => '全部推荐',
    );
}


function goods_list($is_delete, $real_goods=1)
{
   
    $param_str = '-' . $is_delete . '-' . $real_goods;
    $result = get_filter($param_str);
    if ($result === false)
    {
        $day = getdate();
        $today = local_mktime(23, 59, 59, $day['mon'], $day['mday'], $day['year']);

        $filter['cat_id']           = empty($_REQUEST['cat_id']) ? 0 : intval($_REQUEST['cat_id']);
        $filter['intro_type']       = empty($_REQUEST['intro_type']) ? '' : trim($_REQUEST['intro_type']);
        $filter['is_promote']       = empty($_REQUEST['is_promote']) ? 0 : intval($_REQUEST['is_promote']);
        $filter['stock_warning']    = empty($_REQUEST['stock_warning']) ? 0 : intval($_REQUEST['stock_warning']);
        $filter['brand_id']         = empty($_REQUEST['brand_id']) ? 0 : intval($_REQUEST['brand_id']);
        $filter['keyword']          = empty($_REQUEST['keyword']) ? '' : trim($_REQUEST['keyword']);
        if ($_REQUEST['is_ajax'] == 1)
        {
            $filter['keyword'] = json_str_iconv($filter['keyword']);
        }
        $filter['sort_by']          = empty($_REQUEST['sort_by']) ? 'goods_id' : trim($_REQUEST['sort_by']);
        $filter['sort_order']       = empty($_REQUEST['sort_order']) ? 'DESC' : trim($_REQUEST['sort_order']);
        $filter['extension_code']   = empty($_REQUEST['extension_code']) ? '' : trim($_REQUEST['extension_code']);
        $filter['is_delete']        = $is_delete;
        $filter['real_goods']       = $real_goods;

        $where = $filter['cat_id'] > 0 ? " AND " . get_children($filter['cat_id']) : '';

       
        switch ($filter['intro_type'])
        {
            case 'is_best':
                $where .= " AND is_best=1";
                break;
            case 'is_hot':
                $where .= ' AND is_hot=1';
                break;
            case 'is_new':
                $where .= ' AND is_new=1';
                break;
            case 'is_promote':
                $where .= " AND is_promote = 1 AND promote_price > 0 AND promote_start_date <= '$today' AND promote_end_date >= '$today'";
                break;
            case 'all_type';
                $where .= " AND (is_best=1 OR is_hot=1 OR is_new=1 OR (is_promote = 1 AND promote_price > 0 AND promote_start_date <= '" . $today . "' AND promote_end_date >= '" . $today . "'))";
        }

       
        if ($filter['stock_warning'])
        {
            $where .= ' AND goods_number <= warn_number ';
        }

       
        if ($filter['brand_id'])
        {
            $where .= " AND brand_id='$filter[brand_id]'";
        }

       
        if ($filter['extension_code'])
        {
            $where .= " AND extension_code='$filter[extension_code]'";
        }

       
        if (!empty($filter['keyword']))
        {
            $where .= " AND (goods_sn LIKE '%" . mysql_like_quote($filter['keyword']) . "%' OR goods_name LIKE '%" . mysql_like_quote($filter['keyword']) . "%')";
        }

        if ($real_goods > -1)
        {
            $where .= " AND is_real='$real_goods'";
        }

       
        $sql = "SELECT COUNT(*) FROM " .$GLOBALS['ecs']->table('goods'). " AS g WHERE is_delete='$is_delete' $where";
        $filter['record_count'] = $GLOBALS['db']->getOne($sql);

       
        $filter = page_and_size($filter);

        $sql = "SELECT goods_id, goods_name, goods_sn, shop_price, is_on_sale, is_best, is_new, is_hot, sort_order, goods_number, integral, " .
                    " (promote_price > 0 AND promote_start_date <= '$today' AND promote_end_date >= '$today') AS is_promote ".
                    " FROM " . $GLOBALS['ecs']->table('goods') . " AS g WHERE is_delete='$is_delete' $where" .
                    " ORDER BY $filter[sort_by] $filter[sort_order] ".
                    " LIMIT " . $filter['start'] . ",$filter[page_size]";

        $filter['keyword'] = stripslashes($filter['keyword']);
        set_filter($filter, $sql, $param_str);
    }
    else
    {
        $sql    = $result['sql'];
        $filter = $result['filter'];
    }
    $row = $GLOBALS['db']->getAll($sql);

    return array('goods' => $row, 'filter' => $filter, 'page_count' => $filter['page_count'], 'record_count' => $filter['record_count']);
}


function vgoods_list($type_id)
{
   
//    $sql = "SELECT * FROM " .$GLOBALS['ecs']->table('ks_cardgoods').
//               " WHERE cg_catid = '$type_id'";
              
      $sql = "SELECT g.goods_id, g.goods_name, g.goods_sn, g.shop_price, g.goods_number, ".
                "c.cg_id, c.cg_catid, c.cg_goodid " .
            'FROM ' . $GLOBALS['ecs']->table('goods') . ' AS g ' .
            'LEFT JOIN ' . $GLOBALS['ecs']->table('ks_cardgoods') . ' AS c ON c.cg_goodid = g.goods_id ' .
            "WHERE c.cg_catid = '$type_id' " .
            'ORDER BY c.cg_id';      
              
              
    $result = $GLOBALS['db']->getAll($sql);
    $goods = array();
   
    foreach ($result AS $idx => $row)
    {
       
        $goods[$idx]['id']           = $row['cg_id'];
        $goods[$idx]['type_id']         = $row['cg_catid'];
        $goods[$idx]['good_id']        = $row['cg_goodid'];
        $goods[$idx]['goods_id']        = $row['goods_id'];
        $goods[$idx]['goods_name']        = $row['goods_name'];
        $goods[$idx]['goods_sn']        = $row['goods_sn'];
        $goods[$idx]['shop_price']        = $row['shop_price'];
        $goods[$idx]['goods_number']        = $row['goods_number'];

    }

return $goods;

}

?>


在admin下
创建kt_card.php

代码如下
<?php


define('IN_ECS', true);

require(dirname(__FILE__) . '/includes/init.php');


if (empty($_REQUEST['act']))
{
    $_REQUEST['act'] = 'cat';
}
else
{
    $_REQUEST['act'] = trim($_REQUEST['act']);
}


$exc = new exchange($ecs->table('kt_bcards'), $db, 'card_id', 'card_sn');


//-- 翻页、排序


if ($_REQUEST['act'] == 'query')
{
    $list = get_order_list();

    $smarty->assign('type_list',    $list['item']);
    $smarty->assign('filter',       $list['filter']);
    $smarty->assign('record_count', $list['record_count']);
    $smarty->assign('page_count',   $list['page_count']);

    $sort_flag  = sort_flag($list['filter']);
    $smarty->assign($sort_flag['tag'], $sort_flag['img']);

    make_json_result($smarty->fetch('ks_order_list.htm'), '',
        array('filter' => $list['filter'], 'page_count' => $list['page_count']));
}


//-- 修改储值卡价格


if ($_REQUEST['act'] == 'edit_fee')
{
    
    $card_id     = !empty($_REQUEST['id'])    ? intval($_REQUEST['id'])    : 0;
   
    $smarty->assign('lang',         $_LANG);
    $smarty->assign('ur_here',     '修改储值卡价格');
    $smarty->assign('action_link', array('text' => '储值卡列表', 'href' => "kt_card.php?act=list"));
    $smarty->assign('action',       'edit_fee');
    $smarty->assign('form_act',     'update_fee');
    $smarty->assign('cfg_lang',     $_CFG['lang']);

    $list = $db->getRow("SELECT * FROM " .$ecs->table('kt_bcards'). " WHERE card_id = '$card_id'");

    $smarty->assign('card',    $list);

    assign_query_info();
    $smarty->display('kt_card_fee.htm');
}



//-- 修改储值卡价格


if ($_REQUEST['act'] == 'update_fee')
{
    
    $card_id     = !empty($_REQUEST['id'])    ? intval($_REQUEST['id'])    : 0;
    $card_type   = !empty($_REQUEST['card_type'])    ? intval($_REQUEST['card_type'])    : 0;
   
    $sql = "UPDATE " .$ecs->table('kt_bcards'). " SET ".
           "card_type        = '$card_type', ".
           "card_bonus        = '$card_type' ".
           "WHERE card_id    = '$card_id'";

   $db->query($sql);
   
   
    $log_info = "初始化储值卡余额" . $card_type . "元,储值卡id为:".$card_id ;

    $sql = 'INSERT INTO ' . $ecs->table('admin_log') . ' (log_time, user_id, log_info, ip_address) ' .
            " VALUES ('" . gmtime() . "', $_SESSION[admin_id], '" . stripslashes($log_info) . "', '" . real_ip() . "')";
    $db->query($sql);
   
    $url = "kt_card.php?act=list";

    ecs_header("Location: $url\n");
    exit;
 
}


//-- 导出线下发放的信息

if ($_REQUEST['act'] == 'excel')
{
    @set_time_limit(0);


   
    $bonus_filename = "储值卡" .'_bonus_list';
    if (EC_CHARSET != 'gbk')
    {
        $bonus_filename = ecs_iconv('UTF8', 'GB2312',$bonus_filename);
    }

    header("Content-type: application/vnd.ms-excel; charset=utf-8");
    header("Content-Disposition: attachment; filename=$bonus_filename.xls");

   
    if (EC_CHARSET != 'gbk')
    {
        echo ecs_iconv('UTF8', 'GB2312', '储值卡序号') ."\t";
        echo ecs_iconv('UTF8', 'GB2312', '储值卡密码') ."\t\n";
    }
    else
    {
        echo "储值卡序号" ."\t";
        echo "储值卡密码" ."\t\n";
    }

    $val = array();
    $sql = "SELECT card_sn, card_pwd ".
           "FROM ".$ecs->table('kt_bcards').
           "ORDER BY card_id";
    $res = $db->query($sql);

    $code_table = array();
    while ($val = $db->fetchRow($res))
    {
        echo $val['card_sn'] . "\t";
        echo $val['card_pwd'] . "\t";
        echo "\t\n";
    }
}


//-- 订单列表

if ($_REQUEST['act'] == 'order')
{
      $id = intval($_GET['id']);
      $keywords      = trim($_POST['keywords']);
    $smarty->assign('ur_here',     '储值卡订单列表');
    $smarty->assign('action_link', array('text' => '礼品卡类型', 'href' => 'kt_card.php?act=order'));
    $smarty->assign('full_page',   1);

    $list = get_order_list($id,$keywords);

    $smarty->assign('type_list',    $list['item']);
    $smarty->assign('filter',       $list['filter']);
    $smarty->assign('record_count', $list['record_count']);
    $smarty->assign('page_count',   $list['page_count']);

    $sort_flag  = sort_flag($list['filter']);
    $smarty->assign($sort_flag['tag'], $sort_flag['img']);

    assign_query_info();
    $smarty->display('kt_order_list.htm');
}


//-- 修改订单状态

if ($_REQUEST['act'] == 'order_status')
{
    check_authz_json('card_and_card');

    $id = intval($_GET['id']);
    $stat = intval($_GET['stat']);
   
    switch ($stat)
    {
        case 0:
        $sqlstat = "order_status        = 1 ";
        break;
       
        case 1:
        $sqlstat = "order_status        = 2 ";
        break;
       
        case 2:
        $sqlstat = "order_status        = 3 ";
        break;
       
        case 3:
        $sqlstat = "order_status        = 0 ";
        break;
       
        default:
        $sqlstat = "order_status        = 0 ";
    }
 
   $sql = "UPDATE " .$ecs->table('kt_order'). " SET ".
           $sqlstat .
           "WHERE order_id    = '$id'";

   $db->query($sql);

    $url = "kt_card.php?act=order";

    ecs_header("Location: $url\n");
    exit;

}


//-- 礼品卡订单详情


if ($_REQUEST['act'] == 'order_info')
{
   
     
    $order_id     = !empty($_REQUEST['id'])    ? intval($_REQUEST['id'])    : 0;
   
    $smarty->assign('lang',         $_LANG);
    $smarty->assign('ur_here',     '订单详情');
    $smarty->assign('action_link', array('text' => '订单列表', 'href' => "kt_card.php?act=order"));
    $smarty->assign('action',       'order_info');

    $smarty->assign('form_act',     'order_update');
    $smarty->assign('cfg_lang',     $_CFG['lang']);

    $list = $db->getRow("SELECT * FROM " .$ecs->table('kt_order'). " WHERE order_id = '$order_id'");

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

    assign_query_info();
    $smarty->display('kt_order_info.htm');

}


//-- 订单编辑页面


if ($_REQUEST['act'] == 'order_update')
{

   
    $id        = !empty($_POST['id'])    ? intval($_POST['id'])    : 0;
    $order_fee       = !empty($_POST['order_fee'])    ? floatval($_POST['order_fee'])    : 0.00;
    $order_exc      = !empty($_POST['order_exc'])    ? floatval($_POST['order_exc'])    : 0.00;
    $order_clr   = !empty($_POST['order_clr'])    ? intval($_POST['order_clr'])    : 0;
    $order_user      = !empty($_POST['order_user'])  ? trim($_POST['order_user'])    : '';
    $order_address   = !empty($_POST['order_address'])  ? trim($_POST['order_address'])    : '';
    $order_tel      = !empty($_POST['order_tel'])  ? trim($_POST['order_tel'])    : '';
    $order_phone      = !empty($_POST['order_phone'])  ? trim($_POST['order_phone'])    : '';
    $order_bak      = !empty($_POST['order_bak'])  ? trim($_POST['order_bak'])    : '';
    $shipping_time      = !empty($_POST['shipping_time'])  ? trim($_POST['shipping_time'])    : '';


    $sql = "UPDATE " .$ecs->table('kt_order'). " SET ".
           "order_fee        = '$order_fee', ".
           "order_exc        = '$order_exc', ".
           "order_clr        = '$order_clr', ".
           "order_user        = '$order_user', ".
           "order_address        = '$order_address', ".
           "order_tel        = '$order_tel', ".
           "order_phone         = '$order_phone', ".
           "order_bak         = '$order_bak', ".
           "shipping_time         = '$shipping_time' ".
           "WHERE order_id    = '$id'";

   $db->query($sql);

  
  
   clear_cache_files();

  
   $link[] = array('text' => '返回此订单' , 'href' => "kt_card.php?act=order_info&id=$id");
   sys_msg($_LANG['edit'] .' '.$_POST['type_name'].' '. $_LANG['attradd_succed'], 0, $link);
  
  }
 

//-- 储值卡商品配送信息

if ($_REQUEST['act'] == 'goods')
{
      $id = $_GET['gid'];
     
    $smarty->assign('ur_here',     '储值卡配送商品');
    $smarty->assign('action_link', array('text' => '储值卡订单列表', 'href' => 'kt_card.php?act=order'));
    $smarty->assign('full_page',   1);

    $list = get_order_goods_list($id);

    $smarty->assign('type_list',    $list);

    assign_query_info();
    $smarty->display('kt_order_goods.htm');
}


//-- 储值实卡列表


if ($_REQUEST['act'] == 'list')
{
      $id   = intval($_GET['id']);
      $pageid = !empty($_REQUEST['page'])    ? intval($_REQUEST['page'])    : 1;
      $pagesize = 50;
   
    $smarty->assign('ur_here',     '储值卡实卡');
    $smarty->assign('action_link', array('text' => '生成储值卡', 'href' => "kt_card.php?act=edit_card"));
    $smarty->assign('full_page',   1);

    $list = get_card_list($id,$pagesize,$pageid);
    $pages = get_card_page($pagesize);

    $smarty->assign('type_list',    $list);
    $smarty->assign('pages',    $pages);

    assign_query_info();
    $smarty->display('kt_card_list.htm');
}


function get_card_page($pagesize)
{

    $sql = "SELECT COUNT(*) FROM " .$GLOBALS['ecs']->table('kt_bcards');             
    $total = $GLOBALS['db']->getOne($sql);
   
    $total = intval($total);
    $pagesize = intval($pagesize);
   
    $pages = ceil($total/$pagesize); //计算总分页
   
    for ($i = 1; $i <= $pages; $i++)
    {
      $pagestr.="<a href="kt_card.php?act=list&page=".$i."">第".$i."页</a>&nbsp;&nbsp;";
    }

return $pagestr;

}


function get_card_list($id,$pagesize,$pageid)
{
    $startrow = ($pageid-1)*$pagesize;
 
    if(empty($id))
    {
    $sql = "SELECT * FROM " .$GLOBALS['ecs']->table('kt_bcards') . " ORDER BY card_id desc LIMIT $startrow,$pagesize";
   }
   else
   {
       $sql = "SELECT * FROM " .$GLOBALS['ecs']->table('kt_bcards') . "WHERE card_id = '$id' ORDER BY card_id desc" ;
  }
                           
    $result = $GLOBALS['db']->getAll($sql);
    $cards = array();
   
    foreach ($result AS $idx => $row)
    {
       
          $cards[$idx]['card_id']           = $row['card_id'];
        $cards[$idx]['card_sn']         = $row['card_sn'];
        $cards[$idx]['card_pwd']         = $row['card_pwd'];
        $cards[$idx]['add_time']        = local_date($GLOBALS['_CFG']['time_format'],$row['add_time']);
        $cards[$idx]['used_time']        = local_date($GLOBALS['_CFG']['time_format'],$row['used_time']);
        $cards[$idx]['card_type']        = $row['card_type'];
        $cards[$idx]['card_bonus']        = $row['card_bonus'];
       
        if($row['used_time'] == 0)
        {
        $cards[$idx]['used_time']        = $row['used_time'];
        }
        else
        {
        $cards[$idx]['used_time']        = local_date($GLOBALS['_CFG']['time_format'],$row['used_time']);
        }
       
        $cards[$idx]['order_id']        = $row['order_id'];

    }

return $cards;

}


if ($_REQUEST['act'] == 'edit_card')
{
   
   
    $smarty->assign('lang',         $_LANG);
    $smarty->assign('ur_here',     '储值卡列表');
    $smarty->assign('action_link', array('text' => '储值卡列表', 'href' => "kt_card.php?act=list"));
    $smarty->assign('action',       'edit_card');

    $smarty->assign('form_act',     'card_update');
    $smarty->assign('cfg_lang',     $_CFG['lang']);

    assign_query_info();
    $smarty->display('kt_edit_card.htm');

}


//-- 生成储值实卡


if ($_REQUEST['act'] == 'card_update')
{
   
     
      $sn_head      = !empty($_POST['sn_head'])  ? trim($_POST['sn_head'])    : '';
    $bnum     = !empty($_REQUEST['bnum'])    ? intval($_REQUEST['bnum'])    : 0;
    $cnum     = !empty($_REQUEST['cnum'])    ? intval($_REQUEST['cnum'])    : 0;
    $card_type     = !empty($_REQUEST['card_type'])    ? intval($_REQUEST['card_type'])    : 0;
   
    if($cnum != 0)
    {
    create_card($sn_head,$bnum,$cnum,$card_type);
    }
 
    $url = "kt_card.php?act=list";

    ecs_header("Location: $url\n");
    exit;
}


//-- 删除礼品卡实卡

if ($_REQUEST['act'] == 'delsn')
{
    check_authz_json('card_and_card');

    $id = intval($_GET['id']);

//   $exc->drop($id);


   
    $db->query("DELETE FROM " .$ecs->table('kt_bcards'). " WHERE card_id = '$id'");

    $url = "kt_card.php?act=list";

    ecs_header("Location: $url\n");
    exit;

}



function create_card($sn_head,$bnum,$cnum,$card_type)

{
    if($cnum != 0)
  {
    $add_time = gmtime();
    $used_time = 0;
    $cnum = $cnum + $bnum;
 
    for ($i = $bnum; $i < $cnum; $i++)
    {
        $card_sn = $sn_head . str_pad($i, 6, '0', STR_PAD_LEFT);
        $card_pwd = rancard(10,'0123456789');
       
        $sql = "SELECT * FROM " .$GLOBALS['ecs']->table('kt_bcards').
                      " WHERE card_sn = '$card_sn'" .
                      " OR card_pwd = '$card_pwd'";

        $record_arr = $GLOBALS['db']->getRow($sql);

             if (empty($record_arr))

             {
                $GLOBALS['db']->query("INSERT INTO ".$GLOBALS['ecs']->table('kt_bcards')." (card_sn, card_pwd, add_time, used_time, card_type, card_bonus) VALUES('$card_sn','$card_pwd','$add_time','$used_time','$card_type','$card_type')");
             }
             else
             {
                 break;
             }

    }
  }

}




function rancard($length,$string = '0123456789abcdefghijklmnopqrstuvwxyz') {
$rstr = '';
$strlen = strlen($string);
for ($i=0; $i<$length; $i++) {
   $rstr .= $string{mt_rand(0,$strlen-1)};
}
return $rstr;
}


function get_order_goods_list($id)
{

  
        $sql = "SELECT * FROM " .$GLOBALS['ecs']->table('goods') . " WHERE goods_id in ($id)" ;
                           
    $result = $GLOBALS['db']->getAll($sql);
    $goods = array();
   
    foreach ($result AS $idx => $row)
    {
       
          $goods[$idx]['goods_id']           = $row['goods_id'];
        $goods[$idx]['goods_sn']           = $row['goods_sn'];
        $goods[$idx]['goods_name']         = $row['goods_name'];

    }

return $goods;
}



function get_goods_name($id)

{
    $sql = "SELECT goods_name FROM " .$GLOBALS['ecs']->table('goods').
               " WHERE goods_id = '$id'";
  $result = $GLOBALS['db']->getOne($sql);
 
  return $result;
              
}


function get_order_list($id,$keywords)
{
  
    $result = get_filter();
    if ($result === false)
    {
       
        $filter['sort_by']    = empty($_REQUEST['sort_by']) ? 'order_id' : trim($_REQUEST['sort_by']);
        $filter['sort_order'] = empty($_REQUEST['sort_order']) ? 'DESC' : trim($_REQUEST['sort_order']);

        $sql = "SELECT COUNT(*) FROM ".$GLOBALS['ecs']->table('kt_order');
        $filter['record_count'] = $GLOBALS['db']->getOne($sql);

       
        $filter = page_and_size($filter);
        if(empty($id))
        {
        $sql = "SELECT * FROM " .$GLOBALS['ecs']->table('kt_order'). " ORDER BY $filter[sort_by] $filter[sort_order]";
        }
        else
        {
        $sql = "SELECT * FROM " .$GLOBALS['ecs']->table('kt_order'). " WHERE card_id = '$id'" . " ORDER BY $filter[sort_by] $filter[sort_order]";
        }
         if(empty($keywords))
        {
        $sql = "SELECT * FROM " .$GLOBALS['ecs']->table('kt_order'). " ORDER BY $filter[sort_by] $filter[sort_order]";
        }
        else
        {
        $card_id = get_card_id($keywords);
        $sql = "SELECT * FROM " .$GLOBALS['ecs']->table('kt_order'). " WHERE card_id = '$card_id' ";
        } 
        set_filter($filter, $sql);
    }
    else
    {
        $sql    = $result['sql'];
        $filter = $result['filter'];
    }
    $arr = array();
    $res = $GLOBALS['db']->selectLimit($sql, $filter['page_size'], $filter['start']);

    while ($row = $GLOBALS['db']->fetchRow($res))
    {
        $row['order_time'] = local_date($GLOBALS['_CFG']['time_format'],$row['order_time']);
        $arr[] = $row;
    }

    $arr = array('item' => $arr, 'filter' => $filter, 'page_count' => $filter['page_count'], 'record_count' => $filter['record_count']);

    return $arr;
}



function get_card_id($keywords)

{
    $sql = "SELECT card_id FROM " .$GLOBALS['ecs']->table('kt_bcards').
               " WHERE card_sn = '$keywords'";
  $result = $GLOBALS['db']->getOne($sql);
 
  return $result;
              
}



function get_type_name($card_type)

{
    $sql = "SELECT cat_name FROM " .$GLOBALS['ecs']->table('ks_cardcats').
               " WHERE cat_id = '$card_type'";
  $result = $GLOBALS['db']->getOne($sql);
 
  return $result;
              
}

?>


这段是最有意思的部分,写后台模板

admin/templates
创建文件
ks_card_goods_list.htm

<!-- $Id: goods_list.htm 15908 2009-05-05 09:22:04Z liuhui $ -->

{if $full_page}
{include file="pageheader.htm"}
{insert_scripts files="../js/utils.js,listtable.js"}

<!-- 商品搜索 -->
<div class="form-div">
  <form action="javascript:searchGoods()" name="searchForm">
    <img src="images/icon_search.gif" width="26" height="22" border="0" alt="SEARCH" />
    {if $smarty.get.act neq "trash"}
    <!-- 分类 -->
    <select name="cat_id"><option value="0">所有分类</option>{$cat_list}</select>
    <!-- 品牌 -->
    <select name="brand_id"><option value="0">所有品牌</option>{html_options options=$brand_list}</select>
    <!-- 推荐 -->
    <select name="intro_type"><option value="0">全部</option>{html_options options=$intro_list selected=$smarty.get.intro_type}</select>
    {/if}
    <!-- 关键字 -->
    关键字 <input type="text" name="keyword" size="15" />
    <input type="hidden" name="tid" value="{$type_id}" />
    <input type="submit" value="搜索" class="button" />
  </form>
</div>

{literal}
<script language="JavaScript">
    function searchGoods()
    {
{/literal}
        {if $smarty.get.act neq "trash"}
        listTable.filter['cat_id'] = document.forms['searchForm'].elements['cat_id'].value;
        listTable.filter['brand_id'] = document.forms['searchForm'].elements['brand_id'].value;
        listTable.filter['intro_type'] = document.forms['searchForm'].elements['intro_type'].value;
        {/if}
{literal}
        listTable.filter['keyword'] = Utils.trim(document.forms['searchForm'].elements['keyword'].value);
        listTable.filter['page'] = 1;
        listTable.filter['tid'] = document.forms['searchForm'].elements['tid'].value;
        listTable.loadList();
    }
</script>
{/literal}
<!-- 商品列表 -->
<form method="post" action="" name="listForm" onsubmit="return confirmSubmit(this)">
  <!-- start goods list -->
  <div class="list-div" id="listDiv">
{/if}
<table cellpadding="3" cellspacing="1">
  <tr>
    <th>
     编号
    </th>
    <th>商品名称</th>
    <th>货号</th>
    <th>价格</th>
    {if $use_storage}
    <th>库存</th>
    {/if}
    <th>操作</th>
  <tr>
  {foreach from=$goods_list item=goods}
  <tr>
    <td>{$goods.goods_id}</td>
    <td class="first-cell" style="{if $goods.is_promote}color:red;{/if}"><a href="/goods.php?id={$goods.goods_id}" target="_blank">{$goods.goods_name|escape:html}</a></td>
    <td>{$goods.goods_sn}</td>
    <td align="right">{$goods.shop_price}</td>
    {if $use_storage}
    <td align="right">{if $code eq 'virtual_card'}{$goods.goods_number}{else}{$goods.goods_number}{/if}</td>
    {/if}
    <td align="center">
      <a href="ks_card_goods.php?act=addgood&id={$goods.goods_id}&tid={$type_id}">设置关联</a>
    </td>
  </tr>
  {foreachelse}
  <tr><td class="no-records" colspan="10">{$lang.no_records}</td></tr>
  {/foreach}
</table>
<!-- end goods list -->

<!-- 分页 -->
<table id="page-table" cellspacing="0">
  <tr>
    <td align="right" nowrap="true">
    {include file="page.htm"}
    </td>
  </tr>
</table>

{if $full_page}
</div>

</form>

<script type="text/javascript">
  listTable.recordCount = {$record_count};
  listTable.pageCount = {$page_count};

  {foreach from=$filter item=item key=key}
  listTable.filter.{$key} = '{$item}';
  {/foreach}

  {literal}
  onload = function()
  {
    startCheckOrder(); // 开始检查订单
    document.forms['listForm'].reset();
  }

 
  function confirmSubmit(frm, ext)
  {
      if (frm.elements['type'].value == 'trash')
      {
          return confirm(batch_trash_confirm);
      }
      else if (frm.elements['type'].value == 'not_on_sale')
      {
          return confirm(batch_no_on_sale);
      }
      else if (frm.elements['type'].value == 'move_to')
      {
          ext = (ext == undefined) ? true : ext;
          return ext && frm.elements['target_cat'].value != 0;
      }
      else if (frm.elements['type'].value == '')
      {
          return false;
      }
      else
      {
          return true;
      }
  }

  function changeAction()
  {
      var frm = document.forms['listForm'];

      // 切换分类列表的显示
      frm.elements['target_cat'].style.display = frm.elements['type'].value == 'move_to' ? '' : 'none';

      if (!document.getElementByIdx_x_x('btnSubmit').disabled &&
          confirmSubmit(frm, false))
      {
          frm.submit();
      }
  }
{/literal}
</script>
{include file="pagefooter.htm"}
{/if}

创建
ks_card_list.htm

<!-- $Id: bonus_type.htm 14216 2008-03-10 02:27:21Z testyang $ -->

{if $full_page}
{include file="pageheader.htm"}
<h1>页码:  {$pages}</h1>
{insert_scripts files="../js/utils.js,listtable.js"}
<!-- start bonus_type list -->
<form method="post" action="" name="listForm">
<div class="list-div" id="listDiv">
{/if}

  <table cellpadding="3" cellspacing="1">
    <tr>
      <th>编号</th>
      <th>礼品卡类型</th>
      <th>礼品卡序号</th>
      <th>礼品卡密码</th>
      <th>创建时间</th>
      <th>使用时间</th>
      <th>操作</th>
    </tr>
    {foreach from=$type_list item=type}
    <tr>
      <td align="center" class="first-cell"><span>{$type.id}</span></td>
      <td align="center">{$type.type_name}</td>
      <td align="center">{$type.card_sn}</td>
      <td align="center">{$type.card_pwd}</td>
      <td align="center">{$type.add_time}</td>
      <td align="center">{if $type.used_time eq '0'}未使用{else}{$type.used_time}{/if}</td>
      <td align="center">
          {if $type.order_id neq '0'}
        <a href="ks_card.php?act=order&id={$type.order_id}">订单</a> |
        {/if}
        <a href="ks_card.php?act=edit_card_type&cid={$type.id}&tid={$type.type_id}">编辑</a> |
        <a href="ks_card.php?act=delsn&amp;id={$type.id}&tid={$type.type_id}">作废</a></span></td>
    </tr>
      {foreachelse}
    <tr><td class="no-records" colspan="10">{$lang.no_records}</td></tr>
      {/foreach}

  </table>

{if $full_page}
</div>
</form>
<!-- end bonus_type list -->

<script type="text/javascript" language="JavaScript">
<!--
  listTable.recordCount = {$record_count};
  listTable.pageCount = {$page_count};

  {foreach from=$filter item=item key=key}
  listTable.filter.{$key} = '{$item}';
  {/foreach}

  {literal}
  onload = function()
  {
     // 开始检查订单
     startCheckOrder();
  }
  {/literal}
//-->
</script>
{include file="pagefooter.htm"}
{/if}

创建
ks_card_type.htm

<!-- $Id: bonus_type.htm 14216 2008-03-10 02:27:21Z testyang $ -->

{if $full_page}
{include file="pageheader.htm"}
{insert_scripts files="../js/utils.js,listtable.js"}
<!-- start bonus_type list -->
<form method="post" action="" name="listForm">
<div class="list-div" id="listDiv">
{/if}

  <table cellpadding="3" cellspacing="1">
    <tr>
      <th>礼品卡类型</th>
      <th>类型标识</th>
      <th>描述</th>
      <th>可选择数</th>
      <th>发放数量</th>
      <th>使用数量</th>
      <th>操作</th>
    </tr>
    {foreach from=$type_list item=type}
    <tr>
      <td class="first-cell"><span>{$type.cat_name|escape:html}</span></td>
      <td>{$type.cat_mark}</td>
      <td>{$type.cat_desc}</td>
      <td align="right"><span>{$type.cat_sgn}</span></td>
      <td align="right"><span>{$type.all_num}</span></td>
      <td align="right">{$type.ok_num}</td>
      <td align="center">
          <a href="ks_card.php?act=excel&tid={$type.cat_id}">发放</a> |
        <a href="ks_card_goods.php?act=goods&tid={$type.cat_id}">添加</a> |
        <a href="ks_card_goods.php?act=vgoods&tid={$type.cat_id}">商品</a> |
        <a href="ks_card.php?act=list&amp;tid={$type.cat_id}">卡号</a> |
        <a href="ks_card.php?act=edit&amp;tid={$type.cat_id}">编辑</a> |
        <a href="ks_card.php?act=remove&amp;tid={$type.cat_id}">移除</a></span></td>
    </tr>
      {foreachelse}
    <tr><td class="no-records" colspan="10">{$lang.no_records}</td></tr>
      {/foreach}

  </table>

{if $full_page}
</div>
</form>
<!-- end bonus_type list -->

<script type="text/javascript" language="JavaScript">
<!--
  listTable.recordCount = {$record_count};
  listTable.pageCount = {$page_count};

  {foreach from=$filter item=item key=key}
  listTable.filter.{$key} = '{$item}';
  {/foreach}

  {literal}
  onload = function()
  {
     // 开始检查订单
     startCheckOrder();
  }
  {/literal}
//-->
</script>
{include file="pagefooter.htm"}
{/if}

创建
ks_card_type_info.htm

<!-- $Id: bonus_type_info.htm 14216 2008-03-10 02:27:21Z testyang $ -->

<script type="text/javascript" src="../js/calendar.php?lang={$cfg_lang}"></script>
<link href="../js/calendar/calendar.css" rel="stylesheet" type="text/css" />

{include file="pageheader.htm"}
<div class="main-div">
<form action="ks_card.php" method="post" name="theForm" enctype="multipart/form-data" onsubmit="return validate()">
<table width="100%">
  <tr>
    <td class="label">类型名称</td>
    <td>
      <input type='text' name='type_name' maxlength="30" value="{$bonus_arr.cat_name}" size='20' />    </td>
  </tr>
  <tr>
    <td class="label">
      <a href="javascript:showNotice('Type_money_a');" title="{$lang.form_notice}">
      <img src="images/notice.gif" width="16" height="16" border="0" alt="{$lang.form_notice}"></a>类型标识</td>
    <td>
    <input type="text" name="type_mark" value="{$bonus_arr.cat_mark}" size="20" />
    <br /><span class="notice-span" {if $help_open}style="display:block" {else} style="display:none" {/if} id="Type_money_a">类型标识是礼品卡序号前缀.例:某个礼品卡序号为:PPOK332255,那么PPOK可能是类型标识.用来通过标识直观获取礼品卡类型,方便使用与管理.</span>    </td>
  </tr>
  <tr>
    <td class="label"><a href="javascript:showNotice('NoticeMinGoodsAmount');" title="{$lang.form_notice}"> <img src="images/notice.gif" width="16" height="16" border="0" alt="{$lang.form_notice}" /></a>类型描述</td>
    <td><textarea name="type_desc" type="text" rows="3" cols="20">{$bonus_arr.cat_desc}</textarea>
    <br /><span class="notice-span" {if $help_open}style="display:block" {else} style="display:none" {/if} id="NoticeMinGoodsAmount">礼品卡类型注释,便于记忆.</span> </td>
  </tr>
 <tr>
    <td class="label"><a href="javascript:showNotice('SelNum');" title="{$lang.form_notice}"> <img src="images/notice.gif" width="16" height="16" border="0" alt="{$lang.form_notice}" /></a>可选择量</td>
    <td><input name="type_num" type="text" value="{$bonus_arr.cat_sgn}" maxlength="2" size="20" />
    <br /><span class="notice-span" {if $help_open}style="display:block" {else} style="display:none" {/if} id="SelNum">礼品5选几,4选几.</span> </td>
  </tr>
  <tr>
    <td class="label">&nbsp;</td>
    <td>
      <input type="submit" value="{$lang.button_submit}" class="button" />
      <input type="reset" value="{$lang.button_reset}" class="button" />
      <input type="hidden" name="act" value="{$form_act}" />
      <input type="hidden" name="type_id" value="{$bonus_arr.cat_id}" />    </td>
  </tr>
</table>
</form>
</div>
{insert_scripts files="../js/utils.js,validator.js"}
{literal}
<script language="javascript">
<!--
document.forms['theForm'].elements['type_name'].focus();

function validate()
{
  validator = new Validator("theForm");
  validator.required("type_name",      "类型名为空");
  validator.required("type_mark",      "标识为空");
  validator.required("type_num",       "可选量为空");
  validator.isNumber("type_num",       "可选量必须是数字", true);

  return validator.passed();
}
onload = function()
{
  {/literal}
  get_value = '{$bonus_arr.send_type}';
  {literal}

  showunit(get_value)
  // 开始检查订单
  startCheckOrder();
}

function gObj(obj)
{
  var theObj;
  if (document.getElementByIdx_x_x)
  {
    if (typeof obj=="string") {
      return document.getElementByIdx_x_x(obj);
    } else {
      return obj.style;
    }
  }
  return null;
}

function showunit(get_value)
{
  gObj("1").style.display =  (get_value == 2) ? "" : "none";
  document.forms['theForm'].elements['selbtn1'].disabled  = (get_value != 1 && get_value != 2);
  document.forms['theForm'].elements['selbtn2'].disabled  = (get_value != 1 && get_value != 2);

  return;
}
//-->
</script>
{/literal}
{include file="pagefooter.htm"}

创建
ks_card_vgoods_list.htm

<!-- $Id: goods_list.htm 15908 2009-05-05 09:22:04Z liuhui $ -->

{if $full_page}
{include file="pageheader.htm"}
{insert_scripts files="../js/utils.js,listtable.js"}

<form method="post" action="" name="listForm" onsubmit="return confirmSubmit(this)">
  <!-- start goods list -->
  <div class="list-div" id="listDiv">
{/if}
<table cellpadding="3" cellspacing="1">
  <tr>
    <th>
     编号
    </th>
    <th>商品名称</th>
    <th>货号</th>
    <th>价格</th>
    {if $use_storage}
    <th>库存</th>
    {/if}
    <th>操作</th>
  <tr>
  {foreach from=$goods_list item=goods}
  <tr>
    <td>{$goods.goods_id}</td>
    <td class="first-cell" style="{if $goods.is_promote}color:red;{/if}"><a href="/goods.php?id={$goods.goods_id}" target="_blank">{$goods.goods_name|escape:html}</a></td>
    <td>{$goods.goods_sn}</td>
    <td align="right">{$goods.shop_price}</td>
    {if $use_storage}
    <td align="right">{if $code eq 'virtual_card'}{$goods.goods_number}{else}{$goods.goods_number}{/if}</td>
    {/if}
    <td align="center">
      <a href="ks_card_goods.php?act=delgood&id={$goods.id}&tid={$type_id}">删除关联</a>
    </td>
  </tr>
  {foreachelse}
  <tr><td class="no-records" colspan="10">{$lang.no_records}</td></tr>
  {/foreach}
</table>
<!-- end goods list -->

{if $full_page}
</div>

</form>

<script type="text/javascript">
  listTable.recordCount = {$record_count};
  listTable.pageCount = {$page_count};

  {foreach from=$filter item=item key=key}
  listTable.filter.{$key} = '{$item}';
  {/foreach}

  {literal}
  onload = function()
  {
    startCheckOrder(); // 开始检查订单
    document.forms['listForm'].reset();
  }

 
  function confirmSubmit(frm, ext)
  {
      if (frm.elements['type'].value == 'trash')
      {
          return confirm(batch_trash_confirm);
      }
      else if (frm.elements['type'].value == 'not_on_sale')
      {
          return confirm(batch_no_on_sale);
      }
      else if (frm.elements['type'].value == 'move_to')
      {
          ext = (ext == undefined) ? true : ext;
          return ext && frm.elements['target_cat'].value != 0;
      }
      else if (frm.elements['type'].value == '')
      {
          return false;
      }
      else
      {
          return true;
      }
  }

  function changeAction()
  {
      var frm = document.forms['listForm'];

      // 切换分类列表的显示
      frm.elements['target_cat'].style.display = frm.elements['type'].value == 'move_to' ? '' : 'none';

      if (!document.getElementByIdx_x_x('btnSubmit').disabled &&
          confirmSubmit(frm, false))
      {
          frm.submit();
      }
  }
{/literal}
</script>
{include file="pagefooter.htm"}
{/if}

创建

ks_edit_card.htm

<!-- $Id: bonus_type_info.htm 14216 2008-03-10 02:27:21Z testyang $ -->

<script type="text/javascript" src="../js/calendar.php?lang={$cfg_lang}"></script>
<link href="../js/calendar/calendar.css" rel="stylesheet" type="text/css" />

{include file="pageheader.htm"}
<div class="main-div">
<form action="ks_card.php" method="post" name="theForm" enctype="multipart/form-data" onsubmit="return validate()">
<table width="100%">
  <tr>
    <td class="label">初始序号</td>
    <td>
      <input type='text' name='bnum' maxlength="30" value="0" size='20' />    </td>
  </tr>
  <tr>
    <td class="label">生成数量</td>
    <td>
      <input type='text' name='cnum' maxlength="30" value="10" size='20' />    </td>
  </tr>
  <tr>
    <td class="label">&nbsp;</td>
    <td>
      <input type="submit" value="生成" class="button" />
      <input type="hidden" name="act" value="{$form_act}" />
      <input type="hidden" name="tid" value="{$type_id}" />
    </td>
  </tr>
</table>
</form>
</div>
{insert_scripts files="../js/utils.js,validator.js"}
{literal}
<script language="javascript">
<!--
document.forms['theForm'].elements['type_name'].focus();

function validate()
{
  validator = new Validator("theForm");
  validator.required("bnum",         "序号为空");
  validator.required("cnum",      "数量为空");

  return validator.passed();
}
onload = function()
{
  {/literal}
  get_value = '{$bonus_arr.send_type}';
  {literal}

  showunit(get_value)
  // 开始检查订单
  startCheckOrder();
}

function gObj(obj)
{
  var theObj;
  if (document.getElementByIdx_x_x)
  {
    if (typeof obj=="string") {
      return document.getElementByIdx_x_x(obj);
    } else {
      return obj.style;
    }
  }
  return null;
}

function showunit(get_value)
{
  gObj("1").style.display =  (get_value == 2) ? "" : "none";
  document.forms['theForm'].elements['selbtn1'].disabled  = (get_value != 1 && get_value != 2);
  document.forms['theForm'].elements['selbtn2'].disabled  = (get_value != 1 && get_value != 2);

  return;
}
//-->
</script>
{/literal}
{include file="pagefooter.htm"}


创建

ks_edit_card_type.htm

<!-- $Id: bonus_type_info.htm 14216 2008-03-10 02:27:21Z testyang $ -->

<script type="text/javascript" src="../js/calendar.php?lang={$cfg_lang}"></script>
<link href="../js/calendar/calendar.css" rel="stylesheet" type="text/css" />

{include file="pageheader.htm"}
<div class="main-div">
<form action="ks_card.php" method="post" name="theForm" enctype="multipart/form-data" onsubmit="return validate()">
<table width="100%">
  <tr>
    <td class="label">礼品卡类别</td>
    <td>
      <select name='card_type'>
          <option value='{$card_type}' selected>{$card_name}</option>
          {foreach from=$type_list item=type}
<option value='{$type.cat_id}'>{$type.cat_name}</option>
 {/foreach}
</select>
      </td>
  </tr>
  <tr>
    <td class="label">&nbsp;</td>
    <td>
      <input type="submit" value="修改" class="button" />
      <input type="hidden" name="act" value="{$form_act}" />
      <input type="hidden" name="cid" value="{$card_id}" />
    </td>
  </tr>
</table>
</form>
</div>
{insert_scripts files="../js/utils.js,validator.js"}
{literal}
<script language="javascript">
<!--
document.forms['theForm'].elements['type_name'].focus();

function validate()
{
  validator = new Validator("theForm");
  validator.required("card_type",         "礼品卡分类为空");

  return validator.passed();
}
onload = function()
{
  {/literal}
  get_value = '{$bonus_arr.send_type}';
  {literal}

  showunit(get_value)
  // 开始检查订单
  startCheckOrder();
}

function gObj(obj)
{
  var theObj;
  if (document.getElementByIdx_x_x)
  {
    if (typeof obj=="string") {
      return document.getElementByIdx_x_x(obj);
    } else {
      return obj.style;
    }
  }
  return null;
}

function showunit(get_value)
{
  gObj("1").style.display =  (get_value == 2) ? "" : "none";
  document.forms['theForm'].elements['selbtn1'].disabled  = (get_value != 1 && get_value != 2);
  document.forms['theForm'].elements['selbtn2'].disabled  = (get_value != 1 && get_value != 2);

  return;
}
//-->
</script>
{/literal}
{include file="pagefooter.htm"}

创建
ks_order_goods.htm

<!-- $Id: bonus_type.htm 14216 2008-03-10 02:27:21Z testyang $ -->

{if $full_page}
{include file="pageheader.htm"}
{insert_scripts files="../js/utils.js,listtable.js"}
<!-- start bonus_type list -->
<form method="post" action="" name="listForm">
<div class="list-div" id="listDiv">
{/if}

  <table cellpadding="3" cellspacing="1">
    <tr>
      <th>编号</th>
      <th>货号</th>
      <th>名字</th>
    </tr>
    {foreach from=$type_list item=type}
    <tr>
      <td align="center" class="first-cell"><span>{$type.goods_id}</span></td>
      <td align="center">{$type.goods_sn}</td>
      <td align="center"><a href="/goods.php?id={$type.goods_id}" target="_blank">{$type.goods_name}</a></td>
    </tr>
      {foreachelse}
    <tr><td class="no-records" colspan="10">{$lang.no_records}</td></tr>
      {/foreach}

  </table>

{if $full_page}
</div>
</form>
<!-- end bonus_type list -->

<script type="text/javascript" language="JavaScript">
<!--
  listTable.recordCount = {$record_count};
  listTable.pageCount = {$page_count};

  {foreach from=$filter item=item key=key}
  listTable.filter.{$key} = '{$item}';
  {/foreach}

  {literal}
  onload = function()
  {
     // 开始检查订单
     startCheckOrder();
  }
  {/literal}
//-->
</script>
{include file="pagefooter.htm"}
{/if}

创建

ks_order_info.htm

<!-- $Id: bonus_type_info.htm 14216 2008-03-10 02:27:21Z testyang $ -->

<script type="text/javascript" src="../js/calendar.php?lang={$cfg_lang}"></script>
<link href="../js/calendar/calendar.css" rel="stylesheet" type="text/css" />

{include file="pageheader.htm"}
<div class="main-div">
<form action="ks_card.php" method="post" name="theForm" enctype="multipart/form-data" onsubmit="return validate()">
<table width="100%">
    <tr>
    <td class="label">编号</td>
    <td>
      <input disabled="true" readOnly="true" type='text' name='order_id' maxlength="30" value="{$order.order_id}" size='20' />    </td>
  </tr>
  <tr>
    <td class="label">订单号</td>
    <td>
      <input disabled="true" readOnly="true" type='text' name='order_sn' maxlength="30" value="{$order.order_sn}" size='20' />    </td>
  </tr>
   <tr>
    <td class="label">礼品卡分类</td>
    <td>
      <input disabled="true" readOnly="true" type='text' name='order_goodcatid' maxlength="30" value="{$order.order_goodcatid}" size='20' />    </td>
  </tr>
  <tr>
    <td class="label">联系人</td>
    <td>
      <input type='text' name='order_user' maxlength="30" value="{$order.order_user}" size='20' />    </td>
  </tr>
  <tr>
    <td class="label">联系地址</td>
    <td>
      <input type='text' name='order_address' maxlength="30" value="{$order.order_address}" size='20' />    </td>
  </tr>
  <tr>
    <td class="label">联系电话</td>
    <td>
      <input type='text' name='order_tel' maxlength="30" value="{$order.order_tel}" size='20' />    </td>
  </tr>
  <tr>
    <td class="label">移动电话</td>
    <td>
      <input type='text' name='order_phone' maxlength="30" value="{$order.order_phone}" size='20' />    </td>
  </tr>
  <tr>
    <td class="label">特殊要求备注</td>
    <td>
      <input type='text' name='order_bak' maxlength="30" value="{$order.order_bak}" size='20' />    </td>
  </tr>
  <tr>
    <td class="label">配送时间</td>
    <td>
      <input type='text' name='shipping_time' maxlength="30" value="{$order.shipping_time}" size='20' />    </td>
  </tr>
  <tr>
    <td class="label">订单创建时间</td>
    <td>
      <input disabled="true" readOnly="true" type='text' name='order_time' maxlength="30" value="{$order.order_time}" size='20' />    </td>
  </tr>
  <tr>
    <td class="label">订单状态</td>
    <td>
      <input disabled="true" readOnly="true" type='text' name='order_status' maxlength="30" value="{$order.order_status}" size='20' />    </td>
  </tr>
  <tr>
    <td class="label">&nbsp;</td>
    <td>
      <input type="submit" value="修改" class="button" />
      <input type="hidden" name="act" value="{$form_act}" />
      <input type="hidden" name="id" value="{$order.order_id}" />
    </td>
  </tr>
</table>
</form>
</div>
{insert_scripts files="../js/utils.js,validator.js"}
{literal}
<script language="javascript">
<!--
document.forms['theForm'].elements['type_name'].focus();

function validate()
{
  validator = new Validator("theForm");
  validator.required("order_user",         "联系人为空");
  validator.required("order_address",      "联系地址为空");
  validator.required("order_tel",          "联系电话为空");

  return validator.passed();
}
onload = function()
{
  {/literal}
  get_value = '{$bonus_arr.send_type}';
  {literal}

  showunit(get_value)
  // 开始检查订单
  startCheckOrder();
}

function gObj(obj)
{
  var theObj;
  if (document.getElementByIdx_x_x)
  {
    if (typeof obj=="string") {
      return document.getElementByIdx_x_x(obj);
    } else {
      return obj.style;
    }
  }
  return null;
}

function showunit(get_value)
{
  gObj("1").style.display =  (get_value == 2) ? "" : "none";
  document.forms['theForm'].elements['selbtn1'].disabled  = (get_value != 1 && get_value != 2);
  document.forms['theForm'].elements['selbtn2'].disabled  = (get_value != 1 && get_value != 2);

  return;
}
//-->
</script>
{/literal}
{include file="pagefooter.htm"}

创建
ks_order_list.htm

<!-- $Id: bonus_type.htm 14216 2008-03-10 02:27:21Z testyang $ -->

{if $full_page}
{include file="pageheader.htm"}
<form action="ks_card.php" method="post" name="theForm" enctype="multipart/form-data">
<h1>礼品卡序号:<input type='text' name='keywords' maxlength="30" value="" size='20' /><input type="submit" value="查询" class="button" /></h1>
<input type="hidden" name="act" value="order" />
</form>
{insert_scripts files="../js/utils.js,listtable.js"}
<!-- start bonus_type list -->
<form method="post" action="" name="listForm">
<div class="list-div" id="listDiv">
{/if}
 
  <table cellpadding="3" cellspacing="1">
    <tr>
      <th>编号</th>
      <th>订单号</th>
      <th>礼品卡分类</th>
      <th>联系人</th>
      <th>特殊要求备注</th>
      <th>创建时间</th>
      <th>订单状态</th>
      <th>操作</th>
    </tr>
    {foreach from=$type_list item=type}
    <tr>
      <td align="center" class="first-cell"><span>{$type.order_id}</span></td>
      <td align="center">{$type.order_sn}</td>
      <td align="center">{$type.order_goodcatname}</td>
      <td align="center">联系人:{$type.order_user}&nbsp电话:{$type.order_tel}&nbsp{$type.order_phone}<br />地址:{$type.order_address}&nbsp配送时间:{$type.shipping_time}</td>
      <td align="center">{$type.order_bak}</td>
      <td align="center">{$type.order_time}</td>
      <td align="center">
        <a href="ks_card.php?act=order_status&id={$type.order_id}&stat={$type.order_status}">{if $type.order_status eq 0}正常{elseif $type.order_status eq 1}确认{elseif $type.order_status eq 2}配送{elseif $type.order_status eq 3}完成{/if}</a></td>
      <td align="center">
        <a href="ks_card.php?act=order_info&id={$type.order_id}">订单详情</a> |
        <a href="ks_card.php?act=goods&gid={$type.order_goods}">配送商品</a> |
        <a href="ks_card.php?act=list&id={$type.card_id}">礼品卡</a></td>
    </tr>
      {foreachelse}
    <tr><td class="no-records" colspan="10">{$lang.no_records}</td></tr>
      {/foreach}
     <tr>
      <td align="right" nowrap="true" colspan="8">{include file="page.htm"}</td>
    </tr>
  </table>

{if $full_page}
</div>
</form>
<!-- end bonus_type list -->

<script type="text/javascript" language="JavaScript">
<!--
  listTable.recordCount = {$record_count};
  listTable.pageCount = {$page_count};

  {foreach from=$filter item=item key=key}
  listTable.filter.{$key} = '{$item}';
  {/foreach}

  {literal}
  onload = function()
  {
     // 开始检查订单
     startCheckOrder();
  }
  {/literal}
//-->
</script>
{include file="pagefooter.htm"}
{/if}


后台最后一部分模板

admin/

创建

kt_card_fee.htm

<!-- $Id: bonus_type_info.htm 14216 2008-03-10 02:27:21Z testyang $ -->

<script type="text/javascript" src="../js/calendar.php?lang={$cfg_lang}"></script>
<link href="../js/calendar/calendar.css" rel="stylesheet" type="text/css" />

{include file="pageheader.htm"}
<div class="main-div">
<form action="kt_card.php" method="post" name="theForm" enctype="multipart/form-data" onsubmit="return validate()">
<table width="100%">
    <tr>
    <td class="label">初始化储值卡金额</td>
    <td>
      <input type='text' name='card_type' maxlength="30" value="{$card.card_type}" size='20' />    </td>
  </tr>
  <tr>
    <td class="label">&nbsp;</td>
    <td>
      <input type="submit" value="修改" class="button" />
      <input type="hidden" name="act" value="{$form_act}" />
      <input type="hidden" name="id" value="{$card.card_id}" />
    </td>
  </tr>
</table>
</form>
</div>
{insert_scripts files="../js/utils.js,validator.js"}
{literal}
<script language="javascript">
<!--
document.forms['theForm'].elements['type_name'].focus();

function validate()
{
  validator = new Validator("theForm");
  validator.required("card_type",         "金额为空");

  return validator.passed();
}
onload = function()
{
  {/literal}
  get_value = '{$bonus_arr.send_type}';
  {literal}

  showunit(get_value)
  // 开始检查订单
  startCheckOrder();
}

function gObj(obj)
{
  var theObj;
  if (document.getElementByIdx_x_x)
  {
    if (typeof obj=="string") {
      return document.getElementByIdx_x_x(obj);
    } else {
      return obj.style;
    }
  }
  return null;
}

function showunit(get_value)
{
  gObj("1").style.display =  (get_value == 2) ? "" : "none";
  document.forms['theForm'].elements['selbtn1'].disabled  = (get_value != 1 && get_value != 2);
  document.forms['theForm'].elements['selbtn2'].disabled  = (get_value != 1 && get_value != 2);

  return;
}
//-->
</script>
{/literal}
{include file="pagefooter.htm"}

创建

kt_card_list.htm


<!-- $Id: bonus_type.htm 14216 2008-03-10 02:27:21Z testyang $ -->

{if $full_page}
{include file="pageheader.htm"}
<h1>页码:  {$pages}</h1>
{insert_scripts files="../js/utils.js,listtable.js"}
<!-- start bonus_type list -->
<form method="post" action="" name="listForm">
<div class="list-div" id="listDiv">
{/if}

  <table cellpadding="3" cellspacing="1">
    <tr>
      <th>编号</th>
      <th>储值卡序号</th>
      <th>储值卡密码</th>
      <th>创建时间</th>
      <th>使用时间</th>
      <th>初始金额</th>
      <th>可用余额</th>
      <th>操作</th>
    </tr>
    {foreach from=$type_list item=type}
    <tr>
      <td align="center" class="first-cell"><span>{$type.card_id}</span></td>
      <td align="center">{$type.card_sn}</td>
      <td align="center">{$type.card_pwd}</td>
      <td align="center">{$type.add_time}</td>
      <td align="center">{if $type.used_time eq '0'}未使用{else}{$type.used_time}{/if}</td>
      <td align="center">{$type.card_type}</td>
      <td align="center">{$type.card_bonus}</td>
      <td align="center">
          <a href="kt_card.php?act=excel">发放</a> |
          <a href="kt_card.php?act=edit_fee&id={$type.card_id}">编辑</a> |
        <a href="kt_card.php?act=delsn&amp;id={$type.card_id}">作废</a></span></td>
    </tr>
      {foreachelse}
    <tr><td class="no-records" colspan="10">{$lang.no_records}</td></tr>
      {/foreach}

  </table>

{if $full_page}
</div>
</form>
<!-- end bonus_type list -->

<script type="text/javascript" language="JavaScript">
<!--
  listTable.recordCount = {$record_count};
  listTable.pageCount = {$page_count};

  {foreach from=$filter item=item key=key}
  listTable.filter.{$key} = '{$item}';
  {/foreach}

  {literal}
  onload = function()
  {
     // 开始检查订单
     startCheckOrder();
  }
  {/literal}
//-->
</script>
{include file="pagefooter.htm"}
{/if}

创建

kt_edit_card.htm

<!-- $Id: bonus_type_info.htm 14216 2008-03-10 02:27:21Z testyang $ -->

<script type="text/javascript" src="../js/calendar.php?lang={$cfg_lang}"></script>
<link href="../js/calendar/calendar.css" rel="stylesheet" type="text/css" />

{include file="pageheader.htm"}
<div class="main-div">
<form action="kt_card.php" method="post" name="theForm" enctype="multipart/form-data" onsubmit="return validate()">
<table width="100%">
      <tr>
    <td class="label">前缀标识</td>
    <td>
      <input type='text' name='sn_head' maxlength="30" value="CZK" size='20' />    </td>
  </tr>
  <tr>
    <td class="label">初始序号</td>
    <td>
      <input type='text' name='bnum' maxlength="30" value="0" size='20' />    </td>
  </tr>
  <tr>
    <td class="label">生成数量</td>
    <td>
      <input type='text' name='cnum' maxlength="30" value="10" size='20' />    </td>
  </tr>
  <tr>
    <td class="label">初始金额</td>
    <td>
      <input type='text' name='card_type' maxlength="30" value="0" size='20' />    </td>
  </tr>
  <tr>
    <td class="label">&nbsp;</td>
    <td>
      <input type="submit" value="生成" class="button" />
      <input type="hidden" name="act" value="{$form_act}" />
    </td>
  </tr>
</table>
</form>
</div>
{insert_scripts files="../js/utils.js,validator.js"}
{literal}
<script language="javascript">
<!--
document.forms['theForm'].elements['type_name'].focus();

function validate()
{
  validator = new Validator("theForm");
 validator.required("bnum",         "序号为空");
  validator.required("cnum",      "数量为空");
  validator.required("sn_head",         "前缀为空");

  return validator.passed();
}
onload = function()
{
  {/literal}
  get_value = '{$bonus_arr.send_type}';
  {literal}

  showunit(get_value)
  // 开始检查订单
  startCheckOrder();
}

function gObj(obj)
{
  var theObj;
  if (document.getElementByIdx_x_x)
  {
    if (typeof obj=="string") {
      return document.getElementByIdx_x_x(obj);
    } else {
      return obj.style;
    }
  }
  return null;
}

function showunit(get_value)
{
  gObj("1").style.display =  (get_value == 2) ? "" : "none";
  document.forms['theForm'].elements['selbtn1'].disabled  = (get_value != 1 && get_value != 2);
  document.forms['theForm'].elements['selbtn2'].disabled  = (get_value != 1 && get_value != 2);

  return;
}
//-->
</script>
{/literal}
{include file="pagefooter.htm"}

创建

kt_order_goods.htm

<!-- $Id: bonus_type.htm 14216 2008-03-10 02:27:21Z testyang $ -->

{if $full_page}
{include file="pageheader.htm"}
{insert_scripts files="../js/utils.js,listtable.js"}
<!-- start bonus_type list -->
<form method="post" action="" name="listForm">
<div class="list-div" id="listDiv">
{/if}

  <table cellpadding="3" cellspacing="1">
    <tr>
      <th>编号</th>
      <th>货号</th>
      <th>名字</th>
    </tr>
    {foreach from=$type_list item=type}
    <tr>
      <td align="center" class="first-cell"><span>{$type.goods_id}</span></td>
      <td align="center">{$type.goods_sn}</td>
      <td align="center"><a href="/goods.php?id={$type.goods_id}" target="_blank">{$type.goods_name}</a></td>
    </tr>
      {foreachelse}
    <tr><td class="no-records" colspan="10">{$lang.no_records}</td></tr>
      {/foreach}

  </table>

{if $full_page}
</div>
</form>
<!-- end bonus_type list -->

<script type="text/javascript" language="JavaScript">
<!--
  listTable.recordCount = {$record_count};
  listTable.pageCount = {$page_count};

  {foreach from=$filter item=item key=key}
  listTable.filter.{$key} = '{$item}';
  {/foreach}

  {literal}
  onload = function()
  {
     // 开始检查订单
     startCheckOrder();
  }
  {/literal}
//-->
</script>
{include file="pagefooter.htm"}
{/if}
.
创建

kt_order_info.htm

<!-- $Id: bonus_type_info.htm 14216 2008-03-10 02:27:21Z testyang $ -->

<script type="text/javascript" src="../js/calendar.php?lang={$cfg_lang}"></script>
<link href="../js/calendar/calendar.css" rel="stylesheet" type="text/css" />

{include file="pageheader.htm"}
<div class="main-div">
<form action="kt_card.php" method="post" name="theForm" enctype="multipart/form-data" onsubmit="return validate()">
<table width="100%">
    <tr>
    <td class="label">编号</td>
    <td>
      <input disabled="true" readOnly="true" type='text' name='order_id' maxlength="30" value="{$order.order_id}" size='20' />    </td>
  </tr>
  <tr>
    <td class="label">储值卡编号</td>
    <td>
      <input disabled="true" readOnly="true" type='text' name='card_id' maxlength="30" value="{$order.card_id}" size='20' />    </td>
  </tr>
  <tr>
    <td class="label">订单号</td>
    <td>
      <input disabled="true" readOnly="true" type='text' name='order_sn' maxlength="30" value="{$order.order_sn}" size='20' />    </td>
  </tr>
   <tr>
    <td class="label">订单总价</td>
    <td>
      <input type='text' name='order_fee' maxlength="30" value="{$order.order_fee}" size='20' />    </td>
  </tr>
  <tr>
    <td class="label">还需支付</td>
    <td>
      <input type='text' name='order_exc' maxlength="30" value="{$order.order_exc}" size='20' />    </td>
  </tr>
   <tr>
    <td class="label">余额送礼</td>
    <td>
     <input type="radio" value="1" name="order_clr" {if $order.order_clr eq 1 }checked{/if}>是
     <input type="radio" value="0" name="order_clr" {if $order.order_clr eq 0 }checked{/if}>否   </td>
  </tr>
  <tr>
    <td class="label">联系人</td>
    <td>
      <input type='text' name='order_user' maxlength="30" value="{$order.order_user}" size='20' />    </td>
  </tr>
  <tr>
    <td class="label">联系地址</td>
    <td>
      <input type='text' name='order_address' maxlength="30" value="{$order.order_address}" size='20' />    </td>
  </tr>
  <tr>
    <td class="label">联系电话</td>
    <td>
      <input type='text' name='order_tel' maxlength="30" value="{$order.order_tel}" size='20' />    </td>
  </tr>
  <tr>
    <td class="label">移动电话</td>
    <td>
      <input type='text' name='order_phone' maxlength="30" value="{$order.order_phone}" size='20' />    </td>
  </tr>
  <tr>
    <td class="label">特殊要求备注</td>
    <td>
      <input type='text' name='order_bak' maxlength="30" value="{$order.order_bak}" size='20' />    </td>
  </tr>
  <tr>
    <td class="label">配送时间</td>
    <td>
      <input type='text' name='shipping_time' maxlength="30" value="{$order.shipping_time}" size='20' />    </td>
  </tr>
  <tr>
    <td class="label">订单创建时间</td>
    <td>
      <input disabled="true" readOnly="true" type='text' name='order_time' maxlength="30" value="{$order.order_time}" size='20' />    </td>
  </tr>
  <tr>
    <td class="label">订单状态</td>
    <td>
      <input disabled="true" readOnly="true" type='text' name='order_status' maxlength="30" value="{$order.order_status}" size='20' />    </td>
  </tr>
  <tr>
    <td class="label">&nbsp;</td>
    <td>
      <input type="submit" value="修改" class="button" />
      <input type="hidden" name="act" value="{$form_act}" />
      <input type="hidden" name="id" value="{$order.order_id}" />
    </td>
  </tr>
</table>
</form>
</div>
{insert_scripts files="../js/utils.js,validator.js"}
{literal}
<script language="javascript">
<!--
document.forms['theForm'].elements['type_name'].focus();

function validate()
{
  validator = new Validator("theForm");
  validator.required("order_user",         "联系人为空");
  validator.required("order_address",      "联系地址为空");
  validator.required("order_tel",          "联系电话为空");

  return validator.passed();
}
onload = function()
{
  {/literal}
  get_value = '{$bonus_arr.send_type}';
  {literal}

  showunit(get_value)
  // 开始检查订单
  startCheckOrder();
}

function gObj(obj)
{
  var theObj;
  if (document.getElementByIdx_x_x)
  {
    if (typeof obj=="string") {
      return document.getElementByIdx_x_x(obj);
    } else {
      return obj.style;
    }
  }
  return null;
}

function showunit(get_value)
{
  gObj("1").style.display =  (get_value == 2) ? "" : "none";
  document.forms['theForm'].elements['selbtn1'].disabled  = (get_value != 1 && get_value != 2);
  document.forms['theForm'].elements['selbtn2'].disabled  = (get_value != 1 && get_value != 2);

  return;
}
//-->
</script>
{/literal}
{include file="pagefooter.htm"}

创建

kt_order_list.htm

{if $full_page}
{include file="pageheader.htm"}
<form action="kt_card.php" method="post" name="theForm" enctype="multipart/form-data">
<h1>储值卡序号:<input type='text' name='keywords' maxlength="30" value="" size='20' /><input type="submit" value="查询" class="button" /></h1>
<input type="hidden" name="act" value="order" />
</form>
{insert_scripts files="../js/utils.js,listtable.js"}
<!-- start bonus_type list -->
<form method="post" action="" name="listForm">
<div class="list-div" id="listDiv">
{/if}

  <table cellpadding="3" cellspacing="1">
    <tr>
      <th>编号</th>
      <th>订单号</th>
      <th>订单总价</th>
      <th>超出价格</th>
      <th>余额送礼</th>
      <th>联系人</th>
      <th>特殊要求备注</th>
      <th>创建时间</th>
      <th>订单状态</th>
      <th>操作</th>
    </tr>
    {foreach from=$type_list item=type}
    <tr>
      <td align="center" class="first-cell"><span>{$type.order_id}</span></td>
      <td align="center">{$type.order_sn}</td>
      <td align="center">{$type.order_fee}</td>
      <td align="center">{$type.order_exc}</td>
      <td align="center">{if $type.order_clr eq 0}否{else}价值:{$type.order_clr}元{/if}</td>
      <td align="center">联系人:{$type.order_user}&nbsp电话:{$type.order_tel}&nbsp{$type.order_phone}<br />地址:{$type.order_address}&nbsp配送时间:{$type.shipping_time}</td>
      <td align="center">{$type.order_bak}</td>
      <td align="center">{$type.order_time}</td>
      <td align="center">
        <a href="kt_card.php?act=order_status&id={$type.order_id}&stat={$type.order_status}">{if $type.order_status eq 0}正常{elseif $type.order_status eq 1}确认{elseif $type.order_status eq 2}配送{elseif $type.order_status eq 3}完成{/if}</a></td>
      <td align="center">
        <a href="kt_card.php?act=order_info&id={$type.order_id}">详情</a> |
        <a href="kt_card.php?act=goods&gid={$type.order_goods}">商品</a> |
        <a href="kt_card.php?act=list&id={$type.card_id}">储值卡</a></td>
    </tr>
      {foreachelse}
    <tr><td class="no-records" colspan="10">{$lang.no_records}</td></tr>
      {/foreach}
     <tr>
      <td align="right" nowrap="true" colspan="8">{include file="page.htm"}</td>
    </tr>
  </table>

{if $full_page}
</div>
</form>
<!-- end bonus_type list -->

<script type="text/javascript" language="JavaScript">
<!--
  listTable.recordCount = {$record_count};
  listTable.pageCount = {$page_count};

  {foreach from=$filter item=item key=key}
  listTable.filter.{$key} = '{$item}';
  {/foreach}

  {literal}
  onload = function()
  {
     // 开始检查订单
     startCheckOrder();
  }
  {/literal}
//-->
</script>
{include file="pagefooter.htm"}
{/if}



项目跟目录创建控制器文件  ktcard.php
用户储值卡管理
<?php

define('IN_ECS', true);

require(dirname(__FILE__) . '/includes/init.php');

$action  = isset($_REQUEST['act']) ? trim($_REQUEST['act']) : 'default';

// 不需要登录的操作或自己验证是否登录(如ajax处理)的act
$not_login_arr = array('act_login','update_ktcard','next_ktcard');


$ui_arr = array('default');


if (empty($_SESSION['user_id']))
{
    if (!in_array($action, $not_login_arr))
    {
        if (in_array($action, $ui_arr))
        {
            if (!empty($_SERVER['QUERY_STRING']))
            {
                $back_act = 'ktcard.php?' . $_SERVER['QUERY_STRING'];
            }
            $action = 'default';
        }
        else
        {
            //未登录提交数据。非正常途径提交数据!
            die('已经记录此非法操作IP');
        }
    }
}


if ($action == 'default')
{
   
    assign_template();
    $smarty->assign('page_title', '用户储值卡管理');   
    $smarty->assign('ur_here',    '储值卡');
    $smarty->assign('helps',      get_shop_help());   
    $smarty->assign('act',    'act_login');   
    $smarty->assign('action',      $action);  
    $smarty->assign('back_act',      $back_act);       
   
    $smarty->display('ktcard.dwt');
   
}


if ($action == 'act_login') {

    $card_sn    = isset($_REQUEST['card_sn'])? trim($_REQUEST['card_sn']): '0';
 
    $card_pwd   = isset($_REQUEST['card_pwd'])? trim($_REQUEST['card_pwd']): '0';

        if ($card_sn != '0')

        {

               $sql = "SELECT * FROM " .$ecs->table('kt_bcards').
                      " WHERE card_sn = '$card_sn'" .
                      " AND card_pwd = '$card_pwd'";

               $record_arr = $db->getRow($sql);

             if (empty($record_arr))

             {
                 show_message('卡号或密码错误');
                 return 0;
             }
             else
             {

                   assign_template();
                $smarty->assign('page_title', '用户储值卡管理');   
                $smarty->assign('ur_here',    '储值卡');
                $smarty->assign('helps',      get_shop_help());   
                $smarty->assign('act',    'next_ktcard');   
                $smarty->assign('action',      $action);  
                $smarty->assign('back_act',     $back_act); 
                $smarty->assign('card_sn',      $card_sn);
                $smarty->assign('card_pwd',     $card_pwd);
                $smarty->assign('card_bonus',    $record_arr['card_bonus']); 
                $smarty->assign('goods_list',    get_order_goods_list());   
                $smarty->display('ktcard.dwt');
               
             }
        }

}


if ($action == 'next_ktcard')
{
      $arr       = array();
      $arr       = $_POST['goods'];
      $goods     = !empty($arr) ? join(",",$arr) : '0';
   
    $card_sn    = isset($_REQUEST['card_sn'])? trim($_REQUEST['card_sn']): '0';
      $card_pwd   = isset($_REQUEST['card_pwd'])? trim($_REQUEST['card_pwd']): '0';
   
      $sql = "SELECT * FROM " .$ecs->table('kt_bcards').
                      " WHERE card_sn = '$card_sn'" .
                      " AND card_pwd = '$card_pwd'";

    $record_arr = $db->getRow($sql);
    $card_bonus = $record_arr['card_bonus'];
   
    $sql = "SELECT SUM(shop_price) FROM " .$GLOBALS['ecs']->table('goods').
               " WHERE goods_id in ($goods)";
    $fee = $GLOBALS['db']->getOne($sql);
            
             if ($fee > $card_bonus)
             {
                 $order_msg = $fee - $card_bonus;
                 $order_msg = "订单超出储值卡余额 $order_msg 元,收货时还需补交 $order_msg 元.";
             }
            else
             {
                $order_msg = $card_bonus - $fee;
                 $order_msg = "订单总额: $fee 元,提交当前订单之后储值卡余额为: $order_msg 元.";
             }
             if (empty($record_arr))

             {
                 show_message('卡号或密码错误');
                 return 0;
             }
            if (empty($arr))
             {
                 show_message('请选择商品');
                 return 0;
             }

    assign_template();
    $smarty->assign('page_title', '用户储值卡管理');   
    $smarty->assign('ur_here',    '储值卡');
    $smarty->assign('helps',      get_shop_help());   
    $smarty->assign('act',    'update_ktcard');   
    $smarty->assign('action',      $action);  
    $smarty->assign('back_act',      $back_act); 
    $smarty->assign('card_sn',      $card_sn);
    $smarty->assign('card_pwd',     $card_pwd); 
    $smarty->assign('goods_id',     $goods);
    $smarty->assign('card_bonus',    $record_arr['card_bonus']);
    $smarty->assign('fee',    $fee);
    $smarty->assign('order_msg',    $order_msg);
   
    $smarty->display('ktcard.dwt');
   
}
   


if ($action == 'update_ktcard')
{
    $order_user    = isset($_REQUEST['order_user'])? trim($_REQUEST['order_user']): '0';
    $order_address    = isset($_REQUEST['order_address'])? trim($_REQUEST['order_address']): '0';
    $order_tel    = isset($_REQUEST['order_tel'])? trim($_REQUEST['order_tel']): '0';
    $order_phone    = isset($_REQUEST['order_phone'])? trim($_REQUEST['order_phone']): '0';
    $order_bak    = isset($_REQUEST['order_bak'])? trim($_REQUEST['order_bak']): '0';
    $shipping_time    = isset($_REQUEST['shipping_time'])? trim($_REQUEST['shipping_time']): '0';
    $order_clr     = !empty($_REQUEST['order_clr'])    ? intval($_REQUEST['order_clr'])    : 0;
   
   
  $card_sn    = isset($_REQUEST['card_sn'])? trim($_REQUEST['card_sn']): '0';
    $card_pwd   = isset($_REQUEST['card_pwd'])? trim($_REQUEST['card_pwd']): '0';
   
    $goods   = isset($_REQUEST['goods'])? trim($_REQUEST['goods']): '0';
   
    $order_sn = get_order_sn(); 
  $order_time = gmtime();
 
  $sql = "SELECT * FROM " .$ecs->table('kt_bcards').
                      " WHERE card_sn = '$card_sn'" .
                      " AND card_pwd = '$card_pwd'";

    $record_arr = $db->getRow($sql);
    $card_bonus = $record_arr['card_bonus'];
 
  $sql = "SELECT SUM(shop_price) FROM " .$GLOBALS['ecs']->table('goods').
               " WHERE goods_id in ($goods)";
  $fee = $GLOBALS['db']->getOne($sql);


            if (empty($order_user) OR (empty($order_tel) AND empty($order_phone)))
             {
                 show_message('联系人为必填项,电话任选其一.');
                 return 0;
             }
            
              if ($card_sn != '0')
            {

               $sql = "SELECT * FROM " .$ecs->table('kt_bcards').
                      " WHERE card_sn = '$card_sn'" .
                      " AND card_pwd = '$card_pwd'";

               $record_arr = $db->getRow($sql);

             if (empty($record_arr))

             {
                 show_message('卡号或密码错误');
                 return 0;
             }
             else
             {
                  $card_id = intval($record_arr['card_id']);
                  
                     if ($fee > $card_bonus)
                     {
                         $order_exc = $fee - $card_bonus;
                          $sql = "UPDATE " .$ecs->table('kt_bcards'). " SET ".
                      "card_bonus         = 0 ".
                      " WHERE card_sn = '$card_sn'" .
                      " AND card_pwd = '$card_pwd'";
                      $db->query($sql);
                      $order_clr = 0;
                     }
                     else
                      {
                         $order_exc = 0;
                         $card_bonus_last = $card_bonus - $fee;
                      $sql = "UPDATE " .$ecs->table('kt_bcards'). " SET ".
                      "card_bonus         = '$card_bonus_last' ".
                      " WHERE card_sn = '$card_sn'" .
                      " AND card_pwd = '$card_pwd'";
                      $db->query($sql);
                                             if($order_clr <> 0)
                                            {
                                                   $order_clr = $card_bonus_last;
                                                   $sql = "UPDATE " .$ecs->table('kt_bcards'). " SET ".
                      "card_bonus         = 0 ".
                      " WHERE card_sn = '$card_sn'" .
                      " AND card_pwd = '$card_pwd'";
                      $db->query($sql);
                                                  
                                            }
                       }

                  
                  $GLOBALS['db']->query("INSERT INTO ".$GLOBALS['ecs']->table('kt_order')." (card_id, order_sn, order_fee, order_exc, order_clr, order_user, order_address, order_tel, order_phone, order_bak, shipping_time, order_time, order_goods, order_status) VALUES($card_id,'$order_sn','$fee','$order_exc','$order_clr','$order_user','$order_address','$order_tel','$order_phone','$order_bak','$shipping_time','$order_time','$goods',0)");
            
                $sql = "UPDATE " .$ecs->table('kt_bcards'). " SET ".
                      "used_time         = '$order_time' ".
                      " WHERE card_sn = '$card_sn'" .
                      " AND card_pwd = '$card_pwd'";

                $db->query($sql);
               $action = 'default';
                  show_message('已经成功提交订单!', '返回储值卡管理', 'ktcard.php','default');
             }
           }
  echo 'asdfasdffffffffffffffffffffffffffffffffffffffff';
}


function get_order_sn()
{
   
    mt_srand((double) microtime() * 1000000);

    return date('Ymd') . str_pad(mt_rand(1, 99999), 5, '0', STR_PAD_LEFT);
}


function get_order_goods_list()
{

  
    $sql = "SELECT * FROM " .$GLOBALS['ecs']->table('goods') . " WHERE is_on_sale = 1 ORDER BY goods_id desc" ;
                           
    $result = $GLOBALS['db']->getAll($sql);
    $goods = array();
   
    foreach ($result AS $idx => $row)
    {
          $goods[$idx]['goods_id']           = $row['goods_id'];
        $goods[$idx]['goods_name']         = $row['goods_name'];
        $goods[$idx]['shop_price']         = $row['shop_price'];
    }

return $goods;
}



function get_goods_name($id)

{
    $sql = "SELECT goods_name FROM " .$GLOBALS['ecs']->table('goods').
               " WHERE goods_id = '$id'";
  $result = $GLOBALS['db']->getOne($sql);
 
  return $result;
              
}



function get_goods_bak($id)

{
    $sql = "SELECT seller_note FROM " .$GLOBALS['ecs']->table('goods').
               " WHERE goods_id = '$id'";
  $result = $GLOBALS['db']->getOne($sql);
 
  return $result;
              
}


?>



储值卡模板页面
\themes\default
创建
可以自己布局页面
ktcard.dwt



<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="Keywords" content="{$keywords}" />
<meta name="Description" content="{$description}" /><meta http-equiv=x-ua-compatible content=ie=7 />
<!-- TemplateBeginEditable name="doctitle" -->
<title>{$page_title}</title>
<!-- TemplateEndEditable --><!-- TemplateBeginEditable name="head" --><!-- TemplateEndEditable -->
<link rel="shortcut icon" href="favicon.ico" />
<link rel="icon" href="animated_favicon.gif" type="image/gif" />
<link href="{$ecs_css_path}" rel="stylesheet" type="text/css" />{* 包含脚本文件 *}
{insert_scripts files='common.js'}
</head>
<body>
  <div id="wrap">
    <!-- #BeginLibraryItem "/library/page_header.lbi" --><!-- #EndLibraryItem -->
    <!-- #BeginLibraryItem "/library/ur_here.lbi" --><!-- #EndLibraryItem -->
   
    <!--{if $action eq 'default'}-->
    <div class="container">
      <div class="module">
        <h1><span></span>储值卡</h1>
        <div class="content" style="padding:8px;">
         <form name="formLogin" action="ktcard.php" method="post"">
            <table width="100%" border="0" align="left" cellpadding="3" cellspacing="5">
              <tr>
                <td width="40%" align="right">储值卡序号</td>
                <td width="60%"><input name="card_sn" type="text" size="20" class="inputBg" /></td>
              </tr>
              <tr>
                <td align="right">储值卡密码</td>
                <td>
                <input name="card_pwd" type="text" size="20"  class="inputBg"/>
                </td>
              </tr>
                            <tr>
                <td>&nbsp;</td>
                <td align="left">
                  <input type="hidden" name="act" value="{$act}" />
                  <input type="hidden" name="back_act" value="{$back_act}" />
                  <input type="submit" name="submit" value="" class="us_Submit" />
                </td>
              </tr>
            </table>
          </form>
        </div>
      </div>
    </div>
    <!--{/if}-->
   
    <!--{if $action eq 'act_login'}-->
    <div class="container">
      <div class="module">
        <h1><span></span>储值卡</h1>
        <div class="content" style="padding:8px;">
             <div style="color:red;">储值卡余额: {$card_bonus}元</div>
         <form name="formLogin" action="ktcard.php" method="post"">
             <div style="width:900px;margin:0 auto;">
             {foreach from=$goods_list item=goods}
             <li style="float:left;width:300px;"><input name="goods[]" type="checkbox" value="{$goods.goods_id}" /> <a href="/goods.php?id={$goods.goods_id}" target="_blank">{$goods.goods_name}  ¥{$goods.shop_price}</a></li>
             {foreachelse}
                没有可选商品,请联系客服.
             {/foreach}
             </div>
                <div style="text-align: center;padding-top:10px;">
                  <input type="hidden" name="act" value="{$act}" />
                  <input type="hidden" name="back_act" value="{$back_act}" />
                  <input type="hidden" name="card_sn" value="{$card_sn}" />
                  <input type="hidden" name="card_pwd" value="{$card_pwd}" />
                  <input type="submit" name="submit" value="" style="width:145px; height:40px; background:url(images/bnt_subOrder.gif) no-repeat 0 0; border:none; cursor:pointer;" />
                </div>
          </form>
        </div>
      </div>
    </div>
    <!--{/if}-->
   
     <!--{if $action eq 'next_ktcard'}-->
    <div class="container">
      <div class="module">
        <h1><span></span>储值卡</h1>
        <div class="content" style="padding:8px;">
        <div style="color:red;">储值卡余额: {$card_bonus}元  此次消费总额:{$fee}元   说明: {$order_msg}</div>
         <form name="formLogin" action="ktcard.php" method="post"">
            <table width="100%" border="0" align="left" cellpadding="3" cellspacing="5">
              <tr>
                <td width="40%" align="right">联系人</td>
                <td width="60%"><input name="order_user" type="text" size="20" class="inputBg" /></td>
              </tr>
              <tr>
                <td align="right">联系地址</td>
                <td>
                <input name="order_address" type="text" size="20"  class="inputBg"/>
                </td>
              </tr>
              <tr>
                <td align="right">固定电话</td>
                <td>
                <input name="order_tel" type="text" size="20"  class="inputBg"/>
                </td>
              </tr>
              <tr>
                <td align="right">移动电话</td>
                <td>
                <input name="order_phone" type="text" size="20"  class="inputBg"/>
                </td>
              </tr>
              <tr>
                <td align="right">特殊要求</td>
                <td>
                <input name="order_bak" type="text" size="20"  class="inputBg"/>
                </td>
              </tr>
              <tr>
                <td align="right">配送时间</td>
                <td>
                <input type="radio" name="shipping_time" value="全天" checked="checked" />全天
                <input type="radio" name="shipping_time" value="上午" />上午
                <input type="radio" name="shipping_time" value="下午" />下午
                </td>
              </tr>
              <tr>
                <td align="right">余额送礼</td>
                <td>
                <input type="checkbox" name="order_clr" value="1" />储值卡内剩余小余额通过赠品形式连同礼品同时送达
                </td>
              </tr>
              <tr>
                <td align="right">配送说明:</td>
                <td>
                购物总额200元以上五环内免费送货,五环外需额外附加配送费用.详情请咨询本站客服.
                </td>
              </tr>
                            <tr>
                <td>&nbsp;</td>
                <td align="left">
                  <input type="hidden" name="act" value="{$act}" />
                  <input type="hidden" name="back_act" value="{$back_act}" />
                  <input type="hidden" name="card_sn" value="{$card_sn}" />
                  <input type="hidden" name="card_pwd" value="{$card_pwd}" />
                  <input type="hidden" name="goods" value="{$goods_id}" />
                  <input type="submit" name="submit" value="" style="width:145px; height:40px; background:url(images/bnt_subOrder.gif) no-repeat 0 0; border:none; cursor:pointer;" />
                </td>
              </tr>
            </table>
          </form>
        </div>
      </div>
    </div>
    <!--{/if}-->
   
     <!--{if $action eq 'order_info'}-->
    <div class="container">
      <div class="module">
        <h1><span></span>已提交的订单</h1>
        <div class="content" style="padding:8px;">
         <table width="100%" border="0" align="left" cellpadding="3" cellspacing="5">
    <tr>
    <td width="40%" align="right">订单号</td>
    <td width="60%" >
      <input disabled="true" readOnly="true" type='text' name='order_id' maxlength="30" value="{$order.order_sn}" size='20' />    </td>
  </tr>
  <tr>
    <td align="right">联系人</td>
    <td>
      <input disabled="true" readOnly="true" type='text' name='order_user' maxlength="30" value="{$order.order_user}" size='20' />    </td>
  </tr>
  <tr>
    <td align="right">联系地址</td>
    <td>
      <input disabled="true" readOnly="true" type='text' name='order_address' maxlength="30" value="{$order.order_address}" size='20' />    </td>
  </tr>
  <tr>
    <td align="right">联系电话</td>
    <td>
      <input disabled="true" readOnly="true" type='text' name='order_tel' maxlength="30" value="{$order.order_tel}" size='20' />    </td>
  </tr>
  <tr>
    <td align="right">移动电话</td>
    <td>
      <input disabled="true" readOnly="true" type='text' name='order_phone' maxlength="30" value="{$order.order_phone}" size='20' />    </td>
  </tr>
  <tr>
    <td align="right">特殊要求备注</td>
    <td>
      <input disabled="true" readOnly="true" type='text' name='order_bak' maxlength="30" value="{$order.order_bak}" size='20' />    </td>
  </tr>
  <tr>
    <td align="right">配送时间</td>
    <td>
      <input disabled="true" readOnly="true" type='text' name='shipping_time' maxlength="30" value="{$order.shipping_time}" size='20' />    </td>
  </tr>
  <tr>
    <td align="right">订单创建时间</td>
    <td>
      <input disabled="true" readOnly="true" type='text' name='order_time' maxlength="30" value="{$order_time}" size='20' />    </td>
  </tr>
  <tr>
    <td align="right">订单状态</td>
    <td>
      <input disabled="true" readOnly="true" type='text' name='order_status' maxlength="30" value="{if $type.order_status eq 0}正常{elseif $type.order_status eq 1}已确认{elseif $type.order_status eq 2}已配送{elseif $type.order_status eq 3}完成{/if}" size='20' />    </td>
  </tr>
</table>
        </div>
      </div>
    </div>
    <!--{/if}-->
   
   
    <!-- #BeginLibraryItem "/library/help.lbi" --><!-- #EndLibraryItem -->
    <!-- #BeginLibraryItem "/library/page_footer.lbi" --><!-- #EndLibraryItem -->
  </div>
</body>
</html>

项目根目录创建
用户礼品卡管理
kscard.php

<?php
define('IN_ECS', true);

require(dirname(__FILE__) . '/includes/init.php');

$action  = isset($_REQUEST['act']) ? trim($_REQUEST['act']) : 'default';

// 不需要登录的操作或自己验证是否登录(如ajax处理)的act
$not_login_arr = array('act_login','update_kscard');


$ui_arr = array('default');


if (empty($_SESSION['user_id']))
{
    if (!in_array($action, $not_login_arr))
    {
        if (in_array($action, $ui_arr))
        {
            if (!empty($_SERVER['QUERY_STRING']))
            {
                $back_act = 'kscard.php?' . $_SERVER['QUERY_STRING'];
            }
            $action = 'default';
        }
        else
        {
            //未登录提交数据。非正常途径提交数据!
            die('已经记录此非法操作IP');
        }
    }
}


if ($action == 'default')
{
   
    assign_template();
    $smarty->assign('page_title', '用户礼品卡管理');   
    $smarty->assign('ur_here',    '礼品卡');
    $smarty->assign('helps',      get_shop_help());   
    $smarty->assign('act',    'act_login');   
    $smarty->assign('action',      $action);  
    $smarty->assign('back_act',      $back_act);       
   
    $smarty->display('kscard.dwt');
   
}


if ($action == 'act_login') {

    $card_sn    = isset($_REQUEST['card_sn'])? trim($_REQUEST['card_sn']): '0';
 
    $card_pwd   = isset($_REQUEST['card_pwd'])? trim($_REQUEST['card_pwd']): '0';

        if ($card_sn != '0')

        {

               $sql = "SELECT * FROM " .$ecs->table('ks_cards').
                      " WHERE card_sn = '$card_sn'" .
                      " AND card_pwd = '$card_pwd'";

               $record_arr = $db->getRow($sql);

             if (empty($record_arr))

             {
                 show_message('卡号或密码错误');
                 return 0;
             }
             else
             {
                   if($record_arr['order_id'] == 0)
                   {
                   assign_template();
                $smarty->assign('page_title', '用户礼品卡管理');   
                $smarty->assign('ur_here',    '礼品卡');
                $smarty->assign('helps',      get_shop_help());   
                $smarty->assign('act',    'update_kscard');   
                $smarty->assign('action',      $action);  
                $smarty->assign('back_act',     $back_act); 
                $smarty->assign('card_sn',      $card_sn);
                $smarty->assign('card_id',      $record_arr['card_id']);
                $smarty->assign('card_pwd',     $card_pwd);
                $smarty->assign('card_type',    $record_arr['card_type']); 
                $smarty->assign('goods_list',    get_order_goods_list($record_arr['card_type']));
                $smarty->assign('sel_num',    get_goods_num($record_arr['card_type']));    
                $smarty->display('kscard.dwt');
                }
                else
                {
                 assign_template();
                $smarty->assign('page_title', '用户礼品卡管理');   
                $smarty->assign('ur_here',    '礼品卡');
                $smarty->assign('helps',      get_shop_help());   
                $smarty->assign('act',        'order_info');   
                $smarty->assign('action',     'order_info');  
               
                $order_id = $record_arr['order_id'];
                $list = $db->getRow("SELECT * FROM " .$ecs->table('ks_order'). " WHERE order_id = '$order_id'");
                $order_time = local_date("Y-h-d H:i:s", $list[order_time]);
                $smarty->assign('order_time',    $order_time);
                $smarty->assign('order',    $list); 
                $smarty->display('kscard.dwt');
                }
               
             }
        }

}
   


if ($action == 'update_kscard')
{
    $order_user    = isset($_REQUEST['order_user'])? trim($_REQUEST['order_user']): '0';
    $order_address    = isset($_REQUEST['order_address'])? trim($_REQUEST['order_address']): '0';
    $order_tel    = isset($_REQUEST['order_tel'])? trim($_REQUEST['order_tel']): '0';
    $order_phone    = isset($_REQUEST['order_phone'])? trim($_REQUEST['order_phone']): '0';
    $order_bak    = isset($_REQUEST['order_bak'])? trim($_REQUEST['order_bak']): '0';
    $shipping_time    = isset($_REQUEST['shipping_time'])? trim($_REQUEST['shipping_time']): '0';
   
    $arr       = array();
    $arr       = $_POST['goods'];
    $goods_num = count($arr);
    $goods     = !empty($arr) ? join(",",$arr) : '0';
   
    $card_sn    = isset($_REQUEST['card_sn'])? trim($_REQUEST['card_sn']): '0';
    $card_pwd   = isset($_REQUEST['card_pwd'])? trim($_REQUEST['card_pwd']): '0';
    $card_type   = !empty($_REQUEST['card_type'])? intval($_REQUEST['card_type']): 0;
   
    $sel_num   = !empty($_REQUEST['sel_num'])? intval($_REQUEST['sel_num']): 0;
   
    $card_id   = !empty($_REQUEST['card_id'])? intval($_REQUEST['card_id']): 0;

            if (empty($order_user) OR (empty($order_tel) AND empty($order_phone)))
             {
                 show_message('联系人为必填项,电话任选其一.');
                 return 0;
             }
             if (empty($arr))
             {
                 show_message('请选择商品');
                 return 0;
             }
             if ($sel_num <> $goods_num)
             {
                 show_message("商品限定只选择($sel_num)种,请重新选择.");
                 return 0;
             }
            
              if ($card_sn != '0')

            {

               $sql = "SELECT * FROM " .$ecs->table('ks_cards').
                      " WHERE card_sn = '$card_sn'" .
                      " AND card_pwd = '$card_pwd'";

               $record_arr = $db->getRow($sql);

             if (empty($record_arr))

             {
                 show_message('卡号或密码错误');
                 return 0;
             }
             else
             {
                  $order_sn = get_order_sn(); 
                  $order_time = gmtime();
                  
                  $GLOBALS['db']->query("INSERT INTO ".$GLOBALS['ecs']->table('ks_order')." (order_sn, card_id, order_goodcatid, order_user, order_address, order_tel, order_phone, order_bak, shipping_time, order_time, order_goods, order_status) VALUES('$order_sn','$card_id','$card_type','$order_user','$order_address','$order_tel','$order_phone','$order_bak','$shipping_time','$order_time','$goods',0)");
                  
                  $sql = 'SELECT order_id FROM ' . $GLOBALS['ecs']->table('ks_order') . " WHERE order_time = '$order_time'";
               $order_id = $GLOBALS['db']->getOne($sql);
              
                $sql = "UPDATE " .$ecs->table('ks_cards'). " SET ".
                      "order_id         = '$order_id' ,".
                      "used_time         = '$order_time' ".
                      " WHERE card_sn = '$card_sn'" .
                      " AND card_pwd = '$card_pwd'";

           $db->query($sql);
               $action = 'default';
                  show_message('已经成功提交订单!', '返回礼品卡管理', 'kscard.php','default');
             }
           }
  echo 'asdfasdffffffffffffffffffffffffffffffffffffffff';
}


function get_order_sn()
{
   
    mt_srand((double) microtime() * 1000000);

    return date('Ymd') . str_pad(mt_rand(1, 99999), 5, '0', STR_PAD_LEFT);
}


function get_order_goods_list($id)
{

  
    $sql = "SELECT * FROM " .$GLOBALS['ecs']->table('ks_cardgoods') . " WHERE cg_catid = $id" ;
                           
    $result = $GLOBALS['db']->getAll($sql);
    $goods = array();
   
    foreach ($result AS $idx => $row)
    {
       
        $goods[$idx]['cg_id']           = $row['cg_id'];
        $goods[$idx]['cg_catid']         = $row['cg_catid'];
        $goods[$idx]['cg_goodid']         = $row['cg_goodid'];
        $goods[$idx]['cg_goodname']        = get_goods_name($row['cg_goodid']);
        $goods[$idx]['cg_goodbak']        = get_goods_bak($row['cg_goodid']);

    }

return $goods;
}



function get_goods_name($id)

{
    $sql = "SELECT goods_name FROM " .$GLOBALS['ecs']->table('goods').
               " WHERE goods_id = '$id'";
  $result = $GLOBALS['db']->getOne($sql);
 
  return $result;
              
}



function get_goods_bak($id)

{
    $sql = "SELECT seller_note FROM " .$GLOBALS['ecs']->table('goods').
               " WHERE goods_id = '$id'";
  $result = $GLOBALS['db']->getOne($sql);
 
  return $result;
              
}



function get_goods_num($id)

{
    $sql = "SELECT cat_sgn FROM " .$GLOBALS['ecs']->table('ks_cardcats').
               " WHERE cat_id = '$id'";
  $result = $GLOBALS['db']->getOne($sql);
 
  return $result;
              
}
?>


最后一步
themes\default
创建
kscard.dwt
用户礼品卡管理模板页


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="Keywords" content="{$keywords}" />
<meta name="Description" content="{$description}" /><meta http-equiv=x-ua-compatible content=ie=7 />
<!-- TemplateBeginEditable name="doctitle" -->
<title>{$page_title}</title>
<!-- TemplateEndEditable --><!-- TemplateBeginEditable name="head" --><!-- TemplateEndEditable -->
<link rel="shortcut icon" href="favicon.ico" />
<link rel="icon" href="animated_favicon.gif" type="image/gif" />
<link href="{$ecs_css_path}" rel="stylesheet" type="text/css" />{* 包含脚本文件 *}
{insert_scripts files='common.js'}
</head>
<body>
  <div id="wrap">
    <!-- #BeginLibraryItem "/library/page_header.lbi" --><!-- #EndLibraryItem -->
    <!-- #BeginLibraryItem "/library/ur_here.lbi" --><!-- #EndLibraryItem -->
   
    <!--{if $action eq 'default'}-->
    <div class="container">
      <div class="module">
        <h1><span></span>礼品卡</h1>
        <div class="content" style="padding:8px;">
         <form name="formLogin" action="kscard.php" method="post"">
            <table width="100%" border="0" align="left" cellpadding="3" cellspacing="5">
              <tr>
                <td width="40%" align="right">礼品卡序号</td>
                <td width="60%"><input name="card_sn" type="text" size="20" class="inputBg" /></td>
              </tr>
              <tr>
                <td align="right">礼品卡密码</td>
                <td>
                <input name="card_pwd" type="text" size="20"  class="inputBg"/>
                </td>
              </tr>
                            <tr>
                <td>&nbsp;</td>
                <td align="left">
                  <input type="hidden" name="act" value="{$act}" />
                  <input type="hidden" name="back_act" value="{$back_act}" />
                  <input type="submit" name="submit" value="" class="us_Submit" />
                </td>
              </tr>
            </table>
          </form>
        </div>
      </div>
    </div>
    <!--{/if}-->
   
    <!--{if $action eq 'act_login'}-->
    <div class="container">
      <div class="module">
        <h1><span></span>礼品卡</h1>
        <div class="content" style="padding:8px;">
         <form name="formLogin" action="kscard.php" method="post"">
            <table width="100%" border="0" align="left" cellpadding="3" cellspacing="5">
              <tr>
                <td width="40%" align="right">联系人</td>
                <td width="60%"><input name="order_user" type="text" size="20" class="inputBg" /></td>
              </tr>
              <tr>
                <td align="right">联系地址</td>
                <td>
                <input name="order_address" type="text" size="20"  class="inputBg"/>
                </td>
              </tr>
              <tr>
                <td align="right">固定电话</td>
                <td>
                <input name="order_tel" type="text" size="20"  class="inputBg"/>
                </td>
              </tr>
              <tr>
                <td align="right">移动电话</td>
                <td>
                <input name="order_phone" type="text" size="20"  class="inputBg"/>
                </td>
              </tr>
              <tr>
                <td align="right">特殊要求</td>
                <td>
                <input name="order_bak" type="text" size="20"  class="inputBg"/>
                </td>
              </tr>
              <tr>
                <td align="right">配送时间</td>
                <td>
                <input type="radio" name="shipping_time" value="全天" checked="checked" />全天
                <input type="radio" name="shipping_time" value="上午" />上午
                <input type="radio" name="shipping_time" value="下午" />下午
                </td>
              </tr>
              <tr>
                <td align="right">选择商品<br /></td>
                <td>
                {foreach from=$goods_list item=goods}
                <input name="goods[]" type="checkbox" value="{$goods.cg_goodid}" /><a href="/goods.php?id={$goods.cg_goodid}" target="_blank">{$goods.cg_goodname}</a>
                {if $goods.cg_goodbak}
                 (说明:{$goods.cg_goodbak}) 
                 {/if}<br />
                {foreachelse}
                没有可选商品,请联系客服.
                {/foreach}
                <span style="color:red;">可选{$sel_num}件</span>
                </td>
              </tr>
                            <tr>
                <td>&nbsp;</td>
                <td align="left">
                  <input type="hidden" name="act" value="{$act}" />
                  <input type="hidden" name="back_act" value="{$back_act}" />
                  <input type="hidden" name="card_sn" value="{$card_sn}" />
                  <input type="hidden" name="card_id" value="{$card_id}" />
                  <input type="hidden" name="card_pwd" value="{$card_pwd}" />
                  <input type="hidden" name="card_type" value="{$card_type}" />
                  <input type="hidden" name="sel_num" value="{$sel_num}" />
                  <input type="submit" name="submit" value="" style="width:145px; height:40px; background:url(images/bnt_subOrder.gif) no-repeat 0 0; border:none; cursor:pointer;" />
                </td>
              </tr>
            </table>
          </form>
        </div>
      </div>
    </div>
    <!--{/if}-->
   
     <!--{if $action eq 'order_info'}-->
    <div class="container">
      <div class="module">
        <h1><span></span>已提交的订单</h1>
        <div class="content" style="padding:8px;">
         <table width="100%" border="0" align="left" cellpadding="3" cellspacing="5">
    <tr>
    <td width="40%" align="right">订单号</td>
    <td width="60%" >
      <input disabled="true" readOnly="true" type='text' name='order_id' maxlength="30" value="{$order.order_sn}" size='20' />    </td>
  </tr>
  <tr>
    <td align="right">联系人</td>
    <td>
      <input disabled="true" readOnly="true" type='text' name='order_user' maxlength="30" value="{$order.order_user}" size='20' />    </td>
  </tr>
  <tr>
    <td align="right">联系地址</td>
    <td>
      <input disabled="true" readOnly="true" type='text' name='order_address' maxlength="30" value="{$order.order_address}" size='20' />    </td>
  </tr>
  <tr>
    <td align="right">联系电话</td>
    <td>
      <input disabled="true" readOnly="true" type='text' name='order_tel' maxlength="30" value="{$order.order_tel}" size='20' />    </td>
  </tr>
  <tr>
    <td align="right">移动电话</td>
    <td>
      <input disabled="true" readOnly="true" type='text' name='order_phone' maxlength="30" value="{$order.order_phone}" size='20' />    </td>
  </tr>
  <tr>
    <td align="right">特殊要求备注</td>
    <td>
      <input disabled="true" readOnly="true" type='text' name='order_bak' maxlength="30" value="{$order.order_bak}" size='20' />    </td>
  </tr>
  <tr>
    <td align="right">配送时间</td>
    <td>
      <input disabled="true" readOnly="true" type='text' name='shipping_time' maxlength="30" value="{$order.shipping_time}" size='20' />    </td>
  </tr>
  <tr>
    <td align="right">订单创建时间</td>
    <td>
      <input disabled="true" readOnly="true" type='text' name='order_time' maxlength="30" value="{$order_time}" size='20' />    </td>
  </tr>
  <tr>
    <td align="right">订单状态</td>
    <td>
      <input disabled="true" readOnly="true" type='text' name='order_status' maxlength="30" value="{if $type.order_status eq 0}正常{elseif $type.order_status eq 1}已确认{elseif $type.order_status eq 2}已配送{elseif $type.order_status eq 3}完成{/if}" size='20' />    </td>
  </tr>
</table>
        </div>
      </div>
    </div>
    <!--{/if}-->
   
   
    <!-- #BeginLibraryItem "/library/help.lbi" --><!-- #EndLibraryItem -->
    <!-- #BeginLibraryItem "/library/page_footer.lbi" --><!-- #EndLibraryItem -->
  </div>
</body>
</html>


充值卡功能插件全部上传完毕……
转载自http://blog.sina.com.cn/huanglei2011

本文地址:http://cms.xisix.com:8880/post-99.html

添加新评论