首页 » 工作 » 方法 » 正文

骑士CMS(74cms)增加积分充值卡(积分包优惠)功能

发布者:站点默认
2014/02/27 浏览数(2,085) 分类:方法 骑士CMS(74cms)增加积分充值卡(积分包优惠)功能已关闭评论

积分充值卡说明

1、只能使用支付宝(不提供其它支付方式的代码,勿扰!)、 74CMS版本:3.4;

2、积分充值卡可后台设置卡的金额和内含的积分数(详见下文的效果图),如400RMB充值卡可充入800积分;

3、此功能用于优惠打折;

效果预览:

企业会员使用界面74CMSPointPackShow 添加积分充值卡74CMSPointPackAdd 编辑积分充值卡74CMSPointPackEdit 积分充值卡列表74CMSPointPackList

操作步骤:

零、添加数据表

注意表前缀!content字段暂未使用,可以删除。

-- 创建 point-packs 表
CREATE TABLE IF NOT EXISTS `#@_point_packs` (
  `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
  `name` varchar(64) NOT NULL COMMENT '名称',
  `price` float(6,1) NOT NULL COMMENT '价格',
  `points` int(10) unsigned NOT NULL DEFAULT '0' COMMENT '积分',
  `small_img` varchar(80) DEFAULT NULL COMMENT '缩略图',
  `content` mediumtext COMMENT '介绍',
  `addtime` int(10) unsigned NOT NULL DEFAULT '0' COMMENT '添加日期',
  PRIMARY KEY (`id`),
  KEY `addtime` (`addtime`)
) ENGINE=MyISAM  DEFAULT CHARSET=gbk COMMENT='积分包' AUTO_INCREMENT=1;
-- 修改 order 表
ALTER TABLE `#@_order` ADD `otype` tinyint(1) NOT NULL DEFAULT '0' COMMENT '订单类型,0默认,1积分包' AFTER  `utype`;

一、网站后台

1、增加入口链接

打开 /admin/templates/default/sys/admin_left_tools.htm

<!-- 在 -->
<li ><a href="admin_gifts.php"  target="mainFrame"  >礼品卡</a></li>
<!-- 下边再加一行:-->
<li ><a href="admin_point_packs.php"  target="mainFrame"  >{#$QISHI.points_byname#}充值卡</a></li>

2、新建后台积分卡管理程序文件“/admin/admin_point_packs.php”,内容为:

<?php
/*
 * 积分充值卡
 */
define('IN_QISHI',true);
require_once(dirname(__FILE__).'/../data/config.php');
require_once(dirname(__FILE__).'/include/admin_common.inc.php');
require_once(ADMIN_ROOT_PATH.'include/admin_point_packs_fun.php'); // 这个积分充值卡文件需要创建,见下一步
require_once(ADMIN_ROOT_PATH.'include/upload.php');
$act = !empty($_GET['act']) ? trim($_GET['act']) : 'list';
$smarty->assign('act',$act);
check_permissions($_SESSION['admin_purview'],"point_packs");
$smarty->assign('pageheader',$_CFG['points_byname'].'充值卡');
if($act == 'list') {
	get_token();
	require_once(QISHI_ROOT_PATH.'include/page.class.php');
	$oederbysql=" order BY id  DESC";
	$wheresql="";
	$joinsql="";
	$total_sql="SELECT COUNT(*) AS num FROM ".table('point_packs').$joinsql.$wheresql;
	$total=$db->get_total($total_sql);
	$page = new page(array('total'=>$total, 'perpage'=>$perpage));
	$currenpage=$page->nowindex;
	$offset=($currenpage-1)*$perpage;
	$list = get_point_packs($offset, $perpage,$joinsql.$wheresql.$oederbysql);
	// $smarty->assign('category',get_gifts_category());
	$smarty->assign('list',$list);
	$smarty->assign('total',$total);
	$smarty->assign('page',$page->show(3));
	$smarty->assign('navlabel',"list");
	$smarty->display('point_packs/admin_point_packs_list.htm');
} elseif($act == 'add') {
	get_token();
	$smarty->assign('navlabel',"add");
	$smarty->display('point_packs/admin_point_packs_add.htm');
} elseif($act == 'add_save') {
	check_token();
	$setsqlarr['name']=!empty($_POST['name'])?trim($_POST['name']):adminmsg('请填写名称!',1);
	$setsqlarr['price']=floatval($_POST['price']);
	$setsqlarr['points'] =intval($_POST['points']);
	$setsqlarr['content'] =$_POST['content'];
	if($_FILES['small_img']['name']) {
		$upfiles_dir.=date("Y/m/d/");
		make_dir($upfiles_dir);
		$small_img=_asUpFiles($upfiles_dir, "small_img", 1024*2, 'jpg/gif/png',true);
		$makefile=$upfiles_dir.$small_img;
		make_dir($thumb_dir.date("Y/m/d/"));
		makethumb($makefile,$thumb_dir.date("Y/m/d/"),$thumbwidth=360,$thumbheight=180);
		$setsqlarr['small_img']=date("Y/m/d/").$small_img;
	}
	$setsqlarr['addtime']=time();
	$link[0]['text'] = "返回".$_CFG['points_byname']."充值卡列表";
	$link[0]['href'] = '?act=list';
	!inserttable(table('point_packs'),$setsqlarr)?adminmsg("添加失败!",0):adminmsg("添加成功!",2,$link);
}
elseif($act == 'edit') {
	get_token();
	$id=intval($_GET['id']);
	$rs=get_one($id);
	$smarty->assign('rs',$rs);
	$smarty->assign('upfiles_dir',$upfiles_dir); 
	$smarty->assign('thumb_dir',$thumb_dir); 
	$smarty->assign('navlabel',"rs");
	$smarty->display('point_packs/admin_point_packs_edit.htm');
}
elseif($act == 'del_img') {
	check_token();
	$id=intval($_GET['id']);
	$img=$_GET['img'];
	$sql="update ".table('point_packs')." set Small_img='' where id=".$id." LIMIT 1";
	$db->query($sql);
	@unlink($upfiles_dir.$img);
	@unlink($thumb_dir.$img);
	adminmsg("删除缩略图成功!",2);
}
elseif($act == 'edit_save'){
	check_token();
	$id=intval($_POST['id']);
	$setsqlarr['name']=!empty($_POST['name'])?trim($_POST['name']):adminmsg('请填写名称!',1);
	$setsqlarr['price']=floatval($_POST['price']);
	$setsqlarr['points'] =intval($_POST['points']);
	$setsqlarr['content'] =$_POST['content'];
	if($_FILES['small_img']['name']) {
		$upfiles_dir.=date("Y/m/d/");
		make_dir($upfiles_dir);
		$small_img=_asUpFiles($upfiles_dir, "small_img", 1024*2, 'jpg/gif/png',true);
		$makefile=$upfiles_dir.$small_img;
		make_dir($thumb_dir.date("Y/m/d/"));
		makethumb($makefile,$thumb_dir.date("Y/m/d/"),$thumbwidth=360,$thumbheight=180);
		$setsqlarr['small_img']=date("Y/m/d/").$small_img;
	}
	$link[0]['text'] = "查看修改结果";
	$link[0]['href'] = '?act=edit&id='.$id;
	$link[1]['text'] = "返回列表";
	$link[1]['href'] = '?act=list';
	!updatetable(table('point_packs'),$setsqlarr," id='$id' ")?adminmsg("修改失败!",0):adminmsg("修改成功!",2,$link);
}
elseif($act == 'del') {
	check_token();
	$id=$_REQUEST['id'];
	$num=del($id);
	if ($num>0) {
		adminmsg("删除成功!共删除".$num."行",2);
	} else {
		adminmsg("删除失败!",0);
	}
}
else{
	exit('Here is another world.');
}
?>

3、新建后台积分卡管理程序模板:

建立目录:/admin/templates/default/point_packs/admin_point_packs_add.htm
建立文件:/admin/templates/default/point_packs/admin_point_packs_edit.htm
          /admin/templates/default/point_packs/admin_point_packs_list.htm
          /admin/templates/default/point_packs/admin_point_packs_nav.htm

内容见附件:点击下载

4、新建后台积分卡功能函数文件:admin/include/admin_point_packs_fun.php

<?php
/*
 * 74cms 积分充值卡
 */
if(!defined('IN_QISHI')) {
 	die('Access Denied!');
}
function get_point_packs($offset, $perpage, $sql= '') {
	global $db,$_CFG;
	$limit=" LIMIT ".$offset.','.$perpage;
	$result = $db->query("SELECT * FROM ".table('point_packs').$sql.$limit);
	while($row = $db->fetch_array($result)) {
		$row_arr[] = $row;
	}
	return $row_arr;
}
function del($id) {
	global $db;
	if(!is_array($id)) $id=array($id);
	$return=0;
	$sqlin=implode(",",$id);
	if (preg_match("/^(\d{1,10},)*(\d{1,10})$/",$sqlin)) {
		if (!$db->query("Delete from ".table('point_packs')." WHERE id IN (".$sqlin.") ")) return false;
		$return=$return+$db->affected_rows();
	}
	return $return;
}
function get_one($id) {
	global $db;
	$sql = "select * from ".table('point_packs')." where id=".intval($id)." LIMIT 1";
	return $db->getone($sql);
}
?>

5、修改订单生成功能,增加订单类型以区分默认订单和积分充值卡订单

a、修改 /include/fun_company.php 中的 add_order() 为:

//增加订单
function add_order($uid,$oid,$amount,$payment_name,$description,$addtime,$points='',$setmeal='',$utype='1',$otype='0,0'){
	// 注,后边增加了一个 $otype 参数(orderType),格式“1,积分充值卡ID” 
	global $db;
	$otype = explode(',', $otype); // 新加行: 这个 otype 是新增加的参数,用于区别积分充值卡订单,格式“1,积分充值卡ID” 16:40 2014年2月25日 星期二
	$setsqlarr['otype']=$otype[0]; // 新加行
	$setsqlarr['notes']= empty($otype[1]) ? '' : $otype[1]; // 新加行:使用此字段为积分充值卡记录所选积分充值卡的ID
	$setsqlarr['uid']=intval($uid); // 从这行开始,下边的代码没有关于增加积分充值卡的改动
	$setsqlarr['oid']=$oid;
	$setsqlarr['amount']=$amount;
	$setsqlarr['payment_name']=$payment_name;
	$setsqlarr['description']=$description;
	$setsqlarr['addtime']=$addtime;
	$setsqlarr['points']=$points;
	$setsqlarr['setmeal']=$setmeal;
	$setsqlarr['utype']=$utype;

	write_memberslog($uid,1,3001,$_SESSION['username'],"添加订单,编号{$oid},金额{$amount}元");
	$userinfo=get_user_info($uid);
		//sendemail
		$mailconfig=get_cache('mailconfig');
		if ($mailconfig['set_order']=="1" && $userinfo['email_audit']=="1" && $amount>0)
		{
		global $_CFG;
		$paymenttpye=get_payment_info($payment_name);
		dfopen("{$_CFG['site_domain']}{$_CFG['site_dir']}plus/asyn_mail.php?uid={$uid}&key=".asyn_userkey($uid)."&act=set_order&oid={$oid}&amount={$amount}&paymenttpye={$paymenttpye['byname']}");
		}
		//sendemail
		//sms
		$sms=get_cache('sms_config');
		if ($sms['open']=="1" && $sms['set_order']=="1"  && $userinfo['mobile_audit']=="1" && $amount>0)
		{
		global $_CFG;
		$paymenttpye=get_payment_info($payment_name);
		dfopen("{$_CFG['site_domain']}{$_CFG['site_dir']}plus/asyn_sms.php?uid={$uid}&key=".asyn_userkey($uid)."&act=set_order&oid={$oid}&amount={$amount}&paymenttpye={$paymenttpye['byname']}");
		}
		//sms
	return inserttable(table('order'),$setsqlarr,true);
}

b、修改 /include/fun_company.php 中的 order_paid() ,积分充值卡的订单单独处理,代码:

//付款后开通
function order_paid($v_oid) {
	global $db,$timestamp,$_CFG;
	$order=$db->getone("select * from ".table('order')." WHERE oid ='{$v_oid}' AND is_paid= '1' LIMIT 1 ");
	// 积分充值卡代码开始:
	if ($order && 1== $order['otype']){ // upall:积分充值卡 2014-02-26 09:41:48 Wednesday
		// 设置为已付款
		$user=get_user_info($order['uid']);
		$sql = "UPDATE ".table('order')." SET is_paid= '2',payment_time='{$timestamp}' WHERE oid='{$v_oid}' LIMIT 1 ";
		if (!$db->query($sql)) return false;
		if($order['amount']=='0.00'){$ismoney=1;
		}else{$ismoney=2;}
		// 该积分充值卡是否被删除
		$pointPacksId = (int)$order['notes'];
		$r = $db->getone("SELECT `points`,`name` FROM ".table('point_packs')." WHERE id = '$pointPacksId' LIMIT 1");
		empty($r)?showmsg('您选购的'.$_CFG['points_byname'].'充值卡不存在'):'';
		// 充值
		report_deal($order['uid'],1,$r['points']);				
		$user_points=get_user_points($order['uid']);
		$notes=date('Y-m-d H:i',time()). " 通过[". get_payment_info($order['payment_name'],true). "]成功购买". $_CFG['points_byname']. "充值卡[". $r['name']. "](+{$r['points']}".$_CFG['points_byname']."),(剩余:{$user_points}),订单:{$v_oid}";
		write_memberslog($order['uid'],1,9001,$user['username'],$notes);
		//会员套餐变更记录。会员购买成功。2表示:会员自己购买
		write_setmeallog($order['uid'],$user['username'],$notes,2,$order['amount'],$ismoney,1);
	}
	elseif ($order && 1 != $order['otype']) {
	// 积分充值卡代码结束(上边的IF添加了一个条件)
		$user=get_user_info($order['uid']);
		$sql = "UPDATE ".table('order')." SET is_paid= '2',payment_time='{$timestamp}' WHERE oid='{$v_oid}' LIMIT 1 ";
		if (!$db->query($sql)) return false;
		if($order['amount']=='0.00'){
			$ismoney=1;
		}else{
			$ismoney=2;
		}
		if ($order['points']>0) {
				report_deal($order['uid'],1,$order['points']);				
				$user_points=get_user_points($order['uid']);
				$notes=date('Y-m-d H:i',time())."通过:".get_payment_info($order['payment_name'],true)." 成功充值 ".$order['amount']."元,(+{$order['points']}),(剩余:{$user_points}),订单:{$v_oid}";					
				write_memberslog($order['uid'],1,9001,$user['username'],$notes);

				//会员套餐变更记录。会员购买成功。2表示:会员自己购买
				write_setmeallog($order['uid'],$user['username'],$notes,2,$order['amount'],$ismoney,1);
		
		} elseif ($order['setmeal']>0) {
				set_members_setmeal($order['uid'],$order['setmeal']);
				$setmeal=get_setmeal_one($order['setmeal']);
				$notes=date('Y-m-d H:i',time())."通过:".get_payment_info($order['payment_name'],true)." 成功充值 ".$order['amount']."元并开通{$setmeal['setmeal_name']}";
				write_memberslog($order['uid'],1,9002,$user['username'],$notes);
				//会员套餐变更记录。会员购买成功。2表示:会员自己购买
				write_setmeallog($order['uid'],$user['username'],$notes,2,$order['amount'],$ismoney,2,1);
		}
	}
	//sendemail
	$mailconfig=get_cache('mailconfig');
	if ($mailconfig['set_payment']=="1" && $user['email_audit']=="1" && $order['amount']>0)
	{
	dfopen("{$_CFG['site_domain']}{$_CFG['site_dir']}plus/asyn_mail.php?uid={$order['uid']}&key=".asyn_userkey($order['uid'])."&act=set_payment");
	}
	//sendemail
	//sms
	$sms=get_cache('sms_config');
	if ($sms['open']=="1" && $sms['set_payment']=="1"  && $user['mobile_audit']=="1" && $order['amount']>0)
	{
	dfopen("{$_CFG['site_domain']}{$_CFG['site_dir']}plus/asyn_sms.php?uid={$order['uid']}&key=".asyn_userkey($order['uid'])."&act=set_payment");
	}
	//sms
	return true;
}

二、会员后台

1、编辑程序文件:/user/company/company_service.php

a、编辑“elseif ($act==’order_add’)”块,在display前增加:

// 接入积分充值卡功能 2014-02-25 14:24:00 Tuesday
$s = 'SELECT * FROM '.table('point_packs').' ORDER BY id ASC';
$q = $db->query($s);
while($r = $db->fetch_array($q)) {$point_packs[] = $r; }
$smarty->assign('point_packs',$point_packs);
$smarty->assign('thumb_dir',"../../data/".$_CFG['updir_thumb']."/"); 

b、增加一个“else if”,代码:

elseif ($act=='point_pack_order') // upall:积分充值卡 2014-02-25 15:11:09 Tuesday
{
	if (empty($company_profile['companyname']))
	{
		$link[0]['text'] = "填写企业资料";
		$link[0]['href'] = 'company_info.php?act=company_profile';
		showmsg("请先填写您的企业资料!",1,$link);
	}
	$myorder=get_user_order($_SESSION['uid'],1);
	$order_num=count($myorder);
	if (count($order_num)>=5) {
		$link[0]['text'] = "立即查看";
		$link[0]['href'] = '?act=order_list&is_paid=1';
		showmsg("未处理的订单不能超过 5 条,请先处理后再次申请!",1,$link,true,8);
	}

	$id = (int)$_GET['id'];
	$s = "SELECT `name`,`price` FROM ".table('point_packs')." WHERE id=".intval($id)." LIMIT 1";
	$r = $db->getone($s);
	empty($r) ? showmsg('您要购买的'.$_CFG['points_byname'].'充值卡不存在') : '';
	$amount = $r['price'];
	$name = $r['name'];
	$payment_name='alipay';// empty($_POST['payment_name'])?showmsg("请选择付款方式!",1):$_POST['payment_name'];
	$paymenttpye=get_payment_info($payment_name);
	if (empty($paymenttpye)) showmsg("支付方式错误!",0);
	$fee=number_format(($amount/100)*$paymenttpye['fee'],1,'.','');//手续费
	$order['oid']= date('Ymd',time())."-".$paymenttpye['partnerid']."-".date('His',time());//订单号
	$order['v_url']=$_CFG['site_domain'].$_CFG['site_dir']."include/payment/respond_".$paymenttpye['typename'].".php";
	$order['v_amount']=$amount+$fee; 
	$points=$amount*$_CFG['payment_rate'];
	$order_id=add_order($_SESSION['uid'],$order['oid'],$amount,$payment_name,'购买'.$_CFG['points_byname']."充值卡($name):".$points, $timestamp,$points,'',1,$pointPacks="1,$id");
	if ($order_id){
		$link[0]['text'] = "现在去付款";
		$link[0]['href'] = "?act=payment&order_id=".$order_id;
		$link[1]['text'] = "查看订单";
		$link[1]['href'] = '?act=order_list';
		showmsg('充值订单添加成功!',2,$link,true,5);
	} else {
		showmsg("添加订单失败!",0);
	}
}

2、编辑模板文件:/templates/你的模板文件夹/member_company/company_order_add.htm,在合适的位置增加代码:

<style>
/* 这里的样式根据自己需要可单独编写,非必需 */
.c {  clear: both;}
.r {  float: right;}
#pointPacks {  margin: 10px 0;  border: solid 1px #D8D8D8;  background-color: #F8F8F8;}
#pointPacks dt {  height: 35px;  line-height: 35px;  text-indent: 10px;  font-weight: bold;  border-bottom: solid 1px #D8D8D8;  font-size: 14px;}
#pointPacks dd {  padding: 10px;}#pointPacks dd li {  float: left;  width: 50%;  margin: 10px 0;  position: relative;}
#pointPacks dd li .thumb {	position:relative;	margin:0 auto;}
#pointPacks dd li .thumb,#pointPacks dd li .thumb img {  width: 360px;  height: 180px;}
#pointPacks dd li .thumb img {  position: absolute;  left: 0;  top: 0;  background-color: #C95800;  border-radius: 5px;}
#pointPacks dd li .buy {	display:none;	position:absolute;	left:0;	top:0;	width:360px;	height:180px;	text-align:center; background-color:#884400;	background-color: rgba(136,68,0,.7);	color:#FFF;	text-align:center;	line-height: 180px; font-size: 48px; border-radius:5px; left:18px; }
#pointPacks dd li.hover .buy, #pointPacks dd li:hover .buy {display:block; }
#pointPacks dd li .title {display:none; font-weight: bold; color: #C00; }
#pointPacks dd li .points {color: #FFF; position: absolute; left: 80px; top: 110px; font-size: 18px; }
#pointPacks dd li .price {position:absolute; right: 75px; top: 135px; font-size: 28px;line-height: 30px;}
</style>
<dl id="pointPacks">
	<dt>购买{#$QISHI.points_byname#}充值卡</dt>
	<dd>
		<ul>
			{#foreach from=$point_packs item=list#}
			<li>
				<div class="thumb" href=""><img src="{#$thumb_dir#}{#$list.small_img#}" alt="{#$list.name#}" /></div>
				<div class="info">
					<span class="title">  {#$list.name#} </span>
					<span class="price">  ¥{#$list.price|number_format:2#} </span>
					<span class="points"> {#$list.points#}{#$QISHI.points_byname#} </span>
					<a class="buy" href="?act=point_pack_order&amp;id={#$list.id#}" class="r">立即购买</a>
				</div>
			</li>
			{#/foreach#}
		</ul>
	<div class="c"></div>
	</dd>
</dl>

<完>

点击返回顶部
  1. 留言
  2. 联系方式