user.php
/* 显示页面的action列表 */
$ui_arr = array('register', 'login', 'profile',... 增加 cz
然后在下面代码处加入
if ($action == 'cz')//冲值
{
if($_GET['a']=='add'){
if (empty($_SESSION['user_id'])){
show_message("该用户不存在。", '返回上一页', 'user.php?act=cz');
}
else{
$k=strtoupper(substr($_POST['k'],0,8));
$p=strtoupper(substr($_POST['p'],0,8));
$row = $db -> getRow("SELECT * FROM cz_access WHERE `kid`='$k' and kpass='$p'");
if (empty($row[id])){ show_message("卡号,密码不正确。", '返回上一页', 'user.php?act=cz');}
if ($row[yes]>0){show_message("卡号已经被使用了。", '返回上一页', 'user.php?act=cz');}
$r = $db -> getRow("SELECT num,name,ksj,jsj FROM cz_type WHERE id=".$row['type']);
if(!( time()>=strtotime($r['ksj']) and time()<=strtotime($r['jsj']) )){show_message("该卡号不在使用范围之内。".$r['ksj']."--".$r['jsj'], '返回上一页', 'user.php?act=cz');}
$db->query("update cz_access set yes=1,uid=".$_SESSION['user_id'].",sj='".date("Y-n-j G:i:s")."' where id=".$row['id']);
log_account_change($_SESSION['user_id'],$r[num],0,0,0,'易购卡冲值');
$db->query("insert into cz_logs (log) values ('用户:".$_SESSION['user_id'].$_SESSION['user_name']."|冲值金额:".$r[num]."元|卡类型:".$r['name']."|时间:".date("Y-n-j G:i:s")."') ");
show_message("冲值成功。", '返回上一页', 'user.php?act=cz');
}
}
include_once(ROOT_PATH .'includes/lib_clips.php');
$info=get_user_default($user_id);
$smarty->assign('surplus', $info['surplus']);
$sql = 'SELECT b.name,b.num,a.kid,a.kpass,a.sj FROM cz_access as a left join cz_type as b on a.type=b.id WHERE a.uid='.$user_id.' ORDER BY a.sj desc';
$list = $db->getAll($sql);
$smarty->assign('list', $list);
$smarty->display('user_transaction.dwt');
}
--------------------------------------------------------------------------------------------------------------------
themes\default\user_transaction.dwt 模板里增加充值模板
<!-- {if $action eq "cz"} -->
<h5 class="user-title"><span>我的易购卡</span></h5>
<table width="100%" border="0" cellpadding="5" cellspacing="1" bgcolor="#EDD28B">
<tr align="center">
<td bgcolor="#ffffff">{$lang.process_time}</td>
<td bgcolor="#ffffff">{$lang.surplus_pro_type}</td>
<td bgcolor="#ffffff">{$lang.money}</td>
<td bgcolor="#ffffff">卡号</td>
<td bgcolor="#ffffff">密码</td>
</tr>
<!--{foreach from=$list item=item}-->
<tr>
<td align="center" bgcolor="#ffffff">{$item.sj}</td>
<td align="center" bgcolor="#ffffff">{$item.name}</td>
<td align="center" bgcolor="#ffffff">{$item.num}</td>
<td align="center" bgcolor="#ffffff">{$item.kid}</td>
<td align="center" bgcolor="#ffffff">{$item.kpass}</td>
</tr>
<!--{/foreach}-->
<tr>
<td colspan="7" align="right" bgcolor="#ffffff">{$lang.current_surplus}{$surplus}</td> </tr> </table><br>
<h5 class="user-title"><span>添加充值卡</span></h5>
<div style="border:1px solid #EDD28B" class="box">
<form name="form1" method="post" action="user.php?act=cz&a=add">
<table width="80%" border="0"> <tr>
<td width="80" align="center">卡号:</td>
<td width="23%"><input name="k" type="text" id="k" maxlength="8" class="inputBg" ></td>
<td width="80" align="center">密码:</td>
<td width="39%"><input name="p" type="text" id="p" maxlength="8" class="inputBg" ></td>
<td width="23%">
<input type="submit" name="button" id="button" value="冲 值" style="border:none;" class="bnt_blue_1">
</td> </tr></table></form>
</div>
<!-- {/if} -->
----------------------------------------------------------------------------------------------------------------------------------------------------------
themes\default\library\user_menu.lbi
<a href="user.php?act=cz"{if $action eq 'cz'}class="curs"{/if}>我的充值卡</a>
------------------------------------------------------------------------------------------------------------------------
数据库
充值卡表
CREATE TABLE IF NOT EXISTS `cz_access` (
`id` int(10) unsigned NOT NULL AUTO_INCREMENT,
`kid` varchar(10) NOT NULL,
`kpass` varchar(10) NOT NULL,
`type` int(11) NOT NULL,
`yes` int(11) NOT NULL,
`uid` int(11) NOT NULL,
`sj` varchar(20) NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8 AUTO_INCREMENT=30 ;
管理员表
CREATE TABLE IF NOT EXISTS `cz_admin` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`user` varchar(30) NOT NULL,
`pass` varchar(32) NOT NULL,
`date` varchar(20) NOT NULL,
`ip` varchar(20) NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8 AUTO_INCREMENT=44 ;
INSERT INTO `cz_admin` (`id`, `user`, `pass`, `date`, `ip`) VALUES
(43, 'admin', '97e79218963eb72c92a249dd5a330142', '1408952509', '223.222.111.11');
充值日志表
CREATE TABLE IF NOT EXISTS `cz_logs` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`log` varchar(200) NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8 AUTO_INCREMENT=15 ;
INSERT INTO `cz_logs` (`id`, `log`) VALUES
(13, '用户:528何金银|冲值金额:10元|卡类型:测试购物卡|时间:2015-1-15 12:27:18'),
(14, '用户:528何金银|冲值金额:10元|卡类型:测试购物卡|时间:2015-1-15 12:30:30');
充值卡类型表
CREATE TABLE IF NOT EXISTS `cz_type` (
`id` int(11) unsigned NOT NULL AUTO_INCREMENT,
`name` varchar(20) NOT NULL,
`ksj` varchar(15) NOT NULL,
`jsj` varchar(20) NOT NULL,
`js` varchar(300) NOT NULL,
`num` int(11) NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8 AUTO_INCREMENT=5 ;
INSERT INTO `cz_type` (`id`, `name`, `ksj`, `jsj`, `js`, `num`) VALUES
(1, '测试购物卡', '2015-1-1', '2015-1-30', '测试的1', 100),
(2, '测试购物卡', '2015-1-1', '2015-1-30', '测试的2', 50),
充值卡生成的后台是自己写的 没有集成到ecshop里 功能比较简单 代码就不发上来了。